polyadvent

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

test_scene.c (2066B)


      1 
      2 #include "scene.h"
      3 #include "entity.h"
      4 #include "game.h"
      5 #include "debug.h"
      6 #include <assert.h>
      7 
      8 #include <unistd.h>
      9 
     10 
     11 /* #define t_assert(cond, msg) if (cond) { printf(msg); } */
     12 #define t_assert(cond, msg) assert(cond && msg);
     13 
     14 
     15 void delete_every_other_entity()
     16 {
     17     u32 count;
     18     entity_id *ids;
     19 
     20     for (u32 i = RESERVED_ENTITIES; i < 1000; i++) {
     21         get_all_entities(&count, &ids);
     22 
     23         if (i >= count)
     24             return;
     25 
     26         if (i % 2 == 0) {
     27             struct entity *ent = get_entity(&ids[i]); assert(ent);
     28             struct model *pmodel = get_model(&ent->model_id);
     29 
     30             if (pmodel)
     31                 destroy_model(&ent->model_id);
     32             destroy_entity(&ids[i]);
     33         }
     34     }
     35 }
     36 
     37 
     38 int scene_tests(struct game *game) {
     39     struct node *root = get_node(&game->test_resources.root_id);
     40     assert(root);
     41 
     42     u32 ent_count;
     43     int initial_node_count = node_count(root);
     44     reset_scene(game);
     45     t_assert(node_count(root) == initial_node_count,
     46            "scene: node count doesn't match initial after reset_scene");
     47 
     48     get_all_entities(&ent_count, NULL);
     49     t_assert(ent_count == RESERVED_ENTITIES,
     50            "scene: entity count isn't reset after reset_scene");
     51 
     52 
     53     default_scene(game);
     54     get_all_entities(&ent_count, NULL);
     55 
     56     t_assert(ent_count > RESERVED_ENTITIES,
     57            "scene: entity count isn't larger after loading default scene");
     58 
     59     reset_scene(game);
     60     get_all_entities(&ent_count, NULL);
     61     t_assert(ent_count == RESERVED_ENTITIES,
     62            "scene: entity count isn't reset after reset_scene");
     63 
     64     t_assert(node_count(root) == initial_node_count,
     65            "scene: node count doesn't match initial after reset_scene");
     66 
     67     entity_test_scene(game);
     68 
     69     get_all_entities(&ent_count, NULL);
     70     /* assert(ent_count == 102); */
     71 
     72     delete_every_other_entity();
     73 
     74     return 1;
     75 }
     76 
     77 
     78 int main(int argc, char *argv[])
     79 {
     80     struct game game;
     81     int res = chdir("/home/jb55/src/c/polyadvent");
     82     assert(res == 0);
     83     game_init(&game, 1024, 768);
     84     scene_tests(&game);
     85     return 0;
     86 }