entity add initialize function
This commit is contained in:
parent
971bc22b85
commit
6fc58d553a
@ -1,3 +1,14 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
#include "android.h"
|
#include "android.h"
|
||||||
|
#include "metamgr.h"
|
||||||
|
|
||||||
|
Android::Android()
|
||||||
|
{
|
||||||
|
entity_subtype = EST_Android;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Android::Initialize()
|
||||||
|
{
|
||||||
|
health = meta->i->health();
|
||||||
|
}
|
||||||
|
@ -4,5 +4,8 @@
|
|||||||
|
|
||||||
class Android : public Human
|
class Android : public Human
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Android();
|
||||||
|
virtual void Initialize() override;
|
||||||
};
|
};
|
||||||
|
@ -20,17 +20,26 @@ enum EntityType_e
|
|||||||
ET_Smoke = 9
|
ET_Smoke = 9
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum EntitySubType_e
|
||||||
|
{
|
||||||
|
EST_None = 0,
|
||||||
|
EST_Player = 1,
|
||||||
|
EST_Android = 2,
|
||||||
|
};
|
||||||
|
|
||||||
class Room;
|
class Room;
|
||||||
class Entity
|
class Entity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unsigned short entity_uniid = 0;
|
unsigned short entity_uniid = 0;
|
||||||
EntityType_e entity_type = ET_None;
|
EntityType_e entity_type = ET_None;
|
||||||
|
EntitySubType_e entity_subtype = EST_None;
|
||||||
Room* room = nullptr;
|
Room* room = nullptr;
|
||||||
Vector2D pos;
|
Vector2D pos;
|
||||||
Vector2D dir;
|
Vector2D dir;
|
||||||
int updated_times = 0;
|
int updated_times = 0;
|
||||||
|
|
||||||
|
virtual void Initialize() {};
|
||||||
virtual void Update(int delta_time) {};
|
virtual void Update(int delta_time) {};
|
||||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) {};
|
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) {};
|
||||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) {};
|
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) {};
|
||||||
|
@ -2,10 +2,16 @@
|
|||||||
|
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
|
|
||||||
|
namespace MetaData
|
||||||
|
{
|
||||||
|
struct Player;
|
||||||
|
}
|
||||||
|
|
||||||
class Human : public Entity
|
class Human : public Entity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string team_uniid;
|
std::string team_uniid;
|
||||||
|
MetaData::Player* meta = nullptr;
|
||||||
|
|
||||||
float health = 0.0;
|
float health = 0.0;
|
||||||
bool dead = false;
|
bool dead = false;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "cs_proto.pb.h"
|
#include "cs_proto.pb.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
#include "metamgr.h"
|
||||||
|
|
||||||
const int F_del_objids = 2;
|
const int F_del_objids = 2;
|
||||||
const int F_full_objects = 3;
|
const int F_full_objects = 3;
|
||||||
@ -21,6 +22,16 @@ const int F_explosions = 22;
|
|||||||
const int F_emotes = 23;
|
const int F_emotes = 23;
|
||||||
const int F_ack = 24;
|
const int F_ack = 24;
|
||||||
|
|
||||||
|
Player::Player()
|
||||||
|
{
|
||||||
|
entity_subtype = EST_Player;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::Initialize()
|
||||||
|
{
|
||||||
|
health = meta->i->health();
|
||||||
|
}
|
||||||
|
|
||||||
void Player::Update(int delta_time)
|
void Player::Update(int delta_time)
|
||||||
{
|
{
|
||||||
if (updated_times % 2 == 0) {
|
if (updated_times % 2 == 0) {
|
||||||
|
@ -34,6 +34,8 @@ class Player : public Human
|
|||||||
GGListener::Instance()->SendToClient(socket_handle, 0, msg);
|
GGListener::Instance()->SendToClient(socket_handle, 0, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player();
|
||||||
|
virtual void Initialize() override;
|
||||||
virtual void Update(int delta_time) override;
|
virtual void Update(int delta_time) override;
|
||||||
|
|
||||||
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
void _CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg);
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "cs_proto.pb.h"
|
#include "cs_proto.pb.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
#include "android.h"
|
||||||
|
#include "metamgr.h"
|
||||||
|
|
||||||
const int ROOM_MAX_PLAYER_NUM = 50;
|
const int ROOM_MAX_PLAYER_NUM = 50;
|
||||||
|
|
||||||
@ -38,7 +40,10 @@ Player* Room::GetPlayerByAccountId(const std::string& accountid)
|
|||||||
Player* Room::GetPlayerByUniId(unsigned short uniid)
|
Player* Room::GetPlayerByUniId(unsigned short uniid)
|
||||||
{
|
{
|
||||||
auto itr = uniid_hash_.find(uniid);
|
auto itr = uniid_hash_.find(uniid);
|
||||||
return itr != uniid_hash_.end() ? itr->second : nullptr;
|
return itr != uniid_hash_.end() &&
|
||||||
|
itr->second->entity_type == ET_Player &&
|
||||||
|
itr->second->entity_subtype == EST_Player ?
|
||||||
|
(Player*)itr->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Room::AliveCount()
|
int Room::AliveCount()
|
||||||
@ -59,3 +64,22 @@ unsigned short Room::AllocUniid()
|
|||||||
{
|
{
|
||||||
return ++current_uniid;
|
return ++current_uniid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Room::ShuaAndroid()
|
||||||
|
{
|
||||||
|
MetaData::Player* hum_meta = MetaMgr::Instance()->GetPlayer(40002);
|
||||||
|
assert(hum_meta);
|
||||||
|
if (!hum_meta) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 30; ++i) {
|
||||||
|
Android* hum = new Android();
|
||||||
|
hum->meta = hum_meta;
|
||||||
|
hum->entity_uniid = AllocUniid();
|
||||||
|
hum->pos.x = 100 + rand() % 400;
|
||||||
|
hum->pos.y = 200 + rand() % 500;
|
||||||
|
hum->room = this;
|
||||||
|
hum->Initialize();
|
||||||
|
uniid_hash_[hum->entity_uniid] = hum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,6 +12,7 @@ namespace MetaData
|
|||||||
struct Map;
|
struct Map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Entity;
|
||||||
class Player;
|
class Player;
|
||||||
class Room
|
class Room
|
||||||
{
|
{
|
||||||
@ -27,6 +28,7 @@ public:
|
|||||||
Player* GetPlayerByUniId(unsigned short uniid);
|
Player* GetPlayerByUniId(unsigned short uniid);
|
||||||
void AddPlayer(Player* hum);
|
void AddPlayer(Player* hum);
|
||||||
unsigned short AllocUniid();
|
unsigned short AllocUniid();
|
||||||
|
void ShuaAndroid();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned short current_uniid = 0;
|
unsigned short current_uniid = 0;
|
||||||
@ -34,5 +36,5 @@ public:
|
|||||||
int elapsed_time_ = 0;
|
int elapsed_time_ = 0;
|
||||||
|
|
||||||
std::map<std::string, Player*> accountid_hash_;
|
std::map<std::string, Player*> accountid_hash_;
|
||||||
std::map<unsigned short, Player*> uniid_hash_;
|
std::map<unsigned short, Entity*> uniid_hash_;
|
||||||
};
|
};
|
||||||
|
@ -28,6 +28,11 @@ void RoomMgr::Update(int delta_time)
|
|||||||
|
|
||||||
void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||||
{
|
{
|
||||||
|
MetaData::Player* hum_meta = MetaMgr::Instance()->GetPlayer(40001);
|
||||||
|
assert(hum_meta);
|
||||||
|
if (!hum_meta) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
Room* room = GetJoinableRoom(msg.account_id());
|
Room* room = GetJoinableRoom(msg.account_id());
|
||||||
if (!room) {
|
if (!room) {
|
||||||
room = new Room();
|
room = new Room();
|
||||||
@ -37,11 +42,14 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
room->map_meta = MetaMgr::Instance()->GetMap(1001);
|
room->map_meta = MetaMgr::Instance()->GetMap(1001);
|
||||||
|
room->ShuaAndroid();
|
||||||
room_hash_[room->room_uuid] = room;
|
room_hash_[room->room_uuid] = room;
|
||||||
}
|
}
|
||||||
unsigned short new_uniid = room->AllocUniid();
|
unsigned short new_uniid = room->AllocUniid();
|
||||||
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(new_uniid, msg);
|
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(new_uniid, msg);
|
||||||
|
hum->meta = hum_meta;
|
||||||
hum->socket_handle = hdr.socket_handle;
|
hum->socket_handle = hdr.socket_handle;
|
||||||
|
hum->Initialize();
|
||||||
room->AddPlayer(hum);
|
room->AddPlayer(hum);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user