merge master

This commit is contained in:
aozhiwei 2019-04-10 20:25:40 +08:00
commit 5beec80050
17 changed files with 426 additions and 502 deletions

View File

@ -1,12 +1,9 @@
#include "precompile.h"
#include "building.h"
#include "metamgr.h"
#include "movement.h"
#include "room.h"
#include "collider.h"
#include "obstacle.h"
#include "human.h"
#include "metamgr.h"
#include "room.h"
#include "loot.h"
Building::Building():Entity()
@ -34,70 +31,20 @@ void Building::RecalcSelfCollider()
obj.y() + obj.height()/2.0 - meta->i->tileheight()/2.0);
colliders.push_back(collider);
}
for (auto& obj : meta->doors) {
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(61701);
if (thing) {
Obstacle* entity = new Obstacle();
entity->room = room;
entity->meta = thing;
entity->entity_uniid = room->AllocUniid();
entity->is_door = true;
entity->door_id = obj.door_id;
entity->door_state = DoorStateClose;
entity->building = this;
entity->door_house_uniid = entity_uniid;
entity->door_state0 = obj.state0;
entity->door_state1 = obj.state1;
#if 1
entity->pos = Vector2D(pos.x + entity->door_state0->x() - meta->i->tilewidth() / 2.0,
pos.y + entity->door_state0->y() - meta->i->tileheight() / 2.0);
#endif
entity->Initialize();
room->uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
for (size_t i = 0; i < meta->doors.size(); ++i) {
room->CreateDoor(this, i);
}
for (auto& obj : meta->i->lootobj()) {
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(obj.id());
if (thing) {
Obstacle* entity = new Obstacle();
entity->room = room;
entity->meta = thing;
#if 1
entity->building = this;
#endif
entity->entity_uniid = room->AllocUniid();
entity->pos = Vector2D(pos.x + obj.x() - meta->i->tilewidth() / 2.0,
pos.y + obj.y() - meta->i->tileheight() / 2.0);
entity->Initialize();
room->uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
room->CreateHouseObstacle(this, obj.id(), obj.x(), obj.y());
}
for (auto& obj : meta->i->dropobj()) {
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(obj.id());
if (equip_meta) {
Loot* entity = new Loot();
entity->room = room;
entity->meta = equip_meta;
entity->entity_uniid = room->AllocUniid();
entity->pos = Vector2D(pos.x + obj.x() - meta->i->tilewidth() / 2.0,
pos.y + obj.y() - meta->i->tileheight() / 2.0);
entity->item_id = obj.id();
entity->count = 1;
entity->Initialize();
room->uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
room->CreateLoot(obj.id(),
Vector2D(
pos.x + obj.x() - meta->i->tilewidth() / 2.0,
pos.y + obj.y() - meta->i->tileheight() / 2.0
),
1
);
}
}

View File

@ -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";

View File

View 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
{
};

View File

@ -113,7 +113,6 @@ void Human::Shot(Vector2D& target_dir)
if (!curr_weapon->meta) {
return;
}
{
cs::MFShot* shot = room->frame_data.shots.Add();
shot->set_player_id(entity_uniid);
@ -130,20 +129,7 @@ void Human::Shot(Vector2D& target_dir)
bullet->set_bulletskin(10001);
bullet->set_gun_id(curr_weapon->meta->i->id());
}
{
Bullet* bullet = new Bullet();
bullet->player = this;
bullet->room = room;
bullet->gun_meta = curr_weapon->meta;
bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
bullet->pos = pos;
bullet->dir = target_dir;
bullet->born_pos = pos;
bullet->born_dir = target_dir;
bullet->entity_uniid = bullet->room->AllocUniid();
bullet->Initialize();
room->AddBullet(bullet);
}
room->CreateBullet(this, curr_weapon->meta, pos, target_dir, 0);
}
void Human::RecalcSelfCollider()
@ -276,35 +262,13 @@ void Human::UpdatePoisoning()
}
}
void Human::DropItem(int item_id)
{
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(item_id);
if (equip_meta) {
Loot* entity = new Loot();
entity->room = room;
entity->meta = equip_meta;
entity->entity_uniid = room->AllocUniid();
{
Vector2D dir = Vector2D::UP;
dir.Rotate(a8::RandAngle());
entity->pos = pos + dir * (25 + rand() % 50);
}
entity->item_id = equip_meta->i->id();
entity->count = 1;
entity->Initialize();
room->uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
}
void Human::SyncAroundPlayers()
{
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(this);
}
room->TouchHumanList(a8::XParams(),
[this] (Human* hum, a8::XParams& param)
{
hum->new_objects.insert(this);
});
}
void Human::AutoLoadingBullet(bool manual)
@ -383,7 +347,7 @@ void Human::BeKill(int killer_id, const std::string& killer_name)
health = 0.0f;
dead_frameno = room->frame_no;
send_gameover = true;
--room->alive_count_;
room->OnHumanDie(this);
SyncAroundPlayers();
}
}

View File

@ -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
@ -103,7 +80,6 @@ class Human : public Entity
void FindPath();
float GetRadius();
void UpdatePoisoning();
void DropItem(int item_id);
void SyncAroundPlayers();
void AutoLoadingBullet(bool manual = false);
void StartAction(ActionType_e action_type,

View File

@ -138,9 +138,7 @@ void Player::UpdateSelectWeapon()
curr_weapon = weapon;
ResetAction();
need_sync_active_player = true;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(this);
}
SyncAroundPlayers();
AutoLoadingBullet();
}
}
@ -302,21 +300,7 @@ void Player::Shot()
bullet->set_gun_id(curr_weapon->meta->i->id());
bullet->set_fly_distance(fly_distance);
}
{
Bullet* bullet = new Bullet();
bullet->player = this;
bullet->room = room;
bullet->gun_meta = curr_weapon->meta;
bullet->meta = MetaMgr::Instance()->GetEquip(curr_weapon->meta->i->use_bullet());
bullet->pos = bullet_born_pos;
bullet->dir = attack_dir;
bullet->born_pos = bullet_born_pos;
bullet->born_dir = attack_dir;
bullet->fly_distance = fly_distance;
bullet->entity_uniid = bullet->room->AllocUniid();
bullet->Initialize();
room->AddBullet(bullet);
}
room->CreateBullet(this, curr_weapon->meta, bullet_born_pos, attack_dir, fly_distance);
}
--curr_weapon->ammo;
int slot_id = curr_weapon->meta->i->_inventory_slot();
@ -404,15 +388,17 @@ void Player::ObstacleInteraction(Obstacle* entity)
entity->building->pos.y + entity->door_state0->y() - entity->building->meta->i->tileheight() / 2.0);
}
entity->RecalcSelfCollider();
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
if (entity->TestCollision(pair.second)) {
pair.second->last_collision_door = entity;
} else if (pair.second->last_collision_door == entity) {
pair.second->last_collision_door = nullptr;
}
room->TouchHumanList(a8::XParams(),
[entity] (Human* hum, a8::XParams& param)
{
hum->new_objects.insert(entity);
hum->part_objects.insert(entity);
if (entity->TestCollision(hum)) {
hum->last_collision_door = entity;
} else if (hum->last_collision_door == entity) {
hum->last_collision_door = nullptr;
}
});
} else {
}
}
@ -445,9 +431,7 @@ void Player::LootInteraction(Loot* entity)
need_sync_active_player = true;
}
need_sync_active_player = true;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(this);
}
SyncAroundPlayers();
} else {
Weapon* weapon = nullptr;
if (weapons[GUN_SLOT1].weapon_id == 0) {
@ -475,9 +459,7 @@ void Player::LootInteraction(Loot* entity)
weapon->meta = item_meta;
AutoLoadingBullet();
need_sync_active_player = true;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(this);
}
SyncAroundPlayers();
}
}
break;
@ -512,7 +494,7 @@ void Player::LootInteraction(Loot* entity)
if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) {
return;
}
DropItem(old_item_meta->i->id());
room->DropItem(pos, old_item_meta->i->id());
}
backpack = item_meta->i->id();
}
@ -527,7 +509,7 @@ void Player::LootInteraction(Loot* entity)
if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) {
return;
}
DropItem(old_item_meta->i->id());
room->DropItem(pos, old_item_meta->i->id());
}
chest = item_meta->i->id();
} else if (item_meta->i->equip_subtype() == 2) {
@ -537,7 +519,7 @@ void Player::LootInteraction(Loot* entity)
if (old_item_meta->i->equip_lv() >= item_meta->i->equip_lv()) {
return;
}
DropItem(old_item_meta->i->id());
room->DropItem(pos, old_item_meta->i->id());
}
helmet = item_meta->i->id();
}
@ -682,34 +664,13 @@ void Player::UpdateDropWeapon()
}
}
if (drop_ok) {
#if 1
{
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(weapon_id);
if (equip_meta) {
Loot* entity = new Loot();
entity->room = room;
entity->meta = equip_meta;
entity->entity_uniid = room->AllocUniid();
{
Vector2D dir = Vector2D::UP;
dir.Rotate(a8::RandAngle());
entity->pos = pos + dir * (25 + rand() % 50);
room->CreateLoot(weapon_id, pos + dir * (25 + rand() % 50), std::max(1, weapon_ammo));
}
entity->item_id = weapon_id;
entity->count = std::max(1, weapon_ammo);
entity->Initialize();
room->uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
}
#endif
need_sync_active_player = true;
for (auto& pair : room->human_hash_) {
pair.second->new_objects.insert(this);
}
SyncAroundPlayers();
}
}
}
@ -829,11 +790,7 @@ void Player::MakeUpdateMsg()
}
}
if (updated_times == 0) {
for (auto& pair : room->uniid_hash_) {
if (pair.second->entity_type == ET_Building) {
new_objects.insert(pair.second);
}
}
room->FetchBuilding(this);
}
for (auto& itr : new_objects) {
itr->FillMFObjectFull(update_msg->add_full_objects());

View File

@ -6,17 +6,10 @@
void PlayerMgr::Init()
{
}
void PlayerMgr::UnInit()
{
}
void PlayerMgr::Update()
{
}
Player* PlayerMgr::GetPlayerBySocket(int socket)
@ -25,10 +18,10 @@ Player* PlayerMgr::GetPlayerBySocket(int socket)
return itr != socket_hash_.end() ? itr->second : nullptr;
}
Player* PlayerMgr::CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, const cs::CMJoin& msg)
Player* PlayerMgr::CreatePlayerByCMJoin(int socket, const cs::CMJoin& msg)
{
Player* hum = new Player();
hum->entity_uniid = obj_uniid;
hum->socket_handle = socket;
hum->account_id = msg.account_id();
hum->name = msg.name();
hum->health = 100;
@ -39,10 +32,10 @@ Player* PlayerMgr::CreatePlayerByCMJoin(int socket, unsigned short obj_uniid, co
hum->use_touch = msg.use_touch();
hum->avatar_url = msg.avatar_url();
hum->energy_shield = msg.energy_shield();
socket_hash_[socket] = hum;
// hum->baseskin = msg.baseskin();
// hum->basemelee = msg.basemelee();
// hum->elo_score = msg.elo_score();
// hum->gmode = msg.gmode();
socket_hash_[socket] = hum;
return hum;
}

View File

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

View File

@ -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"

View File

@ -109,7 +109,9 @@ void Room::AddPlayer(Player* hum)
hum->attack_dir.Normalize();
hum->attack_dir.Rotate(a8::RandAngle());
}
hum->entity_uniid = AllocUniid();
hum->room = this;
hum->Initialize();
uniid_hash_[hum->entity_uniid] = hum;
moveable_hash_[hum->entity_uniid] = hum;
accountid_hash_[hum->account_id] = hum;
@ -172,82 +174,6 @@ void Room::ShuaAndroid()
}
}
void Room::ShuaObstacle(Human* hum)
{
MetaData::MapThing* a_thing = MetaMgr::Instance()->GetMapThing(61101);
MetaData::MapThing* b_thing = MetaMgr::Instance()->GetMapThing(61401);
if (!a_thing || !b_thing) {
return;
}
#if 1
{
Obstacle* entity = new Obstacle();
entity->room = this;
entity->meta = a_thing;
entity->entity_uniid = AllocUniid();
#if 0
entity->dir = Vector2D::UP;
#endif
#if 0
entity->pos = Vector2D(100.0f, 164.0f);
#else
entity->pos = hum->pos - Vector2D::LEFT * hum->meta->i->radius() - 100;
#endif
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
#endif
#if 1
{
Obstacle* entity = new Obstacle();
entity->room = this;
entity->meta = b_thing;
entity->entity_uniid = AllocUniid();
#if 0
entity->dir = Vector2D::UP;
#endif
#if 0
entity->pos = Vector2D(100.0f, 100.0f);
#else
entity->pos = hum->pos + Vector2D::RIGHT * hum->meta->i->radius() + 100;
#endif
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
#endif
}
void Room::ShuaBuilding(Human* hum)
{
MetaData::Building* a_building = MetaMgr::Instance()->GetBuilding(1);
if (!a_building) {
return;
}
#if 1
{
Building* entity = new Building();
entity->room = this;
entity->meta = a_building;
entity->entity_uniid = AllocUniid();
entity->pos = hum->pos - Vector2D::UP * hum->meta->i->radius() + 500;
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
#endif
}
bool Room::RandomPos(Human* hum, float distance, Vector2D& out_pos)
{
Vector2D dir = hum->pos;
@ -294,11 +220,6 @@ Human* Room::FindEnemy(Human* hum)
return !enemys.empty() ? enemys[0] : nullptr;
}
void Room::AddBullet(Bullet* bullet)
{
be_added_hash_[bullet->entity_uniid] = bullet;
}
void Room::CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects)
{
assert(uniid_hash_.size() < 1000);
@ -476,6 +397,131 @@ void Room::FillSMMapInfo(cs::SMMapInfo& map_info)
}
}
void Room::DropItem(Vector2D pos, int item_id)
{
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(item_id);
if (equip_meta) {
Loot* entity = new Loot();
entity->room = this;
entity->meta = equip_meta;
entity->entity_uniid = AllocUniid();
{
Vector2D dir = Vector2D::UP;
dir.Rotate(a8::RandAngle());
entity->pos = pos + dir * (25 + rand() % 50);
}
entity->item_id = equip_meta->i->id();
entity->count = 1;
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
}
void Room::CreateDoor(Building* building, int door_idx)
{
if (door_idx >= 0 && door_idx < building->meta->doors.size()) {
MetaData::Building::Door* door_meta = &building->meta->doors[door_idx];
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(61701);
if (thing) {
Obstacle* entity = new Obstacle();
entity->room = this;
entity->meta = thing;
entity->entity_uniid = AllocUniid();
entity->is_door = true;
entity->door_id = door_meta->door_id;
entity->door_state = DoorStateClose;
entity->building = building;
entity->door_house_uniid = building->entity_uniid;
entity->door_state0 = door_meta->state0;
entity->door_state1 = door_meta->state1;
entity->pos = Vector2D(building->pos.x + entity->door_state0->x() - building->meta->i->tilewidth() / 2.0,
building->pos.y + entity->door_state0->y() - building->meta->i->tileheight() / 2.0);
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
}
}
void Room::CreateHouseObstacle(Building* building, int id, float x, float y)
{
MetaData::MapThing* thing = MetaMgr::Instance()->GetMapThing(id);
if (thing) {
Obstacle* entity = new Obstacle();
entity->room = this;
entity->meta = thing;
entity->building = building;
entity->entity_uniid = AllocUniid();
entity->pos = Vector2D(building->pos.x + x - building->meta->i->tilewidth() / 2.0,
building->pos.y + y - building->meta->i->tileheight() / 2.0);
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
}
void Room::CreateLoot(int equip_id, Vector2D pos, int count)
{
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(equip_id);
if (equip_meta) {
Loot* entity = new Loot();
entity->room = this;
entity->meta = equip_meta;
entity->entity_uniid = AllocUniid();
entity->pos = pos;
entity->item_id = equip_id;
entity->count = count;
entity->Initialize();
uniid_hash_[entity->entity_uniid] = entity;
for (auto& pair : human_hash_) {
pair.second->new_objects.insert(entity);
pair.second->part_objects.insert(entity);
}
}
}
void Room::CreateBullet(Human* hum, MetaData::Equip* gun_meta,
Vector2D pos, Vector2D dir, float fly_distance)
{
Bullet* bullet = new Bullet();
bullet->player = hum;
bullet->room = this;
bullet->gun_meta = gun_meta;
bullet->meta = MetaMgr::Instance()->GetEquip(gun_meta->i->use_bullet());
bullet->pos = pos;
bullet->dir = dir;
bullet->born_pos = pos;
bullet->born_dir = dir;
bullet->fly_distance = fly_distance;
bullet->entity_uniid = AllocUniid();
bullet->Initialize();
be_added_hash_[bullet->entity_uniid] = bullet;
}
void Room::FetchBuilding(Human* hum)
{
for (auto& pair : uniid_hash_) {
if (pair.second->entity_type == ET_Building) {
hum->new_objects.insert(pair.second);
}
}
}
void Room::OnHumanDie(Human* hum)
{
--alive_count_;
}
void Room::ClearDeletedObjects()
{
for (auto& obj_uniid : frame_data.deleted_objects) {
@ -507,6 +553,19 @@ void Room::TouchPlayerList(a8::XParams param,
}
}
void Room::TouchHumanList(a8::XParams param,
std::function<void (Human*, a8::XParams&)> func)
{
if (!func) {
return;
}
for (auto& pair : human_hash_) {
if (pair.second) {
func(pair.second, param);
}
}
}
void Room::ProcAddedObjects()
{
if (!be_added_hash_.empty()) {
@ -636,11 +695,7 @@ void Room::UpdateGas()
continue;
}
bool b1 = CircleContainCircle(gas_data.pos_old,
#if 1
gas_data.gas_progress,
#else
gas_data.rad_old,
#endif
pair.second->pos,
pair.second->GetRadius()
);

View File

@ -1,34 +1,19 @@
#pragma once
#include "cs_proto.pb.h"
enum RoomState_e
{
RS_Inactive = 0,
RS_Waiting = 1,
RS_Moveing = 2
};
#include "framedata.h"
namespace MetaData
{
struct Map;
struct SafeArea;
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;
class Player;
class Building;
class Room
{
public:
@ -46,40 +31,48 @@ public:
Player* GetPlayerByUniId(unsigned short uniid);
Entity* GetEntityByUniId(unsigned short uniid);
void AddPlayer(Player* hum);
void AddBullet(Bullet* bullet);
unsigned short AllocUniid();
void ShuaAndroid();
void ShuaObstacle(Human* hum);
void ShuaBuilding(Human* hum);
bool RandomPos(Human* hum, float distance, Vector2D& out_pos);
Human* FindEnemy(Human* hum);
void CollisionDetection(Entity* sender, int detection_flags, std::vector<Entity*>& objects);
void AddDeletedObject(unsigned short obj_uniid);
void FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg);
void ResetFrameData();
void TouchPlayerList(a8::XParams param,
std::function<void (Player*, a8::XParams&)> func);
void TouchHumanList(a8::XParams param,
std::function<void (Human*, a8::XParams&)> func);
void BeAddedObject(Entity* entity);
void ProcDrop(Vector2D center, int drop_id);
void CreateThings();
void FillSMMapInfo(cs::SMMapInfo& map_info);
void DropItem(Vector2D pos, int item_id);
void CreateDoor(Building* building, int door_idx);
void CreateHouseObstacle(Building* building, int id, float x, float y);
void CreateLoot(int equip_id, Vector2D pos, int count);
void CreateBullet(Human* hum, MetaData::Equip* gun_meta,
Vector2D pos, Vector2D dir, float fly_distance);
void FetchBuilding(Human* hum);
void OnHumanDie(Human* hum);
private:
unsigned short AllocUniid();
void ResetFrameData();
void ClearDeletedObjects();
void ProcAddedObjects();
void UpdateGas();
bool GenSmallCircle(Vector2D big_circle_pos, float big_circle_rad, float small_circle_rad,
Vector2D& out_pos);
public:
unsigned short current_uniid = 0;
RoomState_e state_ = RS_Inactive;
private:
int elapsed_time_ = 0;
int alive_count_ = 0;
unsigned short current_uniid = 0;
RoomState_e state_ = RS_Inactive;
std::map<std::string, Player*> accountid_hash_;
std::map<unsigned short, Entity*> uniid_hash_;
std::map<unsigned short, Entity*> moveable_hash_;
std::map<unsigned short, Entity*> uniid_hash_;
std::map<unsigned short, Human*> human_hash_;
std::map<unsigned short, Entity*> be_added_hash_;
};

View File

@ -12,12 +12,10 @@
void RoomMgr::Init()
{
}
void RoomMgr::UnInit()
{
}
void RoomMgr::Update(int delta_time)
@ -47,18 +45,10 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
inactive_room_hash_[room->room_uuid] = room;
room_hash_[room->room_uuid] = room;
}
unsigned short new_uniid = room->AllocUniid();
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, new_uniid, msg);
Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.socket_handle, msg);
hum->meta = hum_meta;
hum->socket_handle = hdr.socket_handle;
hum->Initialize();
room->AddPlayer(hum);
#if 1
room->CreateThings();
#else
room->ShuaObstacle(hum);
room->ShuaBuilding(hum);
#endif
{
cs::SMJoinedNotify notifymsg;

View File

@ -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);

View File

@ -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;
};

View 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));
}

View 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;
};