add framedata.* vector2d.*
This commit is contained in:
parent
d1e2cc438f
commit
b814b2af96
@ -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";
|
||||
|
||||
|
0
server/gameserver/framedata.cc
Normal file
0
server/gameserver/framedata.cc
Normal file
17
server/gameserver/framedata.h
Normal file
17
server/gameserver/framedata.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "cs_proto.pb.h"
|
||||
|
||||
struct RoomFrameData
|
||||
{
|
||||
std::set<unsigned short> deleted_objects;
|
||||
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFExplosion>> explosions_hash;
|
||||
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>> smokes_hash;
|
||||
::google::protobuf::RepeatedPtrField<::cs::MFEmote> emotes;
|
||||
::google::protobuf::RepeatedPtrField<::cs::MFBullet> bullets;
|
||||
::google::protobuf::RepeatedPtrField<::cs::MFShot> shots;
|
||||
};
|
||||
|
||||
struct HumanFrameData
|
||||
{
|
||||
};
|
@ -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
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <a8/udplog.h>
|
||||
|
||||
#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"
|
||||
|
||||
|
@ -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<unsigned short> deleted_objects;
|
||||
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFExplosion>> explosions_hash;
|
||||
std::map<long long, ::google::protobuf::RepeatedPtrField<::cs::MFSmoke>> 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;
|
||||
|
@ -1,141 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#if 1
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#else
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Dense>
|
||||
#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 <Eigen/Core>
|
||||
#include <Eigen/Dense>
|
||||
#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);
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
137
server/gameserver/vector2d.cc
Normal file
137
server/gameserver/vector2d.cc
Normal file
@ -0,0 +1,137 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#if 1
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/vec2.hpp>
|
||||
#else
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Dense>
|
||||
#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 <Eigen/Core>
|
||||
#include <Eigen/Dense>
|
||||
#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));
|
||||
}
|
36
server/gameserver/vector2d.h
Normal file
36
server/gameserver/vector2d.h
Normal file
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user