优化list_head
This commit is contained in:
parent
de470a6801
commit
bf4e4fad50
@ -57,6 +57,9 @@ void MapService::Init(int width, int height, int cell_width)
|
|||||||
|
|
||||||
map_cells_ = (list_head*)malloc(sizeof(list_head) * width * height);
|
map_cells_ = (list_head*)malloc(sizeof(list_head) * width * height);
|
||||||
memset(map_cells_, 0, sizeof(list_head) * width * height);
|
memset(map_cells_, 0, sizeof(list_head) * width * height);
|
||||||
|
for (int i = 0; i < max_grid_id_; ++i) {
|
||||||
|
INIT_LIST_HEAD(&map_cells_[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapService::UnInit()
|
void MapService::UnInit()
|
||||||
@ -121,9 +124,6 @@ void MapService::AddCollider(ColliderComponent* collider)
|
|||||||
for (int y = min_grid_y; y <= max_grid_y; ++y) {
|
for (int y = min_grid_y; y <= max_grid_y; ++y) {
|
||||||
int grid_id = x + y * map_width_;
|
int grid_id = x + y * map_width_;
|
||||||
list_head* head = &map_cells_[grid_id];
|
list_head* head = &map_cells_[grid_id];
|
||||||
if (head->next == nullptr && head->prev == nullptr) {
|
|
||||||
INIT_LIST_HEAD(head);
|
|
||||||
}
|
|
||||||
CellNode* node = new CellNode();
|
CellNode* node = new CellNode();
|
||||||
node->collider = collider;
|
node->collider = collider;
|
||||||
list_add_tail(&node->entry, head);
|
list_add_tail(&node->entry, head);
|
||||||
@ -179,7 +179,7 @@ void MapService::GetColliders(Room* room,
|
|||||||
int grid_id = center_grid_id + grid_offset_arr_[i];
|
int grid_id = center_grid_id + grid_offset_arr_[i];
|
||||||
if (grid_id >= 0 && grid_id < max_grid_id_) {
|
if (grid_id >= 0 && grid_id < max_grid_id_) {
|
||||||
list_head* head = &map_cells_[grid_id];
|
list_head* head = &map_cells_[grid_id];
|
||||||
if (head->next == nullptr && head->prev == nullptr) {
|
if (list_empty(head)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
struct CellNode *node, *tmp;
|
struct CellNode *node, *tmp;
|
||||||
|
@ -111,20 +111,25 @@ void Obstacle::FillMFObjectFull(Room* room, cs::MFObjectFull* full_data)
|
|||||||
p->set_scale(1.0f);
|
p->set_scale(1.0f);
|
||||||
|
|
||||||
p->set_obstacle_id(meta->i->thing_id());
|
p->set_obstacle_id(meta->i->thing_id());
|
||||||
p->set_health(health_);
|
p->set_health(GetHealth(room));
|
||||||
p->set_dead(dead_);
|
p->set_dead(IsDead(room));
|
||||||
p->set_dead_at_thisframe(IsDead(room) ? dead_frameno_ <= room->frame_no : false);
|
p->set_dead_at_thisframe(IsDead(room) ? GetDeadFrameNo(room) <= room->frame_no : false);
|
||||||
|
|
||||||
p->set_is_door(is_door_);
|
p->set_is_door(is_door_);
|
||||||
#if 0
|
if (is_door_ && IsPermanent()) {
|
||||||
if (is_door_) {
|
ObstacleData* data = room->GetPermanentObstacleData(entity_uniid);
|
||||||
|
if (!a8::HasBitFlag(data->flags, kHealth)) {
|
||||||
|
data->health = health_;
|
||||||
|
a8::SetBitFlag(data->flags, kHealth);
|
||||||
|
}
|
||||||
|
|
||||||
p->set_door_id(door_id_);
|
p->set_door_id(door_id_);
|
||||||
p->set_door_open_times(door_open_times_);
|
p->set_door_open_times(data->door_open_times);
|
||||||
p->set_door_old_state((int)door_state_);
|
p->set_door_old_state((int)data->door_state);
|
||||||
p->set_door_new_state((int)door_state_);
|
p->set_door_new_state((int)data->door_state);
|
||||||
p->set_door_house_uniid(door_house_uniid_);
|
p->set_door_house_uniid(door_house_uniid_);
|
||||||
p->set_door_house_id(building_->meta->i->mapid());
|
p->set_door_house_id(building_->meta->i->mapid());
|
||||||
if (door_state_ == DoorStateClose) {
|
if (data->door_state == DoorStateClose) {
|
||||||
p->set_door_width(door_state0_->width());
|
p->set_door_width(door_state0_->width());
|
||||||
p->set_door_height(door_state0_->height());
|
p->set_door_height(door_state0_->height());
|
||||||
} else {
|
} else {
|
||||||
@ -132,7 +137,6 @@ void Obstacle::FillMFObjectFull(Room* room, cs::MFObjectFull* full_data)
|
|||||||
p->set_door_height(door_state1_->height());
|
p->set_door_height(door_state1_->height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Obstacle::GetAabbBox(AabbCollider& aabb_box)
|
void Obstacle::GetAabbBox(AabbCollider& aabb_box)
|
||||||
|
@ -1572,7 +1572,7 @@ void Room::NotifyGameStart()
|
|||||||
|
|
||||||
void Room::InitObstacleDatas()
|
void Room::InitObstacleDatas()
|
||||||
{
|
{
|
||||||
obstacle_datas_.reserve(FIXED_OBJECT_MAXID);
|
obstacle_datas_.resize(FIXED_OBJECT_MAXID);
|
||||||
memset(&obstacle_datas_[0], 0, sizeof(ObstacleData) * FIXED_OBJECT_MAXID);
|
memset(&obstacle_datas_[0], 0, sizeof(ObstacleData) * FIXED_OBJECT_MAXID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user