added trees/sideroad decorations

dev V0.15
Sylvain PILLOT 7 months ago
parent ddc326403f
commit 97933c64c0
  1. 10
      src/include/circuit.h
  2. 1
      src/include/drawstuff.h
  3. 5
      src/include/segment.h
  4. 18
      src/main.cc
  5. 6
      src/parameters.h
  6. 189
      src/src/circuit.cc
  7. 6
      src/src/segment.cc

@ -36,6 +36,12 @@ enum CurveType
RIGHT_CURVE = +1
};
enum Decoration
{
PALMTREE = 0,
DEADTREE = 1,
OAKTREE = 2
};
void initData( void );
void createCircuit( void );
@ -47,6 +53,10 @@ void printCircuit( void );
void printCircuit( int i );
void drawCircuitSegment( uint16_t index );
void drawDecoration( uint16_t index );
void freeDecoration( void );
void prepareDecoration( void );
void addStraightLine( Length l );
void addCurve( Length l, CurveStrength s, CurveType t );

@ -7,3 +7,4 @@ void drawGrass( int y1, int y2, uint8_t R, uint8_t G, uint8_t B );
void drawSky( void );
void drawSky( int ymin, int ymax );

@ -31,8 +31,9 @@ class Segment
int16_t W=0;
// Decorations on the Road (Left and Right)
int8_t Ldeco=0;
int8_t RDeco=0;
int8_t LDeco=-1;
int8_t RDeco=-1;
int8_t DScale=0;
};
#endif // SEGMENT_H

@ -158,6 +158,7 @@ int main(void)
prof_enter(perf_create);
createCircuit();
prepareDecoration();
prof_leave(perf_create);
time_create = prof_time(perf_create);
@ -217,20 +218,17 @@ int main(void)
drawSky( );
//cam->cX = interpolatePositionX(fround(cam->cZ));
cam->cY = fix( 300 ) + interpolatePositionY(fround(cam->cZ));
//currentcurve = 0;
//for (int k=indexstart; k<indexend-1; k++)
for( int k=indexend-1; k>=indexstart; k--)
{
currentcurve = circuit[k]->CumulatedCurve;
drawCircuitSegment( k );
//currentcurve += circuit[k]->Curve;
drawDecoration( k );
}
//r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT);
if (ShowDebug1)
{
Segment* currentSeg = circuit[indexstart];
@ -263,6 +261,11 @@ int main(void)
dprint( 1, 1, C_RED, "Cra=%.3D ms", time_create );
dprint( 1, 15, C_RED, "Prj=%.3D ms", time_project );
dprint( 1, 29, C_RED, "Rdr=%.3D ms", time_render );
for( int k=indexend-1; k>=indexstart; k--)
{
dprint( 100, 1+10*k-indexstart, C_WHITE, "S[%d]=%d", k, circuit[k]->DScale );
}
}
dsubimage( SCREEN_CX-36, SCREEN_HEIGHT-48, &player, 257,1,72,46, DIMAGE_NONE);
@ -291,8 +294,11 @@ int main(void)
prof_quit();
usb_close();
circuit.clear();
delete cam;
freeDecoration();
return 1;
}

@ -8,13 +8,13 @@
#define SCREEN_CX 198
#define SCREEN_CY 112
#define SEGMENT_LENGTH 200
#define ROAD_WIDTH 600
#define SEGMENT_LENGTH 250
#define ROAD_WIDTH 700
#define ASPECT_RATIO 1.767
#define DISTANCE_SCREEN 0.83444
#define MAX_RENDER_DISTANCE 2500
#define MAX_RENDER_DISTANCE 3000
#define std ustl

@ -14,6 +14,110 @@ extern uint8_t shiftcolor;
extern int MAX_SEGMENT;
extern bool ShowDebug1;
extern bopti_image_t car1, car2, car3, car4, car5, car6, car7, car8;
extern bopti_image_t tree1, tree2, tree3;
bopti_image_t *scaledTrees[3][25] = { 0 };
size_t image_size_profile(int profile, int width, int height)
{
size_t size = sizeof(bopti_image_t);
if(profile == 0 || profile == 1) // PX_RGB565, PX_RGB565A
size += width * height * 2;
else if(profile == 2) // PX_P8
size += 512 + width * height;
else if(profile == 3) // PX_P4
size += 32 + ((width + 1) / 2) * height;
return size;
}
size_t image_size(bopti_image_t const *img)
{
return image_size_profile(img->profile, img->width, img->height);
}
int get_pixel(bopti_image_t const *img, int x, int y)
{
if((unsigned)x >= img->width || (unsigned)y >= img->height)
return 0;
uint8_t *bytes = (void *)img->data;
if(img->profile <= 1)
return img->data[y * img->width + x];
if(img->profile == 2)
return bytes[y * img->width + x + 512];
if(img->profile == 3)
{
int s = (img->width + 1) >> 1;
int i = y * s + (x >> 1) + 32;
if(x & 1)
return bytes[i] & 0x0f;
else
return bytes[i] >> 4;
}
return 0;
}
void set_pixel(bopti_image_t *img, int x, int y, int color)
{
if((unsigned)x >= img->width || (unsigned)y >= img->height)
return;
uint8_t *bytes = (void *)img->data;
if(img->profile <= 1)
img->data[y * img->width + x] = color;
else if(img->profile == 2)
bytes[y * img->width + x + 512] = color;
else if(img->profile == 3)
{
int s = (img->width + 1) >> 1;
int i = y * s + (x >> 1) + 32;
if(x & 1)
bytes[i] = (bytes[i] & 0xf0) | (color & 0x0f);
else
bytes[i] = (bytes[i] & 0x0f) | ((color & 0x0f) << 4);
}
}
bopti_image_t *resize(bopti_image_t const *src, int w, int h)
{
size_t size = image_size_profile(src->profile, w, h);
bopti_image_t *img = malloc(size);
if(!img) return NULL;
size_t palette_size = 0;
if(src->profile == 2) // PX_P8
palette_size = 512;
else if(src->profile == 3) // PX_P4
palette_size = 32;
img->profile = src->profile;
img->alpha = src->alpha;
img->width = w;
img->height = h;
memcpy(img->data, src->data, palette_size);
for(int y = 0; y < h; y++)
for(int x = 0; x < w; x++)
{
int color = get_pixel(src, x * src->width / w, y * src->height / h);
set_pixel(img, x, y, color);
}
return img;
}
void initData( void )
{
cam = new camera();
@ -25,12 +129,12 @@ void initData( void )
void createCircuit( void )
{
/* for( int i=0; i<MAX_SEGMENT; i++)
{
Segment *seg=new Segment( i );
if (seg!=nullptr) circuit.push_back( seg );
}
*/
/* for( int i=0; i<MAX_SEGMENT; i++)
{
Segment *seg=new Segment( i );
if (seg!=nullptr) circuit.push_back( seg );
}
*/
addStraightLine( L_VERYSHORT );
addStraightLine( L_VERYSHORT );
@ -55,7 +159,7 @@ void addStraightLine( Length l )
for( int i=0; i<l; i++)
{
//Segment *s=new Segment( i );
Segment *seg=new Segment( 0, lastY, lastZ + (i+1)*SEGMENT_LENGTH, 0 );
Segment *seg=new Segment( 0, lastY, lastZ + (i+1)*SEGMENT_LENGTH, 0, PALMTREE, DEADTREE );
if (seg!=nullptr) circuit.push_back( seg );
}
}
@ -74,7 +178,7 @@ void addCurve( Length l, CurveStrength s, CurveType t )
for( int i=0; i<l; i++)
{
//Segment *s=new Segment( i );
Segment *seg=new Segment( 0, lastY, lastZ+(i+1)*SEGMENT_LENGTH, s*t );
Segment *seg=new Segment( 0, lastY, lastZ+(i+1)*SEGMENT_LENGTH, s*t, DEADTREE, OAKTREE );
if (seg!=nullptr) circuit.push_back( seg );
}
}
@ -94,7 +198,7 @@ void addHill( Length l, HillSize s, HillType t )
for( int i=0; i<l; i++)
{
//Segment *s=new Segment( i );
Segment *seg=new Segment( 0, lastY+(i+1)*t*s, lastZ+(i+1)*SEGMENT_LENGTH, 0 );
Segment *seg=new Segment( 0, lastY+(i+1)*t*s, lastZ+(i+1)*SEGMENT_LENGTH, 0, OAKTREE, PALMTREE );
if (seg!=nullptr) circuit.push_back( seg );
}
}
@ -228,3 +332,70 @@ fixed_t interpolatePositionY( double currentZ )
return result;
}
void prepareDecoration( void )
{
bopti_image_t const *src;
for( int k=0; k<3; k++)
{
float scale=1.0f;
for( int i=0; i<25; i++)
{
if(k==0) src = &tree1;
else if(k==1) src = &tree2;
else if(k==2) src = &tree3;
int width = (int) ((float) src->width * scale);
int height = (int) ((float) src->height * scale);
scaledTrees[k][i] = resize(src, width, height);
scale*=0.85f;
}
}
}
void freeDecoration( void )
{
for( int k=0; k<3; k++)
for( int i=0; i<25; i++)
free(scaledTrees[k][i]);
}
void drawDecoration( uint16_t index )
{
bopti_image_t *image;
int distance = fround(fdiv( (fixdouble(circuit[index]->wZ) - cam->cZ), fix(SEGMENT_LENGTH) )) - 1;
if (distance<0) distance = 0;
else if (distance>24) distance = 24;
circuit[index]->DScale = distance;
int deco = circuit[index]->LDeco;
if (deco!=-1)
{
image = scaledTrees[deco][distance];
int X = circuit[index]->X + circuit[index]->CumulatedCurve - 1.5*circuit[index]->W - image->width/2;
int Y = circuit[index]->Y - image->height;
dimage( X, Y, image );
}
deco = circuit[index]->RDeco;
if (deco!=-1)
{
image = scaledTrees[deco][distance];
int X = circuit[index]->X + circuit[index]->CumulatedCurve + 1.5*circuit[index]->W - image->width/2;
int Y = circuit[index]->Y - image->height;
dimage( X, Y, image );
}
}

@ -21,8 +21,8 @@ Segment::Segment( int16_t x, int16_t y, double z, int8_t c )
wY = y;
wZ = z;
Curve = c;
Ldeco = 0;
RDeco = 0;
LDeco = -1;
RDeco = -1;
}
@ -32,7 +32,7 @@ Segment::Segment( int16_t x, int16_t y, double z, int8_t c, int8_t left, int8_t
wY = y;
wZ = z;
Curve = c;
Ldeco = left;
LDeco = left;
RDeco = right;
}

Loading…
Cancel
Save