Using global game instance instead of passing it as an argument.
This commit is contained in:
parent
c6cb48d539
commit
b4cb4634cf
|
|
@ -1 +1 @@
|
|||
Subproject commit 4a93ca2a9d77eeb65ac51bba13560258d83fe772
|
||||
Subproject commit 95167c91e8713cf05e9bade6c978903e9f0bdb39
|
||||
|
|
@ -82,7 +82,7 @@ inline int door_component_destroy(component_t *component)
|
|||
|
||||
inline int door_component_subscribe(door_component_data_t *component_data, entity_t *entity)
|
||||
{
|
||||
if(event_bus_subscribe(&game.event_bus, component_data->topic_id, door_component_callback, entity)) return_failure_int;
|
||||
if(event_bus_subscribe(component_data->topic_id, door_component_callback, entity)) return_failure_int;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ inline int interact_component_init(component_t *component)
|
|||
|
||||
component_data->topic_id = 0;
|
||||
|
||||
if(event_bus_new_topic(&game.event_bus, component_data->topic_id)) return_failure_int;
|
||||
if(event_bus_new_topic(component_data->topic_id)) return_failure_int;
|
||||
|
||||
component_data->activated = true;
|
||||
|
||||
|
|
@ -83,14 +83,14 @@ inline int interact_component_interact(interact_component_data_t *component_data
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(event_bus_publish(&game.event_bus, component_data->topic_id, component_data->state)) return_failure_int;
|
||||
if(event_bus_publish(component_data->topic_id, component_data->state)) return_failure_int;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
inline int interact_component_modify_topic_id(interact_component_data_t *component_data, size_t id)
|
||||
{
|
||||
if(event_bus_change_topic_id(&game.event_bus, component_data->topic_id, id)) return_failure_int;
|
||||
if(event_bus_change_topic_id(component_data->topic_id, id)) return_failure_int;
|
||||
|
||||
component_data->topic_id = id;
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ inline int lever_component_destroy(component_t *component)
|
|||
|
||||
inline int lever_component_subscribe(lever_component_data_t *component_data, entity_t *entity)
|
||||
{
|
||||
if(event_bus_subscribe(&game.event_bus, component_data->topic_id, lever_component_callback, entity)) return_failure_int;
|
||||
if(event_bus_subscribe(component_data->topic_id, lever_component_callback, entity)) return_failure_int;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
|||
{
|
||||
physics_system_data->speed = PLAYER_DEFAULT_RUN_SPEED;
|
||||
|
||||
asset_t *asset = asset_manager_get_asset(&game.asset_manager, "player_run_sheet");
|
||||
asset_t *asset = asset_manager_get_asset("player_run_sheet");
|
||||
if(!asset) return_failure_int;
|
||||
|
||||
sprite_component_data->texture = asset->data;
|
||||
|
|
@ -137,7 +137,7 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
|||
{
|
||||
physics_system_data->speed = PLAYER_DEFAULT_WALK_SPEED;
|
||||
|
||||
asset_t *asset = asset_manager_get_asset(&game.asset_manager, "player_walk_sheet");
|
||||
asset_t *asset = asset_manager_get_asset("player_walk_sheet");
|
||||
if(!asset) return_failure_int;
|
||||
|
||||
sprite_component_data->texture = asset->data;
|
||||
|
|
@ -150,7 +150,7 @@ static inline int player_system_set_animation_and_speed(player_system_data_t *sy
|
|||
}
|
||||
else if(!(system_data->state & PLAYER_MOVING) && (system_data->last_state & PLAYER_MOVING))
|
||||
{
|
||||
asset_t *asset = asset_manager_get_asset(&game.asset_manager, "player_idle_sheet");
|
||||
asset_t *asset = asset_manager_get_asset("player_idle_sheet");
|
||||
if(!asset) return_failure_int;
|
||||
|
||||
sprite_component_data->texture = asset->data;
|
||||
|
|
|
|||
41
src/game.c
41
src/game.c
|
|
@ -14,15 +14,15 @@ int game_init(void)
|
|||
game.is_running = false;
|
||||
|
||||
if(display_init()) return_failure_int;
|
||||
if(asset_manager_init(&game.asset_manager)) return_failure_int;
|
||||
event_bus_init(&game.event_bus);
|
||||
entity_manager_init(&game.entity_manager);
|
||||
if(asset_manager_init()) return_failure_int;
|
||||
event_bus_init();
|
||||
entity_manager_init();
|
||||
|
||||
if(!asset_manager_load_asset(&game.asset_manager, "tileset", ASSET_TEXTURE)) return_failure_int;
|
||||
if(!asset_manager_load_asset("tileset", ASSET_TEXTURE)) return_failure_int;
|
||||
|
||||
/* ======== Player ======== */
|
||||
{
|
||||
entity_t *player_entity = entity_manager_new_entity(&game.entity_manager, 0);
|
||||
entity_t *player_entity = entity_manager_new_entity(0);
|
||||
if(!player_entity) return_failure_int;
|
||||
|
||||
{
|
||||
|
|
@ -45,14 +45,13 @@ int game_init(void)
|
|||
|
||||
sprite_component_data_t *sprite_component_data = sprite_component->data;
|
||||
|
||||
if(!asset_manager_load_asset(&game.asset_manager, "player_idle_sheet", ASSET_TEXTURE)) return_failure_int;
|
||||
if(!asset_manager_load_asset(&game.asset_manager, "player_walk_sheet", ASSET_TEXTURE)) return_failure_int;
|
||||
if(!asset_manager_load_asset(&game.asset_manager, "player_run_sheet", ASSET_TEXTURE)) return_failure_int;
|
||||
|
||||
asset_t *asset = asset_manager_get_asset(&game.asset_manager, "player_idle_sheet");
|
||||
asset_t *asset = asset_manager_load_asset("player_idle_sheet", ASSET_TEXTURE);
|
||||
if(!asset) return_failure_int;
|
||||
|
||||
sprite_component_data->texture = asset->data;
|
||||
|
||||
if(!asset_manager_load_asset("player_walk_sheet", ASSET_TEXTURE)) return_failure_int;
|
||||
if(!asset_manager_load_asset("player_run_sheet", ASSET_TEXTURE)) return_failure_int;
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -95,7 +94,7 @@ int game_init(void)
|
|||
}
|
||||
/* ======== Lever ========*/
|
||||
{
|
||||
entity_t *lever_entity = entity_manager_new_entity(&game.entity_manager, 1);
|
||||
entity_t *lever_entity = entity_manager_new_entity(1);
|
||||
if(!lever_entity) return_failure_int;
|
||||
|
||||
{
|
||||
|
|
@ -118,7 +117,7 @@ int game_init(void)
|
|||
|
||||
sprite_component_data_t *sprite_component_data = sprite_component->data;
|
||||
|
||||
asset_t *asset = asset_manager_load_asset(&game.asset_manager, "lever_sheet", ASSET_TEXTURE);
|
||||
asset_t *asset = asset_manager_load_asset("lever_sheet", ASSET_TEXTURE);
|
||||
if(!asset) return_failure_int;
|
||||
|
||||
sprite_component_data->texture = asset->data;
|
||||
|
|
@ -196,7 +195,7 @@ int game_init(void)
|
|||
|
||||
/* ======== Door ======== */
|
||||
{
|
||||
entity_t *door_entity = entity_manager_new_entity(&game.entity_manager, 1);
|
||||
entity_t *door_entity = entity_manager_new_entity(1);
|
||||
if(!door_entity) return_failure_int;
|
||||
|
||||
{
|
||||
|
|
@ -219,7 +218,7 @@ int game_init(void)
|
|||
|
||||
sprite_component_data_t * sprite_component_data = sprite_component->data;
|
||||
|
||||
asset_t *asset = asset_manager_load_asset(&game.asset_manager, "barred_door_sheet", ASSET_TEXTURE);
|
||||
asset_t *asset = asset_manager_load_asset("barred_door_sheet", ASSET_TEXTURE);
|
||||
if(!asset) return_failure_int;
|
||||
|
||||
sprite_component_data->texture = asset->data;
|
||||
|
|
@ -274,7 +273,7 @@ int game_init(void)
|
|||
|
||||
/* ======== Door 2 ======== */
|
||||
{
|
||||
entity_t *door2_entity = entity_manager_new_entity(&game.entity_manager, 1);
|
||||
entity_t *door2_entity = entity_manager_new_entity(1);
|
||||
if(!door2_entity) return_failure_int;
|
||||
|
||||
{
|
||||
|
|
@ -297,7 +296,7 @@ int game_init(void)
|
|||
|
||||
sprite_component_data_t *sprite_component_data = sprite_component->data;
|
||||
|
||||
asset_t *asset = asset_manager_load_asset(&game.asset_manager, "wooden_door_sheet", ASSET_TEXTURE);
|
||||
asset_t *asset = asset_manager_load_asset("wooden_door_sheet", ASSET_TEXTURE);
|
||||
if(!asset) return_failure_int;
|
||||
|
||||
sprite_component_data->texture = asset->data;
|
||||
|
|
@ -373,7 +372,7 @@ void game_handle_event(void)
|
|||
|
||||
int game_update(void)
|
||||
{
|
||||
if(entity_manager_update(&game.entity_manager))
|
||||
if(entity_manager_update())
|
||||
{
|
||||
game.is_running = false;
|
||||
return_failure_int;
|
||||
|
|
@ -390,7 +389,7 @@ int game_render(void)
|
|||
return_failure_int;
|
||||
}
|
||||
|
||||
if(entity_manager_draw(&game.entity_manager))
|
||||
if(entity_manager_draw())
|
||||
{
|
||||
game.is_running = false;
|
||||
return_failure_int;
|
||||
|
|
@ -403,9 +402,9 @@ int game_render(void)
|
|||
|
||||
int game_exit(void)
|
||||
{
|
||||
entity_manager_exit(&game.entity_manager);
|
||||
event_bus_exit(&game.event_bus);
|
||||
if(asset_manager_exit(&game.asset_manager)) return_failure_int;
|
||||
entity_manager_exit();
|
||||
event_bus_exit();
|
||||
if(asset_manager_exit()) return_failure_int;
|
||||
display_exit();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
Loading…
Reference in New Issue