Hi!
I'm trying to setup a basic sparse-set based ECS for game development.
I tried the following approach:
GDOCTestWorld :: struct {
position_components : ecs.ComponentContainer(PositionComponent, MAX_ENTITIES),
velocity_components : ecs.ComponentContainer(VelocityComponent, MAX_ENTITIES),
drawable_components : ecs.ComponentContainer(DrawableComponent, MAX_ENTITIES),
collision_components : ecs.ComponentContainer(CollisionComponent, MAX_ENTITIES),
using base : ecs.World
}
main :: proc() {
world := GDOCTestWorld {}
[...]
}
So, ComponentContainer is a sparse-set and I create and insert the containers manually in a sructure with subtype of ecs.World.
When I run the project, I'm given the following warning: Warning: Declaration of 'world' may cause a stack overflow due to its type 'GDOCTestWorld' having a size of 400096 bytes
Searching here, on discord, I learned that structs area allocated to the stack, so I can see a reason for the warning, so I tried to change my struct, now by using the following approach:
GDOCTestWorld :: struct {
position_components : ^ecs.ComponentContainer(PositionComponent, MAX_ENTITIES),
[...]
}
main :: proc() {
world := GDOCTestWorld {
position_components = new(ecs.ComponentContainer(PositionComponent, MAX_ENTITIES)),
[...]
}
[...]
}
And now it still works, but without the warning.
But, shouldn't pointers be always pointing to something? I didn't create the "something" anywhere... Where are the concrete values the pointer are pointing to?
Am I missing something? Is there a better approach than mine?
I'm not familiar with manually memory management languages, I'm still figuring things out.