Code etwas aufgerumt

Funktionierender Framelimiter
This commit is contained in:
seba 2008-04-05 01:27:46 +02:00
parent f6881092c8
commit 2016d1cb50
6 changed files with 60 additions and 6 deletions

View File

@ -1,6 +1,6 @@
CC = g++
AR = ar
OBJECTS = punkt3d.o punkt2d.o emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o
OBJECTS = punkt3d.o punkt2d.o emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o fpsmanager.o
OBJOPT = -Wall -c `sdl-config --cflags`
SUBDIRS = glgui glmenu
SUBDIROBJECTS = glgui/*.o glmenu/*.o
@ -8,8 +8,6 @@ VERSION = 0.0.1
LIBNAME = libsegl
seglar: $(OBJECTS) subdirs
@echo OBJOPT $(OBJOPT)
@echo CC $(CC)
rm -f $(LIBNAME).a
$(AR) rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS)
# ranlib $(LIBNAME).a

33
fpsmanager.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "fpsmanager.h"
FPSManager::FPSManager(int _fps) {
setFPS(_fps);
frames = 0;
framerate = 0;
lastticks = SDL_GetTicks();
}
void FPSManager::setFPS(int _fps) {
if(_fps<1 || _fps > 500)
return;
tickrate = 1000.0f/(float)_fps;
}
void FPSManager::delay() {
frames++;
Uint32 now = SDL_GetTicks();
Uint32 target = lastticks + (Uint32)(tickrate * (float)frames);
if(now <= target) {
SDL_Delay(target-now);
} else {
framerate = frames/((now-lastticks)/1000.0f);
frames = 0;
lastticks = SDL_GetTicks();
}
}
float FPSManager::getFPS() {
return framerate;
}

20
fpsmanager.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef __FPSMANAGER_H
#define __FPSMANAGER_H
#include <SDL.h>
class FPSManager {
private:
Uint32 lastticks;
int frames;
float tickrate;
float framerate;
public:
FPSManager(int _fps);
void setFPS(int _fps);
void delay();
float getFPS();
};
#endif

View File

@ -85,7 +85,7 @@ void MIToggle::setValueInt(int val) {
void MIToggle::setValueString(std::string str) {
for(unsigned int t=0; t<toggles.size(); t++) {
std::cout << str << " == " << toggles[t] << std::endl;
// std::cout << str << " == " << toggles[t] << std::endl;
if(str==toggles[t]) {
togglepos = t;
value = getValueString();

View File

@ -113,6 +113,7 @@ void MenuMenu::render() {
// fullvalwidth = clen + vlen + valuewidth;
maxlen = std::max(clen, cvlen+extravalwidth+(cvlen>0?valuewidth:0));
glDisable(GL_DEPTH_TEST);
if(paintbackground&&true) {
// geht noch nicht ganz
glDisable(GL_TEXTURE_2D);
@ -154,10 +155,12 @@ void MenuMenu::render() {
glColor4f(0.2f, 0.2f, 0.2f, 0.3f);
GLFontEngine::paintSDLRect(bgarea);
glDisable(GL_BLEND);
}
for(unsigned int i=0; i<menuitems.size(); i++) {
menuitems[i]->render(pos, centermenu, basefontsize, maxwidth, valuewidth, ((unsigned int)itempos==i)&&dohighlight, clen, cvlen, cvlen+extravalwidth+valuewidth);
pos.y += basefontsize + menuitems[i]->getFontSizeAdd() + offset;
}
glEnable(GL_DEPTH_TEST);
}

View File

@ -136,7 +136,7 @@ bool GLTexture::setParameter(GLint _minfilter, GLint _magfilter, GLint _wraps, G
unloadTexture();
return loadLocalSurface();
} else if(filename!="") {
std::cout << "Filename: " << filename << std::endl;
//std::cout << "Filename: " << filename << std::endl;
return loadImage(filename);
} else {
// keine datei, kein surface
@ -144,7 +144,7 @@ bool GLTexture::setParameter(GLint _minfilter, GLint _magfilter, GLint _wraps, G
std::cerr << "Couldn't reload GLTexture " << this << "- No surface, no file!" << std::endl;
return false;
}
std::cout << "Texture reloaded" << std::endl;
//std::cout << "Texture reloaded" << std::endl;
}
int GLTexture::getW() {