This commit is contained in:
aozhiwei 2019-04-16 11:14:25 +08:00
parent 06a6dd0806
commit d46e2597ee
5 changed files with 54 additions and 2 deletions

View File

@ -63,6 +63,8 @@ class Human : public Entity
int curr_scope_idx = 0;
std::vector<int> inventory;
bool need_sync_team_data = false;
bool need_sync_teammate_data = false;
bool need_sync_active_player = false;
HumanFrameData frame_data;
@ -73,7 +75,7 @@ class Human : public Entity
int pain_killer_frameno = 0;
xtimer_list* pain_killer_timer = nullptr;
std::set<Human*> friends;
std::set<Human*>* team_members = nullptr;
Human();
virtual ~Human() override;

View File

@ -931,6 +931,12 @@ void Player::MakeUpdateMsg()
}
}
}
if (need_sync_team_data) {
need_sync_team_data = false;
}
if (need_sync_teammate_data) {
need_sync_teammate_data = false;
}
if (send_update_msg_times == 0) {
room->FetchBuilding(this);
}

View File

@ -1,5 +1,7 @@
#include "precompile.h"
#include <random>
#include <a8/mutable_xobject.h>
#include <a8/timer.h>
#include <a8/udplog.h>
@ -17,6 +19,7 @@
#include "loot.h"
#include "collision.h"
#include "roommgr.h"
#include "app.h"
const int ROOM_MAX_PLAYER_NUM = 50;
#if 0
@ -39,6 +42,7 @@ Room::~Room()
void Room::Init()
{
xtimer.Init(RoomXGetTickCount, this, 100, 100);
xtimer_attacher.xtimer = &xtimer;
ShuaAndroid();
CreateThings();
@ -54,10 +58,22 @@ void Room::Init()
}
}
);
if (App::Instance()->flags.find(1) != App::Instance()->flags.end()) {
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * 3,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
room->AutoMatchTeam();
},
&xtimer_attacher.timer_list_);
}
}
void Room::UnInit()
{
xtimer_attacher.ClearTimerList();
if (!stats_timer_) {
a8::Timer::Instance()->DeleteTimer(stats_timer_);
stats_timer_ = nullptr;
@ -875,3 +891,27 @@ void Room::OutputDebugLog()
}
profile.max_rundelay = 0;
}
void Room::AutoMatchTeam()
{
std::vector<Human*> humans;
for (auto& pair : human_hash_) {
humans.push_back(pair.second);
}
std::random_shuffle(humans.begin(), humans.end());
std::set<Human*>* team_members = nullptr;
for (size_t i = 0; i < humans.size(); ++i) {
if (i % 4 == 0) {
++current_teamid;
team_hash_[current_teamid] = std::set<Human*>();
auto itr = team_hash_.find(current_teamid);
team_members = &itr->second;
}
humans[i]->team_id = current_teamid;
humans[i]->team_members = team_members;
humans[i]->need_sync_team_data = true;
humans[i]->need_sync_teammate_data = true;
humans[i]->need_sync_active_player = true;
team_members->insert(humans[i]);
}
}

View File

@ -85,15 +85,19 @@ private:
bool GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float small_circle_rad,
Vector2D& out_pos);
void OutputDebugLog();
void AutoMatchTeam();
private:
timer_list* stats_timer_ = nullptr;
int elapsed_time_ = 0;
int alive_count_ = 0;
a8::XTimerAttacher xtimer_attacher;
int current_teamid = 0;
unsigned short current_uniid = 0;
RoomState_e state_ = RS_Inactive;
std::map<int, std::set<Human*>> team_hash_;
std::map<std::string, Player*> accountid_hash_;
std::map<unsigned short, Entity*> moveable_hash_;
std::map<unsigned short, Entity*> uniid_hash_;

View File

@ -615,7 +615,7 @@ message SMUpdate
optional MFVector2D gas_pos_old = 30; //
optional MFGasData gas_data = 17; //
repeated MFTeamData team_data = 18; //
repeated MFTeammateInfo teammate_data = 19; //()
optional MFTeammateInfo teammate_data = 19; //()
repeated MFBullet bullets = 20; //
repeated MFShot shots = 21; //
repeated MFExplosion explosions = 22; //