polyadvent

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

commit 4db80aba976d7495a1d7a38f8af40a35b650e001
parent 3618b5b4fa76c1ec20462bfdc314f69ab56f80b7
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 18 Nov 2018 16:04:10 -0800

wip: scene stuff

Diffstat:
Msrc/entity.c | 3+++
Msrc/entity.h | 3++-
Msrc/game.c | 24++++--------------------
Msrc/ply.c | 4++++
Asrc/scene.c | 43+++++++++++++++++++++++++++++++++++++++++++
5 files changed, 56 insertions(+), 21 deletions(-)

diff --git a/src/entity.c b/src/entity.c @@ -88,6 +88,9 @@ struct entity *add_entity(struct entity *e, struct entity_id *id) { return new; } +void destroy_entity(struct entity *ent) { + +} void destroy_entity_system() { free(esys.entities); diff --git a/src/entity.h b/src/entity.h @@ -26,7 +26,8 @@ struct entity_id { }; struct entity *init_entity(struct entity *); -struct entity *delete_entities(); +void delete_entities(); +void destroy_entity(struct entity *); void init_entity_system(); struct entity *get_entity(struct entity_id *); struct entity *get_all_entities(u32 *count, struct entity_id **ids); diff --git a/src/game.c b/src/game.c @@ -117,6 +117,8 @@ void game_init(struct game *game, int width, int height) { node_init(sun_camera); init_orbit(&res->orbit_camera); + root->label = "root"; + // ENTITIES @@ -129,31 +131,12 @@ void game_init(struct game *game, int width, int height) { node_attach(&player->node, root); node_translate(&player->node, V3(terrain->size/2.,terrain->size/2.,0.0)); + // orbit camera res->orbit_camera.coords.azimuth = -quat_yaw(player->node.orientation) - RAD(90.0); res->orbit_camera.coords.inclination = RAD(60); res->orbit_camera.coords.radius = 5.0; - res->camera_node = &res->orbit_camera.node; - struct entity *tower = new_entity(NULL); - ok = load_model(&tower->model, "tower"); - assert(ok); - tower->node.label = "tower"; - node_attach(&tower->node, &player->node); - node_translate(&tower->node, V3(0.0, 50.0, 0.0)); - node_recalc(&tower->node); - float z = terrain->fn(terrain, tower->node.mat[M_X], tower->node.mat[M_Y]); - node_detach(&tower->node, &player->node); - tower->node.mat[M_Z] = z; - // END ENTITIES - - - // player init - - root->label = "root"; - - input_init(&game->input); - // free camera node_init(&res->free_camera); res->free_camera.label = "free_camera"; @@ -162,6 +145,7 @@ void game_init(struct game *game, int width, int height) { node_rotate(&res->free_camera, V3(100, 0, 0)); node_translate(&res->free_camera, V3(0,-40,20)); + input_init(&game->input); // FBO STUFF init_fbo(&res->shadow_buffer); diff --git a/src/ply.c b/src/ply.c @@ -228,6 +228,10 @@ int parse_ply(const char *filename, struct geometry *geom) { geom->num_verts = nverts * 3; make_buffer_geometry(geom); + free(geom->vertices); + free(geom->normals); + free(geom->colors); + free(geom->indices); } return success; diff --git a/src/scene.c b/src/scene.c @@ -0,0 +1,43 @@ + +#include "game.h" +#include "model.h" +#include <assert.h> + +void reset_scene(struct game *game) { + struct entity *terrain_ent = get_terrain_entity(&game->terrain); + struct entity *player_ent = get_player(&game->test_resources); + + // hide terrain and player by default + terrain_ent->flags |= ENT_INVISIBLE; + player_ent->flags |= ENT_INVISIBLE; +} + +void default_scene(struct game *game) { + struct terrain *terrain = &game->terrain; + struct entity *terrain_ent = get_terrain_entity(terrain); + struct entity *player = get_player(&game->test_resources); + + // show terrain + terrain_ent->flags &= ~ENT_INVISIBLE; + + // show player + player->flags &= ~ENT_INVISIBLE; + + struct entity *tower = new_entity(NULL); + int ok = load_model(&tower->model, "tower"); + assert(ok); + tower->node.label = "tower"; + node_attach(&tower->node, &player->node); + node_translate(&tower->node, V3(0.0, 50.0, 0.0)); + node_recalc(&tower->node); + float z = terrain->fn(terrain, tower->node.mat[M_X], tower->node.mat[M_Y]); + node_detach(&tower->node, &player->node); + tower->node.mat[M_Z] = z; + // END ENTITIES + + +} + +void pbr_scene(struct game *game) { + +}