mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-27 12:31:54 +00:00
Make kartdebugwaypoints far more clear to use for the debugging lines
Fix memory reallocation issue that I don't think could be seen currently
This commit is contained in:
parent
3d3b8b6bc6
commit
738d1f1940
2 changed files with 70 additions and 42 deletions
|
|
@ -461,7 +461,7 @@ boolean K_PathfindAStar(path_t *const path, pathfindsetup_t *const pathfindsetup
|
||||||
if (nodesarraycount >= pathfindsetup->nodesarraycapacity)
|
if (nodesarraycount >= pathfindsetup->nodesarraycapacity)
|
||||||
{
|
{
|
||||||
pathfindsetup->nodesarraycapacity = pathfindsetup->nodesarraycapacity * 2;
|
pathfindsetup->nodesarraycapacity = pathfindsetup->nodesarraycapacity * 2;
|
||||||
nodesarray = Z_Realloc(nodesarray, pathfindsetup->nodesarraycapacity, PU_STATIC, NULL);
|
nodesarray = Z_Realloc(nodesarray, pathfindsetup->nodesarraycapacity * sizeof(pathfindnode_t), PU_STATIC, NULL);
|
||||||
|
|
||||||
if (nodesarray == NULL)
|
if (nodesarray == NULL)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
110
src/k_waypoint.c
110
src/k_waypoint.c
|
|
@ -326,6 +326,34 @@ waypoint_t *K_GetWaypointFromIndex(size_t waypointindex)
|
||||||
return waypoint;
|
return waypoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------
|
||||||
|
static UINT32 K_DistanceBetweenWaypoints(waypoint_t *const waypoint1, waypoint_t *const waypoint2)
|
||||||
|
|
||||||
|
Gets the Euclidean distance between 2 waypoints by using their mobjs. Used for the heuristic.
|
||||||
|
|
||||||
|
Input Arguments:-
|
||||||
|
waypoint1 - The first waypoint
|
||||||
|
waypoint2 - The second waypoint
|
||||||
|
|
||||||
|
Return:-
|
||||||
|
Euclidean distance between the 2 waypoints
|
||||||
|
--------------------------------------------------*/
|
||||||
|
static UINT32 K_DistanceBetweenWaypoints(waypoint_t *const waypoint1, waypoint_t *const waypoint2)
|
||||||
|
{
|
||||||
|
UINT32 finaldist = UINT32_MAX;
|
||||||
|
I_Assert(waypoint1 != NULL);
|
||||||
|
I_Assert(waypoint2 != NULL);
|
||||||
|
|
||||||
|
{
|
||||||
|
const fixed_t xydist =
|
||||||
|
P_AproxDistance(waypoint1->mobj->x - waypoint2->mobj->x, waypoint1->mobj->y - waypoint2->mobj->y);
|
||||||
|
const fixed_t xyzdist = P_AproxDistance(xydist, waypoint1->mobj->z - waypoint2->mobj->z);
|
||||||
|
finaldist = ((UINT32)xyzdist >> FRACBITS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return finaldist;
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------
|
/*--------------------------------------------------
|
||||||
void K_DebugWaypointsSpawnLine(waypoint_t *const waypoint1, waypoint_t *const waypoint2)
|
void K_DebugWaypointsSpawnLine(waypoint_t *const waypoint1, waypoint_t *const waypoint2)
|
||||||
|
|
||||||
|
|
@ -341,8 +369,21 @@ static void K_DebugWaypointsSpawnLine(waypoint_t *const waypoint1, waypoint_t *c
|
||||||
mobj_t *spawnedmobj;
|
mobj_t *spawnedmobj;
|
||||||
fixed_t stepx, stepy, stepz;
|
fixed_t stepx, stepy, stepz;
|
||||||
fixed_t x, y, z;
|
fixed_t x, y, z;
|
||||||
|
UINT32 waypointdist;
|
||||||
INT32 n;
|
INT32 n;
|
||||||
UINT32 numofframes = 1; // If this was 0 it could divide by 0
|
skincolors_t linkcolour = SKINCOLOR_GREEN;
|
||||||
|
|
||||||
|
// This array is used to choose which colour should be on this connection
|
||||||
|
const skincolors_t linkcolours[] = {
|
||||||
|
SKINCOLOR_RED,
|
||||||
|
SKINCOLOR_BLUE,
|
||||||
|
SKINCOLOR_ORANGE,
|
||||||
|
SKINCOLOR_PINK,
|
||||||
|
SKINCOLOR_DREAM,
|
||||||
|
SKINCOLOR_CYAN,
|
||||||
|
SKINCOLOR_WHITE,
|
||||||
|
};
|
||||||
|
const size_t linkcolourssize = sizeof(linkcolours) / sizeof(skincolors_t);
|
||||||
|
|
||||||
// Error conditions
|
// Error conditions
|
||||||
I_Assert(waypoint1 != NULL);
|
I_Assert(waypoint1 != NULL);
|
||||||
|
|
@ -351,13 +392,18 @@ static void K_DebugWaypointsSpawnLine(waypoint_t *const waypoint1, waypoint_t *c
|
||||||
I_Assert(waypoint2->mobj != NULL);
|
I_Assert(waypoint2->mobj != NULL);
|
||||||
I_Assert(cv_kartdebugwaypoints.value != 0);
|
I_Assert(cv_kartdebugwaypoints.value != 0);
|
||||||
|
|
||||||
|
linkcolour = K_GetWaypointID(waypoint1)%linkcolourssize;
|
||||||
|
|
||||||
waypointmobj1 = waypoint1->mobj;
|
waypointmobj1 = waypoint1->mobj;
|
||||||
waypointmobj2 = waypoint2->mobj;
|
waypointmobj2 = waypoint2->mobj;
|
||||||
|
|
||||||
n = SPARKLES_PER_CONNECTION;
|
n = SPARKLES_PER_CONNECTION;
|
||||||
numofframes = S_SPRK16 - S_SPRK1;
|
|
||||||
|
|
||||||
// Draw the sparkles
|
// For every 2048 fracunits, double the number of sparkles
|
||||||
|
waypointdist = K_DistanceBetweenWaypoints(waypoint1, waypoint2);
|
||||||
|
n *= (waypointdist / 2048) + 1;
|
||||||
|
|
||||||
|
// Draw the line
|
||||||
stepx = (waypointmobj2->x - waypointmobj1->x) / n;
|
stepx = (waypointmobj2->x - waypointmobj1->x) / n;
|
||||||
stepy = (waypointmobj2->y - waypointmobj1->y) / n;
|
stepy = (waypointmobj2->y - waypointmobj1->y) / n;
|
||||||
stepz = (waypointmobj2->z - waypointmobj1->z) / n;
|
stepz = (waypointmobj2->z - waypointmobj1->z) / n;
|
||||||
|
|
@ -366,10 +412,17 @@ static void K_DebugWaypointsSpawnLine(waypoint_t *const waypoint1, waypoint_t *c
|
||||||
z = waypointmobj1->z;
|
z = waypointmobj1->z;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
spawnedmobj = P_SpawnMobj(x, y, z, MT_SPARK);
|
if ((leveltime + n) % 16 <= 4)
|
||||||
P_SetMobjState(spawnedmobj, S_SPRK1 + ((leveltime + n) % (numofframes + 1)));
|
{
|
||||||
spawnedmobj->state->nextstate = S_NULL;
|
spawnedmobj = P_SpawnMobj(x, y, z, MT_SPARK);
|
||||||
spawnedmobj->state->tics = 1;
|
P_SetMobjState(spawnedmobj, S_THOK);
|
||||||
|
spawnedmobj->state->nextstate = S_NULL;
|
||||||
|
spawnedmobj->state->tics = 1;
|
||||||
|
spawnedmobj->frame = spawnedmobj->frame & ~FF_TRANSMASK;
|
||||||
|
spawnedmobj->color = linkcolours[linkcolour];
|
||||||
|
spawnedmobj->scale = FixedMul(FRACUNIT/4, FixedDiv((15 - ((leveltime + n) % 16))*FRACUNIT, 15*FRACUNIT));
|
||||||
|
}
|
||||||
|
|
||||||
x += stepx;
|
x += stepx;
|
||||||
y += stepy;
|
y += stepy;
|
||||||
z += stepz;
|
z += stepz;
|
||||||
|
|
@ -578,34 +631,6 @@ static void K_UpdateNodesArrayBaseSize(size_t newnodesarraysize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------
|
|
||||||
static UINT32 K_DistanceBetweenWaypoints(waypoint_t *const waypoint1, waypoint_t *const waypoint2)
|
|
||||||
|
|
||||||
Gets the Euclidean distance between 2 waypoints by using their mobjs. Used for the heuristic.
|
|
||||||
|
|
||||||
Input Arguments:-
|
|
||||||
waypoint1 - The first waypoint
|
|
||||||
waypoint2 - The second waypoint
|
|
||||||
|
|
||||||
Return:-
|
|
||||||
Euclidean distance between the 2 waypoints
|
|
||||||
--------------------------------------------------*/
|
|
||||||
static UINT32 K_DistanceBetweenWaypoints(waypoint_t *const waypoint1, waypoint_t *const waypoint2)
|
|
||||||
{
|
|
||||||
UINT32 finaldist = UINT32_MAX;
|
|
||||||
I_Assert(waypoint1 != NULL);
|
|
||||||
I_Assert(waypoint2 != NULL);
|
|
||||||
|
|
||||||
{
|
|
||||||
const fixed_t xydist =
|
|
||||||
P_AproxDistance(waypoint1->mobj->x - waypoint2->mobj->x, waypoint1->mobj->y - waypoint2->mobj->y);
|
|
||||||
const fixed_t xyzdist = P_AproxDistance(xydist, waypoint1->mobj->z - waypoint2->mobj->z);
|
|
||||||
finaldist = ((UINT32)xyzdist >> FRACBITS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return finaldist;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------
|
/*--------------------------------------------------
|
||||||
static void **K_WaypointPathfindGetNext(void *data, size_t *numconnections)
|
static void **K_WaypointPathfindGetNext(void *data, size_t *numconnections)
|
||||||
|
|
||||||
|
|
@ -1443,13 +1468,16 @@ static waypoint_t *K_MakeWaypoint(mobj_t *const mobj)
|
||||||
|
|
||||||
P_SetTarget(&madewaypoint->mobj, mobj);
|
P_SetTarget(&madewaypoint->mobj, mobj);
|
||||||
|
|
||||||
// Go through the other waypoint mobjs in the map to find out how many waypoints are after this one
|
// Don't allow a waypoint that has its next ID set to itself to work
|
||||||
for (otherwaypointmobj = waypointcap; otherwaypointmobj != NULL; otherwaypointmobj = otherwaypointmobj->tracer)
|
if (mobj->threshold != mobj->movecount) {
|
||||||
{
|
// Go through the other waypoint mobjs in the map to find out how many waypoints are after this one
|
||||||
// threshold = next waypoint id, movecount = my id
|
for (otherwaypointmobj = waypointcap; otherwaypointmobj != NULL; otherwaypointmobj = otherwaypointmobj->tracer)
|
||||||
if (mobj->threshold == otherwaypointmobj->movecount)
|
|
||||||
{
|
{
|
||||||
madewaypoint->numnextwaypoints++;
|
// threshold = next waypoint id, movecount = my id
|
||||||
|
if (mobj->threshold == otherwaypointmobj->movecount)
|
||||||
|
{
|
||||||
|
madewaypoint->numnextwaypoints++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue