sw-battle-test-c

Interesting test task in C instead of C++
git clone git://bsandro.tech/sw-battle-test-c
Log | Files | Refs | README

entity.c (654B)


      1 #define STB_DS_IMPLEMENTATION
      2 
      3 #include <string.h>
      4 #include <stdlib.h>
      5 #include <stdio.h>
      6 #include "stb_ds.h"
      7 #include "core/ecs/entity.h"
      8 
      9 Entity * Entity_New(int id) {
     10     Entity *e = malloc(sizeof(Entity));
     11     bzero(e, sizeof(Entity));
     12     e->id = id;
     13     return e;
     14 }
     15 
     16 bool Entity_Add_Component(Entity *e, Component c) {
     17     //printf("%d add component %d\n", e->id, c.type);
     18     arrput(e->components, c);
     19     return true;
     20 }
     21 
     22 Component * Entity_Find_Component(Entity *e, ComponentType t) {
     23     for (int i=0;i<arrlen(e->components);++i) {
     24         if (e->components[i].type==t) {
     25             return &e->components[i];
     26         }
     27     }
     28     return NULL;
     29 }