[Scummvm-git-logs] scummvm master -> db1f09a0c2f799ab0feca363b7b0e8f3d5c03de6

yinsimei roseline.yin at gmail.com
Sun Apr 15 22:11:12 CEST 2018


This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
756a1096d8 SLUDGE: Remove unused global variable captureAllKeys
7c74e81e0a SLUDGE: Objectify PeopleManager
53c79fdde9 SLUDGE: Refactor PersonaAnimation related code in PeopleManager
2cf79dc67c SLUDGE: Refactor save/load costume to Persona
db1f09a0c2 SLUDGE: Refactor OnScreenPerson related public method in PeopleManager


Commit: 756a1096d8f07bf8dec93be126f8b702a884daa3
    https://github.com/scummvm/scummvm/commit/756a1096d8f07bf8dec93be126f8b702a884daa3
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-15T22:10:41+02:00

Commit Message:
SLUDGE: Remove unused global variable captureAllKeys

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/loadsave.cpp
    engines/sludge/sludger.cpp


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index d6cfbb5..8cba903 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -60,7 +60,6 @@ Variable *launchResult = NULL;
 
 extern int lastFramesPerSecond, thumbWidth, thumbHeight;
 extern bool allowAnyFilename;
-extern bool captureAllKeys;
 extern VariableStack *noStack;
 extern StatusStuff  *nowStatus;
 extern ScreenRegion *overRegion;
@@ -1991,9 +1990,10 @@ builtIn(transitionLevel) {
 
 builtIn(captureAllKeys) {
 	UNUSEDALL
-	captureAllKeys = getBoolean(fun->stack->thisVar);
+	// This built-in function doesn't have any effect any more, we capture all keys by default
+	bool captureAllKeysDeprecated = getBoolean(fun->stack->thisVar);
 	trimStack(fun->stack);
-	setVariable(fun->reg, SVT_INT, captureAllKeys);
+	setVariable(fun->reg, SVT_INT, captureAllKeysDeprecated);
 	return BR_CONTINUE;
 }
 
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 2a69d02..01ee147 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -62,7 +62,6 @@ extern Floor *currentFloor;                          // In floor.cpp
 extern FILETIME fileTime;                           // In sludger.cpp
 extern byte brightnessLevel;               // "    "   "
 extern byte fadeMode;                      // In transition.cpp
-extern bool captureAllKeys;
 extern bool allowAnyFilename;
 extern uint16 saveEncoding;                 // in savedata.cpp
 
@@ -359,7 +358,7 @@ bool saveGame(const Common::String &fname) {
 	// DON'T ADD ANYTHING NEW BEFORE THIS POINT!
 
 	fp->writeByte(allowAnyFilename);
-	fp->writeByte(captureAllKeys);
+	fp->writeByte(false); // deprecated captureAllKeys
 	fp->writeByte(true);
 	g_sludge->_txtMan->saveFont(fp);
 
@@ -498,8 +497,8 @@ bool loadGame(const Common::String &fname) {
 	if (ssgVersion >= VERSION(1, 4)) {
 		allowAnyFilename = fp->readByte();
 	}
-	captureAllKeys = fp->readByte();
-	fp->readByte();  // updateDisplay (part of movie playing)
+	fp->readByte(); // deprecated captureAllKeys
+	fp->readByte(); // updateDisplay (part of movie playing)
 
 	g_sludge->_txtMan->loadFont(ssgVersion, fp);
 
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 0da7f39..01d3b17 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -67,7 +67,6 @@ int selectedLanguage = 0;
 
 int gameVersion;
 FILETIME fileTime;
-bool captureAllKeys = false;
 
 byte brightnessLevel = 255;
 
@@ -79,7 +78,6 @@ Variable *globalVars;
 
 int numGlobals = 0;
 
-extern SpritePalette pastePalette;
 extern Variable *launchResult;
 extern int lastFramesPerSecond, thumbWidth, thumbHeight;
 
@@ -171,7 +169,6 @@ void initSludge() {
 	lastFramesPerSecond = -1;
 	thumbWidth = thumbHeight = 0;
 	allowAnyFilename = true;
-	captureAllKeys = false;
 	noStack = nullptr;
 	numBIFNames = numUserFunc = 0;
 	allUserFunc = allBIFNames = nullptr;


Commit: 7c74e81e0ac7f9482c3732cb9305929d9e83a0c4
    https://github.com/scummvm/scummvm/commit/7c74e81e0ac7f9482c3732cb9305929d9e83a0c4
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-15T22:10:41+02:00

Commit Message:
SLUDGE: Objectify PeopleManager

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/cursors.cpp
    engines/sludge/freeze.cpp
    engines/sludge/loadsave.cpp
    engines/sludge/main_loop.cpp
    engines/sludge/people.cpp
    engines/sludge/people.h
    engines/sludge/sludge.cpp
    engines/sludge/sludge.h
    engines/sludge/sludger.cpp
    engines/sludge/speech.cpp
    engines/sludge/variable.cpp


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 8cba903..e8e9b87 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -62,7 +62,6 @@ extern int lastFramesPerSecond, thumbWidth, thumbHeight;
 extern bool allowAnyFilename;
 extern VariableStack *noStack;
 extern StatusStuff  *nowStatus;
-extern ScreenRegion *overRegion;
 extern int numBIFNames, numUserFunc;
 
 extern Common::String *allUserFunc;
@@ -856,7 +855,7 @@ builtIn(anim) {
 	}
 
 	// First store the frame numbers and take 'em off the stack
-	PersonaAnimation  *ba = createPersonaAnim(numParams - 1, fun->stack);
+	PersonaAnimation  *ba = g_sludge->_peopleMan->createPersonaAnim(numParams - 1, fun->stack);
 
 	// Only remaining paramter is the file number
 	int fileNumber;
@@ -868,7 +867,7 @@ builtIn(anim) {
 	LoadedSpriteBank *sprBanky = g_sludge->_gfxMan->loadBankForAnim(fileNumber);
 	if (!sprBanky)
 		return BR_ERROR;    // File not found, fatal done already
-	setBankFile(ba, sprBanky);
+	g_sludge->_peopleMan->setBankFile(ba, sprBanky);
 
 	// Return value
 	newAnimationVariable(fun->reg, ba);
@@ -1341,7 +1340,7 @@ builtIn(getObjectX) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 
-	OnScreenPerson *pers = findPerson(objectNumber);
+	OnScreenPerson *pers = g_sludge->_peopleMan->findPerson(objectNumber);
 	if (pers) {
 		setVariable(fun->reg, SVT_INT, pers->x);
 	} else {
@@ -1362,7 +1361,7 @@ builtIn(getObjectY) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 
-	OnScreenPerson *pers = findPerson(objectNumber);
+	OnScreenPerson *pers = g_sludge->_peopleMan->findPerson(objectNumber);
 	if (pers) {
 		setVariable(fun->reg, SVT_INT, pers->y);
 	} else {
@@ -1450,7 +1449,7 @@ builtIn(addCharacter) {
 	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	if (addPerson(x, y, objectNumber, p))
+	if (g_sludge->_peopleMan->addPerson(x, y, objectNumber, p))
 		return BR_CONTINUE;
 	return BR_ERROR;
 }
@@ -1461,7 +1460,7 @@ builtIn(hideCharacter) {
 	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setShown(false, objectNumber);
+	g_sludge->_peopleMan->setShown(false, objectNumber);
 	return BR_CONTINUE;
 }
 
@@ -1471,14 +1470,14 @@ builtIn(showCharacter) {
 	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setShown(true, objectNumber);
+	g_sludge->_peopleMan->setShown(true, objectNumber);
 	return BR_CONTINUE;
 }
 
 builtIn(removeAllCharacters) {
 	UNUSEDALL
 	killSpeechTimers();
-	killMostPeople();
+	g_sludge->_peopleMan->killMostPeople();
 	return BR_CONTINUE;
 }
 
@@ -1491,7 +1490,7 @@ builtIn(setCharacterDrawMode) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setDrawMode(di, obj);
+	g_sludge->_peopleMan->setDrawMode(di, obj);
 	return BR_CONTINUE;
 }
 builtIn(setCharacterTransparency) {
@@ -1503,7 +1502,7 @@ builtIn(setCharacterTransparency) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setPersonTransparency(obj, x);
+	g_sludge->_peopleMan->setPersonTransparency(obj, x);
 	return BR_CONTINUE;
 }
 builtIn(setCharacterColourise) {
@@ -1524,7 +1523,7 @@ builtIn(setCharacterColourise) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setPersonColourise(obj, r, g, b, mix);
+	g_sludge->_peopleMan->setPersonColourise(obj, r, g, b, mix);
 	return BR_CONTINUE;
 }
 
@@ -1537,7 +1536,7 @@ builtIn(setScale) {
 	if (!getValueType(val1, SVT_INT, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setScale((int16)val1, (int16)val2);
+	g_sludge->_peopleMan->setScale((int16)val1, (int16)val2);
 	return BR_CONTINUE;
 }
 
@@ -1549,7 +1548,7 @@ builtIn(stopCharacter) {
 	trimStack(fun->stack);
 
 	// Return value
-	setVariable(fun->reg, SVT_INT, stopPerson(obj));
+	setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->stopPerson(obj));
 	return BR_CONTINUE;
 }
 
@@ -1560,7 +1559,7 @@ builtIn(pasteCharacter) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 
-	OnScreenPerson *thisPerson = findPerson(obj);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(obj);
 	if (thisPerson) {
 		PersonaAnimation  *myAnim;
 		myAnim = thisPerson->myAnim;
@@ -1589,8 +1588,8 @@ builtIn(animate) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	animatePerson(obj, pp);
-	setVariable(fun->reg, SVT_INT, timeForAnim(pp));
+	g_sludge->_peopleMan->animatePerson(obj, pp);
+	setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->timeForAnim(pp));
 	return BR_CONTINUE;
 }
 
@@ -1604,7 +1603,7 @@ builtIn(setCostume) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	animatePerson(obj, pp);
+	g_sludge->_peopleMan->animatePerson(obj, pp);
 	return BR_CONTINUE;
 }
 
@@ -1617,7 +1616,7 @@ builtIn(floatCharacter) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setVariable(fun->reg, SVT_INT, floatCharacter(di, obj));
+	setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->floatCharacter(di, obj));
 	return BR_CONTINUE;
 }
 
@@ -1630,7 +1629,7 @@ builtIn(setCharacterWalkSpeed) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setVariable(fun->reg, SVT_INT, setCharacterWalkSpeed(di, obj));
+	setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->setCharacterWalkSpeed(di, obj));
 	return BR_CONTINUE;
 }
 
@@ -1643,7 +1642,7 @@ builtIn(turnCharacter) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setVariable(fun->reg, SVT_INT, turnPersonToFace(obj, di));
+	setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->turnPersonToFace(obj, di));
 	return BR_CONTINUE;
 }
 
@@ -1656,7 +1655,7 @@ builtIn(setCharacterExtra) {
 	if (!getValueType(obj, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	setVariable(fun->reg, SVT_INT, setPersonExtra(obj, di));
+	setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->setPersonExtra(obj, di));
 	return BR_CONTINUE;
 }
 
@@ -1666,7 +1665,7 @@ builtIn(removeCharacter) {
 	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	removeOneCharacter(objectNumber);
+	g_sludge->_peopleMan->removeOneCharacter(objectNumber);
 	return BR_CONTINUE;
 }
 
@@ -1686,12 +1685,12 @@ static BuiltReturn moveChr(int numParams, LoadedFunction *fun, bool force, bool
 			trimStack(fun->stack);
 
 			if (force) {
-				if (forceWalkingPerson(x, y, objectNumber, fun, -1))
+				if (g_sludge->_peopleMan->forceWalkingPerson(x, y, objectNumber, fun, -1))
 					return BR_PAUSE;
 			} else if (immediate) {
-				jumpPerson(x, y, objectNumber);
+				g_sludge->_peopleMan->jumpPerson(x, y, objectNumber);
 			} else {
-				if (makeWalkingPerson(x, y, objectNumber, fun, -1))
+				if (g_sludge->_peopleMan->makeWalkingPerson(x, y, objectNumber, fun, -1))
 					return BR_PAUSE;
 			}
 			return BR_CONTINUE;
@@ -1712,12 +1711,12 @@ static BuiltReturn moveChr(int numParams, LoadedFunction *fun, bool force, bool
 				return BR_CONTINUE;
 
 			if (force) {
-				if (forceWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di))
+				if (g_sludge->_peopleMan->forceWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di))
 					return BR_PAUSE;
 			} else if (immediate) {
-				jumpPerson(reggie->sX, reggie->sY, objectNumber);
+				g_sludge->_peopleMan->jumpPerson(reggie->sX, reggie->sY, objectNumber);
 			} else {
-				if (makeWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di))
+				if (g_sludge->_peopleMan->makeWalkingPerson(reggie->sX, reggie->sY, objectNumber, fun, reggie->di))
 					return BR_PAUSE;
 			}
 			return BR_CONTINUE;
@@ -2007,7 +2006,7 @@ builtIn(spinCharacter) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 
-	OnScreenPerson *thisPerson = findPerson(objectNumber);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber);
 	if (thisPerson) {
 		thisPerson->wantAngle = number;
 		thisPerson->spinning = true;
@@ -2026,7 +2025,7 @@ builtIn(getCharacterDirection) {
 	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	OnScreenPerson *thisPerson = findPerson(objectNumber);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber);
 	if (thisPerson) {
 		setVariable(fun->reg, SVT_INT, thisPerson->direction);
 	} else {
@@ -2041,7 +2040,7 @@ builtIn(isCharacter) {
 	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	OnScreenPerson *thisPerson = findPerson(objectNumber);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber);
 	setVariable(fun->reg, SVT_INT, thisPerson != NULL);
 	return BR_CONTINUE;
 }
@@ -2052,7 +2051,7 @@ builtIn(normalCharacter) {
 	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	OnScreenPerson *thisPerson = findPerson(objectNumber);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber);
 	if (thisPerson) {
 		thisPerson->myAnim = thisPerson->myPersona->animation[thisPerson->direction];
 		setVariable(fun->reg, SVT_INT, 1);
@@ -2068,7 +2067,7 @@ builtIn(isMoving) {
 	if (!getValueType(objectNumber, SVT_OBJTYPE, fun->stack->thisVar))
 		return BR_ERROR;
 	trimStack(fun->stack);
-	OnScreenPerson *thisPerson = findPerson(objectNumber);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objectNumber);
 	if (thisPerson) {
 		setVariable(fun->reg, SVT_INT, thisPerson->walking);
 	} else {
@@ -2173,7 +2172,7 @@ builtIn(setCharacterSpinSpeed) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 
-	OnScreenPerson *thisPerson = findPerson(who);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(who);
 
 	if (thisPerson) {
 		thisPerson->spinSpeed = speed;
@@ -2194,7 +2193,7 @@ builtIn(setCharacterAngleOffset) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 
-	OnScreenPerson *thisPerson = findPerson(who);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(who);
 
 	if (thisPerson) {
 		thisPerson->angleOffset = angle;
@@ -2390,7 +2389,7 @@ builtIn(getCharacterScale) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 
-	OnScreenPerson *pers = findPerson(objectNumber);
+	OnScreenPerson *pers = g_sludge->_peopleMan->findPerson(objectNumber);
 	if (pers) {
 		setVariable(fun->reg, SVT_INT, pers->scale * 100);
 	} else {
diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp
index 0c7745e..849a627 100644
--- a/engines/sludge/cursors.cpp
+++ b/engines/sludge/cursors.cpp
@@ -44,18 +44,18 @@ CursorManager::~CursorManager() {
 }
 
 void CursorManager::init() {
-	_mouseCursorAnim = makeNullAnim();
+	_mouseCursorAnim = _vm->_peopleMan->makeNullAnim();
 	_mouseCursorFrameNum = 0;
 	_mouseCursorCountUp = 0;
 }
 
 void CursorManager::kill() {
-	deleteAnim(_mouseCursorAnim);
+	_vm->_peopleMan->deleteAnim(_mouseCursorAnim);
 	_mouseCursorAnim = nullptr;
 }
 
 void CursorManager::pickAnimCursor(PersonaAnimation  *pp) {
-	deleteAnim(_mouseCursorAnim);
+	_vm->_peopleMan->deleteAnim(_mouseCursorAnim);
 	_mouseCursorAnim = pp;
 	_mouseCursorFrameNum = 0;
 	_mouseCursorCountUp = 0;
@@ -107,18 +107,18 @@ void CursorManager::pasteCursor(int x, int y, PersonaAnimation  *c) {
 void CursorManager::freeze(FrozenStuffStruct *frozenStuff) {
 	frozenStuff->mouseCursorAnim = _mouseCursorAnim;
 	frozenStuff->mouseCursorFrameNum = _mouseCursorFrameNum;
-	_mouseCursorAnim = makeNullAnim();
+	_mouseCursorAnim = _vm->_peopleMan->makeNullAnim();
 	_mouseCursorFrameNum = 0;
 }
 
 void CursorManager::resotre(FrozenStuffStruct *frozenStuff) {
-	deleteAnim(_mouseCursorAnim);
+	_vm->_peopleMan->deleteAnim(_mouseCursorAnim);
 	_mouseCursorAnim = frozenStuff->mouseCursorAnim;
 	_mouseCursorFrameNum = frozenStuff->mouseCursorFrameNum;
 }
 
 void CursorManager::saveCursor(Common::WriteStream *stream) {
-	saveAnim(_mouseCursorAnim, stream);
+	_vm->_peopleMan->saveAnim(_mouseCursorAnim, stream);
 	stream->writeUint16BE(_mouseCursorFrameNum);
 }
 
@@ -126,7 +126,7 @@ bool CursorManager::loadCursor(Common::SeekableReadStream *stream) {
 	_mouseCursorAnim = new PersonaAnimation;
 	if (!checkNew(_mouseCursorAnim))
 		return false;
-	if (!loadAnim(_mouseCursorAnim, stream))
+	if (!_vm->_peopleMan->loadAnim(_mouseCursorAnim, stream))
 		return false;
 	_mouseCursorFrameNum = stream->readUint16BE();
 	return true;
diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp
index 0f03273..cbafa40 100644
--- a/engines/sludge/freeze.cpp
+++ b/engines/sludge/freeze.cpp
@@ -41,10 +41,6 @@
 
 namespace Sludge {
 
-extern OnScreenPerson *allPeople;
-extern ScreenRegion *allScreenRegions;
-extern ScreenRegion *overRegion;
-
 void GraphicsManager::freezeGraphics() {
 
 	int w = _winWidth;
@@ -87,8 +83,7 @@ bool GraphicsManager::freeze() {
 	_backdropSurface.copyFrom(_freezeSurface);
 	_backdropExists = true;
 
-	newFreezer->allPeople = allPeople;
-	allPeople = NULL;
+	_vm->_peopleMan->freeze(newFreezer);
 
 	StatusStuff  *newStatusStuff = new StatusStuff ;
 	if (!checkNew(newStatusStuff))
@@ -133,9 +128,7 @@ void GraphicsManager::unfreeze(bool killImage) {
 	_vm->_evtMan->mouseX() = (int)(_vm->_evtMan->mouseX() / _cameraZoom);
 	_vm->_evtMan->mouseY() = (int)(_vm->_evtMan->mouseY() / _cameraZoom);
 
-	killAllPeople();
-	allPeople = _frozenStuff->allPeople;
-
+	g_sludge->_peopleMan->resotre(_frozenStuff);
 	g_sludge->_regionMan->resotre(_frozenStuff);
 
 	killLightMap();
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 01ee147..bfedcfc 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -214,11 +214,11 @@ bool saveVariable(Variable *from, Common::WriteStream *stream) {
 			return saveStackRef(from->varData.theStack, stream);
 
 		case SVT_COSTUME:
-			saveCostume(from->varData.costumeHandler, stream);
+			g_sludge->_peopleMan->saveCostume(from->varData.costumeHandler, stream);
 			return false;
 
 		case SVT_ANIM:
-			saveAnim(from->varData.animHandler, stream);
+			g_sludge->_peopleMan->saveAnim(from->varData.animHandler, stream);
 			return false;
 
 		case SVT_NULL:
@@ -253,14 +253,14 @@ bool loadVariable(Variable *to, Common::SeekableReadStream *stream) {
 			to->varData.costumeHandler = new Persona;
 			if (!checkNew(to->varData.costumeHandler))
 				return false;
-			loadCostume(to->varData.costumeHandler, stream);
+			g_sludge->_peopleMan->loadCostume(to->varData.costumeHandler, stream);
 			return true;
 
 		case SVT_ANIM:
 			to->varData.animHandler = new PersonaAnimation ;
 			if (!checkNew(to->varData.animHandler))
 				return false;
-			loadAnim(to->varData.animHandler, stream);
+			g_sludge->_peopleMan->loadAnim(to->varData.animHandler, stream);
 			return true;
 
 		default:
@@ -397,7 +397,7 @@ bool saveGame(const Common::String &fname) {
 		saveVariable(&globalVars[a], fp);
 	}
 
-	savePeople(fp);
+	g_sludge->_peopleMan->savePeople(fp);
 
 	if (currentFloor->numPolygons) {
 		fp->writeByte(1);
@@ -502,7 +502,6 @@ bool loadGame(const Common::String &fname) {
 
 	g_sludge->_txtMan->loadFont(ssgVersion, fp);
 
-	killAllPeople();
 	g_sludge->_regionMan->kill();
 
 	int camerX = fp->readUint16BE();
@@ -540,7 +539,7 @@ bool loadGame(const Common::String &fname) {
 		loadVariable(&globalVars[a], fp);
 	}
 
-	loadPeople(fp);
+	g_sludge->_peopleMan->loadPeople(fp);
 
 	if (fp->readByte()) {
 		if (!setFloor(fp->readUint16BE()))
diff --git a/engines/sludge/main_loop.cpp b/engines/sludge/main_loop.cpp
index 905d91d..eac8610 100644
--- a/engines/sludge/main_loop.cpp
+++ b/engines/sludge/main_loop.cpp
@@ -63,7 +63,7 @@ int main_loop(Common::String filename) {
 
 	while (!g_sludge->_evtMan->quit()) {
 		g_sludge->_evtMan->checkInput();
-		walkAllPeople();
+		g_sludge->_peopleMan->walkAllPeople();
 		if (g_sludge->_evtMan->handleInput()) {
 			runSludge();
 		}
diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp
index d069479..a43f0f1 100644
--- a/engines/sludge/people.cpp
+++ b/engines/sludge/people.cpp
@@ -47,22 +47,30 @@
 namespace Sludge {
 
 extern VariableStack *noStack;
-
 extern int ssgVersion;
-
-ScreenRegion personRegion;
 extern Floor *currentFloor;
 
-OnScreenPerson *allPeople = NULL;
-int16 scaleHorizon = 75;
-int16 scaleDivide = 150;
+PeopleManager::PeopleManager(SludgeEngine *vm) {
+	_vm = vm;
+	_allPeople = nullptr;
+	_scaleHorizon = 75;
+	_scaleDivide = 150;
+	_personRegion = new ScreenRegion;
+}
+
+PeopleManager::~PeopleManager() {
+	kill();
 
-void setFrames(OnScreenPerson &m, int a) {
+	delete _personRegion;
+	_personRegion = nullptr;
+}
+
+void PeopleManager::setFrames(OnScreenPerson &m, int a) {
 	m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction];
 }
 
-PersonaAnimation  *createPersonaAnim(int num, VariableStack *&stacky) {
-	PersonaAnimation  *newP = new PersonaAnimation ;
+PersonaAnimation *PeopleManager::createPersonaAnim(int num, VariableStack *&stacky) {
+	PersonaAnimation *newP = new PersonaAnimation ;
 	checkNew(newP);
 
 	newP->numFrames = num;
@@ -93,8 +101,8 @@ PersonaAnimation  *createPersonaAnim(int num, VariableStack *&stacky) {
 	return newP;
 }
 
-PersonaAnimation  *makeNullAnim() {
-	PersonaAnimation  *newAnim = new PersonaAnimation ;
+PersonaAnimation *PeopleManager::makeNullAnim() {
+	PersonaAnimation *newAnim = new PersonaAnimation ;
 	if (!checkNew(newAnim))
 		return NULL;
 
@@ -104,10 +112,10 @@ PersonaAnimation  *makeNullAnim() {
 	return newAnim;
 }
 
-PersonaAnimation  *copyAnim(PersonaAnimation  *orig) {
+PersonaAnimation *PeopleManager::copyAnim(PersonaAnimation *orig) {
 	int num = orig->numFrames;
 
-	PersonaAnimation  *newAnim = new PersonaAnimation ;
+	PersonaAnimation *newAnim = new PersonaAnimation ;
 	if (!checkNew(newAnim))
 		return NULL;
 
@@ -135,7 +143,7 @@ PersonaAnimation  *copyAnim(PersonaAnimation  *orig) {
 	return newAnim;
 }
 
-void deleteAnim(PersonaAnimation  *orig) {
+void PeopleManager::deleteAnim(PersonaAnimation *orig) {
 
 	if (orig) {
 		if (orig->numFrames) {
@@ -146,7 +154,7 @@ void deleteAnim(PersonaAnimation  *orig) {
 	}
 }
 
-void turnMeAngle(OnScreenPerson *thisPerson, int direc) {
+void PeopleManager::turnMeAngle(OnScreenPerson *thisPerson, int direc) {
 	int d = thisPerson->myPersona->numDirections;
 	thisPerson->angle = direc;
 	direc += (180 / d) + 180 + thisPerson->angleOffset;
@@ -155,14 +163,14 @@ void turnMeAngle(OnScreenPerson *thisPerson, int direc) {
 	thisPerson->direction = (direc * d) / 360;
 }
 
-bool initPeople() {
-	personRegion.sX = 0;
-	personRegion.sY = 0;
-	personRegion.di = -1;
+bool PeopleManager::init() {
+	_personRegion->sX = 0;
+	_personRegion->sY = 0;
+	_personRegion->di = -1;
 	return true;
 }
 
-void spinStep(OnScreenPerson *thisPerson) {
+void PeopleManager::spinStep(OnScreenPerson *thisPerson) {
 	int diff = (thisPerson->angle + 360) - thisPerson->wantAngle;
 	int eachSlice = thisPerson->spinSpeed ? thisPerson->spinSpeed : (360 / thisPerson->myPersona->numDirections);
 	while (diff > 180) {
@@ -179,7 +187,7 @@ void spinStep(OnScreenPerson *thisPerson) {
 	}
 }
 
-void rethinkAngle(OnScreenPerson *thisPerson) {
+void PeopleManager::rethinkAngle(OnScreenPerson *thisPerson) {
 	int d = thisPerson->myPersona->numDirections;
 	int direc = thisPerson->angle + (180 / d) + 180 + thisPerson->angleOffset;
 	while (direc >= 360)
@@ -187,7 +195,7 @@ void rethinkAngle(OnScreenPerson *thisPerson) {
 	thisPerson->direction = (direc * d) / 360;
 }
 
-bool turnPersonToFace(int thisNum, int direc) {
+bool PeopleManager::turnPersonToFace(int thisNum, int direc) {
 	OnScreenPerson *thisPerson = findPerson(thisNum);
 	if (thisPerson) {
 		if (thisPerson->continueAfterWalking)
@@ -202,7 +210,7 @@ bool turnPersonToFace(int thisNum, int direc) {
 	return false;
 }
 
-bool setPersonExtra(int thisNum, int extra) {
+bool PeopleManager::setPersonExtra(int thisNum, int extra) {
 	OnScreenPerson *thisPerson = findPerson(thisNum);
 	if (thisPerson) {
 		thisPerson->extra = extra;
@@ -213,20 +221,20 @@ bool setPersonExtra(int thisNum, int extra) {
 	return false;
 }
 
-void setScale(int16 h, int16 d) {
-	scaleHorizon = h;
-	scaleDivide = d;
+void PeopleManager::setScale(int16 h, int16 d) {
+	_scaleHorizon = h;
+	_scaleDivide = d;
 }
 
-void moveAndScale(OnScreenPerson &me, float x, float y) {
+void PeopleManager::moveAndScale(OnScreenPerson &me, float x, float y) {
 	me.x = x;
 	me.y = y;
-	if (!(me.extra & EXTRA_NOSCALE) && scaleDivide)
-		me.scale = (me.y - scaleHorizon) / scaleDivide;
+	if (!(me.extra & EXTRA_NOSCALE) && _scaleDivide)
+		me.scale = (me.y - _scaleHorizon) / _scaleDivide;
 }
 
-OnScreenPerson *findPerson(int v) {
-	OnScreenPerson *thisPerson = allPeople;
+OnScreenPerson *PeopleManager::findPerson(int v) {
+	OnScreenPerson *thisPerson = _allPeople;
 	while (thisPerson) {
 		if (v == thisPerson->thisType->objectNum)
 			break;
@@ -235,13 +243,13 @@ OnScreenPerson *findPerson(int v) {
 	return thisPerson;
 }
 
-void movePerson(int x, int y, int objNum) {
+void PeopleManager::movePerson(int x, int y, int objNum) {
 	OnScreenPerson *moveMe = findPerson(objNum);
 	if (moveMe)
 		moveAndScale(*moveMe, x, y);
 }
 
-void setShown(bool h, int ob) {
+void PeopleManager::setShown(bool h, int ob) {
 	OnScreenPerson *moveMe = findPerson(ob);
 	if (moveMe)
 		moveMe->show = h;
@@ -271,7 +279,7 @@ enum drawModes {
 	numDrawModes
 };
 
-void setMyDrawMode(OnScreenPerson *moveMe, int h) {
+void PeopleManager::setMyDrawMode(OnScreenPerson *moveMe, int h) {
 	switch (h) {
 		case drawModeTransparent3:
 			moveMe->r = moveMe->g = moveMe->b = 0;
@@ -377,7 +385,7 @@ void setMyDrawMode(OnScreenPerson *moveMe, int h) {
 
 }
 
-void setDrawMode(int h, int ob) {
+void PeopleManager::setDrawMode(int h, int ob) {
 	OnScreenPerson *moveMe = findPerson(ob);
 	if (!moveMe)
 		return;
@@ -385,7 +393,7 @@ void setDrawMode(int h, int ob) {
 	setMyDrawMode(moveMe, h);
 }
 
-void setPersonTransparency(int ob, byte x) {
+void PeopleManager::setPersonTransparency(int ob, byte x) {
 	OnScreenPerson *moveMe = findPerson(ob);
 	if (!moveMe)
 		return;
@@ -395,7 +403,7 @@ void setPersonTransparency(int ob, byte x) {
 	moveMe->transparency = x;
 }
 
-void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix) {
+void PeopleManager::setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix) {
 	OnScreenPerson *moveMe = findPerson(ob);
 	if (!moveMe)
 		return;
@@ -406,11 +414,11 @@ void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix) {
 	moveMe->colourmix = colourmix;
 }
 
-void shufflePeople() {
-	OnScreenPerson **thisReference = &allPeople;
+void PeopleManager::shufflePeople() {
+	OnScreenPerson **thisReference = &_allPeople;
 	OnScreenPerson *A, *B;
 
-	if (!allPeople)
+	if (!_allPeople)
 		return;
 
 	while ((*thisReference)->next) {
@@ -434,11 +442,11 @@ void shufflePeople() {
 	}
 }
 
-void drawPeople() {
+void PeopleManager::drawPeople() {
 	shufflePeople();
 
-	OnScreenPerson *thisPerson = allPeople;
-	PersonaAnimation  *myAnim = NULL;
+	OnScreenPerson *thisPerson = _allPeople;
+	PersonaAnimation *myAnim = NULL;
 	g_sludge->_regionMan->resetOverRegion();
 
 	while (thisPerson) {
@@ -473,10 +481,10 @@ void drawPeople() {
 				r = g_sludge->_gfxMan->scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim->theSprites->bank.myPalette, thisPerson, m);
 				if (r) {
 					if (!thisPerson->thisType->screenName.empty()) {
-						if (personRegion.thisType != thisPerson->thisType)
+						if (_personRegion->thisType != thisPerson->thisType)
 							g_sludge->_regionMan->resetLastRegion();
-						personRegion.thisType = thisPerson->thisType;
-						g_sludge->_regionMan->setOverRegion(&personRegion);
+						_personRegion->thisType = thisPerson->thisType;
+						g_sludge->_regionMan->setOverRegion(_personRegion);
 					}
 				}
 			}
@@ -504,38 +512,30 @@ void drawPeople() {
 	}
 }
 
-void makeTalker(OnScreenPerson &me) {
+void PeopleManager::makeTalker(OnScreenPerson &me) {
 	setFrames(me, ANI_TALK);
 }
 
-void makeSilent(OnScreenPerson &me) {
+void PeopleManager::makeSilent(OnScreenPerson &me) {
 	setFrames(me, ANI_STAND);
 }
 
-bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
+bool PeopleManager::handleClosestPoint(int &setX, int &setY, int &setPoly) {
 	int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1, xTest2, yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF, thisDistance;
 
-//	FILE * dbug = fopen ("debug_closest.txt", "at");
-//	fprintf (dbug, "\nGetting closest point to %i, %i\n", setX, setY);
-
 	for (i = 0; i < currentFloor->numPolygons; i++) {
 		oldJ = currentFloor->polygon[i].numVertices - 1;
 		for (j = 0; j < currentFloor->polygon[i].numVertices; j++) {
-//			fprintf (dbug, "Polygon %i, line %i... ", i, j);
 			xTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].x;
 			yTest1 = currentFloor->vertex[currentFloor->polygon[i].vertexID[j]].y;
 			xTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].x;
 			yTest2 = currentFloor->vertex[currentFloor->polygon[i].vertexID[oldJ]].y;
 			closestPointOnLine(closestX, closestY, xTest1, yTest1, xTest2, yTest2, setX, setY);
-//			fprintf (dbug, "closest point is %i, %i... ", closestX, closestY);
 			xTest1 = setX - closestX;
 			yTest1 = setY - closestY;
 			thisDistance = xTest1 * xTest1 + yTest1 * yTest1;
-//			fprintf (dbug, "Distance squared %i\n", thisDistance);
 
 			if (thisDistance < currentDistance) {
-//				fprintf (dbug, "** We have a new winner!**\n");
-
 				currentDistance = thisDistance;
 				gotX = closestX;
 				gotY = closestY;
@@ -544,7 +544,6 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
 			oldJ = j;
 		}
 	}
-//	fclose (dbug);
 
 	if (gotPoly == -1)
 		return false;
@@ -555,7 +554,7 @@ bool handleClosestPoint(int &setX, int &setY, int &setPoly) {
 	return true;
 }
 
-bool doBorderStuff(OnScreenPerson *moveMe) {
+bool PeopleManager::doBorderStuff(OnScreenPerson *moveMe) {
 	if (moveMe->inPoly == moveMe->walkToPoly) {
 		moveMe->inPoly = -1;
 		moveMe->thisStepX = moveMe->walkToX;
@@ -625,7 +624,7 @@ bool doBorderStuff(OnScreenPerson *moveMe) {
 	return true;
 }
 
-bool walkMe(OnScreenPerson *thisPerson, bool move = true) {
+bool PeopleManager::walkMe(OnScreenPerson *thisPerson, bool move) {
 	float xDiff, yDiff, maxDiff, s;
 
 	for (;;) {
@@ -666,7 +665,7 @@ bool walkMe(OnScreenPerson *thisPerson, bool move = true) {
 	return false;
 }
 
-bool makeWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) {
+bool PeopleManager::makeWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) {
 	if (x == 0 && y == 0)
 		return false;
 	if (currentFloor->numPolygons == 0)
@@ -705,7 +704,7 @@ bool makeWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) {
 	}
 }
 
-bool stopPerson(int o) {
+bool PeopleManager::stopPerson(int o) {
 	OnScreenPerson *moveMe = findPerson(o);
 	if (moveMe)
 		if (moveMe->continueAfterWalking) {
@@ -719,7 +718,7 @@ bool stopPerson(int o) {
 	return false;
 }
 
-bool forceWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) {
+bool PeopleManager::forceWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di) {
 	if (x == 0 && y == 0)
 		return false;
 	OnScreenPerson *moveMe = findPerson(objNum);
@@ -749,7 +748,7 @@ bool forceWalkingPerson(int x, int y, int objNum, LoadedFunction *func, int di)
 	}
 }
 
-void jumpPerson(int x, int y, int objNum) {
+void PeopleManager::jumpPerson(int x, int y, int objNum) {
 	if (x == 0 && y == 0)
 		return;
 	OnScreenPerson *moveMe = findPerson(objNum);
@@ -763,7 +762,7 @@ void jumpPerson(int x, int y, int objNum) {
 	moveAndScale(*moveMe, x, y);
 }
 
-bool floatCharacter(int f, int objNum) {
+bool PeopleManager::floatCharacter(int f, int objNum) {
 	OnScreenPerson *moveMe = findPerson(objNum);
 	if (!moveMe)
 		return false;
@@ -771,7 +770,7 @@ bool floatCharacter(int f, int objNum) {
 	return true;
 }
 
-bool setCharacterWalkSpeed(int f, int objNum) {
+bool PeopleManager::setCharacterWalkSpeed(int f, int objNum) {
 	if (f <= 0)
 		return false;
 	OnScreenPerson *moveMe = findPerson(objNum);
@@ -781,8 +780,8 @@ bool setCharacterWalkSpeed(int f, int objNum) {
 	return true;
 }
 
-void walkAllPeople() {
-	OnScreenPerson *thisPerson = allPeople;
+void PeopleManager::walkAllPeople() {
+	OnScreenPerson *thisPerson = _allPeople;
 
 	while (thisPerson) {
 		if (thisPerson->walking) {
@@ -799,7 +798,7 @@ void walkAllPeople() {
 	}
 }
 
-bool addPerson(int x, int y, int objNum, Persona *p) {
+bool PeopleManager::addPerson(int x, int y, int objNum, Persona *p) {
 	OnScreenPerson *newPerson = new OnScreenPerson;
 	if (!checkNew(newPerson))
 		return false;
@@ -849,7 +848,7 @@ bool addPerson(int x, int y, int objNum, Persona *p) {
 	}
 
 	// NOW ADD IT IN THE RIGHT PLACE
-	OnScreenPerson **changethat = &allPeople;
+	OnScreenPerson **changethat = &_allPeople;
 
 	while (((*changethat) != NULL) && ((*changethat)->y < y))
 		changethat = &((*changethat)->next);
@@ -860,7 +859,7 @@ bool addPerson(int x, int y, int objNum, Persona *p) {
 	return (bool)(newPerson->thisType != NULL);
 }
 
-int timeForAnim(PersonaAnimation  *fram) {
+int PeopleManager::timeForAnim(PersonaAnimation *fram) {
 	int total = 0;
 	for (int a = 0; a < fram->numFrames; a++) {
 		total += fram->frames[a].howMany;
@@ -868,7 +867,7 @@ int timeForAnim(PersonaAnimation  *fram) {
 	return total;
 }
 
-void animatePerson(int obj, PersonaAnimation  *fram) { // Set a new SINGLE animation
+void PeopleManager::animatePerson(int obj, PersonaAnimation *fram) { // Set a new SINGLE animation
 	OnScreenPerson *moveMe = findPerson(obj);
 	if (moveMe) {
 		if (moveMe->continueAfterWalking)
@@ -880,7 +879,7 @@ void animatePerson(int obj, PersonaAnimation  *fram) { // Set a new SINGLE anima
 	}
 }
 
-void animatePerson(int obj, Persona *per) {             // Set a new costume
+void PeopleManager::animatePerson(int obj, Persona *per) {             // Set a new costume
 	OnScreenPerson *moveMe = findPerson(obj);
 	if (moveMe) {
 		//  if (moveMe->continueAfterWalking) abortFunction (moveMe->continueAfterWalking);
@@ -897,22 +896,22 @@ void animatePerson(int obj, Persona *per) {             // Set a new costume
 	}
 }
 
-void killAllPeople() {
+void PeopleManager::kill() {
 	OnScreenPerson *killPeople;
-	while (allPeople) {
-		if (allPeople->continueAfterWalking)
-			abortFunction(allPeople->continueAfterWalking);
-		allPeople->continueAfterWalking = NULL;
-		killPeople = allPeople;
-		allPeople = allPeople->next;
+	while (_allPeople) {
+		if (_allPeople->continueAfterWalking)
+			abortFunction(_allPeople->continueAfterWalking);
+		_allPeople->continueAfterWalking = NULL;
+		killPeople = _allPeople;
+		_allPeople = _allPeople->next;
 		g_sludge->_objMan->removeObjectType(killPeople->thisType);
 		delete killPeople;
 	}
 }
 
-void killMostPeople() {
+void PeopleManager::killMostPeople() {
 	OnScreenPerson *killPeople;
-	OnScreenPerson **lookyHere = &allPeople;
+	OnScreenPerson **lookyHere = &_allPeople;
 
 	while (*lookyHere) {
 		if ((*lookyHere)->extra & EXTRA_NOREMOVE) {
@@ -933,12 +932,12 @@ void killMostPeople() {
 	}
 }
 
-void removeOneCharacter(int i) {
+void PeopleManager::removeOneCharacter(int i) {
 	OnScreenPerson *p = findPerson(i);
 
 	if (p) {
 		ScreenRegion *overRegion = g_sludge->_regionMan->getOverRegion();
-		if (overRegion == &personRegion && overRegion->thisType == p->thisType) {
+		if (overRegion == _personRegion && overRegion->thisType == p->thisType) {
 			overRegion = nullptr;
 		}
 
@@ -947,7 +946,7 @@ void removeOneCharacter(int i) {
 		p->continueAfterWalking = NULL;
 		OnScreenPerson **killPeople;
 
-		for (killPeople = &allPeople; *killPeople != p; killPeople = &((*killPeople)->next)) {
+		for (killPeople = &_allPeople; *killPeople != p; killPeople = &((*killPeople)->next)) {
 			;
 		}
 
@@ -957,7 +956,7 @@ void removeOneCharacter(int i) {
 	}
 }
 
-bool saveAnim(PersonaAnimation  *p, Common::WriteStream *stream) {
+bool PeopleManager::saveAnim(PersonaAnimation *p, Common::WriteStream *stream) {
 	stream->writeUint16BE(p->numFrames);
 	if (p->numFrames) {
 		stream->writeUint32LE(p->theSprites->ID);
@@ -971,7 +970,7 @@ bool saveAnim(PersonaAnimation  *p, Common::WriteStream *stream) {
 	return true;
 }
 
-bool loadAnim(PersonaAnimation  *p, Common::SeekableReadStream *stream) {
+bool PeopleManager::loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream) {
 	p->numFrames = stream->readUint16BE();
 
 	if (p->numFrames) {
@@ -997,21 +996,20 @@ bool loadAnim(PersonaAnimation  *p, Common::SeekableReadStream *stream) {
 	return true;
 }
 
-bool saveCostume(Persona *cossy, Common::WriteStream *stream) {
+bool PeopleManager::saveCostume(Persona *cossy, Common::WriteStream *stream) {
 	int a;
 	stream->writeUint16BE(cossy->numDirections);
 	for (a = 0; a < cossy->numDirections * 3; a++) {
 		if (!saveAnim(cossy->animation[a], stream))
 			return false;
 	}
-//	debugCostume ("Saved", cossy);
 	return true;
 }
 
-bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream) {
+bool PeopleManager::loadCostume(Persona *cossy, Common::SeekableReadStream *stream) {
 	int a;
 	cossy->numDirections = stream->readUint16BE();
-	cossy->animation = new PersonaAnimation  *[cossy->numDirections * 3];
+	cossy->animation = new PersonaAnimation *[cossy->numDirections * 3];
 	if (!checkNew(cossy->animation))
 		return false;
 	for (a = 0; a < cossy->numDirections * 3; a++) {
@@ -1022,16 +1020,15 @@ bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream) {
 		if (!loadAnim(cossy->animation[a], stream))
 			return false;
 	}
-//	debugCostume ("Loaded", cossy);
 	return true;
 }
 
-bool savePeople(Common::WriteStream *stream) {
-	OnScreenPerson *me = allPeople;
+bool PeopleManager::savePeople(Common::WriteStream *stream) {
+	OnScreenPerson *me = _allPeople;
 	int countPeople = 0, a;
 
-	stream->writeSint16LE(scaleHorizon);
-	stream->writeSint16LE(scaleDivide);
+	stream->writeSint16LE(_scaleHorizon);
+	stream->writeSint16LE(_scaleDivide);
 
 	while (me) {
 		countPeople++;
@@ -1040,7 +1037,7 @@ bool savePeople(Common::WriteStream *stream) {
 
 	stream->writeUint16BE(countPeople);
 
-	me = allPeople;
+	me = _allPeople;
 	for (a = 0; a < countPeople; a++) {
 
 		stream->writeFloatLE(me->x);
@@ -1093,17 +1090,19 @@ bool savePeople(Common::WriteStream *stream) {
 	return true;
 }
 
-bool loadPeople(Common::SeekableReadStream *stream) {
-	OnScreenPerson **pointy = &allPeople;
+bool PeopleManager::loadPeople(Common::SeekableReadStream *stream) {
+	kill();
+
+	OnScreenPerson **pointy = &_allPeople;
 	OnScreenPerson *me;
 
-	scaleHorizon = stream->readSint16LE();
-	scaleDivide = stream->readSint16LE();
+	_scaleHorizon = stream->readSint16LE();
+	_scaleDivide = stream->readSint16LE();
 
 	int countPeople = stream->readUint16BE();
 	int a;
 
-	allPeople = NULL;
+	_allPeople = NULL;
 	for (a = 0; a < countPeople; a++) {
 		me = new OnScreenPerson;
 		if (!checkNew(me))
@@ -1184,8 +1183,17 @@ bool loadPeople(Common::SeekableReadStream *stream) {
 		*pointy = me;
 		pointy = &(me->next);
 	}
-//	db ("End of loadPeople");
 	return true;
 }
 
+void PeopleManager::freeze(FrozenStuffStruct *frozenStuff) {
+	frozenStuff->allPeople = _allPeople;
+	_allPeople = nullptr;
+}
+
+void PeopleManager::resotre(FrozenStuffStruct *frozenStuff) {
+	kill();
+	_allPeople = frozenStuff->allPeople;
+}
+
 } // End of namespace Sludge
diff --git a/engines/sludge/people.h b/engines/sludge/people.h
index 95b8e92..3fe4194 100644
--- a/engines/sludge/people.h
+++ b/engines/sludge/people.h
@@ -26,6 +26,9 @@
 
 namespace Sludge {
 
+struct FrozenStuffStruct;
+struct ScreenRegion;
+
 struct AnimFrame {
 	int frameNum, howMany;
 	int noise;
@@ -42,12 +45,12 @@ struct AnimFrame {
 
 struct PersonaAnimation {
 	struct LoadedSpriteBank *theSprites;
-	AnimFrame  *frames;
+	AnimFrame *frames;
 	int numFrames;
 };
 
 struct Persona {
-	PersonaAnimation  **animation;
+	PersonaAnimation **animation;
 	int numDirections;
 };
 
@@ -59,8 +62,8 @@ struct OnScreenPerson {
 	int walkToX, walkToY, thisStepX, thisStepY, inPoly, walkToPoly;
 	bool walking, spinning;
 	struct LoadedFunction *continueAfterWalking;
-	PersonaAnimation  *myAnim;
-	PersonaAnimation  *lastUsedAnim;
+	PersonaAnimation *myAnim;
+	PersonaAnimation *lastUsedAnim;
 	Persona *myPersona;
 	int frameNum, frameTick, angle, wantAngle, angleOffset;
 	bool show;
@@ -70,62 +73,91 @@ struct OnScreenPerson {
 	byte r, g, b, colourmix, transparency;
 };
 
-// Initialisation and creation
-bool initPeople();
-bool addPerson(int x, int y, int objNum, Persona *p);
-
-// Draw to screen and to backdrop
-void drawPeople();
-void freezePeople(int, int);
-
-// Removalisationisms
-void killAllPeople();
-void killMostPeople();
-void removeOneCharacter(int i);
-
-// Things which affect or use all characters
-OnScreenPerson *findPerson(int v);
-void setScale(int16 h, int16 d);
-
-// Things which affect one character
-void makeTalker(OnScreenPerson &me);
-void makeSilent(OnScreenPerson &me);
-void setShown(bool h, int ob);
-void setDrawMode(int h, int ob);
-void setPersonTransparency(int ob, byte x);
-void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix);
-
-// Moving 'em
-void movePerson(int x, int y, int objNum);
-bool makeWalkingPerson(int x, int y, int objNum, struct LoadedFunction *func, int di);
-bool forceWalkingPerson(int x, int y, int objNum, struct LoadedFunction *func, int di);
-void jumpPerson(int x, int y, int objNum);
-void walkAllPeople();
-bool turnPersonToFace(int thisNum, int direc);
-bool stopPerson(int o);
-bool floatCharacter(int f, int objNum);
-bool setCharacterWalkSpeed(int f, int objNum);
-
-// Animating 'em
-void animatePerson(int obj, PersonaAnimation  *);
-void animatePerson(int obj, Persona *per);
-PersonaAnimation  *createPersonaAnim(int num, struct VariableStack *&stacky);
-inline void setBankFile(PersonaAnimation  *newP, LoadedSpriteBank *sB) {
-	newP->theSprites = sB;
-}
-bool setPersonExtra(int f, int newSetting);
-int timeForAnim(PersonaAnimation  *fram);
-PersonaAnimation  *copyAnim(PersonaAnimation  *orig);
-PersonaAnimation  *makeNullAnim();
-void deleteAnim(PersonaAnimation  *orig);
-
-// Loading and saving
-bool saveAnim(PersonaAnimation  *p, Common::WriteStream *stream);
-bool loadAnim(PersonaAnimation  *p, Common::SeekableReadStream *stream);
-bool savePeople(Common::WriteStream *stream);
-bool loadPeople(Common::SeekableReadStream *stream);
-bool saveCostume(Persona *cossy, Common::WriteStream *stream);
-bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream);
+class PeopleManager {
+public:
+	PeopleManager(SludgeEngine *vm);
+	~PeopleManager();
+
+	// Initialisation and creation
+	bool init();
+	bool addPerson(int x, int y, int objNum, Persona *p);
+
+	// Draw to screen and to backdrop
+	void drawPeople();
+	void freezePeople(int, int);
+
+	// Removalisationisms
+	void kill();
+	void killMostPeople();
+	void removeOneCharacter(int i);
+
+	// Things which affect or use all characters
+	OnScreenPerson *findPerson(int v);
+	void setScale(int16 h, int16 d);
+
+	// Things which affect one character
+	void makeTalker(OnScreenPerson &me);
+	void makeSilent(OnScreenPerson &me);
+	void setShown(bool h, int ob);
+	void setDrawMode(int h, int ob);
+	void setPersonTransparency(int ob, byte x);
+	void setPersonColourise(int ob, byte r, byte g, byte b, byte colourmix);
+
+	// Moving 'em
+	void movePerson(int x, int y, int objNum);
+	bool makeWalkingPerson(int x, int y, int objNum, struct LoadedFunction *func, int di);
+	bool forceWalkingPerson(int x, int y, int objNum, struct LoadedFunction *func, int di);
+	void jumpPerson(int x, int y, int objNum);
+	void walkAllPeople();
+	bool turnPersonToFace(int thisNum, int direc);
+	bool stopPerson(int o);
+	bool floatCharacter(int f, int objNum);
+	bool setCharacterWalkSpeed(int f, int objNum);
+
+	// Animating 'em
+	void animatePerson(int obj, PersonaAnimation *);
+	void animatePerson(int obj, Persona *per);
+	PersonaAnimation *createPersonaAnim(int num, struct VariableStack *&stacky);
+	inline void setBankFile(PersonaAnimation *newP, LoadedSpriteBank *sB) {
+		newP->theSprites = sB;
+	}
+	bool setPersonExtra(int f, int newSetting);
+	int timeForAnim(PersonaAnimation *fram);
+	PersonaAnimation *copyAnim(PersonaAnimation *orig);
+	PersonaAnimation *makeNullAnim();
+	void deleteAnim(PersonaAnimation *orig);
+
+	// Loading and saving
+	bool saveAnim(PersonaAnimation *p, Common::WriteStream *stream);
+	bool loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream);
+	bool savePeople(Common::WriteStream *stream);
+	bool loadPeople(Common::SeekableReadStream *stream);
+	bool saveCostume(Persona *cossy, Common::WriteStream *stream);
+	bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream);
+
+	// Freeze
+	void freeze(FrozenStuffStruct *frozenStuff);
+	void resotre(FrozenStuffStruct *frozenStuff);
+
+private:
+	ScreenRegion *_personRegion;
+	OnScreenPerson *_allPeople;
+	int16 _scaleHorizon;
+	int16 _scaleDivide;
+
+	SludgeEngine *_vm;
+
+	void setFrames(OnScreenPerson &m, int a);
+	void turnMeAngle(OnScreenPerson *thisPerson, int direc);
+	void spinStep(OnScreenPerson *thisPerson);
+	void rethinkAngle(OnScreenPerson *thisPerson);
+	void moveAndScale(OnScreenPerson &me, float x, float y);
+	void setMyDrawMode(OnScreenPerson *moveMe, int h);
+	void shufflePeople();
+	bool handleClosestPoint(int &setX, int &setY, int &setPoly);
+	bool doBorderStuff(OnScreenPerson *moveMe);
+	bool walkMe(OnScreenPerson *thisPerson, bool move = true);
+};
 
 } // End of namespace Sludge
 
diff --git a/engines/sludge/sludge.cpp b/engines/sludge/sludge.cpp
index 483fb53..38fe12a 100644
--- a/engines/sludge/sludge.cpp
+++ b/engines/sludge/sludge.cpp
@@ -29,6 +29,7 @@
 #include "sludge/event.h"
 #include "sludge/fonttext.h"
 #include "sludge/graphics.h"
+#include "sludge/people.h"
 #include "sludge/region.h"
 #include "sludge/sludge.h"
 #include "sludge/sound.h"
@@ -74,6 +75,7 @@ SludgeEngine::SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc)
 	fatalInfo = "Initialisation error! Something went wrong before we even got started!";
 
 	// Init managers
+	_peopleMan = new PeopleManager(this);
 	_resMan = new ResourceManager();
 	_languageMan = new LanguageManager();
 	_objMan = new ObjectManager(this);
@@ -126,6 +128,8 @@ SludgeEngine::~SludgeEngine() {
 	_speechMan = nullptr;
 	delete _regionMan;
 	_regionMan = nullptr;
+	delete _peopleMan;
+	_peopleMan = nullptr;
 }
 
 Common::Error SludgeEngine::run() {
diff --git a/engines/sludge/sludge.h b/engines/sludge/sludge.h
index fa10382..66a443e 100644
--- a/engines/sludge/sludge.h
+++ b/engines/sludge/sludge.h
@@ -41,6 +41,7 @@ extern SludgeEngine *g_sludge;
 class CursorManager;
 class EventManager;
 class GraphicsManager;
+class PeopleManager;
 class RegionManager;
 class SoundManager;
 class SpeechManager;
@@ -90,6 +91,7 @@ public:
 	CursorManager *_cursorMan;
 	SpeechManager *_speechMan;
 	RegionManager *_regionMan;
+	PeopleManager *_peopleMan;
 
 	SludgeEngine(OSystem *syst, const SludgeGameDescription *gameDesc);
 	virtual ~SludgeEngine();
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 01d3b17..4f5f204 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -147,7 +147,7 @@ void initSludge() {
 	g_sludge->_languageMan->init();
 	g_sludge->_gfxMan->init();
 	g_sludge->_resMan->init();
-	initPeople();
+	g_sludge->_peopleMan->init();
 	initFloor();
 	g_sludge->_objMan->init();
 	g_sludge->_speechMan->init();
@@ -179,7 +179,7 @@ void initSludge() {
 
 void killSludge() {
 	killAllFunctions();
-	killAllPeople();
+	g_sludge->_peopleMan->kill();
 	g_sludge->_regionMan->kill();
 	setFloorNull();
 	g_sludge->_speechMan->kill();
@@ -330,7 +330,7 @@ void displayBase() {
 	g_sludge->_gfxMan->clear(); // Clear screen
 	g_sludge->_gfxMan->drawBackDrop();// Draw Backdrop
 	g_sludge->_gfxMan->drawZBuffer(g_sludge->_gfxMan->getCamX(), g_sludge->_gfxMan->getCamY(), false);
-	drawPeople();// Then add any moving characters...
+	g_sludge->_peopleMan->drawPeople();// Then add any moving characters...
 	g_sludge->_gfxMan->displaySpriteLayers();
 }
 
diff --git a/engines/sludge/speech.cpp b/engines/sludge/speech.cpp
index 6324da8..c688bf3 100644
--- a/engines/sludge/speech.cpp
+++ b/engines/sludge/speech.cpp
@@ -61,7 +61,7 @@ void SpeechManager::kill() {
 	}
 
 	if (_speech->currentTalker) {
-		makeSilent(*(_speech->currentTalker));
+		g_sludge->_peopleMan->makeSilent(*(_speech->currentTalker));
 		_speech->currentTalker = NULL;
 	}
 
@@ -176,7 +176,7 @@ int SpeechManager::wrapSpeechPerson(const Common::String &theText, OnScreenPerso
 					- thePerson.thisType->speechGap,
 			thePerson.thisType->wrapSpeech, sampleFile);
 	if (animPerson) {
-		makeTalker(thePerson);
+		g_sludge->_peopleMan->makeTalker(thePerson);
 		_speech->currentTalker = &thePerson;
 	}
 	return i;
@@ -188,7 +188,7 @@ int SpeechManager::wrapSpeech(const Common::String &theText, int objT, int sampl
 	int cameraY = g_sludge->_gfxMan->getCamY();
 
 	_speech->lookWhosTalking = objT;
-	OnScreenPerson *thisPerson = findPerson(objT);
+	OnScreenPerson *thisPerson = g_sludge->_peopleMan->findPerson(objT);
 	if (thisPerson) {
 		setObjFontColour(thisPerson->thisType);
 		i = wrapSpeechPerson(theText, *thisPerson, sampleFile, animPerson);
@@ -274,7 +274,7 @@ bool SpeechManager::load(Common::SeekableReadStream *stream) {
 	_speech->lookWhosTalking = stream->readUint16BE();
 
 	if (stream->readByte()) {
-		_speech->currentTalker = findPerson(stream->readUint16BE());
+		_speech->currentTalker = g_sludge->_peopleMan->findPerson(stream->readUint16BE());
 	} else {
 		_speech->currentTalker = NULL;
 	}
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index 9cbb9f4..ae96dd6 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -65,7 +65,7 @@ void unlinkVar(Variable &thisVar) {
 			break;
 
 		case SVT_ANIM:
-			deleteAnim(thisVar.varData.animHandler);
+			g_sludge->_peopleMan->deleteAnim(thisVar.varData.animHandler);
 			break;
 
 		default:
@@ -87,10 +87,10 @@ void newAnimationVariable(Variable &thisVar, PersonaAnimation  *i) {
 
 PersonaAnimation  *getAnimationFromVar(Variable &thisVar) {
 	if (thisVar.varType == SVT_ANIM)
-		return copyAnim(thisVar.varData.animHandler);
+		return g_sludge->_peopleMan->copyAnim(thisVar.varData.animHandler);
 
 	if (thisVar.varType == SVT_INT && thisVar.varData.intValue == 0)
-		return makeNullAnim();
+		return g_sludge->_peopleMan->makeNullAnim();
 
 	fatal("Expecting an animation variable; found Variable of type", typeName[thisVar.varType]);
 	return NULL;
@@ -116,7 +116,7 @@ Persona *getCostumeFromVar(Variable &thisVar) {
 				return NULL;
 
 			for (int iii = 0; iii < 3; iii++)
-				p->animation[iii] = copyAnim(thisVar.varData.animHandler);
+				p->animation[iii] = g_sludge->_peopleMan->copyAnim(thisVar.varData.animHandler);
 
 			break;
 
@@ -370,7 +370,7 @@ bool copyMain(const Variable &from, Variable &to) {
 			return true;
 
 		case SVT_ANIM:
-			to.varData.animHandler = copyAnim(from.varData.animHandler);
+			to.varData.animHandler = g_sludge->_peopleMan->copyAnim(from.varData.animHandler);
 			return true;
 
 		case SVT_NULL:


Commit: 53c79fdde90f9dfa5467e501c3dcfb19a7494793
    https://github.com/scummvm/scummvm/commit/53c79fdde90f9dfa5467e501c3dcfb19a7494793
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-15T22:10:41+02:00

Commit Message:
SLUDGE: Refactor PersonaAnimation related code in PeopleManager

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/cursors.cpp
    engines/sludge/cursors.h
    engines/sludge/loadsave.cpp
    engines/sludge/people.cpp
    engines/sludge/people.h
    engines/sludge/variable.cpp
    engines/sludge/variable.h


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index e8e9b87..19aa937 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -855,7 +855,7 @@ builtIn(anim) {
 	}
 
 	// First store the frame numbers and take 'em off the stack
-	PersonaAnimation  *ba = g_sludge->_peopleMan->createPersonaAnim(numParams - 1, fun->stack);
+	PersonaAnimation *ba = new PersonaAnimation(numParams - 1, fun->stack);
 
 	// Only remaining paramter is the file number
 	int fileNumber;
@@ -867,7 +867,7 @@ builtIn(anim) {
 	LoadedSpriteBank *sprBanky = g_sludge->_gfxMan->loadBankForAnim(fileNumber);
 	if (!sprBanky)
 		return BR_ERROR;    // File not found, fatal done already
-	g_sludge->_peopleMan->setBankFile(ba, sprBanky);
+	ba->theSprites = sprBanky;
 
 	// Return value
 	newAnimationVariable(fun->reg, ba);
@@ -1589,7 +1589,7 @@ builtIn(animate) {
 		return BR_ERROR;
 	trimStack(fun->stack);
 	g_sludge->_peopleMan->animatePerson(obj, pp);
-	setVariable(fun->reg, SVT_INT, g_sludge->_peopleMan->timeForAnim(pp));
+	setVariable(fun->reg, SVT_INT, pp->getTotalTime());
 	return BR_CONTINUE;
 }
 
diff --git a/engines/sludge/cursors.cpp b/engines/sludge/cursors.cpp
index 849a627..0ec46e2 100644
--- a/engines/sludge/cursors.cpp
+++ b/engines/sludge/cursors.cpp
@@ -44,18 +44,24 @@ CursorManager::~CursorManager() {
 }
 
 void CursorManager::init() {
-	_mouseCursorAnim = _vm->_peopleMan->makeNullAnim();
+	_mouseCursorAnim = new PersonaAnimation();
 	_mouseCursorFrameNum = 0;
 	_mouseCursorCountUp = 0;
 }
 
 void CursorManager::kill() {
-	_vm->_peopleMan->deleteAnim(_mouseCursorAnim);
+	if (_mouseCursorAnim) {
+		delete _mouseCursorAnim;
+		_mouseCursorAnim = nullptr;
+	}
 	_mouseCursorAnim = nullptr;
 }
 
 void CursorManager::pickAnimCursor(PersonaAnimation  *pp) {
-	_vm->_peopleMan->deleteAnim(_mouseCursorAnim);
+	if (_mouseCursorAnim) {
+		delete _mouseCursorAnim;
+		_mouseCursorAnim = nullptr;
+	}
 	_mouseCursorAnim = pp;
 	_mouseCursorFrameNum = 0;
 	_mouseCursorCountUp = 0;
@@ -107,18 +113,21 @@ void CursorManager::pasteCursor(int x, int y, PersonaAnimation  *c) {
 void CursorManager::freeze(FrozenStuffStruct *frozenStuff) {
 	frozenStuff->mouseCursorAnim = _mouseCursorAnim;
 	frozenStuff->mouseCursorFrameNum = _mouseCursorFrameNum;
-	_mouseCursorAnim = _vm->_peopleMan->makeNullAnim();
+	_mouseCursorAnim = new PersonaAnimation();
 	_mouseCursorFrameNum = 0;
 }
 
 void CursorManager::resotre(FrozenStuffStruct *frozenStuff) {
-	_vm->_peopleMan->deleteAnim(_mouseCursorAnim);
+	if (_mouseCursorAnim) {
+		delete _mouseCursorAnim;
+		_mouseCursorAnim = nullptr;
+	}
 	_mouseCursorAnim = frozenStuff->mouseCursorAnim;
 	_mouseCursorFrameNum = frozenStuff->mouseCursorFrameNum;
 }
 
 void CursorManager::saveCursor(Common::WriteStream *stream) {
-	_vm->_peopleMan->saveAnim(_mouseCursorAnim, stream);
+	_mouseCursorAnim->save(stream);
 	stream->writeUint16BE(_mouseCursorFrameNum);
 }
 
@@ -126,7 +135,7 @@ bool CursorManager::loadCursor(Common::SeekableReadStream *stream) {
 	_mouseCursorAnim = new PersonaAnimation;
 	if (!checkNew(_mouseCursorAnim))
 		return false;
-	if (!_vm->_peopleMan->loadAnim(_mouseCursorAnim, stream))
+	if (!_mouseCursorAnim->load(stream))
 		return false;
 	_mouseCursorFrameNum = stream->readUint16BE();
 	return true;
diff --git a/engines/sludge/cursors.h b/engines/sludge/cursors.h
index 4229900..f3c71c2 100644
--- a/engines/sludge/cursors.h
+++ b/engines/sludge/cursors.h
@@ -53,7 +53,7 @@ public:
 private:
 	SludgeEngine *_vm;
 
-	PersonaAnimation  *_mouseCursorAnim;
+	PersonaAnimation *_mouseCursorAnim;
 	int _mouseCursorFrameNum;
 	int _mouseCursorCountUp;
 };
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index bfedcfc..20725ce 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -218,7 +218,7 @@ bool saveVariable(Variable *from, Common::WriteStream *stream) {
 			return false;
 
 		case SVT_ANIM:
-			g_sludge->_peopleMan->saveAnim(from->varData.animHandler, stream);
+			from->varData.animHandler->save(stream);
 			return false;
 
 		case SVT_NULL:
@@ -260,7 +260,7 @@ bool loadVariable(Variable *to, Common::SeekableReadStream *stream) {
 			to->varData.animHandler = new PersonaAnimation ;
 			if (!checkNew(to->varData.animHandler))
 				return false;
-			g_sludge->_peopleMan->loadAnim(to->varData.animHandler, stream);
+			to->varData.animHandler->load(stream);
 			return true;
 
 		default:
diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp
index a43f0f1..1574166 100644
--- a/engines/sludge/people.cpp
+++ b/engines/sludge/people.cpp
@@ -50,42 +50,32 @@ extern VariableStack *noStack;
 extern int ssgVersion;
 extern Floor *currentFloor;
 
-PeopleManager::PeopleManager(SludgeEngine *vm) {
-	_vm = vm;
-	_allPeople = nullptr;
-	_scaleHorizon = 75;
-	_scaleDivide = 150;
-	_personRegion = new ScreenRegion;
-}
-
-PeopleManager::~PeopleManager() {
-	kill();
-
-	delete _personRegion;
-	_personRegion = nullptr;
+PersonaAnimation::PersonaAnimation() {
+	theSprites = nullptr;
+	numFrames = 0;
+	frames = nullptr;
 }
 
-void PeopleManager::setFrames(OnScreenPerson &m, int a) {
-	m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction];
+PersonaAnimation::~PersonaAnimation() {
+	if (numFrames) {
+		delete[] frames;
+		frames = nullptr;
+	}
 }
 
-PersonaAnimation *PeopleManager::createPersonaAnim(int num, VariableStack *&stacky) {
-	PersonaAnimation *newP = new PersonaAnimation ;
-	checkNew(newP);
-
-	newP->numFrames = num;
-	newP->frames = new AnimFrame [num];
-	checkNew(newP->frames);
-
+PersonaAnimation::PersonaAnimation(int num, VariableStack *&stacky) {
+	theSprites = nullptr;
+	numFrames = num;
+	frames = new AnimFrame[num];
 	int a = num, frameNum, howMany;
 
 	while (a) {
 		a--;
-		newP->frames[a].noise = 0;
+		frames[a].noise = 0;
 		if (stacky->thisVar.varType == SVT_FILE) {
-			newP->frames[a].noise = stacky->thisVar.varData.intValue;
+			frames[a].noise = stacky->thisVar.varData.intValue;
 		} else if (stacky->thisVar.varType == SVT_FUNC) {
-			newP->frames[a].noise = -stacky->thisVar.varData.intValue;
+			frames[a].noise = -stacky->thisVar.varData.intValue;
 		} else if (stacky->thisVar.varType == SVT_STACK) {
 			getValueType(frameNum, SVT_INT, stacky->thisVar.varData.theStack->first->thisVar);
 			getValueType(howMany, SVT_INT, stacky->thisVar.varData.theStack->first->next->thisVar);
@@ -94,64 +84,97 @@ PersonaAnimation *PeopleManager::createPersonaAnim(int num, VariableStack *&stac
 			howMany = 1;
 		}
 		trimStack(stacky);
-		newP->frames[a].frameNum = frameNum;
-		newP->frames[a].howMany = howMany;
+		frames[a].frameNum = frameNum;
+		frames[a].howMany = howMany;
 	}
-
-	return newP;
-}
-
-PersonaAnimation *PeopleManager::makeNullAnim() {
-	PersonaAnimation *newAnim = new PersonaAnimation ;
-	if (!checkNew(newAnim))
-		return NULL;
-
-	newAnim->theSprites = NULL;
-	newAnim->numFrames = 0;
-	newAnim->frames = NULL;
-	return newAnim;
 }
 
-PersonaAnimation *PeopleManager::copyAnim(PersonaAnimation *orig) {
+PersonaAnimation::PersonaAnimation(PersonaAnimation *orig) {
 	int num = orig->numFrames;
 
-	PersonaAnimation *newAnim = new PersonaAnimation ;
-	if (!checkNew(newAnim))
-		return NULL;
-
 	// Copy the easy bits...
-	newAnim->theSprites = orig->theSprites;
-	newAnim->numFrames = num;
+	theSprites = orig->theSprites;
+	numFrames = num;
 
 	if (num) {
-
-		// Argh!Frames!We need a whole NEW array of AnimFrame  structures...
-
-		newAnim->frames = new AnimFrame [num];
-		if (!checkNew(newAnim->frames))
-			return NULL;
+		// Argh! Frames! We need a whole NEW array of AnimFrame  structures...
+		frames = new AnimFrame[num];
 
 		for (int a = 0; a < num; a++) {
-			newAnim->frames[a].frameNum = orig->frames[a].frameNum;
-			newAnim->frames[a].howMany = orig->frames[a].howMany;
-			newAnim->frames[a].noise = orig->frames[a].noise;
+			frames[a].frameNum = orig->frames[a].frameNum;
+			frames[a].howMany = orig->frames[a].howMany;
+			frames[a].noise = orig->frames[a].noise;
 		}
 	} else {
-		newAnim->frames = NULL;
+		frames = nullptr;
 	}
+}
 
-	return newAnim;
+int PersonaAnimation::getTotalTime() {
+	int total = 0;
+	for (int a = 0; a < numFrames; a++) {
+		total += frames[a].howMany;
+	}
+	return total;
 }
 
-void PeopleManager::deleteAnim(PersonaAnimation *orig) {
+bool PersonaAnimation::save(Common::WriteStream *stream) {
+	stream->writeUint16BE(numFrames);
+	if (numFrames) {
+		stream->writeUint32LE(theSprites->ID);
 
-	if (orig) {
-		if (orig->numFrames) {
-			delete[] orig->frames;
+		for (int a = 0; a < numFrames; a++) {
+			stream->writeUint32LE(frames[a].frameNum);
+			stream->writeUint32LE(frames[a].howMany);
+			stream->writeUint32LE(frames[a].noise);
 		}
-		delete orig;
-		orig = NULL;
 	}
+	return true;
+}
+
+bool PersonaAnimation::load(Common::SeekableReadStream *stream) {
+	numFrames = stream->readUint16BE();
+
+	if (numFrames) {
+		int a = stream->readUint32LE();
+		frames = new AnimFrame [numFrames];
+		if (!checkNew(frames))
+			return false;
+		theSprites = g_sludge->_gfxMan->loadBankForAnim(a);
+
+		for (a = 0; a < numFrames; a++) {
+			frames[a].frameNum = stream->readUint32LE();
+			frames[a].howMany = stream->readUint32LE();
+			if (ssgVersion >= VERSION(2, 0)) {
+				frames[a].noise = stream->readUint32LE();
+			} else {
+				frames[a].noise = 0;
+			}
+		}
+	} else {
+		theSprites = NULL;
+		frames = NULL;
+	}
+	return true;
+}
+
+PeopleManager::PeopleManager(SludgeEngine *vm) {
+	_vm = vm;
+	_allPeople = nullptr;
+	_scaleHorizon = 75;
+	_scaleDivide = 150;
+	_personRegion = new ScreenRegion;
+}
+
+PeopleManager::~PeopleManager() {
+	kill();
+
+	delete _personRegion;
+	_personRegion = nullptr;
+}
+
+void PeopleManager::setFrames(OnScreenPerson &m, int a) {
+	m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction];
 }
 
 void PeopleManager::turnMeAngle(OnScreenPerson *thisPerson, int direc) {
@@ -859,14 +882,6 @@ bool PeopleManager::addPerson(int x, int y, int objNum, Persona *p) {
 	return (bool)(newPerson->thisType != NULL);
 }
 
-int PeopleManager::timeForAnim(PersonaAnimation *fram) {
-	int total = 0;
-	for (int a = 0; a < fram->numFrames; a++) {
-		total += fram->frames[a].howMany;
-	}
-	return total;
-}
-
 void PeopleManager::animatePerson(int obj, PersonaAnimation *fram) { // Set a new SINGLE animation
 	OnScreenPerson *moveMe = findPerson(obj);
 	if (moveMe) {
@@ -956,51 +971,11 @@ void PeopleManager::removeOneCharacter(int i) {
 	}
 }
 
-bool PeopleManager::saveAnim(PersonaAnimation *p, Common::WriteStream *stream) {
-	stream->writeUint16BE(p->numFrames);
-	if (p->numFrames) {
-		stream->writeUint32LE(p->theSprites->ID);
-
-		for (int a = 0; a < p->numFrames; a++) {
-			stream->writeUint32LE(p->frames[a].frameNum);
-			stream->writeUint32LE(p->frames[a].howMany);
-			stream->writeUint32LE(p->frames[a].noise);
-		}
-	}
-	return true;
-}
-
-bool PeopleManager::loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream) {
-	p->numFrames = stream->readUint16BE();
-
-	if (p->numFrames) {
-		int a = stream->readUint32LE();
-		p->frames = new AnimFrame [p->numFrames];
-		if (!checkNew(p->frames))
-			return false;
-		p->theSprites = g_sludge->_gfxMan->loadBankForAnim(a);
-
-		for (a = 0; a < p->numFrames; a++) {
-			p->frames[a].frameNum = stream->readUint32LE();
-			p->frames[a].howMany = stream->readUint32LE();
-			if (ssgVersion >= VERSION(2, 0)) {
-				p->frames[a].noise = stream->readUint32LE();
-			} else {
-				p->frames[a].noise = 0;
-			}
-		}
-	} else {
-		p->theSprites = NULL;
-		p->frames = NULL;
-	}
-	return true;
-}
-
 bool PeopleManager::saveCostume(Persona *cossy, Common::WriteStream *stream) {
 	int a;
 	stream->writeUint16BE(cossy->numDirections);
 	for (a = 0; a < cossy->numDirections * 3; a++) {
-		if (!saveAnim(cossy->animation[a], stream))
+		if (!cossy->animation[a]->save(stream))
 			return false;
 	}
 	return true;
@@ -1017,7 +992,7 @@ bool PeopleManager::loadCostume(Persona *cossy, Common::SeekableReadStream *stre
 		if (!checkNew(cossy->animation[a]))
 			return false;
 
-		if (!loadAnim(cossy->animation[a], stream))
+		if (!cossy->animation[a]->load(stream))
 			return false;
 	}
 	return true;
@@ -1044,7 +1019,7 @@ bool PeopleManager::savePeople(Common::WriteStream *stream) {
 		stream->writeFloatLE(me->y);
 
 		saveCostume(me->myPersona, stream);
-		saveAnim(me->myAnim, stream);
+		me->myAnim->save(stream);
 		stream->writeByte(me->myAnim == me->lastUsedAnim);
 
 		stream->writeFloatLE(me->scale);
@@ -1120,7 +1095,7 @@ bool PeopleManager::loadPeople(Common::SeekableReadStream *stream) {
 		me->y = stream->readFloatLE();
 
 		loadCostume(me->myPersona, stream);
-		loadAnim(me->myAnim, stream);
+		me->myAnim->load(stream);
 
 		me->lastUsedAnim = stream->readByte() ? me->myAnim : NULL;
 
diff --git a/engines/sludge/people.h b/engines/sludge/people.h
index 3fe4194..86ada69 100644
--- a/engines/sludge/people.h
+++ b/engines/sludge/people.h
@@ -27,6 +27,7 @@
 namespace Sludge {
 
 struct FrozenStuffStruct;
+struct LoadedSpriteBank;
 struct ScreenRegion;
 
 struct AnimFrame {
@@ -44,9 +45,21 @@ struct AnimFrame {
 #define EXTRA_RECTANGULAR   64
 
 struct PersonaAnimation {
-	struct LoadedSpriteBank *theSprites;
+	LoadedSpriteBank *theSprites;
 	AnimFrame *frames;
 	int numFrames;
+
+	PersonaAnimation();
+	PersonaAnimation(int num, struct VariableStack *&stacky);
+	PersonaAnimation(PersonaAnimation *orig);
+	~PersonaAnimation();
+
+	// Setter & getter
+	int getTotalTime();
+
+	// Save & load
+	bool save(Common::WriteStream *stream);
+	bool load(Common::SeekableReadStream *stream);
 };
 
 struct Persona {
@@ -117,19 +130,9 @@ public:
 	// Animating 'em
 	void animatePerson(int obj, PersonaAnimation *);
 	void animatePerson(int obj, Persona *per);
-	PersonaAnimation *createPersonaAnim(int num, struct VariableStack *&stacky);
-	inline void setBankFile(PersonaAnimation *newP, LoadedSpriteBank *sB) {
-		newP->theSprites = sB;
-	}
 	bool setPersonExtra(int f, int newSetting);
-	int timeForAnim(PersonaAnimation *fram);
-	PersonaAnimation *copyAnim(PersonaAnimation *orig);
-	PersonaAnimation *makeNullAnim();
-	void deleteAnim(PersonaAnimation *orig);
 
 	// Loading and saving
-	bool saveAnim(PersonaAnimation *p, Common::WriteStream *stream);
-	bool loadAnim(PersonaAnimation *p, Common::SeekableReadStream *stream);
 	bool savePeople(Common::WriteStream *stream);
 	bool loadPeople(Common::SeekableReadStream *stream);
 	bool saveCostume(Persona *cossy, Common::WriteStream *stream);
diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp
index ae96dd6..5537377 100644
--- a/engines/sludge/variable.cpp
+++ b/engines/sludge/variable.cpp
@@ -65,7 +65,10 @@ void unlinkVar(Variable &thisVar) {
 			break;
 
 		case SVT_ANIM:
-			g_sludge->_peopleMan->deleteAnim(thisVar.varData.animHandler);
+			if (thisVar.varData.animHandler) {
+				delete thisVar.varData.animHandler;
+				thisVar.varData.animHandler = nullptr;
+			}
 			break;
 
 		default:
@@ -85,12 +88,12 @@ void newAnimationVariable(Variable &thisVar, PersonaAnimation  *i) {
 	thisVar.varData.animHandler = i;
 }
 
-PersonaAnimation  *getAnimationFromVar(Variable &thisVar) {
+PersonaAnimation *getAnimationFromVar(Variable &thisVar) {
 	if (thisVar.varType == SVT_ANIM)
-		return g_sludge->_peopleMan->copyAnim(thisVar.varData.animHandler);
+		return new PersonaAnimation(thisVar.varData.animHandler);
 
 	if (thisVar.varType == SVT_INT && thisVar.varData.intValue == 0)
-		return g_sludge->_peopleMan->makeNullAnim();
+		return new PersonaAnimation();
 
 	fatal("Expecting an animation variable; found Variable of type", typeName[thisVar.varType]);
 	return NULL;
@@ -116,7 +119,7 @@ Persona *getCostumeFromVar(Variable &thisVar) {
 				return NULL;
 
 			for (int iii = 0; iii < 3; iii++)
-				p->animation[iii] = g_sludge->_peopleMan->copyAnim(thisVar.varData.animHandler);
+				p->animation[iii] = new PersonaAnimation(thisVar.varData.animHandler);
 
 			break;
 
@@ -370,7 +373,7 @@ bool copyMain(const Variable &from, Variable &to) {
 			return true;
 
 		case SVT_ANIM:
-			to.varData.animHandler = g_sludge->_peopleMan->copyAnim(from.varData.animHandler);
+			to.varData.animHandler = new PersonaAnimation(from.varData.animHandler);
 			return true;
 
 		case SVT_NULL:
diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h
index 005eb1c..a3cc57d 100644
--- a/engines/sludge/variable.h
+++ b/engines/sludge/variable.h
@@ -24,6 +24,8 @@
 
 namespace Sludge {
 
+struct Persona;
+struct PersonaAnimation;
 struct Variable;
 struct VariableStack;
 
@@ -58,8 +60,8 @@ union VariableData {
 	signed int intValue;
 	const char *theString;
 	StackHandler *theStack;
-	struct PersonaAnimation  *animHandler;
-	struct Persona *costumeHandler;
+	PersonaAnimation *animHandler;
+	Persona *costumeHandler;
 	FastArrayHandler *fastArray;
 };
 


Commit: 2cf79dc67c8c904833e7c16b71b7f6fb64d6d011
    https://github.com/scummvm/scummvm/commit/2cf79dc67c8c904833e7c16b71b7f6fb64d6d011
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-15T22:10:41+02:00

Commit Message:
SLUDGE: Refactor save/load costume to Persona

Changed paths:
    engines/sludge/loadsave.cpp
    engines/sludge/people.cpp
    engines/sludge/people.h


diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index 20725ce..9d0a008 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -214,7 +214,7 @@ bool saveVariable(Variable *from, Common::WriteStream *stream) {
 			return saveStackRef(from->varData.theStack, stream);
 
 		case SVT_COSTUME:
-			g_sludge->_peopleMan->saveCostume(from->varData.costumeHandler, stream);
+			from->varData.costumeHandler->save(stream);
 			return false;
 
 		case SVT_ANIM:
@@ -253,7 +253,7 @@ bool loadVariable(Variable *to, Common::SeekableReadStream *stream) {
 			to->varData.costumeHandler = new Persona;
 			if (!checkNew(to->varData.costumeHandler))
 				return false;
-			g_sludge->_peopleMan->loadCostume(to->varData.costumeHandler, stream);
+			to->varData.costumeHandler->load(stream);
 			return true;
 
 		case SVT_ANIM:
diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp
index 1574166..27301c2 100644
--- a/engines/sludge/people.cpp
+++ b/engines/sludge/people.cpp
@@ -158,6 +158,33 @@ bool PersonaAnimation::load(Common::SeekableReadStream *stream) {
 	return true;
 }
 
+bool Persona::save(Common::WriteStream *stream) {
+	int a;
+	stream->writeUint16BE(numDirections);
+	for (a = 0; a < numDirections * 3; a++) {
+		if (!animation[a]->save(stream))
+			return false;
+	}
+	return true;
+}
+
+bool Persona::load(Common::SeekableReadStream *stream) {
+	int a;
+	numDirections = stream->readUint16BE();
+	animation = new PersonaAnimation *[numDirections * 3];
+	if (!checkNew(animation))
+		return false;
+	for (a = 0; a < numDirections * 3; a++) {
+		animation[a] = new PersonaAnimation ;
+		if (!checkNew(animation[a]))
+			return false;
+
+		if (!animation[a]->load(stream))
+			return false;
+	}
+	return true;
+}
+
 PeopleManager::PeopleManager(SludgeEngine *vm) {
 	_vm = vm;
 	_allPeople = nullptr;
@@ -971,33 +998,6 @@ void PeopleManager::removeOneCharacter(int i) {
 	}
 }
 
-bool PeopleManager::saveCostume(Persona *cossy, Common::WriteStream *stream) {
-	int a;
-	stream->writeUint16BE(cossy->numDirections);
-	for (a = 0; a < cossy->numDirections * 3; a++) {
-		if (!cossy->animation[a]->save(stream))
-			return false;
-	}
-	return true;
-}
-
-bool PeopleManager::loadCostume(Persona *cossy, Common::SeekableReadStream *stream) {
-	int a;
-	cossy->numDirections = stream->readUint16BE();
-	cossy->animation = new PersonaAnimation *[cossy->numDirections * 3];
-	if (!checkNew(cossy->animation))
-		return false;
-	for (a = 0; a < cossy->numDirections * 3; a++) {
-		cossy->animation[a] = new PersonaAnimation ;
-		if (!checkNew(cossy->animation[a]))
-			return false;
-
-		if (!cossy->animation[a]->load(stream))
-			return false;
-	}
-	return true;
-}
-
 bool PeopleManager::savePeople(Common::WriteStream *stream) {
 	OnScreenPerson *me = _allPeople;
 	int countPeople = 0, a;
@@ -1018,7 +1018,7 @@ bool PeopleManager::savePeople(Common::WriteStream *stream) {
 		stream->writeFloatLE(me->x);
 		stream->writeFloatLE(me->y);
 
-		saveCostume(me->myPersona, stream);
+		me->myPersona->save(stream);
 		me->myAnim->save(stream);
 		stream->writeByte(me->myAnim == me->lastUsedAnim);
 
@@ -1094,7 +1094,7 @@ bool PeopleManager::loadPeople(Common::SeekableReadStream *stream) {
 		me->x = stream->readFloatLE();
 		me->y = stream->readFloatLE();
 
-		loadCostume(me->myPersona, stream);
+		me->myPersona->load(stream);
 		me->myAnim->load(stream);
 
 		me->lastUsedAnim = stream->readByte() ? me->myAnim : NULL;
diff --git a/engines/sludge/people.h b/engines/sludge/people.h
index 86ada69..baf127c 100644
--- a/engines/sludge/people.h
+++ b/engines/sludge/people.h
@@ -65,6 +65,10 @@ struct PersonaAnimation {
 struct Persona {
 	PersonaAnimation **animation;
 	int numDirections;
+
+	// Save & load
+	bool save(Common::WriteStream *stream);
+	bool load(Common::SeekableReadStream *stream);
 };
 
 struct OnScreenPerson {
@@ -135,8 +139,6 @@ public:
 	// Loading and saving
 	bool savePeople(Common::WriteStream *stream);
 	bool loadPeople(Common::SeekableReadStream *stream);
-	bool saveCostume(Persona *cossy, Common::WriteStream *stream);
-	bool loadCostume(Persona *cossy, Common::SeekableReadStream *stream);
 
 	// Freeze
 	void freeze(FrozenStuffStruct *frozenStuff);


Commit: db1f09a0c2f799ab0feca363b7b0e8f3d5c03de6
    https://github.com/scummvm/scummvm/commit/db1f09a0c2f799ab0feca363b7b0e8f3d5c03de6
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-15T22:10:41+02:00

Commit Message:
SLUDGE: Refactor OnScreenPerson related public method in PeopleManager

Changed paths:
    engines/sludge/people.cpp
    engines/sludge/people.h
    engines/sludge/speech.cpp


diff --git a/engines/sludge/people.cpp b/engines/sludge/people.cpp
index 27301c2..7a70e62 100644
--- a/engines/sludge/people.cpp
+++ b/engines/sludge/people.cpp
@@ -185,6 +185,18 @@ bool Persona::load(Common::SeekableReadStream *stream) {
 	return true;
 }
 
+void OnScreenPerson::setFrames(int a) {
+	myAnim = myPersona->animation[(a * myPersona->numDirections) + direction];
+}
+
+void OnScreenPerson::makeTalker() {
+	setFrames(ANI_TALK);
+}
+
+void OnScreenPerson::makeSilent() {
+	setFrames(ANI_STAND);
+}
+
 PeopleManager::PeopleManager(SludgeEngine *vm) {
 	_vm = vm;
 	_allPeople = nullptr;
@@ -200,10 +212,6 @@ PeopleManager::~PeopleManager() {
 	_personRegion = nullptr;
 }
 
-void PeopleManager::setFrames(OnScreenPerson &m, int a) {
-	m.myAnim = m.myPersona->animation[(a * m.myPersona->numDirections) + m.direction];
-}
-
 void PeopleManager::turnMeAngle(OnScreenPerson *thisPerson, int direc) {
 	int d = thisPerson->myPersona->numDirections;
 	thisPerson->angle = direc;
@@ -254,7 +262,8 @@ bool PeopleManager::turnPersonToFace(int thisNum, int direc) {
 		thisPerson->walking = false;
 		thisPerson->spinning = false;
 		turnMeAngle(thisPerson, direc);
-		setFrames(*thisPerson, g_sludge->_speechMan->isCurrentTalker(thisPerson) ? ANI_TALK : ANI_STAND);
+		_vm->_speechMan->isCurrentTalker(thisPerson) ?
+				thisPerson->makeTalker() : thisPerson->makeSilent();
 		return true;
 	}
 	return false;
@@ -497,7 +506,7 @@ void PeopleManager::drawPeople() {
 
 	OnScreenPerson *thisPerson = _allPeople;
 	PersonaAnimation *myAnim = NULL;
-	g_sludge->_regionMan->resetOverRegion();
+	_vm->_regionMan->resetOverRegion();
 
 	while (thisPerson) {
 		if (thisPerson->show) {
@@ -507,7 +516,7 @@ void PeopleManager::drawPeople() {
 				thisPerson->frameNum = 0;
 				thisPerson->frameTick = myAnim->frames[0].howMany;
 				if (myAnim->frames[thisPerson->frameNum].noise > 0) {
-					g_sludge->_soundMan->startSound(myAnim->frames[thisPerson->frameNum].noise, false);
+					_vm->_soundMan->startSound(myAnim->frames[thisPerson->frameNum].noise, false);
 					thisPerson->frameNum++;
 					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
 					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
@@ -528,13 +537,13 @@ void PeopleManager::drawPeople() {
 			}
 			if (m != 2) {
 				bool r = false;
-				r = g_sludge->_gfxMan->scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim->theSprites->bank.myPalette, thisPerson, m);
+				r = _vm->_gfxMan->scaleSprite(myAnim->theSprites->bank.sprites[fNum], myAnim->theSprites->bank.myPalette, thisPerson, m);
 				if (r) {
 					if (!thisPerson->thisType->screenName.empty()) {
 						if (_personRegion->thisType != thisPerson->thisType)
-							g_sludge->_regionMan->resetLastRegion();
+							_vm->_regionMan->resetLastRegion();
 						_personRegion->thisType = thisPerson->thisType;
-						g_sludge->_regionMan->setOverRegion(_personRegion);
+						_vm->_regionMan->setOverRegion(_personRegion);
 					}
 				}
 			}
@@ -545,7 +554,7 @@ void PeopleManager::drawPeople() {
 			thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
 			if (thisPerson->show && myAnim && myAnim->frames) {
 				if (myAnim->frames[thisPerson->frameNum].noise > 0) {
-					g_sludge->_soundMan->startSound(myAnim->frames[thisPerson->frameNum].noise, false);
+					_vm->_soundMan->startSound(myAnim->frames[thisPerson->frameNum].noise, false);
 					thisPerson->frameNum++;
 					thisPerson->frameNum %= thisPerson->myAnim->numFrames;
 					thisPerson->frameTick = thisPerson->myAnim->frames[thisPerson->frameNum].howMany;
@@ -562,14 +571,6 @@ void PeopleManager::drawPeople() {
 	}
 }
 
-void PeopleManager::makeTalker(OnScreenPerson &me) {
-	setFrames(me, ANI_TALK);
-}
-
-void PeopleManager::makeSilent(OnScreenPerson &me) {
-	setFrames(me, ANI_STAND);
-}
-
 bool PeopleManager::handleClosestPoint(int &setX, int &setY, int &setPoly) {
 	int gotX = 320, gotY = 200, gotPoly = -1, i, j, xTest1, yTest1, xTest2, yTest2, closestX, closestY, oldJ, currentDistance = 0xFFFFF, thisDistance;
 
@@ -670,7 +671,7 @@ bool PeopleManager::doBorderStuff(OnScreenPerson *moveMe) {
 		moveMe->spinning = true;
 	}
 
-	setFrames(*moveMe, ANI_WALK);
+	moveMe->setFrames(ANI_WALK);
 	return true;
 }
 
@@ -689,7 +690,7 @@ bool PeopleManager::walkMe(OnScreenPerson *thisPerson, bool move) {
 		if (ABS(maxDiff) > s) {
 			if (thisPerson->spinning) {
 				spinStep(thisPerson);
-				setFrames(*thisPerson, ANI_WALK);
+				thisPerson->setFrames(ANI_WALK);
 			}
 			s = maxDiff / s;
 			if (move)
@@ -710,7 +711,7 @@ bool PeopleManager::walkMe(OnScreenPerson *thisPerson, bool move) {
 	}
 
 	thisPerson->walking = false;
-	setFrames(*thisPerson, ANI_STAND);
+	thisPerson->setFrames(ANI_STAND);
 	moveAndScale(*thisPerson, thisPerson->walkToX, thisPerson->walkToY);
 	return false;
 }
@@ -762,7 +763,7 @@ bool PeopleManager::stopPerson(int o) {
 			moveMe->continueAfterWalking = NULL;
 			moveMe->walking = false;
 			moveMe->spinning = false;
-			setFrames(*moveMe, ANI_STAND);
+			moveMe->setFrames(ANI_STAND);
 			return true;
 		}
 	return false;
@@ -838,7 +839,7 @@ void PeopleManager::walkAllPeople() {
 			walkMe(thisPerson);
 		} else if (thisPerson->spinning) {
 			spinStep(thisPerson);
-			setFrames(*thisPerson, ANI_STAND);
+			thisPerson->setFrames(ANI_STAND);
 		}
 		if ((!thisPerson->walking) && (!thisPerson->spinning) && thisPerson->continueAfterWalking) {
 			restartFunction(thisPerson->continueAfterWalking);
@@ -854,7 +855,7 @@ bool PeopleManager::addPerson(int x, int y, int objNum, Persona *p) {
 		return false;
 
 	// EASY STUFF
-	newPerson->thisType = g_sludge->_objMan->loadObjectType(objNum);
+	newPerson->thisType = _vm->_objMan->loadObjectType(objNum);
 	newPerson->scale = 1;
 	newPerson->extra = 0;
 	newPerson->continueAfterWalking = NULL;
@@ -882,7 +883,7 @@ bool PeopleManager::addPerson(int x, int y, int objNum, Persona *p) {
 	newPerson->lastUsedAnim = 0;
 	newPerson->frameTick = 0;
 
-	setFrames(*newPerson, ANI_STAND);
+	newPerson->setFrames(ANI_STAND);
 
 	// HEIGHT (BASED ON 1st FRAME OF 1st ANIMATION... INC. SPECIAL CASES)
 	int fNumSigned = p->animation[0]->frames[0].frameNum;
@@ -931,9 +932,9 @@ void PeopleManager::animatePerson(int obj, Persona *per) {             // Set a
 		moveMe->myPersona = per;
 		rethinkAngle(moveMe);
 		if (moveMe->walking) {
-			setFrames(*moveMe, ANI_WALK);
+			moveMe->setFrames(ANI_WALK);
 		} else {
-			setFrames(*moveMe, ANI_STAND);
+			moveMe->setFrames(ANI_STAND);
 		}
 	}
 }
@@ -946,7 +947,7 @@ void PeopleManager::kill() {
 		_allPeople->continueAfterWalking = NULL;
 		killPeople = _allPeople;
 		_allPeople = _allPeople->next;
-		g_sludge->_objMan->removeObjectType(killPeople->thisType);
+		_vm->_objMan->removeObjectType(killPeople->thisType);
 		delete killPeople;
 	}
 }
@@ -968,7 +969,7 @@ void PeopleManager::killMostPeople() {
 			if (killPeople->continueAfterWalking)
 				abortFunction(killPeople->continueAfterWalking);
 			killPeople->continueAfterWalking = NULL;
-			g_sludge->_objMan->removeObjectType(killPeople->thisType);
+			_vm->_objMan->removeObjectType(killPeople->thisType);
 			delete killPeople;
 		}
 	}
@@ -978,7 +979,7 @@ void PeopleManager::removeOneCharacter(int i) {
 	OnScreenPerson *p = findPerson(i);
 
 	if (p) {
-		ScreenRegion *overRegion = g_sludge->_regionMan->getOverRegion();
+		ScreenRegion *overRegion = _vm->_regionMan->getOverRegion();
 		if (overRegion == _personRegion && overRegion->thisType == p->thisType) {
 			overRegion = nullptr;
 		}
@@ -993,7 +994,7 @@ void PeopleManager::removeOneCharacter(int i) {
 		}
 
 		*killPeople = p->next;
-		g_sludge->_objMan->removeObjectType(p->thisType);
+		_vm->_objMan->removeObjectType(p->thisType);
 		delete p;
 	}
 }
@@ -1058,7 +1059,7 @@ bool PeopleManager::savePeople(Common::WriteStream *stream) {
 		stream->writeByte(me->colourmix);
 		stream->writeByte(me->transparency);
 
-		g_sludge->_objMan->saveObjectRef(me->thisType, stream);
+		_vm->_objMan->saveObjectRef(me->thisType, stream);
 
 		me = me->next;
 	}
@@ -1142,7 +1143,7 @@ bool PeopleManager::loadPeople(Common::SeekableReadStream *stream) {
 		} else {
 			setMyDrawMode(me, stream->readUint16BE());
 		}
-		me->thisType = g_sludge->_objMan->loadObjectRef(stream);
+		me->thisType = _vm->_objMan->loadObjectRef(stream);
 
 		// Anti-aliasing settings
 		if (ssgVersion >= VERSION(1, 6)) {
diff --git a/engines/sludge/people.h b/engines/sludge/people.h
index baf127c..60ad672 100644
--- a/engines/sludge/people.h
+++ b/engines/sludge/people.h
@@ -88,6 +88,10 @@ struct OnScreenPerson {
 	struct ObjectType *thisType;
 	int extra, spinSpeed;
 	byte r, g, b, colourmix, transparency;
+
+	void makeTalker();
+	void makeSilent();
+	void setFrames(int a);
 };
 
 class PeopleManager {
@@ -113,8 +117,6 @@ public:
 	void setScale(int16 h, int16 d);
 
 	// Things which affect one character
-	void makeTalker(OnScreenPerson &me);
-	void makeSilent(OnScreenPerson &me);
 	void setShown(bool h, int ob);
 	void setDrawMode(int h, int ob);
 	void setPersonTransparency(int ob, byte x);
@@ -152,14 +154,15 @@ private:
 
 	SludgeEngine *_vm;
 
-	void setFrames(OnScreenPerson &m, int a);
+	void shufflePeople();
+	bool handleClosestPoint(int &setX, int &setY, int &setPoly);
+
+	// OnScreenPerson manipulation
 	void turnMeAngle(OnScreenPerson *thisPerson, int direc);
 	void spinStep(OnScreenPerson *thisPerson);
 	void rethinkAngle(OnScreenPerson *thisPerson);
 	void moveAndScale(OnScreenPerson &me, float x, float y);
 	void setMyDrawMode(OnScreenPerson *moveMe, int h);
-	void shufflePeople();
-	bool handleClosestPoint(int &setX, int &setY, int &setPoly);
 	bool doBorderStuff(OnScreenPerson *moveMe);
 	bool walkMe(OnScreenPerson *thisPerson, bool move = true);
 };
diff --git a/engines/sludge/speech.cpp b/engines/sludge/speech.cpp
index c688bf3..cac4a5e 100644
--- a/engines/sludge/speech.cpp
+++ b/engines/sludge/speech.cpp
@@ -61,8 +61,8 @@ void SpeechManager::kill() {
 	}
 
 	if (_speech->currentTalker) {
-		g_sludge->_peopleMan->makeSilent(*(_speech->currentTalker));
-		_speech->currentTalker = NULL;
+		_speech->currentTalker->makeSilent();
+		_speech->currentTalker = nullptr;
 	}
 
 	SpeechLine *killMe;
@@ -176,7 +176,7 @@ int SpeechManager::wrapSpeechPerson(const Common::String &theText, OnScreenPerso
 					- thePerson.thisType->speechGap,
 			thePerson.thisType->wrapSpeech, sampleFile);
 	if (animPerson) {
-		g_sludge->_peopleMan->makeTalker(thePerson);
+		thePerson.makeTalker();
 		_speech->currentTalker = &thePerson;
 	}
 	return i;





More information about the Scummvm-git-logs mailing list