Objectize actionmap.cpp

svn-id: r14399
This commit is contained in:
Eugene Sandulenko 2004-08-01 00:03:45 +00:00
parent 7f5f1c1418
commit d530fc7696
8 changed files with 79 additions and 107 deletions

View file

@ -29,25 +29,24 @@
#include "console_mod.h"
#include "gfx_mod.h"
#include "actionmap_mod.h"
#include "actionmap.h"
namespace Saga {
static R_ACTIONMAP_INFO ActmapModule;
int ACTIONMAP_Register(void) {
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, NULL);
"action_info", NULL, R_CVAR_NONE, 0, 0, this);
return R_SUCCESS;
}
int ACTIONMAP_Init(void) {
ActionMap::ActionMap(void) {
debug(0, "ACTIONMAP Module: Initializing...");
ActmapModule.init = 1;
return R_SUCCESS;
_initialized = true;
}
int ACTIONMAP_Load(const byte * exmap_res, size_t exmap_res_len) {
int ActionMap::load(const byte * exmap_res, size_t exmap_res_len) {
// Loads exit map data from specified exit map resource
R_ACTIONMAP_ENTRY *exmap_entry;
R_POINT *exmap_pt_tbl;
@ -55,7 +54,7 @@ int ACTIONMAP_Load(const byte * exmap_res, size_t exmap_res_len) {
int exit_ct;
int i, pt;
assert(ActmapModule.init);
assert(_initialized);
assert(exmap_res != NULL);
MemoryReadStream *readS = new MemoryReadStream(exmap_res, exmap_res_len);
@ -98,68 +97,68 @@ int ACTIONMAP_Load(const byte * exmap_res, size_t exmap_res_len) {
exmap_entry[i].pt_tbl = exmap_pt_tbl;
}
ActmapModule.exits_loaded = 1;
ActmapModule.n_exits = exit_ct;
ActmapModule.exits_tbl = exmap_entry;
_exits_loaded = 1;
_n_exits = exit_ct;
_exits_tbl = exmap_entry;
ActmapModule.exmap_res = exmap_res;
ActmapModule.exmap_res_len = exmap_res_len;
_exmap_res = exmap_res;
_exmap_res_len = exmap_res_len;
return R_SUCCESS;
}
int ACTIONMAP_Free(void) {
int ActionMap::freeMap(void) {
// Frees the currently loaded exit map data
R_ACTIONMAP_ENTRY *exmap_entry;
int i;
if (!ActmapModule.exits_loaded) {
if (!_exits_loaded) {
return R_SUCCESS;
}
for (i = 0; i < ActmapModule.n_exits; i++) {
exmap_entry = &ActmapModule.exits_tbl[i];
for (i = 0; i < _n_exits; i++) {
exmap_entry = &_exits_tbl[i];
free(exmap_entry->pt_tbl);
}
free(ActmapModule.exits_tbl);
free(_exits_tbl);
ActmapModule.exits_loaded = 0;
ActmapModule.exits_tbl = NULL;
ActmapModule.n_exits = 0;
_exits_loaded = 0;
_exits_tbl = NULL;
_n_exits = 0;
return R_SUCCESS;
}
int ACTIONMAP_Shutdown(void) {
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(ActmapModule.init);
assert(_initialized);
if (!ActmapModule.exits_loaded) {
if (!_exits_loaded) {
return R_FAILURE;
}
for (i = 0; i < ActmapModule.n_exits; i++) {
if (ActmapModule.exits_tbl[i].pt_count == 2) {
for (i = 0; i < _n_exits; i++) {
if (_exits_tbl[i].pt_count == 2) {
GFX_DrawFrame(ds,
&ActmapModule.exits_tbl[i].pt_tbl[0],
&ActmapModule.exits_tbl[i].pt_tbl[1], color);
} else if (ActmapModule.exits_tbl[i].pt_count > 2) {
GFX_DrawPolyLine(ds, ActmapModule.exits_tbl[i].pt_tbl,
ActmapModule.exits_tbl[i].pt_count, color);
&_exits_tbl[i].pt_tbl[0],
&_exits_tbl[i].pt_tbl[1], color);
} else if (_exits_tbl[i].pt_count > 2) {
GFX_DrawPolyLine(ds, _exits_tbl[i].pt_tbl,
_exits_tbl[i].pt_count, color);
}
}
return R_SUCCESS;
}
void CF_action_info(int argc, char *argv[], void *refCon) {
void ActionMap::actionInfo(int argc, char *argv[]) {
R_POINT *pt;
int i;
@ -168,28 +167,30 @@ void CF_action_info(int argc, char *argv[], void *refCon) {
(void)(argc);
(void)(argv);
if (!ActmapModule.exits_loaded) {
if (!_exits_loaded) {
return;
}
CON_Print("%d exits loaded.\n", ActmapModule.n_exits);
CON_Print("%d exits loaded.\n", _n_exits);
for (i = 0; i < ActmapModule.n_exits; i++) {
for (i = 0; i < _n_exits; i++) {
CON_Print ("Action %d: Exit to: %d; Pts: %d; Unk0: %d Unk2: %d Scr_N: %d",
i, ActmapModule.exits_tbl[i].exit_scene,
ActmapModule.exits_tbl[i].pt_count,
ActmapModule.exits_tbl[i].unknown00,
ActmapModule.exits_tbl[i].unknown02,
ActmapModule.exits_tbl[i].unknown06);
i, _exits_tbl[i].exit_scene,
_exits_tbl[i].pt_count,
_exits_tbl[i].unknown00,
_exits_tbl[i].unknown02,
_exits_tbl[i].unknown06);
for (pt_i = 0; pt_i < ActmapModule.exits_tbl[i].pt_count; pt_i++) {
pt = &ActmapModule.exits_tbl[i].pt_tbl[pt_i];
for (pt_i = 0; pt_i < _exits_tbl[i].pt_count; pt_i++) {
pt = &_exits_tbl[i].pt_tbl[pt_i];
CON_Print(" pt: %d (%d, %d)", pt_i, pt->x, pt->y);
}
}
}
return;
static void CF_action_info(int argc, char *argv[], void *refCon) {
((ActionMap *)refCon)->actionInfo(argc, argv);
}
} // End of namespace Saga

View file

@ -38,16 +38,27 @@ struct R_ACTIONMAP_ENTRY {
R_POINT *pt_tbl;
};
struct R_ACTIONMAP_INFO {
int init;
int exits_loaded;
int n_exits;
R_ACTIONMAP_ENTRY *exits_tbl;
const byte *exmap_res;
size_t exmap_res_len;
};
class ActionMap {
public:
int reg(void);
ActionMap(void);
void CF_action_info(int argc, char *argv[], void *refCon);
int load(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[]);
private:
bool _initialized;
int _exits_loaded;
int _n_exits;
R_ACTIONMAP_ENTRY *_exits_tbl;
const byte *_exmap_res;
size_t _exmap_res_len;
};
} // End of namespace Saga

View file

@ -1,42 +0,0 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2004 The ScummVM project
*
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
// Action map module - public module header
#ifndef SAGA_ACTIONMAP_MOD_H_
#define SAGA_ACTIONMAP_MOD_H_
namespace Saga {
int ACTIONMAP_Register(void);
int ACTIONMAP_Init(void);
int ACTIONMAP_Load(const byte *exmap_res, size_t exmap_res_len);
int ACTIONMAP_Draw(R_SURFACE *ds, int color);
int ACTIONMAP_Free(void);
int ACTIONMAP_Shutdown(void);
} // End of namespace Saga
#endif

View file

@ -37,7 +37,7 @@
#include "sprite_mod.h"
#include "text_mod.h"
#include "actionmap_mod.h"
#include "actionmap.h"
#include "objectmap_mod.h"
#include "render.h"
@ -50,7 +50,7 @@ int Render::reg(void) {
return R_SUCCESS;
}
Render::Render(OSystem *system) : _system(system), _initialized(false) {
Render::Render(SagaEngine *vm, OSystem *system) : _vm(vm), _system(system), _initialized(false) {
R_GAME_DISPLAYINFO disp_info;
int tmp_w, tmp_h, tmp_bytepp;
@ -136,7 +136,7 @@ int Render::drawScene() {
// Display scene maps, if applicable
if (getFlags() & RF_OBJECTMAP_TEST) {
OBJECTMAP_Draw(backbuf_surface, &mouse_pt, GFX_GetWhite(), GFX_GetBlack());
ACTIONMAP_Draw(backbuf_surface, GFX_MatchColor(R_RGB_RED));
_vm->_actionMap->draw(backbuf_surface, GFX_MatchColor(R_RGB_RED));
}
// Draw queued actors

View file

@ -52,7 +52,7 @@ struct R_BUFFER_INFO {
class Render {
public:
int reg(void);
Render(OSystem *system);
Render(SagaEngine *vm, OSystem *system);
~Render(void);
bool initialized();
int drawScene(void);

View file

@ -43,7 +43,7 @@
#include "console_mod.h"
#include "cvar_mod.h"
#include "events_mod.h"
#include "actionmap_mod.h"
#include "actionmap.h"
#include "font_mod.h"
#include "game_mod.h"
#include "game.h"
@ -119,7 +119,6 @@ void SagaEngine::go() {
GAME_Register();
ACTIONMAP_Register();
OBJECTMAP_Register();
SCRIPT_Register();
ACTOR_Register();
@ -158,7 +157,7 @@ void SagaEngine::go() {
FONT_Init();
SPRITE_Init();
_anim = new Anim();
ACTIONMAP_Init();
_actionMap = new ActionMap();
OBJECTMAP_Init();
ISOMAP_Init();
SCRIPT_Init();
@ -194,7 +193,7 @@ void SagaEngine::go() {
}
// Initialize graphics
_render = new Render(_system);
_render = new Render(this, _system);
if (!_render->initialized()) {
return;
}
@ -207,6 +206,7 @@ void SagaEngine::go() {
_render->reg();
_anim->reg();
_actionMap->reg();
SYSTIMER_ResetMSCounter();

View file

@ -43,6 +43,7 @@ class Sound;
class Music;
class Anim;
class Render;
class ActionMap;
using Common::MemoryReadStream;
@ -71,6 +72,7 @@ public:
Music *_music;
Anim *_anim;
Render *_render;
ActionMap *_actionMap;
private:
int decodeBGImageRLE(const byte *inbuf, size_t inbuf_len, byte *outbuf, size_t outbuf_len);

View file

@ -32,7 +32,7 @@
#include "console_mod.h"
#include "cvar_mod.h"
#include "events_mod.h"
#include "actionmap_mod.h"
#include "actionmap.h"
#include "gfx_mod.h"
#include "isomap_mod.h"
#include "script_mod.h"
@ -622,7 +622,7 @@ int ProcessSceneResources() {
break;
case SAGA_ACTION_MAP:
debug(0, "Loading exit map resource...");
if (ACTIONMAP_Load(res_data, res_data_len) != R_SUCCESS) {
if (_vm->_actionMap->load(res_data, res_data_len) != R_SUCCESS) {
warning("Error loading exit map resource");
return R_FAILURE;
}
@ -792,7 +792,7 @@ int SCENE_End() {
PALANIM_Free();
OBJECTMAP_Free();
ACTIONMAP_Free();
_vm->_actionMap->freeMap();
ys_dll_destroy(SceneModule.anim_list);