add movement component
This commit is contained in:
parent
6fc58d553a
commit
e356fbc67e
@ -2,6 +2,7 @@
|
||||
|
||||
#include "android.h"
|
||||
#include "metamgr.h"
|
||||
#include "movement.h"
|
||||
|
||||
Android::Android()
|
||||
{
|
||||
@ -12,3 +13,8 @@ void Android::Initialize()
|
||||
{
|
||||
health = meta->i->health();
|
||||
}
|
||||
|
||||
void Android::Update(int delta_time)
|
||||
{
|
||||
movement_component->Update(delta_time);
|
||||
}
|
||||
|
@ -8,4 +8,5 @@ class Android : public Human
|
||||
|
||||
Android();
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(int delta_time) override;
|
||||
};
|
||||
|
@ -28,6 +28,7 @@ enum EntitySubType_e
|
||||
};
|
||||
|
||||
class Room;
|
||||
class MovementComponent;
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
@ -38,7 +39,10 @@ class Entity
|
||||
Vector2D pos;
|
||||
Vector2D dir;
|
||||
int updated_times = 0;
|
||||
MovementComponent* movement_component = nullptr;
|
||||
|
||||
Entity() {};
|
||||
virtual ~Entity() {};
|
||||
virtual void Initialize() {};
|
||||
virtual void Update(int delta_time) {};
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) {};
|
||||
|
@ -2,6 +2,18 @@
|
||||
|
||||
#include "human.h"
|
||||
#include "cs_proto.pb.h"
|
||||
#include "movement.h"
|
||||
|
||||
Human::Human()
|
||||
{
|
||||
movement_component = new MovementComponent();
|
||||
}
|
||||
|
||||
Human::~Human()
|
||||
{
|
||||
delete movement_component;
|
||||
movement_component = nullptr;
|
||||
}
|
||||
|
||||
void Human::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
{
|
||||
|
@ -36,6 +36,8 @@ class Human : public Entity
|
||||
std::set<Human*> new_players;
|
||||
std::set<Human*> part_players;
|
||||
|
||||
Human();
|
||||
virtual ~Human() override;
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
|
||||
|
||||
|
8
server/gameserver/movement.cc
Normal file
8
server/gameserver/movement.cc
Normal file
@ -0,0 +1,8 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
void MovementComponent::Update(int delta_time)
|
||||
{
|
||||
|
||||
}
|
11
server/gameserver/movement.h
Normal file
11
server/gameserver/movement.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
class Entity;
|
||||
class MovementComponent
|
||||
{
|
||||
public:
|
||||
Entity* owner = nullptr;
|
||||
int elapsed_time_ = 0;
|
||||
|
||||
virtual void Update(int delta_time);
|
||||
};
|
@ -5,6 +5,7 @@
|
||||
#include "cs_proto.pb.h"
|
||||
#include "room.h"
|
||||
#include "metamgr.h"
|
||||
#include "movement.h"
|
||||
|
||||
const int F_del_objids = 2;
|
||||
const int F_full_objects = 3;
|
||||
@ -34,6 +35,7 @@ void Player::Initialize()
|
||||
|
||||
void Player::Update(int delta_time)
|
||||
{
|
||||
movement_component->Update(delta_time);
|
||||
if (updated_times % 2 == 0) {
|
||||
cs::SMUpdate msg;
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "room.h"
|
||||
#include "android.h"
|
||||
#include "metamgr.h"
|
||||
#include "movement.h"
|
||||
|
||||
const int ROOM_MAX_PLAYER_NUM = 50;
|
||||
|
||||
@ -13,7 +14,7 @@ void Room::Update(int delta_time)
|
||||
{
|
||||
elapsed_time_ += delta_time;
|
||||
while (elapsed_time_ >= 50) {
|
||||
for (auto& pair : uniid_hash_) {
|
||||
for (auto& pair : moveable_hash_) {
|
||||
pair.second->Update(50);
|
||||
pair.second->updated_times++;
|
||||
}
|
||||
@ -57,6 +58,7 @@ void Room::AddPlayer(Player* hum)
|
||||
hum->pos.y = 200 + rand() % 200;
|
||||
hum->room = this;
|
||||
uniid_hash_[hum->entity_uniid] = hum;
|
||||
moveable_hash_[hum->entity_uniid] = hum;
|
||||
accountid_hash_[hum->account_id] = hum;
|
||||
}
|
||||
|
||||
@ -81,5 +83,6 @@ void Room::ShuaAndroid()
|
||||
hum->room = this;
|
||||
hum->Initialize();
|
||||
uniid_hash_[hum->entity_uniid] = hum;
|
||||
moveable_hash_[hum->entity_uniid] = hum;
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,5 @@ public:
|
||||
|
||||
std::map<std::string, Player*> accountid_hash_;
|
||||
std::map<unsigned short, Entity*> uniid_hash_;
|
||||
std::map<unsigned short, Entity*> moveable_hash_;
|
||||
};
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "playermgr.h"
|
||||
#include "app.h"
|
||||
#include "metamgr.h"
|
||||
#include "movement.h"
|
||||
|
||||
void RoomMgr::Init()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user