remove bullet from gridcell
This commit is contained in:
parent
24b1944909
commit
c86e3eb10c
@ -331,7 +331,6 @@ void Bullet::MapServiceUpdate()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
room->grid_service->MoveBullet(this);
|
||||
Check(distance);
|
||||
}
|
||||
} while(!later_removed_ && move_length >= 0.0001f);
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "gridcell.h"
|
||||
#include "bullet.h"
|
||||
#include "entity.h"
|
||||
#include "human.h"
|
||||
#include "room.h"
|
||||
@ -12,11 +11,9 @@
|
||||
GridCell::GridCell()
|
||||
{
|
||||
entitys_.reserve(MAX_ROOM_IDX);
|
||||
bullets_.reserve(MAX_ROOM_IDX);
|
||||
creatures_.reserve(MAX_ROOM_IDX);
|
||||
for (int i = 0; i < MAX_ROOM_IDX; ++i) {
|
||||
entitys_.push_back(std::set<Entity*>());
|
||||
bullets_.push_back(std::set<Bullet*>());
|
||||
creatures_.push_back(std::set<Creature*>());
|
||||
}
|
||||
}
|
||||
@ -25,7 +22,6 @@ GridCell::GridCell()
|
||||
void GridCell::ClearRoomData(Room* room)
|
||||
{
|
||||
entitys_[room->GetRoomIdx()].clear();
|
||||
bullets_[room->GetRoomIdx()].clear();
|
||||
creatures_[room->GetRoomIdx()].clear();
|
||||
}
|
||||
|
||||
@ -57,16 +53,6 @@ void GridCell::TraverseCreatures(std::function<void (Creature*, bool&)>& func,
|
||||
}
|
||||
}
|
||||
|
||||
void GridCell::AddBullet(Bullet* bullet)
|
||||
{
|
||||
bullets_[bullet->room->GetRoomIdx()].insert(bullet);
|
||||
}
|
||||
|
||||
void GridCell::RemoveBullet(Bullet* bullet)
|
||||
{
|
||||
bullets_[bullet->room->GetRoomIdx()].erase(bullet);
|
||||
}
|
||||
|
||||
void GridCell::AddPermanentEntity(Entity* entity)
|
||||
{
|
||||
entitys_[0].insert(entity);
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
class Entity;
|
||||
class Human;
|
||||
class Bullet;
|
||||
class Room;
|
||||
class Creature;
|
||||
|
||||
@ -23,8 +22,6 @@ public:
|
||||
void AddCreature(Creature* c);
|
||||
void RemoveCreature(Creature* c);
|
||||
bool CreatureExists(Creature* c);
|
||||
void AddBullet(Bullet* bullet);
|
||||
void RemoveBullet(Bullet* bullet);
|
||||
void AddPermanentEntity(Entity* entity);
|
||||
void AddRoomEntity(Room* room, Entity* entity);
|
||||
void RemoveRoomEntity(Room* room, Entity* entity);
|
||||
@ -40,6 +37,5 @@ public:
|
||||
|
||||
private:
|
||||
std::vector<std::set<Entity*>> entitys_;
|
||||
std::vector<std::set<Bullet*>> bullets_;
|
||||
std::vector<std::set<Creature*>> creatures_;
|
||||
};
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#include "gridservice.h"
|
||||
#include "human.h"
|
||||
#include "bullet.h"
|
||||
#include "room.h"
|
||||
#include "gridcell.h"
|
||||
|
||||
@ -161,54 +160,6 @@ void GridService::MoveCreature(Creature* c)
|
||||
}
|
||||
}
|
||||
|
||||
void GridService::AddBullet(Bullet* bullet)
|
||||
{
|
||||
int x = (int)bullet->GetX() + cell_width_;
|
||||
int y = (int)bullet->GetY() + cell_width_;
|
||||
if (BroderOverFlow(x, y)) {
|
||||
abort();
|
||||
}
|
||||
bullet->SetGridId(x/cell_width_ + (y/cell_width_) * cell_count_per_row_);
|
||||
if (bullet->GetGridId() == 0 || bullet->GetGridId() > max_grid_id_) {
|
||||
abort();
|
||||
}
|
||||
cells_[bullet->GetGridId()].AddBullet(bullet);
|
||||
GetAllCells(bullet->room, bullet->GetGridId(), bullet->GetGridList());
|
||||
}
|
||||
|
||||
void GridService::MoveBullet(Bullet* bullet)
|
||||
{
|
||||
int new_x = (int)bullet->GetX() + cell_width_;
|
||||
int new_y = (int)bullet->GetY() + cell_width_;
|
||||
int new_grid_id = new_x/cell_width_ + (new_y/cell_width_) * cell_count_per_row_;
|
||||
if (BroderOverFlow(new_x, new_y)) {
|
||||
abort();
|
||||
}
|
||||
if (new_grid_id == 0 || new_grid_id > max_grid_id_) {
|
||||
abort();
|
||||
}
|
||||
if (new_grid_id != bullet->GetGridId()) {
|
||||
std::set<GridCell*> inc_grid_list;
|
||||
std::set<GridCell*> dec_grid_list;
|
||||
std::set<GridCell*> old_grid_list = bullet->GetGridList();
|
||||
ComputeDiff(bullet->room,
|
||||
bullet->GetGridId(),
|
||||
new_grid_id,
|
||||
bullet->GetGridList(),
|
||||
inc_grid_list,
|
||||
dec_grid_list);
|
||||
cells_[bullet->GetGridId()].RemoveBullet(bullet);
|
||||
cells_[new_grid_id].AddBullet(bullet);
|
||||
bullet->SetGridId(new_grid_id);
|
||||
}
|
||||
}
|
||||
|
||||
void GridService::DelBullet(Bullet* bullet)
|
||||
{
|
||||
GridCell& cell = cells_[bullet->GetGridId()];
|
||||
cell.RemoveBullet(bullet);
|
||||
}
|
||||
|
||||
void GridService::AddRoomEntity(Room* room, Entity* entity)
|
||||
{
|
||||
assert(!entity->IsEntityType(ET_Player));
|
||||
|
@ -3,7 +3,6 @@
|
||||
class Human;
|
||||
class Entity;
|
||||
class Room;
|
||||
class Bullet;
|
||||
class Creature;
|
||||
class GridCell;
|
||||
class GridService
|
||||
@ -24,10 +23,6 @@ class GridService
|
||||
void RemoveCreature(Creature* c);
|
||||
void MoveCreature(Creature* c);
|
||||
|
||||
void AddBullet(Bullet* bullet);
|
||||
void MoveBullet(Bullet* bullet);
|
||||
void DelBullet(Bullet* bullet);
|
||||
|
||||
void AddRoomEntity(Room* room, Entity* entity);
|
||||
void DelRoomEntity(Room* room, Entity* entity);
|
||||
|
||||
|
@ -597,7 +597,6 @@ int Room::CreateBullet(Creature* sender,
|
||||
bullet->is_tank_skin = is_tank_skin;
|
||||
bullet->Initialize();
|
||||
AddObjectLater(bullet);
|
||||
grid_service->AddBullet(bullet);
|
||||
bullet_uniid = bullet->GetUniId();
|
||||
}
|
||||
return bullet_uniid;
|
||||
@ -674,7 +673,6 @@ void Room::InternalRemoveObjectLater(Entity* entity, a8::XTimerAttacher& xtimer_
|
||||
case ET_Bullet:
|
||||
{
|
||||
room->RemoveFromMoveableHash((Bullet*)entity);
|
||||
room->grid_service->DelBullet((Bullet*)entity);
|
||||
}
|
||||
break;
|
||||
case ET_Loot:
|
||||
|
Loading…
x
Reference in New Issue
Block a user