diff --git a/code/foundation/src/models/components.h b/code/foundation/src/models/components.h index d2f4626..1035909 100644 --- a/code/foundation/src/models/components.h +++ b/code/foundation/src/models/components.h @@ -3,13 +3,13 @@ #include "models/assets.h" #define ecs_get_mut_ex(world, entity, T) \ -(ECS_CAST(T*, world_component_cached(world, entity, ecs_id(T)))) +(ECS_CAST(T*, ecs_get_mut(world, entity, T))) #define ecs_get_if(world, entity, T) \ (world_entity_valid(entity) ? ecs_get(world, entity, T) : NULL) #define ecs_get_mut_if_ex(world, entity, component) \ -(ecs_get_if(world, entity, component) ? ecs_get_mut_ex(world, entity, component) : NULL) +(ecs_get_if(world, entity, component) ? ecs_get_mut(world, entity, component) : NULL) #ifndef ecs_get_mut_if #define ecs_get_mut_if(world, entity, component)\ @@ -69,6 +69,8 @@ typedef struct { float my; float bx; float by; + float hx; + float hy; uint8_t use; uint8_t sprint; uint8_t ctrl; diff --git a/code/foundation/src/models/prefabs/player.c b/code/foundation/src/models/prefabs/player.c index 1e5b985..e5e2cb6 100644 --- a/code/foundation/src/models/prefabs/player.c +++ b/code/foundation/src/models/prefabs/player.c @@ -19,12 +19,14 @@ uint64_t player_spawn(char *name) { ecs_set_name(world_ecs(), e, name); ecs_set(world_ecs(), e, ClientInfo, {0}); - ecs_set(world_ecs(), e, Input, {0}); ecs_set(world_ecs(), e, Inventory, {0}); ecs_set(world_ecs(), e, Health, {.hp = PLAYER_MAX_HP, .max_hp = PLAYER_MAX_HP}); ecs_set(world_ecs(), e, HealthRegen, {.amt = 15.0f}); ecs_set(world_ecs(), e, Velocity, { 0 }); ecs_set(world_ecs(), e, PhysicsBody, { .kind = PHYS_AABB, .mass = INFINITE_MASS }); + Input *i = ecs_get_mut(world_ecs(), e, Input); + *i = (Input){ 0 }; + i->hx = 1.0f; librg_entity_owner_set(world_tracker(), e, (int64_t)e); diff --git a/code/foundation/src/packets/pkt_send_keystate.c b/code/foundation/src/packets/pkt_send_keystate.c index f34ce6d..28d8b17 100644 --- a/code/foundation/src/packets/pkt_send_keystate.c +++ b/code/foundation/src/packets/pkt_send_keystate.c @@ -63,6 +63,8 @@ int32_t pkt_send_keystate_handler(pkt_header *header) { i->y = zpl_clamp(table.y, -1.0f, 1.0f); i->mx = table.mx; i->my = table.my; + i->hx = (i->x != 0.0f) ? i->x : i->hx; + i->hy = (i->y != 0.0f) ? i->y : i->hy; i->use |= table.use; i->sprint = table.sprint; i->ctrl = table.ctrl; diff --git a/code/foundation/src/world/entity_view.c b/code/foundation/src/world/entity_view.c index 0a6f424..eda287c 100644 --- a/code/foundation/src/world/entity_view.c +++ b/code/foundation/src/world/entity_view.c @@ -15,7 +15,9 @@ pkt_desc pkt_entity_view_desc[] = { { PKT_UINT(entity_view, kind) }, { PKT_UINT(entity_view, flag) }, { PKT_HALF(entity_view, x) }, - { PKT_HALF(entity_view, y) }, + { PKT_HALF(entity_view, y) }, + { PKT_HALF(entity_view, hx) }, + { PKT_HALF(entity_view, hy) }, { PKT_HALF(entity_view, angle) }, { PKT_KEEP_IF(entity_view, blocks_used, 0, 2) }, // NOTE(zaklaus): skip velocity for chunks diff --git a/code/foundation/src/world/entity_view.h b/code/foundation/src/world/entity_view.h index 4cfd4bb..16cdb57 100644 --- a/code/foundation/src/world/entity_view.h +++ b/code/foundation/src/world/entity_view.h @@ -53,6 +53,8 @@ typedef struct entity_view { float vy; float tx; float ty; + float hx; + float hy; float angle; float hp; diff --git a/code/foundation/src/world/world.c b/code/foundation/src/world/world.c index 1cd8a64..5ca0ee1 100644 --- a/code/foundation/src/world/world.c +++ b/code/foundation/src/world/world.c @@ -87,6 +87,14 @@ entity_view* world_build_entity_view(int64_t e) { view.frame = spr->frame; } + { + const Input* in = ecs_get(world_ecs(), e, Input); + if (in) { + view.hx = in->hx; + view.hy = in->hy; + } + } + view.inside_vehicle = ecs_get(world_ecs(), e, IsInVehicle) != 0 ? true : false; Inventory* inv = 0; diff --git a/code/games/survival/src/renderer.c b/code/games/survival/src/renderer.c index 7601e62..b6340ba 100644 --- a/code/games/survival/src/renderer.c +++ b/code/games/survival/src/renderer.c @@ -103,7 +103,7 @@ void renderer_draw_entry(uint64_t key, entity_view *data, game_world_render_entr DrawNametag("Player", key, data, x, y-16); //DrawTextureRec(GetSpriteTexture2D(assets_find(ASSET_PLAYER)), ASSET_SRC_RECT(), (Vector2){data->x-(WORLD_BLOCK_SIZE/2), data->y-(WORLD_BLOCK_SIZE/2)}, ColorAlpha(WHITE, data->tran_time)); //DrawCircleEco(x, y, size, ColorAlpha(YELLOW, data->tran_time)); - DrawSpriteEco(test_player_anim.spritesheet, TickSpriteAnimation(&test_player_anim), x, y, 0.0f, 2.0f, WHITE); + DrawSpriteEco(test_player_anim.spritesheet, TickSpriteAnimation(&test_player_anim), x, y, 0.0f, 2.0f, WHITE); //if (data->has_items && !data->inside_vehicle) { // float ix = data->x;