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

Fix alpha parsing. #69

Merged
merged 9 commits into from
Jul 23, 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
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
submodules: true

- name: Build wheels
uses: pypa/cibuildwheel@v2.15
uses: pypa/cibuildwheel@v2.16.5
env:
MACOSX_DEPLOYMENT_TARGET: "10.15"

Expand Down
35 changes: 22 additions & 13 deletions parser/Map/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,38 @@ Map::Map(const std::string& name)

reader->rpos(mdnmLocation + 4);
auto const mdnmSize = reader->Read<std::uint32_t>();
std::vector<char> doodadNameBuffer(mdnmSize);
reader->ReadBytes(&doodadNameBuffer[0], doodadNameBuffer.size());

char* p;
// Can be 0.
if (mdnmSize > 0)
{

for (p = &doodadNameBuffer[0]; *p == '\0'; ++p)
;
std::vector<char> doodadNameBuffer(mdnmSize);
reader->ReadBytes(&doodadNameBuffer[0], doodadNameBuffer.size());

do
{
m_doodadNames.emplace_back(p);
p = strchr(p, '\0');
if (!p)
break;
++p;
} while (p <= &doodadNameBuffer[doodadNameBuffer.size() - 1]);
for (p = &doodadNameBuffer[0]; *p == '\0'; ++p)
;

do
{
m_doodadNames.emplace_back(p);
p = strchr(p, '\0');
if (!p)
break;
++p;
} while (p <= &doodadNameBuffer[doodadNameBuffer.size() - 1]);
}

size_t monmLocation;
if (!reader->GetChunkLocation("MONM", wmoNameOffset, monmLocation))
THROW(Result::MONM_NOT_FOUND);

reader->rpos(monmLocation + 4);
auto const monmSize = reader->Read<std::uint32_t>();

// Truncated files, i.e. UnderMine.
if (monmSize == 0 || reader->IsEOF())
THROW(Result::BUFFER_TOO_SMALL);

std::vector<char> wmoNameBuffer(monmSize);
reader->ReadBytes(&wmoNameBuffer[0], wmoNameBuffer.size());

Expand Down
52 changes: 52 additions & 0 deletions pathfind/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,18 @@ std::shared_ptr<WmoModel> Map::EnsureWmoModelLoaded(const std::string& mpq_path)
return model;
}

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

bool Map::HasADT(int x, int y) const
{
return m_hasADT[x][y];
Expand Down Expand Up @@ -720,6 +732,46 @@ bool Map::FindNextZ(const Tile* tile, float x, float y, float zHint,
return true;
}

bool Map::FindPointInBetweenVectors(const math::Vertex& start, const math::Vertex& end,
const float distance,
math::Vertex& inBetweenPoint) const
{
const float generalDistance = start.GetDistance(end);
if (generalDistance < distance) {
return false;
}

const float factor = distance / generalDistance;
const float dx = start.X + factor * (end.X - start.X);
const float dy = start.Y + factor * (end.Y - start.Y);
constexpr float extents[] = {1.f, 1.f, 1.f};

const math::Vertex v1 {dx, dy, start.Z};
const math::Vertex v2 {dx, dy, end.Z};

float recastMiddle[3];
math::Convert::VertexToRecast(v1, recastMiddle);

dtPolyRef polyRef;
if (m_navQuery.findNearestPoly(recastMiddle, extents, &m_queryFilter,
&polyRef, nullptr) != DT_SUCCESS) {
math::Convert::VertexToRecast(v2, recastMiddle);
if (m_navQuery.findNearestPoly(recastMiddle, extents, &m_queryFilter,
&polyRef, nullptr) != DT_SUCCESS) {
return false;
}
}

float outputPoint[3];
if (m_navQuery.closestPointOnPoly(polyRef, recastMiddle, outputPoint, NULL) !=
DT_SUCCESS) {
return false;
}

math::Convert::VertexToWow(outputPoint, inBetweenPoint);
return true;
}

bool Map::FindRandomPointAroundCircle(const math::Vertex& centerPosition,
const float radius,
math::Vertex& randomPoint) const
Expand Down
6 changes: 6 additions & 0 deletions pathfind/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Map
Map(const std::filesystem::path& dataPath, const std::string& mapName);

bool HasADT(int x, int y) const;
bool HasADTs() const;
bool IsADTLoaded(int x, int y) const;
bool LoadADT(int x, int y);
void UnloadADT(int x, int y);
Expand Down Expand Up @@ -159,6 +160,11 @@ class Map
float radius,
math::Vertex& randomPoint) const;

bool FindPointInBetweenVectors(const math::Vertex& start,
const math::Vertex& end,
const float distance,
math::Vertex& inBetweenPoint) const;

const dtNavMesh& GetNavMesh() const { return m_navMesh; }
const dtNavMeshQuery& GetNavMeshQuery() const { return m_navQuery; }
};
Expand Down
31 changes: 31 additions & 0 deletions pathfind/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ bool adt_loaded(pathfind::Map& map, int adt_x, int adt_y) {
return map.IsADTLoaded(adt_x, adt_y);
}

bool has_adts(pathfind::Map& map) {
return map.HasADTs();
}

py::list python_query_heights(const pathfind::Map& map, float x, float y)
{
py::list result;
Expand Down Expand Up @@ -106,6 +110,18 @@ py::object get_zone_and_area(pathfind::Map& map, float x, float y, float z)
return py::make_tuple(zone, area);
}

py::object find_point_in_between_vectors(pathfind::Map& map, float distance, float x1, float y1, float z1, float x2, float y2, float z2)
{
const math::Vertex start {x1, y1, z1};
const math::Vertex end {x2, y2, z2};
math::Vertex in_between_point {};
if (!map.FindPointInBetweenVectors(start, end, distance, in_between_point)) {
return py::none();
}

return py::make_tuple(in_between_point.X, in_between_point.Y, in_between_point.Z);
}

py::object find_random_point_around_circle(pathfind::Map& map, float x, float y, float z, float radius) {
const math::Vertex start {x, y, z};

Expand Down Expand Up @@ -181,6 +197,17 @@ This is the value that would be achieved by walking from start to stop.)del",
py::arg("y"),
py::arg("z")
)
.def("find_point_in_between_vectors",
&find_point_in_between_vectors,
"Returns a point in between two vectors given a distance.",
py::arg("distance"),
py::arg("x1"),
py::arg("y1"),
py::arg("z1"),
py::arg("x2"),
py::arg("y2"),
py::arg("z2")
)
.def("find_random_point_around_circle",
&find_random_point_around_circle,
"Returns a random point from a circle within or slightly outside of the given radius.",
Expand All @@ -189,6 +216,10 @@ This is the value that would be achieved by walking from start to stop.)del",
py::arg("z"),
py::arg("radius")
)
.def("has_adts",
&has_adts,
"Checks if the map has any ADT."
)
.def("adt_loaded",
&adt_loaded,
"Checks if a specific ADT is loaded.",
Expand Down
6 changes: 6 additions & 0 deletions utility/BinaryStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ bool BinaryStream::GetChunkLocation(const std::string& chunkName,
return false;
}

bool BinaryStream::IsEOF()
{
auto const buff = buffer();
return m_rpos == buff->size();
}

void BinaryStream::Compress()
{
std::vector<std::uint8_t> buff(
Expand Down
1 change: 1 addition & 0 deletions utility/BinaryStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class BinaryStream
bool GetChunkLocation(const std::string& chunkName, size_t& result) const;
bool GetChunkLocation(const std::string& chunkName, size_t startLoc,
size_t& result) const;
bool IsEOF();

void Compress();
void Decompress();
Expand Down
6 changes: 6 additions & 0 deletions utility/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Vector3 Vector3::CrossProduct(const Vector3& a, const Vector3& b)
a.X * b.Y - a.Y * b.X);
}

float Vector3::GetDistance(const Vector3& other) const
{
return sqrtf(powf((X - other.X), 2) + powf((Y - other.Y), 2) +
powf((Z - other.Z), 2));
}

Vector3 Vector3::Normalize(const Vector3& a)
{
const float d = 1.f / sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z);
Expand Down
1 change: 1 addition & 0 deletions utility/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct Vector3
static Vector3 CrossProduct(const Vector3& a, const Vector3& b);
static Vector3 Normalize(const Vector3& a);
static Vector3 Transform(const Vector3& position, const Matrix& matrix);
float GetDistance(const Vector3& other) const;

float X;
float Y;
Expand Down
Loading