完成视野改造
This commit is contained in:
parent
b9dce95940
commit
1b8b0852ee
@ -14,12 +14,22 @@ void FrameMaker::Debug_FullObject(Human* hum)
|
|||||||
{
|
{
|
||||||
if (!hum->new_objects.empty()) {
|
if (!hum->new_objects.empty()) {
|
||||||
a8::MutableXObject* out_data = a8::MutableXObject::NewArray();
|
a8::MutableXObject* out_data = a8::MutableXObject::NewArray();
|
||||||
for (auto& itr : hum->new_objects) {
|
for (auto& pair : hum->new_objects) {
|
||||||
int uniid = itr->GetUniId();
|
|
||||||
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
|
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
|
||||||
xobj->SetVal("uniid", uniid);
|
xobj->SetVal("uniid", pair.first);
|
||||||
xobj->SetVal("", itr->GetEntityType());
|
if (pair.second.Get()) {
|
||||||
xobj->SetVal("pos", a8::Format("%d,%d", {itr->GetPos().x, itr->GetPos().y}));
|
xobj->SetVal("matched", 1);
|
||||||
|
xobj->SetVal("type", pair.second.Get()->GetEntityType());
|
||||||
|
xobj->SetVal("pos", a8::Format("%d,%d",
|
||||||
|
{pair.second.Get()->GetPos().x,
|
||||||
|
pair.second.Get()->GetPos().y}));
|
||||||
|
} else {
|
||||||
|
xobj->SetVal("matched", 0);
|
||||||
|
xobj->SetVal("type", 0);
|
||||||
|
xobj->SetVal("pos", a8::Format("%d,%d",
|
||||||
|
{0,
|
||||||
|
0}));
|
||||||
|
}
|
||||||
out_data->Push(*xobj);
|
out_data->Push(*xobj);
|
||||||
}
|
}
|
||||||
hum->SendDebugMsg(a8::Format("view_debug frameno:%d server_full_obj:%s",
|
hum->SendDebugMsg(a8::Format("view_debug frameno:%d server_full_obj:%s",
|
||||||
@ -71,38 +81,51 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Debug_FullObject(hum);
|
Debug_FullObject(hum);
|
||||||
#endif
|
#endif
|
||||||
for (auto& itr : hum->new_objects) {
|
for (auto& pair : hum->new_objects) {
|
||||||
|
Entity* e = pair.second.Get();
|
||||||
|
if (!e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (hum->del_objects.find(itr->GetUniId()) != hum->del_objects.end()) {
|
if (hum->del_objects.find(e->GetUniId()) != hum->del_objects.end()) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (itr != hum &&
|
if (e != hum &&
|
||||||
itr->GetEntityType() == ET_Player &&
|
e->GetEntityType() == ET_Player &&
|
||||||
((Human*)itr)->HasBuffEffect(kBET_Fly)){
|
((Human*)e)->HasBuffEffect(kBET_Fly)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (hum->IsPlayer() && itr->CanSeeMe(hum)) {
|
if (hum->IsPlayer() && e->CanSeeMe(hum)) {
|
||||||
itr->FillMFObjectFull(room, (Human*)hum, msg->add_full_objects());
|
e->FillMFObjectFull(room, (Human*)hum, msg->add_full_objects());
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (itr->GetEntityType() == ET_Car) {
|
if (e->GetEntityType() == ET_Car) {
|
||||||
hum->SendDebugMsg(a8::Format("载具出现", {}));
|
hum->SendDebugMsg(a8::Format("载具出现", {}));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (App::Instance()->HasFlag(2) && itr->GetEntityType() == ET_Player) {
|
if (App::Instance()->HasFlag(2) && e->GetEntityType() == ET_Player) {
|
||||||
room->BroadcastDebugMsg(a8::Format("投放 %d pos:%d,%d 出现",
|
room->BroadcastDebugMsg(a8::Format("投放 %d pos:%d,%d 出现",
|
||||||
{
|
{
|
||||||
itr->GetUniId(),
|
e->GetUniId(),
|
||||||
itr->GetPos().x,
|
e->GetPos().x,
|
||||||
itr->GetPos().y,
|
e->GetPos().y,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
for (auto& itr : hum->part_objects) {
|
{
|
||||||
Entity* entity = itr.first;
|
int deleted_uniid = 0;
|
||||||
|
for (auto& pair : hum->part_objects) {
|
||||||
|
Entity* entity = pair.second.object.Get();
|
||||||
|
if (!entity) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
abort();
|
||||||
|
#endif
|
||||||
|
deleted_uniid = pair.first;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (entity->IsDead(room) &&
|
if (entity->IsDead(room) &&
|
||||||
hum->room->GetFrameNo() - entity->GetDeadFrameNo(room) > 10) {
|
hum->room->GetFrameNo() - entity->GetDeadFrameNo(room) > 10) {
|
||||||
continue;
|
continue;
|
||||||
@ -114,13 +137,17 @@ cs::SMUpdate* FrameMaker::MakeUpdateMsg(Human* hum)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (((Human*)hum)->GetPos().ManhattanDistance(entity->GetPos()) > VIEW_RANGE + 300) {
|
if (((Human*)hum)->GetPos().ManhattanDistance(entity->GetPos()) > VIEW_RANGE + 300) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
entity->FillMFObjectPart(room, (Human*)hum, msg->add_part_objects());
|
entity->FillMFObjectPart(room, (Human*)hum, msg->add_part_objects());
|
||||||
}
|
}
|
||||||
|
if (deleted_uniid > 0) {
|
||||||
|
hum->part_objects.erase(deleted_uniid);
|
||||||
|
}
|
||||||
|
}
|
||||||
for (auto& itr : hum->del_objects) {
|
for (auto& itr : hum->del_objects) {
|
||||||
msg->add_del_objids(itr);
|
msg->add_del_objids(itr);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -931,7 +931,7 @@ void Human::DecHP(float dec_hp, int killer_id, const std::string& killer_name, i
|
|||||||
|
|
||||||
void Human::AddToNewObjects(Entity* entity)
|
void Human::AddToNewObjects(Entity* entity)
|
||||||
{
|
{
|
||||||
new_objects.insert(entity);
|
new_objects[entity->GetUniId()] = entity->GetEntityWeakPtrRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Human::AddToPartObjects(Entity* entity)
|
void Human::AddToPartObjects(Entity* entity)
|
||||||
@ -941,7 +941,8 @@ void Human::AddToPartObjects(Entity* entity)
|
|||||||
part_obj.entity_type = entity->GetEntityType();
|
part_obj.entity_type = entity->GetEntityType();
|
||||||
part_obj.entity_subtype = entity->GetEntitySubType();
|
part_obj.entity_subtype = entity->GetEntitySubType();
|
||||||
part_obj.add_frameno = room->GetFrameNo();
|
part_obj.add_frameno = room->GetFrameNo();
|
||||||
part_objects[entity] = part_obj;
|
part_obj.object = entity->GetEntityWeakPtrRef();
|
||||||
|
part_objects[entity->GetUniId()] = part_obj;
|
||||||
entity->OnAddToTargetPartObject(this);
|
entity->OnAddToTargetPartObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -954,7 +955,7 @@ void Human::RemovePartObjects(Entity* entity)
|
|||||||
entity->GetUniId()
|
entity->GetUniId()
|
||||||
}));
|
}));
|
||||||
#endif
|
#endif
|
||||||
part_objects.erase(entity);
|
part_objects.erase(entity->GetUniId());
|
||||||
entity->OnRemoveFromTargetPartObject(this);
|
entity->OnRemoveFromTargetPartObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -970,18 +971,18 @@ int Human::GetPartObjectsCount()
|
|||||||
|
|
||||||
bool Human::InNewObjects(Entity* target)
|
bool Human::InNewObjects(Entity* target)
|
||||||
{
|
{
|
||||||
return new_objects.find(target) != new_objects.end();
|
return new_objects.find(target->GetUniId()) != new_objects.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Human::InPartObjects(Entity* target)
|
bool Human::InPartObjects(Entity* target)
|
||||||
{
|
{
|
||||||
return part_objects.find(target) != part_objects.end();
|
return part_objects.find(target->GetUniId()) != part_objects.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Human::RemoveObjects(Entity* entity)
|
void Human::RemoveObjects(Entity* entity)
|
||||||
{
|
{
|
||||||
del_objects.insert(entity->GetUniId());
|
del_objects.insert(entity->GetUniId());
|
||||||
new_objects.erase(entity);
|
new_objects.erase(entity->GetUniId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Human::AddOutObjects(Entity* entity)
|
void Human::AddOutObjects(Entity* entity)
|
||||||
@ -2805,7 +2806,7 @@ void Human::NotifyObservers(cs::SMUpdate* msg, cs::MFActivePlayerData* active_pl
|
|||||||
std::set<Entity*> view_objects;
|
std::set<Entity*> view_objects;
|
||||||
GetViewObjects(view_objects);
|
GetViewObjects(view_objects);
|
||||||
for (Entity* entity : view_objects) {
|
for (Entity* entity : view_objects) {
|
||||||
if (new_objects.find(entity) == new_objects.end()) {
|
if (new_objects.find(entity->GetUniId()) == new_objects.end()) {
|
||||||
entity->FillMFObjectFull(room, this, msg->add_full_objects());
|
entity->FillMFObjectFull(room, this, msg->add_full_objects());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ struct PartObject
|
|||||||
int entity_type = 0;
|
int entity_type = 0;
|
||||||
int entity_subtype = 0;
|
int entity_subtype = 0;
|
||||||
long long add_frameno = 0;
|
long long add_frameno = 0;
|
||||||
|
EntityWeakPtr object;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct xtimer_list;
|
struct xtimer_list;
|
||||||
@ -290,8 +291,8 @@ protected:
|
|||||||
long long leave_frameno_ = 0;
|
long long leave_frameno_ = 0;
|
||||||
|
|
||||||
std::array<int, IS_END> volume_ = {};
|
std::array<int, IS_END> volume_ = {};
|
||||||
std::set<Entity*> new_objects;
|
std::map<int, EntityWeakPtr> new_objects;
|
||||||
std::map<Entity*, PartObject> part_objects;
|
std::map<int, PartObject> part_objects;
|
||||||
std::set<int> del_objects;
|
std::set<int> del_objects;
|
||||||
std::set<int> out_objects;
|
std::set<int> out_objects;
|
||||||
std::vector<int> shots_;
|
std::vector<int> shots_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user