305 lines
7.6 KiB
C++
305 lines
7.6 KiB
C++
#include <gint/display.h>
|
|
#include <gint/drivers/r61524.h>
|
|
|
|
#include <gint/keyboard.h>
|
|
#include <gint/gint.h>
|
|
#include <gint/defs/types.h>
|
|
#include <fxlibc/printf.h>
|
|
|
|
#include <libprof.h>
|
|
#include <gint/usb.h>
|
|
#include <gint/usb-ff-bulk.h>
|
|
|
|
#include <math.h>
|
|
#include <vector>
|
|
#include <array>
|
|
|
|
|
|
#include "include/camera.h"
|
|
#include "include/segment.h"
|
|
#include "parameters.h"
|
|
#include "include/circuit.h"
|
|
#include "include/drawstuff.h"
|
|
|
|
|
|
|
|
extern bopti_image_t car1, car2, car3, car4, car5, car6, car7, car8;
|
|
extern bopti_image_t tree1, tree2, tree3;
|
|
extern bopti_image_t player;
|
|
|
|
|
|
std::vector<Segment*> circuit;
|
|
int MAX_SEGMENT=0;
|
|
camera *cam;
|
|
|
|
|
|
|
|
bool stop = false;
|
|
bool record = false;
|
|
bool screenshot = false;
|
|
bool ShowDebug1 = false;
|
|
bool ShowDebug2 = false;
|
|
|
|
uint16_t currentcurve=0;
|
|
uint8_t shiftcolor=0;
|
|
|
|
float speed = 0;
|
|
float maxspeedforward = 8;
|
|
float maxspeedbackward = 4;
|
|
int direction = 1;
|
|
bool speedcontrol = false;
|
|
|
|
|
|
static void get_inputs( float dt )
|
|
{
|
|
key_event_t ev;
|
|
while((ev = pollevent()).type != KEYEV_NONE)
|
|
{
|
|
|
|
}
|
|
speedcontrol = false;
|
|
|
|
if(keydown(KEY_LEFT)) cam->decX(25.0);
|
|
if(keydown(KEY_RIGHT)) cam->incX(25.0);
|
|
|
|
if(keydown(KEY_SHIFT))
|
|
{
|
|
if (direction==-1 && speed > 0)
|
|
{
|
|
direction = -1;
|
|
speed -= 0.5;
|
|
if (speed<0) speed=0;
|
|
cam->decZ(speed*dt);
|
|
}
|
|
else
|
|
{
|
|
direction = 1;
|
|
speed+=0.05;
|
|
if (speed>maxspeedforward) speed=maxspeedforward;
|
|
cam->incZ(speed*dt);
|
|
}
|
|
|
|
speedcontrol = true;
|
|
}
|
|
if(keydown(KEY_ALPHA))
|
|
{
|
|
if (direction==1 && speed > 0)
|
|
{
|
|
direction = 1;
|
|
speed -= 0.5;
|
|
if (speed<0) speed=0;
|
|
cam->incZ(speed*dt);
|
|
}
|
|
else
|
|
{
|
|
direction = -1;
|
|
speed+=0.025;
|
|
if (speed>maxspeedbackward) speed=maxspeedbackward;
|
|
cam->decZ(speed*dt);
|
|
}
|
|
|
|
speedcontrol = true;
|
|
}
|
|
|
|
//if(keydown(KEY_7)) cam->incY(10.0);
|
|
//if(keydown(KEY_1)) cam->decY(10.0);
|
|
//if(keydown(KEY_MENU)) gint_osmenu();
|
|
|
|
if(keydown(KEY_EXIT)) stop = true;
|
|
|
|
if(keydown(KEY_F1))
|
|
{
|
|
ShowDebug1 = !ShowDebug1;
|
|
ShowDebug2 = false;
|
|
}
|
|
if(keydown(KEY_F2))
|
|
{
|
|
ShowDebug2 = !ShowDebug2;
|
|
ShowDebug1 = false;
|
|
}
|
|
|
|
if(keydown(KEY_F6)) record = !record;
|
|
if(keydown(KEY_F4)) screenshot = true;
|
|
|
|
if (speedcontrol==false)
|
|
{
|
|
speed-=0.3;
|
|
if (speed<0) speed=0;
|
|
|
|
if (direction==1)
|
|
cam->incZ(speed*dt);
|
|
else
|
|
cam->decZ(speed*dt);
|
|
}
|
|
}
|
|
|
|
|
|
int main(void)
|
|
{
|
|
__printf_enable_fp();
|
|
__printf_enable_fixed();
|
|
|
|
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
|
|
usb_open(interfaces, GINT_CALL_NULL);
|
|
|
|
prof_t perf_create, perf_project, perf_render;
|
|
uint32_t 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( );
|
|
|
|
//--------------
|
|
|
|
perf_create = prof_make();
|
|
prof_enter(perf_create);
|
|
|
|
createCircuit();
|
|
prepareDecoration();
|
|
|
|
prof_leave(perf_create);
|
|
time_create = prof_time(perf_create);
|
|
|
|
//--------------
|
|
MAX_SEGMENT = circuit.size();
|
|
|
|
int indexstart = 0;
|
|
int indexend = 0;
|
|
|
|
uint32_t maxDistance = (MAX_SEGMENT-nbInterestingSegments-5)*SEGMENT_LENGTH;
|
|
|
|
uint32_t dt=0;
|
|
uint16_t l=0;
|
|
|
|
while (!stop)
|
|
{
|
|
get_inputs( dt );
|
|
dt = ((float) (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;
|
|
|
|
// there is an offset equals to 400 on z position
|
|
// this is to compute the first index of segment to be projected to screen
|
|
|
|
if (indexstart<0) indexstart=0;
|
|
if (indexstart>MAX_SEGMENT-nbInterestingSegments-1-2) indexstart=MAX_SEGMENT-nbInterestingSegments-1-2;
|
|
|
|
|
|
//--------------
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
prof_leave(perf_project);
|
|
time_project = prof_time(perf_project);
|
|
|
|
//--------------
|
|
|
|
perf_render = prof_make();
|
|
prof_enter(perf_render);
|
|
|
|
drawSky( );
|
|
|
|
cam->cY = fix( 300 ) + interpolatePositionY(fround(cam->cZ));
|
|
|
|
for( int k=indexend-1; k>=indexstart; k--)
|
|
{
|
|
currentcurve = circuit[k]->CumulatedCurve;
|
|
drawCircuitSegment( k );
|
|
drawDecoration( k );
|
|
}
|
|
|
|
|
|
|
|
if (ShowDebug1)
|
|
{
|
|
Segment* currentSeg = circuit[indexstart];
|
|
|
|
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 );
|
|
|
|
dprint( 1, 55, C_WHITE, "It=%d", l);
|
|
dprint( 1, 69, C_GREEN, "St=%d ", indexstart );
|
|
dprint( 1, 83, C_GREEN, "En=%d", indexend );
|
|
dprint( 1, 97, C_RED, "Sz= %d", circuit.size() );
|
|
|
|
dprint( 100, 55, C_WHITE, "SzSgmt=%d bytes", sizeof(Segment) );
|
|
dprint( 100, 69, C_WHITE, ">XYZc=(%d,%d,%.0lf,%d)", circuit[indexstart]->wX, circuit[indexstart]->wY, circuit[indexstart]->wZ, circuit[indexstart]->Curve );
|
|
dprint( 100, 83, C_WHITE, ">XYZc=(%d,%d,%.0lf,%d)", circuit[indexend]->wX, circuit[indexend]->wY, circuit[indexend]->wZ, circuit[indexstart]->Curve );
|
|
dprint( 100, 97, C_WHITE, "C[i]Adr= %p", ¤tSeg),
|
|
|
|
dprint( 320, 1, C_WHITE, "CamX=%d", fround( cam->cX ) );
|
|
dprint( 320, 15, C_WHITE, "CamY=%d", fround( cam->cY ) );
|
|
dprint( 320, 29, C_WHITE, "CamZ=%d", fround( cam->cZ ) );
|
|
|
|
dprint( 320, 55, C_WHITE, "Dir=%d", direction );
|
|
dprint( 320, 69, C_WHITE, "Spd=%.1f", speed );
|
|
dprint( 320, 83, C_WHITE, "Dz =%.1f", speed*dt );
|
|
dprint( 320, 97, C_WHITE, "dt =%.3D ms", dt );
|
|
}
|
|
if (ShowDebug2)
|
|
{
|
|
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);
|
|
|
|
//dupdate();
|
|
r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT);
|
|
|
|
|
|
prof_leave(perf_render);
|
|
time_render = prof_time(perf_render);
|
|
|
|
if (screenshot && usb_is_open())
|
|
{
|
|
usb_fxlink_screenshot(true);
|
|
screenshot = false;
|
|
}
|
|
|
|
if(record && usb_is_open())
|
|
{
|
|
usb_fxlink_videocapture(false);
|
|
}
|
|
|
|
l++;
|
|
}
|
|
|
|
prof_quit();
|
|
usb_close();
|
|
|
|
|
|
circuit.clear();
|
|
delete cam;
|
|
|
|
freeDecoration();
|
|
|
|
return 1;
|
|
}
|