[Scummvm-cvs-logs] SF.net SVN: scummvm:[49485] scummvm/trunk/backends/platform/psp
Bluddy at users.sourceforge.net
Bluddy at users.sourceforge.net
Mon Jun 7 15:47:28 CEST 2010
Revision: 49485
http://scummvm.svn.sourceforge.net/scummvm/?rev=49485&view=rev
Author: Bluddy
Date: 2010-06-07 13:47:27 +0000 (Mon, 07 Jun 2010)
Log Message:
-----------
PSP: found bug in fast getMillis() implementation. Fixed it by adding a fixed amount to the time counter.
Modified Paths:
--------------
scummvm/trunk/backends/platform/psp/osys_psp.cpp
scummvm/trunk/backends/platform/psp/osys_psp.h
scummvm/trunk/backends/platform/psp/thread.cpp
scummvm/trunk/backends/platform/psp/thread.h
Modified: scummvm/trunk/backends/platform/psp/osys_psp.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/osys_psp.cpp 2010-06-07 13:47:14 UTC (rev 49484)
+++ scummvm/trunk/backends/platform/psp/osys_psp.cpp 2010-06-07 13:47:27 UTC (rev 49485)
@@ -37,7 +37,6 @@
#include "backends/platform/psp/psppixelformat.h"
#include "backends/platform/psp/osys_psp.h"
#include "backends/platform/psp/powerman.h"
-#include "backends/platform/psp/thread.h"
#include "backends/saves/psp/psp-saves.h"
#include "backends/timer/default/default-timer.h"
@@ -300,7 +299,7 @@
}
uint32 OSystem_PSP::getMillis() {
- return PspThread::getMillis();
+ return _pspRtc.getMillis();
}
void OSystem_PSP::delayMillis(uint msecs) {
Modified: scummvm/trunk/backends/platform/psp/osys_psp.h
===================================================================
--- scummvm/trunk/backends/platform/psp/osys_psp.h 2010-06-07 13:47:14 UTC (rev 49484)
+++ scummvm/trunk/backends/platform/psp/osys_psp.h 2010-06-07 13:47:27 UTC (rev 49485)
@@ -40,6 +40,7 @@
#include "backends/platform/psp/input.h"
#include "backends/platform/psp/audio.h"
#include "backends/timer/psp/timer.h"
+#include "backends/platform/psp/thread.h"
#include <SDL.h>
@@ -59,6 +60,7 @@
InputHandler _inputHandler;
PspAudio _audio;
PspTimer _pspTimer;
+ PspRtc _pspRtc;
void initSDL();
Modified: scummvm/trunk/backends/platform/psp/thread.cpp
===================================================================
--- scummvm/trunk/backends/platform/psp/thread.cpp 2010-06-07 13:47:14 UTC (rev 49484)
+++ scummvm/trunk/backends/platform/psp/thread.cpp 2010-06-07 13:47:27 UTC (rev 49485)
@@ -29,6 +29,7 @@
#include <pspthreadman.h>
#include "backends/platform/psp/thread.h"
+#include "backends/platform/psp/trace.h"
void PspThread::delayMillis(uint32 ms) {
sceKernelDelayThread(ms * 1000);
@@ -38,15 +39,49 @@
sceKernelDelayThread(us);
}
-uint32 PspThread::getMillis() {
+void PspRtc::init() { // init our starting ticks
uint32 ticks[2];
sceRtcGetCurrentTick((u64 *)ticks);
- return (ticks[0]/1000);
+
+ _startMillis = ticks[0]/1000;
+ _startMicros = ticks[0];
+ //_lastMillis = ticks[0]/1000; //debug - only when we don't subtract startMillis
}
-uint32 PspThread::getMicros() {
+#define MS_LOOP_AROUND 4294967 /* We loop every 2^32 / 1000 = 71 minutes */
+#define MS_LOOP_CHECK 60000 /* Threading can cause weird mixups without this */
+
+// Note that after we fill up 32 bits ie 50 days we'll loop back to 0, which may cause
+// unpredictable results
+uint32 PspRtc::getMillis() {
uint32 ticks[2];
+
+ sceRtcGetCurrentTick((u64 *)ticks); // can introduce weird thread delays
+
+ uint32 millis = ticks[0]/1000;
+ millis -= _startMillis; // get ms since start of program
+
+ if ((int)_lastMillis - (int)millis > MS_LOOP_CHECK) { // we must have looped around
+ if (_looped == false) { // check to make sure threads do this once
+ _looped = true;
+ _milliOffset += MS_LOOP_AROUND; // add the needed offset
+ PSP_DEBUG_PRINT("looping around. last ms[%d], curr ms[%d]\n", _lastMillis, millis);
+ }
+ } else {
+ _looped = false;
+ }
+
+ _lastMillis = millis;
+
+ return millis + _milliOffset;
+}
+
+uint32 PspRtc::getMicros() {
+ uint32 ticks[2];
+
sceRtcGetCurrentTick((u64 *)ticks);
+ ticks[0] -= _startMicros;
+
return ticks[0];
}
Modified: scummvm/trunk/backends/platform/psp/thread.h
===================================================================
--- scummvm/trunk/backends/platform/psp/thread.h 2010-06-07 13:47:14 UTC (rev 49484)
+++ scummvm/trunk/backends/platform/psp/thread.h 2010-06-07 13:47:27 UTC (rev 49485)
@@ -32,10 +32,22 @@
public:
static void delayMillis(uint32 ms);
static void delayMicros(uint32 us);
- static uint32 getMillis();
- static uint32 getMicros();
};
+class PspRtc {
+private:
+ uint32 _startMillis;
+ uint32 _startMicros;
+ uint32 _lastMillis;
+ uint32 _milliOffset; // to prevent looping around of millis
+ bool _looped; // make sure we only loop once
+public:
+ PspRtc() : _startMillis(0), _startMicros(0), _lastMillis(0), _milliOffset(0), _looped(false) { init(); }
+ void init();
+ uint32 getMillis();
+ uint32 getMicros();
+};
+
enum ThreadPriority {
PRIORITY_MAIN_THREAD = 36,
PRIORITY_TIMER_THREAD = 30,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list