mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-03 16:58:26 +00:00
Globals from script 0 are now initialized in script_init_engine(), and are accessed from the relevant variables pointer. Removed direct reference to script 0 from the engine state
svn-id: r49536
This commit is contained in:
parent
95b080f60b
commit
536b2614e8
@ -58,14 +58,13 @@ int script_init_engine(EngineState *s) {
|
||||
s->_msgState = new MessageState(s->_segMan);
|
||||
s->gc_countdown = GC_INTERVAL - 1;
|
||||
|
||||
SegmentId script_000_segment = s->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK);
|
||||
|
||||
if (script_000_segment <= 0) {
|
||||
// Script 0 should always be at segment 1
|
||||
if (s->_segMan->getScriptSegment(0, SCRIPT_GET_LOCK) != 1) {
|
||||
debug(2, "Failed to instantiate script.000");
|
||||
return 1;
|
||||
}
|
||||
|
||||
s->script_000 = s->_segMan->getScript(script_000_segment);
|
||||
s->initGlobals();
|
||||
|
||||
s->_segMan->initSysStrings();
|
||||
|
||||
|
@ -870,7 +870,7 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
|
||||
s->_segMan->reconstructStack(s);
|
||||
s->_segMan->reconstructScripts(s);
|
||||
s->_segMan->reconstructClones();
|
||||
s->script_000 = s->_segMan->getScript(s->_segMan->getScriptSegment(0, SCRIPT_GET_DONT_LOAD));
|
||||
s->initGlobals();
|
||||
s->gc_countdown = GC_INTERVAL - 1;
|
||||
|
||||
// Time state:
|
||||
|
@ -85,7 +85,6 @@ void EngineState::reset(bool isRestoring) {
|
||||
#endif
|
||||
|
||||
if (!isRestoring) {
|
||||
script_000 = 0;
|
||||
_gameObj = NULL_REG;
|
||||
|
||||
_memorySegmentSize = 0;
|
||||
@ -127,12 +126,23 @@ void EngineState::wait(int16 ticks) {
|
||||
g_sci->getEventManager()->sleep(ticks * 1000 / 60);
|
||||
}
|
||||
|
||||
void EngineState::initGlobals() {
|
||||
Script *script_000 = _segMan->getScript(1);
|
||||
|
||||
if (!script_000->_localsBlock)
|
||||
error("Script 0 has no locals block");
|
||||
|
||||
variables_seg[VAR_GLOBAL] = script_000->_localsSegment;
|
||||
variables_base[VAR_GLOBAL] = variables[VAR_GLOBAL] = script_000->_localsBlock->_locals.begin();
|
||||
variables_max[VAR_GLOBAL] = script_000->_localsBlock->_locals.size();
|
||||
}
|
||||
|
||||
uint16 EngineState::currentRoomNumber() const {
|
||||
return script_000->_localsBlock->_locals[13].toUint16();
|
||||
return variables[VAR_GLOBAL][13].toUint16();
|
||||
}
|
||||
|
||||
void EngineState::setRoomNumber(uint16 roomNumber) {
|
||||
script_000->_localsBlock->_locals[13] = make_reg(0, roomNumber);
|
||||
variables[VAR_GLOBAL][13] = make_reg(0, roomNumber);
|
||||
}
|
||||
|
||||
void EngineState::shrinkStackToBase() {
|
||||
|
@ -79,13 +79,6 @@ enum {
|
||||
MAX_SAVE_DIR_SIZE = MAXPATHLEN
|
||||
};
|
||||
|
||||
/** values for EngineState.restarting_flag */
|
||||
enum {
|
||||
SCI_GAME_IS_NOT_RESTARTING = 0,
|
||||
SCI_GAME_WAS_RESTARTED = 1,
|
||||
SCI_GAME_IS_RESTARTING_NOW = 2
|
||||
};
|
||||
|
||||
class FileHandle {
|
||||
public:
|
||||
Common::String _name;
|
||||
@ -145,7 +138,7 @@ public:
|
||||
bool _executionStackPosChanged; /**< Set to true if the execution stack position should be re-evaluated by the vm */
|
||||
|
||||
reg_t r_acc; /**< Accumulator */
|
||||
int16 restAdjust; /**< current &rest register (only used for save games) */
|
||||
int16 restAdjust; /**< current &rest register */
|
||||
reg_t r_prev; /**< previous comparison result */
|
||||
|
||||
StackPtr stack_base; /**< Pointer to the least stack element */
|
||||
@ -158,8 +151,6 @@ public:
|
||||
SegmentId variables_seg[4]; ///< Same as above, contains segment IDs
|
||||
int variables_max[4]; ///< Max. values for all variables
|
||||
|
||||
Script *script_000; /**< script 000, e.g. for globals */
|
||||
|
||||
int loadFromLauncher;
|
||||
|
||||
AbortGameState abortScriptProcessing;
|
||||
@ -171,6 +162,11 @@ public:
|
||||
uint16 currentRoomNumber() const;
|
||||
void setRoomNumber(uint16 roomNumber);
|
||||
|
||||
/**
|
||||
* Sets global variables from script 0
|
||||
*/
|
||||
void initGlobals();
|
||||
|
||||
/**
|
||||
* Shrink execution stack to size.
|
||||
* Contains an assert it is not already smaller.
|
||||
|
@ -736,24 +736,9 @@ void run_vm(EngineState *s, bool restoring) {
|
||||
if (!restoring)
|
||||
s->execution_stack_base = s->_executionStack.size() - 1;
|
||||
|
||||
#ifndef DISABLE_VALIDATIONS
|
||||
// Initialize maximum variable count
|
||||
if (s->script_000->_localsBlock)
|
||||
s->variables_max[VAR_GLOBAL] = s->script_000->_localsBlock->_locals.size();
|
||||
else
|
||||
s->variables_max[VAR_GLOBAL] = 0;
|
||||
#endif
|
||||
|
||||
s->variables_seg[VAR_GLOBAL] = s->script_000->_localsSegment;
|
||||
s->variables_seg[VAR_TEMP] = s->variables_seg[VAR_PARAM] = s->_segMan->findSegmentByType(SEG_TYPE_STACK);
|
||||
s->variables_base[VAR_TEMP] = s->variables_base[VAR_PARAM] = s->stack_base;
|
||||
|
||||
// SCI code reads the zeroth argument to determine argc
|
||||
if (s->script_000->_localsBlock)
|
||||
s->variables_base[VAR_GLOBAL] = s->variables[VAR_GLOBAL] = s->script_000->_localsBlock->_locals.begin();
|
||||
else
|
||||
s->variables_base[VAR_GLOBAL] = s->variables[VAR_GLOBAL] = NULL;
|
||||
|
||||
s->_executionStackPosChanged = true; // Force initialization
|
||||
|
||||
while (1) {
|
||||
|
@ -84,10 +84,8 @@ bool GfxAnimate::invoke(List *list, int argc, reg_t *argv) {
|
||||
if (!_ignoreFastCast) {
|
||||
// Check if the game has a fastCast object set
|
||||
// if we don't abort kAnimate processing, at least in kq5 there will be animation cels drawn into speech boxes.
|
||||
reg_t global84 = _s->script_000->_localsBlock->_locals[84];
|
||||
|
||||
if (!global84.isNull()) {
|
||||
if (!strcmp(_s->_segMan->getObjectName(global84), "fastCast"))
|
||||
if (!_s->variables[VAR_GLOBAL][84].isNull()) {
|
||||
if (!strcmp(_s->_segMan->getObjectName(_s->variables[VAR_GLOBAL][84]), "fastCast"))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user