[3.3.5] Get zone/area IDs from vmap data in the liquid update#19840
Conversation
| if (area->zone) | ||
| m_zoneId = area->zone; | ||
|
|
||
| /*if (GetTypeId() == TYPEID_PLAYER) |
There was a problem hiding this comment.
Heads-up, enable this block if you're reproing to get me some useful info (also, give me a .gps).
There was a problem hiding this comment.
how about a timer to be able to know how much it takes?
| virtual bool getAreaInfo(unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const=0; | ||
| virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const=0; | ||
| // get both area + liquid data in a single vmap lookup | ||
| virtual void getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, uint8 reqLiquidType, |
There was a problem hiding this comment.
refactor this to output all of these parameters into a structure
| void WorldObject::AddToWorld() | ||
| { | ||
| Object::AddToWorld(); | ||
| GetMap()->GetZoneAndAreaId(m_zoneId, m_areaId, GetPositionX(), GetPositionY(), GetPositionZ()); |
| // transports | ||
| Transport* m_transport; | ||
|
|
||
| // zone/area ID updated in Unit::Update (only Units can move) |
There was a problem hiding this comment.
False. GameObjects and DynamicObjects can move when on transport. (and on master AreaTriggers, always)
There was a problem hiding this comment.
Hm, should we do the call in their ::Update too? Or are transports always their own area?
| void Unit::UpdateUnderwaterState(Map* m, float x, float y, float z) | ||
| void Unit::UpdatePositionData() | ||
| { | ||
| PositionFullVMapData data; |
There was a problem hiding this comment.
FullTerrainStatus (naming - matters here because you are returning GridMap data if on flat/nowmo terrain)
|
It's somewhat unrealated to this PR, but since you are currently working on it this could an intressting issue to solve: #19761. I did not look into this issue at all, so i'm not sure if zone/area id is even the root cause here. |
|
That'd be an issue with base gridmap/vmap data, @nawuko. Not something this PR will (or aims to) address. |
|
okay, just wanted to be sure its not a problem in the lookup logic. Thanks for looking into that 👍 |
|
I honestly can't say whether it is, @nawuko - though it seems unlikely. |
| data.liquidInfo.type = info.hitModel->GetLiquidType(); | ||
| if (!reqLiquidType || (GetLiquidFlagsPtr(data.liquidInfo.type) & reqLiquidType)) | ||
| if (info.hitInstance->GetLiquidLevel(pos, info, data.liquidInfo.level)) | ||
| data.hasLiquid = true; |
There was a problem hiding this comment.
Looks like a good place to use Optional
There was a problem hiding this comment.
Would make it inconsistent with other vmap methods though.
|
@Shauren it is my understanding that any movement of a worldobject while it's added to a map should go through one of the methods calling |
| data.liquidInfo.type = info.hitModel->GetLiquidType(); | ||
| if (!reqLiquidType || (GetLiquidFlagsPtr(data.liquidInfo.type) & reqLiquidType)) | ||
| if (info.hitInstance->GetLiquidLevel(pos, info, data.liquidInfo.level)) | ||
| data.hasLiquid = true; |
|
|
||
| bool getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const override; | ||
| bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type) const override; | ||
| virtual void getAreaAndLiquidData(unsigned int mapId, float x, float y, float z, uint8 reqLiquidType, AreaAndLiquidData& data) const override; |
| #define VMAP_INVALID_HEIGHT -100000.0f // for check | ||
| #define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case | ||
|
|
||
| struct TC_COMMON_API AreaAndLiquidData |
There was a problem hiding this comment.
*_API macro is only needed when your struct/class has methods implemented in .cpp file
| // transports | ||
| Transport* m_transport; | ||
|
|
||
| virtual void _ProcessPositionDataChanged(PositionFullTerrainStatus const& data); |
There was a problem hiding this comment.
don't prefix method names with _
| { | ||
| WorldObject::_ProcessPositionDataChanged(data); | ||
|
|
||
| /*if (GetTypeId() == TYPEID_PLAYER) |
|
|
||
| struct PositionFullTerrainStatus | ||
| { | ||
| bool hasFullAreaInfo; |
There was a problem hiding this comment.
pls, Optional (no has*** members)
|
|
||
| // area lookup | ||
| AreaTableEntry const* areaEntry = nullptr; | ||
| if (vmapData.hasAreaInfo && !(z + 2.0f > mapHeight && mapHeight > vmapData.floorZ)) |
There was a problem hiding this comment.
dont bring out the negation before (), especially when you have conditions you can easily change (> to <=)
| data.areaInfo.groupId = vmapData.areaInfo.groupId; | ||
| data.areaInfo.mogpFlags = vmapData.areaInfo.flags; | ||
| } | ||
|
|
| return result; | ||
| } | ||
|
|
||
| void Map::getFullTerrainStatusForPosition(float x, float y, float z, PositionFullTerrainStatus& data, uint8 reqLiquidType) const |
There was a problem hiding this comment.
method name? make it start with uppercase (you can leave the one in vmapmanager as-is)
|
|
||
| void DisableSpline(); | ||
|
|
||
| void _ProcessPositionDataChanged(PositionFullTerrainStatus const& data) override; |
There was a problem hiding this comment.
don't prefix method names with _
… liquid info in a single vmap lookup - Use this lookup in Map:: relocation methods to update m_areaId and m_zoneId fields on WorldObject - Adjust GetZoneId/GetAreaId on WorldObject to always return these cached fields - Clean up liquid state handling on Unit and Player since I'm at it (fixes and closes TrinityCore#16489)
78ced7b to
ed93010
Compare
|
Travis build fail is due to outdated boost (it has 1.55, we require 1.59). Removing in place construction ( |
|
Ref boost::optional move semantics, not the first time this happens: Is the performance hit that bad? IIRC POD types were just copied instead moved, you can still use boost::in_place to perform an in-place initialization |
|
We use boost::in_place everywhere in packets on master branch (you just need a no-arg constructor, or just no constructors at all) |
|
|
||
| struct PositionFullTerrainStatus | ||
| { | ||
| typedef VMAP::AreaAndLiquidData::AreaInfo AreaInfo; |
There was a problem hiding this comment.
I know this is convenient but don't do this. Don't make all users of Map class also include VMapManager
|
This is the zero-overhead pattern that is used in master branch for building packets - assigning boost::in_place() no-arg version is the same as calling .emplace() with no args |
…it to update a new field in WorldObject, and use that to feed a new GetFloorZ call on WorldObject.
…TrinityCore#19840)" This reverts commit f6c8497.
…TrinityCore#19840)" This reverts commit f6c8497.
…TrinityCore#19840)" This reverts commit f6c8497.
…d update (TrinityCore#19840)"" This reverts commit 0bf9e05.
…yCore#19840) * Add new method Map::getFullVMapDataForPosition to get area info and liquid info in a single vmap lookup * Use this lookup in Map:: relocation methods to update m_areaId and m_zoneId fields on WorldObject * Adjust GetZoneId/GetAreaId on WorldObject to always return these cached fields * Clean up liquid state handling on Unit and Player * Hand floor's Z coord up through GetFullTerrainStatusForPosition, use it to update a new field in WorldObject, and use that to feed a new GetFloorZ call on WorldObject. Closes TrinityCore#16489 (cherry picked from commit f6c8497)
…yCore#19840) * Add new method Map::getFullVMapDataForPosition to get area info and liquid info in a single vmap lookup * Use this lookup in Map:: relocation methods to update m_areaId and m_zoneId fields on WorldObject * Adjust GetZoneId/GetAreaId on WorldObject to always return these cached fields * Clean up liquid state handling on Unit and Player * Hand floor's Z coord up through GetFullTerrainStatusForPosition, use it to update a new field in WorldObject, and use that to feed a new GetFloorZ call on WorldObject. Closes TrinityCore#16489 (cherry picked from commit f6c8497)
…yCore#19840) * Add new method Map::getFullVMapDataForPosition to get area info and liquid info in a single vmap lookup * Use this lookup in Map:: relocation methods to update m_areaId and m_zoneId fields on WorldObject * Adjust GetZoneId/GetAreaId on WorldObject to always return these cached fields * Clean up liquid state handling on Unit and Player * Hand floor's Z coord up through GetFullTerrainStatusForPosition, use it to update a new field in WorldObject, and use that to feed a new GetFloorZ call on WorldObject. Closes TrinityCore#16489 (cherry picked from commit f6c8497)
…yCore#19840) * Add new method Map::getFullVMapDataForPosition to get area info and liquid info in a single vmap lookup * Use this lookup in Map:: relocation methods to update m_areaId and m_zoneId fields on WorldObject * Adjust GetZoneId/GetAreaId on WorldObject to always return these cached fields * Clean up liquid state handling on Unit and Player * Hand floor's Z coord up through GetFullTerrainStatusForPosition, use it to update a new field in WorldObject, and use that to feed a new GetFloorZ call on WorldObject. Closes TrinityCore#16489 (cherry picked from commit f6c8497)
…yCore#19840) * Add new method Map::getFullVMapDataForPosition to get area info and liquid info in a single vmap lookup * Use this lookup in Map:: relocation methods to update m_areaId and m_zoneId fields on WorldObject * Adjust GetZoneId/GetAreaId on WorldObject to always return these cached fields * Clean up liquid state handling on Unit and Player * Hand floor's Z coord up through GetFullTerrainStatusForPosition, use it to update a new field in WorldObject, and use that to feed a new GetFloorZ call on WorldObject. Closes TrinityCore#16489 (cherry picked from commit f6c8497)
…yCore#19840) * Add new method Map::getFullVMapDataForPosition to get area info and liquid info in a single vmap lookup * Use this lookup in Map:: relocation methods to update m_areaId and m_zoneId fields on WorldObject * Adjust GetZoneId/GetAreaId on WorldObject to always return these cached fields * Clean up liquid state handling on Unit and Player * Hand floor's Z coord up through GetFullTerrainStatusForPosition, use it to update a new field in WorldObject, and use that to feed a new GetFloorZ call on WorldObject. Closes TrinityCore#16489 (cherry picked from commit f6c8497)
Right now, every call to
GetZoneId/GetAreaId(which seem innocuous enough) actually invokes a full vmaps lookup to find the zone/area id of the object. This is kind of bad.However, as discussed in #19056, we already do liquid state updates on every server tick for everything, and that's a vmap lookup. And that vmap lookup gives us the zone/area data, we just don't use it.
And even that is kind of stupid, because why are we doing liquid updates every tick if it liquid data is static? Instead, we now do liquid update whenever the WorldObject's position changes.
Then we save it on the WorldObject, and use that info to turn
GetZoneIdandGetAreaIdinto simple member accesses.