Add animations back
This commit is contained in:
@@ -21,8 +21,7 @@ ECS_COMPONENT_DECLARE(Path);
|
|||||||
|
|
||||||
ECS_COMPONENT_DECLARE(TextureRegion);
|
ECS_COMPONENT_DECLARE(TextureRegion);
|
||||||
|
|
||||||
//ECS_COMPONENT_DECLARE(Animation);
|
ECS_COMPONENT_DECLARE(Animation);
|
||||||
//ECS_COMPONENT_DECLARE(AnimationType);
|
|
||||||
|
|
||||||
ECS_TAG_DECLARE(Selectable);
|
ECS_TAG_DECLARE(Selectable);
|
||||||
ECS_TAG_DECLARE(Selected);
|
ECS_TAG_DECLARE(Selected);
|
||||||
@@ -60,8 +59,7 @@ void initComponentIDs(ecs_world_t *ecs) {
|
|||||||
|
|
||||||
ECS_COMPONENT_DEFINE(ecs, TextureRegion);
|
ECS_COMPONENT_DEFINE(ecs, TextureRegion);
|
||||||
|
|
||||||
//ECS_COMPONENT_DEFINE(ecs, Animation);
|
ECS_COMPONENT_DEFINE(ecs, Animation);
|
||||||
//ECS_COMPONENT_DEFINE(ecs, AnimationType);
|
|
||||||
|
|
||||||
ECS_TAG_DEFINE(ecs, Selectable);
|
ECS_TAG_DEFINE(ecs, Selectable);
|
||||||
ECS_TAG_DEFINE(ecs, Selected);
|
ECS_TAG_DEFINE(ecs, Selected);
|
||||||
|
|||||||
@@ -101,23 +101,19 @@ extern ECS_COMPONENT_DECLARE(TextureRegion);
|
|||||||
* Animation components
|
* Animation components
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
|
|
||||||
/*
|
|
||||||
typedef struct Animation {
|
typedef struct Animation {
|
||||||
EntityType entityType;
|
EntityType entityType;
|
||||||
AnimationType animType;
|
AnimType animType;
|
||||||
|
|
||||||
|
AnimationFrame frame;
|
||||||
AnimationSequence sequence;
|
AnimationSequence sequence;
|
||||||
BzTileset *tileset;
|
BzTileset *tileset;
|
||||||
|
|
||||||
i32 curFrame;
|
i32 curFrame;
|
||||||
f32 frameDuration;
|
|
||||||
f32 elapsed;
|
f32 elapsed;
|
||||||
} Animation;
|
} Animation;
|
||||||
extern ECS_COMPONENT_DECLARE(Animation);
|
extern ECS_COMPONENT_DECLARE(Animation);
|
||||||
|
|
||||||
extern ECS_COMPONENT_DECLARE(AnimationType);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct EntityArms {
|
typedef struct EntityArms {
|
||||||
ecs_entity_t left;
|
ecs_entity_t left;
|
||||||
ecs_entity_t right;
|
ecs_entity_t right;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ void terrainRender(BzTileMap *map, BzTileLayer *layer) {
|
|||||||
tile = bzTilesetGetTileID(tileset, tile);
|
tile = bzTilesetGetTileID(tileset, tile);
|
||||||
if (tile != -1) {
|
if (tile != -1) {
|
||||||
if (terrainHasAnimation(tile)) {
|
if (terrainHasAnimation(tile)) {
|
||||||
f32 frameDuration = terrainGetAnimationFrame(tile, 0).duration / 1000.0f;
|
f32 frameDuration = terrainGetAnimationFrame(tile, 0).duration;
|
||||||
i32 numFrames = terrainGetAnimationSequence(tile).frameCount;
|
i32 numFrames = terrainGetAnimationSequence(tile).frameCount;
|
||||||
i32 frameIdx = (i32) (elapsed / frameDuration) % numFrames;
|
i32 frameIdx = (i32) (elapsed / frameDuration) % numFrames;
|
||||||
tile = terrainGetAnimationFrame(tile, frameIdx).frame;
|
tile = terrainGetAnimationFrame(tile, frameIdx).frame;
|
||||||
@@ -174,7 +174,7 @@ bool init(void *userData) {
|
|||||||
ECS_SYSTEM(ECS, entityHarvestTaskSystem, EcsOnUpdate, Position, Rotation, HarvestTask);
|
ECS_SYSTEM(ECS, entityHarvestTaskSystem, EcsOnUpdate, Position, Rotation, HarvestTask);
|
||||||
|
|
||||||
//ECS_SYSTEM(ECS, entityUpdateAnimationState, EcsOnUpdate, Velocity, AnimationType);
|
//ECS_SYSTEM(ECS, entityUpdateAnimationState, EcsOnUpdate, Velocity, AnimationType);
|
||||||
//ECS_SYSTEM(ECS, entityUpdateAnimation, EcsOnUpdate, Animation, TextureRegion);
|
ECS_SYSTEM(ECS, entityUpdateAnimation, EcsOnUpdate, Animation, TextureRegion);
|
||||||
|
|
||||||
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
|
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
|
||||||
|
|
||||||
|
|||||||
@@ -139,14 +139,15 @@ ecs_entity_t createWorker(Position position, Size size, BzSpatialGrid *grid, BzT
|
|||||||
ecs_set(ECS, e, Velocity, {});
|
ecs_set(ECS, e, Velocity, {});
|
||||||
ecs_set(ECS, e, Steering, {});
|
ecs_set(ECS, e, Steering, {});
|
||||||
ecs_set(ECS, e, TextureRegion, {tileset->tiles, bzTilesetGetTileRegion(tileset, gid)});
|
ecs_set(ECS, e, TextureRegion, {tileset->tiles, bzTilesetGetTileRegion(tileset, gid)});
|
||||||
/*
|
|
||||||
ecs_set(ECS, e, Animation, {
|
ecs_set(ECS, e, Animation, {
|
||||||
.entityType = ENTITY_WORKER,
|
.entityType = ENTITY_WORKER,
|
||||||
|
.animType = ANIM_IDLE,
|
||||||
|
|
||||||
|
.sequence = entityGetAnimationSequence(ENTITY_WORKER, ANIM_IDLE),
|
||||||
.tileset = tileset,
|
.tileset = tileset,
|
||||||
.curFrame = 0,
|
.curFrame = 0,
|
||||||
|
.elapsed = 0.0f,
|
||||||
});
|
});
|
||||||
ecs_set(ECS, e, AnimationType, {ANIM_IDLE});
|
|
||||||
*/
|
|
||||||
ecs_add_id(ECS, e, Selectable);
|
ecs_add_id(ECS, e, Selectable);
|
||||||
ecs_add_id(ECS, e, Unit);
|
ecs_add_id(ECS, e, Unit);
|
||||||
ecs_add_id(ECS, e, Worker);
|
ecs_add_id(ECS, e, Worker);
|
||||||
|
|||||||
@@ -288,25 +288,26 @@ void entityUpdateAnimationState(ecs_iter_t *it) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void entityUpdateAnimation(ecs_iter_t *it) {
|
void entityUpdateAnimation(ecs_iter_t *it) {
|
||||||
/*
|
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
Animation *anim = ecs_field(it, Animation, 1);
|
Animation *anim = ecs_field(it, Animation, 1);
|
||||||
TextureRegion *t = ecs_field(it, TextureRegion, 2);
|
TextureRegion *texture = ecs_field(it, TextureRegion, 2);
|
||||||
|
|
||||||
float dt = GetFrameTime();
|
float dt = GetFrameTime();
|
||||||
|
|
||||||
for (i32 i = 0; i < it->count; i++) {
|
for (i32 i = 0; i < it->count; i++) {
|
||||||
anim[i].frameDuration = game->frameDuration;
|
AnimationFrame frame = anim[i].frame;
|
||||||
|
AnimationSequence seq = anim[i].sequence;
|
||||||
|
|
||||||
anim[i].elapsed += dt;
|
anim[i].elapsed += dt;
|
||||||
if (anim[i].elapsed < anim[i].frameDuration) continue;
|
if (anim[i].elapsed < frame.duration) continue;
|
||||||
|
|
||||||
anim[i].curFrame = (anim[i].curFrame + 1) % anim[i].sequence.frameCount;
|
i32 nextFrame = (anim[i].curFrame + 1) % seq.frameCount;
|
||||||
|
anim[i].curFrame = nextFrame;
|
||||||
BzTile tile = anim[i].sequence.startFrame + anim[i].curFrame + anim[i].tileset->startID;
|
anim[i].frame = entityGetAnimationFrame(anim[i].entityType, anim[i].animType, nextFrame);
|
||||||
t[i].rec = bzTilesetGetTileRegion(anim[i].tileset, tile);
|
|
||||||
anim[i].elapsed = 0.0f;
|
anim[i].elapsed = 0.0f;
|
||||||
|
|
||||||
|
texture[i].rec = bzTilesetGetTileRegion(anim[i].tileset, anim[i].frame.frame);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void render(ecs_iter_t *it) {
|
static void render(ecs_iter_t *it) {
|
||||||
|
|||||||
Reference in New Issue
Block a user