This commit is contained in:
aozhiwei 2019-06-11 12:38:19 +08:00
parent 281c3b1fe4
commit 0a92af2723
3 changed files with 30 additions and 8 deletions

View File

@ -9,8 +9,8 @@ else()
endif()
set(CMAKE_BUILD_TYPE "Debug")
#set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1")
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1 -DRAY_DETECTION=1")
#set(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1 -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1 -DRAY_DETECTION=1")
#set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DA8_TCP_SESSION2=1 -fsanitize=address -fno-omit-frame-pointer")

View File

@ -7,9 +7,12 @@
#include "metadata.h"
#include "collider.h"
#include "collision.h"
#include "app.h"
void MovementComponent::RayDetection()
{
App::Instance()->perf.ray_times++;
long long tick = a8::XGetTickCount();
Clear();
if (owner->entity_type == ET_Bullet) {
Bullet* bullet = (Bullet*)owner;
@ -19,26 +22,31 @@ void MovementComponent::RayDetection()
target_point = hum->pos + hum->move_dir * (MAP_CELL_WIDTH - MAP_GRID_WIDTH);
target_distance = (target_point - start_point).Norm();
{
long long tick1 = a8::XGetTickCount();
Vector2D left_dir = hum->move_dir;
left_dir.Rotate(-90);
left_dir.Normalize();
Vector2D right_dir = hum->move_dir;
right_dir.Rotate(+90);
right_dir.Normalize();
App::Instance()->perf.params[1] += a8::XGetTickCount() - tick1;
Vector2D left_p0 = left_dir * (hum->meta->i->radius() + 1);
Vector2D left_p1 = left_p0 + hum->move_dir * (MAP_CELL_WIDTH - MAP_GRID_WIDTH);
Vector2D right_p0 = right_dir * (hum->meta->i->radius() + 1);
Vector2D right_p1 = right_p0 + hum->move_dir * (MAP_CELL_WIDTH - MAP_GRID_WIDTH);
Vector2D left_p0 = hum->pos + left_dir * (hum->meta->i->radius() + 1);
Vector2D left_p1 = left_p0 + hum->move_dir * (MAP_CELL_WIDTH - MAP_GRID_WIDTH * 3);
Vector2D right_p0 = hum->pos + right_dir * (hum->meta->i->radius() + 1);
Vector2D right_p1 = right_p0 + hum->move_dir * (MAP_CELL_WIDTH - MAP_GRID_WIDTH * 3);
int count = 0;
for (auto& grid : hum->grid_list) {
for (Entity* entity : grid->entity_list) {
count++;
switch (entity->entity_type) {
case ET_Obstacle:
{
if (
(hum->last_collision_door == nullptr || hum->last_collision_door != entity)
){
long long tick2 = a8::XGetTickCount();
AabbCollider aabb_box;
entity->GetAabbBox(aabb_box);
if (IntersectSegmentAabb(left_p0, left_p1,
@ -50,11 +58,14 @@ void MovementComponent::RayDetection()
) {
detection_objects.insert(entity);
}
App::Instance()->perf.params[3] += a8::XGetTickCount() - tick2;
App::Instance()->perf.params[4]++;
}
}
break;
case ET_Building:
{
long long tick2 = a8::XGetTickCount();
AabbCollider aabb_box;
entity->GetAabbBox(aabb_box);
if (IntersectSegmentAabb(left_p0, left_p1,
@ -66,6 +77,8 @@ void MovementComponent::RayDetection()
) {
detection_objects.insert(entity);
}
App::Instance()->perf.params[3] += a8::XGetTickCount() - tick2;
App::Instance()->perf.params[4]++;
}
break;
default:
@ -74,9 +87,16 @@ void MovementComponent::RayDetection()
break;
}
}
}//end for
if (App::Instance()->perf.params[2] < count) {
App::Instance()->perf.params[2] = count;
}
if (App::Instance()->perf.params[6] < detection_objects.size()) {
App::Instance()->perf.params[6] = detection_objects.size();
}
}
}
App::Instance()->perf.ray_time += a8::XGetTickCount() - tick;
}
void MovementComponent::Clear()

View File

@ -127,6 +127,7 @@ void Player::UpdateMove()
Vector2D old_pos = pos;
pos = pos + move_dir;
if (movement->TestCollision()) {
App::Instance()->perf.params[0]++;
pos = old_pos;
FindPath();
movement->RayDetection();
@ -137,6 +138,7 @@ void Player::UpdateMove()
movement->passed_distance += 1;
if (movement->passed_distance + 10 > movement->target_distance) {
movement->RayDetection();
App::Instance()->perf.params[5]++;
}
}
room->grid_service.MoveHuman(this);
@ -732,8 +734,8 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
move_dir.Normalize();
moving = true;
#ifdef RAY_DETECTION
if (std::abs(move_dir.x - old_move_dir.x) > 0.00001f ||
std::abs(move_dir.y - old_move_dir.y) > 0.00001f) {
if (std::abs(move_dir.x - old_move_dir.x) > 0.0001f ||
std::abs(move_dir.y - old_move_dir.y) > 0.0001f) {
movement->RayDetection();
}
#endif