remove obb

This commit is contained in:
aozhiwei 2019-04-02 14:00:02 +08:00
parent 5a871025ec
commit f36d0a8383
5 changed files with 35 additions and 98 deletions

View File

@ -73,3 +73,4 @@ const int SERVER_FRAME_RATE = 20;
const int SYNC_FRAME_RATE = 10;
const int MAX_INVENTORY_NUM = 14;
const int MAX_WEAPON_NUM = 5;

View File

@ -12,6 +12,19 @@ Human::Human()
{
movement = new MovementComponent();
movement->owner = this;
default_weapon.weapon_idx = 0;
default_weapon.weapon_id = 12102;
default_weapon.weapon_lv = 1;
weapons.reserve(MAX_WEAPON_NUM);
for (size_t i = 0; i < MAX_WEAPON_NUM; ++i) {
auto& weapon = a8::FastAppend(weapons);
weapon.weapon_idx = i;
weapon.weapon_id = 0;
weapon.weapon_lv = 0;
weapon.num = 0;
}
weapons[0] = default_weapon;
curr_weapon = &weapons[0];
}
Human::~Human()
@ -57,9 +70,7 @@ void Human::FillMFObjectFull(cs::MFObjectFull* full_data)
p->set_helmet(helmet);
p->set_chest(chest);
#if 0
p->set_weapon(weapon);
#endif
curr_weapon->ToPB(p->mutable_weapon());
p->set_energy_shield(energy_shield);
p->set_vip(vip);
p->set_sdmg(sdmg);
@ -74,9 +85,7 @@ void Human::Shot(Vector2D& target_dir)
{
cs::MFShot* shot = room->frame_data.shots.Add();
shot->set_player_id(entity_uniid);
#if 0
shot->set_weapon_id(weapon_meta->i->id());
#endif
curr_weapon->ToPB(shot->mutable_weapon());
shot->set_offhand(true);
shot->set_bullskin(10001);
}

View File

@ -48,6 +48,10 @@ class Human : public Entity
long long dead_frameno = 0;
bool game_over = false;
Weapon default_weapon;
std::vector<Weapon> weapons;
Weapon* curr_weapon = nullptr;
HumanFrameData frame_data;
std::set<Human*> my_seen_players;

View File

@ -119,97 +119,9 @@ float Vector2D::Norm()
return fabs(sqrt(x*x + y*y));
}
#if 0
struct Segment
void Weapon::ToPB(cs::MFWeapon* pb_obj)
{
Vector2D p0;
Vector2D p1;
Vector2D dir;
Segment(const Vector2D& p0_, const Vector2D& p1_)
{
p0 = p0_;
p1 = p1_;
dir = p1 - p0;
}
};
struct Polygon
{
std::vector<Vector2D> vertices;
std::vector<Segment> edges;
std::tuple<float, float> Project(Vector2D axis)
{
axis = axis.Normalize();
float min_v = vertices[0].Dot(axis);
float max_v = min_v;
for (size_t i = 0; i < vertices.size(); ++i) {
float proj = vertices[i].Dot(axis);
if (proj < min_v) {
min_v = proj;
}
if (proj > max_v) {
max_v = proj;
}
}
return std::make_tuple(min_v, max_v);
}
bool Contains(float n, std::tuple<float, float>& range)
{
float a = std::get<0>(range);
float b = std::get<1>(range);
if (b < a) {
a = b;
b = std::get<0>(range);
}
return n >= a && n <= b;
}
bool Overlap(std::tuple<float, float>& a, std::tuple<float, float>& b)
{
return
Contains(std::get<0>(a), b) ||
Contains(std::get<1>(a), b) ||
Contains(std::get<0>(b), a) ||
Contains(std::get<1>(b), a);
}
bool Sat(Polygon& b)
{
for (size_t i = 0; i < vertices.size(); ++i) {
Vector2D axis = edges[i].dir;
axis = axis.Perp();
auto a_ = Project(axis);
auto b_ = b.Project(axis);
if (!Overlap(a_, b_)) {
return false;
}
}
for (size_t i = 0; i < b.vertices.size(); ++i) {
Vector2D axis = b.edges[i].dir;
axis = axis.Perp();
auto a_ = Project(axis);
auto b_ = b.Project(axis);
if (!Overlap(a_, b_)) {
return false;
}
}
return true;
}
};
static Polygon newPolygon(std::vector<Vector2D>& vertices)
{
Polygon shape;
shape.vertices = vertices;
for (int i = 0; i < vertices.size() - 1; ++i) {
shape.edges.push_back(Segment(vertices[i + 1], vertices[i]));
}
shape.edges.push_back(Segment(vertices[vertices.size() - 1], vertices[0]));
return shape;
pb_obj->set_weapon_id(weapon_id);
pb_obj->set_weapon_lv(weapon_lv);
pb_obj->set_num(num);
}
#endif

View File

@ -12,6 +12,7 @@ struct PerfMonitor
namespace cs
{
class MFVector2D;
class MFWeapon;
}
struct Vector2D
@ -61,3 +62,13 @@ struct GasData
MetaData::SafeArea* new_area_meta = nullptr;
bool is_last_gas = false;
};
struct Weapon
{
int weapon_idx = 0;
int weapon_id = 0;
int weapon_lv = 0;
int num = 0;
void ToPB(cs::MFWeapon* pb_obj);
};