[Scummvm-git-logs] scummvm master -> 91db7c5967646c972f0f169811cb9033c354330d

yinsimei roseline.yin at gmail.com
Sun Apr 15 01:10:07 CEST 2018


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

Summary:
b575aac25a SLUDGE: Rename KillAll to Kill in RegionManager
91db7c5967 SLUDGE: Replace linked list by Common::List in RegionManager


Commit: b575aac25a8aaa8409d4729e2cc2044e96681524
    https://github.com/scummvm/scummvm/commit/b575aac25a8aaa8409d4729e2cc2044e96681524
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-15T01:09:35+02:00

Commit Message:
SLUDGE: Rename KillAll to Kill in RegionManager

Changed paths:
    engines/sludge/builtin.cpp
    engines/sludge/freeze.cpp
    engines/sludge/loadsave.cpp
    engines/sludge/region.cpp
    engines/sludge/region.h
    engines/sludge/sludger.cpp


diff --git a/engines/sludge/builtin.cpp b/engines/sludge/builtin.cpp
index 4d4726a..d6cfbb5 100644
--- a/engines/sludge/builtin.cpp
+++ b/engines/sludge/builtin.cpp
@@ -1428,7 +1428,7 @@ builtIn(showBoxes) {
 
 builtIn(removeAllScreenRegions) {
 	UNUSEDALL
-	g_sludge->_regionMan->killAll();
+	g_sludge->_regionMan->kill();
 	return BR_CONTINUE;
 }
 
diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp
index 2df8f55..15125db 100644
--- a/engines/sludge/freeze.cpp
+++ b/engines/sludge/freeze.cpp
@@ -136,7 +136,7 @@ void GraphicsManager::unfreeze(bool killImage) {
 	killAllPeople();
 	allPeople = _frozenStuff->allPeople;
 
-	g_sludge->_regionMan->killAll();
+	g_sludge->_regionMan->kill();
 	g_sludge->_regionMan->resotre(_frozenStuff);
 
 	killLightMap();
diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp
index bd4b383..2a69d02 100644
--- a/engines/sludge/loadsave.cpp
+++ b/engines/sludge/loadsave.cpp
@@ -504,7 +504,7 @@ bool loadGame(const Common::String &fname) {
 	g_sludge->_txtMan->loadFont(ssgVersion, fp);
 
 	killAllPeople();
-	g_sludge->_regionMan->killAll();
+	g_sludge->_regionMan->kill();
 
 	int camerX = fp->readUint16BE();
 	int camerY = fp->readUint16BE();
diff --git a/engines/sludge/region.cpp b/engines/sludge/region.cpp
index 3ce4d92..409c4fc 100644
--- a/engines/sludge/region.cpp
+++ b/engines/sludge/region.cpp
@@ -41,9 +41,8 @@ RegionManager::RegionManager(SludgeEngine *vm)
 	_overRegion = nullptr;
 }
 
-RegionManager::~RegionManager()
-{
-
+RegionManager::~RegionManager() {
+	kill();
 }
 
 void RegionManager::showBoxes() {
@@ -123,7 +122,7 @@ void RegionManager::loadRegions(Common::SeekableReadStream *stream) {
 	*pointy = NULL;
 }
 
-void RegionManager::killAll() {
+void RegionManager::kill() {
 	ScreenRegion *killRegion;
 	while (_allScreenRegions) {
 		killRegion = _allScreenRegions;
diff --git a/engines/sludge/region.h b/engines/sludge/region.h
index 3a74149..06b7a62 100644
--- a/engines/sludge/region.h
+++ b/engines/sludge/region.h
@@ -39,7 +39,7 @@ public:
 	~RegionManager();
 
 	// Kill
-	void killAll();
+	void kill();
 
 	// Add & remove region
 	bool addScreenRegion(int x1, int y1, int x2, int y2, int, int, int, int objectNum);
diff --git a/engines/sludge/sludger.cpp b/engines/sludge/sludger.cpp
index 9eb0eb8..0da7f39 100644
--- a/engines/sludge/sludger.cpp
+++ b/engines/sludge/sludger.cpp
@@ -183,7 +183,7 @@ void initSludge() {
 void killSludge() {
 	killAllFunctions();
 	killAllPeople();
-	g_sludge->_regionMan->killAll();
+	g_sludge->_regionMan->kill();
 	setFloorNull();
 	g_sludge->_speechMan->kill();
 	g_sludge->_languageMan->kill();


Commit: 91db7c5967646c972f0f169811cb9033c354330d
    https://github.com/scummvm/scummvm/commit/91db7c5967646c972f0f169811cb9033c354330d
Author: Simei Yin (roseline.yin at gmail.com)
Date: 2018-04-15T01:09:35+02:00

Commit Message:
SLUDGE: Replace linked list by Common::List in RegionManager

Changed paths:
    engines/sludge/freeze.cpp
    engines/sludge/freeze.h
    engines/sludge/region.cpp
    engines/sludge/region.h


diff --git a/engines/sludge/freeze.cpp b/engines/sludge/freeze.cpp
index 15125db..0f03273 100644
--- a/engines/sludge/freeze.cpp
+++ b/engines/sludge/freeze.cpp
@@ -136,7 +136,6 @@ void GraphicsManager::unfreeze(bool killImage) {
 	killAllPeople();
 	allPeople = _frozenStuff->allPeople;
 
-	g_sludge->_regionMan->kill();
 	g_sludge->_regionMan->resotre(_frozenStuff);
 
 	killLightMap();
diff --git a/engines/sludge/freeze.h b/engines/sludge/freeze.h
index 830c2d8..647ccc9 100644
--- a/engines/sludge/freeze.h
+++ b/engines/sludge/freeze.h
@@ -32,12 +32,15 @@ struct ScreenRegion;
 struct SpeechStruct;
 struct StatusStuff ;
 struct EventHandlers;
+struct ScreenRegion;
+
+typedef Common::List<ScreenRegion *> ScreenRegionList;
 
 class Parallax;
 
 struct FrozenStuffStruct {
 	OnScreenPerson *allPeople;
-	ScreenRegion *allScreenRegions;
+	ScreenRegionList *allScreenRegions;
 	Graphics::Surface backdropSurface;
 	Graphics::Surface lightMapSurface;
 	Graphics::Surface *zBufferSprites;
diff --git a/engines/sludge/region.cpp b/engines/sludge/region.cpp
index 409c4fc..4410951 100644
--- a/engines/sludge/region.cpp
+++ b/engines/sludge/region.cpp
@@ -36,80 +36,62 @@ namespace Sludge {
 RegionManager::RegionManager(SludgeEngine *vm)
 {
 	_vm = vm;
-	_allScreenRegions = nullptr;
+	_allScreenRegions = new ScreenRegionList;
+	_allScreenRegions->clear();
 	_lastRegion = nullptr;
 	_overRegion = nullptr;
 }
 
 RegionManager::~RegionManager() {
 	kill();
+
+	delete _allScreenRegions;
+	_allScreenRegions = nullptr;
 }
 
 void RegionManager::showBoxes() {
-	ScreenRegion*huntRegion = _allScreenRegions;
-
-	while (huntRegion) {
-		g_sludge->_gfxMan->drawVerticalLine(huntRegion->x1, huntRegion->y1, huntRegion->y2);
-		g_sludge->_gfxMan->drawVerticalLine(huntRegion->x2, huntRegion->y1, huntRegion->y2);
-		g_sludge->_gfxMan->drawHorizontalLine(huntRegion->x1, huntRegion->y1, huntRegion->x2);
-		g_sludge->_gfxMan->drawHorizontalLine(huntRegion->x1, huntRegion->y2, huntRegion->x2);
-		huntRegion = huntRegion->next;
+	for (ScreenRegionList::iterator it = _allScreenRegions->begin(); it != _allScreenRegions->end(); ++it) {
+		g_sludge->_gfxMan->drawVerticalLine((*it)->x1, (*it)->y1, (*it)->y2);
+		g_sludge->_gfxMan->drawVerticalLine((*it)->x2, (*it)->y1, (*it)->y2);
+		g_sludge->_gfxMan->drawHorizontalLine((*it)->x1, (*it)->y1, (*it)->x2);
+		g_sludge->_gfxMan->drawHorizontalLine((*it)->x1, (*it)->y2, (*it)->x2);
 	}
 }
 
 void RegionManager::removeScreenRegion(int objectNum) {
-	ScreenRegion **huntRegion = &_allScreenRegions;
-	ScreenRegion *killMe;
-
-	while (*huntRegion) {
-		if ((*huntRegion)->thisType->objectNum == objectNum) {
-			killMe = *huntRegion;
-			*huntRegion = killMe->next;
+	for (ScreenRegionList::iterator it = _allScreenRegions->begin(); it != _allScreenRegions->end(); ++it) {
+		if ((*it)->thisType->objectNum == objectNum) {
+			ScreenRegion *killMe = *it;
 			g_sludge->_objMan->removeObjectType(killMe->thisType);
 			if (killMe == _overRegion)
-				_overRegion = NULL;
+				_overRegion = nullptr;
 			delete killMe;
-			killMe = NULL;
-		} else {
-			huntRegion = &((*huntRegion)->next);
+			killMe = nullptr;
+			_allScreenRegions->reverse_erase(it);
 		}
 	}
 }
 
 void RegionManager::saveRegions(Common::WriteStream *stream) {
-	int numRegions = 0;
-	ScreenRegion *thisRegion = _allScreenRegions;
-	while (thisRegion) {
-		thisRegion = thisRegion->next;
-		numRegions++;
-	}
+	uint numRegions = _allScreenRegions->size();
 	stream->writeUint16BE(numRegions);
-	thisRegion = _allScreenRegions;
-	while (thisRegion) {
-		stream->writeUint16BE(thisRegion->x1);
-		stream->writeUint16BE(thisRegion->y1);
-		stream->writeUint16BE(thisRegion->x2);
-		stream->writeUint16BE(thisRegion->y2);
-		stream->writeUint16BE(thisRegion->sX);
-		stream->writeUint16BE(thisRegion->sY);
-		stream->writeUint16BE(thisRegion->di);
-		g_sludge->_objMan->saveObjectRef(thisRegion->thisType, stream);
-
-		thisRegion = thisRegion->next;
+	for (ScreenRegionList::iterator it = _allScreenRegions->begin(); it != _allScreenRegions->end(); ++it) {
+		stream->writeUint16BE((*it)->x1);
+		stream->writeUint16BE((*it)->y1);
+		stream->writeUint16BE((*it)->x2);
+		stream->writeUint16BE((*it)->y2);
+		stream->writeUint16BE((*it)->sX);
+		stream->writeUint16BE((*it)->sY);
+		stream->writeUint16BE((*it)->di);
+		g_sludge->_objMan->saveObjectRef((*it)->thisType, stream);
 	}
 }
 
 void RegionManager::loadRegions(Common::SeekableReadStream *stream) {
 	int numRegions = stream->readUint16BE();
-
-	ScreenRegion *newRegion;
-	ScreenRegion **pointy = &_allScreenRegions;
-
 	while (numRegions--) {
-		newRegion = new ScreenRegion;
-		*pointy = newRegion;
-		pointy = &(newRegion->next);
-
+		ScreenRegion *newRegion = new ScreenRegion;
+		_allScreenRegions->push_back(newRegion);
 		newRegion->x1 = stream->readUint16BE();
 		newRegion->y1 = stream->readUint16BE();
 		newRegion->x2 = stream->readUint16BE();
@@ -119,17 +101,15 @@ void RegionManager::loadRegions(Common::SeekableReadStream *stream) {
 		newRegion->di = stream->readUint16BE();
 		newRegion->thisType = g_sludge->_objMan->loadObjectRef(stream);
 	}
-	*pointy = NULL;
 }
 
 void RegionManager::kill() {
-	ScreenRegion *killRegion;
-	while (_allScreenRegions) {
-		killRegion = _allScreenRegions;
-		_allScreenRegions = _allScreenRegions->next;
+	for (ScreenRegionList::iterator it = _allScreenRegions->begin(); it != _allScreenRegions->end(); ++it) {
+		ScreenRegion *killRegion = (*it);
 		g_sludge->_objMan->removeObjectType(killRegion->thisType);
 		delete killRegion;
 	}
+	_allScreenRegions->clear();
 	_overRegion = nullptr;
 	_lastRegion = nullptr;
 }
@@ -147,49 +127,49 @@ bool RegionManager::addScreenRegion(int x1, int y1, int x2, int y2, int sX, int
 	newRegion->sX = sX;
 	newRegion->sY = sY;
 	newRegion->thisType = g_sludge->_objMan->loadObjectType(objectNum);
-	newRegion->next = _allScreenRegions;
-	_allScreenRegions = newRegion;
-	return (bool) (newRegion->thisType != NULL);
+	_allScreenRegions->push_front(newRegion);
+	return (bool) (newRegion->thisType != nullptr);
 }
 
 void RegionManager::updateOverRegion() {
 	int cameraX = g_sludge->_gfxMan->getCamX();
 	int cameraY = g_sludge->_gfxMan->getCamY();
-	ScreenRegion *thisRegion = _allScreenRegions;
-	while (thisRegion) {
-		if ((g_sludge->_evtMan->mouseX() >= thisRegion->x1 - cameraX)
-				&& (g_sludge->_evtMan->mouseY() >= thisRegion->y1 - cameraY)
-				&& (g_sludge->_evtMan->mouseX() <= thisRegion->x2 - cameraX)
-				&& (g_sludge->_evtMan->mouseY() <= thisRegion->y2 - cameraY)) {
-			_overRegion = thisRegion;
+	for (ScreenRegionList::iterator it = _allScreenRegions->begin(); it != _allScreenRegions->end(); ++it) {
+		if ((g_sludge->_evtMan->mouseX() >= (*it)->x1 - cameraX)
+				&& (g_sludge->_evtMan->mouseY() >= (*it)->y1 - cameraY)
+				&& (g_sludge->_evtMan->mouseX() <= (*it)->x2 - cameraX)
+				&& (g_sludge->_evtMan->mouseY() <= (*it)->y2 - cameraY)) {
+			_overRegion = (*it);
 			return;
 		}
-		thisRegion = thisRegion->next;
 	}
-	_overRegion = NULL;
+	_overRegion = nullptr;
 	return;
 }
 
 ScreenRegion *RegionManager::getRegionForObject(int obj) {
-	ScreenRegion *thisRegion = _allScreenRegions;
-
-	while (thisRegion) {
-		if (obj == thisRegion->thisType->objectNum) {
-			return thisRegion;
+	for (ScreenRegionList::iterator it = _allScreenRegions->begin(); it != _allScreenRegions->end(); ++it) {
+		if (obj == (*it)->thisType->objectNum) {
+			return (*it);
 		}
-		thisRegion = thisRegion->next;
 	}
 
-	return NULL;
+	return nullptr;
 }
 
 void RegionManager::freeze(FrozenStuffStruct *frozenStuff) {
 	frozenStuff->allScreenRegions = _allScreenRegions;
-	_allScreenRegions = nullptr;
+	_allScreenRegions = new ScreenRegionList;
 	_overRegion = nullptr;
 }
 
 void RegionManager::resotre(FrozenStuffStruct *frozenStuff) {
+	// kill
+	kill();
+	delete _allScreenRegions;
+	_allScreenRegions = nullptr;
+
+	// restore
 	_allScreenRegions = frozenStuff->allScreenRegions;
 	_overRegion = nullptr;
 }
diff --git a/engines/sludge/region.h b/engines/sludge/region.h
index 06b7a62..5f307cc 100644
--- a/engines/sludge/region.h
+++ b/engines/sludge/region.h
@@ -30,8 +30,8 @@ namespace Sludge {
 struct ScreenRegion {
 	int x1, y1, x2, y2, sX, sY, di;
 	ObjectType *thisType;
-	ScreenRegion *next;
 };
+typedef Common::List<ScreenRegion *> ScreenRegionList;
 
 class RegionManager {
 public:
@@ -69,7 +69,7 @@ public:
 private:
 	SludgeEngine *_vm;
 
-	ScreenRegion *_allScreenRegions;
+	ScreenRegionList *_allScreenRegions;
 	ScreenRegion *_overRegion;
 	ScreenRegion *_lastRegion;
 };





More information about the Scummvm-git-logs mailing list