Remove entity arms - bad idea

This commit is contained in:
2024-02-07 11:02:06 +01:00
parent 32caeeb995
commit 28ee6da17b
7 changed files with 1 additions and 123 deletions

View File

@@ -29,8 +29,6 @@ ECS_COMPONENT_DECLARE(Animation);
ECS_COMPONENT_DECLARE(Easing); ECS_COMPONENT_DECLARE(Easing);
ECS_COMPONENT_DECLARE(HitBox); ECS_COMPONENT_DECLARE(HitBox);
ECS_COMPONENT_DECLARE(Arms);
ECS_COMPONENT_DECLARE(Arm);
ECS_COMPONENT_DECLARE(BzBTState); ECS_COMPONENT_DECLARE(BzBTState);
ECS_COMPONENT_DECLARE(AIBlackboard); ECS_COMPONENT_DECLARE(AIBlackboard);
@@ -76,8 +74,6 @@ void initComponentIDs(ecs_world_t *ecs) {
ECS_COMPONENT_DEFINE(ecs, Easing); ECS_COMPONENT_DEFINE(ecs, Easing);
ECS_COMPONENT_DEFINE(ecs, HitBox); ECS_COMPONENT_DEFINE(ecs, HitBox);
ECS_COMPONENT_DEFINE(ecs, Arms);
ECS_COMPONENT_DEFINE(ecs, Arm);
ECS_COMPONENT_DEFINE(ecs, BzBTState); ECS_COMPONENT_DEFINE(ecs, BzBTState);
ECS_COMPONENT_DEFINE(ecs, AIBlackboard); ECS_COMPONENT_DEFINE(ecs, AIBlackboard);

View File

@@ -199,30 +199,6 @@ extern ECS_COMPONENT_DECLARE(Easing);
typedef Rectangle HitBox; typedef Rectangle HitBox;
extern ECS_COMPONENT_DECLARE(HitBox); extern ECS_COMPONENT_DECLARE(HitBox);
typedef struct WeaponMelee {
ecs_entity_t weapon;
f32 reach;
f32 damage;
f32 speed;
} WeaponMelee;
typedef struct WeaponRanged {
ecs_entity_t weapon;
int32_t ammo;
} WeaponRanged;
typedef struct WeaponShield {
ecs_entity_t weapon;
} WeaponShield;
typedef struct Arms {
ecs_entity_t primary;
ecs_entity_t secondary;
} Arms;
extern ECS_COMPONENT_DECLARE(Arms);
typedef struct Arm {
f32 offset;
f32 extended;
} Arm;
extern ECS_COMPONENT_DECLARE(Arm);
extern ECS_COMPONENT_DECLARE(BzBTState); extern ECS_COMPONENT_DECLARE(BzBTState);
extern ECS_COMPONENT_DECLARE(AIBlackboard); extern ECS_COMPONENT_DECLARE(AIBlackboard);

View File

@@ -80,18 +80,6 @@ ecs_entity_t entityCreateWorker(const Position position, Player player, Game *ga
.carryCapacity = 5, .carryCapacity = 5,
}); });
ecs_entity_t right = entityCreateEmpty();
Arms arms = {.primary = right};
ecs_set_ptr(ECS, e, Arms, &arms);
ecs_set(ECS, right, Arm, {.offset = 45.0f, 4.5f});
ecs_set(ECS, right, Rotation, { 0.0f });
TextureRegion daggerRegion = {
tileset->tiles,
bzTilesetGetTileRegion(tileset, getItemTile(ITEM_AXE))
};
ecs_set_ptr(ECS, right, TextureRegion, &daggerRegion);
return e; return e;
} }

View File

@@ -507,8 +507,7 @@ static void renderGame(Game *game, float dt) {
.rotation = r[i], .rotation = r[i],
.canHaveAlpha = true, .canHaveAlpha = true,
}; };
if (ecs_has_id(ECS, it.entities[i], ecs_id(Unit)) || if (ecs_has_id(ECS, it.entities[i], ecs_id(Unit))) {
ecs_has_id(ECS, it.entities[i], ecs_id(Arm))) {
Vector2 pos = {dst.x, dst.y}; Vector2 pos = {dst.x, dst.y};
Vec2i cellPos = bzTileMapPosToTile(map, pos); Vec2i cellPos = bzTileMapPosToTile(map, pos);
bzTileMapSetCollisions(map, true, COLL_LAYER_TRANSPARENCY, bzTileMapSetCollisions(map, true, COLL_LAYER_TRANSPARENCY,
@@ -689,8 +688,6 @@ void igInspectWindow(ecs_entity_t entity, bool *open) {
igInspectComp("TextureRegion", entity, ecs_id(TextureRegion), igTextureRegion); igInspectComp("TextureRegion", entity, ecs_id(TextureRegion), igTextureRegion);
igInspectComp("Animation", entity, ecs_id(Animation), igAnimation); igInspectComp("Animation", entity, ecs_id(Animation), igAnimation);
igInspectComp("Easing", entity, ecs_id(Easing), igEasing); igInspectComp("Easing", entity, ecs_id(Easing), igEasing);
igInspectComp("Arms", entity, ecs_id(Arms), igArms);
igInspectComp("Arm", entity, ecs_id(Arm), igArm);
igInspectComp("BzBTState", entity, ecs_id(BzBTState), igBzBTState); igInspectComp("BzBTState", entity, ecs_id(BzBTState), igBzBTState);
igInspectComp("AIBlackboard", entity, ecs_id(AIBlackboard), igAIBlackboard); igInspectComp("AIBlackboard", entity, ecs_id(AIBlackboard), igAIBlackboard);
igInspectComp("Worker", entity, ecs_id(Worker), igWorker); igInspectComp("Worker", entity, ecs_id(Worker), igWorker);

View File

@@ -236,35 +236,6 @@ void entityFollowPath(ecs_iter_t *it) {
} }
} }
static void entityUpdateArm(ecs_entity_t armEntity, Position pos, Velocity vel,
Rotation rot, Orientation orient) {
if (!armEntity) return;
const Arm arm = *ecs_get(ECS, armEntity, Arm);
f32 time = fmod(GetTime() * 2.0f, 2.0f);
if (time > 1.0f) time = 2.0f - time;
f32 velLen = Clamp(Vector2Length(vel), 0, 4.0f) * time;
Vector2 v = {arm.extended, velLen};
v = Vector2Rotate(v, orient + arm.offset);
v = Vector2Add(v, pos);
ecs_set_ptr(ECS, armEntity, Position, &v);
}
void entityUpdateArms(ecs_iter_t *it) {
Position *position = ecs_field(it, Position, 1);
Velocity *velocity = ecs_field(it, Velocity, 2);
Rotation *rotation = ecs_field(it, Rotation, 3);
Orientation *orientation = ecs_field(it, Orientation, 4);
Arms *arms = ecs_field(it, Arms, 5);
for (i32 i = 0; i < it->count; i++) {
entityUpdateArm(arms[i].primary, position[i], velocity[i],
rotation[i], orientation[i]);
entityUpdateArm(arms[i].secondary, position[i], velocity[i],
rotation[i], orientation[i]);
}
}
void renderColliders(ecs_iter_t *it) { void renderColliders(ecs_iter_t *it) {
Position *pos = ecs_field(it, Position, 1); Position *pos = ecs_field(it, Position, 1);
HitBox *hitbox = ecs_field(it, HitBox , 2); HitBox *hitbox = ecs_field(it, HitBox , 2);
@@ -287,16 +258,6 @@ void renderOrientationDirection(ecs_iter_t *it) {
} }
} }
void renderArmPosition(ecs_iter_t *it) {
Position *pos = ecs_field(it, Position, 1);
Arm *arm = ecs_field(it, Arm, 2);
for (i32 i = 0; i < it->count; i++) {
DrawCircle(pos[i].x, pos[i].y, 1.5f, ORANGE);
}
}
void renderDebugPath(ecs_iter_t *it) { void renderDebugPath(ecs_iter_t *it) {
Path *path = ecs_field(it, Path, 1); Path *path = ecs_field(it, Path, 1);

View File

@@ -40,7 +40,6 @@ Vector2 entityGetCenter(Position position, HitBox hitBox) {
ecs_entity_t renderCollidersSystem; ecs_entity_t renderCollidersSystem;
ecs_entity_t renderOrientDirSystem; ecs_entity_t renderOrientDirSystem;
ecs_entity_t renderArmPositionSystem;
ecs_entity_t renderDebugPathSystem; ecs_entity_t renderDebugPathSystem;
ECS_DTOR(SpatialGridID, gridID, { ECS_DTOR(SpatialGridID, gridID, {
@@ -64,21 +63,6 @@ ECS_MOVE(Path, dst, src, {
*dst = *src; *dst = *src;
}) })
ECS_DTOR(Arms, arms, {
if (arms->primary) {
ecs_delete(ECS, arms->primary);
arms->primary = 0;
}
if (arms->secondary) {
ecs_delete(ECS, arms->secondary);
arms->secondary = 0;
}
})
ECS_MOVE(Arms, dst, src, {
*dst = *src;
})
ECS_DTOR(Building, building, { ECS_DTOR(Building, building, {
Vec2i pos = building->pos; Vec2i pos = building->pos;
Vec2i size = building->size; Vec2i size = building->size;
@@ -98,10 +82,6 @@ void setupSystems() {
.dtor = ecs_dtor(Path), .dtor = ecs_dtor(Path),
.move_dtor = ecs_move(Path) .move_dtor = ecs_move(Path)
}); });
ecs_set_hooks(ECS, Arms, {
.dtor = ecs_dtor(Arms),
.move_dtor = ecs_move(Arms)
});
ecs_set_hooks(ECS, Building, { ecs_set_hooks(ECS, Building, {
.dtor = ecs_dtor(Building), .dtor = ecs_dtor(Building),
.move_dtor = ecs_move(Building) .move_dtor = ecs_move(Building)
@@ -123,7 +103,6 @@ void setupSystems() {
ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, Velocity, TargetPosition, Steering); ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, Velocity, TargetPosition, Steering);
ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path); ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path);
ECS_SYSTEM(ECS, entityUpdateArms, EcsOnUpdate, Position, Velocity, Rotation, Orientation, Arms);
ECS_SYSTEM(ECS, resetHarvestCount, EcsOnUpdate, Harvestable); ECS_SYSTEM(ECS, resetHarvestCount, EcsOnUpdate, Harvestable);
ECS_SYSTEM(ECS, updateAISystem, EcsOnUpdate, BzBTState); ECS_SYSTEM(ECS, updateAISystem, EcsOnUpdate, BzBTState);
@@ -136,11 +115,9 @@ void setupSystems() {
ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, HitBox); ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, HitBox);
ECS_SYSTEM(ECS, renderOrientationDirection, EcsOnUpdate, Position, Orientation); ECS_SYSTEM(ECS, renderOrientationDirection, EcsOnUpdate, Position, Orientation);
ECS_SYSTEM(ECS, renderArmPosition, EcsOnUpdate, Position, Arm);
renderDebugPathSystem = renderDebugPath; renderDebugPathSystem = renderDebugPath;
renderOrientDirSystem = renderOrientationDirection; renderOrientDirSystem = renderOrientationDirection;
renderArmPositionSystem = renderArmPosition;
renderCollidersSystem = renderColliders; renderCollidersSystem = renderColliders;
//ecs_enable(ECS, renderOrientDirSystem, false); //ecs_enable(ECS, renderOrientDirSystem, false);

View File

@@ -141,16 +141,6 @@ void entityMoveToTarget(ecs_iter_t *it);
*/ */
void entityFollowPath(ecs_iter_t *it); void entityFollowPath(ecs_iter_t *it);
/*
* 1. Position
* 2. Velocity
* 3. Rotation
* 4. Orientation
* 5. Arms
*/
void entityUpdateArms(ecs_iter_t *it);
/* /*
* 1: Position * 1: Position
* 2: HitBox * 2: HitBox
@@ -163,12 +153,6 @@ void renderColliders(ecs_iter_t *it);
*/ */
void renderOrientationDirection(ecs_iter_t *it); void renderOrientationDirection(ecs_iter_t *it);
/*
* 1. Position
* 2. Arm
*/
void renderArmPosition(ecs_iter_t *it);
/* /*
* 1: Path * 1: Path
*/ */
@@ -230,7 +214,6 @@ Vector2 entityGetCenter(Position position, HitBox hitBox);
extern ecs_entity_t renderCollidersSystem; extern ecs_entity_t renderCollidersSystem;
extern ecs_entity_t renderOrientDirSystem; extern ecs_entity_t renderOrientDirSystem;
extern ecs_entity_t renderArmPositionSystem;
extern ecs_entity_t renderDebugPathSystem; extern ecs_entity_t renderDebugPathSystem;
void setupSystems(); void setupSystems();