Skip to content

Commit

Permalink
Fix 3D Ground Loading (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyackman authored Jul 12, 2024
1 parent 62eb590 commit 32168e2
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions src/util/teleport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,45 @@

namespace YimMenu::Teleport
{
inline bool LoadGroundAtCoords(rage::fvector3& coords)
inline bool LoadGroundAtCoords(rage::fvector3& location)
{
float groundZ;
bool done = false;
auto notificationId = Notifications::Show("Streaming", "Loading ground at coords", NotificationType::Info, 5000);

for (int i = 0; i < 20; i++)
constexpr float max_ground_check = 1000.f;
constexpr int max_attempts = 300;
float ground_z = location.z;
int current_attempts = 0;
bool found_ground;
float height;

do
{
for (int z = 0; z < 1000; z += 25)
{
float ground_iteration = static_cast<float>(z);
if (i >= 1 && (z % 100 == 0))
{
STREAMING::REQUEST_COLLISION_AT_COORD(coords.x, coords.y, ground_iteration);
ScriptMgr::Yield(1ms);
}
if (MISC::GET_GROUND_Z_FOR_3D_COORD(coords.x, coords.y, ground_iteration, &groundZ, false))
{
coords.z = groundZ + 1.f;
done = true;
}
}

float height;
if (done && WATER::GET_WATER_HEIGHT(coords.x, coords.y, coords.z, &height))
{
coords.z = height + 1.f;
}

if (done)
found_ground = MISC::GET_GROUND_Z_FOR_3D_COORD(location.x, location.y, max_ground_check, &ground_z, FALSE);
STREAMING::REQUEST_COLLISION_AT_COORD(location.x, location.y, location.z);

if (current_attempts % 10 == 0)
{
Notifications::Erase(notificationId);

return true;
location.z += 25.f;
}

++current_attempts;

ScriptMgr::Yield();
} while (!found_ground && current_attempts < max_attempts);

if (!found_ground)
{
return false;
}

Notifications::Erase(notificationId);
Notifications::Show("Streaming", "Failed loading ground at coords", NotificationType::Warning);

coords.z = 1000.f;

return false;

if (WATER::GET_WATER_HEIGHT(location.x, location.y, location.z, &height))
{
location.z = height;
}
else
{
location.z = ground_z + 1.f;
}

return true;
}

// Entity typdef is being ambiguous with Entity class
Expand Down Expand Up @@ -120,4 +116,4 @@ namespace YimMenu::Teleport
return true;
}
}
}
}

0 comments on commit 32168e2

Please sign in to comment.