Jelajahi Sumber

Remove Timer class in favour of a simpler two-functions-implementation

Daniele Bartolini 13 tahun lalu
induk
melakukan
65e02762ab
8 mengubah file dengan 27 tambahan dan 167 penghapusan
  1. 0 3
      src/CMakeLists.txt
  2. 0 1
      src/Crown.h
  3. 0 1
      src/Device.cpp
  4. 0 2
      src/Device.h
  5. 3 0
      src/os/OS.h
  6. 24 0
      src/os/linux/LinuxOS.cpp
  7. 0 87
      src/os/linux/LinuxTimer.cpp
  8. 0 73
      src/os/linux/LinuxTimer.h

+ 0 - 3
src/CMakeLists.txt

@@ -55,7 +55,6 @@ set (HEADERS
 	TextRenderer.h
 	Texture.h
 	TextureManager.h
-	Timer.h
 	VertexBuffer.h
 	World.h
 )
@@ -217,7 +216,6 @@ set (LINUX_SRC
 #	EGLRenderWindow.cpp
 	os/linux/GLXRenderWindow.cpp
 	os/linux/LinuxOS.cpp
-	os/linux/LinuxTimer.cpp
 	os/linux/Input.cpp
 	os/linux/LinuxTCPSocket.cpp
 	os/linux/LinuxUDPSocket.cpp	
@@ -225,7 +223,6 @@ set (LINUX_SRC
 
 set (LINUX_HEADERS
 #	os/linux/EGLRenderWindow.h
-	os/linux/LinuxTimer.h
 )
 
 set (WIN_SRC

+ 0 - 1
src/Crown.h

@@ -99,7 +99,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Skybox.h"
 #include "TextRenderer.h"
 #include "TextureManager.h"
-#include "Timer.h"
 #include "VertexBuffer.h"
 
 // Engine/Filesystem

+ 0 - 1
src/Device.cpp

@@ -30,7 +30,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Log.h"
 #include "OS.h"
 #include "Renderer.h"
-#include "Timer.h"
 #include "Types.h"
 #include <cstdlib>
 

+ 0 - 2
src/Device.h

@@ -27,7 +27,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Config.h"
-#include "Timer.h"
 #include "Str.h"
 
 namespace crown
@@ -76,7 +75,6 @@ private:
 	bool					mIsRunning	: 1;
 
 	Renderer*				mRenderer;
-	Timer					mTimer;
 
 	// Disable copying
 	Device(const Device&);

+ 3 - 0
src/os/OS.h

@@ -97,7 +97,10 @@ void			hide_cursor();
 void			show_cursor();
 
 //-----------------------------------------------------------------------------
+uint64_t		milliseconds();
+uint64_t		microseconds();
 
+//-----------------------------------------------------------------------------
 enum OSEventType
 {
 	OSET_NONE				= 0,

+ 24 - 0
src/os/linux/LinuxOS.cpp

@@ -31,12 +31,16 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include <sys/types.h>
 #include <dirent.h>
 #include <cstdlib>
+#include <sys/time.h>
+#include <time.h>
 
 namespace crown
 {
 namespace os
 {
 
+static timespec base_time;
+
 //-----------------------------------------------------------------------------
 void printf(const char* string, ...)
 {
@@ -202,6 +206,26 @@ bool ls(const char* path, List<Str>& fileList)
 //-----------------------------------------------------------------------------
 void init_os()
 {
+	// Initilize the base time
+	clock_gettime(CLOCK_MONOTONIC, &base_time);
+}
+
+//-----------------------------------------------------------------------------
+uint64_t milliseconds()
+{
+	timespec tmp;
+
+	clock_gettime(CLOCK_MONOTONIC, &tmp);
+
+	return (tmp.tv_sec - base_time.tv_sec) * 1000 + (tmp.tv_nsec - base_time.tv_nsec) / 1000000;
+}
+
+//-----------------------------------------------------------------------------
+uint64_t microseconds()
+{
+	timespec tmp;
+	clock_gettime(CLOCK_MONOTONIC, &tmp);
+	return (tmp.tv_sec - base_time.tv_sec) * 1000000 + (tmp.tv_nsec - base_time.tv_nsec) / 1000;
 }
 
 } // namespace os

+ 0 - 87
src/os/linux/LinuxTimer.cpp

@@ -1,87 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Types.h"
-#include "Timer.h"
-#include <sys/time.h>
-
-namespace crown
-{
-
-Timer::Timer()
-{
-	Reset();
-}
-
-Timer::~Timer()
-{
-}
-
-void Timer::Reset()
-{
-	clock_gettime(CLOCK_MONOTONIC, &mCreationTime);
-}
-
-uint64_t Timer::GetMilliseconds() const
-{
-	timespec tmp;
-	clock_gettime(CLOCK_MONOTONIC, &tmp);
-	return (tmp.tv_sec - mCreationTime.tv_sec) * 1000 + (tmp.tv_nsec - mCreationTime.tv_nsec) / 1000000;
-}
-
-uint64_t Timer::GetMicroseconds() const
-{
-	timespec tmp;
-	clock_gettime(CLOCK_MONOTONIC, &tmp);
-	return (tmp.tv_sec - mCreationTime.tv_sec) * 1000000 + (tmp.tv_nsec - mCreationTime.tv_nsec) / 1000;
-}
-
-
-void Timer::StartMilliseconds()
-{
-	clock_gettime(CLOCK_MONOTONIC, &mStartTime);
-}
-
-uint64_t Timer::StopMilliseconds() const
-{
-	timespec tmp;
-	clock_gettime(CLOCK_MONOTONIC, &tmp);
-	return (tmp.tv_sec - mStartTime.tv_sec) * 1000 + (tmp.tv_nsec - mStartTime.tv_nsec) / 1000000;
-}
-
-void Timer::StartMicroseconds()
-{
-	clock_gettime(CLOCK_MONOTONIC, &mStartTime);
-}
-
-uint64_t Timer::StopMicroseconds() const
-{
-	timespec tmp;
-	clock_gettime(CLOCK_MONOTONIC, &tmp);
-	return (tmp.tv_sec - mStartTime.tv_sec) * 1000000 + (tmp.tv_nsec - mStartTime.tv_nsec) / 1000;
-}
-
-} // namespace crown
-

+ 0 - 73
src/os/linux/LinuxTimer.h

@@ -1,73 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include <time.h>
-#include "Types.h"
-
-namespace crown
-{
-
-class Timer
-{
-
-public:
-
-	//! Constructor
-	Timer();
-
-	//! Destructor
-	~Timer();
-
-	//! Returns the time (in milliseconds) elapsed since the instantiation of this class
-	uint64_t GetMilliseconds() const;
-
-	//! Returns the time (in microseconds) elapsed since the instantiation of this class
-	uint64_t GetMicroseconds() const;
-
-	//! Records the current time
-	void StartMilliseconds();
-
-	//! Returns the time (in milliseconds) elapsed since the last call to StartMilliseconds()
-	uint64_t StopMilliseconds() const;
-
-	//! Records the current time
-	void StartMicroseconds();
-
-	//! Returns the time (in microseconds) elapsed since the last call to StartMicroseconds()
-	uint64_t StopMicroseconds() const;
-
-private:
-
-	// Records the initial reference time
-	void Reset();
-
-	timespec mCreationTime;		// Time at instantiation
-	timespec mStartTime;		// Time at Start* call
-};
-
-} // namespace crown
-