Parcourir la source

Removing some boost and SDL

Panagiotis Christopoulos Charitos il y a 13 ans
Parent
commit
2ab6e11776

+ 7 - 2
include/anki/util/HighRezTimer.h

@@ -1,6 +1,8 @@
 #ifndef ANKI_UTIL_HIGH_REZ_TIMER_H
 #ifndef ANKI_UTIL_HIGH_REZ_TIMER_H
 #define ANKI_UTIL_HIGH_REZ_TIMER_H
 #define ANKI_UTIL_HIGH_REZ_TIMER_H
 
 
+#include "anki/util/StdTypes.h"
+
 namespace anki {
 namespace anki {
 
 
 /// High resolution timer. All time in seconds
 /// High resolution timer. All time in seconds
@@ -8,7 +10,7 @@ class HighRezTimer
 {
 {
 public:
 public:
 	/// The type that the timer manipulates the results
 	/// The type that the timer manipulates the results
-	typedef double Scalar;
+	typedef F64 Scalar;
 
 
 	/// Start the timer
 	/// Start the timer
 	void start();
 	void start();
@@ -23,11 +25,14 @@ public:
 	/// Get the current date's seconds
 	/// Get the current date's seconds
 	static Scalar getCurrentTime();
 	static Scalar getCurrentTime();
 
 
+	/// Micro sleep
+	static void sleep(Scalar seconds);
+
 private:
 private:
 	Scalar startTime = 0.0;
 	Scalar startTime = 0.0;
 	Scalar stopTime = 0.0;
 	Scalar stopTime = 0.0;
 };
 };
 
 
-} // end namespace
+} // end namespace anki
 
 
 #endif
 #endif

+ 1 - 1
src/CMakeLists.txt

@@ -12,7 +12,7 @@ ENDFOREACH()
 
 
 ADD_LIBRARY(anki)
 ADD_LIBRARY(anki)
 
 
-TARGET_LINK_LIBRARIES(anki ${ANKI_LIBS} BulletSoftBody BulletDynamics BulletCollision LinearMath ankiglew ankitinyxml2 ankilua GLU GL jpeg SDL png freetype)
+TARGET_LINK_LIBRARIES(anki ${ANKI_LIBS} BulletSoftBody BulletDynamics BulletCollision LinearMath ankiglew ankitinyxml2 ankilua GLU GL png freetype)
 
 
 SET_TARGET_PROPERTIES(anki PROPERTIES LINKER_LANGUAGE CXX)
 SET_TARGET_PROPERTIES(anki PROPERTIES LINKER_LANGUAGE CXX)
 
 

+ 9 - 4
src/core/App.cpp

@@ -89,6 +89,7 @@ void App::init(int argc, char* argv[])
 //==============================================================================
 //==============================================================================
 void App::initWindow()
 void App::initWindow()
 {
 {
+#if 0
 	ANKI_LOGI("SDL window initializing...");
 	ANKI_LOGI("SDL window initializing...");
 
 
 	if(SDL_Init(SDL_INIT_VIDEO) < 0)
 	if(SDL_Init(SDL_INIT_VIDEO) < 0)
@@ -138,6 +139,7 @@ void App::initWindow()
 	}
 	}
 
 
 	ANKI_LOGI("SDL window initialization ends");
 	ANKI_LOGI("SDL window initialization ends");
+#endif
 }
 }
 
 
 //==============================================================================
 //==============================================================================
@@ -164,26 +166,32 @@ void App::initDirs()
 //==============================================================================
 //==============================================================================
 void App::togleFullScreen()
 void App::togleFullScreen()
 {
 {
+#if 0
 	//SDL_WM_ToggleFullScreen(mainSurf);
 	//SDL_WM_ToggleFullScreen(mainSurf);
 	SDL_SetWindowFullscreen(windowId, fullScreenFlag ? SDL_TRUE : SDL_FALSE);
 	SDL_SetWindowFullscreen(windowId, fullScreenFlag ? SDL_TRUE : SDL_FALSE);
 	fullScreenFlag = !fullScreenFlag;
 	fullScreenFlag = !fullScreenFlag;
+#endif
 }
 }
 
 
 //==============================================================================
 //==============================================================================
 void App::swapBuffers()
 void App::swapBuffers()
 {
 {
+#if 0
 	//SDL_GL_SwapBuffers();
 	//SDL_GL_SwapBuffers();
 	SDL_GL_SwapWindow(windowId);
 	SDL_GL_SwapWindow(windowId);
+#endif
 }
 }
 
 
 //==============================================================================
 //==============================================================================
 void App::quit(int code)
 void App::quit(int code)
 {
 {
+#if 0
 	SDL_FreeSurface(iconImage);
 	SDL_FreeSurface(iconImage);
 	SDL_GL_DeleteContext(glContext);
 	SDL_GL_DeleteContext(glContext);
 	SDL_DestroyWindow(windowId);
 	SDL_DestroyWindow(windowId);
 	SDL_Quit();
 	SDL_Quit();
 	exit(code);
 	exit(code);
+#endif
 }
 }
 
 
 //==============================================================================
 //==============================================================================
@@ -204,10 +212,7 @@ void App::printAppInfo()
 	msg << "platform ID " << ANKI_PLATFORM << ", ";
 	msg << "platform ID " << ANKI_PLATFORM << ", ";
 	msg << "compiler ID " << ANKI_COMPILER << ", ";
 	msg << "compiler ID " << ANKI_COMPILER << ", ";
 	msg << "GLEW " << glewGetString(GLEW_VERSION) << ", ";
 	msg << "GLEW " << glewGetString(GLEW_VERSION) << ", ";
-	const SDL_version* v = SDL_Linked_Version();
-	msg << "SDL " << int(v->major) << '.' << int(v->minor) << '.' 
-		<< int(v->patch) << ", " << "build date " __DATE__ << ", " 
-		<< "rev " << ANKI_REVISION;
+	msg << "build date " __DATE__ ", " << "rev " << ANKI_REVISION;
 
 
 	ANKI_LOGI(msg.str());
 	ANKI_LOGI(msg.str());
 }
 }

+ 2 - 1
src/renderer/MainRenderer.cpp

@@ -5,7 +5,6 @@
 #include "anki/util/Filesystem.h"
 #include "anki/util/Filesystem.h"
 #include <cstdlib>
 #include <cstdlib>
 #include <cstdio>
 #include <cstdio>
-#include <jpeglib.h>
 #include <fstream>
 #include <fstream>
 
 
 #define glewGetContext() (&glContext)
 #define glewGetContext() (&glContext)
@@ -159,6 +158,7 @@ void MainRenderer::takeScreenshotTga(const char* filename)
 //==============================================================================
 //==============================================================================
 void MainRenderer::takeScreenshotJpeg(const char* filename)
 void MainRenderer::takeScreenshotJpeg(const char* filename)
 {
 {
+#if 0
 	// open file
 	// open file
 	FILE* outfile = fopen(filename, "wb");
 	FILE* outfile = fopen(filename, "wb");
 
 
@@ -203,6 +203,7 @@ void MainRenderer::takeScreenshotJpeg(const char* filename)
 	// done
 	// done
 	free(buffer);
 	free(buffer);
 	fclose(outfile);
 	fclose(outfile);
+#endif
 }
 }
 
 
 //==============================================================================
 //==============================================================================

+ 93 - 7
src/util/HighRezTimer.cpp

@@ -1,9 +1,38 @@
 #include "anki/util/HighRezTimer.h"
 #include "anki/util/HighRezTimer.h"
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
-#include <boost/date_time/posix_time/posix_time.hpp>
+
+#include <sys/time.h>
+#include <signal.h>
+#include <unistd.h>
+#include <errno.h>
+#if HAVE_NANOSLEEP || HAVE_CLOCK_GETTIME
+#	include <time.h>
+#endif
 
 
 namespace anki {
 namespace anki {
 
 
+//==============================================================================
+// The first ticks value of the application
+#ifdef HAVE_CLOCK_GETTIME
+static struct timespec gstart;
+#else
+static struct timeval gstart;
+#endif
+
+struct Dummy
+{
+	Dummy()
+	{
+#if HAVE_CLOCK_GETTIME
+		clock_gettime(CLOCK_MONOTONIC, &gstart);
+#else
+		gettimeofday(&gstart, NULL);
+#endif
+	}
+};
+
+static Dummy dummy;
+
 //==============================================================================
 //==============================================================================
 void HighRezTimer::start()
 void HighRezTimer::start()
 {
 {
@@ -37,11 +66,68 @@ HighRezTimer::Scalar HighRezTimer::getElapsedTime() const
 //==============================================================================
 //==============================================================================
 HighRezTimer::Scalar HighRezTimer::getCurrentTime()
 HighRezTimer::Scalar HighRezTimer::getCurrentTime()
 {
 {
-	/// XXX Remove the boost
-	using namespace boost::posix_time;
-	uint64_t ms = ptime(microsec_clock::local_time()).time_of_day().
-		total_milliseconds();
-	return Scalar(ms) / 1000.0;
+	U32 ticks;
+
+#if HAVE_CLOCK_GETTIME
+	struct timespec now;
+	clock_gettime(CLOCK_MONOTONIC, &now);
+	ticks = (now.tv_sec - gstart.tv_sec) * 1000 
+	        + (now.tv_nsec - gstart.tv_nsec) / 1000000;
+#else
+	struct timeval now;
+	gettimeofday(&now, NULL);
+	ticks = (now.tv_sec - gstart.tv_sec) * 1000 
+	        + (now.tv_usec - gstart.tv_usec) / 1000;
+#endif
+
+	return Scalar(ticks) / 1000.0;
+}
+
+//==============================================================================
+void HighRezTimer::sleep(Scalar sec)
+{
+	int was_error;
+	U32 ms = U32(sec * 1000.0);
+
+#if HAVE_NANOSLEEP
+	struct timespec elapsed, tv;
+#else
+	struct timeval tv;
+	U32 then, now, elapsed;
+#endif
+
+	// Set the timeout interval
+#if HAVE_NANOSLEEP
+	elapsed.tv_sec = ms / 1000;
+	elapsed.tv_nsec = (ms % 1000) * 1000000;
+#else
+	then = getCurrentTime() * 1000.0;
+#endif
+
+	do 
+	{
+		errno = 0;
+
+#if HAVE_NANOSLEEP
+		tv.tv_sec = elapsed.tv_sec;
+		tv.tv_nsec = elapsed.tv_nsec;
+		was_error = nanosleep(&tv, &elapsed);
+#else
+		// Calculate the time interval left (in case of interrupt)
+		now = getCurrentTime() * 1000.0;
+		elapsed = now - then;
+		then = now;
+		if(elapsed >= ms)
+		{
+			break;
+		}
+		ms -= elapsed;
+		tv.tv_sec = ms / 1000;
+		tv.tv_usec = (ms % 1000) * 1000;
+
+		was_error = select(0, NULL, NULL, NULL, &tv);
+#endif
+	} while(was_error && (errno == EINTR));
 }
 }
 
 
-} // end namespace
+} // end namespace anki

+ 2 - 2
testapp/Main.cpp

@@ -286,8 +286,8 @@ void mainLoop()
 		timer.stop();
 		timer.stop();
 		if(timer.getElapsedTime() < AppSingleton::get().getTimerTick())
 		if(timer.getElapsedTime() < AppSingleton::get().getTimerTick())
 		{
 		{
-			SDL_Delay((AppSingleton::get().getTimerTick()
-				- timer.getElapsedTime()) * 1000.0);
+			HighRezTimer::sleep(AppSingleton::get().getTimerTick()
+				- timer.getElapsedTime());
 		}
 		}
 #else
 #else
 		if(MainRendererSingleton::get().getFramesCount() == 1000)
 		if(MainRendererSingleton::get().getFramesCount() == 1000)