[Scummvm-cvs-logs] SF.net SVN: scummvm:[38928] scummvm/trunk/engines/parallaction

peres001 at users.sourceforge.net peres001 at users.sourceforge.net
Fri Feb 27 09:56:19 CET 2009


Revision: 38928
          http://scummvm.svn.sourceforge.net/scummvm/?rev=38928&view=rev
Author:   peres001
Date:     2009-02-27 08:56:19 +0000 (Fri, 27 Feb 2009)

Log Message:
-----------
The engine has now to build the drawing list for the graphic department, instead of setting visibility flags; the new field _prog has been added to GfxObj to help sorting the list.
The outcome is that cleaning up unused resources on location switches is now easier to manage, and less error prone.

Modified Paths:
--------------
    scummvm/trunk/engines/parallaction/callables_ns.cpp
    scummvm/trunk/engines/parallaction/gfxbase.cpp
    scummvm/trunk/engines/parallaction/graphics.cpp
    scummvm/trunk/engines/parallaction/graphics.h
    scummvm/trunk/engines/parallaction/parallaction.cpp
    scummvm/trunk/engines/parallaction/parallaction.h
    scummvm/trunk/engines/parallaction/parser.h
    scummvm/trunk/engines/parallaction/parser_br.cpp
    scummvm/trunk/engines/parallaction/parser_ns.cpp

Modified: scummvm/trunk/engines/parallaction/callables_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/callables_ns.cpp	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/callables_ns.cpp	2009-02-27 08:56:19 UTC (rev 38928)
@@ -244,8 +244,6 @@
 	_moveSarcGetZone->translate(_sarcophagusDeltaX, -_sarcophagusDeltaX / 20);
 	_moveSarcExaZone->translate(_sarcophagusDeltaX, -_sarcophagusDeltaX / 20);
 
-	_zonesToUpdate.push_back(_moveSarcGetZone);
-
 	// check if the puzzle has been completed, by verifying the position of
 	// the sarcophagi
 	if (_moveSarcGetZones[0]->getX() == 35 &&

Modified: scummvm/trunk/engines/parallaction/gfxbase.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/gfxbase.cpp	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/gfxbase.cpp	2009-02-27 08:56:19 UTC (rev 38928)
@@ -33,7 +33,7 @@
 namespace Parallaction {
 
 GfxObj::GfxObj(uint objType, Frames *frames, const char* name) :
-	_frames(frames), _keep(true), x(0), y(0), z(0), _flags(kGfxObjNormal),
+	_frames(frames), _keep(true), x(0), y(0), z(0), _flags(0),
 	type(objType), frame(0), layer(3), scale(100), _hasMask(false), _hasPath(false)  {
 
 	if (name) {
@@ -88,6 +88,27 @@
 	_flags &= ~flags;
 }
 
+void Gfx::addObjectToScene(GfxObj *obj) {
+	if (!obj) {
+		return;
+	}
+
+	if (!obj->isVisible()) {
+		return;
+	}
+
+	if (SCENE_DRAWLIST_SIZE == _sceneObjects.size()) {
+		warning("number of objects in the current scene is larger than the fixed drawlist size");
+	}
+
+	_sceneObjects.push_back(obj);
+}
+
+void Gfx::resetSceneDrawList() {
+	_sceneObjects.clear();
+	_sceneObjects.reserve(SCENE_DRAWLIST_SIZE);
+}
+
 GfxObj* Gfx::loadAnim(const char *name) {
 	Frames* frames = _disk->loadFrames(name);
 	assert(frames);
@@ -98,15 +119,11 @@
 	// animation Z is not set here, but controlled by game scripts and user interaction.
 	// it is always >=0 and <screen height
 	obj->transparentKey = 0;
-	_sceneObjects.push_back(obj);
 	return obj;
 }
 
 GfxObj* Gfx::loadCharacterAnim(const char *name) {
-	GfxObj *obj = loadAnim(name);
-	obj->setFlags(kGfxObjCharacter);
-	obj->clearFlags(kGfxObjNormal);
-	return obj;
+	return loadAnim(name);
 }
 
 GfxObj* Gfx::loadGet(const char *name) {
@@ -116,7 +133,6 @@
 	obj->z = kGfxObjGetZ;	// this preset Z value ensures that get zones are drawn after doors but before animations
 	obj->type = kGfxObjTypeGet;
 	obj->transparentKey = 0;
-	_sceneObjects.push_back(obj);
 	return obj;
 }
 
@@ -129,31 +145,17 @@
 
 	obj->z = kGfxObjDoorZ;	// this preset Z value ensures that doors are drawn first
 	obj->transparentKey = 0;
-	_sceneObjects.push_back(obj);
 	return obj;
 }
 
-void Gfx::clearGfxObjects(uint filter) {
 
-	for (uint i = 0; i < _sceneObjects.size() ; ) {
-		if ((_sceneObjects[i]->_flags & filter) != 0) {
-			_sceneObjects.remove_at(i);
-		} else {
-			i++;
-		}
-	}
-
-}
-
 void Gfx::freeLocationObjects() {
 	freeDialogueObjects();
-	clearGfxObjects(kGfxObjNormal);
 	freeLabels();
 }
 
 void Gfx::freeCharacterObjects() {
 	freeDialogueObjects();
-	clearGfxObjects(kGfxObjCharacter);
 }
 
 void BackgroundInfo::loadGfxObjMask(const char *name, GfxObj *obj) {
@@ -202,7 +204,7 @@
 
 
 bool compareZ(const GfxObj* a1, const GfxObj* a2) {
-	return a1->z < a2->z;
+	return (a1->z == a2->z) ? (a1->_prog < a2->_prog) : (a1->z < a2->z);
 }
 
 void Gfx::sortScene() {

Modified: scummvm/trunk/engines/parallaction/graphics.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.cpp	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/graphics.cpp	2009-02-27 08:56:19 UTC (rev 38928)
@@ -372,6 +372,10 @@
 	_scrollPos = CLIP(scrollX, _minScroll, _maxScroll);
 }
 
+void Gfx::beginFrame() {
+	resetSceneDrawList();
+}
+
 void Gfx::updateScreen() {
 
 	// the scene is calculated in game coordinates, so no translation
@@ -714,6 +718,8 @@
 		_backupPal.clone(paletteInfo.palette);
 	}
 
+	resetSceneDrawList();
+
 	return;
 }
 

Modified: scummvm/trunk/engines/parallaction/graphics.h
===================================================================
--- scummvm/trunk/engines/parallaction/graphics.h	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/graphics.h	2009-02-27 08:56:19 UTC (rev 38928)
@@ -273,9 +273,6 @@
 enum {
 	kGfxObjVisible = 1,
 
-	kGfxObjNormal = 2,
-	kGfxObjCharacter = 4,
-
 	kGfxObjTypeDoor = 0,
 	kGfxObjTypeGet = 1,
 	kGfxObjTypeAnim = 2,
@@ -299,6 +296,7 @@
 	int16 x, y;
 
 	int32 z;
+	uint32 _prog;	// this value is used when sorting, in case that comparing z is not enough to tell which object goes on front
 
 	uint32 _flags;
 
@@ -419,26 +417,28 @@
 
 
 typedef Common::Array<GfxObj*> GfxObjArray;
+#define SCENE_DRAWLIST_SIZE 100
 
-
 class Gfx {
 
 protected:
 	Parallaction*		_vm;
+	void resetSceneDrawList();
 
 public:
 	Disk *_disk;
 
+	void beginFrame();
+	void addObjectToScene(GfxObj *obj);
 	GfxObjArray _sceneObjects;
 	GfxObj* loadAnim(const char *name);
 	GfxObj* loadGet(const char *name);
 	GfxObj* loadDoor(const char *name);
 	GfxObj* loadCharacterAnim(const char *name);
+	void sortScene();
 	void freeCharacterObjects();
 	void freeLocationObjects();
 	void showGfxObj(GfxObj* obj, bool visible);
-	void clearGfxObjects(uint filter);
-	void sortScene();
     void blt(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor);
 	void unpackBlt(const Common::Rect& r, byte *data, uint size, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor);
 

Modified: scummvm/trunk/engines/parallaction/parallaction.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.cpp	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/parallaction.cpp	2009-02-27 08:56:19 UTC (rev 38928)
@@ -338,6 +338,8 @@
 		_input->setArrowCursor();
 	}
 
+	_gfx->beginFrame();
+
 	runPendingZones();
 
 	if (shouldQuit())
@@ -494,8 +496,31 @@
 	obj->z = anim->getZ();
 	obj->layer = layer;
 	obj->scale = scale;
+	_gfx->addObjectToScene(obj);
 }
 
+void Parallaction::drawZone(ZonePtr zone) {
+	if (!zone) {
+		return;
+	}
+
+	GfxObj *obj = 0;
+	if (ACTIONTYPE(zone) == kZoneGet) {
+		obj = zone->u.get->gfxobj;
+	} else
+	if (ACTIONTYPE(zone) == kZoneDoor) {
+		obj = zone->u.door->gfxobj;
+	}
+
+	if (!obj) {
+		return;
+	}
+
+	obj->x = zone->getX();
+	obj->y = zone->getY();
+	_gfx->addObjectToScene(obj);
+}
+
 void Parallaction::updateZones() {
 	debugC(9, kDebugExec, "Parallaction::updateZones()\n");
 
@@ -512,16 +537,10 @@
 		}
 	}
 
-	// examine the list of get zones to update
-	for (ZoneList::iterator zit = _zonesToUpdate.begin(); zit != _zonesToUpdate.end(); ++zit) {
-		ZonePtr z = *zit;
-		if (ACTIONTYPE(z) == kZoneGet) {
-			GfxObj *obj = z->u.get->gfxobj;
-			obj->x = z->getX();
-			obj->y = z->getY();
-		}
+	// go through all zones and mark/unmark each of them for display
+	for (ZoneList::iterator zit = _location._zones.begin(); zit != _location._zones.end(); ++zit) {
+		drawZone(*zit);
 	}
-	_zonesToUpdate.clear();
 
 	debugC(9, kDebugExec, "Parallaction::updateZones done()\n");
 }

Modified: scummvm/trunk/engines/parallaction/parallaction.h
===================================================================
--- scummvm/trunk/engines/parallaction/parallaction.h	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/parallaction.h	2009-02-27 08:56:19 UTC (rev 38928)
@@ -305,6 +305,7 @@
 	void 	exitCommentMode();
 	void	updateView();
 	void 	drawAnimation(AnimationPtr anim);
+	void 	drawZone(ZonePtr zone);
 	void	updateZones();
 	void	doLocationEnterTransition();
 	void	allocateLocationSlot(const char *name);
@@ -312,8 +313,6 @@
 	void	showLocationComment(const Common::String &text, bool end);
 	void 	setupBalloonManager();
 
-	ZoneList	_zonesToUpdate;
-
 public:
 	void	beep();
 	void	pauseJobs();

Modified: scummvm/trunk/engines/parallaction/parser.h
===================================================================
--- scummvm/trunk/engines/parallaction/parser.h	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/parser.h	2009-02-27 08:56:19 UTC (rev 38928)
@@ -106,6 +106,7 @@
 
 	Table		*_zoneTypeNames;
 	Table		*_zoneFlagNames;
+	uint		_zoneProg;
 
 	// location parser
 	OpcodeSet	_locationParsers;

Modified: scummvm/trunk/engines/parallaction/parser_br.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_br.cpp	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/parser_br.cpp	2009-02-27 08:56:19 UTC (rev 38928)
@@ -786,6 +786,7 @@
 			obj->frame = 0;
 			obj->x = z->getX();
 			obj->y = z->getY();
+			obj->_prog = _zoneProg;
 			data->gfxobj = obj;
 		}
 

Modified: scummvm/trunk/engines/parallaction/parser_ns.cpp
===================================================================
--- scummvm/trunk/engines/parallaction/parser_ns.cpp	2009-02-27 08:46:39 UTC (rev 38927)
+++ scummvm/trunk/engines/parallaction/parser_ns.cpp	2009-02-27 08:56:19 UTC (rev 38928)
@@ -290,7 +290,13 @@
 void LocationParser_ns::parseAnimation(AnimationList &list, char *name) {
 	debugC(5, kDebugParser, "parseAnimation(name: %s)", name);
 
+	if (_vm->_location.findAnimation(name)) {
+		_script->skip("endanimation");
+		return;
+	}
+
 	AnimationPtr a(new Animation);
+	_zoneProg++;
 
 	strncpy(a->_name, name, ZONENAME_LENGTH);
 	a->_flags |= kFlagsIsAnimation;
@@ -328,7 +334,6 @@
 }
 
 void ProgramParser_ns::parse(Script *script, ProgramPtr program) {
-
 	_script = script;
 	_program = program;
 
@@ -1088,7 +1093,7 @@
 }
 
 void LocationParser_ns::parse(Script *script) {
-
+	_zoneProg = 0;
 	_numForwardedCommands = 0;
 
 	ctxt.end = false;
@@ -1360,6 +1365,7 @@
 	}
 
 	ZonePtr z(new Zone);
+	_zoneProg++;
 
 	strncpy(z->_name, name, ZONENAME_LENGTH);
 
@@ -1389,6 +1395,7 @@
 			obj->frame = 0;
 			obj->x = z->getX();
 			obj->y = z->getY();
+			obj->_prog = _zoneProg;
 			_vm->_gfx->showGfxObj(obj, visible);
 
 			data->gfxobj = obj;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list