Introduce a new struct TimeDate, replacing struct tm in client code. May lead to compilation issues in ports, which should be trivial to fix, though

svn-id: r44793
This commit is contained in:
Max Horn 2009-10-08 19:41:38 +00:00
parent f5ccaf7e29
commit 42120ed626
33 changed files with 134 additions and 75 deletions

View file

@ -125,9 +125,15 @@ void OSystem_PalmBase::initBackend() {
OSystem::initBackend();
}
void OSystem_PalmBase::getTimeAndDate(struct tm &t) const {
void OSystem_PalmBase::getTimeAndDate(TimeDate &td) const {
time_t curTime = time(0);
t = *localtime(&curTime);
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;
}
uint32 OSystem_PalmBase::getMillis() {

View file

@ -239,7 +239,7 @@ public:
bool pollEvent(Common::Event &event);
void getTimeAndDate(struct tm &t) const;
void getTimeAndDate(TimeDate &t) const;
virtual uint32 getMillis();
virtual void delayMillis(uint msecs);

View file

@ -123,7 +123,7 @@ class OSystem_Dreamcast : private DCHardware, public BaseBackend, public Filesys
void delayMillis(uint msecs);
// Get the current time and date. Correspond to time()+localtime().
void getTimeAndDate(struct tm &t) const;
void getTimeAndDate(TimeDate &t) const;
// Get the next event.
// Returns true if an event was retrieved.

View file

@ -193,10 +193,16 @@ bool OSystem_Dreamcast::getFeatureState(Feature f)
}
}
void OSystem_Dreamcast::getTimeAndDate(struct tm &t) const {
void OSystem_Dreamcast::getTimeAndDate(TimeDate &td) const {
time_t curTime;
time(&curTime);
t = *localtime(&curTime);
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;
}
void DCHardware::dc_init_hardware()

View file

@ -655,14 +655,20 @@ void OSystem_DS::delayMillis(uint msecs) {
}
void OSystem_DS::getTimeAndDate(struct tm &t) const {
void OSystem_DS::getTimeAndDate(TimeDate &td) const {
time_t curTime;
#if 0
curTime = time(0);
#else
curTime = 0xABCD1234 + DS::getMillis() / 1000;
#endif
t = *localtime(&curTime);
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;
}
FilesystemFactory *OSystem_DS::getFilesystemFactory() {

View file

@ -118,7 +118,7 @@ public:
virtual bool pollEvent(Common::Event &event);
virtual uint32 getMillis();
virtual void delayMillis(uint msecs);
virtual void getTimeAndDate(struct tm &t) const;
virtual void getTimeAndDate(TimeDate &t) const;
virtual MutexRef createMutex(void);
virtual void lockMutex(MutexRef mutex);

View file

@ -138,7 +138,7 @@ public:
// Quit
void quit();
void getTimeAndDate(struct tm &t) const;
void getTimeAndDate(TimeDate &t) const;
virtual Common::TimerManager *getTimerManager();
// Mutex handling

View file

@ -301,9 +301,15 @@ void OSystem_GP2X::delayMillis(uint msecs) {
SDL_Delay(msecs);
}
void OSystem_GP2X::getTimeAndDate(struct tm &t) const {
void OSystem_GP2X::getTimeAndDate(TimeDate &td) const {
time_t curTime = time(0);
t = *localtime(&curTime);
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;
}
Common::TimerManager *OSystem_GP2X::getTimerManager() {

View file

@ -198,9 +198,15 @@ void OSystem_IPHONE::setTimerCallback(TimerProc callback, int interval) {
void OSystem_IPHONE::quit() {
}
void OSystem_IPHONE::getTimeAndDate(struct tm &t) const {
void OSystem_IPHONE::getTimeAndDate(TimeDate &td) const {
time_t curTime = time(0);
t = *localtime(&curTime);
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;
}
Common::SaveFileManager *OSystem_IPHONE::getSavefileManager() {

View file

@ -169,7 +169,7 @@ public:
FilesystemFactory *getFilesystemFactory() { return _fsFactory; }
virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0);
virtual void getTimeAndDate(struct tm &t) const;
virtual void getTimeAndDate(TimeDate &t) const;
virtual Common::SaveFileManager *getSavefileManager();
virtual Audio::Mixer *getMixer();

View file

@ -115,7 +115,7 @@ public:
virtual Common::SaveFileManager *getSavefileManager();
virtual Audio::Mixer *getMixer();
virtual void getTimeAndDate(struct tm &t) const;
virtual void getTimeAndDate(TimeDate &t) const;
virtual Common::TimerManager *getTimerManager();
FilesystemFactory *getFilesystemFactory();
@ -321,7 +321,7 @@ Common::TimerManager *OSystem_NULL::getTimerManager() {
return _timer;
}
void OSystem_NULL::getTimeAndDate(struct tm &t) const {
void OSystem_NULL::getTimeAndDate(TimeDate &t) const {
}
FilesystemFactory *OSystem_NULL::getFilesystemFactory() {

View file

@ -106,7 +106,7 @@ void OSystem_PS2::readRtcTime(void) {
g_day, g_month, g_year + 2000);
}
void OSystem_PS2::getTimeAndDate(struct tm &t) const {
void OSystem_PS2::getTimeAndDate(TimeDate &t) const {
uint32 currentSecs = g_timeSecs + (msecCount - g_lastTimeCheck) / 1000;
if (currentSecs >= SECONDS_PER_DAY) {
@ -121,6 +121,4 @@ void OSystem_PS2::getTimeAndDate(struct tm &t) const {
t.tm_year = g_year + 100;
t.tm_mday = g_day;
t.tm_mon = g_month - 1;
// tm_wday, tm_yday and tm_isdst are zero for now
t.tm_wday = t.tm_yday = t.tm_isdst = 0;
}

View file

@ -124,7 +124,7 @@ public:
virtual Common::SaveFileManager *getSavefileManager();
virtual FilesystemFactory *getFilesystemFactory();
virtual void getTimeAndDate(struct tm &t) const;
virtual void getTimeAndDate(TimeDate &t) const;
void timerThread(void);
void soundThread(void);

View file

@ -1155,9 +1155,15 @@ void OSystem_PSP::quit() {
sceKernelExitGame();
}
void OSystem_PSP::getTimeAndDate(struct tm &t) const {
void OSystem_PSP::getTimeAndDate(TimeDate &td) const {
time_t curTime = time(0);
t = *localtime(&curTime);
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;
}
#define PSP_CONFIG_FILE "ms0:/scummvm.ini"

View file

@ -159,7 +159,7 @@ public:
Audio::Mixer *getMixer() { return _mixer; }
Common::TimerManager *getTimerManager() { return _timer; }
FilesystemFactory *getFilesystemFactory() { return &PSPFilesystemFactory::instance(); }
void getTimeAndDate(struct tm &t) const;
void getTimeAndDate(TimeDate &t) const;
virtual void quit();

View file

@ -295,9 +295,15 @@ void OSystem_SDL::delayMillis(uint msecs) {
SDL_Delay(msecs);
}
void OSystem_SDL::getTimeAndDate(struct tm &t) const {
void OSystem_SDL::getTimeAndDate(TimeDate &td) const {
time_t curTime = time(0);
t = *localtime(&curTime);
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;
}
Common::TimerManager *OSystem_SDL::getTimerManager() {

View file

@ -183,7 +183,7 @@ public:
// Quit
virtual void quit(); // overloaded by CE backend
virtual void getTimeAndDate(struct tm &t) const;
virtual void getTimeAndDate(TimeDate &t) const;
virtual Common::TimerManager *getTimerManager();
// Mutex handling

View file

@ -264,9 +264,15 @@ FilesystemFactory *OSystem_Wii::getFilesystemFactory() {
return &WiiFilesystemFactory::instance();
}
void OSystem_Wii::getTimeAndDate(struct tm &t) const {
void OSystem_Wii::getTimeAndDate(TimeDate &td) const {
time_t curTime = time(0);
t = *localtime(&curTime);
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;
}
void OSystem_Wii::showOptionsDialog() {

View file

@ -211,7 +211,7 @@ public:
virtual Audio::Mixer *getMixer();
virtual Common::TimerManager *getTimerManager();
virtual FilesystemFactory *getFilesystemFactory();
virtual void getTimeAndDate(struct tm &t) const;
virtual void getTimeAndDate(TimeDate &t) const;
};
#endif

View file

@ -2523,13 +2523,12 @@ void OSystem_WINCE3::quit() {
OSystem_SDL::quit();
}
void OSystem_WINCE3::getTimeAndDate(struct tm &t) const {
void OSystem_WINCE3::getTimeAndDate(TimeDate &t) const {
SYSTEMTIME systime;
GetLocalTime(&systime);
t.tm_year = systime.wYear - 1900;
t.tm_mon = systime.wMonth - 1;
t.tm_wday = systime.wDayOfWeek;
t.tm_mday = systime.wDay;
t.tm_hour = systime.wHour;
t.tm_min = systime.wMinute;

View file

@ -85,7 +85,7 @@ public:
void setupMixer();
// Overloaded from OSystem
void engineInit();
void getTimeAndDate(struct tm &t) const;
void getTimeAndDate(TimeDate &t) const;
virtual Common::SeekableReadStream *createConfigReadStream();
virtual Common::WriteStream *createConfigWriteStream();

View file

@ -53,6 +53,24 @@ namespace Common {
class FilesystemFactory;
/**
* A structure describing time and date. This is a clone of struct tm
* from time.h. We roll our own since not all systems provide time.h.
* We also do not imitate all files of struct tm, only those we
* actually need.
*
* @note For now, the members are named exactly as in struct tm to ease
* the transition.
*/
struct TimeDate {
int tm_sec; ///< seconds (0 - 60)
int tm_min; ///< minutes (0 - 59)
int tm_hour; ///< hours (0 - 23)
int tm_mday; ///< day of month (1 - 31)
int tm_mon; ///< month of year (0 - 11)
int tm_year; ///< year - 1900
};
/**
* Interface for ScummVM backends. If you want to port ScummVM to a system
* which is not currently covered by any of our backends, this is the place
@ -805,7 +823,7 @@ public:
* Corresponds on many systems to the combination of time()
* and localtime().
*/
virtual void getTimeAndDate(struct tm &t) const = 0;
virtual void getTimeAndDate(TimeDate &t) const = 0;
/**
* Return the timer manager singleton. For more information, refer

View file

@ -28,8 +28,6 @@
// Multi-slots by Claudio Matsuoka <claudio@helllabs.org>
//
#include <time.h> // for extended infos
#include "common/file.h"
#include "graphics/thumbnail.h"
#include "common/config-manager.h"
@ -79,7 +77,7 @@ int AgiEngine::saveGame(const char *fileName, const char *description) {
Graphics::saveThumbnail(*out);
// Creation date/time
tm curTime;
TimeDate curTime;
_system->getTimeAndDate(curTime);
uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);

View file

@ -23,8 +23,6 @@
*
*/
#include <time.h> // for extended infos
#include "draci/draci.h"
#include "draci/saveload.h"
@ -95,7 +93,7 @@ Common::Error saveSavegameData(int saveGameIdx, const Common::String &saveName,
if (f == NULL)
return Common::kNoGameDataFoundError;
tm curTime;
TimeDate curTime;
vm._system->getTimeAndDate(curTime);
// Save the savegame header

View file

@ -23,8 +23,6 @@
*
*/
#include <time.h> // FIXME: for Inter::renewTimeInVars()
#include "common/endian.h"
#include "gob/gob.h"
@ -159,7 +157,7 @@ void Inter::initControlVars(char full) {
}
void Inter::renewTimeInVars() {
struct tm t;
TimeDate t;
_vm->_system->getTimeAndDate(t);
WRITE_VAR(5, 1900 + t.tm_year);

View file

@ -23,8 +23,6 @@
*
*/
#include <time.h> // for extended infos
#include "common/config-manager.h"
#include "common/savefile.h"
#include "common/system.h"
@ -199,7 +197,7 @@ void SagaEngine::save(const char *fileName, const char *saveName) {
Graphics::saveThumbnail(*out);
// Date / time
tm curTime;
TimeDate curTime;
_system->getTimeAndDate(curTime);
uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);

View file

@ -25,8 +25,6 @@
#include "common/system.h"
#include <time.h> // FIXME: For struct tm
#include "sci/sci.h"
#include "sci/debug.h"
#include "sci/engine/state.h"
@ -115,7 +113,7 @@ enum {
};
reg_t kGetTime(EngineState *s, int argc, reg_t *argv) {
tm loc_time;
TimeDate loc_time;
uint32 elapsedTime;
int retval = 0; // Avoid spurious warning

View file

@ -28,9 +28,6 @@
#include "common/func.h"
#include "common/serializer.h"
#include <time.h> // FIXME: For struct tm
#include "sci/sci.h"
#include "sci/gfx/operations.h"
#include "sci/gfx/menubar.h"
@ -497,7 +494,7 @@ static void sync_songlib_t(Common::Serializer &s, SongLibrary &obj) {
int gamestate_save(EngineState *s, Common::WriteStream *fh, const char* savename, const char *version) {
tm curTime;
TimeDate curTime;
g_system->getTimeAndDate(curTime);
SavegameMetadata meta;

View file

@ -23,8 +23,6 @@
*
*/
#include <time.h> // for ScummEngine::saveInfos / ScummEngine::loadInfos
#include "common/config-manager.h"
#include "common/savefile.h"
#include "common/system.h"
@ -779,10 +777,10 @@ void ScummEngine::saveInfos(Common::WriteStream* file) {
section.size = SaveInfoSectionSize;
// still save old format for older versions
section.timeTValue = time(0);
section.timeTValue = 0;
section.playtime = _system->getMillis() / 1000 - _engineStartTime;
tm curTime;
TimeDate curTime;
_system->getTimeAndDate(curTime);
section.date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);

View file

@ -23,8 +23,6 @@
*
*/
#include <time.h> // for ScummEngine_v6::o6_getDateTime()
#include "common/config-manager.h"
#include "common/system.h"
@ -2940,7 +2938,7 @@ void ScummEngine_v6::o6_pickVarRandom() {
}
void ScummEngine_v6::o6_getDateTime() {
struct tm t;
TimeDate t;
_system->getTimeAndDate(t);
VAR(VAR_TIMEDATE_YEAR) = t.tm_year;

View file

@ -23,8 +23,6 @@
*
*/
#include <time.h> // for extended infos
#include "common/file.h"
#include "common/util.h"
#include "common/savefile.h"
@ -1112,7 +1110,7 @@ void Control::saveGameToFile(uint8 slot) {
Graphics::saveThumbnail(*outf);
// Date / time
tm curTime;
TimeDate curTime;
_system->getTimeAndDate(curTime);
uint32 saveDate = (curTime.tm_mday & 0xFF) << 24 | ((curTime.tm_mon + 1) & 0xFF) << 16 | ((curTime.tm_year + 1900) & 0xFFFF);
@ -1278,7 +1276,7 @@ bool Control::convertSaveGame(uint8 slot, char* desc) {
newSave->writeByte(SAVEGAME_VERSION);
// Date / time
tm curTime;
TimeDate curTime;
_system->getTimeAndDate(curTime);
uint32 saveDate = (curTime.tm_mday & 0xFF) << 24 | ((curTime.tm_mon + 1) & 0xFF) << 16 | ((curTime.tm_year + 1900) & 0xFFFF);

View file

@ -95,7 +95,7 @@ struct SaveGameHeader {
uint32 size;
uint32 ver;
char desc[SG_DESC_LEN];
struct tm dateTime;
TimeDate dateTime;
};
enum {
@ -124,18 +124,13 @@ static char *SaveSceneSsData = 0; // points to 'SAVED_DATA ssdata[MAX_NEST]'
void setNeedLoad() { NeedLoad = true; }
static void syncTime(Common::Serializer &s, struct tm &t) {
static void syncTime(Common::Serializer &s, TimeDate &t) {
s.syncAsUint16LE(t.tm_year);
s.syncAsByte(t.tm_mon);
s.syncAsByte(t.tm_mday);
s.syncAsByte(t.tm_hour);
s.syncAsByte(t.tm_min);
s.syncAsByte(t.tm_sec);
if (s.isLoading()) {
t.tm_wday = 0;
t.tm_yday = 0;
t.tm_isdst = 0;
}
}
static bool syncSaveGameHeader(Common::Serializer &s, SaveGameHeader &hdr) {
@ -299,6 +294,28 @@ static char *NewName(void) {
return result;
}
/**
* Compare two TimeDate structs to see which one was earlier.
* Returns 0 if they are equal, a negative value if a is lower / first, and
* a positive value if b is lower / first.
*/
static int cmpTimeDate(const TimeDate &a, const TimeDate &b) {
int tmp;
#define CMP_ENTRY(x) tmp = a.x - b.x; if (tmp != 0) return tmp
CMP_ENTRY(tm_year);
CMP_ENTRY(tm_mon);
CMP_ENTRY(tm_mday);
CMP_ENTRY(tm_hour);
CMP_ENTRY(tm_min);
CMP_ENTRY(tm_sec);
#undef CMP_ENTRY
return 0;
}
/**
* Interrogate the current DOS directory for saved game files.
* Store the file details, ordered by time, in savedFiles[] and return
@ -341,7 +358,7 @@ int getList(Common::SaveFileManager *saveFileMan, const Common::String &target)
i = numSfiles;
#ifndef DISABLE_SAVEGAME_SORTING
for (i = 0; i < numSfiles; i++) {
if (difftime(mktime(&hdr.dateTime), mktime(&savedFiles[i].dateTime)) > 0) {
if (cmpTimeDate(hdr.dateTime, savedFiles[i].dateTime) > 0) {
Common::copy_backward(&savedFiles[i], &savedFiles[numSfiles], &savedFiles[numSfiles + 1]);
break;
}

View file

@ -27,8 +27,6 @@
#ifndef TINSEL_SAVESCN_H
#define TINSEL_SAVESCN_H
#include <time.h> // for time_t struct
#include "tinsel/actors.h" // SAVED_ACTOR
#include "tinsel/dw.h" // SCNHANDLE
#include "tinsel/rince.h" // SAVED_MOVER
@ -52,7 +50,7 @@ enum {
struct SFILES {
char name[FNAMELEN];
char desc[SG_DESC_LEN + 2];
struct tm dateTime;
TimeDate dateTime;
};
struct SAVED_DATA {