Compare commits

..

No commits in common. "bcf80c29138e88273a76b1ca4dc71dada702d3cb" and "849a9f0059a367df47cf99ede638f74fcab613ae" have entirely different histories.

4 changed files with 15 additions and 72 deletions

View File

@ -1,12 +0,0 @@
# 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.

View File

@ -2,16 +2,13 @@
#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
@ -24,4 +21,6 @@
#define MAX_PARTICLES 32
#define N_TAGS 10
#define N_COMPONENTS 20
#define MAX_COMP_POOL_SIZE MAX_ENTITIES
#endif // _ENGINE_CONF_H

View File

@ -43,7 +43,7 @@ void print_memory_info()
void* new_component_generic(unsigned int comp_type, unsigned int* idx)
{
assert(comp_type < MAX_N_COMPONENTS);
assert(comp_type < 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 < MAX_N_COMPONENTS);
assert(comp_type < 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;

View File

@ -4,66 +4,22 @@
int main(void) {
assert(mem_arena_init(4));
printf("Initial\n");
mem_arena_print();
{
printf("Single map\n");
cc_map( int, int ) int_map;
cc_init(&int_map);
cc_reserve(&int_map, 2048);
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);
printf("Insertion\n");
mem_arena_print();
mem_arena_print();
cc_cleanup(&int_map);
cc_cleanup(&int_map);
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_print();
mem_arena_deinit();
return 0;