Ticket #8765: curtime.patch

File curtime.patch, 5.4 KB (added by fingolfin, 14 years ago)
  • engines/scumm/saveload.cpp

     
    2323 *
    2424 */
    2525
    26 
    27 
    2826#include "common/config-manager.h"
    2927#include "common/savefile.h"
    3028#include "common/system.h"
     
    555553
    556554        // For header version 1, we load the data in with our old method
    557555        if (section.version == 1) {
    558                 time_t tmp = section.timeTValue;
    559                 tm *curTime = localtime(&tmp);
    560                 stuff->date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF;
    561                 stuff->time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF;
     556                //time_t tmp = section.timeTValue;
     557                //tm *curTime = localtime(&tmp);
     558                //stuff->date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF;
     559                //stuff->time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF;
     560                stuff->date = 0;
     561                stuff->time = 0;
    562562        }
    563563
    564564        if (section.version >= 2) {
     
    588588        // still save old format for older versions
    589589        section.timeTValue = time(0);
    590590        section.playtime = _system->getMillis() / 1000 - _engineStartTime;
     591       
     592        tm curTime;
     593        _system->getTimeAndDate(curTime);
     594       
     595        section.date = (curTime.tm_mday & 0xFF) << 24 | ((curTime.tm_mon + 1) & 0xFF) << 16 | (curTime.tm_year + 1900) & 0xFFFF;
     596        section.time = (curTime.tm_hour & 0xFF) << 8 | (curTime.tm_min) & 0xFF;
    591597
    592         time_t curTime_ = time(0);
    593         tm *curTime = localtime(&curTime_);
    594         section.date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF;
    595         section.time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF;
    596 
    597598        file->writeUint32BE(section.type);
    598599        file->writeUint32BE(section.version);
    599600        file->writeUint32BE(section.size);
  • engines/scumm/script_v6.cpp

     
    2323 *
    2424 */
    2525
    26 
    27 
    2826#include "common/config-manager.h"
     27#include "common/system.h"
    2928
    3029#include "scumm/actor.h"
    3130#include "scumm/charset.h"
     
    30033002}
    30043003
    30053004void ScummEngine_v6::o6_getDateTime() {
    3006         struct tm *t;
    3007         time_t now = time(NULL);
     3005        struct tm t;
     3006        _system->getTimeAndDate(t);
    30083007
    3009         t = localtime(&now);
     3008        VAR(VAR_TIMEDATE_YEAR) = t.tm_year;
     3009        VAR(VAR_TIMEDATE_MONTH) = t.tm_mon;
     3010        VAR(VAR_TIMEDATE_DAY) = t.tm_mday;
     3011        VAR(VAR_TIMEDATE_HOUR) = t.tm_hour;
     3012        VAR(VAR_TIMEDATE_MINUTE) = t.tm_min;
    30103013
    3011         VAR(VAR_TIMEDATE_YEAR) = t->tm_year;
    3012         VAR(VAR_TIMEDATE_MONTH) = t->tm_mon;
    3013         VAR(VAR_TIMEDATE_DAY) = t->tm_mday;
    3014         VAR(VAR_TIMEDATE_HOUR) = t->tm_hour;
    3015         VAR(VAR_TIMEDATE_MINUTE) = t->tm_min;
    3016 
    30173014        if (_game.version == 8)
    3018                 VAR(VAR_TIMEDATE_SECOND) = t->tm_sec;
     3015                VAR(VAR_TIMEDATE_SECOND) = t.tm_sec;
    30193016}
    30203017
    30213018void ScummEngine_v6::o6_getPixel() {
  • engines/gob/inter.cpp

     
    125125}
    126126
    127127void Inter::renewTimeInVars() {
    128         struct tm *t;
    129         time_t now = time(NULL);
     128        struct tm t;
     129        _vm->_system->getTimeAndDate(t);
    130130
    131         t = localtime(&now);
    132 
    133         WRITE_VAR(5, 1900 + t->tm_year);
    134         WRITE_VAR(6, t->tm_mon + 1);
     131        WRITE_VAR(5, 1900 + t.tm_year);
     132        WRITE_VAR(6, t.tm_mon + 1);
    135133        WRITE_VAR(7, 0);
    136         WRITE_VAR(8, t->tm_mday);
    137         WRITE_VAR(9, t->tm_hour);
    138         WRITE_VAR(10, t->tm_min);
    139         WRITE_VAR(11, t->tm_sec);
     134        WRITE_VAR(8, t.tm_mday);
     135        WRITE_VAR(9, t.tm_hour);
     136        WRITE_VAR(10, t.tm_min);
     137        WRITE_VAR(11, t.tm_sec);
    140138}
    141139
    142140void Inter::storeMouse() {
  • common/system.h

     
    724724
    725725        /** Delay/sleep for the specified amount of milliseconds. */
    726726        virtual void delayMillis(uint msecs) = 0;
     727       
     728        /** Get the current time and date. Correspond to time()+localtime(). */
     729        virtual void getTimeAndDate(struct tm &t) const;
    727730
    728731        /**
    729732         * Return the timer manager singleton. For more information, refer
  • common/system.cpp

     
    3535#include "gui/message.h"
    3636#include "sound/mixer.h"
    3737
     38#include <time.h>
     39
    3840OSystem *g_system = 0;
    3941
    4042OSystem::OSystem() {
     
    121123        memset(screen->pixels, 0, screen->h * screen->pitch);
    122124        unlockScreen();
    123125}
     126
     127void OSystem::getTimeAndDate(struct tm &t) const {
     128        time_t curTime = time(0);
     129        t = *localtime(&curTime);
     130}
  • backends/platform/ps2/ps2time.cpp

     
    104104}
    105105
    106106extern "C" time_t time(time_t *p) {
     107        if (p) *p = (time_t)g_timeSecs;
    107108        return (time_t)g_timeSecs;
    108109}
    109110
    110111extern "C" struct tm *localtime(const time_t *p) {
     112        // FIXME: This function should actually use the value in *p!
     113        // But the work needed for that is not necessary -- just implement
     114        // OSystem::getTimeAndDate using the code provided here, and
     115        // ditch the custom time & localtime methods.
    111116        uint32 currentSecs = g_timeSecs + (msecCount - g_lastTimeCheck) / 1000;
    112117        if (currentSecs >= SECONDS_PER_DAY) {
    113118                buildNewDate(+1);