Ticket #8758: scriptvars.patch
File scriptvars.patch, 7.6 KB (added by , 16 years ago) |
---|
-
engines/cine/script.h
26 26 #ifndef CINE_SCRIPT_H 27 27 #define CINE_SCRIPT_H 28 28 29 #include "common/savefile.h" 30 29 31 namespace Cine { 30 32 31 33 #define SCRIPT_STACK_SIZE 50 32 34 35 class ScriptVars { 36 private: 37 unsigned int _size; 38 int16 *_vars; 39 40 public: 41 explicit ScriptVars(unsigned int len = 50); 42 ScriptVars(Common::InSaveFile &fHandle, unsigned int len = 50); 43 ScriptVars(const ScriptVars &src); 44 ~ScriptVars(void); 45 46 ScriptVars &operator=(const ScriptVars &src); 47 int16 &operator[](unsigned int idx); 48 int16 operator[](unsigned int idx) const; 49 50 void save(Common::OutSaveFile &fHandle); 51 void save(Common::OutSaveFile &fHandle, unsigned int len); 52 void load(Common::InSaveFile &fHandle); 53 void load(Common::InSaveFile &fHandle, unsigned int len); 54 void reset(void); 55 }; 56 33 57 struct scriptStruct { 34 58 byte *ptr; 35 59 uint16 size; -
engines/cine/object.h
26 26 #ifndef CINE_OBJECT_H 27 27 #define CINE_OBJECT_H 28 28 29 #include "script.h" 30 29 31 namespace Cine { 30 32 31 33 struct objectStruct { … … 53 55 #define NUM_MAX_VAR 256 54 56 55 57 extern objectStruct objectTable[NUM_MAX_OBJECT]; 56 extern uint16 globalVars[NUM_MAX_VAR];58 extern ScriptVars globalVars; 57 59 58 60 extern overlayHeadElement overlayHead; 59 61 -
engines/cine/various.cpp
171 171 pNewElement->stack[i] = 0; 172 172 } 173 173 174 for (i = 0; i < 50; i++) {175 pNewElement->localVars[i] = 0;176 }177 178 174 pNewElement->compareResult = 0; 179 175 pNewElement->scriptPosition = 0; 180 176 … … 329 325 for (i = 0; i < SCRIPT_STACK_SIZE; i++) 330 326 newElement->stack[i] = fHandle->readUint16BE(); 331 327 332 for (i = 0; i < 50; i++) 333 newElement->localVars[i] = fHandle->readUint16BE(); 328 newElement->localVars.load(*fHandle); 334 329 335 330 newElement->compareResult = fHandle->readUint16BE(); 336 331 newElement->scriptPosition = fHandle->readUint16BE(); … … 455 450 objectTable[i].costume = 0; 456 451 } 457 452 458 for (i = 0; i < 255; i++) { 459 globalVars[i] = 0; 460 } 453 globalVars.reset(); 461 454 462 455 var2 = var3 = var4 = var5 = 0; 463 456 … … 520 513 tempPalette[i] = fHandle->readUint16BE(); 521 514 } 522 515 523 for (i = 0; i < 255; i++) { 524 globalVars[i] = fHandle->readUint16BE(); 525 } 516 globalVars.load(*fHandle, NUM_MAX_VAR - 1); 526 517 527 518 for (i = 0; i < 16; i++) { 528 519 zoneData[i] = fHandle->readUint16BE(); … … 683 674 fHandle->writeUint16BE(tempPalette[i]); 684 675 } 685 676 686 for (i = 0; i < 255; i++) { 687 fHandle->writeUint16BE(globalVars[i]); 688 } 677 globalVars.save(*fHandle, NUM_MAX_VAR - 1); 689 678 690 679 for (i = 0; i < 16; i++) { 691 680 fHandle->writeUint16BE(zoneData[i]); … … 757 746 fHandle->writeUint16BE(currentHead->stack[i]); 758 747 } 759 748 760 for (i = 0; i < 50; i++) { 761 fHandle->writeUint16BE(currentHead->localVars[i]); 762 } 749 currentHead->localVars.save(*fHandle); 763 750 764 751 fHandle->writeUint16BE(currentHead->compareResult); 765 752 fHandle->writeUint16BE(currentHead->scriptPosition); … … 788 775 fHandle->writeUint16BE(currentHead->stack[i]); 789 776 } 790 777 791 for (i = 0; i < 50; i++) { 792 fHandle->writeUint16BE(currentHead->localVars[i]); 793 } 778 currentHead->localVars.save(*fHandle); 794 779 795 780 fHandle->writeUint16BE(currentHead->compareResult); 796 781 fHandle->writeUint16BE(currentHead->scriptPosition); -
engines/cine/prc.h
31 31 struct prcLinkedListStruct { 32 32 struct prcLinkedListStruct *next; 33 33 int16 stack[SCRIPT_STACK_SIZE]; 34 int16 localVars[50];34 ScriptVars localVars; 35 35 uint16 compareResult; 36 36 uint16 scriptPosition; 37 37 byte *scriptPtr; -
engines/cine/script.cpp
453 453 return val; 454 454 } 455 455 456 // empty array 457 ScriptVars::ScriptVars(unsigned int len) : _size(len), _vars(new int16[len]) { 458 assert(_vars); 459 reset(); 460 } 461 462 // read game save, for later use 463 ScriptVars::ScriptVars(Common::InSaveFile &fHandle, unsigned int len) 464 : _size(len), _vars(new int16[len]) { 465 466 assert(_vars); 467 468 load(fHandle); 469 } 470 471 // copy constructor 472 ScriptVars::ScriptVars(const ScriptVars &src) : _size(src._size), _vars(new int16[_size]) { 473 assert(_vars); 474 memcpy(_vars, src._vars, _size * sizeof(int16)); 475 } 476 477 ScriptVars::~ScriptVars(void) { 478 delete[] _vars; 479 } 480 481 ScriptVars &ScriptVars::operator=(const ScriptVars &src) { 482 ScriptVars tmp(src); 483 int16 *tmpvars = _vars; 484 485 _vars = tmp._vars; 486 tmp._vars = tmpvars; 487 _size = src._size; 488 489 return *this; 490 } 491 492 // array access 493 int16 &ScriptVars::operator[](unsigned int idx) { 494 debugN(5, "assert(%d < %d)", idx, _size); 495 assert(idx < _size); 496 return _vars[idx]; 497 } 498 499 int16 ScriptVars::operator[](unsigned int idx) const { 500 debugN(5, "assert(%d < %d)\n", idx, _size); 501 assert(idx < _size); 502 return _vars[idx]; 503 } 504 505 // dump to savefile 506 void ScriptVars::save(Common::OutSaveFile &fHandle) { 507 save(fHandle, _size); 508 } 509 510 // globalVars[255] is not written to savefiles... 511 void ScriptVars::save(Common::OutSaveFile &fHandle, unsigned int len) { 512 debugN(5, "assert(%d <= %d)\n", len, _size); 513 assert(len <= _size); 514 for (unsigned int i = 0; i < len; i++) { 515 fHandle.writeUint16BE(_vars[i]); 516 } 517 } 518 519 // read from savefile 520 void ScriptVars::load(Common::InSaveFile &fHandle) { 521 load(fHandle, _size); 522 } 523 524 void ScriptVars::load(Common::InSaveFile &fHandle, unsigned int len) { 525 debugN(5, "assert(%d <= %d)\n", len, _size); 526 assert(len <= _size); 527 for (unsigned int i = 0; i < len; i++) { 528 _vars[i] = fHandle.readUint16BE(); 529 } 530 } 531 532 void ScriptVars::reset(void) { 533 memset( _vars, 0, _size * sizeof(int16)); 534 } 535 456 536 void addGfxElementA0(int16 param1, int16 param2) { 457 537 overlayHeadElement *currentHead = &overlayHead; 458 538 overlayHeadElement *tempHead = currentHead; … … 661 741 pNewElement->stack[i] = scriptTable[idx].stack[i]; 662 742 } 663 743 664 for (i = 0; i < 50; i++) {665 pNewElement->localVars[i] = 0;666 }667 668 744 pNewElement->compareResult = 0; 669 745 pNewElement->scriptPosition = 0; 670 746 -
engines/cine/object.cpp
36 36 namespace Cine { 37 37 38 38 objectStruct objectTable[NUM_MAX_OBJECT]; 39 uint16 globalVars[NUM_MAX_VAR];39 ScriptVars globalVars(NUM_MAX_VAR); 40 40 overlayHeadElement overlayHead; 41 41 42 42 void unloadAllMasks(void) { … … 45 45 while (current) { 46 46 overlayHeadElement *next = current->next; 47 47 48 free(current);48 delete current; 49 49 50 50 current = next; 51 51 } … … 124 124 125 125 tempPtr2->previous = currentHeadPtr->previous; 126 126 127 free(currentHeadPtr);127 delete currentHeadPtr; 128 128 129 129 return 0; 130 130 } … … 151 151 152 152 tempPtr2->previous = currentHeadPtr->previous; 153 153 154 free(currentHeadPtr);154 delete currentHeadPtr; 155 155 return 0; 156 156 } 157 157 -
engines/cine/cine.cpp
136 136 objectTable[i].name[0] = 0; 137 137 } 138 138 139 for (i = 0; i < NUM_MAX_VAR; i++) {140 globalVars[i] = 0;141 }142 143 139 for (i = 0; i < NUM_MAX_SCRIPT; i++) { 144 140 scriptTable[i].ptr = NULL; 145 141 scriptTable[i].size = 0;