-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
100 lines (87 loc) · 2.53 KB
/
main.c
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "scene.h"
#include "file.h"
#include "parse.h"
#include "object.h"
#include "symbol.h"
#include "dlb_memory.h"
#include "dlb_vector.h"
#include "dlb_hash.h"
#include "dlb_arena.h"
#include <stdio.h>
#include <string.h>
#define DLB_MEMORY_IMPLEMENTATION
#include "dlb_memory.h"
#define DLB_VECTOR_IMPLEMENTATION
#include "dlb_vector.h"
#define DLB_HASH_IMPLEMENTATION
#define DLB_HASH_TEST
#include "dlb_hash.h"
#define DLB_ARENA_IMPLEMENTATION
#include "dlb_arena.h"
ta_entity *entity_create(ta_scene *scn, const char *name) {
ta_entity *e = scene_obj_init(scn, F_TA_ENTITY);
e->type = ENTITY_DEFAULT;
e->name = name;
e->transform.position.x = 1.1f;
e->transform.position.y = 1.2f;
e->transform.position.z = 1.3f;
e->transform.rotation.x = 2.1f;
e->transform.rotation.y = 2.2f;
e->transform.rotation.z = 2.3f;
e->transform.rotation.w = 2.4f;
e->transform.scale.x = 3.1f;
e->transform.scale.y = 3.2f;
e->transform.scale.z = 3.3f;
return e;
}
void write_scene(const char *filename) {
ta_scene *scene = scene_init("test scene");
entity_create(scene, "Timmy");
entity_create(scene, "Bobby");
printf("[WRITE: %s]\n", filename);
scene_print(scene, stdout);
printf("\n");
file *data_file = file_open(filename, FILE_WRITE);
scene_print(scene, data_file->hnd);
file_close(data_file);
scene_free(scene);
}
void read_scene(const char *filename) {
file *data_file = file_open(filename, FILE_READ);
ta_scene *scene = scene_load(data_file);
file_close(data_file);
printf("[READ %s]\n", filename);
fprintf(stdout, "---------------------------------\n");
scene_print(scene, stdout);
fprintf(stdout, "---------------------------------\n");
scene_free(scene);
}
void tests() {
parse_tests();
dlb_hash_test();
}
DLB_ASSERT_HANDLER(assert_handler) {
fprintf(stderr,
"\n---[DLB_ASSERT_HANDLER]---------------------------------------------------------\n"
"Source file: %s:%d\n\n"
"%s\n"
"--------------------------------------------------------------------------------\n",
filename, line, expr
);
UNUSED(getchar());
exit(1);
}
int main(int argc, char *argv[]) {
dlb_assert_handler = assert_handler;
tests();
init_symbols();
obj_register();
//const char *filename = "data/scene.dml";
//write_scene(filename);
//read_scene(filename);
const char *filename = "data/custom.dml";
read_scene(filename);
printf("\nfin.\n");
UNUSED(getchar());
return 0;
}