diff --git a/src/include/circuit.h b/src/include/circuit.h index 7e3938a..4db76b2 100644 --- a/src/include/circuit.h +++ b/src/include/circuit.h @@ -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 ); diff --git a/src/include/drawstuff.h b/src/include/drawstuff.h index fabdac5..dff6916 100644 --- a/src/include/drawstuff.h +++ b/src/include/drawstuff.h @@ -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 ); + diff --git a/src/include/segment.h b/src/include/segment.h index 501445a..c64779a 100644 --- a/src/include/segment.h +++ b/src/include/segment.h @@ -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 diff --git a/src/main.cc b/src/main.cc index 127f6b6..378afdc 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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=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; } diff --git a/src/parameters.h b/src/parameters.h index e4717c1..0722682 100644 --- a/src/parameters.h +++ b/src/parameters.h @@ -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 diff --git a/src/src/circuit.cc b/src/src/circuit.cc index 8849840..8d34929 100644 --- a/src/src/circuit.cc +++ b/src/src/circuit.cc @@ -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; iwidth * 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 ); + } +} diff --git a/src/src/segment.cc b/src/src/segment.cc index f2135d3..43b955c 100644 --- a/src/src/segment.cc +++ b/src/src/segment.cc @@ -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; }