[Scummvm-cvs-logs] CVS: scummvm/saga actionmap.cpp,1.23,1.24 actionmap.h,1.10,1.11 actor.cpp,1.25,1.26 render.cpp,1.32,1.33 saga.cpp,1.50,1.51 saga.h,1.38,1.39 scene.cpp,1.40,1.41 scene.h,1.11,1.12

Eugene Sandulenko sev at users.sourceforge.net
Thu Oct 7 15:33:42 CEST 2004


Update of /cvsroot/scummvm/scummvm/saga
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19359

Modified Files:
	actionmap.cpp actionmap.h actor.cpp render.cpp saga.cpp saga.h 
	scene.cpp scene.h 
Log Message:
Remove duplicated code in actor walk code.
Turn ActionMap into real object.
Rename ActionMap variables to conform our code guidelines.


Index: actionmap.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actionmap.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- actionmap.cpp	4 Oct 2004 23:09:38 -0000	1.23
+++ actionmap.cpp	7 Oct 2004 22:31:39 -0000	1.24
@@ -32,30 +32,7 @@
 
 namespace Saga {
 
-static void CF_action_info(int argc, char *argv[], void *refCon);
-
-int ActionMap::reg(void) {
-	CVAR_RegisterFunc(CF_action_info,
-					  "action_info", NULL, R_CVAR_NONE, 0, 0, this);
-	return R_SUCCESS;
-}
-
-ActionMap::ActionMap(SagaEngine *vm) : _vm(vm) {
-	debug(0, "ACTIONMAP Module: Initializing...");
-
-	_exits_loaded = 0;
-	_exits_tbl = NULL;
-	_n_exits = 0;
-
-	_initialized = true;
-}
-
-ActionMap::~ActionMap(void) {
-	freeMap();
-}
-
-
-int ActionMap::loadMap(const byte * exmap_res, size_t exmap_res_len) {
+ActionMap::ActionMap(SagaEngine *vm, const byte * exmap_res, size_t exmap_res_len) : _vm(vm) {
 	// Loads exit map data from specified exit map resource
 	R_ACTIONMAP_ENTRY *exmap_entry;
 	Point *exmap_pt_tbl;
@@ -63,7 +40,6 @@
 	int exit_ct;
 	int i, pt;
 
-	assert(_initialized);
 	assert(exmap_res != NULL);
 
 	MemoryReadStream readS(exmap_res, exmap_res_len);
@@ -71,31 +47,31 @@
 	// Load exits
 	exit_ct = readS.readSint16LE();
 	if (exit_ct < 0) {
-		return R_FAILURE;
+		return;
 	}
 
 	exmap_entry = (R_ACTIONMAP_ENTRY *)malloc(exit_ct * sizeof *exmap_entry);
 	if (exmap_entry == NULL) {
 		warning("Memory allocation failure");
-		return R_MEM;
+		return;
 	}
 
 	for (i = 0; i < exit_ct; i++) {
 		exmap_entry[i].unknown00 = readS.readSint16LE();
 		exmap_entry[i].unknown02 = readS.readSint16LE();
-		exmap_entry[i].exit_scene = readS.readSint16LE();
+		exmap_entry[i].exitScene = readS.readSint16LE();
 		exmap_entry[i].unknown06 = readS.readSint16LE();
 
 		exmap_entry[i].pt_count = readS.readSint16LE();
 		if (exmap_entry[i].pt_count < 0) {
 			free(exmap_entry);
-			return R_FAILURE;
+			return;
 		}
 
 		exmap_pt_tbl = (Point *)malloc(exmap_entry[i].pt_count * sizeof *exmap_pt_tbl);
 		if (exmap_pt_tbl == NULL) {
 			warning("Memory allocation failure");
-			return R_MEM;
+			return;
 		}
 
 		for (pt = 0; pt < exmap_entry[i].pt_count; pt++) {
@@ -106,103 +82,66 @@
 		exmap_entry[i].pt_tbl = exmap_pt_tbl;
 	}
 
-	_exits_loaded = 1;
-	_n_exits = exit_ct;
-	_exits_tbl = exmap_entry;
-
-	_exmap_res = exmap_res;
-	_exmap_res_len = exmap_res_len;
-
-	return R_SUCCESS;
+	_nExits = exit_ct;
+	_exitsTbl = exmap_entry;
 }
 
-int ActionMap::freeMap(void) {
+ActionMap::~ActionMap(void) {
 	// Frees the currently loaded exit map data
 	R_ACTIONMAP_ENTRY *exmap_entry;
 	int i;
 
-	if (!_exits_loaded) {
-		return R_SUCCESS;
-	}
-
-	if (_exits_tbl) {
-		for (i = 0; i < _n_exits; i++) {
-			exmap_entry = &_exits_tbl[i];
+	if (_exitsTbl) {
+		for (i = 0; i < _nExits; i++) {
+			exmap_entry = &_exitsTbl[i];
 
 			if (exmap_entry != NULL)
 				free(exmap_entry->pt_tbl);
 		}
 
-		free(_exits_tbl);
+		free(_exitsTbl);
 	}
-
-	_exits_loaded = 0;
-	_exits_tbl = NULL;
-	_n_exits = 0;
-
-	return R_SUCCESS;
-}
-
-int ActionMap::shutdown(void) {
-	return R_SUCCESS;
 }
 
-int ActionMap::draw(R_SURFACE * ds, int color) {
+int ActionMap::draw(R_SURFACE *ds, int color) {
 	int i;
 
-	assert(_initialized);
-
-	if (!_exits_loaded) {
-		return R_FAILURE;
-	}
-
-	for (i = 0; i < _n_exits; i++) {
-		if (_exits_tbl[i].pt_count == 2) {
+	for (i = 0; i < _nExits; i++) {
+		if (_exitsTbl[i].pt_count == 2) {
 			_vm->_gfx->drawFrame(ds,
-				&_exits_tbl[i].pt_tbl[0],
-				&_exits_tbl[i].pt_tbl[1], color);
-		} else if (_exits_tbl[i].pt_count > 2) {
-			_vm->_gfx->drawPolyLine(ds, _exits_tbl[i].pt_tbl,
-							 _exits_tbl[i].pt_count, color);
+				&_exitsTbl[i].pt_tbl[0],
+				&_exitsTbl[i].pt_tbl[1], color);
+		} else if (_exitsTbl[i].pt_count > 2) {
+			_vm->_gfx->drawPolyLine(ds, _exitsTbl[i].pt_tbl,
+							 _exitsTbl[i].pt_count, color);
 		}
 	}
 
 	return R_SUCCESS;
 }
 
-void ActionMap::actionInfo(int argc, char *argv[]) {
+void ActionMap::info(void) {
 	Point *pt;
 
 	int i;
 	int pt_i;
 
-	(void)(argc);
-	(void)(argv);
-
-	if (!_exits_loaded) {
-		return;
-	}
-
-	_vm->_console->print("%d exits loaded.\n", _n_exits);
+	_vm->_console->print("%d exits loaded.\n", _nExits);
 
-	for (i = 0; i < _n_exits; i++) {
+	for (i = 0; i < _nExits; i++) {
 		_vm->_console->print ("Action %d: Exit to: %d; Pts: %d; Unk0: %d Unk2: %d Scr_N: %d",
-				   i, _exits_tbl[i].exit_scene,
-				   _exits_tbl[i].pt_count,
-				   _exits_tbl[i].unknown00,
-				   _exits_tbl[i].unknown02,
-				   _exits_tbl[i].unknown06);
+				   i, _exitsTbl[i].exitScene,
+				   _exitsTbl[i].pt_count,
+				   _exitsTbl[i].unknown00,
+				   _exitsTbl[i].unknown02,
+				   _exitsTbl[i].unknown06);
 
-		for (pt_i = 0; pt_i < _exits_tbl[i].pt_count; pt_i++) {
-			pt = &_exits_tbl[i].pt_tbl[pt_i];
+		for (pt_i = 0; pt_i < _exitsTbl[i].pt_count; pt_i++) {
+			pt = &_exitsTbl[i].pt_tbl[pt_i];
 
 			_vm->_console->print("   pt: %d (%d, %d)", pt_i, pt->x, pt->y);
 		}
 	}
 }
 
-static void CF_action_info(int argc, char *argv[], void *refCon) {
-	((ActionMap *)refCon)->actionInfo(argc, argv);
-}
-
 } // End of namespace Saga

Index: actionmap.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actionmap.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- actionmap.h	4 Oct 2004 23:09:38 -0000	1.10
+++ actionmap.h	7 Oct 2004 22:31:39 -0000	1.11
@@ -31,7 +31,7 @@
 struct R_ACTIONMAP_ENTRY {
 	int unknown00;
 	int unknown02;
-	int exit_scene;
+	int exitScene;
 	int unknown06;
 
 	int pt_count;
@@ -41,26 +41,18 @@
 class ActionMap {
  public:
 	int reg(void);
-	ActionMap(SagaEngine *vm);
+	ActionMap(SagaEngine *vm, const byte *exmap_res, size_t exmap_res_len);
 	~ActionMap(void);
 
-	int loadMap(const byte *exmap_res, size_t exmap_res_len);
 	int draw(R_SURFACE *ds, int color);
 
-	int freeMap(void);
-	int shutdown(void);
-
-	void actionInfo(int argc, char *argv[]);
+	void info(void);
 
 private:
 	SagaEngine *_vm;
 
-	bool _initialized;
-	int _exits_loaded;
-	int _n_exits;
-	R_ACTIONMAP_ENTRY *_exits_tbl;
-	const byte *_exmap_res;
-	size_t _exmap_res_len;
+	int _nExits;
+	R_ACTIONMAP_ENTRY *_exitsTbl;
 };
 
 } // End of namespace Saga

Index: actor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/actor.cpp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- actor.cpp	4 Oct 2004 23:09:38 -0000	1.25
+++ actor.cpp	7 Oct 2004 22:31:39 -0000	1.26
@@ -906,25 +906,8 @@
 	new_a_x = path_x + a_walkint->org.x;
 	new_a_y = path_y + a_walkint->org.y;
 
-	if (a_walkint->x_dir == 1) {
-
-		if (new_a_x >= node_p->node_pt.x) {
-			debug(2, "Path complete.");
-			ys_dll_delete(walk_p);
-			a_walkint->wi_active = 0;
-
-			// Release path semaphore
-			if (a_walkint->sem != NULL) {
-				_vm->_script->SThreadReleaseSem(a_walkint->sem);
-			}
-
-			actor->action_frame = 0;
-			actor->action = ACTION_IDLE;
-			*complete_p = 1;
-			return R_FAILURE;
-		}
-	} else {
-		if (new_a_x <= node_p->node_pt.x) {
+	if (((a_walkint->x_dir == 1) && new_a_x >= node_p->node_pt.x) ||
+		((a_walkint->x_dir != 1) && (new_a_x <= node_p->node_pt.x))) {
 			debug(2, "Path complete.");
 			ys_dll_delete(walk_p);
 			a_walkint->wi_active = 0;
@@ -938,7 +921,6 @@
 			actor->action = ACTION_IDLE;
 			*complete_p = 1;
 			return R_FAILURE;
-		}
 	}
 
 	actor_x = (int)new_a_x;

Index: render.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/render.cpp,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- render.cpp	4 Oct 2004 23:09:38 -0000	1.32
+++ render.cpp	7 Oct 2004 22:31:39 -0000	1.33
@@ -34,7 +34,6 @@
 #include "saga/scene.h"
 #include "saga/text.h"
 
-#include "saga/actionmap.h"
 #include "saga/objectmap.h"
 
 #include "saga/render.h"
@@ -137,7 +136,7 @@
 	// Display scene maps, if applicable
 	if (getFlags() & RF_OBJECTMAP_TEST) {
 		_omap->draw(backbuf_surface, &mouse_pt, _gfx->getWhite(), _gfx->getBlack());
-		_vm->_actionMap->draw(backbuf_surface, _gfx->matchColor(R_RGB_RED));
+		_vm->_scene->drawActionMap(backbuf_surface, _gfx->matchColor(R_RGB_RED));
 	}
 
 	// Draw queued actors

Index: saga.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/saga.cpp,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- saga.cpp	1 Oct 2004 06:45:13 -0000	1.50
+++ saga.cpp	7 Oct 2004 22:31:39 -0000	1.51
@@ -40,7 +40,6 @@
 #include "saga/console.h"
 #include "saga/cvar_mod.h"
 #include "saga/events.h"
-#include "saga/actionmap.h"
 #include "saga/font.h"
 #include "saga/game_mod.h"
 #include "saga/game.h"
@@ -185,7 +184,6 @@
 	_gfx = new Gfx(_system, disp_info.logical_w, disp_info.logical_h);
 
 	_isoMap = new IsoMap(_gfx);
-	_actionMap = new ActionMap(this);
 	_objectMap = new ObjectMap(_gfx);
 	
 	_render = new Render(this, _system, _gfx, _objectMap);
@@ -207,7 +205,6 @@
 	_script->reg();
 	_render->reg();
 	_anim->reg();
-	_actionMap->reg();
 	_objectMap->reg();
 
 	_previousTicks = _system->getMillis();
@@ -256,7 +253,6 @@
 
 	delete _interface;
 	delete _render;
-	delete _actionMap;
 	delete _isoMap;
 	delete _objectMap;
 	delete _sndRes;

Index: saga.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/saga.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- saga.h	4 Oct 2004 23:09:38 -0000	1.38
+++ saga.h	7 Oct 2004 22:31:39 -0000	1.39
@@ -45,7 +45,6 @@
 class Music;
 class Anim;
 class Render;
-class ActionMap;
 class IsoMap;
 class ObjectMap;
 class Gfx;
@@ -100,7 +99,6 @@
 	Music *_music;
 	Anim *_anim;
 	Render *_render;
-	ActionMap *_actionMap;
 	IsoMap *_isoMap;
 	ObjectMap *_objectMap;
 	Gfx *_gfx;

Index: scene.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/scene.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- scene.cpp	5 Oct 2004 02:16:26 -0000	1.40
+++ scene.cpp	7 Oct 2004 22:31:39 -0000	1.41
@@ -48,11 +48,15 @@
 
 static void CF_scenechange(int argc, char *argv[], void *refCon);
 static void CF_sceneinfo(int argc, char *argv[], void *refCon);
+static void CF_actioninfo(int argc, char *argv[], void *refCon);
+
 
 int Scene::reg() {
 	CVAR_Register_I(&_sceneNumber, "scene", NULL, R_CVAR_READONLY, 0, 0);
 	CVAR_RegisterFunc(CF_scenechange, "scene_change", "<Scene number>", R_CVAR_NONE, 1, 1, this);
 	CVAR_RegisterFunc(CF_sceneinfo, "scene_info", NULL, R_CVAR_NONE, 0, 0, this);
+	CVAR_RegisterFunc(CF_actioninfo,
+					  "action_info", NULL, R_CVAR_NONE, 0, 0, this);
 
 	return R_SUCCESS;
 }
@@ -678,10 +682,7 @@
 			break;
 		case SAGA_ACTION_MAP:
 			debug(0, "Loading exit map resource...");
-			if (_vm->_actionMap->loadMap(res_data, res_data_len) != R_SUCCESS) {
-				warning("Scene::ProcessSceneResources(): Error loading exit map resource");
-				return R_FAILURE;
-			}
+			_actionMap = new ActionMap(_vm, res_data, res_data_len);
 			break;
 		case SAGA_ISO_TILESET:
 			if (_sceneMode == R_SCENE_MODE_NORMAL) {
@@ -851,7 +852,7 @@
 
 	_vm->_palanim->freePalAnim();
 	_vm->_objectMap->freeMem();
-	_vm->_actionMap->freeMap();
+	delete _actionMap;
 
 	ys_dll_destroy(_animList);
 
@@ -916,6 +917,13 @@
 	return ((Scene *)refCon)->defaultScene(param, scene_info);
 }
 
+static void CF_actioninfo(int argc, char *argv[], void *refCon) {
+	(void)(argc);
+	(void)(argv);
+
+	((Scene *)refCon)->_actionMap->info();
+}
+
 int Scene::defaultScene(int param, R_SCENE_INFO *scene_info) {
 	R_EVENT event;
 

Index: scene.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/saga/scene.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- scene.h	5 Oct 2004 02:16:26 -0000	1.11
+++ scene.h	7 Oct 2004 22:31:39 -0000	1.12
@@ -27,6 +27,7 @@
 #define SAGA_SCENE_H
 
 #include "saga/text.h"
+#include "saga/actionmap.h"
 
 namespace Saga {
 
@@ -235,6 +236,8 @@
 	void sceneInfoCmd(int argc, char *argv[]);
 	void sceneChangeCmd(int argc, char *argv[]);
 
+	void drawActionMap(R_SURFACE *ds, int color) { _actionMap->draw(ds, color); }
+
  private:
 	int loadScene(int scene, int load_flag, R_SCENE_PROC scene_proc, R_SCENE_DESC *, 
 				  int fadeIn);
@@ -271,6 +274,9 @@
 	static int SC_defaultScene(int param, R_SCENE_INFO *scene_info, void *refCon);
 	int defaultScene(int param, R_SCENE_INFO *scene_info);
 
+ public:
+	ActionMap *_actionMap;
+
  private:
 	int IHNMStartProc();
 	int ITEStartProc();





More information about the Scummvm-git-logs mailing list