Ticket #8452: scumm_info_v1.patch
File scumm_info_v1.patch, 9.8 KB (added by , 19 years ago) |
---|
-
scumm/dialogs.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/dialogs.cpp ./scummvm/scumm/dialogs.cpp
old new 271 271 GUI::ListWidget *_list; 272 272 GUI::ButtonWidget *_chooseButton; 273 273 GUI::GraphicsWidget *_gfxWidget; 274 GUI::StaticTextWidget *_date; 275 GUI::StaticTextWidget *_time; 276 GUI::StaticTextWidget *_playtime; 274 277 ScummEngine *_scumm; 275 278 276 279 public: … … 300 303 ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8); 301 304 _gfxWidget->setFlags(GUI::WIDGET_BORDER); 302 305 306 int height = 18 + ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8; 307 308 _date = new StaticTextWidget(this, 309 _w - (kThumbnailWidth + 22), 310 height, 311 kThumbnailWidth + 8, 312 kLineHeight, 313 "Date: 00.00.0000", 314 kTextAlignCenter); 315 _date->setFlags(GUI::WIDGET_CLEARBG); 316 317 height += kLineHeight; 318 319 _time = new StaticTextWidget(this, 320 _w - (kThumbnailWidth + 22), 321 height, 322 kThumbnailWidth + 8, 323 kLineHeight, 324 "Time: 00:00", 325 kTextAlignCenter); 326 _time->setFlags(GUI::WIDGET_CLEARBG); 327 328 height += kLineHeight; 329 330 _playtime = new StaticTextWidget(this, 331 _w - (kThumbnailWidth + 22), 332 height, 333 kThumbnailWidth + 8, 334 kLineHeight, 335 "Playtime: 00:00", 336 kTextAlignCenter); 337 _playtime->setFlags(GUI::WIDGET_CLEARBG); 338 303 339 // Buttons 304 340 addButton(this, _w - 2 * (kBigButtonWidth + 10), _h - kBigButtonHeight - 8, "Cancel", kCloseCmd, 0, GUI::kBigWidgetSize); 305 341 _chooseButton = addButton(this, _w - (kBigButtonWidth + 10), _h - kBigButtonHeight - 8, buttonLabel, kChooseCmd, 0, GUI::kBigWidgetSize); … … 342 378 Graphics::Surface *thumb; 343 379 thumb = _scumm->loadThumbnailFromSlot(_saveMode ? selItem + 1 : selItem); 344 380 _gfxWidget->setGfx(thumb); 381 if (thumb) 382 thumb->free(); 345 383 delete thumb; 346 384 _gfxWidget->draw(); 385 386 InfoStuff infos; 387 memset(&infos, 0, sizeof(InfoStuff)); 388 char buffer[32]; 389 if (_scumm->loadInfosFromSlot(_saveMode ? selItem + 1 : selItem, &infos)) { 390 snprintf(buffer, 32, "Date: %.2d.%.2d.%.4d", 391 (infos.date >> 24) & 0xFF, (infos.date >> 16) & 0xFF, 392 infos.date & 0xFFFF); 393 _date->setLabel(buffer); 394 _date->draw(); 395 396 snprintf(buffer, 32, "Time: %.2d:%.2d", 397 (infos.time >> 8) & 0xFF, infos.time & 0xFF); 398 _time->setLabel(buffer); 399 _time->draw(); 400 401 int minutes = infos.playtime / 60; 402 int hours = minutes / 60; 403 minutes %= 60; 404 405 snprintf(buffer, 32, "Playtime: %.2d:%.2d", 406 hours & 0xFF, minutes & 0xFF); 407 _playtime->setLabel(buffer); 408 _playtime->draw(); 409 } else { 410 snprintf(buffer, 32, "No date saved"); 411 _date->setLabel(buffer); 412 _date->draw(); 413 414 snprintf(buffer, 32, "No time saved"); 415 _time->setLabel(buffer); 416 _time->draw(); 417 418 snprintf(buffer, 32, "No playtime saved"); 419 _playtime->setLabel(buffer); 420 _playtime->draw(); 421 } 347 422 348 423 if (_saveMode) { 349 424 _list->startEditMode(); -
scumm/saveload.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/saveload.cpp ./scummvm/scumm/saveload.cpp
old new 51 51 char name[32]; 52 52 }; 53 53 54 struct SaveInfoHeader { 55 uint32 type; 56 uint32 size; 57 byte version; 58 59 uint32 date; 60 uint16 time; 61 uint32 playtime; 62 }; 63 64 #define INFOHEADER_VERSION 1 54 65 55 66 void ScummEngine::requestSave(int slot, const char *name, bool temporary) { 56 67 _saveLoadSlot = slot; … … 84 95 85 96 out->write(&hdr, sizeof(hdr)); 86 97 saveThumbnail(out); 98 saveInfos(out); 87 99 88 100 Serializer ser(0, out, CURRENT_VER); 89 101 saveOrLoad(&ser, CURRENT_VER); … … 111 123 } 112 124 113 125 // In older versions of ScummVM, the header version was not endian safe. 114 // We account for that by retrying once wi th swapped byte order.126 // We account for that by retrying once wi_system->getMillis() / 1000th swapped byte order. 115 127 if (hdr.ver > CURRENT_VER) 116 128 hdr.ver = SWAP_BYTES_32(hdr.ver); 117 129 if (hdr.ver < VER(7) || hdr.ver > CURRENT_VER) … … 144 156 in->skip(size - 8); 145 157 } 146 158 159 // Since version 56 we have informations about the creating of the save game and the save time here 160 if (hdr.ver >= VER(56)) { 161 InfoStuff infos; 162 if (!loadInfos(in, &infos)) { 163 delete in; 164 return false; 165 } 166 167 _engineStartTime = _system->getMillis() / 1000 - infos.playtime; 168 } else { 169 // start time counting 170 _engineStartTime = _system->getMillis() / 1000; 171 } 172 173 _dialogStartTime = _system->getMillis() / 1000; 174 147 175 // Due to a bug in scummvm up to and including 0.3.0, save games could be saved 148 176 // in the V8/V9 format but were tagged with a V7 mark. Ouch. So we just pretend V7 == V8 here 149 177 if (hdr.ver == VER(7)) … … 438 466 439 467 delete in; 440 468 return thumb; 469 } 470 471 bool ScummEngine::loadInfosFromSlot(int slot, InfoStuff *stuff) { 472 char filename[256]; 473 Common::InSaveFile *in; 474 SaveGameHeader hdr; 475 int len; 476 477 makeSavegameName(filename, slot, false); 478 if (!(in = _saveFileMan->openForLoading(filename))) { 479 return false; 480 } 481 len = in->read(&hdr, sizeof(hdr)); 482 483 if (len != sizeof(hdr) || hdr.type != MKID('SCVM')) { 484 delete in; 485 return false; 486 } 487 488 if (hdr.ver > CURRENT_VER) 489 hdr.ver = TO_LE_32(hdr.ver); 490 if (hdr.ver < VER(56)) { 491 delete in; 492 return false; 493 } 494 495 uint32 type; 496 in->read(&type, 4); 497 498 // Check for the THMB header. Also, work around a bug which caused 499 // the chunk type (incorrectly) to be written in LE on LE machines. 500 if (! (type == MKID('THMB') || (hdr.ver < VER(55) && type == MKID('BMHT')))){ 501 delete in; 502 return false; 503 } 504 uint32 size = in->readUint32BE(); 505 in->skip(size - 8); 506 507 if (!loadInfos(in, stuff)) { 508 delete in; 509 return false; 510 } 511 512 delete in; 513 return true; 514 } 515 516 bool ScummEngine::loadInfos(Common::InSaveFile *file, InfoStuff *stuff) { 517 SaveInfoHeader header; 518 file->read(&header.type, 4); 519 if (header.type != MKID('INFO')) { 520 warning("Couldn't load info section"); 521 return false; 522 } 523 524 header.version = file->readByte(); 525 if (header.version > INFOHEADER_VERSION) { 526 warning("Infoheader version is too high"); 527 return false; 528 } 529 530 header.size = file->readUint32BE(); 531 532 header.date = file->readUint32BE(); 533 header.time = file->readUint16BE(); 534 header.playtime = file->readUint32BE(); 535 536 stuff->date = header.date; 537 stuff->time = header.time; 538 stuff->playtime = header.playtime; 539 540 return true; 541 } 542 543 void ScummEngine::saveInfos(Common::OutSaveFile* file) { 544 SaveInfoHeader header; 545 header.type = MKID('INFO'); 546 header.version = INFOHEADER_VERSION; 547 header.size = sizeof(SaveInfoHeader); 548 549 time_t curTime_ = time(0); 550 tm *curTime = localtime(&curTime_); 551 header.date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF; 552 header.time = (curTime->tm_hour & 0xFF) << 8 | curTime->tm_min & 0xFF; 553 header.playtime = _system->getMillis() / 1000 - _engineStartTime; 554 555 file->write(&header.type, 4); 556 file->writeByte(header.version); 557 file->writeUint32BE(header.size); 558 file->writeUint32BE(header.date); 559 file->writeUint16BE(header.time); 560 file->writeUint32BE(header.playtime); 441 561 } 442 562 443 563 void ScummEngine::saveOrLoad(Serializer *s, uint32 savegameVersion) { -
scumm/saveload.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/saveload.h ./scummvm/scumm/saveload.h
old new 45 45 * only saves/loads those which are valid for the version of the savegame 46 46 * which is being loaded/saved currently. 47 47 */ 48 #define CURRENT_VER 5 548 #define CURRENT_VER 56 49 49 50 50 /** 51 51 * An auxillary macro, used to specify savegame versions. We use this instead -
scumm/scumm.cpp
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/scumm.cpp ./scummvm/scumm/scumm.cpp
old new 2012 2012 #pragma mark - 2013 2013 2014 2014 int ScummEngine::go() { 2015 _engineStartTime = _system->getMillis() / 1000; 2016 2015 2017 // If requested, load a save game instead of running the boot script 2016 2018 if (_saveLoadFlag != 2 || !loadState(_saveLoadSlot, _saveTemporaryState)) { 2017 2019 int args[16]; … … 2448 2450 #pragma mark - 2449 2451 2450 2452 int ScummEngine::runDialog(Dialog &dialog) { 2453 _dialogStartTime = _system->getMillis() / 1000; 2454 2451 2455 // Pause sound & video 2452 2456 bool old_soundsPaused = _sound->_soundsPaused; 2453 2457 _sound->pauseSounds(true); … … 2463 2467 // Resume sound & video 2464 2468 _sound->pauseSounds(old_soundsPaused); 2465 2469 _smushPaused = oldSmushPaused; 2470 2471 _engineStartTime += (_system->getMillis() / 1000) - _dialogStartTime; 2472 _dialogStartTime = 0; 2466 2473 2467 2474 // Return the result 2468 2475 return result; -
scumm/scumm.h
diff --exclude=.cvsignore --exclude=.deps --exclude=CVS -Pur ./scummvm.cvs/scumm/scumm.h ./scummvm/scumm/scumm.h
old new 309 309 int subIndex; 310 310 }; 311 311 312 struct InfoStuff { 313 uint32 date; 314 uint16 time; 315 uint32 playtime; 316 }; 317 312 318 class ResourceManager { 313 319 friend class ScummDebugger; 314 320 friend class ScummEngine; … … 582 588 void requestSave(int slot, const char *name, bool temporary = false); 583 589 void requestLoad(int slot); 584 590 585 // thumbnail stuff591 // thumbnail + info stuff 586 592 public: 587 593 Graphics::Surface *loadThumbnailFromSlot(int slot); 594 bool loadInfosFromSlot(int slot, InfoStuff *stuff); 588 595 589 596 protected: 590 597 Graphics::Surface *loadThumbnail(Common::InSaveFile *file); 598 bool loadInfos(Common::InSaveFile *file, InfoStuff *stuff); 591 599 void saveThumbnail(Common::OutSaveFile *file); 600 void saveInfos(Common::OutSaveFile* file); 601 602 int32 _engineStartTime; 603 int32 _dialogStartTime; 592 604 593 605 protected: 594 606 /* Script VM - should be in Script class */