This commit is contained in:
Aria 2025-03-21 22:23:30 +11:00
commit 9c94d113d3
Signed by untrusted user who does not match committer: aria
GPG key ID: 19AB7AA462B8AB3B
10260 changed files with 1237388 additions and 0 deletions

View file

@ -0,0 +1,60 @@
#ifndef STAR_WORLD_CLIENT_STATE_HPP
#define STAR_WORLD_CLIENT_STATE_HPP
#include "StarRect.hpp"
#include "StarNetElementSystem.hpp"
#include "StarGameTypes.hpp"
namespace Star {
STAR_CLASS(WorldClientState);
// Class to aid in network syncronization of client state such as viewing area
// and player entity id.
class WorldClientState {
public:
WorldClientState();
// Actual area of the client visible screen (rounded to nearest block)
RectI window() const;
void setWindow(RectI const& window);
// Shortcut to find the window center of the client.
Vec2F windowCenter() const;
// Entity of the unique main Player for this client
EntityId playerId() const;
void setPlayer(EntityId playerId);
// Entities that should contribute to the monitoring regions of the client.
List<EntityId> const& clientPresenceEntities() const;
void setClientPresenceEntities(List<EntityId> entities);
// All areas of the server monitored by the client, takes a function to
// resolve an entity id to its bound box.
List<RectI> monitoringRegions(function<Maybe<RectI>(EntityId)> entityBounds) const;
ByteArray writeDelta();
void readDelta(ByteArray delta);
void reset();
private:
int m_windowMonitoringBorder;
int m_presenceEntityMonitoringBorder;
NetElementTopGroup m_netGroup;
uint64_t m_netVersion;
NetElementInt m_windowXMin;
NetElementInt m_windowYMin;
NetElementInt m_windowWidth;
NetElementInt m_windowHeight;
NetElementInt m_playerId;
NetElementData<List<EntityId>> m_clientPresenceEntities;
};
}
#endif