13#include <unordered_map>
145 const std::string ¤tAnimation,
int srcX,
int srcY,
int srcW,
int srcH,
146 float velocityX = 0.0f,
float velocityY = 0.0f, uint32_t serverTick = 0);
174 void setBackground(
const std::string &mainBackground,
const std::string ¶llaxBackground,
175 float scrollSpeed,
float parallaxSpeedFactor);
326 void renderPlayer(
const RenderableEntity &entity,
bool isLocalPlayer);
344 void renderWall(
const RenderableEntity &entity);
388 [[nodiscard]]
float lerp(
float start,
float end,
float t)
const;
397 [[nodiscard]]
float clamp(
float value,
float min,
float max)
const;
406 std::unordered_map<uint32_t, RenderableEntity>
_entities;
Specialized renderer for game entities with client-side interpolation.
void moveEntityLocally(uint32_t entityId, float deltaX, float deltaY)
Move an entity locally (client-side prediction)
float _interpolationSpeed
std::unordered_map< uint32_t, RenderableEntity > _entities
Entity cache: maps entity ID to its renderable state.
void renderHealthBar(float x, float y, int health, int maxHealth)
Render a health bar above an entity.
void setInterpolationSpeed(float speed)
Set the interpolation speed multiplier.
void setLocalPlayerMoving(bool moving)
Set whether the local player is currently moving.
void setMyEntityId(uint32_t id)
Set the local player's entity ID for visual differentiation.
void renderOrbitalModule(const RenderableEntity &entity)
Render an orbital module (drone)
void renderBackground()
Render scrolling background layers.
BackgroundConfig _mainBackground
Main background layer (scrolls at map's scroll speed)
void removeEntity(uint32_t id)
Remove an entity from the rendering cache.
Graphics::RaylibGraphics & _graphics
Reference to graphics subsystem for drawing operations.
void renderProjectile(const RenderableEntity &entity)
Render a projectile (player or enemy bullet)
void renderWall(const RenderableEntity &entity)
Render a wall/obstacle.
void renderDebugInfo(const RenderableEntity &entity)
Render debug information for an entity.
uint64_t getCurrentTimeMs() const
Get current time in milliseconds.
void clearBackground()
Clear background configuration.
~EntityRenderer()=default
Destructor.
bool _localPlayerIsMoving
Track whether local player is currently moving (used for reconciliation logic)
void updateBackground(float deltaTime)
Update background scroll positions.
float _reconciliationThreshold
void setBackground(const std::string &mainBackground, const std::string ¶llaxBackground, float scrollSpeed, float parallaxSpeedFactor)
Set up background layers for parallax scrolling.
void setInterpolationEnabled(bool enabled)
Enable or disable interpolation for smooth movement.
uint32_t _myEntityId
Local player's entity ID (for visual differentiation)
bool _clientSidePredictionEnabled
Client-side prediction enabled flag (for local player only)
void renderPlayer(const RenderableEntity &entity, bool isLocalPlayer)
Render a player entity.
void updateEntity(uint32_t id, RType::Messages::Shared::EntityType type, float x, float y, int health, const std::string ¤tAnimation, int srcX, int srcY, int srcW, int srcH, float velocityX=0.0f, float velocityY=0.0f, uint32_t serverTick=0)
Update or create an entity in the local cache.
void setDebugMode(bool enabled)
Toggle debug information overlay.
void setClientSidePredictionEnabled(bool enabled)
Enable or disable client-side prediction for local player.
float lerp(float start, float end, float t) const
Linear interpolation between two values.
float clamp(float value, float min, float max) const
Clamp a value between min and max.
size_t getEntityCount() const
Get the number of entities currently cached.
bool _interpolationEnabled
Interpolation enabled flag.
void updateInterpolation(float deltaTime)
Update interpolation for all entities.
bool hasEntity(uint32_t id) const
Check if an entity exists in the cache.
void clearAllEntities()
Clear all entities from the cache.
bool _backgroundActive
Whether backgrounds are configured and active.
float getReconciliationThreshold() const
Get the current reconciliation threshold.
void render()
Render all cached entities.
void renderEnemy(const RenderableEntity &entity)
Render an enemy entity.
bool _showDebugInfo
Debug mode: show entity IDs and health bars (toggle with F3)
void setReconciliationThreshold(float threshold)
Set the reconciliation threshold for client-side prediction.
BackgroundConfig _parallaxBackground
Parallax background layer (rendered on top, scrolls slower for depth effect)
Raylib implementation of the IGraphics interface.
EntityType
Entity type enum - matches Cap'n Proto enum.
Configuration for scrolling parallax backgrounds.
int textureHeight
Texture height for tiling.
float scrollOffset
Current scroll offset (updates each frame)
bool loaded
Whether texture is loaded.
std::string textureName
Texture name (loaded texture)
int textureWidth
Texture width for tiling.
std::string texturePath
Asset path for texture loading.
float scrollSpeed
Scroll speed in pixels/second.
A single state snapshot with timestamp for time-based interpolation.
uint64_t timestamp
Local timestamp when received (milliseconds)
uint32_t serverTick
Server tick number.
float velocityX
Velocity X (for extrapolation)
float velocityY
Velocity Y (for extrapolation)
Cached entity state for rendering.
float interpolationFactor
Progress from 0.0 (prev) to 1.0 (target) (DEPRECATED)
int spriteSizeY
Sprite sheet size Y.
uint32_t entityId
Unique entity identifier.
int startPixelX
Sprite sheet start pixel X.
int offsetY
Sprite offset Y for rendering.
float prevY
Previous position Y (DEPRECATED)
float scale
Sprite scale multiplier.
float targetX
Target position X (DEPRECATED)
float targetY
Target position Y (DEPRECATED)
int offsetX
Sprite offset X for rendering.
float prevX
Previous position X (DEPRECATED)
float x
Current rendered position X.
std::string currentAnimation
Current animation name from server.
bool extrapolationEnabled
Allow extrapolation beyond last snapshot.
int health
Current health (-1 for entities without health)
int spriteSizeX
Sprite sheet size X.
std::deque< Snapshot > snapshots
Recent snapshots (max 3)
RType::Messages::Shared::EntityType type
Entity type (Player, Enemy, Bullet, etc.)
int currentFrame
Current animation frame.
std::vector< int > animationFrameIndices
Animation frame sequence (sprite indices to allow freedom of picking frames manually)
uint64_t interpolationDelay
Time to look back for interpolation (ms)
int startPixelY
Sprite sheet start pixel Y.
float y
Current rendered position Y.