Added CarList per Segment
This commit is contained in:
parent
10a4b6fc04
commit
d00981a3f7
102
CppOutRun.layout
102
CppOutRun.layout
|
@ -2,14 +2,9 @@
|
|||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Release" />
|
||||
<File name="src/include/clouds.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="src/src/circuit.cc" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="306" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/src/clouds.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="203" topLine="0" />
|
||||
<Cursor1 position="18164" topLine="562" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/include/circuit.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
@ -17,19 +12,28 @@
|
|||
<Cursor1 position="813" topLine="36" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/include/cars.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="CMakeLists.txt" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="227" topLine="0" />
|
||||
<Cursor1 position="406" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/src/circuit.cc" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="src/include/segment.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="9970" topLine="327" />
|
||||
<Cursor1 position="574" topLine="11" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/include/segment.h" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="src/main.cc" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="906" topLine="6" />
|
||||
<Cursor1 position="7332" topLine="258" />
|
||||
</Cursor>
|
||||
<Folding>
|
||||
<Collapse line="316" />
|
||||
<Collapse line="343" />
|
||||
</Folding>
|
||||
</File>
|
||||
<File name="src/src/cars.cc" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="274" topLine="14" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/colors.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
|
@ -37,6 +41,36 @@
|
|||
<Cursor1 position="352" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/src/clouds.cc" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="203" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/include/cars.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="243" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/include/clouds.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="306" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/fixed.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="778" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/include/drawstuff.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="622" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/parameters.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="285" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/src/drawstuff.cc" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="2486" topLine="61" />
|
||||
|
@ -47,23 +81,9 @@
|
|||
<Collapse line="76" />
|
||||
</Folding>
|
||||
</File>
|
||||
<File name="src/fixed.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="src/src/camera.cc" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="778" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/main.cc" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="6483" topLine="239" />
|
||||
</Cursor>
|
||||
<Folding>
|
||||
<Collapse line="287" />
|
||||
<Collapse line="314" />
|
||||
</Folding>
|
||||
</File>
|
||||
<File name="src/include/camera.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="221" topLine="0" />
|
||||
<Cursor1 position="370" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/src/segment.cc" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
|
||||
|
@ -71,29 +91,9 @@
|
|||
<Cursor1 position="593" topLine="28" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="CMakeLists.txt" open="0" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="src/include/camera.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="406" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/parameters.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="285" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/src/camera.cc" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="370" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/include/drawstuff.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="622" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="src/src/cars.cc" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="921" topLine="10" />
|
||||
<Cursor1 position="221" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
|
|
|
@ -12,7 +12,7 @@ class Cars
|
|||
Cars( float x, double z, uint8_t s, uint8_t t );
|
||||
~Cars();
|
||||
|
||||
void Project3DFP( camera* c );
|
||||
void Project3DFP( camera* c, uint16_t index );
|
||||
|
||||
|
||||
float wX;
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#include <stdint.h>
|
||||
#include "camera.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#define std ustl
|
||||
|
||||
enum BiomeType
|
||||
{
|
||||
|
@ -43,6 +46,8 @@ class Segment
|
|||
int8_t LDeco=-1;
|
||||
int8_t RDeco=-1;
|
||||
int8_t DScale=0;
|
||||
|
||||
std::vector <uint8_t> CarList;
|
||||
};
|
||||
|
||||
#endif // SEGMENT_H
|
||||
|
|
109
src/main.cc
109
src/main.cc
|
@ -41,8 +41,10 @@ std::vector<Cars*> traffic;
|
|||
bool stop = false;
|
||||
bool record = false;
|
||||
bool screenshot = false;
|
||||
|
||||
bool ShowDebug1 = false;
|
||||
bool ShowDebug2 = false;
|
||||
bool ShowDebug3 = false;
|
||||
|
||||
bool BDrawDeco = true;
|
||||
bool BDrawClds = true;
|
||||
|
@ -122,15 +124,29 @@ static void get_inputs( float dt )
|
|||
if(keydown(KEY_EXIT)) stop = true;
|
||||
|
||||
#if IS_FXLIB==1
|
||||
if(keydown(KEY_OPTN))
|
||||
if(keydown(KEY_XOT))
|
||||
{
|
||||
ShowDebug1 = !ShowDebug1;
|
||||
ShowDebug2 = false;
|
||||
}
|
||||
if(keydown(KEY_VARS))
|
||||
{
|
||||
ShowDebug2 = !ShowDebug2;
|
||||
ShowDebug1 = false;
|
||||
ShowDebug2 = false;
|
||||
ShowDebug3 = false;
|
||||
}
|
||||
if(keydown(KEY_LOG))
|
||||
{
|
||||
ShowDebug1 = true;
|
||||
ShowDebug2 = false;
|
||||
ShowDebug3 = false;
|
||||
}
|
||||
if(keydown(KEY_LN))
|
||||
{
|
||||
ShowDebug1 = false;
|
||||
ShowDebug2 = true;
|
||||
ShowDebug3 = false;
|
||||
}
|
||||
if(keydown(KEY_SIN))
|
||||
{
|
||||
ShowDebug1 = false;
|
||||
ShowDebug2 = false;
|
||||
ShowDebug3 = true;
|
||||
}
|
||||
|
||||
if(keydown(KEY_F1)) BDrawDeco = !BDrawDeco;
|
||||
|
@ -219,16 +235,39 @@ int main(void)
|
|||
prof_enter(perf_project);
|
||||
|
||||
|
||||
updateTraffic();
|
||||
if (BDrawCars)
|
||||
{
|
||||
updateTraffic();
|
||||
|
||||
for (int k=0; k<traffic.size(); k++) // Need to project 1 more segment than actual drawing
|
||||
{
|
||||
uint16_t CarSegment = traffic[k]->wZ / SEGMENT_LENGTH;
|
||||
if (CarSegment>=indexstart && CarSegment<indexend)
|
||||
{
|
||||
circuit[CarSegment]->CarList.push_back(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
minYRoad = SCREEN_HEIGHT;
|
||||
|
||||
uint16_t cumulCurve=0;
|
||||
for (int k=indexstart; k<=indexend; k++) // Need to project 1 more segment than actual drawing
|
||||
for (int k=indexstart; k<=indexend; k++) // Need to project 1 more segment than actual drawing
|
||||
{
|
||||
projectCircuitFP( k );
|
||||
if (circuit[k]->Y<minYRoad) minYRoad = circuit[k]->Y;
|
||||
circuit[k]->CumulatedCurve = cumulCurve;
|
||||
projectCircuitFP( k ); // We project the current segment
|
||||
|
||||
if (circuit[k]->Y < minYRoad) // This is a trick to save precious time while drawing the Sky
|
||||
minYRoad = circuit[k]->Y;
|
||||
|
||||
circuit[k]->CumulatedCurve = cumulCurve; // This is the curve accumulated when we are drawing curves
|
||||
cumulCurve += circuit[k]->Curve;
|
||||
|
||||
if (BDrawCars)
|
||||
for( int l=0; l<circuit[k]->CarList.size(); l++ ) // For all cars inside that road segment
|
||||
{
|
||||
uint8_t indexCar = circuit[k]->CarList[l];
|
||||
traffic[indexCar]->Project3DFP( cam, k );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -258,18 +297,16 @@ int main(void)
|
|||
currentcurve = circuit[k]->CumulatedCurve;
|
||||
drawCircuitSegment( k );
|
||||
if (BDrawDeco) drawDecoration( k );
|
||||
}
|
||||
|
||||
if (BDrawCars)
|
||||
for(int k=0; k<traffic.size(); k++)
|
||||
{
|
||||
if (traffic[k]->wZ >= circuit[indexstart]->wZ && traffic[k]->wZ<=circuit[indexend]->wZ)
|
||||
{
|
||||
traffic[k]->visible = true;
|
||||
drawTraffic( k );
|
||||
}
|
||||
else traffic[k]->visible = false;
|
||||
}
|
||||
if (BDrawCars)
|
||||
for( int l=0; l<circuit[k]->CarList.size(); l++ ) // For all cars inside that road segment
|
||||
{
|
||||
uint8_t indexCar = circuit[k]->CarList[l];
|
||||
drawTraffic( indexCar );
|
||||
}
|
||||
|
||||
//circuit[k]->CarList.clear();
|
||||
}
|
||||
|
||||
dsubimage( SCREEN_CX-36, SCREEN_HEIGHT-48, &player, 257,1,72,46, DIMAGE_NONE);
|
||||
|
||||
|
@ -283,7 +320,7 @@ int main(void)
|
|||
dprint( 331, 210, C_WHITE, "RecVid" ); // Key F6
|
||||
#endif // 1
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
if (ShowDebug1)
|
||||
{
|
||||
Segment* currentSeg = circuit[indexstart];
|
||||
|
@ -340,8 +377,30 @@ int main(void)
|
|||
}
|
||||
|
||||
}
|
||||
#endif // 0
|
||||
if (ShowDebug3)
|
||||
{
|
||||
dprint( 1, 1, C_BLACK, "S");
|
||||
for( int k=0; k<=indexend-indexstart; k++)
|
||||
{
|
||||
int nbCars=circuit[indexstart+k]->CarList.size();
|
||||
dprint( 25+k*25, 1, C_BLACK, "%d", indexstart+k );
|
||||
dprint( 25+k*25, 11, C_RED, "%d", nbCars );
|
||||
|
||||
for( int l=0; l<nbCars; l++ ) // For all cars inside that road segment
|
||||
{
|
||||
dprint( 1, 33+10*l, C_BLACK, "C" );
|
||||
dprint( 25+k*25, 33+10*l, C_BLACK, "%d", circuit[indexstart+k]->CarList[l]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
for( int k=indexend-1; k>=indexstart; k--)
|
||||
{
|
||||
circuit[k]->CarList.clear();
|
||||
}
|
||||
|
||||
|
||||
dupdate();
|
||||
|
|
|
@ -2,10 +2,14 @@
|
|||
#include "../include/camera.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "../include/segment.h"
|
||||
#include "../parameters.h"
|
||||
#include "../include/circuit.h"
|
||||
|
||||
|
||||
extern std::vector<Segment*> circuit;
|
||||
|
||||
|
||||
Cars::Cars()
|
||||
{
|
||||
|
@ -26,8 +30,8 @@ Cars::Cars( float x, double z, uint8_t s, uint8_t t )
|
|||
X = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
void Cars::Project3DFP( camera* c )
|
||||
|
||||
void Cars::Project3DFP( camera* c, uint16_t index )
|
||||
{
|
||||
fixed_t DX = (fix(wX*ROAD_WIDTH) - c->cX);
|
||||
fixed_t DY = (interpolatePositionY( wZ ) - c->cY);
|
||||
|
@ -45,8 +49,8 @@ void Cars::Project3DFP( camera* c )
|
|||
fixed_t sX=fmul(fix(SCREEN_CX), (fix(1)+tempx));
|
||||
fixed_t sY=fmul(fix(SCREEN_CY), (fix(1)-tempy));
|
||||
|
||||
X=fround(sX);
|
||||
X=fround(sX) + circuit[ index ]->CumulatedCurve;
|
||||
Y=fround(sY);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ void createTraffic( void )
|
|||
for( int k = 0; k < NB_CARS_TRAFFIC; k++)
|
||||
{
|
||||
int8_t X = rand() % 4;
|
||||
double Z = (double) (rand() % 10000);
|
||||
double Z = (double) (rand() % 4000);
|
||||
uint8_t S = rand() % 4;
|
||||
uint8_t T = rand() % 3;
|
||||
|
||||
|
@ -591,11 +591,15 @@ void drawTraffic( uint16_t index )
|
|||
|
||||
image = scaledCars[traffic[index]->Type][distance];
|
||||
|
||||
/*
|
||||
int X = circuit[segnumber]->X + circuit[segnumber]->CumulatedCurve + traffic[index]->wX*circuit[segnumber]->W - image->width/2;
|
||||
int Y = circuit[segnumber]->Y - image->height;
|
||||
|
||||
traffic[index]->X = X;
|
||||
traffic[index]->Y = Y;
|
||||
*/
|
||||
int X = traffic[index]->X - image->width/2;
|
||||
int Y = traffic[index]->Y - image->height;
|
||||
|
||||
dimage( X, Y, image );
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ void drawSky( uint16_t color )
|
|||
|
||||
void drawSkyOptimised( uint16_t color )
|
||||
{
|
||||
dma_memset(gint_vram, (color << 16) | color, 396 * minYRoad * 2);
|
||||
dma_memset(gint_vram, (color << 16) | color, 396 * (minYRoad+1) * 2);
|
||||
};
|
||||
|
||||
void drawSky( uint8_t R, uint8_t G, uint8_t B )
|
||||
|
|
Loading…
Reference in New Issue