1
This commit is contained in:
parent
83ce4e8334
commit
568cc480b7
@ -331,6 +331,7 @@ void Bullet::MapServiceUpdate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
room->grid_service->MoveBullet(this);
|
||||||
Check(distance);
|
Check(distance);
|
||||||
}
|
}
|
||||||
} while(!later_removed_ && move_length >= 0.0001f);
|
} while(!later_removed_ && move_length >= 0.0001f);
|
||||||
|
@ -220,6 +220,7 @@ Creature::~Creature()
|
|||||||
ClearPassiveSkill();
|
ClearPassiveSkill();
|
||||||
trigger_->UnInit();
|
trigger_->UnInit();
|
||||||
A8_SAFE_DELETE(trigger_);
|
A8_SAFE_DELETE(trigger_);
|
||||||
|
room->grid_service->RemoveCreature(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Creature::HasBuffEffect(int buff_effect_id)
|
bool Creature::HasBuffEffect(int buff_effect_id)
|
||||||
|
@ -7,14 +7,17 @@
|
|||||||
#include "car.h"
|
#include "car.h"
|
||||||
#include "hero.h"
|
#include "hero.h"
|
||||||
#include "creature.h"
|
#include "creature.h"
|
||||||
|
#include "bullet.h"
|
||||||
|
|
||||||
GridCell::GridCell()
|
GridCell::GridCell()
|
||||||
{
|
{
|
||||||
entitys_.reserve(MAX_ROOM_IDX);
|
entitys_.reserve(MAX_ROOM_IDX);
|
||||||
creatures_.reserve(MAX_ROOM_IDX);
|
creatures_.reserve(MAX_ROOM_IDX);
|
||||||
|
bullets_.reserve(MAX_ROOM_IDX);
|
||||||
for (int i = 0; i < MAX_ROOM_IDX; ++i) {
|
for (int i = 0; i < MAX_ROOM_IDX; ++i) {
|
||||||
entitys_.push_back(std::set<Entity*>());
|
entitys_.push_back(std::set<Entity*>());
|
||||||
creatures_.push_back(std::set<Creature*>());
|
creatures_.push_back(std::set<Creature*>());
|
||||||
|
bullets_.push_back(std::set<Bullet*>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,3 +127,13 @@ bool GridCell::CreatureExists(Creature* c)
|
|||||||
{
|
{
|
||||||
return creatures_[c->room->GetRoomIdx()].find(c) != creatures_[c->room->GetRoomIdx()].end();
|
return creatures_[c->room->GetRoomIdx()].find(c) != creatures_[c->room->GetRoomIdx()].end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GridCell::AddBullet(Bullet* bullet)
|
||||||
|
{
|
||||||
|
bullets_[bullet->room->GetRoomIdx()].insert(bullet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GridCell::RemoveBullet(Bullet* bullet)
|
||||||
|
{
|
||||||
|
bullets_[bullet->room->GetRoomIdx()].erase(bullet);
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
class Entity;
|
class Entity;
|
||||||
class Human;
|
class Human;
|
||||||
|
class Bullet;
|
||||||
class Room;
|
class Room;
|
||||||
class Creature;
|
class Creature;
|
||||||
|
|
||||||
@ -22,6 +23,8 @@ public:
|
|||||||
void AddCreature(Creature* c);
|
void AddCreature(Creature* c);
|
||||||
void RemoveCreature(Creature* c);
|
void RemoveCreature(Creature* c);
|
||||||
bool CreatureExists(Creature* c);
|
bool CreatureExists(Creature* c);
|
||||||
|
void AddBullet(Bullet* bullet);
|
||||||
|
void RemoveBullet(Bullet* bullet);
|
||||||
void AddPermanentEntity(Entity* entity);
|
void AddPermanentEntity(Entity* entity);
|
||||||
void AddRoomEntity(Room* room, Entity* entity);
|
void AddRoomEntity(Room* room, Entity* entity);
|
||||||
void RemoveRoomEntity(Room* room, Entity* entity);
|
void RemoveRoomEntity(Room* room, Entity* entity);
|
||||||
@ -38,4 +41,5 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::vector<std::set<Entity*>> entitys_;
|
std::vector<std::set<Entity*>> entitys_;
|
||||||
std::vector<std::set<Creature*>> creatures_;
|
std::vector<std::set<Creature*>> creatures_;
|
||||||
|
std::vector<std::set<Bullet*>> bullets_;
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "human.h"
|
#include "human.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "gridcell.h"
|
#include "gridcell.h"
|
||||||
|
#include "bullet.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1 2 3
|
1 2 3
|
||||||
@ -371,3 +372,51 @@ void GridService::DeatchHuman(Human* target)
|
|||||||
target->SetGridId(0);
|
target->SetGridId(0);
|
||||||
target->GetGridList().clear();
|
target->GetGridList().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@ class Entity;
|
|||||||
class Room;
|
class Room;
|
||||||
class Creature;
|
class Creature;
|
||||||
class GridCell;
|
class GridCell;
|
||||||
|
class Bullet;
|
||||||
class GridService
|
class GridService
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -23,6 +24,10 @@ class GridService
|
|||||||
void RemoveCreature(Creature* c);
|
void RemoveCreature(Creature* c);
|
||||||
void MoveCreature(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 AddRoomEntity(Room* room, Entity* entity);
|
||||||
void DelRoomEntity(Room* room, Entity* entity);
|
void DelRoomEntity(Room* room, Entity* entity);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user