parent
b30646103d
commit
d2a19c5405
|
@ -9,9 +9,6 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Maintain own queue to handle key presses
|
||||
struct sc_queue_32 key_buffer;
|
||||
|
||||
Scene_t* scenes[1];
|
||||
static GameEngine_t engine =
|
||||
{
|
||||
|
@ -23,7 +20,7 @@ static GameEngine_t engine =
|
|||
|
||||
int main(void)
|
||||
{
|
||||
sc_queue_init(&key_buffer);
|
||||
init_engine(&engine);
|
||||
InitWindow(1280, 640, "raylib");
|
||||
SetTargetFPS(60);
|
||||
init_memory_pools();
|
||||
|
@ -48,38 +45,7 @@ int main(void)
|
|||
|
||||
while(true)
|
||||
{
|
||||
|
||||
// This entire key processing relies on the assumption that a pressed key will
|
||||
// appear in the polling of raylib
|
||||
|
||||
unsigned int sz = sc_queue_size(&key_buffer);
|
||||
// Process any existing pressed key
|
||||
for (size_t i = 0; i < sz; i++)
|
||||
{
|
||||
int button = sc_queue_del_first(&key_buffer);
|
||||
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
|
||||
if (IsKeyReleased(button))
|
||||
{
|
||||
do_action(&scene.scene, action, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_action(&scene.scene, action, true);
|
||||
sc_queue_add_last(&key_buffer, button);
|
||||
}
|
||||
}
|
||||
|
||||
// Detect new key presses
|
||||
while(true)
|
||||
{
|
||||
int button = GetKeyPressed();
|
||||
if (button == 0) break;
|
||||
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
|
||||
if (!sc_map_found(&scene.scene.action_map)) continue;
|
||||
do_action(&scene.scene, action, true);
|
||||
sc_queue_add_last(&key_buffer, button);
|
||||
}
|
||||
|
||||
process_inputs(&engine, &scene.scene);
|
||||
update_scene(&scene.scene);
|
||||
update_entity_manager(&scene.scene.ent_manager);
|
||||
// This is needed to advance time delta
|
||||
|
@ -95,7 +61,7 @@ int main(void)
|
|||
}
|
||||
free_scene(&scene.scene);
|
||||
term_level_scene_data(&scene.data);
|
||||
sc_queue_term(&key_buffer);
|
||||
deinit_engine(&engine);
|
||||
term_assets(&engine.assets);
|
||||
CloseWindow();
|
||||
}
|
||||
|
|
32
main.c
32
main.c
|
@ -24,7 +24,7 @@ int main(void)
|
|||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
sc_queue_init(&key_buffer);
|
||||
init_engine(&engine);
|
||||
InitWindow(screenWidth, screenHeight, "raylib");
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
init_memory_pools();
|
||||
|
@ -62,33 +62,7 @@ int main(void)
|
|||
// appear in the polling of raylib
|
||||
Scene_t* curr_scene = engine.scenes[engine.curr_scene];
|
||||
|
||||
unsigned int sz = sc_queue_size(&key_buffer);
|
||||
// Process any existing pressed key
|
||||
for (size_t i = 0; i < sz; i++)
|
||||
{
|
||||
int button = sc_queue_del_first(&key_buffer);
|
||||
ActionType_t action = sc_map_get_64(&curr_scene->action_map, button);
|
||||
if (IsKeyReleased(button))
|
||||
{
|
||||
do_action(curr_scene, action, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_action(curr_scene, action, true);
|
||||
sc_queue_add_last(&key_buffer, button);
|
||||
}
|
||||
}
|
||||
|
||||
// Detect new key presses
|
||||
while(true)
|
||||
{
|
||||
int button = GetKeyPressed();
|
||||
if (button == 0) break;
|
||||
ActionType_t action = sc_map_get_64(&curr_scene->action_map, button);
|
||||
if (!sc_map_found(&curr_scene->action_map)) continue;
|
||||
do_action(curr_scene, action, true);
|
||||
sc_queue_add_last(&key_buffer, button);
|
||||
}
|
||||
process_inputs(&engine, curr_scene);
|
||||
|
||||
update_scene(curr_scene);
|
||||
update_entity_manager(&curr_scene->ent_manager);
|
||||
|
@ -108,7 +82,7 @@ int main(void)
|
|||
free_sandbox_scene(&sandbox_scene);
|
||||
free_game_scene(&level_scene);
|
||||
free_menu_scene(&menu_scene);
|
||||
sc_queue_term(&key_buffer);
|
||||
deinit_engine(&engine);
|
||||
term_assets(&engine.assets);
|
||||
CloseWindow();
|
||||
}
|
||||
|
|
35
scene_test.c
35
scene_test.c
|
@ -5,8 +5,6 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Maintain own queue to handle key presses
|
||||
struct sc_queue_32 key_buffer;
|
||||
|
||||
Scene_t* scenes[1];
|
||||
static GameEngine_t engine =
|
||||
|
@ -19,7 +17,7 @@ static GameEngine_t engine =
|
|||
|
||||
int main(void)
|
||||
{
|
||||
sc_queue_init(&key_buffer);
|
||||
init_engine(&engine);
|
||||
InitWindow(1280, 640, "raylib");
|
||||
SetTargetFPS(60);
|
||||
init_memory_pools();
|
||||
|
@ -47,34 +45,7 @@ int main(void)
|
|||
|
||||
// This entire key processing relies on the assumption that a pressed key will
|
||||
// appear in the polling of raylib
|
||||
|
||||
unsigned int sz = sc_queue_size(&key_buffer);
|
||||
// Process any existing pressed key
|
||||
for (size_t i = 0; i < sz; i++)
|
||||
{
|
||||
int button = sc_queue_del_first(&key_buffer);
|
||||
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
|
||||
if (IsKeyReleased(button))
|
||||
{
|
||||
do_action(&scene.scene, action, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_action(&scene.scene, action, true);
|
||||
sc_queue_add_last(&key_buffer, button);
|
||||
}
|
||||
}
|
||||
|
||||
// Detect new key presses
|
||||
while(true)
|
||||
{
|
||||
int button = GetKeyPressed();
|
||||
if (button == 0) break;
|
||||
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
|
||||
if (!sc_map_found(&scene.scene.action_map)) continue;
|
||||
do_action(&scene.scene, action, true);
|
||||
sc_queue_add_last(&key_buffer, button);
|
||||
}
|
||||
process_inputs(&engine, &scene.scene);
|
||||
|
||||
update_scene(&scene.scene);
|
||||
update_entity_manager(&scene.scene.ent_manager);
|
||||
|
@ -83,7 +54,7 @@ int main(void)
|
|||
if (WindowShouldClose()) break;
|
||||
}
|
||||
free_sandbox_scene(&scene);
|
||||
sc_queue_term(&key_buffer);
|
||||
deinit_engine(&engine);
|
||||
term_assets(&engine.assets);
|
||||
CloseWindow();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,46 @@
|
|||
#include "engine.h"
|
||||
|
||||
void init_engine(GameEngine_t* engine)
|
||||
{
|
||||
sc_queue_init(&engine->key_buffer);
|
||||
}
|
||||
|
||||
void deinit_engine(GameEngine_t* engine)
|
||||
{
|
||||
sc_queue_term(&engine->key_buffer);
|
||||
}
|
||||
|
||||
void process_inputs(GameEngine_t* engine, Scene_t* scene)
|
||||
{
|
||||
unsigned int sz = sc_queue_size(&engine->key_buffer);
|
||||
// Process any existing pressed key
|
||||
for (size_t i = 0; i < sz; i++)
|
||||
{
|
||||
int button = sc_queue_del_first(&engine->key_buffer);
|
||||
ActionType_t action = sc_map_get_64(&scene->action_map, button);
|
||||
if (IsKeyReleased(button))
|
||||
{
|
||||
do_action(scene, action, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_action(scene, action, true);
|
||||
sc_queue_add_last(&engine->key_buffer, button);
|
||||
}
|
||||
}
|
||||
|
||||
// Detect new key presses
|
||||
while(true)
|
||||
{
|
||||
int button = GetKeyPressed();
|
||||
if (button == 0) break;
|
||||
ActionType_t action = sc_map_get_64(&scene->action_map, button);
|
||||
if (!sc_map_found(&scene->action_map)) continue;
|
||||
do_action(scene, action, true);
|
||||
sc_queue_add_last(&engine->key_buffer, button);
|
||||
}
|
||||
}
|
||||
|
||||
void change_scene(GameEngine_t* engine, unsigned int idx)
|
||||
{
|
||||
engine->scenes[engine->curr_scene]->state = SCENE_ENDED;
|
||||
|
|
|
@ -12,6 +12,8 @@ typedef struct GameEngine {
|
|||
unsigned int max_scenes;
|
||||
unsigned int curr_scene;
|
||||
Assets_t assets;
|
||||
// Maintain own queue to handle key presses
|
||||
struct sc_queue_32 key_buffer;
|
||||
} GameEngine_t;
|
||||
void change_scene(GameEngine_t* engine, unsigned int idx);
|
||||
|
||||
|
@ -41,6 +43,10 @@ struct Scene {
|
|||
GameEngine_t *engine;
|
||||
};
|
||||
|
||||
void init_engine(GameEngine_t* engine);
|
||||
void deinit_engine(GameEngine_t* engine);
|
||||
void process_inputs(GameEngine_t* engine, Scene_t* scene);
|
||||
|
||||
// Inline functions, for convenience
|
||||
extern void update_scene(Scene_t* scene);
|
||||
extern void render_scene(Scene_t* scene);
|
||||
|
|
37
water_test.c
37
water_test.c
|
@ -407,7 +407,7 @@ static void player_simple_movement_system(Scene_t* scene)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
sc_queue_init(&key_buffer);
|
||||
init_engine(&engine);
|
||||
InitWindow(1280, 640, "raylib");
|
||||
SetTargetFPS(60);
|
||||
init_memory_pools();
|
||||
|
@ -457,38 +457,7 @@ int main(void)
|
|||
|
||||
while(true)
|
||||
{
|
||||
|
||||
// This entire key processing relies on the assumption that a pressed key will
|
||||
// appear in the polling of raylib
|
||||
|
||||
unsigned int sz = sc_queue_size(&key_buffer);
|
||||
// Process any existing pressed key
|
||||
for (size_t i = 0; i < sz; i++)
|
||||
{
|
||||
int button = sc_queue_del_first(&key_buffer);
|
||||
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
|
||||
if (IsKeyReleased(button))
|
||||
{
|
||||
do_action(&scene.scene, action, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
do_action(&scene.scene, action, true);
|
||||
sc_queue_add_last(&key_buffer, button);
|
||||
}
|
||||
}
|
||||
|
||||
// Detect new key presses
|
||||
while(true)
|
||||
{
|
||||
int button = GetKeyPressed();
|
||||
if (button == 0) break;
|
||||
ActionType_t action = sc_map_get_64(&scene.scene.action_map, button);
|
||||
if (!sc_map_found(&scene.scene.action_map)) continue;
|
||||
do_action(&scene.scene, action, true);
|
||||
sc_queue_add_last(&key_buffer, button);
|
||||
}
|
||||
|
||||
process_inputs(&engine, &scene.scene);
|
||||
update_scene(&scene.scene);
|
||||
update_entity_manager(&scene.scene.ent_manager);
|
||||
// This is needed to advance time delta
|
||||
|
@ -504,7 +473,7 @@ int main(void)
|
|||
}
|
||||
free_scene(&scene.scene);
|
||||
term_level_scene_data(&scene.data);
|
||||
sc_queue_term(&key_buffer);
|
||||
deinit_engine(&engine);
|
||||
term_assets(&engine.assets);
|
||||
CloseWindow();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue