客户端缓存ok
This commit is contained in:
parent
5c55dc75d2
commit
e4fe7b7006
@ -179,6 +179,17 @@ enum MapObjectType_e
|
||||
kMOT_SpawnPoint = 2
|
||||
};
|
||||
|
||||
enum ObjectFlags_e
|
||||
{
|
||||
kOfWriteCache = 0,
|
||||
kOfReadCache = 1,
|
||||
};
|
||||
|
||||
enum ObjectSyncFlags_e
|
||||
{
|
||||
kOsfIsDead = 0,
|
||||
};
|
||||
|
||||
const char* const PROJ_NAME_FMT = "game%d_gameserver";
|
||||
const char* const PROJ_ROOT_FMT = "/data/logs/%s";
|
||||
|
||||
@ -219,3 +230,4 @@ const int MAX_ALL_HTTP_NUM = MAX_SYS_HTTP_NUM + MAX_USER_HTTP_NUM;
|
||||
const int DEFAULT_BORN_POINT_X = 3000;
|
||||
const int DEFAULT_BORN_POINT_Y = 3000;
|
||||
|
||||
const int FIXED_OBJECT_MAXID = 1024;
|
||||
|
@ -109,3 +109,46 @@ void Entity::AddCollider(ColliderComponent* collider)
|
||||
{
|
||||
colliders.push_back(collider);
|
||||
}
|
||||
|
||||
bool Entity::IsClientCached(Human* hum)
|
||||
{
|
||||
ObjectSyncFlags* sync_flags = hum->GetObjectSyncFlags(GetEntityUniId());
|
||||
if (sync_flags) {
|
||||
int flags = sync_flags->flags;
|
||||
if (IsDead(hum->room)) {
|
||||
if (a8::HasBitFlag(flags, kOsfIsDead)) {
|
||||
return sync_flags->last_sync_frameno > 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!a8::HasBitFlag(flags, kOsfIsDead)) {
|
||||
return sync_flags->last_sync_frameno > 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Entity::CanClientCache(Human* hum)
|
||||
{
|
||||
ObjectSyncFlags* sync_flags = hum->GetObjectSyncFlags(GetEntityUniId());
|
||||
return sync_flags != nullptr;
|
||||
}
|
||||
|
||||
void Entity::AddClientCache(Human* hum)
|
||||
{
|
||||
ObjectSyncFlags* sync_flags = hum->GetObjectSyncFlags(GetEntityUniId());
|
||||
if (sync_flags) {
|
||||
int flags = sync_flags->flags;
|
||||
if (IsDead(hum->room)) {
|
||||
a8::SetBitFlag(flags, kOsfIsDead);
|
||||
} else {
|
||||
a8::UnSetBitFlag(flags, kOsfIsDead);
|
||||
}
|
||||
sync_flags->flags = flags;
|
||||
sync_flags->last_sync_frameno = hum->room->GetFrameNo();
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,13 @@ class Entity
|
||||
void BroadcastFullState();
|
||||
void BroadcastDeleteState();
|
||||
void AddCollider(ColliderComponent* collider);
|
||||
int GetEntityUniId() const { return entity_uniid; }
|
||||
virtual bool IsDead(Room* room) { return dead;};
|
||||
|
||||
protected:
|
||||
bool IsClientCached(Human* hum);
|
||||
bool CanClientCache(Human* hum);
|
||||
void AddClientCache(Human* hum);
|
||||
|
||||
private:
|
||||
std::list<ColliderComponent*> colliders;
|
||||
|
@ -2507,3 +2507,12 @@ void Human::ResetTankSkin()
|
||||
tank_oil_max = 0.0f;
|
||||
RecalcSelfCollider();
|
||||
}
|
||||
|
||||
ObjectSyncFlags* Human::GetObjectSyncFlags(int obj_uniid)
|
||||
{
|
||||
if ((size_t)obj_uniid < fixed_object_sync_flags_.size()) {
|
||||
return &fixed_object_sync_flags_[obj_uniid];
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
@ -218,6 +218,7 @@ class Human : public Entity
|
||||
void OnDie();
|
||||
void FreeDownedTimer();
|
||||
void FreeReviveTimer();
|
||||
ObjectSyncFlags* GetObjectSyncFlags(int obj_uniid);
|
||||
|
||||
protected:
|
||||
void _UpdateMove(int speed);
|
||||
@ -268,6 +269,8 @@ protected:
|
||||
Human* follow_target_ = nullptr;
|
||||
bool follow_synced_active_player = false;
|
||||
|
||||
std::array<ObjectSyncFlags, FIXED_OBJECT_MAXID> fixed_object_sync_flags_ = {};
|
||||
|
||||
private:
|
||||
CircleCollider* self_collider_ = nullptr;
|
||||
long long last_sync_gas_frameno = 0;
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
Player* GetPlayerByAccountId(const std::string& accountid);
|
||||
Player* GetPlayerByUniId(int uniid);
|
||||
Entity* GetEntityByUniId(int uniid);
|
||||
long long GetFrameNo() { return frame_no; }
|
||||
|
||||
void AddPlayer(Player* hum);
|
||||
Human* FindEnemy(Human* hum);
|
||||
|
@ -126,3 +126,11 @@ struct BornPoint
|
||||
|
||||
a8::Vec2 RandPoint() const;
|
||||
};
|
||||
|
||||
#pragma pack(1)
|
||||
struct ObjectSyncFlags
|
||||
{
|
||||
unsigned char flags = 0;
|
||||
unsigned char last_sync_frameno = 0;
|
||||
};
|
||||
#pragma pack()
|
||||
|
Loading…
x
Reference in New Issue
Block a user