0.25 with minor corrections

master
Sylvain PILLOT 7 months ago
parent b6e00a98f3
commit 1694aeb3ee
  1. 7
      CMakeLists.txt
  2. 3
      CppOutRun.cbp
  3. 76
      CppOutRun.layout
  4. 5
      assets-cg/backgrnd/fxconv-metadata.txt
  5. BIN
      assets-cg/backgrnd/mountain.png
  6. BIN
      assets-cg/backgrnd/treeline.png
  7. BIN
      assets-cg/trees/tree4.png
  8. BIN
      assets-cg/trees/tree5.png
  9. BIN
      assets-cg/trees/tree6.png
  10. 19
      src/colors.h
  11. 35
      src/include/cars.h
  12. 38
      src/include/circuit.h
  13. 2
      src/include/clouds.h
  14. 5
      src/include/drawstuff.h
  15. 19
      src/include/segment.h
  16. 342
      src/main.cc
  17. 13
      src/parameters.h
  18. 53
      src/src/cars.cc
  19. 396
      src/src/circuit.cc
  20. 3
      src/src/clouds.cc
  21. 54
      src/src/drawstuff.cc
  22. 10
      src/src/segment.cc

@ -16,7 +16,7 @@ set(SOURCES
src/src/circuit.cc
src/src/drawstuff.cc
src/src/clouds.cc
# ...
src/src/cars.cc
)
set(ASSETS_cg
@ -31,10 +31,15 @@ set(ASSETS_cg
assets-cg/trees/tree1.png
assets-cg/trees/tree2.png
assets-cg/trees/tree3.png
assets-cg/trees/tree4.png
assets-cg/trees/tree5.png
assets-cg/trees/tree6.png
assets-cg/player/player.png
assets-cg/clouds/sky1.png
assets-cg/clouds/sky2.png
assets-cg/clouds/sky3.png
assets-cg/backgrnd/mountain.png
assets-cg/backgrnd/treeline.png
)
fxconv_declare_assets(${ASSETS_cg} WITH_METADATA)

@ -28,8 +28,10 @@
<Unit filename="CMakeLists.txt" />
<Unit filename="assets-cg/fxconv-metadata.txt" />
<Unit filename="assets-cg/traffic/fxconv-metadata.txt" />
<Unit filename="src/colors.h" />
<Unit filename="src/fixed.h" />
<Unit filename="src/include/camera.h" />
<Unit filename="src/include/cars.h" />
<Unit filename="src/include/circuit.h" />
<Unit filename="src/include/clouds.h" />
<Unit filename="src/include/drawstuff.h" />
@ -37,6 +39,7 @@
<Unit filename="src/main.cc" />
<Unit filename="src/parameters.h" />
<Unit filename="src/src/camera.cc" />
<Unit filename="src/src/cars.cc" />
<Unit filename="src/src/circuit.cc" />
<Unit filename="src/src/clouds.cc" />
<Unit filename="src/src/drawstuff.cc" />

@ -2,64 +2,94 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="src/include/circuit.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/include/segment.h" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="516" topLine="11" />
<Cursor1 position="574" topLine="11" />
</Cursor>
</File>
<File name="CMakeLists.txt" open="1" top="0" tabpos="7" 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="1219" topLine="0" />
<Cursor1 position="370" topLine="0" />
</Cursor>
</File>
<File name="src/parameters.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/include/circuit.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="189" topLine="0" />
<Cursor1 position="645" topLine="30" />
</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">
<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="3302" topLine="245" />
<Cursor1 position="221" topLine="0" />
</Cursor>
</File>
<File name="src/src/segment.cc" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<File name="CMakeLists.txt" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="368" topLine="12" />
<Cursor1 position="411" topLine="3" />
</Cursor>
</File>
<File name="src/include/drawstuff.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/src/drawstuff.cc" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="354" topLine="0" />
<Cursor1 position="2642" topLine="49" />
</Cursor>
<Folding>
<Collapse line="33" />
<Collapse line="40" />
<Collapse line="76" />
</Folding>
</File>
<File name="src/src/drawstuff.cc" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/parameters.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="953" topLine="0" />
<Cursor1 position="398" topLine="0" />
</Cursor>
</File>
<File name="src/src/circuit.cc" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/colors.h" open="0" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3642" topLine="127" />
<Cursor1 position="352" 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">
<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="124" topLine="0" />
<Cursor1 position="15894" topLine="490" />
</Cursor>
</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">
<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="221" topLine="0" />
<Cursor1 position="306" topLine="0" />
</Cursor>
</File>
<File name="src/src/circuit.cc" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="16690" topLine="486" />
</Cursor>
</File>
<File name="src/fixed.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<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/drawstuff.h" open="0" 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/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/segment.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src/src/segment.cc" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="2" zoom_2="0">
<Cursor>
<Cursor1 position="203" topLine="0" />
</Cursor>
</File>
<File name="src/include/cars.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="443" topLine="0" />
</Cursor>
</File>
<File name="src/src/cars.cc" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="765" topLine="0" />
<Cursor1 position="1019" topLine="11" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -0,0 +1,5 @@
*.png:
type: bopti-image
profile: p4
name_regex: (.*)\.png \1

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

@ -0,0 +1,19 @@
#ifndef COLORS_H
#define COLORS_H
#define LIGHT_GREY_ROAD 0xC638
#define DARK_GREY_ROAD 0xBDD7 //0xB5B6
#define WHITE_STRIPE 0xFFFF
#define RED_STRIPE 0xF800
#define LIGHT_GREEN_GRASS 0x07E5
#define DARK_GREEN_GRASS 0x0680
#define LIGHT_YELLOW_GRASS 0xFFE0
#define DARK_YELLOW_GRASS 0xD6A0
#define DAY_BLUE_SKY 0x017F
#endif // PARAMETERS_H

@ -0,0 +1,35 @@
#ifndef CARS_H
#define CARS_H
#include <stdint.h>
#include "camera.h"
class Cars
{
public:
Cars();
Cars( float x, double z, uint8_t s, uint8_t t );
~Cars();
void Project3DFP( camera* c, uint16_t index );
float wX;
double wZ;
int16_t X;
int16_t Y;
uint8_t S;
uint8_t Speed;
uint8_t Type;
uint8_t DScale;
// for debugging only
bool visible;
uint16_t segnum;
};
#endif // CARS_H

@ -12,9 +12,11 @@ enum Length
enum HillSize
{
H_SMALL = 10,
H_MEDIUM = 20,
H_BIG = 40
H_VERYSMALL = 20,
H_SMALL = 40,
H_MEDIUM = 60,
H_BIG = 80,
H_VERYBIG = 100
};
enum HillType
@ -25,9 +27,11 @@ enum HillType
enum CurveStrength
{
C_EASY = 2,
C_MEDIUM = 4,
C_HARD = 6
C_VERYEASY = 2,
C_EASY = 4,
C_MEDIUM = 6,
C_HARD = 8,
C_VERYHARD = 10
};
enum CurveType
@ -40,30 +44,42 @@ enum Decoration
{
PALMTREE = 0,
DEADTREE = 1,
OAKTREE = 2
OAKTREE = 2,
CACTUS = 3,
BIGLEAF = 4,
SMALLLEAF = 5
};
void initData( void );
void createCircuit( void );
void createClouds( void );
void createTraffic( void );
void projectCircuitFP( void );
void projectCircuitFP( uint16_t index );
void updateTraffic( float dt );
void printCircuit( void );
void printCircuit( int i );
void drawCircuitSegment( uint16_t index );
void drawDecoration( uint16_t index );
void drawTraffic( uint16_t index );
void drawClouds( int offset );
void drawFarBackground( int offset );
void drawNearBackground( int offset );
void freeDecoration( void );
void prepareDecoration( void );
void addStraightLine( Length l );
void addCurve( Length l, CurveStrength s, CurveType t );
void addHill( Length l, HillSize s, HillType t );
void freeTraffic( void );
void prepareTraffic( void );
void addStraightLine( Length l, int8_t biome );
void addCurve( Length l, CurveStrength s, CurveType t, int8_t biome );
void addHill( Length l, HillSize s, HillType t, int8_t biome );
fixed_t interpolatePositionX( double currentZ );
fixed_t interpolatePositionY( double currentZ );
uint16_t findIndex( double currentZ );

@ -21,7 +21,7 @@ class Clouds
int16_t X;
int16_t Y;
int8_t type;
int8_t Type;
};
#endif // CLOUDS_H

@ -3,8 +3,13 @@
void gint_dhline(int x1, int x2, int y, uint16_t color);
void drawPolygon( int x1min, int x1max, int y1, int x2min, int x2max, int y2, uint8_t R, uint8_t G, uint8_t B );
void drawPolygon( int x1min, int x1max, int y1, int x2min, int x2max, int y2, uint16_t color );
void drawGrass( int y1, int y2, uint8_t R, uint8_t G, uint8_t B );
void drawGrass( int y1, int y2, uint16_t color );
void drawSky( void );
void drawSky( uint16_t color );
void drawSky( uint8_t R, uint8_t G, uint8_t B );
void drawSky( int ymin, int ymax );
void drawSkyOptimised( uint16_t color );

@ -5,19 +5,32 @@
#include <stdint.h>
#include "camera.h"
#include <vector>
#define std ustl
enum BiomeType
{
PLAINS = 0,
DESERT = 1
};
class Segment
{
public:
Segment();
Segment( uint16_t n_seg );
Segment( int16_t x, int16_t y, double z, int8_t c );
Segment( int16_t x, int16_t y, double z, int8_t c, int8_t left, int8_t right );
Segment( int16_t x, int16_t y, double z, int8_t c, int8_t s );
Segment( int16_t x, int16_t y, double z, int8_t c, int8_t s, int8_t left, int8_t right );
~Segment();
void Project3DFP( camera* c );
int8_t environment = PLAINS;
int8_t Curve=0;
int8_t Slope=0;
int16_t CumulatedCurve=0;
// World Coordinates (X,Y,Z)
@ -34,6 +47,8 @@ class Segment
int8_t LDeco=-1;
int8_t RDeco=-1;
int8_t DScale=0;
std::vector <uint8_t> CarList;
};
#endif // SEGMENT_H

@ -13,19 +13,23 @@
#include <math.h>
#include <vector>
#include "parameters.h"
#include "colors.h"
#include "include/camera.h"
#include "include/segment.h"
#include "parameters.h"
#include "include/circuit.h"
#include "include/drawstuff.h"
#include "include/clouds.h"
#include "include/cars.h"
extern bopti_image_t car1, car2, car3, car4, car5, car6, car7, car8;
extern bopti_image_t tree1, tree2, tree3;
extern bopti_image_t tree1, tree2, tree3, tree4, tree5, tree6;
extern bopti_image_t player;
extern bopti_image_t sky1, sky2, sky3;
extern bopti_image_t mountain;
extern bopti_image_t treeline;
std::vector<Segment*> circuit;
@ -33,26 +37,48 @@ int MAX_SEGMENT=0;
camera *cam;
std::vector<Clouds*> nuages;
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;
bool BDrawCars = true;
bool BDrawRoad = true;
uint16_t currentcurve=0;
uint8_t shiftcolor=0;
float speed = 0;
float maxspeedforward = 8;
float maxspeedbackward = 4;
float maxspeedforward = 5;
float maxspeedbackward = 2;
int direction = 1;
bool speedcontrol = false;
static void get_inputs( float dt )
uint8_t minYRoad = 224; // We will track the upper Y (in fact the minimum Y during the RoadDrawing to optimize the rendering of the Sky
int8_t viewside = 0;
int deltaFarbackground = 0;
int deltaNearbackground = 0;
int lastindex=0;
int CC=0; // current curve
int CS=0;
static void get_inputs( float dt, int index )
{
CC = circuit[index]->Curve;
CS = circuit[index]->Slope;
key_event_t ev;
while((ev = pollevent()).type != KEYEV_NONE)
{
@ -60,8 +86,35 @@ static void get_inputs( float dt )
}
speedcontrol = false;
if(keydown(KEY_LEFT)) cam->decX(25.0);
if(keydown(KEY_RIGHT)) cam->incX(25.0);
viewside=0;
if (CC<0)
{
viewside=-1;
cam->decX( CC*dt*speed/100 );
}
else if (CC>0)
{
viewside=+1;
cam->decX( CC*dt*speed/100 );
}
if(keydown(KEY_LEFT))
{
cam->decX(25.0);
viewside=-1;
if (CC<0) viewside=-2; // We are in a curve and turning
if (CC>0) viewside=0;
}
if(keydown(KEY_RIGHT))
{
cam->incX(25.0);
viewside=1;
if (CC>0) viewside=+2;
if (CC<0) viewside=0;
}
if(keydown(KEY_SHIFT))
{
@ -108,19 +161,41 @@ static void get_inputs( float dt )
if(keydown(KEY_EXIT)) stop = true;
if(keydown(KEY_F1))
#if IS_FXLIB==1
if(keydown(KEY_XOT))
{
ShowDebug1 = false;
ShowDebug2 = false;
ShowDebug3 = false;
}
if(keydown(KEY_LOG))
{
ShowDebug1 = !ShowDebug1;
ShowDebug1 = true;
ShowDebug2 = false;
ShowDebug3 = false;
}
if(keydown(KEY_F2))
if(keydown(KEY_LN))
{
ShowDebug2 = !ShowDebug2;
ShowDebug1 = false;
ShowDebug2 = true;
ShowDebug3 = false;
}
if(keydown(KEY_SIN))
{
ShowDebug1 = false;
ShowDebug2 = false;
ShowDebug3 = true;
}
if(keydown(KEY_F1)) BDrawDeco = !BDrawDeco;
if(keydown(KEY_F2)) BDrawClds = !BDrawClds;
if(keydown(KEY_F3)) BDrawCars = !BDrawCars;
if(keydown(KEY_F4)) BDrawRoad = !BDrawRoad;
if(keydown(KEY_F5)) screenshot = true;
if(keydown(KEY_F6)) record = !record;
if(keydown(KEY_F4)) screenshot = true;
#endif // IS_FXLIB
if (speedcontrol==false)
{
@ -132,6 +207,30 @@ static void get_inputs( float dt )
else
cam->decZ(speed*dt);
}
/* Adjust position of the background */
if (lastindex!=index)
{
deltaFarbackground -= CC*speed*dt/250;
deltaNearbackground -= CC*speed*dt/100;
}
lastindex = index;
/* adjust speed if we drive on the side of the road */
if (fround(cam->cX)<-1*ROAD_WIDTH && speed>2.0) speed=2.0;
if (fround(cam->cX)>ROAD_WIDTH && speed>2.0) speed=2.0;
if (fround(cam->cX)<-1.35*ROAD_WIDTH && speed>0.0)
{
speed=0.0;
cam->cX=fix(-0.75*ROAD_WIDTH);
}
if (fround(cam->cX)>1.35*ROAD_WIDTH && speed>0.0)
{
speed=0.0;
cam->cX=fix(0.75*ROAD_WIDTH);
}
}
@ -140,27 +239,27 @@ int main(void)
__printf_enable_fp();
__printf_enable_fixed();
#if IS_FXLIB==1
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
usb_open(interfaces, GINT_CALL_NULL);
#endif
prof_t perf_create, perf_project, perf_render;
uint32_t time_create=0, time_project=0, time_render=0;
prof_t perf_update, perf_create, perf_project, perf_render;
uint32_t time_update=0, time_create=0, time_project=0, time_render=0;
prof_init();
int nbInterestingSegments = (MAX_RENDER_DISTANCE / SEGMENT_LENGTH) + 10; // the number of segments to be projected considering the rendering distance
//--------------
initData( );
int nbInterestingSegments = (MAX_RENDER_DISTANCE / SEGMENT_LENGTH); // the number of segments to be projected considering the rendering distance
//--------------
perf_create = prof_make();
prof_enter(perf_create);
createCircuit();
createClouds();
prepareDecoration();
initData( ); // Positioning of the Camera
createCircuit(); // Creates the circuit
createClouds(); // Creates the Sky and Clouds
createTraffic(); // Creates the cas
prepareDecoration(); // Prepares the multiple variations of Decoration (image scaling)
prepareTraffic(); // Prepares the multiple variations of Cars (image scaling)
prof_leave(perf_create);
time_create = prof_time(perf_create);
@ -171,44 +270,77 @@ int main(void)
int indexstart = 0;
int indexend = 0;
uint32_t maxDistance = (MAX_SEGMENT-nbInterestingSegments-5)*SEGMENT_LENGTH;
uint32_t maxDistance = (MAX_SEGMENT-nbInterestingSegments-1)*SEGMENT_LENGTH;
uint32_t dt=0;
uint16_t l=0;
while (!stop)
{
get_inputs( dt );
dt = ((float) (time_render+time_project) / 1000.0);
perf_update = prof_make();
prof_enter(perf_update);
get_inputs( dt, indexstart );
dt = ((float) (time_update+time_render+time_project) / 1000.0);
//--------------
if (fround(cam->cZ)<=0) cam->cZ=fixdouble(0.0);
if (fround(cam->cZ)>=maxDistance) cam->cZ=fixdouble(maxDistance);
indexstart = fround(cam->cZ) / SEGMENT_LENGTH;
indexend = indexstart+nbInterestingSegments+1;
if (indexstart<0) indexstart=0;
// there is an offset equals to 400 on z position
// this is to compute the first index of segment to be projected to screen
indexend = indexstart+nbInterestingSegments+1;
if (indexstart>MAX_SEGMENT-nbInterestingSegments-2) indexstart=MAX_SEGMENT-nbInterestingSegments-2;
if (indexstart<0) indexstart=0;
if (indexstart>MAX_SEGMENT-nbInterestingSegments-1-2) indexstart=MAX_SEGMENT-nbInterestingSegments-1-2;
prof_leave(perf_update);
time_update = prof_time(perf_update);
//--------------
perf_project = prof_make();
prof_enter(perf_project);
//cam->cY = fix( 300 + interpolatePositionY(fround(cam->cZ)) );
uint16_t cumulCurve=0;
for (int k=indexstart; k<=indexend; k++) // Need to project 1 more segment than actual drawing
{
projectCircuitFP( k );
circuit[k]->CumulatedCurve = cumulCurve;
cumulCurve += circuit[k]->Curve;
}
if (BDrawCars)
{
updateTraffic( dt );
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)
{
traffic[k]->visible = true;
circuit[CarSegment]->CarList.push_back(k);
}
else
traffic[k]->visible = false;
}
}
minYRoad = SCREEN_HEIGHT;
uint16_t cumulCurve=0;
for (int k=indexstart; k<=indexend; k++) // Need to project 1 more segment than actual drawing
{
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 );
}
}
prof_leave(perf_project);
time_project = prof_time(perf_project);
@ -218,20 +350,90 @@ int main(void)
perf_render = prof_make();
prof_enter(perf_render);
drawSky( );
drawClouds( l % 396 );
cam->cY = fix( 300 ) + interpolatePositionY(fround(cam->cZ));
drawSky( DAY_BLUE_SKY );
if (BDrawClds)
drawClouds( l % 396 );
drawFarBackground( deltaFarbackground );
drawNearBackground( deltaNearbackground );
cam->cY = fix( 300+2*CS ) + interpolatePositionY(fround(cam->cZ) );
for( int k=indexend-1; k>=indexstart; k--)
{
currentcurve = circuit[k]->CumulatedCurve;
drawCircuitSegment( k );
drawDecoration( k );
if (BDrawRoad)
drawCircuitSegment( k );
if (BDrawDeco)
drawDecoration( k );
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();
}
int mod_base=20;
int mod_comp=10;
if (abs(speed)<1.0) mod_base = 30, mod_comp = 15;
else if (abs(speed)<2.0) mod_base = 20, mod_comp = 10;
else if (abs(speed)<3.0) mod_base = 16, mod_comp = 8;
else if (abs(speed)<4.0) mod_base = 12, mod_comp = 6;
else if (abs(speed)<5.0) mod_base = 8, mod_comp = 4;
else mod_base = 4, mod_comp = 2;
if ((speed==0) || (l%mod_base<=mod_comp)) // the small rick to have the speed impression on wheels and to have the correct view of the car during turns
{
if (viewside==-2) dsubimage( SCREEN_CX-40, SCREEN_HEIGHT-46, &player, 99,1,80,46, DIMAGE_NONE);
else if (viewside==-1) dsubimage( SCREEN_CX-37, SCREEN_HEIGHT-46, &player, 181,1,74,46, DIMAGE_NONE);
else if (viewside==0) dsubimage( SCREEN_CX-36, SCREEN_HEIGHT-46, &player, 257,1,72,46, DIMAGE_NONE);
else if (viewside==1) dsubimage( SCREEN_CX-37, SCREEN_HEIGHT-46, &player, 331,1,74,46, DIMAGE_NONE);
else if (viewside==2) dsubimage( SCREEN_CX-40, SCREEN_HEIGHT-46, &player, 407,1,80,46, DIMAGE_NONE);
}
else
{
if (viewside==-2) dsubimage( SCREEN_CX-40, SCREEN_HEIGHT-46, &player, 99,49,80,46, DIMAGE_NONE);
else if (viewside==-1) dsubimage( SCREEN_CX-37, SCREEN_HEIGHT-46, &player, 181,49,74,46, DIMAGE_NONE);
else if (viewside==0) dsubimage( SCREEN_CX-36, SCREEN_HEIGHT-46, &player, 257,49,72,46, DIMAGE_NONE);
else if (viewside==1) dsubimage( SCREEN_CX-37, SCREEN_HEIGHT-46, &player, 331,49,74,46, DIMAGE_NONE);
else if (viewside==2) dsubimage( SCREEN_CX-40, SCREEN_HEIGHT-46, &player, 407,49,80,46, DIMAGE_NONE);
}
//dprint( 1, 1, C_BLACK, "Crt=%.3D ms", time_create );
//dprint( 1, 15, C_RED, "Prj=%.3D ms", time_project );
//dprint( 1, 30, C_RED, "Rdr=%.3D ms", time_render );
//dprint( 1, 45, C_RED, "Upd=%.3D ms", time_update );
dprint( 1, 1, C_BLACK, "Dt=%.3D ms", dt );
//dprint( 1, 1, C_BLACK, "FPS=%.3D ms", 1000/dt );
/*
#if 0
dprint( 1, 210, C_WHITE, "Decs: %c", BDrawDeco==true?'Y':'N' ); // Key F1
dprint( 67, 210, C_WHITE, "Clds: %c", BDrawClds==true?'Y':'N' ); // Key F2
dprint( 133, 210, C_WHITE, "Cars: %c", BDrawCars==true?'Y':'N' ); // Key F3
dprint( 199, 210, C_WHITE, "DtR: %.1f", ((float) (time_render) / 1000.0) ); // Key F4
dprint( 265, 210, C_WHITE, "ScrSht" ); // Key F5
dprint( 331, 210, C_WHITE, "RecVid" ); // Key F6
#endif // 1
#if 0
if (ShowDebug1)
{
Segment* currentSeg = circuit[indexstart];
@ -261,34 +463,72 @@ int main(void)
}
if (ShowDebug2)
{
#if 0
dprint( 1, 1, C_RED, "Crt=%.3D ms", time_create );
dprint( 1, 15, C_RED, "Prj=%.3D ms", time_project );
dprint( 1, 29, C_RED, "Rdr=%.3D ms", time_render );
dprint( 1, 50, C_BLACK, "ISt_Z=%.1lf", circuit[indexstart]->wZ);
dprint( 1, 65, C_BLACK, "IEd_Z=%.1lf", circuit[indexend]->wZ);
for( int k=indexend-1; k>=indexstart; k--)
{
dprint( 100, 1+10*k-indexstart, C_WHITE, "S[%d]=%d", k, circuit[k]->DScale );
}
for( int k=0; k<nuages.size(); k++)
{
dprint( 250, 1+10*k, C_WHITE, "Cl[%d]=(%d,%d,%d)", k, nuages[k]->X, nuages[k]->Y, nuages[k]->type );
}
#endif // 0
for( int k=0; k<traffic.size(); k++)
{
if (traffic[k]->visible == true) dprint( 1, 1+10*k, C_GREEN, "Car %d Sc=%d wZ=%.0lf / Seg=%d X=%d Y=%d", k, traffic[k]->DScale, traffic[k]->wZ, traffic[k]->segnum, traffic[k]->X, traffic[k]->Y, traffic[k]->S );
else dprint( 1, 1+10*k, C_RED, "Car %d Sc=%d wZ=%.0lf / Seg=%d X=%d Y=%d", k, traffic[k]->DScale, traffic[k]->wZ, traffic[k]->segnum, traffic[k]->X, traffic[k]->Y, traffic[k]->S );
}
}
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
*/
dsubimage( SCREEN_CX-36, SCREEN_HEIGHT-48, &player, 257,1,72,46, DIMAGE_NONE);
/*
for( int k=indexend-1; k>=indexstart; k--)
{
circuit[k]->CarList.clear();
}
*/
dupdate();
//r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT);
//dupdate();
r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT);
prof_leave(perf_render);
time_render = prof_time(perf_render);
#if IS_FXLIB==1
if (screenshot && usb_is_open())
{
usb_fxlink_screenshot(true);
usb_fxlink_screenshot(false);
screenshot = false;
}
@ -296,19 +536,23 @@ int main(void)
{
usb_fxlink_videocapture(false);
}
#endif
l++;
}
prof_quit();
usb_close();
#if IS_FXLIB==1
usb_close();
#endif
circuit.clear();
nuages.clear();
delete cam;
freeDecoration();
freeTraffic();
return 1;
}

@ -14,9 +14,22 @@
#define ASPECT_RATIO 1.767
#define DISTANCE_SCREEN 0.83444
#define MAX_RENDER_DISTANCE 3000
#define NB_CLOUDS_SKY 10
#define NB_CARS_TRAFFIC 100
#define MAX_SUBIMAGES_TREES 12
#define NB_TREES_TYPES 6
#define MAX_SUBIMAGES_CARS 12
#define NB_CARS_TYPES 8
#define std ustl
#define IS_FXLIB 1
#endif // PARAMETERS_H

@ -0,0 +1,53 @@
#include "../include/cars.h"
#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()
{
//ctor
}
Cars::~Cars()
{
//dtor
}
Cars::Cars( float x, double z, uint8_t s, uint8_t t )
{
wX = x;
wZ = z;
Speed = s;
Type = t;
X = 0;
}
void Cars::Project3DFP( camera* c, uint16_t index )
{
fixed_t DX = fix(wX*ROAD_WIDTH) - c->cX;
fixed_t DY = interpolatePositionY(wZ) - c->cY;
fixed_t divDZ = fdiv( fix(1), (fixdouble(wZ) - c->cZ));
fixed_t divAR = fdiv(fix(1), fixdouble(ASPECT_RATIO));
fixed_t Scale = fmul(fixdouble(DISTANCE_SCREEN), divDZ);
fixed_t tempx = fmul(fmul(DX,Scale), divAR);
fixed_t tempy = fmul(DY, Scale);
fixed_t sX=fmul(fix(SCREEN_CX), (fix(1)+tempx));
fixed_t sY=fmul(fix(SCREEN_CY), (fix(1)-tempy));
X = fround(sX) + circuit[ index ]->CumulatedCurve;
Y = fround(sY);
}

@ -2,6 +2,8 @@
#include "../include/segment.h"
#include "../include/camera.h"
#include "../include/clouds.h"
#include "../include/cars.h"
#include "../parameters.h"
#include <gint/display.h>
@ -9,10 +11,13 @@
#include <gint/rtc.h>
#include "../include/drawstuff.h"
#include "../colors.h"
extern std::vector<Segment*> circuit;
extern std::vector<Clouds*> nuages;
extern std::vector<Cars*> traffic;
extern camera *cam;
extern uint16_t currentcurve;
extern uint8_t shiftcolor;
@ -21,11 +26,13 @@ extern bool ShowDebug1;
extern bopti_image_t car1, car2, car3, car4, car5, car6, car7, car8;
extern bopti_image_t tree1, tree2, tree3;
extern bopti_image_t tree1, tree2, tree3, tree4, tree5, tree6;
extern bopti_image_t sky1, sky2, sky3;
extern bopti_image_t mountain;
extern bopti_image_t treeline;
bopti_image_t *scaledTrees[3][25] = { 0 };
bopti_image_t *scaledTrees[NB_TREES_TYPES][MAX_SUBIMAGES_TREES] = { 0 };
bopti_image_t *scaledCars[NB_CARS_TYPES][MAX_SUBIMAGES_CARS] = { 0 };
size_t image_size_profile(int profile, int width, int height)
@ -121,15 +128,12 @@ bopti_image_t *resize(bopti_image_t const *src, int w, int h)
}
void initData( void )
{
cam = new camera();
cam->cX = fixdouble(0.0f);
cam->cY = fixdouble(300.0f);
cam->cZ = fixdouble(260.0f);
cam->cZ = fixdouble(0.0f);
}
@ -142,33 +146,29 @@ void createCircuit( void )
}
*/
addStraightLine( L_VERYSHORT );
addStraightLine( L_VERYSHORT );
addCurve( L_SHORT, C_EASY, LEFT_CURVE );
addHill( L_MEDIUM, H_BIG, UP_HILL );
addHill( L_MEDIUM, H_BIG, DOWN_HILL );
addCurve( L_SHORT, C_HARD, RIGHT_CURVE );
addStraightLine( L_VERYLONG );
addCurve( L_SHORT, C_HARD, LEFT_CURVE );
addStraightLine( L_VERYLONG );
addCurve( L_SHORT, C_EASY, LEFT_CURVE );
addHill( L_MEDIUM, H_BIG, UP_HILL );
addHill( L_MEDIUM, H_BIG, DOWN_HILL );
addCurve( L_SHORT, C_HARD, RIGHT_CURVE );
addStraightLine( L_VERYLONG );
addCurve( L_SHORT, C_HARD, LEFT_CURVE );
addHill( L_MEDIUM, H_BIG, UP_HILL );
addHill( L_MEDIUM, H_BIG, DOWN_HILL );
addCurve( L_SHORT, C_HARD, RIGHT_CURVE );
addStraightLine( L_VERYLONG );
addCurve( L_SHORT, C_HARD, LEFT_CURVE );
addStraightLine( L_VERYLONG );
addCurve( L_SHORT, C_EASY, LEFT_CURVE );
addHill( L_MEDIUM, H_BIG, UP_HILL );
addHill( L_MEDIUM, H_BIG, DOWN_HILL );
addCurve( L_SHORT, C_HARD, RIGHT_CURVE );
addStraightLine( L_VERYLONG );
addCurve( L_SHORT, C_HARD, LEFT_CURVE );
addStraightLine( L_VERYSHORT, PLAINS );
addStraightLine( L_VERYSHORT, DESERT );
//addStraightLine( L_VERYSHORT, PLAINS );
//addStraightLine( L_VERYSHORT, DESERT );
addCurve( L_SHORT, C_HARD, LEFT_CURVE, DESERT );
addCurve( L_SHORT, C_HARD, RIGHT_CURVE, DESERT );
addStraightLine( L_LONG, DESERT );
addHill( L_MEDIUM, H_BIG, UP_HILL, DESERT );
addHill( L_MEDIUM, H_BIG, DOWN_HILL, PLAINS );
//addCurve( L_SHORT, C_HARD, RIGHT_CURVE, PLAINS );
addStraightLine( L_VERYLONG, PLAINS );
addCurve( L_SHORT, C_HARD, LEFT_CURVE, PLAINS );
addStraightLine( L_VERYLONG, DESERT );
addCurve( L_SHORT, C_EASY, LEFT_CURVE, DESERT );
//addHill( L_MEDIUM, H_BIG, UP_HILL, DESERT );
//addHill( L_MEDIUM, H_BIG, DOWN_HILL, DESERT );
//addCurve( L_SHORT, C_HARD, RIGHT_CURVE, PLAINS );
//addStraightLine( L_VERYLONG, PLAINS );
//addCurve( L_SHORT, C_HARD, LEFT_CURVE, PLAINS );
//addHill( L_MEDIUM, H_BIG, UP_HILL, PLAINS );
//addHill( L_MEDIUM, H_BIG, DOWN_HILL, PLAINS );
//addCurve( L_SHORT, C_HARD, RIGHT_CURVE, DESERT );
//addStraightLine( L_VERYLONG, DESERT );
};
@ -176,10 +176,10 @@ void createClouds( void )
{
srand( rtc_ticks() );
for( int k = 0; k < 10; k++)
for( int k = 0; k < NB_CLOUDS_SKY; k++)
{
int X = (rand() % 1188) - 396;
int Y = rand() % 80;
int X = (rand() % 792);
int Y = rand() % 60;
int T = rand() % 3;
Clouds* cl=new Clouds( X, Y, T );
@ -188,15 +188,43 @@ void createClouds( void )
}
void addStraightLine( Length l )
void createTraffic( void )
{
srand( rtc_ticks() );
for( int k = 0; k < NB_CARS_TRAFFIC; k++)
{
int8_t X = rand() % 4;
//double Z = (double) (rand() % 4000);
//int8_t X = 0;
double Z = (k+1)*SEGMENT_LENGTH;
uint8_t S = 4 + (rand() % 2);
uint8_t T = rand() % 8;
Cars* car;
// Depending on which line the car is placed, we choose the right fraction of W
if (X==0) car = new Cars( -0.75, (double) Z, S, T );
else if (X==1) car = new Cars( -0.25, (double) Z, S, T );
else if (X==2) car = new Cars( 0.25, (double) Z, S, T );
else if (X==3) car = new Cars( 0.75, (double) Z, S, T );
if (car!=nullptr)
traffic.push_back( car );
}
}
void addStraightLine( Length l, int8_t biome )
{
double lastZ=0;
int16_t lastY=0;
if (circuit.size()!=0)
uint16_t lastIndex = circuit.size();
if (lastIndex!=0)
{
lastY=circuit[circuit.size()-1]->wY;
lastZ=circuit[circuit.size()-1]->wZ;
lastY=circuit[lastIndex-1]->wY;
lastZ=circuit[lastIndex-1]->wZ+SEGMENT_LENGTH;
}
srand( rtc_ticks() );
@ -207,25 +235,31 @@ void addStraightLine( Length l )
int deco = rand() % 4;
Segment *seg;
if (deco==0) seg=new Segment( 0, lastY, lastZ + (i+1)*SEGMENT_LENGTH, 0, -1, -1 );
else if (deco==1) seg=new Segment( 0, lastY, lastZ + (i+1)*SEGMENT_LENGTH, 0, -1, DEADTREE );
else if (deco==2) seg=new Segment( 0, lastY, lastZ + (i+1)*SEGMENT_LENGTH, 0, PALMTREE, -1 );
else if (deco==3) seg=new Segment( 0, lastY, lastZ + (i+1)*SEGMENT_LENGTH, 0, PALMTREE, DEADTREE );
if (deco==0) seg=new Segment( 0, lastY, lastZ + i*SEGMENT_LENGTH, 0, 0, SMALLLEAF, -1 );
else if (deco==1) seg=new Segment( 0, lastY, lastZ + i*SEGMENT_LENGTH, 0, 0, -1, DEADTREE );
else if (deco==2) seg=new Segment( 0, lastY, lastZ + i*SEGMENT_LENGTH, 0, 0, PALMTREE, -1 );
else if (deco==3) seg=new Segment( 0, lastY, lastZ + i*SEGMENT_LENGTH, 0, 0, CACTUS, BIGLEAF );
if (seg!=nullptr) circuit.push_back( seg );
if (seg!=nullptr)
{
seg->environment = biome;
circuit.push_back( seg );
}
}
}
void addCurve( Length l, CurveStrength s, CurveType t )
void addCurve( Length l, CurveStrength s, CurveType t, int8_t biome )
{
double lastZ=0;
int16_t lastY=0;
if (circuit.size()!=0)
uint16_t lastIndex = circuit.size();
if (lastIndex!=0)
{
lastY=circuit[circuit.size()-1]->wY;
lastZ=circuit[circuit.size()-1]->wZ;
lastY=circuit[lastIndex-1]->wY;
lastZ=circuit[lastIndex-1]->wZ+SEGMENT_LENGTH;
}
srand( rtc_ticks() );
for( int i=0; i<l; i++)
@ -235,26 +269,32 @@ void addCurve( Length l, CurveStrength s, CurveType t )
Segment *seg;
if (deco==0) seg=new Segment( 0, lastY, lastZ+(i+1)*SEGMENT_LENGTH, s*t, -1, -1 );
else if (deco==1) seg=new Segment( 0, lastY, lastZ+(i+1)*SEGMENT_LENGTH, s*t, -1, OAKTREE );
else if (deco==2) seg=new Segment( 0, lastY, lastZ+(i+1)*SEGMENT_LENGTH, s*t, DEADTREE, -1 );
else if (deco==3) seg=new Segment( 0, lastY, lastZ+(i+1)*SEGMENT_LENGTH, s*t, DEADTREE, OAKTREE );
if (deco==0) seg=new Segment( 0, lastY, lastZ+i*SEGMENT_LENGTH, s*t, 0, -1, -1 );
else if (deco==1) seg=new Segment( 0, lastY, lastZ+i*SEGMENT_LENGTH, s*t, 0, -1, OAKTREE );
else if (deco==2) seg=new Segment( 0, lastY, lastZ+i*SEGMENT_LENGTH, s*t, 0, DEADTREE, -1 );
else if (deco==3) seg=new Segment( 0, lastY, lastZ+i*SEGMENT_LENGTH, s*t, 0, DEADTREE, OAKTREE );
if (seg!=nullptr) circuit.push_back( seg );
if (seg!=nullptr)
{
seg->environment = biome;
circuit.push_back( seg );
}
}
}
void addHill( Length l, HillSize s, HillType t )
void addHill( Length l, HillSize s, HillType t, int8_t biome )
{
double lastZ=0;
int16_t lastY=0;
if (circuit.size()!=0)
uint16_t lastIndex = circuit.size();
if (lastIndex!=0)
{
lastY=circuit[circuit.size()-1]->wY;
lastZ=circuit[circuit.size()-1]->wZ;
lastY=circuit[lastIndex-1]->wY;
lastZ=circuit[lastIndex-1]->wZ+SEGMENT_LENGTH;
}
srand( rtc_ticks() );
for( int i=0; i<l; i++)
@ -263,12 +303,16 @@ void addHill( Length l, HillSize s, HillType t )
int deco = rand() % 4;
Segment *seg;
if (deco==0) seg=new Segment( 0, lastY+(i+1)*t*s, lastZ+(i+1)*SEGMENT_LENGTH, 0, -1, -1 );
else if (deco==1) seg=new Segment( 0, lastY+(i+1)*t*s, lastZ+(i+1)*SEGMENT_LENGTH, 0, -1, PALMTREE );
else if (deco==2) seg=new Segment( 0, lastY+(i+1)*t*s, lastZ+(i+1)*SEGMENT_LENGTH, 0, OAKTREE, -1 );
else if (deco==3) seg=new Segment( 0, lastY+(i+1)*t*s, lastZ+(i+1)*SEGMENT_LENGTH, 0, OAKTREE, PALMTREE );
if (deco==0) seg=new Segment( 0, lastY+i*t*s, lastZ+i*SEGMENT_LENGTH, 0, s*t, -1, -1 );
else if (deco==1) seg=new Segment( 0, lastY+i*t*s, lastZ+i*SEGMENT_LENGTH, 0, s*t, -1, PALMTREE );
else if (deco==2) seg=new Segment( 0, lastY+i*t*s, lastZ+i*SEGMENT_LENGTH, 0, s*t, OAKTREE, -1 );
else if (deco==3) seg=new Segment( 0, lastY+i*t*s, lastZ+i*SEGMENT_LENGTH, 0, s*t, OAKTREE, PALMTREE );
if (seg!=nullptr) circuit.push_back( seg );
if (seg!=nullptr)
{
seg->environment = biome;
circuit.push_back( seg );
}
}
}