Ticket #8452: scumm_info_v6.patch
File scumm_info_v6.patch, 10.4 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 "No date saved", 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 "No time saved", 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 "No playtime saved", 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 #if !defined(__GNUC__) 55 #pragma START_PACK_STRUCTS 56 #endif 57 58 struct SaveInfoSection { 59 uint32 type; 60 uint32 version; 61 uint32 size; 62 63 // this should be better a uint64, but 64 // we do not have a type for it... 65 uint32 timeTValue; 66 uint32 playtime; 67 } GCC_PACK; 68 69 #if !defined(__GNUC__) 70 #pragma END_PACK_STRUCTS 71 #endif 72 73 #define INFOSECTION_VERSION 1 54 74 55 75 void ScummEngine::requestSave(int slot, const char *name, bool temporary) { 56 76 _saveLoadSlot = slot; … … 84 104 85 105 out->write(&hdr, sizeof(hdr)); 86 106 saveThumbnail(out); 107 saveInfos(out); 87 108 88 109 Serializer ser(0, out, CURRENT_VER); 89 110 saveOrLoad(&ser, CURRENT_VER); … … 144 165 in->skip(size - 8); 145 166 } 146 167 168 // Since version 56 we have informations about the creation of the save game and the save time here 169 if (hdr.ver >= VER(56)) { 170 InfoStuff infos; 171 if (!loadInfos(in, &infos)) { 172 warning("Info section could not be found"); 173 delete in; 174 return false; 175 } 176 177 _engineStartTime = _system->getMillis() / 1000 - infos.playtime; 178 } else { 179 // start time counting 180 _engineStartTime = _system->getMillis() / 1000; 181 } 182 183 _dialogStartTime = _system->getMillis() / 1000; 184 147 185 // Due to a bug in scummvm up to and including 0.3.0, save games could be saved 148 186 // in the V8/V9 format but were tagged with a V7 mark. Ouch. So we just pretend V7 == V8 here 149 187 if (hdr.ver == VER(7)) … … 359 397 360 398 _sound->pauseSounds(false); 361 399 400 _engineStartTime += _system->getMillis() / 1000 - _dialogStartTime; 401 _dialogStartTime = 0; 402 362 403 return true; 363 404 } 364 405 … … 438 479 439 480 delete in; 440 481 return thumb; 482 } 483 484 bool ScummEngine::loadInfosFromSlot(int slot, InfoStuff *stuff) { 485 char filename[256]; 486 Common::InSaveFile *in; 487 SaveGameHeader hdr; 488 int len; 489 490 makeSavegameName(filename, slot, false); 491 if (!(in = _saveFileMan->openForLoading(filename))) { 492 return false; 493 } 494 len = in->read(&hdr, sizeof(hdr)); 495 496 if (len != sizeof(hdr) || hdr.type != MKID('SCVM')) { 497 delete in; 498 return false; 499 } 500 501 if (hdr.ver > CURRENT_VER) 502 hdr.ver = TO_LE_32(hdr.ver); 503 if (hdr.ver < VER(56)) { 504 delete in; 505 return false; 506 } 507 508 uint32 type; 509 in->read(&type, 4); 510 511 // Check for the THMB header. Also, work around a bug which caused 512 // the chunk type (incorrectly) to be written in LE on LE machines. 513 if (! (type == MKID('THMB') || (hdr.ver < VER(55) && type == MKID('BMHT')))){ 514 delete in; 515 return false; 516 } 517 uint32 size = in->readUint32BE(); 518 in->skip(size - 8); 519 520 if (!loadInfos(in, stuff)) { 521 delete in; 522 return false; 523 } 524 525 delete in; 526 return true; 527 } 528 529 bool ScummEngine::loadInfos(Common::InSaveFile *file, InfoStuff *stuff) { 530 memset(stuff, 0, sizeof(InfoStuff)); 531 532 SaveInfoSection section; 533 file->read(§ion.type, 4); 534 if (section.type != MKID('INFO')) { 535 return false; 536 } 537 538 section.version = file->readUint32BE(); 539 section.size = file->readUint32BE(); 540 541 section.timeTValue = file->readUint32BE(); 542 section.playtime = file->readUint32BE(); 543 544 time_t curTime_ = section.timeTValue; 545 tm *curTime = localtime(&curTime_); 546 stuff->date = (curTime->tm_mday & 0xFF) << 24 | ((curTime->tm_mon + 1) & 0xFF) << 16 | (curTime->tm_year + 1900) & 0xFFFF; 547 stuff->time = (curTime->tm_hour & 0xFF) << 8 | (curTime->tm_min) & 0xFF; 548 stuff->playtime = section.playtime; 549 550 // if we extend the header we should check here for the version 551 // e.g.: 552 // if (header.version == 2) { 553 // // load some things here 554 // } 555 // 556 // if (header.version == 3) { 557 // // ... 558 // } 559 // and so on... 560 561 // skip all newer features 562 if (section.version > INFOSECTION_VERSION) { 563 file->skip(section.size - sizeof(SaveInfoSection)); 564 } 565 566 return true; 567 } 568 569 void ScummEngine::saveInfos(Common::OutSaveFile* file) { 570 SaveInfoSection section; 571 section.type = MKID('INFO'); 572 section.version = INFOSECTION_VERSION; 573 section.size = sizeof(SaveInfoSection); 574 575 section.timeTValue = time(0); 576 section.playtime = _system->getMillis() / 1000 - _engineStartTime; 577 578 file->write(§ion.type, 4); 579 file->writeUint32BE(section.version); 580 file->writeUint32BE(section.size); 581 file->writeUint32BE(section.timeTValue); 582 file->writeUint32BE(section.playtime); 441 583 } 442 584 443 585 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 */