Continue plan data struct for scene management

scene_man
En Yi 2024-06-20 21:41:14 +08:00
parent f98e242378
commit 0653cbd0a2
6 changed files with 30 additions and 21 deletions

View File

@ -21,17 +21,11 @@ typedef struct SceneNode {
Scene_t* next; Scene_t* next;
} SceneNode_t; } SceneNode_t;
typedef struct SceneManager {
Scene_t **scenes; // Array of all possible scenes
unsigned int max_scenes;
SceneNode_t* active; // Scenes to update. This allows multiple scene updates
SceneNode_t* to_render; // Scenes to render. This allows duplicate rendering
} SceneManger_t;
typedef struct GameEngine { typedef struct GameEngine {
Scene_t **scenes; Scene_t **scenes;
unsigned int max_scenes; unsigned int max_scenes;
unsigned int curr_scene; unsigned int curr_scene;
Scene_t* scenes_render_order[MAX_SCENES_TO_RENDER];
Assets_t assets; Assets_t assets;
SFXList_t sfx_list; SFXList_t sfx_list;
// Maintain own queue to handle key presses // Maintain own queue to handle key presses
@ -42,20 +36,22 @@ typedef struct GameEngine {
Vector2 intended_window_size; Vector2 intended_window_size;
} GameEngine_t; } GameEngine_t;
//typedef enum SceneType {
// LEVEL_SCENE = 0,
// MENU_SCENE,
//}SceneType_t;
typedef enum SceneState { typedef enum SceneState {
SCENE_PLAYING = 0, SCENE_PLAYING = 0, // All Systems Active
SCENE_SUSPENDED, SCENE_SUSPENDED, //
SCENE_ENDED, SCENE_ENDED,
}SceneState_t; }SceneState_t;
typedef void(*render_func_t)(Scene_t*); #define SCENE_ACTIVE_BIT (1 << 0) // Systems Active
#define SCENE_RENDER_BIT (1 << 1) // Whether to render
typedef enum ActionResult {
ACTION_PROPAGATE = 0,
ACTION_CONSUMED,
} ActionResult;
typedef void(*system_func_t)(Scene_t*); typedef void(*system_func_t)(Scene_t*);
typedef void(*action_func_t)(Scene_t*, ActionType_t, bool); typedef ActionResult(*action_func_t)(Scene_t*, ActionType_t, bool);
sc_array_def(system_func_t, systems); sc_array_def(system_func_t, systems);
typedef struct RenderLayer { typedef struct RenderLayer {
@ -69,20 +65,23 @@ typedef struct SceneRenderLayers {
} SceneRenderLayers_t; } SceneRenderLayers_t;
struct Scene { struct Scene {
// Not all scene needs an entity manager
// but too late to change this
EntityManager_t ent_manager;
Scene_t* parent_scene;
struct sc_map_64 action_map; // key -> actions struct sc_map_64 action_map; // key -> actions
struct sc_array_systems systems; struct sc_array_systems systems;
SceneRenderLayers_t layers; SceneRenderLayers_t layers;
Color bg_colour; Color bg_colour;
action_func_t action_function; action_func_t action_function;
EntityManager_t ent_manager; // TODO: need move in data, Not all scene need this
float delta_time; float delta_time;
float time_scale; float time_scale;
Vector2 mouse_pos; Vector2 mouse_pos;
//SceneType_t scene_type;
SceneState_t state; SceneState_t state;
ParticleSystem_t part_sys; ParticleSystem_t part_sys;
GameEngine_t *engine; GameEngine_t *engine;
int8_t depth_index; int8_t depth_index;
SceneNode_t child_scene; // Intrusive Linked List for children scene
}; };

View File

@ -1,6 +1,7 @@
#ifndef _ENGINE_CONF_H #ifndef _ENGINE_CONF_H
#define _ENGINE_CONF_H #define _ENGINE_CONF_H
#define MAX_SCENES_TO_RENDER 16
#define MAX_RENDER_LAYERS 4 #define MAX_RENDER_LAYERS 4
#define MAX_ENTITIES 2048 #define MAX_ENTITIES 2048
#define MAX_TEXTURES 16 #define MAX_TEXTURES 16

View File

@ -34,4 +34,10 @@ typedef enum SFXTag {
BUBBLE_SFX, BUBBLE_SFX,
COIN_SFX, COIN_SFX,
} SFXTag_t; } SFXTag_t;
//typedef enum SceneType {
// LEVEL_SCENE = 0,
// MENU_SCENE,
//}SceneType_t;
#endif #endif

View File

@ -797,7 +797,7 @@ static void restart_editor_level(Scene_t* scene)
} }
} }
static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed) static ActionResult level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
{ {
LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data); LevelSceneData_t* data = &(CONTAINER_OF(scene, LevelScene_t, scene)->data);
Entity_t* p_player; Entity_t* p_player;
@ -1002,6 +1002,7 @@ static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
break; break;
} }
} }
return ACTION_PROPAGATE;
} }
void init_sandbox_scene(LevelScene_t* scene) void init_sandbox_scene(LevelScene_t* scene)

View File

@ -45,7 +45,7 @@ static void level_scene_render_func(Scene_t* scene)
EndTextureMode(); EndTextureMode();
} }
static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed) static ActionResult level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
{ {
CPlayerState_t* p_playerstate; CPlayerState_t* p_playerstate;
sc_map_foreach_value(&scene->ent_manager.component_map[CPLAYERSTATE_T], p_playerstate) sc_map_foreach_value(&scene->ent_manager.component_map[CPLAYERSTATE_T], p_playerstate)
@ -96,6 +96,7 @@ static void level_do_action(Scene_t* scene, ActionType_t action, bool pressed)
break; break;
} }
} }
return ACTION_PROPAGATE;
} }
static void render_regular_game_scene(Scene_t* scene) static void render_regular_game_scene(Scene_t* scene)

View File

@ -34,7 +34,7 @@ static void exec_component_function(Scene_t* scene, int sel)
} }
} }
static void menu_do_action(Scene_t* scene, ActionType_t action, bool pressed) static ActionResult menu_do_action(Scene_t* scene, ActionType_t action, bool pressed)
{ {
MenuSceneData_t* data = &(CONTAINER_OF(scene, MenuScene_t, scene)->data); MenuSceneData_t* data = &(CONTAINER_OF(scene, MenuScene_t, scene)->data);
unsigned int new_selection = data->selected_comp; unsigned int new_selection = data->selected_comp;
@ -83,6 +83,7 @@ static void menu_do_action(Scene_t* scene, ActionType_t action, bool pressed)
exec_component_function(scene, data->selected_comp); exec_component_function(scene, data->selected_comp);
} }
} }
return ACTION_PROPAGATE;
} }
static void gui_loop(Scene_t* scene) static void gui_loop(Scene_t* scene)