[Scummvm-git-logs] scummvm master -> 30c00656e1d6e6e8420c662755527ac3b08ee8ff

sev- sev at scummvm.org
Wed May 27 10:41:55 UTC 2020


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
068b3371bd NULL: Add implementation of getMillis, delayMillis and getTimeAndDate
30c00656e1 NULL: Ensure that the timer callback is called regularly


Commit: 068b3371bd5b97339b32c2cc528f9e3d56f82aba
    https://github.com/scummvm/scummvm/commit/068b3371bd5b97339b32c2cc528f9e3d56f82aba
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2020-05-27T12:41:51+02:00

Commit Message:
NULL: Add implementation of getMillis, delayMillis and getTimeAndDate

Changed paths:
    backends/platform/null/null.cpp


diff --git a/backends/platform/null/null.cpp b/backends/platform/null/null.cpp
index 4117982737..efccb65f58 100644
--- a/backends/platform/null/null.cpp
+++ b/backends/platform/null/null.cpp
@@ -20,6 +20,12 @@
  *
  */
 
+#include <time.h>
+#ifdef POSIX
+#include <sys/time.h>
+#include <unistd.h>
+#endif
+
 // We use some stdio.h functionality here thus we need to allow some
 // symbols. Alternatively, we could simply allow everything by defining
 // FORBIDDEN_SYMBOL_ALLOW_ALL
@@ -28,6 +34,7 @@
 #define FORBIDDEN_SYMBOL_EXCEPTION_stderr
 #define FORBIDDEN_SYMBOL_EXCEPTION_fputs
 #define FORBIDDEN_SYMBOL_EXCEPTION_exit
+#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
 
 #include "backends/modular-backend.h"
 #include "base/main.h"
@@ -66,11 +73,16 @@ public:
 
 	virtual uint32 getMillis(bool skipRecord = false);
 	virtual void delayMillis(uint msecs);
-	virtual void getTimeAndDate(TimeDate &t) const {}
+	virtual void getTimeAndDate(TimeDate &t) const;
 
 	virtual void quit();
 
 	virtual void logMessage(LogMessageType::Type type, const char *message);
+
+#ifdef POSIX
+private:
+	timeval _startTime;
+#endif
 };
 
 OSystem_NULL::OSystem_NULL() {
@@ -91,6 +103,10 @@ OSystem_NULL::~OSystem_NULL() {
 }
 
 void OSystem_NULL::initBackend() {
+#ifdef POSIX
+	gettimeofday(&_startTime, 0);
+#endif
+
 	_mutexManager = new NullMutexManager();
 	_timerManager = new DefaultTimerManager();
 	_eventManager = new DefaultEventManager(this);
@@ -112,10 +128,34 @@ bool OSystem_NULL::pollEvent(Common::Event &event) {
 }
 
 uint32 OSystem_NULL::getMillis(bool skipRecord) {
+#ifdef POSIX
+	timeval curTime;
+
+	gettimeofday(&curTime, 0);
+
+	return (uint32)(((curTime.tv_sec - _startTime.tv_sec) * 1000) +
+			((curTime.tv_usec - _startTime.tv_usec) / 1000));
+#else
 	return 0;
+#endif
 }
 
 void OSystem_NULL::delayMillis(uint msecs) {
+#ifdef POSIX
+	usleep(msecs * 1000);
+#endif
+}
+
+void OSystem_NULL::getTimeAndDate(TimeDate &td) const {
+	time_t curTime = time(0);
+	struct tm t = *localtime(&curTime);
+	td.tm_sec = t.tm_sec;
+	td.tm_min = t.tm_min;
+	td.tm_hour = t.tm_hour;
+	td.tm_mday = t.tm_mday;
+	td.tm_mon = t.tm_mon;
+	td.tm_year = t.tm_year;
+	td.tm_wday = t.tm_wday;
 }
 
 void OSystem_NULL::quit() {


Commit: 30c00656e1d6e6e8420c662755527ac3b08ee8ff
    https://github.com/scummvm/scummvm/commit/30c00656e1d6e6e8420c662755527ac3b08ee8ff
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2020-05-27T12:41:51+02:00

Commit Message:
NULL: Ensure that the timer callback is called regularly

Changed paths:
    backends/platform/null/null.cpp
    backends/timer/default/default-timer.cpp
    backends/timer/default/default-timer.h


diff --git a/backends/platform/null/null.cpp b/backends/platform/null/null.cpp
index efccb65f58..41a1f7c685 100644
--- a/backends/platform/null/null.cpp
+++ b/backends/platform/null/null.cpp
@@ -116,14 +116,16 @@ void OSystem_NULL::initBackend() {
 
 	((Audio::MixerImpl *)_mixer)->setReady(false);
 
-	// Note that both the mixer and the timer manager are useless
-	// this way; they need to be hooked into the system somehow to
-	// be functional. Of course, can't do that in a NULL backend :).
+	// Note that the mixer is useless this way; it needs to be hooked
+	// into the system somehow to be functional. Of course, can't do
+	// that in a NULL backend :).
 
 	ModularBackend::initBackend();
 }
 
 bool OSystem_NULL::pollEvent(Common::Event &event) {
+	((DefaultTimerManager *)getTimerManager())->checkTimers();
+
 	return false;
 }
 
diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp
index 8e2eac21b7..02f1f0ed8e 100644
--- a/backends/timer/default/default-timer.cpp
+++ b/backends/timer/default/default-timer.cpp
@@ -62,6 +62,7 @@ void insertPrioQueue(TimerSlot *head, TimerSlot *newSlot) {
 
 
 DefaultTimerManager::DefaultTimerManager() :
+	_timerCallbackNext(0),
 	_head(0) {
 
 	_head = new TimerSlot();
@@ -114,6 +115,16 @@ void DefaultTimerManager::handler() {
 	}
 }
 
+void DefaultTimerManager::checkTimers(uint32 interval) {
+	uint32 curTime = g_system->getMillis();
+
+	// Timer checking & firing
+	if (curTime >= _timerCallbackNext) {
+		handler();
+		_timerCallbackNext = curTime + interval;
+	}
+}
+
 bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, void *refCon, const Common::String &id) {
 	assert(interval > 0);
 	Common::StackLock lock(_mutex);
diff --git a/backends/timer/default/default-timer.h b/backends/timer/default/default-timer.h
index 8b23fb744f..405a59b024 100644
--- a/backends/timer/default/default-timer.h
+++ b/backends/timer/default/default-timer.h
@@ -38,6 +38,8 @@ private:
 	TimerSlot *_head;
 	TimerSlotMap _callbacks;
 
+	uint32 _timerCallbackNext;
+
 public:
 	DefaultTimerManager();
 	virtual ~DefaultTimerManager();
@@ -48,6 +50,12 @@ public:
 	 * Timer callback, to be invoked at regular time intervals by the backend.
 	 */
 	void handler();
+
+	/*
+	 * Ensure that the callback is called at regular time intervals.
+	 * Should be called from pollEvents() on backends without threads.
+	 */
+	void checkTimers(uint32 interval = 10);
 };
 
 #endif




More information about the Scummvm-git-logs mailing list