Compare commits

...

17 Commits
master ... dev

Author SHA1 Message Date
aozhiwei
8239e61794 merge master 2020-08-10 17:28:46 +08:00
aozhiwei
ee7e8e2c28 1 2020-07-28 10:37:49 +08:00
aozhiwei
c76b11503c 1 2020-07-20 17:57:46 +08:00
aozhiwei
14ed14f067 merge test 2020-07-20 17:07:00 +08:00
aozhiwei
580a9e1519 1 2020-07-20 14:49:04 +08:00
aozhiwei
3c3c897625 移除飞机逻辑 2020-07-20 14:44:15 +08:00
aozhiwei
1439a6b612 1 2020-07-08 10:47:56 +08:00
aozhiwei
e7fca225b6 1 2020-07-08 10:47:13 +08:00
aozhiwei
d4a8e500c9 流量优化 2020-07-07 20:40:30 +08:00
aozhiwei
aff0fdb0c8 流量优化 alive_count 2020-07-07 20:25:38 +08:00
aozhiwei
e55e61026b 流量优化 2020-07-07 19:50:49 +08:00
aozhiwei
bcf7da98fe 1 2020-07-07 19:35:33 +08:00
aozhiwei
c053c76844 1 2020-07-07 19:27:04 +08:00
aozhiwei
e4fe7b7006 客户端缓存ok 2020-07-07 19:24:21 +08:00
aozhiwei
5c55dc75d2 重构FillMFObjectPart FillMFObjectFull 2020-07-07 18:49:27 +08:00
aozhiwei
4fcf8e5a75 升级a8 f8 2020-07-07 17:22:10 +08:00
aozhiwei
1740a0faaa 1 2020-07-07 15:51:20 +08:00
26 changed files with 395 additions and 69 deletions

View File

@ -31,25 +31,25 @@ def getExeCmdLine(pid):
def stop(instance_id, node_id, times = 0):
if times > 2:
return
gameserver_ids = getRuningProgramPids('gameserver')
gameserver_ids = getRuningProgramPids('gameserver2001')
pids = gameserver_ids
for pid in pids:
exepath = getExePath(pid)
cmdline = getExeCmdLine(pid)
if cmdline.find("./gameserver\0-i\0%d\0-n\0%d\0" % (instance_id, node_id)) > -1:
if cmdline.find("./gameserver2001\0-i\0%d\0-n\0%d\0" % (instance_id, node_id)) > -1:
os.popen('kill -9 %d' % int(pid))
#endfor
gameserver_ids = getRuningProgramPids('gameserver')
gameserver_ids = getRuningProgramPids('gameserver2001')
pids = gameserver_ids
for pid in pids:
exepath = getExePath(pid)
cmdline = getExeCmdLine(pid)
if cmdline.find("./gameserver\0-i\0%d\0-n\0%d\0" % (instance_id, node_id)) > -1:
if cmdline.find("./gameserver2001\0-i\0%d\0-n\0%d\0" % (instance_id, node_id)) > -1:
time.sleep(1)
stop(instance_id, node_id, times + 1)
def listServer():
gameserver_ids = getRuningProgramPids('gameserver')
gameserver_ids = getRuningProgramPids('gameserver2001')
pids = gameserver_ids
for pid in pids:
exepath = getExePath(pid)
@ -63,7 +63,7 @@ def restartServer(str_instance_ids, str_node_id):
instance_id = int(instance_id)
stop(instance_id, node_id)
time.sleep(0.5)
print('gameserver %d starting......' % instance_id)
print('gameserver2001 %d starting......' % instance_id)
cmd = 'sh start_instance.sh %d %d' % (instance_id, node_id)
os.popen(cmd)
time.sleep(0.5)

View File

@ -3,5 +3,5 @@
source /etc/profile
source /root/.bash_profile
nohup ./gameserver -i $1 -n $2 -f1,2,3,4,6>> gameserver$2_$1.out 2>&1 &
nohup ./gameserver2001 -i $1 -n $2 >> gameserver$2_$1.out 2>&1 &

View File

@ -90,6 +90,9 @@ void AndroidAI::ChangeToState(AndroidState_e to_state)
void AndroidAI::DoMove()
{
Human* hum = (Human*)owner;
if (hum->room->IsWaitingStart()) {
return;
}
if (a8::HasBitFlag(hum->status, HS_Fly)) {
return;
}
@ -118,6 +121,9 @@ void AndroidAI::DoAttack()
a8::HasBitFlag(hum->status, HS_Jump)) {
return;
}
if (hum->room->IsWaitingStart()) {
return;
}
if (hum->room->gas_data.gas_mode == GasInactive) {
return;
}

View File

@ -39,7 +39,7 @@ void Building::RecalcSelfCollider()
}
}
void Building::FillMFObjectPart(cs::MFObjectPart* part_data)
void Building::FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Building);
cs::MFBuildingPart* p = part_data->mutable_union_obj_3();
@ -47,10 +47,28 @@ void Building::FillMFObjectPart(cs::MFObjectPart* part_data)
TypeConvert::ToPb(pos, p->mutable_pos());
}
void Building::FillMFObjectFull(cs::MFObjectFull* full_data)
void Building::FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Building);
if (IsClientCached(hum)) {
int object_flags = 0;
a8::SetBitFlag(object_flags, kOfReadCache);
full_data->set_obj_uniid(GetEntityUniId());
full_data->set_object_flags(object_flags);
return;
}
cs::MFBuildingFull* p = full_data->mutable_union_obj_3();
if (CanClientCache(hum)) {
int object_flags = 0;
a8::SetBitFlag(object_flags, kOfWriteCache);
#if 0
full_data->set_obj_uniid(GetEntityUniId());
#endif
full_data->set_object_flags(object_flags);
AddClientCache(hum);
}
p->set_obj_uniid(entity_uniid);
TypeConvert::ToPb(pos, p->mutable_pos());

View File

@ -22,7 +22,7 @@ class Building : public Entity
virtual ~Building() override;
virtual void Initialize() override;
void RecalcSelfCollider();
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
virtual void FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data) override;
virtual void GetAabbBox(AabbCollider& aabb_box) override;
};

View File

@ -179,6 +179,17 @@ enum MapObjectType_e
kMOT_SpawnPoint = 2
};
enum ObjectFlags_e
{
kOfWriteCache = 0,
kOfReadCache = 1,
};
enum ObjectSyncFlags_e
{
kOsfIsDead = 0,
};
const char* const PROJ_NAME_FMT = "game%d_gameserver";
const char* const PROJ_ROOT_FMT = "/data/logs/%s";
@ -219,3 +230,5 @@ const int MAX_ALL_HTTP_NUM = MAX_SYS_HTTP_NUM + MAX_USER_HTTP_NUM;
const int DEFAULT_BORN_POINT_X = 3000;
const int DEFAULT_BORN_POINT_Y = 3000;
const int FIXED_OBJECT_MAXID = 1024;
const int VIEW_RANGE = 512;

View File

@ -6,6 +6,7 @@
#include "building.h"
#include "human.h"
#include "app.h"
#include "obstacle.h"
Entity::Entity()
{
@ -109,3 +110,50 @@ void Entity::AddCollider(ColliderComponent* collider)
{
colliders.push_back(collider);
}
bool Entity::IsClientCached(Human* hum)
{
ObjectSyncFlags* sync_flags = hum->GetObjectSyncFlags(GetEntityUniId());
if (sync_flags) {
int flags = sync_flags->flags;
if (IsDead(hum->room)) {
if (a8::HasBitFlag(flags, kOsfIsDead)) {
return sync_flags->last_sync_frameno > 0;
} else {
return false;
}
} else {
if (!a8::HasBitFlag(flags, kOsfIsDead)) {
return sync_flags->last_sync_frameno > 0;
} else {
return false;
}
}
}
return false;
}
bool Entity::CanClientCache(Human* hum)
{
ObjectSyncFlags* sync_flags = hum->GetObjectSyncFlags(GetEntityUniId());
if (sync_flags && entity_type == ET_Obstacle) {
Obstacle* obstacle = (Obstacle*)this;
return !obstacle->is_door;
}
return sync_flags != nullptr;
}
void Entity::AddClientCache(Human* hum)
{
ObjectSyncFlags* sync_flags = hum->GetObjectSyncFlags(GetEntityUniId());
if (sync_flags) {
int flags = sync_flags->flags;
if (IsDead(hum->room)) {
a8::SetBitFlag(flags, kOsfIsDead);
} else {
a8::UnSetBitFlag(flags, kOsfIsDead);
}
sync_flags->flags = flags;
sync_flags->last_sync_frameno = hum->room->GetFrameNo();
}
}

View File

@ -8,6 +8,7 @@ namespace cs
class MFObjectFull;
}
class Human;
class Room;
class Obstacle;
class ColliderComponent;
@ -36,8 +37,8 @@ class Entity
virtual ~Entity();
virtual void Initialize();
virtual void Update(int delta_time) {};
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) {};
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) {};
virtual void FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data) {};
virtual void FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data) {};
virtual float GetSpeed() { return 1.0f;};
virtual void GetAabbBox(AabbCollider& aabb_box);
virtual void GetCircleBox(CircleCollider& circle_box);
@ -47,6 +48,13 @@ class Entity
void BroadcastFullState();
void BroadcastDeleteState();
void AddCollider(ColliderComponent* collider);
int GetEntityUniId() const { return entity_uniid; }
virtual bool IsDead(Room* room) { return dead;};
protected:
bool IsClientCached(Human* hum);
bool CanClientCache(Human* hum);
void AddClientCache(Human* hum);
private:
std::list<ColliderComponent*> colliders;

View File

@ -47,8 +47,10 @@ void FrameEvent::AddShot(Human* hum)
} else {
hum->curr_weapon->ToPB(p.mutable_weapon());
}
#if 0
p.set_offhand(true);
p.set_bullskin(10001);
#endif
}
{
int shot_idx = shots_.size() - 1;
@ -75,7 +77,9 @@ void FrameEvent::AddBullet(Human* hum, a8::Vec2 born_pos, a8::Vec2 dir, float fl
}
TypeConvert::ToPb(born_pos, p.mutable_pos());
TypeConvert::ToPb(dir, p.mutable_dir());
#if 0
p.set_bulletskin(10001);
#endif
if (hum->tank_weapon.meta) {
p.set_gun_id(hum->tank_weapon.meta->i->id());
p.set_gun_lv(hum->tank_weapon.weapon_lv);

View File

@ -21,7 +21,7 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
a8::HasBitFlag(((Human*)itr)->status, HS_Fly)) {
continue;
}
itr->FillMFObjectFull(msg->add_full_objects());
itr->FillMFObjectFull((Human*)hum, msg->add_full_objects());
}
for (auto& itr : hum->part_objects) {
Entity* entity = itr;
@ -35,7 +35,10 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
continue;
}
}
entity->FillMFObjectPart(msg->add_part_objects());
if (((Human*)hum)->pos.ManhattanDistance(entity->pos) > VIEW_RANGE + 200) {
continue;
}
entity->FillMFObjectPart((Human*)hum, msg->add_part_objects());
}
for (auto& itr : hum->del_objects) {
msg->add_del_objids(itr);
@ -151,7 +154,10 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(const Human* hum)
msg->set_gas_progress(room->gas_data.gas_progress);
TypeConvert::ToPb(room->gas_data.pos_old, msg->mutable_gas_pos_old());
}
msg->set_alive_count(room->AliveCount());
if (room->GetFrameNo() - room->AliveCountChgFrameNo() <= 4 ||
room->GetFrameNo() - hum->join_frameno <= 2) {
msg->set_alive_count(room->AliveCount());
}
}
return msg;
}

View File

@ -32,7 +32,7 @@ void Hero::RecalcSelfCollider()
self_collider_->rad = master->GetRadius();
}
void Hero::FillMFObjectPart(cs::MFObjectPart* part_data)
void Hero::FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(entity_type);
cs::MFHeroPart* p = part_data->mutable_union_obj_10();
@ -41,7 +41,7 @@ void Hero::FillMFObjectPart(cs::MFObjectPart* part_data)
TypeConvert::ToPb(attack_dir, p->mutable_dir());
}
void Hero::FillMFObjectFull(cs::MFObjectFull* full_data)
void Hero::FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(entity_type);
cs::MFHeroFull* p = full_data->mutable_union_obj_10();

View File

@ -26,8 +26,8 @@ class Hero : public Entity
virtual ~Hero() override;
virtual void Initialize() override;
void RecalcSelfCollider();
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
virtual void FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data) override;
private:
CircleCollider* self_collider_ = nullptr;

View File

@ -93,7 +93,7 @@ float Human::GetSpeed4()
return meta->i->move_speed4();
}
void Human::FillMFObjectPart(cs::MFObjectPart* part_data)
void Human::FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Player);
cs::MFPlayerPart* p = part_data->mutable_union_obj_1();
@ -102,7 +102,7 @@ void Human::FillMFObjectPart(cs::MFObjectPart* part_data)
TypeConvert::ToPb(attack_dir, p->mutable_dir());
}
void Human::FillMFObjectFull(cs::MFObjectFull* full_data)
void Human::FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Player);
cs::MFPlayerFull* p = full_data->mutable_union_obj_1();
@ -238,15 +238,25 @@ void Human::FillMFTeamData(cs::MFTeamData* team_data)
room->frame_no - last_sync_teamdata_frameno_ > SERVER_FRAME_RATE * 2) {
#endif
last_sync_teamdata_frameno_ = room->frame_no;
team_data->set_player_id(entity_uniid);
team_data->set_name(name);
if (room->gas_data.gas_mode == GasInactive) {
team_data->set_name(name);
}
if (room->gas_data.gas_mode != GasInactive &&
room->GetFrameNo() - room->GetBattleStartFrameNo() < 4) {
team_data->set_name(name);
team_data->set_disconnected(socket_handle == 0);
}
TypeConvert::ToPb(pos, team_data->mutable_pos());
TypeConvert::ToPb(attack_dir, team_data->mutable_dir());
team_data->set_health(health);
team_data->set_max_health(GetMaxHP());
team_data->set_disconnected(false);
team_data->set_dead(dead);
team_data->set_downed(downed);
#if 0
team_data->set_disconnected(false);
#endif
}
}
@ -1655,7 +1665,7 @@ void Human::SendUpdateMsg()
}
for (Entity* entity : view_objects) {
if (new_objects.find(entity) == new_objects.end()) {
entity->FillMFObjectFull(msg->add_full_objects());
entity->FillMFObjectFull(this, msg->add_full_objects());
}
}
refreshed_view = true;
@ -2507,3 +2517,12 @@ void Human::ResetTankSkin()
tank_oil_max = 0.0f;
RecalcSelfCollider();
}
ObjectSyncFlags* Human::GetObjectSyncFlags(int obj_uniid)
{
if ((size_t)obj_uniid < fixed_object_sync_flags_.size()) {
return &fixed_object_sync_flags_[obj_uniid];
} else {
return nullptr;
}
}

View File

@ -118,7 +118,7 @@ class Human : public Entity
std::set<Human*> kill_humans;
Human* last_tank_attacker = nullptr;
long long last_tank_attack_idx = 0;
const BornPoint* born_point = nullptr;
BornPoint* born_point = nullptr;
bool shot_start = false;
bool shot_hold = false;
@ -138,8 +138,8 @@ class Human : public Entity
virtual void Initialize() override;
virtual float GetSpeed() override;
virtual float GetSpeed4();
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
virtual void FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data) override;
virtual void FillMFPlayerStats(cs::MFPlayerStats* stats);
virtual void GetAabbBox(AabbCollider& aabb_box);
void FillMFTeamData(cs::MFTeamData* team_data);
@ -218,6 +218,7 @@ class Human : public Entity
void OnDie();
void FreeDownedTimer();
void FreeReviveTimer();
ObjectSyncFlags* GetObjectSyncFlags(int obj_uniid);
protected:
void _UpdateMove(int speed);
@ -268,6 +269,8 @@ protected:
Human* follow_target_ = nullptr;
bool follow_synced_active_player = false;
std::array<ObjectSyncFlags, FIXED_OBJECT_MAXID> fixed_object_sync_flags_ = {};
private:
CircleCollider* self_collider_ = nullptr;
long long last_sync_gas_frameno = 0;

View File

@ -29,7 +29,7 @@ void Loot::RecalcSelfCollider()
{
}
void Loot::FillMFObjectPart(cs::MFObjectPart* part_data)
void Loot::FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Loot);
cs::MFLootPart* p = part_data->mutable_union_obj_5();
@ -37,7 +37,7 @@ void Loot::FillMFObjectPart(cs::MFObjectPart* part_data)
TypeConvert::ToPb(pos, p->mutable_pos());
}
void Loot::FillMFObjectFull(cs::MFObjectFull* full_data)
void Loot::FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Loot);
cs::MFLootFull* p = full_data->mutable_union_obj_5();

View File

@ -26,6 +26,6 @@ class Loot : public Entity
virtual ~Loot() override;
virtual void Initialize() override;
void RecalcSelfCollider();
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
virtual void FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data) override;
};

View File

@ -93,7 +93,7 @@ void Obstacle::RecalcSelfCollider()
}
}
void Obstacle::FillMFObjectPart(cs::MFObjectPart* part_data)
void Obstacle::FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data)
{
part_data->set_object_type(ET_Obstacle);
cs::MFObstaclePart* p = part_data->mutable_union_obj_2();
@ -102,10 +102,28 @@ void Obstacle::FillMFObjectPart(cs::MFObjectPart* part_data)
p->set_scale(1.0f);
}
void Obstacle::FillMFObjectFull(cs::MFObjectFull* full_data)
void Obstacle::FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data)
{
full_data->set_object_type(ET_Obstacle);
if (IsClientCached(hum)) {
int object_flags = 0;
a8::SetBitFlag(object_flags, kOfReadCache);
full_data->set_obj_uniid(GetEntityUniId());
full_data->set_object_flags(object_flags);
return;
}
cs::MFObstacleFull* p = full_data->mutable_union_obj_2();
if (CanClientCache(hum)) {
int object_flags = 0;
a8::SetBitFlag(object_flags, kOfWriteCache);
#if 0
full_data->set_obj_uniid(GetEntityUniId());
#endif
full_data->set_object_flags(object_flags);
AddClientCache(hum);
}
p->set_obj_uniid(entity_uniid);
TypeConvert::ToPb(pos, p->mutable_pos());
p->set_scale(1.0f);

View File

@ -39,8 +39,8 @@ class Obstacle : public Entity
virtual ~Obstacle() override;
virtual void Initialize() override;
void RecalcSelfCollider();
virtual void FillMFObjectPart(cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(cs::MFObjectFull* full_data) override;
virtual void FillMFObjectPart(Human* hum, cs::MFObjectPart* part_data) override;
virtual void FillMFObjectFull(Human* hum, cs::MFObjectFull* full_data) override;
virtual void GetAabbBox(AabbCollider& aabb_box) override;
virtual void GetCircleBox(CircleCollider& circle_box) override;
void Explosion(Bullet* bullet);

View File

@ -107,7 +107,9 @@ void Player::UpdateMove()
if (action_type == AT_Relive) {
CancelAction();
}
if (dead || a8::HasBitFlag(status, HS_Fly)) {
if (dead ||
room->IsWaitingStart() ||
a8::HasBitFlag(status, HS_Fly)) {
moving = false;
moved_frames = 0;
last_collision_door = nullptr;
@ -137,6 +139,8 @@ void Player::UpdateMove()
void Player::UpdateShot()
{
if (dead ||
downed ||
room->IsWaitingStart() ||
a8::HasBitFlag(status, HS_Fly) ||
a8::HasBitFlag(status, HS_Jump) ) {
shot_start = false;
@ -433,7 +437,11 @@ void Player::Shot()
AutoLoadingBullet();
}
last_shot_frameno_ = room->frame_no;
#if 1
room->frame_event.AddBulletNumChg(this);
#else
need_sync_active_player = true;
#endif
}
void Player::ProcInteraction()

View File

@ -69,6 +69,10 @@ void Room::Init()
},
&xtimer_attacher.timer_list_);
}
if (current_teamid >= FIXED_OBJECT_MAXID) {
abort();
}
current_uniid = FIXED_OBJECT_MAXID + 1;
ShuaAndroid();
}
@ -186,6 +190,7 @@ void Room::AddPlayer(Player* hum)
accountid_hash_[hum->account_id] = hum;
human_hash_[hum->entity_uniid] = hum;
++alive_count_;
alive_count_chged_frameno_ = GetFrameNo();
++App::Instance()->perf.alive_count;
grid_service.AddHuman(hum);
hum->FindLocation();
@ -296,6 +301,7 @@ void Room::CreateAndroid(int robot_num)
moveable_hash_[hum->entity_uniid] = hum;
human_hash_[hum->entity_uniid] = hum;
++alive_count_;
alive_count_chged_frameno_ = GetFrameNo();
++App::Instance()->perf.alive_count;
grid_service.AddHuman(hum);
hum->FindLocation();
@ -657,6 +663,7 @@ void Room::OnHumanDie(Human* hum)
frame_event.AddExplosionEx(hum, 0, hum->pos, 1);
}
--alive_count_;
alive_count_chged_frameno_ = GetFrameNo();
--App::Instance()->perf.alive_count;
NotifyUiUpdate();
}
@ -957,45 +964,72 @@ void Room::UpdateGasInactive()
{
if (frame_no - gas_data.gas_start_frameno >=
MetaMgr::Instance()->gas_inactive_time * SERVER_FRAME_RATE) {
#if 1
gas_data.gas_mode = GasWaiting;
gas_data.old_area_meta = MetaMgr::Instance()->GetSafeArea(30001);
gas_data.new_area_meta = MetaMgr::Instance()->GetSafeArea(30002);
gas_data.gas_progress = gas_data.old_area_meta->i->rad();
gas_data.gas_start_frameno = frame_no;
gas_data.pos_old = a8::Vec2(map_meta->i->map_width() / 2.0f,
map_meta->i->map_height() / 2.0f);
gas_data.pos_old_bk = gas_data.pos_old;
{
bool gen_ok = GenSmallCircle(gas_data.pos_old,
gas_data.old_area_meta->i->rad(),
gas_data.new_area_meta->i->rad(),
gas_data.pos_new);
assert(gen_ok);
}
gas_data.rad_old = gas_data.old_area_meta->i->rad();
gas_data.rad_new = gas_data.new_area_meta->i->rad();
battle_start_frameno_ = frame_no;
#else
gas_data.gas_mode = GasJump;
gas_data.gas_start_frameno = frame_no;
#endif
if (human_hash_.size() < ROOM_MAX_PLAYER_NUM) {
CreateAndroid(ROOM_MAX_PLAYER_NUM - human_hash_.size());
NotifyUiUpdate();
}
NotifyUiUpdate();
CombineTeam();
ShuaPlane();
NotifyGameStart();
NotifyWxVoip();
InitAirDrop();
RoomMgr::Instance()->ActiveRoom(room_uuid);
#if 0
ShuaPlane();
int auto_jump_interval = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_interval");
auto_jump_timer_ = xtimer.AddRepeatTimerAndAttach(SERVER_FRAME_RATE * auto_jump_interval,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
int auto_jump_min_num = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_min_num");
int auto_jump_max_num = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_max_num");
int jump_num = a8::RandEx(auto_jump_min_num, auto_jump_max_num);
if (room->last_player_jump_pos.Distance(room->plane.curr_pos) < 64 * 8) {
jump_num = 1 + rand() % 2;
}
for (int i = 0; i < jump_num; ++i) {
room->TouchHumanList(
a8::XParams()
.SetSender(room),
[] (Human* hum, a8::XParams& param) -> bool
{
if (a8::HasBitFlag(hum->status, HS_Fly) && hum->entity_subtype != EST_Player) {
hum->DoJump();
return false;
}
return true;
});
}
},
&xtimer_attacher.timer_list_);
auto_jump_timer_ = xtimer.AddRepeatTimerAndAttach
(SERVER_FRAME_RATE * auto_jump_interval,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
int auto_jump_min_num = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_min_num");
int auto_jump_max_num = MetaMgr::Instance()->GetSysParamAsInt("auto_jump_max_num");
int jump_num = a8::RandEx(auto_jump_min_num, auto_jump_max_num);
if (room->last_player_jump_pos.Distance(room->plane.curr_pos) < 64 * 8) {
jump_num = 1 + rand() % 2;
}
for (int i = 0; i < jump_num; ++i) {
room->TouchHumanList
(
a8::XParams()
.SetSender(room),
[] (Human* hum, a8::XParams& param) -> bool
{
if (a8::HasBitFlag(hum->status, HS_Fly) &&
hum->entity_subtype != EST_Player) {
hum->DoJump();
return false;
}
return true;
});
}
},
&xtimer_attacher.timer_list_);
#endif
}
}
@ -1407,6 +1441,7 @@ void Room::RandRemoveAndroid()
human_hash_.erase(hum->entity_uniid);
removed_robot_hash_[hum->entity_uniid] = hum;
--alive_count_;
alive_count_chged_frameno_ = GetFrameNo();
--App::Instance()->perf.alive_count;
for (auto& pair : human_hash_) {
pair.second->RemovePartObjects(hum);
@ -1550,6 +1585,117 @@ void Room::CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl)
born_point_hash_[AllocUniid()] = born_point;
}
void Room::SecondRandPoint()
{
for (auto& pair : accountid_hash_) {
Human* hum = pair.second;
hum->born_point = AllocBornPoint(hum);
}
CombineTeamBornPoint();
}
void Room::NotifyGameStart()
{
cs::SMGameStart msg;
for (auto& pair : accountid_hash_) {
pair.second->SendNotifyMsg(msg);
}
waiting_start_ = true;
xtimer.AddDeadLineTimerAndAttach
(SERVER_FRAME_RATE * 2,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
room->waiting_start_ = false;
},
&xtimer_attacher.timer_list_);
xtimer.AddDeadLineTimerAndAttach
(SERVER_FRAME_RATE * 1,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
room->SecondRandPoint();
},
&xtimer_attacher.timer_list_);
}
void Room::CombineTeamBornPoint()
{
for (auto& pair : team_hash_) {
Human* target = nullptr;
for (Human* hum : pair.second) {
if (!target) {
target = hum;
} else {
if (target->born_point) {
if (hum->born_point) {
DecBornPointHumanNum(hum->born_point, hum);
}
hum->born_point = target->born_point;
if (hum->born_point) {
IncBornPointHumanNum(hum->born_point, hum);
}
}
} //end if
if (!hum->born_point) {
hum->pos = a8::Vec2(DEFAULT_BORN_POINT_X + rand() % 100,
DEFAULT_BORN_POINT_Y + rand() % 200);
} else {
hum->pos = hum->born_point->RandPoint();
}
hum->FindLocation();
hum->RefreshView();
grid_service.MoveHuman(hum);
}
}
}
void Room::IncBornPointHumanNum(BornPoint* point, Human* hum)
{
switch (hum->entity_subtype) {
case EST_Player:
{
++point->player_num;
}
break;
case EST_Android:
{
++point->android_num;
}
break;
default:
{
}
break;
}
}
void Room::DecBornPointHumanNum(BornPoint* point, Human* hum)
{
switch (hum->entity_subtype) {
case EST_Player:
{
--point->player_num;
}
break;
case EST_Android:
{
--point->android_num;
}
break;
default:
{
}
break;
}
}
int Room::GetOnlinePlayerNum()
{
int num = 0;

View File

@ -56,9 +56,13 @@ public:
void Update(int delta_time);
int GetPlayerNum();
int AliveCount();
long long AliveCountChgFrameNo() { return alive_count_chged_frameno_; }
long long GetBattleStartFrameNo() { return battle_start_frameno_;}
Player* GetPlayerByAccountId(const std::string& accountid);
Player* GetPlayerByUniId(int uniid);
Entity* GetEntityByUniId(int uniid);
long long GetFrameNo() { return frame_no; }
bool IsWaitingStart() { return waiting_start_; }
void AddPlayer(Player* hum);
Human* FindEnemy(Human* hum);
@ -131,13 +135,20 @@ private:
BornPoint* AllocBornPoint(Human* hum);
void CreateMapObject(MetaData::MapTplThing& thing_tpl);
void CreateMapSpawnPoint(MetaData::MapTplThing& thing_tpl);
void SecondRandPoint();
void NotifyGameStart();
void CombineTeamBornPoint();
void IncBornPointHumanNum(BornPoint* point, Human* hum);
void DecBornPointHumanNum(BornPoint* point, Human* hum);
private:
int elapsed_time_ = 0;
int alive_count_ = 0;
long long alive_count_chged_frameno_ = 0;
MetaData::AirLine* airline_ = nullptr;
a8::XTimerAttacher xtimer_attacher;
xtimer_list* auto_jump_timer_ = nullptr;
bool waiting_start_ = false;
int current_teamid = 0;
int current_uniid = 0;

View File

@ -126,3 +126,11 @@ struct BornPoint
a8::Vec2 RandPoint() const;
};
#pragma pack(1)
struct ObjectSyncFlags
{
unsigned char flags = 0;
unsigned char last_sync_frameno = 0;
};
#pragma pack()

View File

@ -38,4 +38,5 @@ enum SMMessageId_e
_SMDebugMsg = 1010;
_SMWxVoip = 1011;
_SMUiUpdate = 1012;
_SMGameStart = 1013;
}

View File

@ -413,6 +413,9 @@ message MFObjectFull
optional MFProjectileFull union_obj_8 = 9;
optional MFSmokeFull union_obj_9 = 10;
optional MFHeroFull union_obj_10 = 11;
optional int32 obj_uniid = 14; //id
optional int32 object_flags = 15; // 1<<0: 1<<1
}
//()
@ -887,4 +890,10 @@ message SMUiUpdate
optional int32 alive_count = 1; //
optional int32 kill_count = 2; //
repeated MFCar car_list = 3; //
}
}
//
message SMGameStart
{
}

@ -1 +1 @@
Subproject commit cdb87a3e673aee3401b3e2ffce3ea1a1e6a603b0
Subproject commit 645913c9d4cc7126475f110b3c7d55bc2f4bc5f0

@ -1 +1 @@
Subproject commit eb455bb95f97dc506566c443be0c72960ceebabf
Subproject commit 6e1e84260c42c24a58fe98e25ea6ccd18331248d