Compare commits
3 Commits
849a9f0059
...
bcf80c2913
Author | SHA1 | Date |
---|---|---|
|
bcf80c2913 | |
|
03b847cdb3 | |
|
23462e6a55 |
|
@ -0,0 +1,12 @@
|
|||
# Some Game Engine Version 2
|
||||
|
||||
A continuation of version 1 of the project to learn more about ECS game engine.
|
||||
|
||||
**DISCLAIMER**: There is no obligations tied to this project. For all I know, the project can just get abandoned at anytime. I **WILL** take my time with this project.
|
||||
|
||||
Libraries/Tools used:
|
||||
- _01heap_ \[[link](https://github.com/pavel-kirienko/o1heap)\]: For custom memory allocation. I thought it would be fun to integrate one.
|
||||
- _sc_ \[[link](https://github.com/tezc/sc)\]: For data structures and some basic things. This library is quite easy to use and integrate.
|
||||
- _cc_ \[[link](https://github.com/JacksonAllan/CC)\]: For map and set data structures. _sc_ isn't quite fleshed out in this department, so using this to augment it. It is also easy to use and integrate.
|
||||
- _cmocka_ \[[link](https://cmocka.org/)\] : For unit testing.
|
||||
- _raylib_ \[[link](https://github.com/raysan5/raylib)\] + _raygui_ \[[link](https://github.com/raysan5/raygui)\]: Basically the backbone of the engine.
|
|
@ -2,13 +2,16 @@
|
|||
#define _ENGINE_CONF_H
|
||||
|
||||
#define MEMORY_ARENA_SIZE_MB 16
|
||||
#define MAX_N_COMPONENTS 20
|
||||
#define MAX_ENTITIES 2047
|
||||
#define MAX_COMP_POOL_SIZE MAX_ENTITIES
|
||||
#define INVALID_COMP_IDX MAX_COMP_POOL_SIZE
|
||||
|
||||
// Take care tuning these params. Web build doesn't work
|
||||
// if memory used too high
|
||||
#define MAX_SCENES_TO_RENDER 8
|
||||
#define MAX_RENDER_LAYERS 4
|
||||
#define MAX_RENDERMANAGER_DEPTH 4
|
||||
#define MAX_ENTITIES 2047
|
||||
|
||||
#define MAX_TEXTURES 16
|
||||
#define MAX_SPRITES 127
|
||||
|
@ -21,6 +24,4 @@
|
|||
#define MAX_PARTICLES 32
|
||||
|
||||
#define N_TAGS 10
|
||||
#define N_COMPONENTS 20
|
||||
#define MAX_COMP_POOL_SIZE MAX_ENTITIES
|
||||
#endif // _ENGINE_CONF_H
|
||||
|
|
|
@ -43,7 +43,7 @@ void print_memory_info()
|
|||
|
||||
void* new_component_generic(unsigned int comp_type, unsigned int* idx)
|
||||
{
|
||||
assert(comp_type < N_COMPONENTS);
|
||||
assert(comp_type < MAX_N_COMPONENTS);
|
||||
assert(comp_type < mem_impl.n_components);
|
||||
|
||||
if (cc_size(&mem_impl.comp_mempools[comp_type].free_set) == 0) return NULL;
|
||||
|
@ -72,7 +72,7 @@ void* get_component_generic(unsigned int comp_type, unsigned int idx)
|
|||
|
||||
void free_component_generic(unsigned int comp_type, unsigned int idx)
|
||||
{
|
||||
assert(comp_type < N_COMPONENTS);
|
||||
assert(comp_type < MAX_N_COMPONENTS);
|
||||
// This just free the component from the memory pool
|
||||
assert(comp_type < mem_impl.n_components);
|
||||
if (idx >= mem_impl.comp_mempools->capacity) return;
|
||||
|
|
|
@ -4,22 +4,66 @@
|
|||
|
||||
int main(void) {
|
||||
assert(mem_arena_init(4));
|
||||
printf("Initial\n");
|
||||
mem_arena_print();
|
||||
|
||||
cc_map( int, int ) int_map;
|
||||
cc_init(&int_map);
|
||||
cc_reserve(&int_map, 2048);
|
||||
{
|
||||
printf("Single map\n");
|
||||
cc_map( int, int ) int_map;
|
||||
cc_init(&int_map);
|
||||
cc_reserve(&int_map, 2048);
|
||||
|
||||
cc_insert(&int_map, 1, 4);
|
||||
cc_insert(&int_map, 2, 7);
|
||||
cc_insert(&int_map, 7, 1);
|
||||
cc_insert(&int_map, 4, 8);
|
||||
cc_insert(&int_map, 1, 4);
|
||||
cc_insert(&int_map, 2, 7);
|
||||
cc_insert(&int_map, 7, 1);
|
||||
cc_insert(&int_map, 4, 8);
|
||||
|
||||
mem_arena_print();
|
||||
printf("Insertion\n");
|
||||
mem_arena_print();
|
||||
|
||||
cc_cleanup(&int_map);
|
||||
cc_cleanup(&int_map);
|
||||
|
||||
mem_arena_print();
|
||||
printf("Clean up\n");
|
||||
mem_arena_print();
|
||||
}
|
||||
|
||||
{
|
||||
printf("Map of maps\n");
|
||||
cc_map(int, cc_map(int,int)) map_of_map;
|
||||
cc_init(&map_of_map);
|
||||
cc_reserve(&map_of_map, 32);
|
||||
for (size_t i = 0; i < 10; i += 2) {
|
||||
cc_map(int, int) base_map;
|
||||
cc_init(&base_map);
|
||||
cc_reserve(&base_map, 2048);
|
||||
cc_insert(&map_of_map, i, base_map);
|
||||
}
|
||||
|
||||
cc_map(int, int)* s = cc_get(&map_of_map, 3);
|
||||
printf("get: %p\n", s);
|
||||
s = cc_get(&map_of_map, 2);
|
||||
printf("get: %p\n", s);
|
||||
cc_insert(s, 3, 5);
|
||||
cc_insert(s, 4, 5);
|
||||
cc_insert(s, 2, 5);
|
||||
cc_insert(s, 1, 5);
|
||||
cc_insert(s, 8, 5);
|
||||
|
||||
s = cc_get(&map_of_map, 2);
|
||||
|
||||
int* v = cc_get(s, 2);
|
||||
printf("get: %i\n", *v);
|
||||
mem_arena_print();
|
||||
|
||||
for (size_t i = 0; i < 10; i += 2) {
|
||||
cc_map(int, int)* base_map = cc_get(&map_of_map, i);;
|
||||
cc_cleanup(base_map);
|
||||
}
|
||||
cc_cleanup(&map_of_map);
|
||||
|
||||
printf("Clean up\n");
|
||||
mem_arena_print();
|
||||
}
|
||||
|
||||
mem_arena_deinit();
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue