This commit is contained in:
aozhiwei 2019-09-12 11:06:42 +08:00
parent 9ce310ce77
commit 9cf6a340f2
5 changed files with 66 additions and 86 deletions

View File

@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.8)
set(GAME_ID 2001)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_BUILD_TYPE "Release")
#set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID}")
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID}")

View File

@ -83,90 +83,6 @@ void Entity::ClearColliders()
colliders.clear();
}
void Entity::FindLocationWithTarget(Entity* target)
{
a8::Vec2 old_pos = pos;
a8::Vec2 new_pos = pos;
AabbCollider a_collider;
GetAabbBox(a_collider);
AabbCollider target_collider;
target->GetAabbBox(target_collider);
{
bool ret = a_collider.CalcSafePoint(&target_collider, new_pos);
if (!ret) {
abort();
}
}
a8::Vec2 new_pos_dir = new_pos - old_pos;
new_pos_dir.Normalize();
float distance = (new_pos - old_pos).Norm();
for (int i = distance; i < 10000000; i += 5) {
pos = old_pos + new_pos_dir * i;
Entity* building = nullptr;
std::set<GridCell*> new_grid_list;
room->grid_service.GetAllCellsByXy(pos.x, pos.y, new_grid_list);
for (auto& grid : new_grid_list) {
for (Entity* entity : grid->entity_list) {
switch (entity->entity_type) {
case ET_Building:
{
if (TestCollision(entity)) {
building = entity;
}
}
break;
default:
break;
}
if (building) {
break;
}
}
if (building) {
break;
}
}
if (!building) {
bool is_collision = false;
std::set<ColliderComponent*> colliders;
room->map_service.GetColliders(pos.x, pos.y, colliders);
for (ColliderComponent* collider : colliders) {
if (TestCollision(collider)) {
is_collision = true;
break;
}
}
if (!is_collision) {
break;
}
}
}
room->grid_service.RemoveFromGridList(grid_list, this);
{
grid_list.clear();
switch (entity_type) {
case ET_Player:
{
room->grid_service.AddHuman((Human*)this);
}
break;
case ET_Bullet:
{
room->grid_service.AddBullet((Bullet*)this);
}
break;
default:
{
room->grid_service.AddEntity(this);
}
break;
}
}
}
void Entity::BroadcastFullState()
{
std::set<GridCell*> grid_list;

View File

@ -44,7 +44,6 @@ class Entity
bool TestCollision(Entity* b);
bool TestCollision(ColliderComponent* b);
bool TestCollisionEx(const a8::Vec2& aabb_pos, AabbCollider& aabb_box);
void FindLocationWithTarget(Entity* target);
void BroadcastFullState();
void BroadcastDeleteState();
void AddCollider(ColliderComponent* collider);

View File

@ -2387,3 +2387,67 @@ void Human::ProcLootSkin(Loot* entity, MetaData::Equip* item_meta)
}
}
}
void Human::FindLocationWithTarget(Entity* target)
{
a8::Vec2 old_pos = pos;
a8::Vec2 new_pos = pos;
AabbCollider a_collider;
GetAabbBox(a_collider);
AabbCollider target_collider;
target->GetAabbBox(target_collider);
{
bool ret = a_collider.CalcSafePoint(&target_collider, new_pos);
if (!ret) {
abort();
}
}
a8::Vec2 new_pos_dir = new_pos - old_pos;
new_pos_dir.Normalize();
float distance = (new_pos - old_pos).Norm();
for (int i = distance; i < 10000000; i += 5) {
pos = old_pos + new_pos_dir * i;
room->grid_service.MoveHuman(this);
Entity* building = nullptr;
std::set<GridCell*> new_grid_list;
room->grid_service.GetAllCellsByXy(pos.x, pos.y, new_grid_list);
for (auto& grid : new_grid_list) {
for (Entity* entity : grid->entity_list) {
switch (entity->entity_type) {
case ET_Building:
{
if (TestCollision(entity)) {
building = entity;
}
}
break;
default:
break;
}
if (building) {
break;
}
}
if (building) {
break;
}
}
if (!building) {
bool is_collision = false;
std::set<ColliderComponent*> colliders;
room->map_service.GetColliders(pos.x, pos.y, colliders);
for (ColliderComponent* collider : colliders) {
if (TestCollision(collider)) {
is_collision = true;
break;
}
}
if (!is_collision) {
break;
}
}
}
}

View File

@ -225,6 +225,7 @@ private:
void DeadDrop();
void FillSMGameOver(cs::SMGameOver& msg);
void SendBattleReport();
void FindLocationWithTarget(Entity* target);
protected:
long long last_shot_frameno_ = 0;