Skip to content

Commit 33f01cf

Browse files
committed
- added road connections view
1 parent 7224892 commit 33f01cf

1 file changed

Lines changed: 127 additions & 2 deletions

File tree

DriverLevelTool/viewer/renderlevel.cpp

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern bool g_displayCollisionBoxes;
2929
extern bool g_displayHeightMap;
3030
extern bool g_displayAllCellLevels;
3131
extern bool g_displayRoads;
32+
extern bool g_displayRoadConnections;
3233
extern bool g_noLod;
3334
extern int g_cellsDrawDistance;
3435

@@ -293,6 +294,131 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
293294
DrawCellObject(co, cameraPos, cameraAngleY, frustrumVolume, true);
294295
}
295296

297+
if (g_displayRoadConnections)
298+
{
299+
#define IS_STRAIGHT_SURFACE(surfid) (((surfid) > -1) && ((surfid) & 0xFFFFE000) == 0 && ((surfid) & 0x1FFF) < levMapDriver2->GetNumStraights())
300+
#define IS_CURVED_SURFACE(surfid) (((surfid) > -1) && ((surfid) & 0xFFFFE000) == 0x4000 && ((surfid) & 0x1FFF) < levMapDriver2->GetNumCurves())
301+
#define IS_JUNCTION_SURFACE(surfid) (((surfid) > -1) && ((surfid) & 0xFFFFE000) == 0x2000 && ((surfid) & 0x1FFF) < levMapDriver2->GetNumJunctions())
302+
303+
for (int i = 0; i < levMapDriver2->GetNumStraights(); i++)
304+
{
305+
DRIVER2_STRAIGHT* straight = levMapDriver2->GetStraight(i);
306+
307+
VECTOR_NOPAD positionA{ straight->Midx, 0, straight->Midz };
308+
309+
for (int j = 0; j < 4; j++)
310+
{
311+
if (straight->ConnectIdx[j] == -1)
312+
continue;
313+
314+
if (IS_STRAIGHT_SURFACE(straight->ConnectIdx[j]))
315+
{
316+
DRIVER2_STRAIGHT* conn = levMapDriver2->GetStraight(straight->ConnectIdx[j]);
317+
VECTOR_NOPAD positionB{ conn->Midx, 0, conn->Midz };
318+
319+
DebugOverlay_Line(FromFixedVector(positionA), FromFixedVector(positionB), ColorRGBA(1,1,0,1));
320+
}
321+
else if (IS_CURVED_SURFACE(straight->ConnectIdx[j]))
322+
{
323+
DRIVER2_CURVE* conn = levMapDriver2->GetCurve(straight->ConnectIdx[j]);
324+
325+
const int radius = conn->inside * 1024 + 256 + 512 * ROAD_LANES_COUNT(conn);
326+
const int curveLength = conn->end - conn->start & 4095;
327+
const int distAlongPath = conn->start + curveLength / 2;
328+
329+
VECTOR_NOPAD positionB{ conn->Midx + (radius * isin(distAlongPath)) / ONE, 0, conn->Midz + (radius * icos(distAlongPath)) / ONE };
330+
331+
DebugOverlay_Line(FromFixedVector(positionA), FromFixedVector(positionB), ColorRGBA(1, 1, 0, 1));
332+
}
333+
else if (IS_JUNCTION_SURFACE(straight->ConnectIdx[j]))
334+
{
335+
DRIVER2_JUNCTION* connJ = levMapDriver2->GetJunction(straight->ConnectIdx[j]);
336+
337+
for (int k = 0; k < 4; k++)
338+
{
339+
if (IS_STRAIGHT_SURFACE(connJ->ExitIdx[k]))
340+
{
341+
DRIVER2_STRAIGHT* connK = levMapDriver2->GetStraight(connJ->ExitIdx[k]);
342+
VECTOR_NOPAD positionB{ connK->Midx, 0, connK->Midz };
343+
344+
DebugOverlay_Line(FromFixedVector(positionA), FromFixedVector(positionB), ColorRGBA(1, 0, 0, 1));
345+
}
346+
else if (IS_CURVED_SURFACE(connJ->ExitIdx[k]))
347+
{
348+
DRIVER2_CURVE* connK = levMapDriver2->GetCurve(connJ->ExitIdx[k]);
349+
const int radius = connK->inside * 1024 + 256 + 512 * ROAD_LANES_COUNT(connK);
350+
const int curveLength = connK->end - connK->start & 4095;
351+
const int distAlongPath = connK->start + curveLength / 2;
352+
353+
VECTOR_NOPAD positionB{ connK->Midx + (radius * isin(distAlongPath)) / ONE, 0, connK->Midz + (radius * icos(distAlongPath)) / ONE };
354+
355+
DebugOverlay_Line(FromFixedVector(positionA), FromFixedVector(positionB), ColorRGBA(1, 0, 0, 1));
356+
}
357+
}
358+
}
359+
} // for j
360+
} // for i
361+
362+
for (int i = 0; i < levMapDriver2->GetNumCurves(); i++)
363+
{
364+
DRIVER2_CURVE* curve = levMapDriver2->GetCurve(i | 0x4000);
365+
366+
VECTOR_NOPAD positionA{ curve->Midx, 0, curve->Midz };
367+
368+
for (int j = 0; j < 4; j++)
369+
{
370+
if (curve->ConnectIdx[j] == -1)
371+
continue;
372+
373+
if (IS_STRAIGHT_SURFACE(curve->ConnectIdx[j]))
374+
{
375+
DRIVER2_STRAIGHT* conn = levMapDriver2->GetStraight(curve->ConnectIdx[j]);
376+
VECTOR_NOPAD positionB{ conn->Midx, 0, conn->Midz };
377+
378+
DebugOverlay_Line(FromFixedVector(positionA), FromFixedVector(positionB), ColorRGBA(1, 1, 0, 1));
379+
}
380+
else if (IS_CURVED_SURFACE(curve->ConnectIdx[j]))
381+
{
382+
DRIVER2_CURVE* conn = levMapDriver2->GetCurve(curve->ConnectIdx[j]);
383+
384+
const int radius = conn->inside * 1024 + 256 + 512 * ROAD_LANES_COUNT(conn);
385+
const int curveLength = conn->end - conn->start & 4095;
386+
const int distAlongPath = conn->start + curveLength / 2;
387+
388+
VECTOR_NOPAD positionB{ conn->Midx + (radius * isin(distAlongPath)) / ONE, 0, conn->Midz + (radius * icos(distAlongPath)) / ONE };
389+
390+
DebugOverlay_Line(FromFixedVector(positionA), FromFixedVector(positionB), ColorRGBA(1, 1, 0, 1));
391+
}
392+
else if (IS_JUNCTION_SURFACE(curve->ConnectIdx[j]))
393+
{
394+
DRIVER2_JUNCTION* connJ = levMapDriver2->GetJunction(curve->ConnectIdx[j]);
395+
396+
for (int k = 0; k < 4; k++)
397+
{
398+
if (IS_STRAIGHT_SURFACE(connJ->ExitIdx[k]))
399+
{
400+
DRIVER2_STRAIGHT* connK = levMapDriver2->GetStraight(connJ->ExitIdx[k]);
401+
VECTOR_NOPAD positionB{ connK->Midx, 0, connK->Midz };
402+
403+
DebugOverlay_Line(FromFixedVector(positionA), FromFixedVector(positionB), ColorRGBA(1, 0, 0, 1));
404+
}
405+
else if (IS_CURVED_SURFACE(connJ->ExitIdx[k]))
406+
{
407+
DRIVER2_CURVE* connK = levMapDriver2->GetCurve(connJ->ExitIdx[k]);
408+
const int radius = connK->inside * 1024 + 256 + 512 * ROAD_LANES_COUNT(connK);
409+
const int curveLength = connK->end - connK->start & 4095;
410+
const int distAlongPath = connK->start + curveLength / 2;
411+
412+
VECTOR_NOPAD positionB{ connK->Midx + (radius * isin(distAlongPath)) / ONE, 0, connK->Midz + (radius * icos(distAlongPath)) / ONE };
413+
414+
DebugOverlay_Line(FromFixedVector(positionA), FromFixedVector(positionB), ColorRGBA(1, 0, 0, 1));
415+
}
416+
}
417+
}
418+
} // for j
419+
} // for i
420+
}
421+
296422
if (g_displayRoads)
297423
{
298424
// TODO: road at their surface height!
@@ -349,6 +475,7 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
349475

350476
int distAlongPath = curve->start;
351477
int curveLength = curve->end - curve->start & 4095;
478+
int radius = curve->inside * 1024 + 256 + 512 * j;
352479

353480
ColorRGBA color(0.0f, 1.0f, 0.0f, 1.0f);
354481

@@ -370,8 +497,6 @@ void DrawLevelDriver2(const Vector3D& cameraPos, float cameraAngleY, const Volum
370497

371498
for (int k = 0; k < 8; k++)
372499
{
373-
int radius = curve->inside * 1024 + 256 + 512 * j;
374-
375500
positionB = VECTOR_NOPAD{ curve->Midx + (radius * isin(distAlongPath)) / ONE, 0, curve->Midz + (radius * icos(distAlongPath)) / ONE };
376501

377502
distAlongPath += curveLength / 7; // 8 - 1

0 commit comments

Comments
 (0)