test_scene.c (2054B)
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 = 0; 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 == 0, 50 "scene: entity count isn't reset after reset_scene"); 51 52 default_scene(game); 53 get_all_entities(&ent_count, NULL); 54 55 t_assert(ent_count > 0, 56 "scene: entity count isn't larger after loading default scene"); 57 58 reset_scene(game); 59 get_all_entities(&ent_count, NULL); 60 t_assert(ent_count == 0, 61 "scene: entity count isn't reset after reset_scene"); 62 63 t_assert(node_count(root) == initial_node_count, 64 "scene: node count doesn't match initial after reset_scene"); 65 66 struct terrain *terrain = NULL; 67 entity_test_scene(game, terrain); 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 engine engine; 81 int res = chdir("/home/jb55/src/c/polyadvent"); 82 assert(res == 0); 83 game_init(&engine, 1024, 768); 84 scene_tests(&engine); 85 return 0; 86 }