添加房间逻辑
This commit is contained in:
parent
8d354d2ad2
commit
3fdfc92394
@ -0,0 +1,71 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "building.h"
|
||||
#include "metamgr.h"
|
||||
#include "movement.h"
|
||||
#include "room.h"
|
||||
#include "collider.h"
|
||||
#include "obstacle.h"
|
||||
#include "human.h"
|
||||
|
||||
Building::Building():Entity()
|
||||
{
|
||||
entity_type = ET_Building;
|
||||
}
|
||||
|
||||
Building::~Building()
|
||||
{
|
||||
}
|
||||
|
||||
void Building::Initialize()
|
||||
{
|
||||
RecalcSelfCollider();
|
||||
}
|
||||
|
||||
void Building::RecalcSelfCollider()
|
||||
{
|
||||
for (auto& obj : meta->i->staticobj()) {
|
||||
AabbCollider* collider = new AabbCollider();
|
||||
collider->owner = this;
|
||||
collider->_min = Vector2D(obj.x() - obj.width()/2.0 - meta->i->tilewidth()/2.0,
|
||||
obj.y() - obj.height()/2.0 - meta->i->tileheight()/2.0);
|
||||
collider->_max = Vector2D(obj.x() + obj.width()/2.0 - meta->i->tilewidth()/2.0,
|
||||
obj.y() + obj.height()/2.0 - meta->i->tileheight()/2.0);
|
||||
colliders.push_back(collider);
|
||||
}
|
||||
for (auto& obj : meta->i->lootobj()) {
|
||||
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(obj.id());
|
||||
if (thing) {
|
||||
Obstacle* entity = new Obstacle();
|
||||
entity->room = room;
|
||||
entity->meta = thing;
|
||||
entity->entity_uniid = room->AllocUniid();
|
||||
entity->pos = Vector2D(pos.x + obj.x() - meta->i->tilewidth() / 2.0,
|
||||
pos.y + obj.y() - meta->i->tileheight() / 2.0);
|
||||
entity->Initialize();
|
||||
room->uniid_hash_[entity->entity_uniid] = entity;
|
||||
for (auto& pair : room->human_hash_) {
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Building::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||
{
|
||||
part_data->set_object_type(ET_Building);
|
||||
cs::MFBuildingPart* p = part_data->mutable_union_obj_3();
|
||||
p->set_obj_uniid(entity_uniid);
|
||||
pos.ToPB(p->mutable_pos());
|
||||
}
|
||||
|
||||
void Building::FillMFObjectFull(cs::MFObjectFull* full_data)
|
||||
{
|
||||
full_data->set_object_type(ET_Building);
|
||||
cs::MFBuildingFull* p = full_data->mutable_union_obj_3();
|
||||
p->set_obj_uniid(entity_uniid);
|
||||
pos.ToPB(p->mutable_pos());
|
||||
|
||||
p->set_building_id(meta->i->_building_id());
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "entity.h"
|
||||
|
||||
namespace MetaData
|
||||
{
|
||||
struct Player;
|
||||
struct Equip;
|
||||
struct Building;
|
||||
}
|
||||
|
||||
class Human;
|
||||
class CircleCollider;
|
||||
class AabbCollider;
|
||||
class Building : public Entity
|
||||
{
|
||||
public:
|
||||
MetaData::Building* meta = nullptr;
|
||||
|
||||
Building();
|
||||
virtual ~Building() override;
|
||||
virtual void Initialize() override;
|
||||
void RecalcSelfCollider();
|
||||
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
|
||||
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
|
||||
|
||||
};
|
@ -40,4 +40,10 @@ namespace MetaData
|
||||
const metatable::Player* i = nullptr;
|
||||
};
|
||||
|
||||
|
||||
struct Building
|
||||
{
|
||||
const metatable::BuildingJson* i = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
std::list<metatable::MapThing> mapthing_meta_list;
|
||||
std::list<MetaData::MapThing> mapthing_list;
|
||||
std::list<metatable::BuildingJson> building_meta_list;
|
||||
std::list<MetaData::Building> building_list;
|
||||
|
||||
std::map<std::string, MetaData::Parameter*> parameter_hash;
|
||||
std::map<int, MetaData::Map*> gamemap_hash;
|
||||
@ -33,6 +34,7 @@ public:
|
||||
std::map<int, MetaData::Equip*> equip_hash;
|
||||
std::map<int, MetaData::Player*> player_hash;
|
||||
std::map<int, MetaData::MapThing*> mapthing_hash;
|
||||
std::map<int, MetaData::Building*> building_hash;
|
||||
|
||||
void Load()
|
||||
{
|
||||
@ -102,6 +104,16 @@ private:
|
||||
mapthing_hash[item.i->thing_id()] = &item;
|
||||
}
|
||||
|
||||
{
|
||||
int building_id = 0;
|
||||
for (auto& meta : building_meta_list) {
|
||||
MetaData::Building& item = a8::FastAppend(building_list);
|
||||
item.i = &meta;
|
||||
meta.set__building_id(building_id++);
|
||||
building_hash[item.i->_building_id()] = &item;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@ -156,3 +168,9 @@ MetaData::Equip* MetaMgr::GetEquip(int id)
|
||||
auto itr = loader_->equip_hash.find(id);
|
||||
return itr != loader_->equip_hash.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
MetaData::Building* MetaMgr::GetBuilding(int building_id)
|
||||
{
|
||||
auto itr = loader_->building_hash.find(building_id);
|
||||
return itr != loader_->building_hash.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
||||
MetaData::MapThing* GetMapThing(int mapthing_id);
|
||||
MetaData::Player* GetPlayer(int id);
|
||||
MetaData::Equip* GetEquip(int id);
|
||||
MetaData::Building* GetBuilding(int building_id);
|
||||
|
||||
private:
|
||||
MetaDataLoader* loader_ = nullptr;
|
||||
|
@ -22,22 +22,41 @@ void Obstacle::Initialize()
|
||||
|
||||
void Obstacle::RecalcSelfCollider()
|
||||
{
|
||||
if (meta->i->thing_id() == 61001) {
|
||||
if (!self_collider2_) {
|
||||
self_collider2_ = new AabbCollider();
|
||||
self_collider2_->owner = this;
|
||||
colliders.push_back(self_collider2_);
|
||||
switch (meta->i->thing_id()) {
|
||||
case 61001:
|
||||
{
|
||||
if (!self_collider2_) {
|
||||
self_collider2_ = new AabbCollider();
|
||||
self_collider2_->owner = this;
|
||||
colliders.push_back(self_collider2_);
|
||||
}
|
||||
self_collider2_->_min = Vector2D(-16.0f, -16.0f);
|
||||
self_collider2_->_max = Vector2D(16.0f, 16.0f);
|
||||
}
|
||||
self_collider2_->_min = Vector2D(-16.0f, -16.0f);
|
||||
self_collider2_->_max = Vector2D(16.0f, 16.0f);
|
||||
} else if (meta->i->thing_id() == 61007) {
|
||||
if (!self_collider_) {
|
||||
self_collider_ = new CircleCollider();
|
||||
self_collider_->owner = this;
|
||||
colliders.push_back(self_collider_);
|
||||
break;
|
||||
case 61017:
|
||||
{
|
||||
//玻璃32 * 12
|
||||
if (!self_collider2_) {
|
||||
self_collider2_ = new AabbCollider();
|
||||
self_collider2_->owner = this;
|
||||
colliders.push_back(self_collider2_);
|
||||
}
|
||||
self_collider2_->_min = Vector2D(-16.0f, -16.0f);
|
||||
self_collider2_->_max = Vector2D(6.0f, 6.0f);
|
||||
}
|
||||
self_collider_->pos = Vector2D();
|
||||
self_collider_->rad = 32 / 2.0;
|
||||
break;
|
||||
case 61007:
|
||||
{
|
||||
if (!self_collider_) {
|
||||
self_collider_ = new CircleCollider();
|
||||
self_collider_->owner = this;
|
||||
colliders.push_back(self_collider_);
|
||||
}
|
||||
self_collider_->pos = Vector2D();
|
||||
self_collider_->rad = 32 / 2.0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "bullet.h"
|
||||
#include "collider.h"
|
||||
#include "obstacle.h"
|
||||
#include "building.h"
|
||||
|
||||
const int ROOM_MAX_PLAYER_NUM = 50;
|
||||
const int ANDROID_NUM = 0;
|
||||
@ -190,6 +191,29 @@ void Room::ShuaObstacle(Human* hum)
|
||||
#endif
|
||||
}
|
||||
|
||||
void Room::ShuaBuilding(Human* hum)
|
||||
{
|
||||
MetaData::Building* a_building = MetaMgr::Instance()->GetBuilding(0);
|
||||
if (!a_building) {
|
||||
return;
|
||||
}
|
||||
#if 1
|
||||
{
|
||||
Building* entity = new Building();
|
||||
entity->room = this;
|
||||
entity->meta = a_building;
|
||||
entity->entity_uniid = AllocUniid();
|
||||
entity->pos = hum->pos - Vector2D::UP * hum->meta->i->radius() + 500;
|
||||
entity->Initialize();
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
for (auto& pair : human_hash_) {
|
||||
pair.second->new_objects.insert(entity);
|
||||
pair.second->part_objects.insert(entity);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Room::RandomPos(Human* hum, float distance, Vector2D& out_pos)
|
||||
{
|
||||
Vector2D dir = hum->pos;
|
||||
@ -264,6 +288,13 @@ void Room::CollisionDetection(Entity* sender, int detection_flags, std::vector<E
|
||||
}
|
||||
}
|
||||
}
|
||||
if (a8::HasBitFlag(detection_flags, ET_Building) && pair.second->entity_type == ET_Building) {
|
||||
if (sender->entity_type == ET_Bullet || sender->entity_type == ET_Player) {
|
||||
if (pair.second != sender && sender->TestCollision(pair.second)) {
|
||||
objects.push_back(pair.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
unsigned short AllocUniid();
|
||||
void ShuaAndroid();
|
||||
void ShuaObstacle(Human* hum);
|
||||
void ShuaBuilding(Human* hum);
|
||||
bool RandomPos(Human* hum, float distance, Vector2D& out_pos);
|
||||
Human* FindEnemy(Human* hum);
|
||||
void CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects);
|
||||
@ -60,7 +61,7 @@ private:
|
||||
void ClearDeletedObjects();
|
||||
void ProcAddedObjects();
|
||||
|
||||
private:
|
||||
public:
|
||||
unsigned short current_uniid = 0;
|
||||
RoomState_e state_ = RS_Inactive;
|
||||
int elapsed_time_ = 0;
|
||||
|
@ -53,6 +53,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
|
||||
hum->Initialize();
|
||||
room->AddPlayer(hum);
|
||||
room->ShuaObstacle(hum);
|
||||
room->ShuaBuilding(hum);
|
||||
|
||||
{
|
||||
cs::SMJoinedNotify notifymsg;
|
||||
|
@ -179,8 +179,6 @@ message MFBuildingPart
|
||||
{
|
||||
optional int32 obj_uniid = 1; //唯一id
|
||||
optional MFVector2D pos = 2; //位置
|
||||
optional int32 building_id = 3; //建筑物id
|
||||
optional int32 ori = 4; //
|
||||
}
|
||||
|
||||
//建筑物-全量
|
||||
@ -189,7 +187,6 @@ message MFBuildingFull
|
||||
optional int32 obj_uniid = 1; //唯一id
|
||||
optional MFVector2D pos = 2; //位置
|
||||
optional int32 building_id = 3; //建筑物id
|
||||
optional int32 ori = 4; //
|
||||
|
||||
optional bool ceiling_dead = 6;
|
||||
}
|
||||
|
@ -119,4 +119,6 @@ message BuildingJson
|
||||
repeated DropObjJson dropObj = 5;
|
||||
repeated StaticObjJson staticObj = 6;
|
||||
repeated LootObjJson lootObj = 7;
|
||||
|
||||
optional int32 _building_id = 20;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user