Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed global wmo tiles #76

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions MapViewer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ void ChangeMap(const std::string& cn)
// 300.f); gRenderer->m_camera.LookAt(avgX, avgY, avgZ);
}

// enable these buttons even for a global WMO map to allow for Z queries
gControls->Enable(Controls::PositionX, true);
gControls->Enable(Controls::PositionY, true);

// if the loaded map has no ADTs, but instead a global WMO, load it now,
// including all mesh tiles
if (auto const wmo = gMap->GetGlobalWmoInstance())
Expand All @@ -647,8 +651,6 @@ void ChangeMap(const std::string& cn)
gRenderer->m_camera.Move(cx + 300.f, cy + 300.f, cz + 300.f);
gRenderer->m_camera.LookAt(cx, cy, cz);

gControls->Enable(Controls::PositionX, false);
gControls->Enable(Controls::PositionY, false);
gControls->Enable(Controls::Load, false);

if (gNavMesh)
Expand All @@ -663,11 +665,7 @@ void ChangeMap(const std::string& cn)
}
}
else
{
gControls->Enable(Controls::PositionX, true);
gControls->Enable(Controls::PositionY, true);
gControls->Enable(Controls::Load, true);
}
}

void LoadPositionFromGUI()
Expand Down Expand Up @@ -794,7 +792,7 @@ void SearchZValues()
for (auto const h : output)
{
result << h << "\n";
gRenderer->AddSphere({posX, posY, h}, 0.25f);
gRenderer->AddSphere({posX, posY, h}, 0.75f);
}

MessageBoxA(nullptr, result.str().c_str(), "Z Search Results", 0);
Expand Down
44 changes: 24 additions & 20 deletions pathfind/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ float random_between_0_and_1() {
namespace pathfind
{
Map::Map(const std::filesystem::path& dataPath, const std::string& mapName)
: m_dataPath(dataPath), m_bvhLoader(dataPath), m_mapName(mapName)
: m_dataPath(dataPath), m_bvhLoader(dataPath), m_mapName(mapName),
m_globalWmoOriginX(0.f), m_globalWmoOriginY(0.f)
{
utility::BinaryStream in(m_dataPath / (mapName + ".map"));

Expand All @@ -114,6 +115,8 @@ Map::Map(const std::filesystem::path& dataPath, const std::string& mapName)

if (hasTerrain)
{
m_hasADTs = true;

std::uint8_t has_adt[MeshSettings::Adts * MeshSettings::Adts / 8];

in.ReadBytes(has_adt, sizeof(has_adt));
Expand Down Expand Up @@ -204,6 +207,7 @@ Map::Map(const std::filesystem::path& dataPath, const std::string& mapName)
else
{
// no ADTs in this map
m_hasADTs = false;
::memset(m_hasADT, 0, sizeof(m_hasADT));

WmoFileInstance globalWmo;
Expand Down Expand Up @@ -239,6 +243,9 @@ Map::Map(const std::filesystem::path& dataPath, const std::string& mapName)
(globalWmo.m_bounds.MaxCorner.Y - globalWmo.m_bounds.MinCorner.Y) /
MeshSettings::TileSize));

m_globalWmoOriginX = globalWmo.m_bounds.MaxCorner.X;
m_globalWmoOriginY = globalWmo.m_bounds.MaxCorner.Y;

params.maxTiles = tileWidth * tileHeight;
params.maxPolys = 1 << DT_POLY_BITS;

Expand Down Expand Up @@ -409,14 +416,7 @@ std::shared_ptr<WmoModel> Map::EnsureWmoModelLoaded(const std::string& mpq_path)

bool Map::HasADTs() const
{
for (int y = 0; y < MeshSettings::Adts; ++y)
for (int x = 0; x < MeshSettings::Adts; ++x) {
if (m_hasADT[x][y]) {
return true;
}
}

return false;
return m_hasADTs;
}

bool Map::HasADT(int x, int y) const
Expand Down Expand Up @@ -588,7 +588,15 @@ const Tile* Map::GetTile(float x, float y) const
{
// find the tile corresponding to this (x, y)
int tileX, tileY;
math::Convert::WorldToTile({x, y, 0.f}, tileX, tileY);

// maps based on a global WMO have their tiles positioned differently
if (HasADTs())
math::Convert::WorldToTile({x, y, 0.f}, tileX, tileY);
else
{
tileX = (m_globalWmoOriginY - y) / MeshSettings::TileSize;
tileY = (m_globalWmoOriginX - x) / MeshSettings::TileSize;
}

auto const tile = m_tiles.find({tileX, tileY});

Expand Down Expand Up @@ -900,19 +908,16 @@ bool Map::ZoneAndArea(const math::Vertex& position, unsigned int& zone,
unsigned int& area) const
{
// find the tile corresponding to this (x, y)
int tileX, tileY;
math::Convert::WorldToTile({position.X, position.Y, 0.f}, tileX, tileY);
auto const tile = GetTile(position.X, position.Y);

auto const tile = m_tiles.find({tileX, tileY});

if (tile == m_tiles.end())
if (!tile)
return false;

std::vector<const Tile*> tiles {tile->second.get()};
std::vector<const Tile*> tiles {tile};

math::Ray ray {
{position.X, position.Y, position.Z},
{position.X, position.Y, tile->second->m_bounds.getMinimum().Z}};
{position.X, position.Y, tile->m_bounds.getMinimum().Z}};

unsigned int localZone, localArea;
auto const rayResult = RayCast(ray, tiles, false, &localZone, &localArea);
Expand All @@ -924,9 +929,8 @@ bool Map::ZoneAndArea(const math::Vertex& position, unsigned int& zone,

float adtHeight;
unsigned int adtZone, adtArea;
auto const adtResult =
GetADTHeight(tile->second.get(), position.X, position.Y, adtHeight,
&adtZone, &adtArea);
auto const adtResult = GetADTHeight(tile, position.X, position.Y, adtHeight,
&adtZone, &adtArea);

if (adtResult && adtHeight > ray.GetHitPoint().Z)
{
Expand Down
6 changes: 6 additions & 0 deletions pathfind/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class Map

BVH m_bvhLoader;

// this is false when the map is based on a global wmo
bool m_hasADTs;

float m_globalWmoOriginX;
float m_globalWmoOriginY;

bool m_hasADT[MeshSettings::Adts][MeshSettings::Adts];
bool m_loadedADT[MeshSettings::Adts][MeshSettings::Adts];

Expand Down
Loading