Ticket #8452: scumm_info_v5.patch
File scumm_info_v5.patch, 10.3 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 21 21 #include "common/stdafx.h" 22 22 23 23 #include "common/config-manager.h" 24 #include "common/savefile.h" 24 25 #include "common/system.h" 25 26 #include "common/scaler.h" 26 27 … … 193 194 194 195 #pragma mark - 195 196 197 Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode); 198 196 199 enum { 197 200 kSaveCmd = 'SAVE', 198 201 kLoadCmd = 'LOAD', … … 271 274 GUI::ListWidget *_list; 272 275 GUI::ButtonWidget *_chooseButton; 273 276 GUI::GraphicsWidget *_gfxWidget; 277 GUI::StaticTextWidget *_date; 278 GUI::StaticTextWidget *_time; 279 GUI::StaticTextWidget *_playtime; 274 280 ScummEngine *_scumm; 275 281 276 282 public: … … 300 306 ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8); 301 307 _gfxWidget->setFlags(GUI::WIDGET_BORDER); 302 308 309 int height = 18 + ((_scumm->_system->getHeight() % 200 && _scumm->_system->getHeight() != 350) ? kThumbnailHeight2 : kThumbnailHeight1) + 8; 310 311 _date = new StaticTextWidget(this, 312 _w - (kThumbnailWidth + 22), 313 height, 314 kThumbnailWidth + 8, 315 kLineHeight, 316 "Date: 00.00.0000", 317 kTextAlignCenter); 318 _date->setFlags(GUI::WIDGET_CLEARBG); 319 320 height += kLineHeight; 321 322 _time = new StaticTextWidget(this, 323 _w - (kThumbnailWidth + 22), 324 height, 325 kThumbnailWidth + 8, 326 kLineHeight, 327 "Time: 00:00", 328 kTextAlignCenter); 329 _time->setFlags(GUI::WIDGET_CLEARBG); 330 331 height += kLineHeight; 332 333 _playtime = new StaticTextWidget(this, 334 _w - (kThumbnailWidth + 22), 335 height, 336 kThumbnailWidth + 8, 337 kLineHeight, 338 "Playtime: 00:00", 339 kTextAlignCenter); 340 _playtime->setFlags(GUI::WIDGET_CLEARBG); 341 303 342 // Buttons 304 343 addButton(this, _w - 2 * (kBigButtonWidth + 10), _h - kBigButtonHeight - 8, "Cancel", kCloseCmd, 0, GUI::kBigWidgetSize); 305 344 _chooseButton = addButton(this, _w - (kBigButtonWidth + 10), _h - kBigButtonHeight - 8, buttonLabel, kChooseCmd, 0, GUI::kBigWidgetSize); … … 342 381 Graphics::Surface *thumb; 343 382 thumb = _scumm->loadThumbnailFromSlot(_saveMode ? selItem + 1 : selItem); 344 383 _gfxWidget->setGfx(thumb); 384 if (thumb) 385 thumb->free(); 345 386 delete thumb; 346 387 _gfxWidget->draw(); 388 389 InfoStuff infos; 390 memset(&infos, 0, sizeof(InfoStuff)); 391 char buffer[32]; 392 if (_scumm->loadInfosFromSlot(_saveMode ? selItem + 1 : selItem, &infos)) { 393 snprintf(buffer, 32, "Date: %.2d.%.2d.%.4d", 394 (infos.date >> 24) & 0xFF, (infos.date >> 16) & 0xFF, 395 infos.date & 0xFFFF); 396 _date->setLabel(buffer); 397 _date->draw(); 398 399 snprintf(buffer, 32, "Time: %.2d:%.2d", 400 (infos.time >> 8) & 0xFF, infos.time & 0xFF); 401 _time->setLabel(buffer); 402 _time->draw(); 403 404 int minutes = infos.playtime / 60; 405 int hours = minutes / 60; 406 minutes %= 60; 407 408 snprintf(buffer, 32, "Playtime: %.2d:%.2d", 409 hours & 0xFF, minutes & 0xFF); 410 _playtime->setLabel(buffer); 411 _playtime->draw(); 412 } else { 413 snprintf(buffer, 32, "No date saved"); 414 _date->setLabel(buffer); 415 _date->draw(); 416 417 snprintf(buffer, 32, "No time saved"); 418 _time->setLabel(buffer); 419 _time->draw(); 420 421 snprintf(buffer, 32, "No playtime saved"); 422 _playtime->setLabel(buffer); 423 _playtime->draw(); 424 } 347 425 348 426 if (_saveMode) { 349 427 _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)) … … 359 387 360 388 _sound->pauseSounds(false); 361 389 390 _engineStartTime += _system->getMillis() / 1000 - _dialogStartTime; 391 _dialogStartTime = 0; 392 362 393 return true; 363 394 } 364 395 … … 438 469 439 470 delete in; 440 471 return thumb; 472 } 473 474 bool ScummEngine::loadInfosFromSlot(int slot, InfoStuff *stuff) { 475 char filename[256]; 476 Common::InSaveFile *in; 477 SaveGameHeader hdr; 478 int len; 479 480 makeSavegameName(filename, slot, false); 481 if (!(in = _saveFileMan->openForLoading(filename))) { 482 return false; 483 } 484 len = in->read(&hdr, sizeof(hdr)); 485 486 if (len != sizeof(hdr) || hdr.type != MKID('SCVM')) { 487 delete in; 488 return false; 489 } 490 491 if (hdr.ver > CURRENT_VER) 492 hdr.ver = TO_LE_32(hdr.ver); 493 if (hdr.ver < VER(56)) { 494 delete in; 495 return false; 496 } 497 498 uint32 type; 499 in->read(&type, 4); 500 501 // Check for the THMB header. Also, work around a bug which caused 502 // the chunk type (incorrectly) to be written in LE on LE machines. 503 if (! (type == MKID('THMB') || (hdr.ver < VER(55) && type == MKID('BMHT')))){ 504 delete in; 505 return false; 506 } 507 uint32 size = in->readUint32BE(); 508 in->skip(size - 8); 509 510 if (!loadInfos(in, stuff)) { 511 delete in; 512 return false; 513 } 514 515 delete in; 516 return true; 517 } 518 519 bool ScummEngine::loadInfos(Common::InSaveFile *file, InfoStuff *stuff) { 520 SaveInfoHeader header; 521 file->read(&header.type, 4); 522 if (header.type != MKID('INFO')) { 523 warning("Couldn't load info section"); 524 return false; 525 } 526 527 header.version = file->readByte(); 528 if (header.version > INFOHEADER_VERSION) { 529 warning("Infoheader version is too high"); 530 return false; 531 } 532 533 header.size = file->readUint32BE(); 534 535 header.date = file->readUint32BE(); 536 header.time = file->readUint16BE(); 537 header.playtime = file->readUint32BE(); 538 539 stuff->date = header.date; 540 stuff->time = header.time; 541 stuff->playtime = header.playtime; 542 543 return true; 544 } 545 546 void ScummEngine::saveInfos(Common::OutSaveFile* file) { 547 SaveInfoHeader header; 548 header.type = MKID('INFO'); 549 header.version = INFOHEADER_VERSION; 550 header.size = sizeof(SaveInfoHeader); 551 552 time_t curTime_ = time(0); 553 tm *curTime = localtime(&curTime_); 554 header.date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF; 555 header.time = (curTime->tm_hour & 0xFF) << 8 | curTime->tm_min & 0xFF; 556 header.playtime = _system->getMillis() / 1000 - _engineStartTime; 557 558 file->write(&header.type, 4); 559 file->writeByte(header.version); 560 file->writeUint32BE(header.size); 561 file->writeUint32BE(header.date); 562 file->writeUint16BE(header.time); 563 file->writeUint32BE(header.playtime); 441 564 } 442 565 443 566 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 2112 2112 #pragma mark - 2113 2113 2114 2114 int ScummEngine::go() { 2115 _engineStartTime = _system->getMillis() / 1000; 2116 2115 2117 // If requested, load a save game instead of running the boot script 2116 2118 if (_saveLoadFlag != 2 || !loadState(_saveLoadSlot, _saveTemporaryState)) { 2117 2119 int args[16]; … … 2548 2550 #pragma mark - 2549 2551 2550 2552 int ScummEngine::runDialog(Dialog &dialog) { 2553 _dialogStartTime = _system->getMillis() / 1000; 2554 2551 2555 // Pause sound & video 2552 2556 bool old_soundsPaused = _sound->_soundsPaused; 2553 2557 _sound->pauseSounds(true); … … 2563 2567 // Resume sound & video 2564 2568 _sound->pauseSounds(old_soundsPaused); 2565 2569 _smushPaused = oldSmushPaused; 2570 2571 _engineStartTime += (_system->getMillis() / 1000) - _dialogStartTime; 2572 _dialogStartTime = 0; 2566 2573 2567 2574 // Return the result 2568 2575 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; … … 583 589 void requestSave(int slot, const char *name, bool temporary = false); 584 590 void requestLoad(int slot); 585 591 586 // thumbnail stuff592 // thumbnail + info stuff 587 593 public: 588 594 Graphics::Surface *loadThumbnailFromSlot(int slot); 595 bool loadInfosFromSlot(int slot, InfoStuff *stuff); 589 596 590 597 protected: 591 598 Graphics::Surface *loadThumbnail(Common::InSaveFile *file); 599 bool loadInfos(Common::InSaveFile *file, InfoStuff *stuff); 592 600 void saveThumbnail(Common::OutSaveFile *file); 601 void saveInfos(Common::OutSaveFile* file); 602 603 int32 _engineStartTime; 604 int32 _dialogStartTime; 593 605 594 606 protected: 595 607 /* Script VM - should be in Script class */