This commit is contained in:
aozhiwei 2019-04-09 14:16:03 +08:00
parent 3fc0c50c98
commit 5466fdc96b
8 changed files with 48 additions and 6 deletions

View File

@ -66,6 +66,9 @@ void Building::RecalcSelfCollider()
Obstacle* entity = new Obstacle(); Obstacle* entity = new Obstacle();
entity->room = room; entity->room = room;
entity->meta = thing; entity->meta = thing;
#if 1
entity->building = this;
#endif
entity->entity_uniid = room->AllocUniid(); entity->entity_uniid = room->AllocUniid();
entity->pos = Vector2D(pos.x + obj.x() - meta->i->tilewidth() / 2.0, entity->pos = Vector2D(pos.x + obj.x() - meta->i->tilewidth() / 2.0,
pos.y + obj.y() - meta->i->tileheight() / 2.0); pos.y + obj.y() - meta->i->tileheight() / 2.0);

View File

@ -16,6 +16,7 @@ class Building : public Entity
{ {
public: public:
MetaData::Building* meta = nullptr; MetaData::Building* meta = nullptr;
int building_id = 0;
Building(); Building();
virtual ~Building() override; virtual ~Building() override;

View File

@ -15,7 +15,7 @@ namespace MetaData
std::vector<std::string> strings2; std::vector<std::string> strings2;
a8::Split(str, strings2, ':'); a8::Split(str, strings2, ':');
assert(strings2.size() == 2); assert(strings2.size() == 2);
rand_space += a8::XValue(strings[1]).GetInt(); rand_space += a8::XValue(strings2[1]).GetInt();
template_list.push_back(std::make_tuple( template_list.push_back(std::make_tuple(
strings2[0], strings2[0],
rand_space rand_space
@ -26,7 +26,7 @@ namespace MetaData
std::string Map::RandTemplate() std::string Map::RandTemplate()
{ {
if (rand_space > 0) { if (rand_space <= 0) {
return ""; return "";
} }
int rnd = rand() % rand_space; int rnd = rand() % rand_space;

View File

@ -86,6 +86,8 @@ private:
if (itr == maptpl_meta_hash.end()) { if (itr == maptpl_meta_hash.end()) {
maptpl_meta_hash[std::get<0>(tuple)] = std::list<metatable::MapTplThingJson>(); maptpl_meta_hash[std::get<0>(tuple)] = std::list<metatable::MapTplThingJson>();
itr = maptpl_meta_hash.find(std::get<0>(tuple)); itr = maptpl_meta_hash.find(std::get<0>(tuple));
} else {
itr->second.clear();
} }
f8::ReadJsonMetaFile(res_path + std::get<0>(tuple) + ".json", itr->second); f8::ReadJsonMetaFile(res_path + std::get<0>(tuple) + ".json", itr->second);
} }

View File

@ -411,6 +411,7 @@ void Room::CreateThings()
Building* entity = new Building(); Building* entity = new Building();
entity->room = this; entity->room = this;
entity->meta = building_meta; entity->meta = building_meta;
entity->building_id = thing_id;
entity->entity_uniid = AllocUniid(); entity->entity_uniid = AllocUniid();
entity->pos = Vector2D(thing_tpl.i->x(), thing_tpl.i->y()); entity->pos = Vector2D(thing_tpl.i->x(), thing_tpl.i->y());
entity->Initialize(); entity->Initialize();
@ -439,6 +440,37 @@ void Room::CreateThings()
} }
} }
void Room::FillSMMapInfo(cs::SMMapInfo& map_info)
{
for (auto& pair :uniid_hash_) {
switch (pair.second->entity_type) {
case ET_Obstacle:
{
Obstacle* entity = (Obstacle*)pair.second;
if (!entity->building) {
cs::MFMapObject* p = map_info.add_objects();
p->set_object_id(entity->meta->i->thing_id());
entity->pos.ToPB(p->mutable_pos());
}
}
break;
case ET_Building:
{
Building* entity = (Building*)pair.second;
cs::MFMapObject* p = map_info.add_objects();
p->set_object_id(entity->building_id);
entity->pos.ToPB(p->mutable_pos());
}
break;
default:
{
}
break;
}
}
}
void Room::ClearDeletedObjects() void Room::ClearDeletedObjects()
{ {
for (auto& obj_uniid : frame_data.deleted_objects) { for (auto& obj_uniid : frame_data.deleted_objects) {

View File

@ -62,6 +62,7 @@ public:
void BeAddedObject(Entity* entity); void BeAddedObject(Entity* entity);
void ProcDrop(Vector2D center, int drop_id); void ProcDrop(Vector2D center, int drop_id);
void CreateThings(); void CreateThings();
void FillSMMapInfo(cs::SMMapInfo& map_info);
private: private:
void ClearDeletedObjects(); void ClearDeletedObjects();

View File

@ -52,8 +52,12 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
hum->socket_handle = hdr.socket_handle; hum->socket_handle = hdr.socket_handle;
hum->Initialize(); hum->Initialize();
room->AddPlayer(hum); room->AddPlayer(hum);
#if 1
room->CreateThings();
#else
room->ShuaObstacle(hum); room->ShuaObstacle(hum);
room->ShuaBuilding(hum); room->ShuaBuilding(hum);
#endif
{ {
cs::SMJoinedNotify notifymsg; cs::SMJoinedNotify notifymsg;
@ -64,6 +68,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
{ {
cs::SMMapInfo notifymsg; cs::SMMapInfo notifymsg;
notifymsg.set_map_id(room->map_meta->i->map_id()); notifymsg.set_map_id(room->map_meta->i->map_id());
room->FillSMMapInfo(notifymsg);
GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg);
} }
} }

View File

@ -91,10 +91,8 @@ message MFVector2D
// //
message MFMapObject message MFMapObject
{ {
//type optional int32 object_id = 1; //id(mapThing表id)
optional MFVector2D pos = 1; // optional MFVector2D pos = 2; //
optional int32 ori = 2; //zzzzz
optional int32 scale = 3; //
} }
// //