Ticket #8452: scumm_info_v2.patch
File scumm_info_v2.patch, 10.0 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)) … … 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 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 */