完成building重构
This commit is contained in:
parent
11b3b76504
commit
5577b62d8c
@ -1,12 +1,9 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
#include "building.h"
|
#include "building.h"
|
||||||
#include "metamgr.h"
|
|
||||||
#include "movement.h"
|
|
||||||
#include "room.h"
|
|
||||||
#include "collider.h"
|
#include "collider.h"
|
||||||
#include "obstacle.h"
|
#include "metamgr.h"
|
||||||
#include "human.h"
|
#include "room.h"
|
||||||
#include "loot.h"
|
#include "loot.h"
|
||||||
|
|
||||||
Building::Building():Entity()
|
Building::Building():Entity()
|
||||||
@ -34,70 +31,18 @@ void Building::RecalcSelfCollider()
|
|||||||
obj.y() + obj.height()/2.0 - meta->i->tileheight()/2.0);
|
obj.y() + obj.height()/2.0 - meta->i->tileheight()/2.0);
|
||||||
colliders.push_back(collider);
|
colliders.push_back(collider);
|
||||||
}
|
}
|
||||||
for (auto& obj : meta->doors) {
|
for (size_t i = 0; i < meta->doors.size(); ++i) {
|
||||||
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(61701);
|
room->CreateDoor(this, i);
|
||||||
if (thing) {
|
|
||||||
Obstacle* entity = new Obstacle();
|
|
||||||
entity->room = room;
|
|
||||||
entity->meta = thing;
|
|
||||||
entity->entity_uniid = room->AllocUniid();
|
|
||||||
entity->is_door = true;
|
|
||||||
entity->door_id = obj.door_id;
|
|
||||||
entity->door_state = DoorStateClose;
|
|
||||||
entity->building = this;
|
|
||||||
entity->door_house_uniid = entity_uniid;
|
|
||||||
entity->door_state0 = obj.state0;
|
|
||||||
entity->door_state1 = obj.state1;
|
|
||||||
#if 1
|
|
||||||
entity->pos = Vector2D(pos.x + entity->door_state0->x() - meta->i->tilewidth() / 2.0,
|
|
||||||
pos.y + entity->door_state0->y() - meta->i->tileheight() / 2.0);
|
|
||||||
#endif
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (auto& obj : meta->i->lootobj()) {
|
for (auto& obj : meta->i->lootobj()) {
|
||||||
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(obj.id());
|
room->CreateHouseObstacle(this, obj.id(), obj.x(), obj.y());
|
||||||
if (thing) {
|
|
||||||
Obstacle* entity = new Obstacle();
|
|
||||||
entity->room = room;
|
|
||||||
entity->meta = thing;
|
|
||||||
#if 1
|
|
||||||
entity->building = this;
|
|
||||||
#endif
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (auto& obj : meta->i->dropobj()) {
|
for (auto& obj : meta->i->dropobj()) {
|
||||||
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(obj.id());
|
room->CreateLoot(obj.id(),
|
||||||
if (equip_meta) {
|
pos.x + obj.x() - meta->i->tilewidth() / 2.0,
|
||||||
Loot* entity = new Loot();
|
pos.y + obj.y() - meta->i->tileheight() / 2.0,
|
||||||
entity->room = room;
|
1
|
||||||
entity->meta = equip_meta;
|
);
|
||||||
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->item_id = obj.id();
|
|
||||||
entity->count = 1;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,6 +419,80 @@ void Room::DropItem(Vector2D pos, int item_id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Room::CreateDoor(Building* building, int door_idx)
|
||||||
|
{
|
||||||
|
if (door_idx >= 0 && door_idx < building->meta->doors.size()) {
|
||||||
|
MetaData::Building::Door* door_meta = &building->meta->doors[door_idx];
|
||||||
|
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(61701);
|
||||||
|
if (thing) {
|
||||||
|
Obstacle* entity = new Obstacle();
|
||||||
|
entity->room = this;
|
||||||
|
entity->meta = thing;
|
||||||
|
entity->entity_uniid = AllocUniid();
|
||||||
|
entity->is_door = true;
|
||||||
|
entity->door_id = door_meta->door_id;
|
||||||
|
entity->door_state = DoorStateClose;
|
||||||
|
entity->building = building;
|
||||||
|
entity->door_house_uniid = building->entity_uniid;
|
||||||
|
entity->door_state0 = door_meta->state0;
|
||||||
|
entity->door_state1 = door_meta->state1;
|
||||||
|
entity->pos = Vector2D(building->pos.x + entity->door_state0->x() - building->meta->i->tilewidth() / 2.0,
|
||||||
|
building->pos.y + entity->door_state0->y() - building->meta->i->tileheight() / 2.0);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Room::CreateHouseObstacle(Building* building, int id, float x, float y)
|
||||||
|
{
|
||||||
|
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(id);
|
||||||
|
if (thing) {
|
||||||
|
Obstacle* entity = new Obstacle();
|
||||||
|
entity->room = this;
|
||||||
|
entity->meta = thing;
|
||||||
|
entity->building = building;
|
||||||
|
entity->entity_uniid = AllocUniid();
|
||||||
|
entity->pos = Vector2D(building->pos.x + x - building->meta->i->tilewidth() / 2.0,
|
||||||
|
building->pos.y + y - building->meta->i->tileheight() / 2.0);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Room::CreateLoot(int equip_id, float x, float y, int count)
|
||||||
|
{
|
||||||
|
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(equip_id);
|
||||||
|
if (equip_meta) {
|
||||||
|
Loot* entity = new Loot();
|
||||||
|
entity->room = this;
|
||||||
|
entity->meta = equip_meta;
|
||||||
|
entity->entity_uniid = AllocUniid();
|
||||||
|
#if 1
|
||||||
|
entity->pos = Vector2D(x, y);
|
||||||
|
#else
|
||||||
|
entity->pos = Vector2D(pos.x + obj.x() - meta->i->tilewidth() / 2.0,
|
||||||
|
pos.y + obj.y() - meta->i->tileheight() / 2.0);
|
||||||
|
#endif
|
||||||
|
entity->item_id = equip_id;
|
||||||
|
entity->count = count;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Room::ClearDeletedObjects()
|
void Room::ClearDeletedObjects()
|
||||||
{
|
{
|
||||||
for (auto& obj_uniid : frame_data.deleted_objects) {
|
for (auto& obj_uniid : frame_data.deleted_objects) {
|
||||||
|
@ -13,6 +13,7 @@ namespace MetaData
|
|||||||
{
|
{
|
||||||
struct Map;
|
struct Map;
|
||||||
struct SafeArea;
|
struct SafeArea;
|
||||||
|
struct Building;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RoomFrameData
|
struct RoomFrameData
|
||||||
@ -29,6 +30,7 @@ class Entity;
|
|||||||
class Bullet;
|
class Bullet;
|
||||||
class Human;
|
class Human;
|
||||||
class Player;
|
class Player;
|
||||||
|
class Building;
|
||||||
class Room
|
class Room
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -62,6 +64,9 @@ public:
|
|||||||
void CreateThings();
|
void CreateThings();
|
||||||
void FillSMMapInfo(cs::SMMapInfo& map_info);
|
void FillSMMapInfo(cs::SMMapInfo& map_info);
|
||||||
void DropItem(Vector2D pos, int item_id);
|
void DropItem(Vector2D pos, int item_id);
|
||||||
|
void CreateDoor(Building* building, int door_idx);
|
||||||
|
void CreateHouseObstacle(Building* building, int id, float x, float y);
|
||||||
|
void CreateLoot(int equip_id, float x, float y, int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ClearDeletedObjects();
|
void ClearDeletedObjects();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user