Browse Source

Code etwas aufgerumt

Funktionierender Framelimiter
seba 13 years ago
parent
commit
2016d1cb50
6 changed files with 60 additions and 6 deletions
  1. 1
    3
      Makefile
  2. 33
    0
      fpsmanager.cpp
  3. 20
    0
      fpsmanager.h
  4. 1
    1
      glmenu/menuitems.cpp
  5. 3
    0
      glmenu/menumenu.cpp
  6. 2
    2
      gltexture.cpp

+ 1
- 3
Makefile View File

@@ -1,6 +1,6 @@
1 1
 CC = g++
2 2
 AR = ar
3
-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
3
+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
4 4
 OBJOPT = -Wall -c `sdl-config --cflags`
5 5
 SUBDIRS = glgui glmenu
6 6
 SUBDIROBJECTS = glgui/*.o glmenu/*.o
@@ -8,8 +8,6 @@ VERSION = 0.0.1
8 8
 LIBNAME = libsegl
9 9
 
10 10
 seglar: $(OBJECTS) subdirs
11
-	@echo OBJOPT $(OBJOPT)
12
-	@echo CC $(CC)
13 11
 	rm -f $(LIBNAME).a
14 12
 	$(AR) rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS)
15 13
 # 	ranlib $(LIBNAME).a

+ 33
- 0
fpsmanager.cpp View File

@@ -0,0 +1,33 @@
1
+#include "fpsmanager.h"
2
+
3
+FPSManager::FPSManager(int _fps) {
4
+	setFPS(_fps);
5
+	frames = 0;
6
+	framerate = 0;
7
+	lastticks = SDL_GetTicks();
8
+}
9
+
10
+void FPSManager::setFPS(int _fps) {
11
+	if(_fps<1 || _fps > 500)
12
+		return; 
13
+	tickrate = 1000.0f/(float)_fps;
14
+}
15
+
16
+void FPSManager::delay() {
17
+	frames++;
18
+	
19
+	Uint32 now    = SDL_GetTicks();
20
+	Uint32 target = lastticks + (Uint32)(tickrate * (float)frames);
21
+	
22
+	if(now <= target) {
23
+		SDL_Delay(target-now);
24
+	} else {
25
+		framerate = frames/((now-lastticks)/1000.0f);
26
+		frames = 0;
27
+		lastticks = SDL_GetTicks();
28
+	}
29
+}
30
+
31
+float FPSManager::getFPS() {
32
+	return framerate;
33
+}

+ 20
- 0
fpsmanager.h View File

@@ -0,0 +1,20 @@
1
+#ifndef __FPSMANAGER_H
2
+#define __FPSMANAGER_H
3
+
4
+#include <SDL.h>
5
+
6
+class FPSManager {
7
+	private:
8
+		Uint32 lastticks;
9
+		int frames;
10
+		float tickrate;
11
+		float framerate;
12
+	public:
13
+		FPSManager(int _fps);
14
+		
15
+		void setFPS(int _fps);
16
+		void delay();
17
+		float getFPS();
18
+};
19
+
20
+#endif

+ 1
- 1
glmenu/menuitems.cpp View File

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

+ 3
- 0
glmenu/menumenu.cpp View File

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

+ 2
- 2
gltexture.cpp View File

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

Loading…
Cancel
Save