~jb55/polyadvent

ref: 4963791592f8b1f6ea91a6121bc5fc8f54cca279 polyadvent/test/test_scene.c -rw-r--r-- 2.0 KiB
49637915William Casarin lots of stuff 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "scene.h"
#include "entity.h"
#include "game.h"
#include "debug.h"
#include <assert.h>

#include <unistd.h>


/* #define t_assert(cond, msg) if (cond) { printf(msg); } */
#define t_assert(cond, msg) assert(cond && msg);


void delete_every_other_entity()
{
    u32 count;
    entity_id *ids;

    for (u32 i = RESERVED_ENTITIES; i < 1000; i++) {
        get_all_entities(&count, &ids);

        if (i >= count)
            return;

        if (i % 2 == 0) {
            struct entity *ent = get_entity(&ids[i]); assert(ent);
            struct model *pmodel = get_model(&ent->model_id);

            if (pmodel)
                destroy_model(&ent->model_id);
            destroy_entity(&ids[i]);
        }
    }
}


int scene_tests(struct game *game) {
    struct node *root = get_node(&game->test_resources.root_id);
    assert(root);

    u32 ent_count;
    int initial_node_count = node_count(root);
    reset_scene(game);
    t_assert(node_count(root) == initial_node_count,
           "scene: node count doesn't match initial after reset_scene");

    get_all_entities(&ent_count, NULL);
    t_assert(ent_count == RESERVED_ENTITIES,
           "scene: entity count isn't reset after reset_scene");


    default_scene(game);
    get_all_entities(&ent_count, NULL);

    t_assert(ent_count > RESERVED_ENTITIES,
           "scene: entity count isn't larger after loading default scene");

    reset_scene(game);
    get_all_entities(&ent_count, NULL);
    t_assert(ent_count == RESERVED_ENTITIES,
           "scene: entity count isn't reset after reset_scene");

    t_assert(node_count(root) == initial_node_count,
           "scene: node count doesn't match initial after reset_scene");

    entity_test_scene(game);

    get_all_entities(&ent_count, NULL);
    /* assert(ent_count == 102); */

    delete_every_other_entity();

    return 1;
}


int main(int argc, char *argv[])
{
    struct game game;
    int res = chdir("/home/jb55/src/c/polyadvent");
    assert(res == 0);
    game_init(&game, 1024, 768);
    scene_tests(&game);
    return 0;
}