Example #1
0
void finishFunction (loadedFunction * fun) {
	int a;

	pauseFunction (fun);
	if (fun -> stack) fatal (ERROR_NON_EMPTY_STACK);
	delete fun -> compiledLines;
	for (a = 0; a < fun -> numLocals; a ++) unlinkVar (fun -> localVars[a]);
	delete fun -> localVars;
	unlinkVar (fun -> reg);
	delete fun;
	fun = NULL;
}
Example #2
0
void abortFunction (loadedFunction * fun) {
	int a;

	pauseFunction (fun);
	while (fun -> stack) trimStack (fun -> stack);
	delete fun -> compiledLines;
	for (a = 0; a < fun -> numLocals; a ++) unlinkVar (fun -> localVars[a]);
	delete fun -> localVars;
	unlinkVar (fun -> reg);
	if (fun -> calledBy) abortFunction (fun -> calledBy);
	delete fun;
	fun = NULL;
}
Example #3
0
void trimStack (variableStack * & stack) {
	variableStack * killMe = stack;
	stack = stack -> next;

	// When calling this, we've ALWAYS checked that stack != NULL
	unlinkVar (killMe -> thisVar);
	delete killMe;
}
Example #4
0
void trimStack(VariableStack *&stack) {
	VariableStack *killMe = stack;
	stack = stack->next;

	//debugC(2, kSludgeDebugStackMachine, "Variable %s was removed from stack", getTextFromAnyVar(killMe->thisVar));

	// When calling this, we've ALWAYS checked that stack != NULL
	unlinkVar(killMe->thisVar);
	delete killMe;
}
Example #5
0
void addVariablesInSecond(Variable &var1, Variable &var2) {
	if (var1.varType == SVT_INT && var2.varType == SVT_INT) {
		var2.varData.intValue += var1.varData.intValue;
	} else {
		Common::String string1 = getTextFromAnyVar(var1);
		Common::String string2 = getTextFromAnyVar(var2);

		unlinkVar(var2);
		var2.varData.theString = createCString(string1 + string2);
		var2.varType = SVT_STRING;
	}
}
Example #6
0
void addVariablesInSecond (variable & var1, variable & var2) {
	if (var1.varType == SVT_INT && var2.varType == SVT_INT) {
		var2.varData.intValue += var1.varData.intValue;
	} else {
		char * string1 = getTextFromAnyVar (var1);
		char * string2 = getTextFromAnyVar (var2);

		unlinkVar (var2);
		var2.varData.theString = joinStrings (string1, string2);
		var2.varType = SVT_STRING;
		delete[] string1;
		delete[] string2;
	}
}
Example #7
0
bool makeFastArraySize (variable & to, int size) {
	if (size < 0) return fatal ("Can't create a fast array with a negative number of elements!");
	unlinkVar (to);
	to.varType = SVT_FASTARRAY;
	to.varData.fastArray = new fastArrayHandler;
	if (! checkNew (to.varData.fastArray)) return false;
	to.varData.fastArray -> fastVariables = new variable[size];
	if (! checkNew (to.varData.fastArray -> fastVariables)) return false;
	for (int i = 0; i < size; i ++) {
		initVarNew (to.varData.fastArray -> fastVariables[i]);
	}
	to.varData.fastArray -> size = size;
	to.varData.fastArray -> timesUsed = 1;
	return true;
}
Example #8
0
int deleteVarFromStack (const variable & va, variableStack * & thisStack, bool allOfEm) {
	variableStack * * huntVar = & thisStack;
	variableStack * killMe;
	int reply = 0;

	while (* huntVar) {
		if (compareVars ((* huntVar) -> thisVar, va)) {
			killMe = * huntVar;
			* huntVar = killMe -> next;
			unlinkVar (killMe -> thisVar);
			delete killMe;
			if (! allOfEm) return 1;
			reply ++;
		} else {
			huntVar = & ((* huntVar) -> next);
		}
	}

	return reply;
}
Example #9
0
void newCostumeVariable (variable & thisVar, persona * i) {
	unlinkVar (thisVar);
	thisVar.varType = SVT_COSTUME;
	thisVar.varData.costumeHandler = i;
}
Example #10
0
void newAnimationVariable (variable & thisVar, personaAnimation * i) {
	unlinkVar (thisVar);
	thisVar.varType = SVT_ANIM;
	thisVar.varData.animHandler = i;
}
Example #11
0
void setVariable (variable & thisVar, variableType vT, int value) {
	unlinkVar (thisVar);
	thisVar.varType = vT;
	thisVar.varData.intValue = value;
}
Example #12
0
bool copyVariable (const variable & from, variable & to) {
	unlinkVar (to);
	return copyMain (from, to);
}
Example #13
0
void makeTextVar (variable & thisVar, const char * txt) {
	unlinkVar (thisVar);
	thisVar.varType = SVT_STRING;
	thisVar.varData.theString = copyString (txt);
}
Example #14
0
bool loadGame(const Common::String &fname) {
	Common::InSaveFile *fp = g_system->getSavefileManager()->openForLoading(fname);
	FILETIME savedGameTime;

	while (allRunningFunctions)
		finishFunction(allRunningFunctions);

	if (fp == NULL)
		return false;

	bool headerBad = false;
	if (fp->readByte() != 'S')
		headerBad = true;
	if (fp->readByte() != 'L')
		headerBad = true;
	if (fp->readByte() != 'U')
		headerBad = true;
	if (fp->readByte() != 'D')
		headerBad = true;
	if (fp->readByte() != 'S')
		headerBad = true;
	if (fp->readByte() != 'A')
		headerBad = true;
	if (headerBad) {
		fatal(ERROR_GAME_LOAD_NO, fname);
		return NULL;
	}
	char c;
	c = fp->readByte();
	while ((c = fp->readByte()))
		;

	int majVersion = fp->readByte();
	int minVersion = fp->readByte();
	ssgVersion = VERSION(majVersion, minVersion);

	if (ssgVersion >= VERSION(1, 4)) {
		if (!g_sludge->_gfxMan->skipThumbnail(fp))
			return fatal(ERROR_GAME_LOAD_CORRUPT, fname);
	}

	uint32 bytes_read = fp->read(&savedGameTime, sizeof(FILETIME));
	if (bytes_read != sizeof(FILETIME) && fp->err()) {
		warning("Reading error in loadGame.");
	}

	if (savedGameTime.dwLowDateTime != fileTime.dwLowDateTime || savedGameTime.dwHighDateTime != fileTime.dwHighDateTime) {
		return fatal(ERROR_GAME_LOAD_WRONG, fname);
	}

	// DON'T ADD ANYTHING NEW BEFORE THIS POINT!

	if (ssgVersion >= VERSION(1, 4)) {
		allowAnyFilename = fp->readByte();
	}
	captureAllKeys = fp->readByte();
	fp->readByte();  // updateDisplay (part of movie playing)

	g_sludge->_txtMan->loadFont(ssgVersion, fp);

	killAllPeople();
	killAllRegions();

	int camerX = fp->readUint16BE();
	int camerY = fp->readUint16BE();
	float camerZ;
	if (ssgVersion >= VERSION(2, 0)) {
		camerZ = fp->readFloatLE();
	} else {
		camerZ = 1.0;
	}

	brightnessLevel = fp->readByte();

	g_sludge->_gfxMan->loadHSI(fp, 0, 0, true);
	g_sludge->_evtMan->loadHandlers(fp);
	loadRegions(fp);

	if (!g_sludge->_cursorMan->loadCursor(fp)) {
		return false;
	}

	LoadedFunction *rFunc;
	LoadedFunction **buildList = &allRunningFunctions;

	int countFunctions = fp->readUint16BE();
	while (countFunctions--) {
		rFunc = loadFunction(fp);
		rFunc->next = NULL;
		(*buildList) = rFunc;
		buildList = &(rFunc->next);
	}

	for (int a = 0; a < numGlobals; a++) {
		unlinkVar(globalVars[a]);
		loadVariable(&globalVars[a], fp);
	}

	loadPeople(fp);

	if (fp->readByte()) {
		if (!setFloor(fp->readUint16BE()))
			return false;
	} else
		setFloorNull();

	if (!g_sludge->_gfxMan->loadZBuffer(fp))
		return false;

	if (!g_sludge->_gfxMan->loadLightMap(ssgVersion, fp)) {
		return false;
	}

	fadeMode = fp->readByte();
	g_sludge->_speechMan->load(fp);
	loadStatusBars(fp);
	g_sludge->_soundMan->loadSounds(fp);

	saveEncoding = fp->readUint16BE();

	if (ssgVersion >= VERSION(1, 6)) {
		if (ssgVersion < VERSION(2, 0)) {
			// aaLoad
			fp->readByte();
			fp->readFloatLE();
			fp->readFloatLE();
		}

		blur_loadSettings(fp);
	}

	if (ssgVersion >= VERSION(1, 3)) {
		g_sludge->_gfxMan->loadColors(fp);

		// Read parallax layers
		while (fp->readByte()) {
			int im = fp->readUint16BE();
			int fx = fp->readUint16BE();
			int fy = fp->readUint16BE();

			if (!g_sludge->_gfxMan->loadParallax(im, fx, fy))
				return false;
		}

		g_sludge->_languageMan->loadLanguageSetting(fp);
	}

	g_sludge->_gfxMan->nosnapshot();
	if (ssgVersion >= VERSION(1, 4)) {
		if (fp->readByte()) {
			if (!g_sludge->_gfxMan->restoreSnapshot(fp))
				return false;
		}
	}

	delete fp;

	g_sludge->_gfxMan->setCamera(camerX, camerY, camerZ);

	clearStackLib();
	return true;
}
Example #15
0
void makeTextVar(Variable &thisVar, const Common::String &txt) {
	unlinkVar(thisVar);
	thisVar.varType = SVT_STRING;
	thisVar.varData.theString = createCString(txt);
}