244 lines
5.9 KiB
C++
244 lines
5.9 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;
|
|
|
|
|
|
std::vector<Segment*> circuit;
|
|
camera *cam;
|
|
|
|
|
|
bool stop = false;
|
|
bool record = false;
|
|
bool screenshot = 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_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();
|
|
|
|
prof_leave(perf_create);
|
|
time_create = prof_time(perf_create);
|
|
|
|
//--------------
|
|
|
|
int indexstart = 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) - 400) / SEGMENT_LENGTH;
|
|
// 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-5-1) indexstart=MAX_SEGMENT-nbInterestingSegments-5-1;
|
|
|
|
|
|
//--------------
|
|
|
|
perf_project = prof_make();
|
|
prof_enter(perf_project);
|
|
|
|
for (int k=indexstart; k<indexstart+nbInterestingSegments+1; k++) // Need to project 1 more segment than actual drawing
|
|
projectCircuitFP( k );
|
|
|
|
prof_leave(perf_project);
|
|
time_project = prof_time(perf_project);
|
|
|
|
//--------------
|
|
|
|
perf_render = prof_make();
|
|
prof_enter(perf_render);
|
|
|
|
drawSky( );
|
|
|
|
for (int k=indexstart; k<indexstart+nbInterestingSegments; k++)
|
|
{
|
|
drawCircuitSegment( k );
|
|
}
|
|
|
|
//r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT);
|
|
|
|
dprint( 1, 1, C_RED, "Circuit Creation = %.3D ms", time_create );
|
|
dprint( 1, 15, C_RED, "Segments Projection = %.3D ms", time_project );
|
|
dprint( 1, 29, C_RED, "Rendering = %.3D ms", time_render );
|
|
|
|
dprint( 1, 55, C_WHITE, "Iteration = %d", l);
|
|
dprint( 1, 69, C_GREEN, "Indexstart = %d ", indexstart );
|
|
dprint( 1, 83, C_GREEN, "Indexend = %d", indexstart+nbInterestingSegments+1 );
|
|
dprint( 1, 97, C_RED, "Circuit Size = %d", circuit.size() );
|
|
|
|
dprint( 300, 1, C_WHITE, "CamX= %d", fround( cam->cX ) );
|
|
dprint( 300, 15, C_WHITE, "CamY= %d", fround( cam->cY ) );
|
|
dprint( 300, 29, C_WHITE, "CamZ= %d", fround( cam->cZ ) );
|
|
|
|
dprint( 280, 55, C_WHITE, "Dir = %d", direction );
|
|
dprint( 280, 69, C_WHITE, "Spd = %.1f", speed );
|
|
dprint( 280, 83, C_WHITE, "Dz = %.1f", speed*dt );
|
|
dprint( 280, 97, C_WHITE, "dt = %.3D ms", dt );
|
|
|
|
//r61524_display(gint_vram, 0, DHEIGHT, R61524_DMA_WAIT);
|
|
dupdate();
|
|
|
|
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;
|
|
|
|
return 1;
|
|
}
|