This commit is contained in:
aozhiwei 2019-03-25 11:37:17 +08:00
commit cc17cbdeca
8 changed files with 67 additions and 74 deletions

View File

@ -148,79 +148,45 @@ void Human::FindPath()
{ {
Vector2D old_pos = pos; Vector2D old_pos = pos;
{ {
float dot = Vector2D::UP.Dot(move_dir); float up_dot = Vector2D::UP.Dot(move_dir);
if (std::abs(dot) <= 0.001f) { //相互垂直 bool at_left_side = Vector2D::LEFT.Dot(move_dir) > 0.0001f;
if (std::abs(up_dot) <= 0.001f) { //相互垂直
//向上 //向上
pos = pos + Vector2D::UP; pos = old_pos + Vector2D::UP;
if (IsCollision()) { if (!IsCollision()) {
return;
} else {
//向下 //向下
pos = old_pos; pos = old_pos + Vector2D::DOWN;
pos = pos + Vector2D::DOWN; if (!IsCollision()) {
if (IsCollision()) {
return; return;
} }
} }
} else if (dot > 0.001f) { //基本相同 } else if (up_dot > 0.001f) { //基本相同
//向右 pos = old_pos + (at_left_side ? Vector2D::LEFT : Vector2D::RIGHT);
pos = pos + Vector2D::RIGHT; if (!IsCollision()) {
if (IsCollision()) { return;
} else {
//向上 //向上
pos = old_pos; pos = old_pos + Vector2D::UP;
pos = pos + Vector2D::UP; if (!IsCollision()) {
if (IsCollision()) {
return; return;
} }
} }
} else if (dot < 0.001f) { //基本相反 } else if (up_dot < 0.001f) { //基本相反
//向右 pos = old_pos + (at_left_side ? Vector2D::LEFT : Vector2D::RIGHT);
pos = pos + Vector2D::RIGHT; if (!IsCollision()) {
if (IsCollision()) { return;
} else {
//向下 //向下
pos = old_pos; pos = old_pos + Vector2D::DOWN;
pos = pos + Vector2D::DOWN; if (!IsCollision()) {
if (IsCollision()) {
return;
}
}
}
}
{
float dot = Vector2D::DOWN.Dot(move_dir);
if (std::abs(dot) <= 0.001f) { //相互垂直
//向下
pos = pos + Vector2D::DOWN;
if (IsCollision()) {
//向上
pos = old_pos;
pos = pos + Vector2D::UP;
if (IsCollision()) {
return;
}
}
} else if (dot > 0.001f) { //基本相同
//向左
pos = pos + Vector2D::LEFT;
if (IsCollision()) {
//向下
pos = old_pos;
pos = pos + Vector2D::DOWN;
if (IsCollision()) {
return;
}
}
} else if (dot < 0.001f) { //基本相反
//向左
pos = pos + Vector2D::LEFT;
if (IsCollision()) {
//向上
pos = old_pos;
pos = pos + Vector2D::UP;
if (IsCollision()) {
return; return;
} }
} }
} }
} }
pos = old_pos;
} }
float Human::GetRadius() float Human::GetRadius()

View File

@ -1,5 +1,7 @@
#include "precompile.h" #include "precompile.h"
#include <float.h>
#include "playermgr.h" #include "playermgr.h"
#include "player.h" #include "player.h"
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
@ -147,11 +149,21 @@ void Player::Shot()
void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg) void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
{ {
bool has_move_dir = msg.has_move_dir();
moving = false;
if (msg.has_move_dir()) { if (msg.has_move_dir()) {
move_dir.FromPB(&msg.move_dir()); if (std::abs(msg.move_dir().x()) > FLT_EPSILON ||
move_dir.Normalize(); std::abs(msg.move_dir().y()) > FLT_EPSILON
) {
move_dir.FromPB(&msg.move_dir());
move_dir.Normalize();
moving = true;
}
} }
assert(!isnan(move_dir.x) && !isnan(move_dir.y));
#if 0
moving = msg.has_move_dir(); moving = msg.has_move_dir();
#endif
if (msg.has_attack_dir()) { if (msg.has_attack_dir()) {
attack_dir.FromPB(&msg.attack_dir()); attack_dir.FromPB(&msg.attack_dir());
attack_dir.Normalize(); attack_dir.Normalize();
@ -201,7 +213,7 @@ void Player::_CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg)
send_func); send_func);
} }
void Player::FillMFPlayerData(cs::MFPlayerData* player_data) void Player::FillMFPlayerData(cs::MFActivePlayerData* player_data)
{ {
player_data->set_has_action(false); player_data->set_has_action(false);
} }

View File

@ -10,7 +10,7 @@ namespace cs
class CMEmote; class CMEmote;
class CMSpectate; class CMSpectate;
class CMVoice; class CMVoice;
class MFPlayerData; class MFActivePlayerData;
} }
class Room; class Room;
@ -55,7 +55,7 @@ class Player : public Human
void _CMSpectate(f8::MsgHdr& hdr, const cs::CMSpectate& msg); void _CMSpectate(f8::MsgHdr& hdr, const cs::CMSpectate& msg);
void _CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg); void _CMVoice(f8::MsgHdr& hdr, const cs::CMVoice& msg);
void FillMFPlayerData(cs::MFPlayerData* player_data); void FillMFPlayerData(cs::MFActivePlayerData* player_data);
private: private:
cs::SMUpdate* update_msg = nullptr; cs::SMUpdate* update_msg = nullptr;

View File

@ -25,7 +25,7 @@ Player* PlayerMgr::GetPlayerBySocket(int socket)
return itr != socket_hash_.end() ? itr->second : nullptr; return itr != socket_hash_.end() ? itr->second : nullptr;
} }
Player* PlayerMgr::CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJoin& msg) Player* PlayerMgr::CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, const cs::CMJoin& msg)
{ {
Player* hum = new Player(); Player* hum = new Player();
hum->entity_uniid = obj_uniid; hum->entity_uniid = obj_uniid;
@ -39,6 +39,7 @@ Player* PlayerMgr::CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJo
hum->use_touch = msg.use_touch(); hum->use_touch = msg.use_touch();
hum->avatar_url = msg.avatar_url(); hum->avatar_url = msg.avatar_url();
hum->energy_shield = msg.energy_shield(); hum->energy_shield = msg.energy_shield();
socket_hash_[socket] = hum;
// hum->baseskin = msg.baseskin(); // hum->baseskin = msg.baseskin();
// hum->basemelee = msg.basemelee(); // hum->basemelee = msg.basemelee();
// hum->elo_score = msg.elo_score(); // hum->elo_score = msg.elo_score();

View File

@ -21,7 +21,7 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
void Update(); void Update();
Player* GetPlayerBySocket(int socket); Player* GetPlayerBySocket(int socket);
Player* CreatePlayerByCMJoin(unsigned short obj_uniid, const cs::CMJoin& msg); Player* CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, const cs::CMJoin& msg);
private: private:
std::map<int, Player*> socket_hash_; std::map<int, Player*> socket_hash_;

View File

@ -139,6 +139,7 @@ void Room::ShuaAndroid()
void Room::ShuaObstacle(Human* hum) void Room::ShuaObstacle(Human* hum)
{ {
#if 0
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(61001); MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(61001);
if (thing) { if (thing) {
Obstacle* entity = new Obstacle(); Obstacle* entity = new Obstacle();
@ -157,6 +158,16 @@ void Room::ShuaObstacle(Human* hum)
pair.second->new_objects.insert(entity); pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity); pair.second->part_objects.insert(entity);
} }
#endif
MetaData::MapThing* a_thing = MetaMgr::Instance()->GetMapThing(61001);
MetaData::MapThing* b_thing = MetaMgr::Instance()->GetMapThing(61007);
if (!a_thing || !b_thing) {
return;
}
{
Obstacle* obj = new Obstacle();
obj->entity_uniid = AllocUniid();
obj->room = this;
} }
} }

View File

@ -47,7 +47,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
room_hash_[room->room_uuid] = room; room_hash_[room->room_uuid] = room;
} }
unsigned short new_uniid = room->AllocUniid(); unsigned short new_uniid = room->AllocUniid();
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(new_uniid, msg); Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, new_uniid, msg);
hum->meta = hum_meta; hum->meta = hum_meta;
hum->socket_handle = hdr.socket_handle; hum->socket_handle = hdr.socket_handle;
hum->Initialize(); hum->Initialize();

View File

@ -228,7 +228,7 @@ message MFLootFull
optional int32 obj_uniid = 1; //id optional int32 obj_uniid = 1; //id
optional MFVector2D pos = 2; // optional MFVector2D pos = 2; //
optional string name = 6; optional int32 item_id = 6;
optional int32 count = 7; optional int32 count = 7;
optional int32 age_ms = 8; optional int32 age_ms = 8;
} }
@ -331,8 +331,8 @@ message MFObjectFull
optional MFSmokeFull union_obj_9 = 10; optional MFSmokeFull union_obj_9 = 10;
} }
// //()
message MFPlayerData message MFActivePlayerData
{ {
optional float boost = 1; optional float boost = 1;
@ -352,6 +352,7 @@ message MFPlayerData
optional int32 spectator_count = 20; optional int32 spectator_count = 20;
} }
//
message MFGasData message MFGasData
{ {
optional int32 mode = 1; //0:inactive 1:waiting 2:moveing optional int32 mode = 1; //0:inactive 1:waiting 2:moveing
@ -373,12 +374,14 @@ message MFTeamData
optional bool downed = 7; optional bool downed = 7;
} }
message MFTeamInfo //
message MFTeammateInfo
{ {
optional int32 team_id = 1; optional int32 team_id = 1;
repeated int32 player_ids = 2; repeated int32 player_ids = 2;
} }
//
message MFBullet message MFBullet
{ {
optional int32 player_id = 1; //id optional int32 player_id = 1; //id
@ -571,12 +574,12 @@ message SMUpdate
repeated MFObjectFull full_objects = 3; //-() repeated MFObjectFull full_objects = 3; //-()
repeated MFObjectPart part_objects = 4; //-() repeated MFObjectPart part_objects = 4; //-()
optional int32 active_player_id = 5; //id(id) optional int32 active_player_id = 5; //id(id)
optional MFPlayerData active_player_data = 6; //() optional MFActivePlayerData active_player_data = 6; //()
optional int32 alive_count = 15; // optional int32 alive_count = 15; //
optional int32 gasT = 16; optional int32 gasT = 16; //
optional MFGasData gas_data = 17; optional MFGasData gas_data = 17; //
repeated MFTeamData team_data = 18; repeated MFTeamData team_data = 18;
repeated MFTeamInfo teams = 19; repeated MFTeammateInfo teams = 19; //
repeated MFBullet bullets = 20; // repeated MFBullet bullets = 20; //
repeated MFShot shots = 21; // repeated MFShot shots = 21; //
repeated MFExplosion explosions = 22; // repeated MFExplosion explosions = 22; //