Rework input

This commit is contained in:
2023-12-07 14:19:10 +01:00
parent d3485303c9
commit 8543cc7b43
6 changed files with 220 additions and 122 deletions

View File

@@ -11,7 +11,6 @@ extern ECS_TAG_DECLARE(TextureTerrain);
extern ECS_TAG_DECLARE(TextureBuildings);
extern ECS_TAG_DECLARE(TextureEntities);
extern ECS_TAG_DECLARE(UnitSelected);
typedef enum ResourceType {
RES_IRON,
@@ -21,6 +20,16 @@ typedef enum ResourceType {
RES_COUNT,
} ResourceType;
static const char *getResourceTypePrettyName(ResourceType type) {
switch (type) {
case RES_IRON: return "Iron";
case RES_WOOD: return "Wood";
case RES_GOLD: return "Gold";
case RES_FOOD: return "Food";
default: return "Invalid";
}
}
typedef struct Resource {
ResourceType type;
i32 amount;
@@ -44,39 +53,24 @@ typedef struct Owner {
} Owner;
extern ECS_COMPONENT_DECLARE(Owner);
/**********************************************************
* Movement components
*********************************************************/
typedef BzSpatialGridID SpatialGridID;
extern ECS_COMPONENT_DECLARE(SpatialGridID);
typedef Vector2 Position, Size, Velocity, TargetPosition, Steering;
typedef f32 Rotation;
extern ECS_COMPONENT_DECLARE(Position);
extern ECS_COMPONENT_DECLARE(Size);
extern ECS_COMPONENT_DECLARE(Velocity);
extern ECS_COMPONENT_DECLARE(TargetPosition);
extern ECS_COMPONENT_DECLARE(Steering);
typedef f32 Rotation;
extern ECS_COMPONENT_DECLARE(Rotation);
typedef struct TextureRegion {
Texture2D texture;
Rectangle rec;
f32 rotation;
bool flipX : 1;
bool flipY : 1;
} TextureRegion;
extern ECS_COMPONENT_DECLARE(TextureRegion);
typedef struct Animation {
EntityType entityType;
AnimationType animType;
AnimationSequence sequence;
BzTileset *tileset;
i32 curFrame;
f32 frameDuration;
f32 elapsed;
} Animation;
extern ECS_COMPONENT_DECLARE(Animation);
extern ECS_COMPONENT_DECLARE(AnimationType);
extern ECS_COMPONENT_DECLARE(Steering);
extern ECS_COMPONENT_DECLARE(TargetPosition);
#define PATH_DATA_SIZE 8
typedef struct PathData {
@@ -91,12 +85,66 @@ typedef struct Path {
} Path;
extern ECS_COMPONENT_DECLARE(Path);
/**********************************************************
* Render components
*********************************************************/
typedef struct TextureRegion {
Texture2D texture;
Rectangle rec;
f32 rotation;
bool flipX : 1;
bool flipY : 1;
} TextureRegion;
extern ECS_COMPONENT_DECLARE(TextureRegion);
/**********************************************************
* Animation components
*********************************************************/
typedef struct Animation {
EntityType entityType;
AnimationType animType;
AnimationSequence sequence;
BzTileset *tileset;
i32 curFrame;
f32 frameDuration;
f32 elapsed;
} Animation;
extern ECS_COMPONENT_DECLARE(Animation);
extern ECS_COMPONENT_DECLARE(AnimationType);
typedef struct EntityArms {
ecs_entity_t left;
ecs_entity_t right;
} EntityArms;
//extern ECS_COMPONENT_DECLARE(EntityArms);
/**********************************************************
* Gameplay components
*********************************************************/
extern ECS_TAG_DECLARE(Selectable);
extern ECS_TAG_DECLARE(Selected);
// Unit can:
// - Attack
extern ECS_TAG_DECLARE(Unit);
// Worker can:
// - Harvest
// - Build
// - Work
// - Attack (since it is also a unit)
extern ECS_TAG_DECLARE(Worker);
extern ECS_TAG_DECLARE(Harvestable);
extern ECS_TAG_DECLARE(Buildable);
extern ECS_TAG_DECLARE(Workable);
extern ECS_TAG_DECLARE(Attackable);
void initComponentIDs(ecs_world_t *ecs);