diff --git a/CppOutRun.layout b/CppOutRun.layout index 08458e5..3aa932c 100644 --- a/CppOutRun.layout +++ b/CppOutRun.layout @@ -2,14 +2,9 @@ - + - - - - - - + @@ -17,19 +12,28 @@ - + - + - + - + - + - + + + + + + + + + + @@ -37,6 +41,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -47,23 +81,9 @@ - + - - - - - - - - - - - - - - - + @@ -71,29 +91,9 @@ - + - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/include/cars.h b/src/include/cars.h index 3692e00..4be5781 100644 --- a/src/include/cars.h +++ b/src/include/cars.h @@ -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; diff --git a/src/include/segment.h b/src/include/segment.h index 4a92042..e4c6f80 100644 --- a/src/include/segment.h +++ b/src/include/segment.h @@ -5,6 +5,9 @@ #include #include "camera.h" +#include + +#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 CarList; }; #endif // SEGMENT_H diff --git a/src/main.cc b/src/main.cc index efba9b0..12d6cbc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -41,8 +41,10 @@ std::vector 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; kwZ / SEGMENT_LENGTH; + if (CarSegment>=indexstart && CarSegmentCarList.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]->YY; - 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; lCarList.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; kwZ >= 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; lCarList.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; lCarList[l]); + } + } + } + #endif + + + + for( int k=indexend-1; k>=indexstart; k--) + { + circuit[k]->CarList.clear(); + } dupdate(); diff --git a/src/src/cars.cc b/src/src/cars.cc index f7e5a12..24cad51 100644 --- a/src/src/cars.cc +++ b/src/src/cars.cc @@ -2,10 +2,14 @@ #include "../include/camera.h" #include +#include +#include "../include/segment.h" #include "../parameters.h" #include "../include/circuit.h" +extern std::vector 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); } -*/ + diff --git a/src/src/circuit.cc b/src/src/circuit.cc index 82df2b4..fb21d56 100644 --- a/src/src/circuit.cc +++ b/src/src/circuit.cc @@ -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 ); } diff --git a/src/src/drawstuff.cc b/src/src/drawstuff.cc index 343b3be..173fa2c 100644 --- a/src/src/drawstuff.cc +++ b/src/src/drawstuff.cc @@ -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 )