重构create object
This commit is contained in:
parent
059f605cf6
commit
4ac5881160
@ -32,21 +32,6 @@ 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 (size_t i = 0; i < meta->doors.size(); ++i) {
|
|
||||||
room->CreateDoor(this, i);
|
|
||||||
}
|
|
||||||
for (auto& obj : meta->i->lootobj()) {
|
|
||||||
room->CreateHouseObstacle(this, obj.id(), obj.x(), obj.y());
|
|
||||||
}
|
|
||||||
for (auto& obj : meta->i->dropobj()) {
|
|
||||||
room->CreateLoot(obj.id(),
|
|
||||||
Vector2D(
|
|
||||||
pos.x + obj.x() - meta->i->tilewidth() / 2.0,
|
|
||||||
pos.y + obj.y() - meta->i->tileheight() / 2.0
|
|
||||||
),
|
|
||||||
1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Building::FillMFObjectPart(cs::MFObjectPart* part_data)
|
void Building::FillMFObjectPart(cs::MFObjectPart* part_data)
|
||||||
|
@ -110,3 +110,5 @@ const int SMOKE_SLOT = 4;
|
|||||||
const int MAP_HEIGHT = 8192;
|
const int MAP_HEIGHT = 8192;
|
||||||
const int MAP_WIDTH = 8192;
|
const int MAP_WIDTH = 8192;
|
||||||
const int MAP_CELL_WIDTH = 64 * 5;
|
const int MAP_CELL_WIDTH = 64 * 5;
|
||||||
|
|
||||||
|
const int DOOR_THING_ID = 61701;
|
||||||
|
@ -341,25 +341,9 @@ void Room::CreateThings()
|
|||||||
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id);
|
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id);
|
||||||
if (thing_meta) {
|
if (thing_meta) {
|
||||||
if (thing_meta->i->is_house()) {
|
if (thing_meta->i->is_house()) {
|
||||||
MetaData::Building* building_meta = MetaMgr::Instance()->GetBuilding(thing_meta->i->house_id());
|
CreateBuilding(thing_id, thing_tpl.i->x(), thing_tpl.i->y());
|
||||||
if (building_meta) {
|
|
||||||
Building* entity = new Building();
|
|
||||||
entity->room = this;
|
|
||||||
entity->meta = building_meta;
|
|
||||||
entity->building_id = thing_id;
|
|
||||||
entity->entity_uniid = AllocUniid();
|
|
||||||
entity->pos = Vector2D(thing_tpl.i->x(), thing_tpl.i->y());
|
|
||||||
entity->Initialize();
|
|
||||||
uniid_hash_[entity->entity_uniid] = entity;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Obstacle* entity = new Obstacle();
|
CreateObstacle(thing_id, thing_tpl.i->x(), thing_tpl.i->y());
|
||||||
entity->room = this;
|
|
||||||
entity->meta = thing_meta;
|
|
||||||
entity->entity_uniid = AllocUniid();
|
|
||||||
entity->pos = Vector2D(thing_tpl.i->x(), thing_tpl.i->y());
|
|
||||||
entity->Initialize();
|
|
||||||
uniid_hash_[entity->entity_uniid] = entity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,38 +384,43 @@ void Room::FillSMMapInfo(cs::SMMapInfo& map_info)
|
|||||||
|
|
||||||
void Room::DropItem(Vector2D pos, int item_id, int item_count)
|
void Room::DropItem(Vector2D pos, int item_id, int item_count)
|
||||||
{
|
{
|
||||||
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(item_id);
|
|
||||||
if (equip_meta) {
|
|
||||||
Loot* entity = new Loot();
|
|
||||||
entity->room = this;
|
|
||||||
entity->meta = equip_meta;
|
|
||||||
entity->entity_uniid = AllocUniid();
|
|
||||||
{
|
{
|
||||||
Vector2D dir = Vector2D::UP;
|
Vector2D dir = Vector2D::UP;
|
||||||
dir.Rotate(a8::RandAngle());
|
dir.Rotate(a8::RandAngle());
|
||||||
entity->pos = pos + dir * (25 + rand() % 50);
|
pos = pos + dir * (25 + rand() % 50);
|
||||||
}
|
|
||||||
entity->item_id = equip_meta->i->id();
|
|
||||||
entity->count = item_count;
|
|
||||||
entity->Initialize();
|
|
||||||
uniid_hash_[entity->entity_uniid] = entity;
|
|
||||||
{
|
|
||||||
std::set<GridCell*> inc_grid_list;
|
|
||||||
grid_service.AddEntity(entity, inc_grid_list);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
CreateLoot(item_id, pos, item_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Room::CreateDoor(Building* building, int door_idx)
|
void Room::CreateBuilding(int thing_id, float building_x, float building_y)
|
||||||
{
|
{
|
||||||
|
MetaData::MapThing* thing_meta = MetaMgr::Instance()->GetMapThing(thing_id);
|
||||||
|
if (!thing_meta) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MetaData::Building* building_meta = MetaMgr::Instance()->GetBuilding(thing_meta->i->house_id());
|
||||||
|
if (building_meta) {
|
||||||
|
Building* building = new Building();
|
||||||
|
building->room = this;
|
||||||
|
building->meta = building_meta;
|
||||||
|
building->building_id = thing_id;
|
||||||
|
building->entity_uniid = AllocUniid();
|
||||||
|
building->pos = Vector2D(building_x, building_y);
|
||||||
|
building->Initialize();
|
||||||
|
uniid_hash_[building->entity_uniid] = building;
|
||||||
|
{
|
||||||
|
std::set<GridCell*> inc_grid_list;
|
||||||
|
grid_service.AddEntity(building, inc_grid_list);
|
||||||
|
}
|
||||||
|
for (size_t door_idx = 0; door_idx < building_meta->doors.size(); ++door_idx) {
|
||||||
if (door_idx >= 0 && door_idx < building->meta->doors.size()) {
|
if (door_idx >= 0 && door_idx < building->meta->doors.size()) {
|
||||||
MetaData::Building::Door* door_meta = &building->meta->doors[door_idx];
|
MetaData::Building::Door* door_meta = &building->meta->doors[door_idx];
|
||||||
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(61701);
|
float x = building->pos.x + door_meta->state0->x() - building->meta->i->tilewidth() / 2.0;
|
||||||
if (thing) {
|
float y = building->pos.y + door_meta->state0->y() - building->meta->i->tileheight() / 2.0;
|
||||||
Obstacle* entity = new Obstacle();
|
InternalCreateObstacle(DOOR_THING_ID, x, y,
|
||||||
entity->room = this;
|
[building, door_meta] (Obstacle* entity)
|
||||||
entity->meta = thing;
|
{
|
||||||
entity->entity_uniid = AllocUniid();
|
entity->building = building;
|
||||||
entity->is_door = true;
|
entity->is_door = true;
|
||||||
entity->door_id = door_meta->door_id;
|
entity->door_id = door_meta->door_id;
|
||||||
entity->door_state = DoorStateClose;
|
entity->door_state = DoorStateClose;
|
||||||
@ -439,58 +428,36 @@ void Room::CreateDoor(Building* building, int door_idx)
|
|||||||
entity->door_house_uniid = building->entity_uniid;
|
entity->door_house_uniid = building->entity_uniid;
|
||||||
entity->door_state0 = door_meta->state0;
|
entity->door_state0 = door_meta->state0;
|
||||||
entity->door_state1 = door_meta->state1;
|
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& obj : building_meta->i->lootobj()) {
|
||||||
|
float x = building->pos.x + obj.x() - building->meta->i->tilewidth() / 2.0;
|
||||||
|
float y = building->pos.y + obj.y() - building->meta->i->tileheight() / 2.0;
|
||||||
|
InternalCreateObstacle(obj.id(), x, y,
|
||||||
|
[building] (Obstacle* entity)
|
||||||
{
|
{
|
||||||
std::set<GridCell*> inc_grid_list;
|
|
||||||
grid_service.AddEntity(entity, inc_grid_list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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->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);
|
for (auto& obj : building_meta->i->dropobj()) {
|
||||||
entity->Initialize();
|
CreateLoot(obj.id(),
|
||||||
uniid_hash_[entity->entity_uniid] = entity;
|
Vector2D(
|
||||||
{
|
building->pos.x + obj.x() - building_meta->i->tilewidth() / 2.0,
|
||||||
std::set<GridCell*> inc_grid_list;
|
building->pos.y + obj.y() - building_meta->i->tileheight() / 2.0
|
||||||
grid_service.AddEntity(entity, inc_grid_list);
|
),
|
||||||
|
1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Room::CreateObstacle(int id, float x, float y)
|
Obstacle* Room::CreateObstacle(int id, float x, float y)
|
||||||
{
|
{
|
||||||
#if 0
|
return InternalCreateObstacle(id, x, y,
|
||||||
a8::XPrintf("createobstacle %d %f %f\n", {id, x, y});
|
[] (Obstacle*)
|
||||||
#endif
|
|
||||||
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(id);
|
|
||||||
if (thing) {
|
|
||||||
Obstacle* entity = new Obstacle();
|
|
||||||
entity->room = this;
|
|
||||||
entity->meta = thing;
|
|
||||||
entity->building = nullptr;
|
|
||||||
entity->entity_uniid = AllocUniid();
|
|
||||||
entity->pos = Vector2D(x, y);
|
|
||||||
entity->Initialize();
|
|
||||||
uniid_hash_[entity->entity_uniid] = entity;
|
|
||||||
{
|
{
|
||||||
std::set<GridCell*> inc_grid_list;
|
});
|
||||||
grid_service.AddEntity(entity, inc_grid_list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Room::CreateLoot(int equip_id, Vector2D pos, int count)
|
void Room::CreateLoot(int equip_id, Vector2D pos, int count)
|
||||||
@ -528,9 +495,7 @@ void Room::CreateBullet(Human* hum, MetaData::Equip* gun_meta,
|
|||||||
bullet->fly_distance = fly_distance;
|
bullet->fly_distance = fly_distance;
|
||||||
bullet->entity_uniid = AllocUniid();
|
bullet->entity_uniid = AllocUniid();
|
||||||
bullet->Initialize();
|
bullet->Initialize();
|
||||||
#if 0
|
AddObjectLater(bullet);
|
||||||
be_added_hash_[bullet->entity_uniid] = bullet;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Room::RemoveObjectLater(Entity* entity)
|
void Room::RemoveObjectLater(Entity* entity)
|
||||||
@ -931,13 +896,6 @@ void Room::AirDrop(int appear_time, int box_id)
|
|||||||
if (thing_meta) {
|
if (thing_meta) {
|
||||||
Vector2D dir = Vector2D::UP;
|
Vector2D dir = Vector2D::UP;
|
||||||
dir.Rotate(a8::RandAngle());
|
dir.Rotate(a8::RandAngle());
|
||||||
#if 0
|
|
||||||
a8::XPrintf("gas_data.pos_new %f %f\n",
|
|
||||||
{
|
|
||||||
gas_data.pos_new.x,
|
|
||||||
gas_data.pos_new.y
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
Vector2D box_pos = gas_data.pos_new + dir * (500 + rand() % 300);
|
Vector2D box_pos = gas_data.pos_new + dir * (500 + rand() % 300);
|
||||||
frame_event.AddAirDrop(appear_time, box_id, box_pos);
|
frame_event.AddAirDrop(appear_time, box_id, box_pos);
|
||||||
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * appear_time / 1000.f,
|
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * appear_time / 1000.f,
|
||||||
@ -983,3 +941,33 @@ void Room::ShuaPlane()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Obstacle* Room::InternalCreateObstacle(int id, float x, float y,
|
||||||
|
std::function<void (Obstacle*)> on_precreate)
|
||||||
|
{
|
||||||
|
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(id);
|
||||||
|
if (thing) {
|
||||||
|
Obstacle* entity = new Obstacle();
|
||||||
|
entity->room = this;
|
||||||
|
entity->meta = thing;
|
||||||
|
entity->building = nullptr;
|
||||||
|
entity->entity_uniid = AllocUniid();
|
||||||
|
entity->pos = Vector2D(x, y);
|
||||||
|
entity->Initialize();
|
||||||
|
if (on_precreate) {
|
||||||
|
on_precreate(entity);
|
||||||
|
}
|
||||||
|
uniid_hash_[entity->entity_uniid] = entity;
|
||||||
|
{
|
||||||
|
std::set<GridCell*> inc_grid_list;
|
||||||
|
grid_service.AddEntity(entity, inc_grid_list);
|
||||||
|
}
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Room::AddObjectLater(Entity* entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@ struct RoomProfile
|
|||||||
|
|
||||||
struct timer_list;
|
struct timer_list;
|
||||||
class Entity;
|
class Entity;
|
||||||
|
class Obstacle;
|
||||||
class Bullet;
|
class Bullet;
|
||||||
class Human;
|
class Human;
|
||||||
class Player;
|
class Player;
|
||||||
@ -74,10 +75,7 @@ public:
|
|||||||
void ScatterDrop(Vector2D center, int drop_id);
|
void ScatterDrop(Vector2D center, int drop_id);
|
||||||
void DropItem(Vector2D pos, int item_id, int item_count);
|
void DropItem(Vector2D pos, int item_id, int item_count);
|
||||||
|
|
||||||
void CreateThings();
|
Obstacle* CreateObstacle(int id, float x, float y);
|
||||||
void CreateDoor(Building* building, int door_idx);
|
|
||||||
void CreateObstacle(int id, float x, float y);
|
|
||||||
void CreateHouseObstacle(Building* building, int id, float x, float y);
|
|
||||||
void CreateLoot(int equip_id, Vector2D pos, int count);
|
void CreateLoot(int equip_id, Vector2D pos, int count);
|
||||||
void CreateBullet(Human* hum, MetaData::Equip* gun_meta,
|
void CreateBullet(Human* hum, MetaData::Equip* gun_meta,
|
||||||
Vector2D pos, Vector2D dir, float fly_distance);
|
Vector2D pos, Vector2D dir, float fly_distance);
|
||||||
@ -97,6 +95,11 @@ private:
|
|||||||
void AirDrop(int appear_time, int box_id);
|
void AirDrop(int appear_time, int box_id);
|
||||||
void ShuaPlane();
|
void ShuaPlane();
|
||||||
int NewTeam();
|
int NewTeam();
|
||||||
|
void CreateThings();
|
||||||
|
void CreateBuilding(int thing_id, float building_x, float building_y);
|
||||||
|
Obstacle* InternalCreateObstacle(int id, float x, float y,
|
||||||
|
std::function<void (Obstacle*)> on_precreate);
|
||||||
|
void AddObjectLater(Entity* entity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
timer_list* stats_timer_ = nullptr;
|
timer_list* stats_timer_ = nullptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user