polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 21ddec754a19406503a6fb40a04aed97848dde52
parent 7f1108e7efcd1971a5f8e421e33f7547489a7aa6
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  4 Oct 2021 17:06:10 -0700

rename game.{c,h} to engine.{c,h}

Diffstat:
Mmain.c | 9++++-----
Msrc/chess.h | 2+-
Asrc/engine.c | 118+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/game.h -> src/engine.h | 0
Dsrc/event.c | 6------
Dsrc/event.h | 9---------
Dsrc/game.c | 118-------------------------------------------------------------------------------
Msrc/movement.c | 2+-
Msrc/movement.h | 2+-
Msrc/render.c | 2+-
Msrc/scene.h | 2+-
Msrc/test_game.c | 2+-
Msrc/test_game.h | 2+-
Msrc/update.c | 2+-
Msrc/update.h | 2+-
Msrc/window.c | 2+-
Msrc/window.h | 2+-
17 files changed, 133 insertions(+), 149 deletions(-)

diff --git a/main.c b/main.c @@ -1,10 +1,10 @@ #include "animation.h" -#include "event.h" +#include "chess.h" +#include "debug.h" +#include "engine.h" #include "fbo.h" #include "file.h" -#include "game.h" -#include "debug.h" #include "geometry.h" #include "gl.h" #include "hires.h" @@ -15,12 +15,11 @@ #include "scene.h" #include "slab.h" #include "terrain.h" +#include "test_game.h" #include "uniform.h" #include "update.h" #include "util.h" #include "window.h" -#include "test_game.h" -#include "chess.h" //#include "rogue/rogue.h" diff --git a/src/chess.h b/src/chess.h @@ -3,7 +3,7 @@ #define POLYADVENT_CHESS_H #include "test_game.h" -#include "game.h" +#include "engine.h" void chess_scene(struct engine *engine, struct test_game *game); diff --git a/src/engine.c b/src/engine.c @@ -0,0 +1,118 @@ + +#include "mat_util.h" +#include "engine.h" +#include "ply.h" +#include "model.h" +#include "terrain.h" +#include "render.h" +#include "util.h" +#include "update.h" +#include "entity.h" +#include "texture.h" +#include "stb_image.h" +#include "skybox.h" +#include "quickhull.h" +#include "poisson.h" +#include "procmesh.h" +#include "util.h" + +#include <assert.h> + +mat4 *cam_init = (float[16]){ + 0.955761, 0.228018, -0.185425, 0.000000, + -0.293528, 0.779583, -0.552437, 0.000000, + 0.018780, 0.580299, 0.802257, 0.000000, + -71.766136, -47.881512, -44.216671, 1.000000 +}; + +bool was_key_pressed_this_frame(struct engine *game, int scancode) +{ + return is_key_down_on_frame(&game->input, scancode, game->frame); +} + +bool was_button_pressed_this_frame(struct engine *game, SDL_GameControllerButton button) +{ + return is_button_down_on_frame(&game->input, button, game->frame); +} + +static void init_user_settings(struct user_settings *settings) { + SDL_SetRelativeMouseMode(SDL_TRUE); + settings->mouse_sens = 0.1; +} + + +static void init_sdl(SDL_Window **window, int width, int height) +{ + SDL_Init( SDL_INIT_JOYSTICK ); + + /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */ + + *window = SDL_CreateWindow("SDL2/OpenGL Demo", 0, 0, width, height, + SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); + + SDL_GL_CreateContext(*window); +} + +void quit_game(struct engine *game) +{ + game->quit = 1; +} + +// TODO: cleanup +void init_misc(struct engine *game) { + game->quit = 0; + game->frame = 0; + game->gpu.num_programs = 0; + +//debug("creating ui...\n"); + //check_gl(); +} + +void init_controller(struct input *input) { + SDL_GameControllerAddMappingsFromFile("data/gamecontrollerdb.txt"); + + int joysticks = SDL_NumJoysticks(); + SDL_GameController *controller = NULL; + + printf("Found %d joysticks\n", joysticks); + + for (int i = 0; i < joysticks; i++) { + if (SDL_IsGameController(i)) { + controller = SDL_GameControllerOpen(i); + if (controller) { + printf("Found a game controller\n"); + input->controller = controller; + break; + } + } else { + printf("Could not open game controller %d: %s\n", i, SDL_GetError()); + } + } +} + +void game_init(struct engine *game, int width, int height) { + game->width = width; + game->height = height; + debug("init sdl...\n"); + init_sdl(&game->window, width, height); + debug("init gl...\n"); + init_gl(); + debug("init entities...\n"); + init_entity_system(); + init_geometry_manager(); + init_model_manager(); + init_node_manager(); + init_user_settings(&game->user_settings); + + check_gl(); + + game->gpu.wireframe = 0; + + init_input(&game->input); + init_controller(&game->input); + //init_controller(&game->input); + debug("init misc...\n"); + init_misc(game); + + printf("gpu programs %d\n", game->gpu.num_programs); +} diff --git a/src/game.h b/src/engine.h diff --git a/src/event.c b/src/event.c @@ -1,6 +0,0 @@ - -#include "event.h" -#include "window.h" -#include "input.h" -#include "game.h" - diff --git a/src/event.h b/src/event.h @@ -1,9 +0,0 @@ - -#ifndef PA_EVENT_H -#define PA_EVENT_H - -#include "gl.h" -#include "input.h" -#include "game.h" - -#endif /* PA_EVENT_H */ diff --git a/src/game.c b/src/game.c @@ -1,118 +0,0 @@ - -#include "mat_util.h" -#include "game.h" -#include "ply.h" -#include "model.h" -#include "terrain.h" -#include "render.h" -#include "util.h" -#include "update.h" -#include "entity.h" -#include "texture.h" -#include "stb_image.h" -#include "skybox.h" -#include "quickhull.h" -#include "poisson.h" -#include "procmesh.h" -#include "util.h" - -#include <assert.h> - -mat4 *cam_init = (float[16]){ - 0.955761, 0.228018, -0.185425, 0.000000, - -0.293528, 0.779583, -0.552437, 0.000000, - 0.018780, 0.580299, 0.802257, 0.000000, - -71.766136, -47.881512, -44.216671, 1.000000 -}; - -bool was_key_pressed_this_frame(struct engine *game, int scancode) -{ - return is_key_down_on_frame(&game->input, scancode, game->frame); -} - -bool was_button_pressed_this_frame(struct engine *game, SDL_GameControllerButton button) -{ - return is_button_down_on_frame(&game->input, button, game->frame); -} - -static void init_user_settings(struct user_settings *settings) { - SDL_SetRelativeMouseMode(SDL_TRUE); - settings->mouse_sens = 0.1; -} - - -static void init_sdl(SDL_Window **window, int width, int height) -{ - SDL_Init( SDL_INIT_JOYSTICK ); - - /* SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); */ - - *window = SDL_CreateWindow("SDL2/OpenGL Demo", 0, 0, width, height, - SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); - - SDL_GL_CreateContext(*window); -} - -void quit_game(struct engine *game) -{ - game->quit = 1; -} - -// TODO: cleanup -void init_misc(struct engine *game) { - game->quit = 0; - game->frame = 0; - game->gpu.num_programs = 0; - -//debug("creating ui...\n"); - //check_gl(); -} - -void init_controller(struct input *input) { - SDL_GameControllerAddMappingsFromFile("data/gamecontrollerdb.txt"); - - int joysticks = SDL_NumJoysticks(); - SDL_GameController *controller = NULL; - - printf("Found %d joysticks\n", joysticks); - - for (int i = 0; i < joysticks; i++) { - if (SDL_IsGameController(i)) { - controller = SDL_GameControllerOpen(i); - if (controller) { - printf("Found a game controller\n"); - input->controller = controller; - break; - } - } else { - printf("Could not open game controller %d: %s\n", i, SDL_GetError()); - } - } -} - -void game_init(struct engine *game, int width, int height) { - game->width = width; - game->height = height; - debug("init sdl...\n"); - init_sdl(&game->window, width, height); - debug("init gl...\n"); - init_gl(); - debug("init entities...\n"); - init_entity_system(); - init_geometry_manager(); - init_model_manager(); - init_node_manager(); - init_user_settings(&game->user_settings); - - check_gl(); - - game->gpu.wireframe = 0; - - init_input(&game->input); - init_controller(&game->input); - //init_controller(&game->input); - debug("init misc...\n"); - init_misc(game); - - printf("gpu programs %d\n", game->gpu.num_programs); -} diff --git a/src/movement.c b/src/movement.c @@ -1,5 +1,5 @@ -#include "game.h" +#include "engine.h" void movement(struct engine *engine, struct node *node, float speed_mult) { diff --git a/src/movement.h b/src/movement.h @@ -1,6 +1,6 @@ #pragma once -#include "game.h" +#include "engine.h" void movement(struct game *game, struct node *node, float speed_mult); void entity_jump(struct entity *ent, float amount); diff --git a/src/render.c b/src/render.c @@ -4,7 +4,7 @@ #include <stdlib.h> #include "gl.h" -#include "game.h" +#include "engine.h" #include "mat4.h" #include "vec3.h" #include "vbo.h" diff --git a/src/scene.h b/src/scene.h @@ -2,6 +2,6 @@ #ifndef SCENE_H #define SCENE_H -#include "game.h" +#include "engine.h" #endif /* SCENE_H */ diff --git a/src/test_game.c b/src/test_game.c @@ -3,7 +3,7 @@ #include "camera.h" #include "entity.h" #include "orbit_util.h" -#include "game.h" +#include "engine.h" #include "node.h" #include "render.h" #include "shader.h" diff --git a/src/test_game.h b/src/test_game.h @@ -8,7 +8,7 @@ #include "skybox.h" #include "orbit.h" #include "gpu.h" -#include "game.h" +#include "engine.h" enum test_game_programs { DEFAULT_PROGRAM, diff --git a/src/update.c b/src/update.c @@ -8,7 +8,7 @@ #include "camera.h" #include "poisson.h" #include "uniform.h" -#include "game.h" +#include "engine.h" #include "mat_util.h" #include "resource.h" #include "shader.h" diff --git a/src/update.h b/src/update.h @@ -2,7 +2,7 @@ #ifndef PA_UPDATE_H #define PA_UPDATE_H -#include "game.h" +#include "engine.h" void update(struct game * game); void gravity(struct entity *ent, float dt); diff --git a/src/window.c b/src/window.c @@ -3,7 +3,7 @@ #include "gl.h" #include "mat4.h" #include "window.h" -#include "game.h" +#include "engine.h" #include "update.h" diff --git a/src/window.h b/src/window.h @@ -3,7 +3,7 @@ #define POLYADVENT_WINDOW_H #include "gl.h" -#include "game.h" +#include "engine.h" void handle_resize(struct engine *game, int width, int height);