use std::vector for array

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7944 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 80c50917890c8396d0508008a9cdc25788c8cc5d
Former-commit-id: eead71d548486558c39b86a4275ba9f5f17ade66
This commit is contained in:
iobyte 2022-01-26 00:34:25 +00:00
parent d22814ba93
commit 23c1e38f76
3 changed files with 33 additions and 42 deletions

View file

@ -85,7 +85,6 @@ static osg::Timer m_timer;
int grMaxTextureUnits = 0;
tdble grMaxDammage = 10000.0;
int grNbCars = 0;
void *grHandle = 0;
void *grTrackHandle = 0;

View file

@ -33,8 +33,6 @@ extern double grCurTime, ratio;
extern void *grHandle;
extern void *grTrackHandle;
extern int grNbCars;
extern int initTrack(tTrack *track);
extern int initCars(tSituation *s);
#define GR_VIEW_STD 0 /* full screen view mode */

View file

@ -18,6 +18,7 @@
***************************************************************************/
#include <algorithm>
#include <vector>
#include <osg/Camera>
#include <osg/Matrix>
@ -1652,16 +1653,17 @@ GetDistToStart(tCarElt *car)
return lg;
}
typedef struct
{
double prio;
int viewable;
int event;
} tSchedView;
class SDCarCamRoadZoomTVD : public SDCarCamRoadZoom
{
tSchedView *schedView;
struct SchedView
{
SchedView() : prio(0.0), viewable(false), event(false) { }
double prio;
bool viewable;
bool event;
};
std::vector<SchedView> schedView;
double camChangeInterval;
double camEventInterval;
double lastEventTime;
@ -1679,14 +1681,7 @@ public:
fovymax, fnear, ffar, myfogstart, myfogend)
{
this->ncars = ncars;
schedView = (tSchedView *)calloc(ncars, sizeof(tSchedView));
if (!schedView)
{
GfTrace("malloc error");
//GfScrShutdown();
exit (1);
}
schedView.resize(ncars);
lastEventTime = 0;
lastViewTime = 0;
current = -1;
@ -1696,11 +1691,9 @@ public:
proximityThld = GfParmGetNum(grHandle, GR_SCT_TVDIR, GR_ATT_PROXTHLD, (char*)NULL, 10.0);
}
~SDCarCamRoadZoomTVD() { free(schedView); }
void update(tCarElt *car, tSituation *s)
{
grNbCars = ncars;
int grNbCars = ncars;
int i, j;
int curCar;
double curPrio;
@ -1724,27 +1717,28 @@ public:
/* Track events*/
if (deltaEventTime > camEventInterval)
{
memset(schedView, 0, ncars * sizeof(tSchedView));
for (i = 0; i < grNbCars; i++)
for (i = 0; i < ncars; i++)
{
schedView[i].viewable = 1;
schedView[i].prio = 0.0;
schedView[i].viewable = true;
schedView[i].event = false;
}
car = screen->getCurrentCar();
schedView[car->index].viewable = 0;
schedView[car->index].viewable = false;
schedView[car->index].prio -= 10000;
for (i = 0; i < grNbCars; i++)
for (i = 0; i < ncars; i++)
{
tdble dist, fs;
car = s->cars[i];
schedView[car->index].prio += grNbCars - i;
schedView[car->index].prio += ncars - i;
fs = GetDistToStart(car);
if ((car->_state & RM_CAR_STATE_NO_SIMU) != 0)
{
schedView[car->index].viewable = 0;
schedView[car->index].viewable = false;
} else
{
}
@ -1755,15 +1749,15 @@ public:
/* out of track*/
if (dist > 0)
{
schedView[car->index].prio += grNbCars;
schedView[car->index].prio += ncars;
if (car->ctrl.raceCmd & RM_CMD_PIT_ASKED)
{
schedView[car->index].prio += grNbCars;
event = 1;
schedView[car->index].prio += ncars;
event = true;
}
}
for (j = i+1; j < grNbCars; j++)
for (j = i+1; j < ncars; j++)
{
tCarElt *car2 = s->cars[j];
tdble fs2 = GetDistToStart(car2);
@ -1774,11 +1768,11 @@ public:
if (d < proximityThld)
{
d = proximityThld - d;
schedView[car->index].prio += d * grNbCars / proximityThld;
schedView[car2->index].prio += d * (grNbCars - 1) / proximityThld;
schedView[car->index].prio += d * ncars / proximityThld;
schedView[car2->index].prio += d * (ncars - 1) / proximityThld;
if (i == 0)
{
event = 1;
event = true;
}
}
}
@ -1786,14 +1780,14 @@ public:
if (car->priv.collision)
{
schedView[car->index].prio += grNbCars;
event = 1;
schedView[car->index].prio += ncars;
event = true;
}
} else
{
if (i == current)
{
event = 1; /* update view*/
event = true; /* update view*/
}
}
}
@ -1805,16 +1799,16 @@ public:
curCar = 0;
curPrio = -1000000.0;
for (i = 0; i < grNbCars; i++)
for (i = 0; i < ncars; i++)
{
if ((schedView[i].prio > curPrio) && (schedView[i].viewable))
if ((schedView[i].prio > curPrio) && schedView[i].viewable)
{
curPrio = schedView[i].prio;
curCar = i;
}
}
for (i = 0; i < grNbCars; i++)
for (i = 0; i < ncars; i++)
{
if (s->cars[i]->index == curCar)
{