WIP on physics/stage BSP stuff

This commit is contained in:
2026-06-27 13:16:28 -04:00
parent cb878cfaa5
commit 462fb12bd5
10 changed files with 130 additions and 66 deletions

View File

@@ -4,18 +4,12 @@
#include <SDL3/SDL.h>
#include <akstdlib.h>
#include <akgl/actor.h>
#define AKGL_STAGE_PARTITION_HORIZONTAL 0
#define AKGL_STAGE_PARTITION_VERTICAL 1
#define AKGL_STAGE_PARTITION_MAXDEPTH 4
// Stages are collections of lights and cameras in a 2D or 3D space wherein actors
// and backgrounds are placed and directed for action.
typedef struct akgl_Stage {
aksl_TreeNode bsp;
akerr_ErrorContext AKERR_NOIGNORE *(*partition)(struct akgl_Stage *self);
akerr_ErrorContext AKERR_NOIGNORE *(*partition_actor)(struct akgl_Stage *self, akgl_Actor *actor);
} akgl_Stage;
typedef struct akgl_BSPContext {
aksl_TreeNode *left;
aksl_TreeNode *right;
@@ -25,11 +19,27 @@ typedef struct akgl_BSPContext {
typedef struct akgl_BSPLeaf {
SDL_FRect extent;
aksl_ListNode *actors;
}
} akgl_BSPLeaf;
// Stages are collections of lights and cameras in a 2D or 3D space wherein actors
// and backgrounds are placed and directed for action.
typedef struct akgl_Stage {
aksl_TreeNode bsp;
akgl_BSPLeaf _rootleaf;
akerr_ErrorContext AKERR_NOIGNORE *(*partition)(struct akgl_Stage *self);
akerr_ErrorContext AKERR_NOIGNORE *(*partition_actor)(struct akgl_Stage *self, akgl_Actor *actor);
} akgl_Stage;
akerr_ErrorContext AKERR_NOIGNORE *akgl_stage_2d(akgl_Stage *self);
// A function to divide the stage into a binary space partition tree with lists of actors in each partition
akerr_ErrorContext AKERR_NOIGNORE *akgl_stage_2d_partition(akgl_Stage *self);
akerr_ErrorContext AKERR_NOIGNORE *akgl_stage_2d_partition_switchdirection(uint8_t direction, uint8_t *dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_stage_2d_bsp_actoriter(aksl_ListNode *node, void *data);
akerr_ErrorContext AKERR_NOIGNORE *akgl_stage_2d_bsp(aksl_TreeNode *root, aksl_ListNode *actors, SDL_FRect extents, uint8_t direction, uint8_t depth, uint8_t maxdepth);
akerr_ErrorContext AKERR_NOIGNORE *akgl_stage_2d_bspfree(akgl_Stage *self);
akerr_ErrorContext AKERR_NOIGNORE *akgl_stage_2d_partition(akgl_Stage *self);
akerr_ErrorContext AKERR_NOIGNORE *akgl_stage_2d_bsp_move(akgl_Stage *self, akgl_Actor *actor);
#endif // _STAGE_H_