Compare commits

...

3 Commits

Author SHA1 Message Date
En Yi bcf80c2913 Test out map of maps 2024-12-29 19:23:07 +08:00
En Yi 03b847cdb3 Update some macro constants 2024-12-29 19:22:54 +08:00
En Yi 23462e6a55 Add README 2024-12-29 17:12:26 +08:00
4 changed files with 72 additions and 15 deletions

12
README.md 100644
View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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;