From b814b2af96266f7fa63db38ba1cceb3dc089bf44 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 10 Apr 2019 19:46:31 +0800 Subject: [PATCH] add framedata.* vector2d.* --- server/gameserver/constant.h | 7 ++ server/gameserver/framedata.cc | 0 server/gameserver/framedata.h | 17 ++++ server/gameserver/human.h | 25 +----- server/gameserver/precompile.h | 2 + server/gameserver/room.h | 19 +---- server/gameserver/types.cc | 134 -------------------------------- server/gameserver/types.h | 53 +++++-------- server/gameserver/vector2d.cc | 137 +++++++++++++++++++++++++++++++++ server/gameserver/vector2d.h | 36 +++++++++ 10 files changed, 220 insertions(+), 210 deletions(-) create mode 100644 server/gameserver/framedata.cc create mode 100644 server/gameserver/framedata.h create mode 100644 server/gameserver/vector2d.cc create mode 100644 server/gameserver/vector2d.h diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index e1a5fed..56f5212 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -83,6 +83,13 @@ enum InventorySlot_e IS_15XSCOPE = 16, }; +enum RoomState_e +{ + RS_Inactive = 0, + RS_Waiting = 1, + RS_Moveing = 2 +}; + const char* const PROJ_NAME_FMT = "game%d_gameserver"; const char* const PROJ_ROOT_FMT = "/data/logs/%s"; diff --git a/server/gameserver/framedata.cc b/server/gameserver/framedata.cc new file mode 100644 index 0000000..e69de29 diff --git a/server/gameserver/framedata.h b/server/gameserver/framedata.h new file mode 100644 index 0000000..9328ee6 --- /dev/null +++ b/server/gameserver/framedata.h @@ -0,0 +1,17 @@ +#pragma once + +#include "cs_proto.pb.h" + +struct RoomFrameData +{ + std::set deleted_objects; + std::map> explosions_hash; + std::map> smokes_hash; + ::google::protobuf::RepeatedPtrField<::cs::MFEmote> emotes; + ::google::protobuf::RepeatedPtrField<::cs::MFBullet> bullets; + ::google::protobuf::RepeatedPtrField<::cs::MFShot> shots; +}; + +struct HumanFrameData +{ +}; diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 1785758..2e2b6ab 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -1,7 +1,7 @@ #pragma once #include "entity.h" -#include "cs_proto.pb.h" +#include "framedata.h" namespace MetaData { @@ -9,29 +9,6 @@ namespace MetaData struct Equip; } -struct HumanFrameData -{ -}; - -struct PlayerStats -{ - int kills = 0; - int damage_amount = 0; - int heal_amount = 0; - - int history_time_alive = 0; - int history_kills = 0; - int history_damage_amount = 0; - int history_heal_amount = 0; - - int gold = 0; - int score = 0; - - int killer_id = 0; - std::string killer_name; - -}; - class CircleCollider; class Obstacle; class Human : public Entity diff --git a/server/gameserver/precompile.h b/server/gameserver/precompile.h index 20e7d9a..e9f30c3 100644 --- a/server/gameserver/precompile.h +++ b/server/gameserver/precompile.h @@ -4,6 +4,7 @@ #include #include "constant.h" +#include "vector2d.h" #include "types.h" #include "error_code.h" #include "global.h" @@ -20,3 +21,4 @@ namespace google #include "framework/cpp/types.h" #include "framework/cpp/protoutils.h" + diff --git a/server/gameserver/room.h b/server/gameserver/room.h index b232a7e..6c75b7b 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -1,13 +1,6 @@ #pragma once -#include "cs_proto.pb.h" - -enum RoomState_e -{ - RS_Inactive = 0, - RS_Waiting = 1, - RS_Moveing = 2 -}; +#include "framedata.h" namespace MetaData { @@ -16,16 +9,6 @@ namespace MetaData struct Building; } -struct RoomFrameData -{ - std::set deleted_objects; - std::map> explosions_hash; - std::map> smokes_hash; - ::google::protobuf::RepeatedPtrField<::cs::MFEmote> emotes; - ::google::protobuf::RepeatedPtrField<::cs::MFBullet> bullets; - ::google::protobuf::RepeatedPtrField<::cs::MFShot> shots; -}; - class Entity; class Bullet; class Human; diff --git a/server/gameserver/types.cc b/server/gameserver/types.cc index cc91bf2..1473792 100644 --- a/server/gameserver/types.cc +++ b/server/gameserver/types.cc @@ -1,141 +1,7 @@ #include "precompile.h" -#if 1 -#include -#include -#include -#else -#include -#include -#endif - #include "cs_proto.pb.h" -const Vector2D Vector2D::UP = Vector2D(0.0f, 1.0f); -const Vector2D Vector2D::RIGHT = Vector2D(1.0f, 0.0f); -const Vector2D Vector2D::DOWN = Vector2D(0.0f, -1.0f); -const Vector2D Vector2D::LEFT = Vector2D(-1.0f, 0.0f); - -void Vector2D::ToPB(cs::MFVector2D* pb_obj) -{ - pb_obj->set_x(x); - pb_obj->set_y(y); -} - -void Vector2D::FromPB(const cs::MFVector2D* pb_obj) -{ - x = pb_obj->x(); - y = pb_obj->y(); -} - -void Vector2D::Normalize() -{ - #if 1 - glm::vec2 v = glm::normalize(glm::vec2(x, y)); - x = v[0]; - y = v[1]; - #else - Eigen::Vector2f v(x, y); - v.normalize(); - x = v[0]; - y = v[1]; - #endif -} - -bool Vector2D::operator == (const Vector2D& b) const -{ - return std::abs(x - b.x) < 0.01f && std::abs(y - b.y) < 0.01f; -} - -Vector2D Vector2D::operator + (const Vector2D& b) const -{ - #if 1 - glm::vec2 v = glm::vec2(x, y) + glm::vec2(b.x, b.y); - return Vector2D(v[0], v[1]); - #else - Eigen::Vector2f v = Eigen::Vector2f(x, y) + Eigen::Vector2f(b.x, b.y); - return Vector2D(v[0], v[1]); - #endif -} - -Vector2D Vector2D::operator - (const Vector2D& b) const -{ - #if 1 - glm::vec2 v = glm::vec2(x, y) - glm::vec2(b.x, b.y); - return Vector2D(v[0], v[1]); - #else - Eigen::Vector2f v = Eigen::Vector2f(x, y) - Eigen::Vector2f(b.x, b.y); - return Vector2D(v[0], v[1]); - #endif -} - -Vector2D Vector2D::operator * (float scale) const -{ - #if 1 - glm::vec2 v = glm::vec2(x, y) * scale; - return Vector2D(v[0], v[1]); - #else - Eigen::Vector2f v = Eigen::Vector2f(x, y) * scale; - return Vector2D(v[0], v[1]); - #endif -} - -Vector2D Vector2D::operator / (float scale) const -{ - #if 1 - glm::vec2 v = glm::vec2(x, y) / scale; - return Vector2D(v[0], v[1]); - #else - Eigen::Vector2f v = Eigen::Vector2f(x, y) * (1.0 / scale); - return Vector2D(v[0], v[1]); - #endif -} - -#if 1 -#include -#include -#endif - -void Vector2D::Rotate(float angle) -{ - Eigen::Vector3f v(x, y, 0); - v = Eigen::AngleAxisf(angle * 3.1415926f, Eigen::Vector3f::UnitZ()) * v; - x = v[0]; - y = v[1]; -} - -float Vector2D::CalcAngle(const Vector2D& b) -{ - float a1 = acos(Dot(b) / Norm() / b.Norm()); - float a2 = atan2(y, x); - float a3 = atan2(y, x) / 0.017 - 90.0f; - #if 0 - return a2; - #else - bool at_right_side = Vector2D::RIGHT.Dot(*this) > 0.0001f; - if (at_right_side) { - a1 = -a1; - } - return a1 / 3.1415926f; - // return a3 / 360.0f; - #endif -} - -Vector2D Vector2D::Perp() -{ - return Vector2D(y, -x); -} - -float Vector2D::Dot(const Vector2D& v) const -{ - return x*v.x + y*v.y; -} - -float Vector2D::Norm() const -{ - return fabs(sqrt(x*x + y*y)); -} - void Weapon::ToPB(cs::MFWeapon* pb_obj) { pb_obj->set_weapon_id(weapon_id); diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 03a20d8..065e59b 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -9,40 +9,6 @@ struct PerfMonitor long long read_count = 0; }; -namespace cs -{ - class MFVector2D; - class MFWeapon; -} - -struct Vector2D -{ - float x = 0.0f; - float y = 0.0f; - - Vector2D(float _x = 0.0f, float _y = 0.0f):x(_x), y(_y) {}; - - void ToPB(cs::MFVector2D* pb_obj); - void FromPB(const cs::MFVector2D* pb_obj); - void Normalize(); - void Rotate(float angle); - float CalcAngle(const Vector2D& b); - - bool operator == (const Vector2D& b) const; - Vector2D operator + (const Vector2D& b) const; - Vector2D operator - (const Vector2D& b) const; - Vector2D operator * (float scale) const; - Vector2D operator / (float scale) const; - Vector2D Perp(); - float Dot(const Vector2D& v) const; - float Norm() const; - - static const Vector2D UP; - static const Vector2D DOWN; - static const Vector2D LEFT; - static const Vector2D RIGHT; -}; - namespace MetaData { struct SafeArea; @@ -75,3 +41,22 @@ struct Weapon void ToPB(cs::MFWeapon* pb_obj); }; + +struct PlayerStats +{ + int kills = 0; + int damage_amount = 0; + int heal_amount = 0; + + int history_time_alive = 0; + int history_kills = 0; + int history_damage_amount = 0; + int history_heal_amount = 0; + + int gold = 0; + int score = 0; + + int killer_id = 0; + std::string killer_name; + +}; diff --git a/server/gameserver/vector2d.cc b/server/gameserver/vector2d.cc new file mode 100644 index 0000000..390a5a4 --- /dev/null +++ b/server/gameserver/vector2d.cc @@ -0,0 +1,137 @@ +#include "precompile.h" + +#if 1 +#include +#include +#include +#else +#include +#include +#endif + +#include "cs_proto.pb.h" + +const Vector2D Vector2D::UP = Vector2D(0.0f, 1.0f); +const Vector2D Vector2D::RIGHT = Vector2D(1.0f, 0.0f); +const Vector2D Vector2D::DOWN = Vector2D(0.0f, -1.0f); +const Vector2D Vector2D::LEFT = Vector2D(-1.0f, 0.0f); + +void Vector2D::ToPB(cs::MFVector2D* pb_obj) +{ + pb_obj->set_x(x); + pb_obj->set_y(y); +} + +void Vector2D::FromPB(const cs::MFVector2D* pb_obj) +{ + x = pb_obj->x(); + y = pb_obj->y(); +} + +void Vector2D::Normalize() +{ + #if 1 + glm::vec2 v = glm::normalize(glm::vec2(x, y)); + x = v[0]; + y = v[1]; + #else + Eigen::Vector2f v(x, y); + v.normalize(); + x = v[0]; + y = v[1]; + #endif +} + +bool Vector2D::operator == (const Vector2D& b) const +{ + return std::abs(x - b.x) < 0.01f && std::abs(y - b.y) < 0.01f; +} + +Vector2D Vector2D::operator + (const Vector2D& b) const +{ + #if 1 + glm::vec2 v = glm::vec2(x, y) + glm::vec2(b.x, b.y); + return Vector2D(v[0], v[1]); + #else + Eigen::Vector2f v = Eigen::Vector2f(x, y) + Eigen::Vector2f(b.x, b.y); + return Vector2D(v[0], v[1]); + #endif +} + +Vector2D Vector2D::operator - (const Vector2D& b) const +{ + #if 1 + glm::vec2 v = glm::vec2(x, y) - glm::vec2(b.x, b.y); + return Vector2D(v[0], v[1]); + #else + Eigen::Vector2f v = Eigen::Vector2f(x, y) - Eigen::Vector2f(b.x, b.y); + return Vector2D(v[0], v[1]); + #endif +} + +Vector2D Vector2D::operator * (float scale) const +{ + #if 1 + glm::vec2 v = glm::vec2(x, y) * scale; + return Vector2D(v[0], v[1]); + #else + Eigen::Vector2f v = Eigen::Vector2f(x, y) * scale; + return Vector2D(v[0], v[1]); + #endif +} + +Vector2D Vector2D::operator / (float scale) const +{ + #if 1 + glm::vec2 v = glm::vec2(x, y) / scale; + return Vector2D(v[0], v[1]); + #else + Eigen::Vector2f v = Eigen::Vector2f(x, y) * (1.0 / scale); + return Vector2D(v[0], v[1]); + #endif +} + +#if 1 +#include +#include +#endif + +void Vector2D::Rotate(float angle) +{ + Eigen::Vector3f v(x, y, 0); + v = Eigen::AngleAxisf(angle * 3.1415926f, Eigen::Vector3f::UnitZ()) * v; + x = v[0]; + y = v[1]; +} + +float Vector2D::CalcAngle(const Vector2D& b) +{ + float a1 = acos(Dot(b) / Norm() / b.Norm()); + float a2 = atan2(y, x); + float a3 = atan2(y, x) / 0.017 - 90.0f; + #if 0 + return a2; + #else + bool at_right_side = Vector2D::RIGHT.Dot(*this) > 0.0001f; + if (at_right_side) { + a1 = -a1; + } + return a1 / 3.1415926f; + // return a3 / 360.0f; + #endif +} + +Vector2D Vector2D::Perp() +{ + return Vector2D(y, -x); +} + +float Vector2D::Dot(const Vector2D& v) const +{ + return x*v.x + y*v.y; +} + +float Vector2D::Norm() const +{ + return fabs(sqrt(x*x + y*y)); +} diff --git a/server/gameserver/vector2d.h b/server/gameserver/vector2d.h new file mode 100644 index 0000000..682d907 --- /dev/null +++ b/server/gameserver/vector2d.h @@ -0,0 +1,36 @@ +#pragma once + +namespace cs +{ + class MFVector2D; + class MFWeapon; +} + +struct Vector2D +{ + float x = 0.0f; + float y = 0.0f; + + Vector2D(float _x = 0.0f, float _y = 0.0f):x(_x), y(_y) {}; + + void ToPB(cs::MFVector2D* pb_obj); + void FromPB(const cs::MFVector2D* pb_obj); + void Normalize(); + void Rotate(float angle); + float CalcAngle(const Vector2D& b); + + bool operator == (const Vector2D& b) const; + Vector2D operator + (const Vector2D& b) const; + Vector2D operator - (const Vector2D& b) const; + Vector2D operator * (float scale) const; + Vector2D operator / (float scale) const; + Vector2D Perp(); + float Dot(const Vector2D& v) const; + float Norm() const; + + static const Vector2D UP; + static const Vector2D DOWN; + static const Vector2D LEFT; + static const Vector2D RIGHT; +}; +