I created a little menu for games 'nd music and such… It’s far from finished but here is a demo:
https://mega.co.nz/#!mp9lCJKC!Vbw-H7RzhbFX9roInJ_Qo_Yt3uUPuaZB2WB9Z9vP1ds
The controls are the left and right buttons on your keyboards.
Now, here’s problem 1: when launching the program there are 5 menu’s you can scroll to. The first time you scroll to a new menu, it tends to stutter.
After you’ve seen the menu 1 time, it doesn’t stutter anymore.
Problem 2: the program is taking up 300mb of RAM while I’m not loading anything into ram at all except for some surfaces that are converted into textures but cleared when done.
However, it doesn’t really go past the ~300mb over time so I don’t think it’s a memory leak.
I can’t detect any form of memory leak in my code either, so I’ll just ask whether other people suffer from this too.
Here’s the rendering code:
Code:
int gfxdraw()
{
//Main loop flag
bool quit = false;
//Event handler
SDL_Event e;
SDL_Rect test;
int timer1 = 0;
int timer2 = 0;
int busy = 0;
int x = 0;
int lasttime = 0;
float movemenu = 0;
while( !quit )
{
//While application is running
//Handle events on queue
while( SDL_PollEvent( &e ) != 0)
{
//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}
handleEvent( e );
}
SDL_RenderClear( gRenderer );
//menucontrol
if(menuvalue != oldmenuvalue)
{
if(busy == 1)
{
if(menuvalue < oldmenuvalue)
{
timer2 = SDL_GetTicks();
x += timer2 - timer1;
movemenu = SCREEN_WIDTH * oldmenuvalue + 100.f * oldmenuvalue - (SCREEN_WIDTH + 100.f) / 400.f * x;
test.h = texh[0];
test.w = texw[0];
test.x = texx[0] - oldmenuvalue * ((texw[0] - SCREEN_WIDTH) / 4.f) + (texw[0] - SCREEN_WIDTH) / 4.f / 400.f * x;
test.y = texy[0];
SDL_RenderCopy( gRenderer, gTexture[0], NULL, &test );
for(int i = 1; i < 45; i++)
{
test.h = texh[i];
test.w = texw[i];
test.x = texx[i] - movemenu;
test.y = texy[i];
SDL_RenderCopy( gRenderer, gTexture[i], NULL, &test );
}
timer1 = timer2;
if(x >= 400)
{
oldmenuvalue = menuvalue;
busy = 0;
x = 0;
}
}
if(menuvalue > oldmenuvalue)
{
timer2 = SDL_GetTicks();
x += timer2 - timer1;
movemenu = SCREEN_WIDTH * oldmenuvalue + 100.f * oldmenuvalue + (SCREEN_WIDTH + 100.f) / 400.f * x;
test.h = texh[0];
test.w = texw[0];
test.x = texx[0] - oldmenuvalue * ((texw[0] - SCREEN_WIDTH) / 4.f) - (texw[0] - SCREEN_WIDTH) / 4.f / 400.f * x;
test.y = texy[0];
SDL_RenderCopy( gRenderer, gTexture[0], NULL, &test );
for(int i = 1; i < 45; i++)
{
test.h = texh[i];
test.w = texw[i];
test.x = texx[i] - movemenu;
test.y = texy[i];
SDL_RenderCopy( gRenderer, gTexture[i], NULL, &test );
}
timer1 = timer2;
if(x >= 400)
{
oldmenuvalue = menuvalue;
busy = 0;
x = 0;
}
}
}
else
{
timer1 = SDL_GetTicks();
busy = 1;
lasttime = 1;
}
}
if(oldmenuvalue == menuvalue || lasttime == 1)
{
test.h = texh[0];
test.w = texw[0];
test.x = texx[0] - ((2560.f / 1920.f * SCREEN_WIDTH - SCREEN_WIDTH) / 4.f * oldmenuvalue);
test.y = texy[0];
SDL_RenderCopy( gRenderer, gTexture[0], NULL, &test );
for(int i = 1; i < 45; i++)
{
test.h = texh[i];
test.w = texw[i];
test.x = texx[i] - SCREEN_WIDTH * oldmenuvalue - 100.f * oldmenuvalue;
test.y = texy[i];
SDL_RenderCopy( gRenderer, gTexture[i], NULL, &test );
}
if(lasttime == 1) lasttime = 0;
}
SDL_RenderPresent( gRenderer );
}
return 0;
}
Thanks in advance,
Luca