Use component for unit selection
This commit is contained in:
14
game/main.c
14
game/main.c
@@ -71,7 +71,11 @@ bool init(void *userData) {
|
||||
input->ESC = KEY_ESCAPE;
|
||||
input->CLICK_LIMIT = 0.2f;
|
||||
|
||||
input->entities = bzArrayCreate(ecs_entity_t, 16);
|
||||
input->unitSelectedQuery = ecs_query(ECS, {
|
||||
.filter.terms = {
|
||||
{ ecs_id(Position) }, { ecs_id(Size) }, { ecs_id(UnitSelected) }
|
||||
}
|
||||
});
|
||||
input->unitPositions = bzArrayCreate(Position, 16);
|
||||
|
||||
|
||||
@@ -178,7 +182,6 @@ void deinit(void *userData) {
|
||||
ecs_fini(ECS);
|
||||
ECS = NULL;
|
||||
|
||||
bzArrayDestroy(inputCopy.entities);
|
||||
bzArrayDestroy(inputCopy.unitPositions);
|
||||
bzObjectPoolDestroy(gameCopy.pools.pathData);
|
||||
bzSpatialGridDestroy(gameCopy.entityGrid);
|
||||
@@ -249,8 +252,11 @@ void imguiRender(float dt, void *userData) {
|
||||
switch (input->state) {
|
||||
case INPUT_SELECTED_UNITS:
|
||||
igText("Selected units:");
|
||||
for (i32 i = 0; i < bzArraySize(input->entities); i++) {
|
||||
igText("\t%llu", bzArrayGet(input->entities, i));
|
||||
ecs_iter_t it = ecs_query_iter(ECS, input->unitSelectedQuery);
|
||||
while (ecs_iter_next(&it)) {
|
||||
for (i32 i = 0; i < it.count; i++) {
|
||||
igText("\t%llu", it.entities[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case INPUT_SELECTED_OBJECT:
|
||||
|
||||
Reference in New Issue
Block a user