corrected a stupid bug in deallocation of std::vector

master
Sylvain PILLOT 7 months ago
parent 271b95880e
commit 50fdc17071
  1. 133
      src/main.cc
  2. 2
      src/parameters.h

@ -25,6 +25,8 @@
#include "include/cars.h"
#include "include/menus.h"
#include <gint/kmalloc.h>
#include <stdio.h>
extern bopti_image_t player;
extern font_t speedfont;
@ -86,6 +88,78 @@ int lastindex=0;
int CC=0; // current curve
int CS=0;
void initEverything( void )
{
CurrentCircuitBiome = PLAINS;
circuit.clear();
nuages.clear();
traffic.clear();
MAX_SEGMENT=0;
DataIndex=0;
stop = false;
record = false;
screenshot = false;
ShowDebug1 = false;
ShowDebug2 = false;
ShowDebug3 = false;
BDrawDeco = true;
BDrawClds = true;
BDrawCars = true;
BDrawFPS = false;
currentcurve=0;
shiftcolor=0;
speed = 0.0;
maxspeedforward = 5.0;
maxspeedbackward = 2.0;
direction = 1;
speedcontrol = false;
minYRoad = 224; // We will track the upper Y (in fact the minimum Y during the RoadDrawing to optimize the rendering of the Sky
viewside = 0;
deltaFarbackground = 0;
deltaNearbackground = 0;
lastindex=0;
CC=0; // current curve
CS=0;
}
int my_profile(int key, int duration, int count)
{
// key: Key being repeated
// duration: How long that key has been pressed
// count: How many times it's been repeated already
// Return value: how long to wait before next repeat (\B5s)
// Only allow KEY_LEFT and KEY_RIGHT
if(key!=KEY_LEFT && key!=KEY_RIGHT && key!=KEY_DOWN && key!=KEY_UP && key!=KEY_ALPHA && key!=KEY_SHIFT)
return -1;
// 500 ms for first repeat, 50 ms after that; stop after 10 repeats
if(count == 0)
return 500*1000;
else
return -1;
}
static void get_inputs( float dt, int index )
{
CC = circuit[index]->Curve;
@ -231,7 +305,7 @@ static void get_inputs( float dt, int index )
}
/* Adjust position of the background */
// Adjust position of the background
if (lastindex!=index)
{
deltaFarbackground -= CC*speed*dt/250;
@ -239,7 +313,7 @@ static void get_inputs( float dt, int index )
}
lastindex = index;
/* adjust speed if we drive on the side of the road */
// 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;
@ -256,6 +330,8 @@ static void get_inputs( float dt, int index )
}
int main(void)
{
__printf_enable_fp();
@ -267,6 +343,9 @@ int main(void)
#endif
kmalloc_arena_t *_uram = kmalloc_get_arena("_uram");
kmalloc_gint_stats_t *_uram_stats;
srand( rtc_ticks() );
prof_init();
@ -274,11 +353,21 @@ int main(void)
drawStartTitle();
char texttosend[1024];
bool exitToOS = false;
do
{
/*
_uram_stats = kmalloc_get_gint_stats(_uram);
sprintf( texttosend, "[Begining of loop] Memory Status - Used: %d - Free: %d - Peak Used: %d", _uram_stats->used_memory, _uram_stats->free_memory, _uram_stats->peak_used_memory);
usb_fxlink_text(texttosend, 0);
*/
// Try to restart from very begining
initEverything();
prof_t perf_update, perf_create, perf_project, perf_render;
int32_t start_time = 99000000;
uint32_t score=99999;
@ -343,19 +432,24 @@ int main(void)
perf_create = prof_make();
prof_enter(perf_create);
initData( ); // Positioning of the Camera
createCircuit( selectedCircuit ); // Creates the circuit
initData( ); // Positioning of the Camera
createCircuit( selectedCircuit ); // Creates the circuit
MAX_SEGMENT = circuit.size();
uint32_t maxDistance = (MAX_SEGMENT-nbInterestingSegments-5)*SEGMENT_LENGTH;
putBillBoards();
createClouds(); // Creates the Sky and Clouds
MAX_SEGMENT = circuit.size();
uint32_t maxDistance = (MAX_SEGMENT-nbInterestingSegments-5)*SEGMENT_LENGTH;
createTraffic( MAX_SEGMENT ); // Creates the cars
putBillBoards();
prepareDecoration( CurrentCircuitBiome ); // Prepares the multiple variations of Decoration (image scaling)
prepareTraffic(); // Prepares the multiple variations of Cars (image scaling)
createClouds(); // Creates the Sky and Clouds
createTraffic( MAX_SEGMENT ); // Creates the cars
prepareDecoration( CurrentCircuitBiome ); // 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);
@ -562,8 +656,6 @@ int main(void)
dsubimage( 245, 5, &speedhud, 37, 117, 38, 13, DIMAGE_NONE); // speed logo
dsubimage( 245, 25, &speedhud, 37, 130, 38, 13, DIMAGE_NONE); // timer logo
dsubimage( 5, 205, &speedhud, 0, 143, 27, 13, DIMAGE_NONE); // fps logo
dfont(&speedfont);
if (drawspeed==0.0)
{
@ -604,6 +696,7 @@ int main(void)
if (BDrawFPS)
{
dsubimage( 5, 205, &speedhud, 0, 143, 27, 13, DIMAGE_NONE); // fps logo
dprint_opt(42,202, C_RGB(0,0,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "%.0f <", (float) (1000.0f/dt) ); // the '>' symbol corresponds to "fps"
dprint_opt(40,200, C_RGB(255,255,0), C_NONE, DTEXT_LEFT, DTEXT_TOP, "%.0f <", (float) (1000.0f/dt) );
@ -661,11 +754,21 @@ int main(void)
l++;
}
// Free all memory
freeTraffic();
freeDecoration();
for(int i=0; i<circuit.size(); i++ ) delete circuit[i]; // Not to forget to delete each elements
circuit.clear();
for(int i=0; i<nuages.size(); i++ ) delete nuages[i]; // Not to forget to delete each elements
nuages.clear();
for(int i=0; i<traffic.size(); i++ ) delete traffic[i]; // Not to forget to delete each elements
traffic.clear();
freeDecoration();
freeTraffic();
}
}
while (exitToOS==false);

@ -15,7 +15,7 @@
#define DISTANCE_SCREEN 0.83444
#define MAX_RENDER_DISTANCE 3600 // 3000 BEFORE
#define MAX_RENDER_DISTANCE 4500 // 3000 BEFORE
#define NB_CLOUDS_SKY 10

Loading…
Cancel
Save