create objectMap class

svn-id: r14440
This commit is contained in:
Jonathan Gray 2004-08-02 15:44:18 +00:00
parent 632612680b
commit dcf5805440
9 changed files with 154 additions and 183 deletions

View file

@ -30,7 +30,7 @@
#include "actor_mod.h" #include "actor_mod.h"
#include "console_mod.h" #include "console_mod.h"
#include "font_mod.h" #include "font_mod.h"
#include "objectmap_mod.h" #include "objectmap.h"
#include "rscfile_mod.h" #include "rscfile_mod.h"
#include "script_mod.h" #include "script_mod.h"
#include "sprite_mod.h" #include "sprite_mod.h"
@ -480,7 +480,7 @@ int HandlePlayfieldClick(R_SURFACE *ds, R_POINT *imouse_pt) {
int script_num; int script_num;
R_POINT iactor_pt; R_POINT iactor_pt;
hit_object = OBJECTMAP_HitTest(imouse_pt, &object_num); hit_object = _vm->_objectMap->hitTest(imouse_pt, &object_num);
if (hit_object != R_SUCCESS) { if (hit_object != R_SUCCESS) {
// Player clicked on empty spot - walk here regardless of verb // Player clicked on empty spot - walk here regardless of verb
@ -489,13 +489,13 @@ int HandlePlayfieldClick(R_SURFACE *ds, R_POINT *imouse_pt) {
return R_SUCCESS; return R_SUCCESS;
} }
if (OBJECTMAP_GetFlags(object_num, &object_flags) != R_SUCCESS) { if (_vm->_objectMap->getFlags(object_num, &object_flags) != R_SUCCESS) {
CON_Print("Invalid object number: %d\n", object_num); CON_Print("Invalid object number: %d\n", object_num);
return R_FAILURE; return R_FAILURE;
} }
if (object_flags & R_OBJECT_NORMAL) { if (object_flags & R_OBJECT_NORMAL) {
if (OBJECTMAP_GetEPNum(object_num, &script_num) == R_SUCCESS) { if (_vm->_objectMap->getEPNum(object_num, &script_num) == R_SUCCESS) {
// Set active verb in script module // Set active verb in script module
_vm->_sdata->putWord(4, 4, I_VerbData[IfModule.active_verb].s_verb); _vm->_sdata->putWord(4, 4, I_VerbData[IfModule.active_verb].s_verb);
@ -524,7 +524,7 @@ int HandlePlayfieldUpdate(R_SURFACE *ds, R_POINT *imouse_pt) {
new_status[0] = 0; new_status[0] = 0;
hit_object = OBJECTMAP_HitTest(imouse_pt, &object_num); hit_object = _vm->_objectMap->hitTest(imouse_pt, &object_num);
if (hit_object != R_SUCCESS) { if (hit_object != R_SUCCESS) {
// Cursor over nothing - just display current verb // Cursor over nothing - just display current verb
@ -532,12 +532,12 @@ int HandlePlayfieldUpdate(R_SURFACE *ds, R_POINT *imouse_pt) {
return R_SUCCESS; return R_SUCCESS;
} }
if (OBJECTMAP_GetFlags(object_num, &object_flags) != R_SUCCESS) { if (_vm->_objectMap->getFlags(object_num, &object_flags) != R_SUCCESS) {
CON_Print("Invalid object number: %d\n", object_num); CON_Print("Invalid object number: %d\n", object_num);
return R_FAILURE; return R_FAILURE;
} }
OBJECTMAP_GetName(object_num, &object_name); _vm->_objectMap->getName(object_num, &object_name);
if (object_flags & R_OBJECT_NORMAL) { if (object_flags & R_OBJECT_NORMAL) {
// Normal scene object - display as subject of verb // Normal scene object - display as subject of verb

View file

@ -32,47 +32,39 @@
#include "cvar_mod.h" #include "cvar_mod.h"
#include "console_mod.h" #include "console_mod.h"
#include "font_mod.h" #include "font_mod.h"
#include "objectmap_mod.h"
#include "objectmap.h" #include "objectmap.h"
namespace Saga { namespace Saga {
static R_OBJECTMAP_INFO OMInfo; static void CF_object_info(int argc, char *argv[], void *refCon);
int OBJECTMAP_Register() { int ObjectMap::reg() {
CVAR_RegisterFunc(CF_object_info, "object_info", NULL, R_CVAR_NONE, 0, 0, NULL); CVAR_RegisterFunc(CF_object_info, "object_info", NULL, R_CVAR_NONE, 0, 0, NULL);
return R_SUCCESS; return R_SUCCESS;
} }
// Initializes the object map module, creates module allocation context // Initializes the object map module, creates module allocation context
int OBJECTMAP_Init() { ObjectMap::ObjectMap(Gfx *gfx) {
debug(0, "OBJECTMAP Module: Initializing..."); debug(0, "ObjectMap Module: Initializing...");
_gfx = gfx;
OMInfo.initialized = 1; _initialized = 1;
return R_SUCCESS;
} }
// Shuts down the object map module, destroys module allocation context // Shuts down the object map module, destroys module allocation context
int OBJECTMAP_Shutdown() { ObjectMap::~ObjectMap() {
if (!OMInfo.initialized) { debug(0, "ObjectMap Module: Shutting down...");
return R_FAILURE;
}
debug(0, "OBJECTMAP Module: Shutting down..."); freeMem();
freeNames();
OBJECTMAP_Free(); debug(0, "ObjectMap Module: Shutdown AOK.");
OBJECTMAP_FreeNames();
debug(0, "OBJECTMAP Module: Shutdown AOK."); _initialized = 0;
OMInfo.initialized = 0;
return R_SUCCESS;
} }
// Loads an object map resource ( objects ( clickareas ( points ) ) ) // Loads an object map resource ( objects ( clickareas ( points ) ) )
int OBJECTMAP_Load(const byte *om_res, size_t om_res_len) { int ObjectMap::load(const byte *om_res, size_t om_res_len) {
R_OBJECTMAP_ENTRY *object_map; R_OBJECTMAP_ENTRY *object_map;
R_CLICKAREA *clickarea; R_CLICKAREA *clickarea;
R_POINT *point; R_POINT *point;
@ -81,28 +73,28 @@ int OBJECTMAP_Load(const byte *om_res, size_t om_res_len) {
MemoryReadStream readS(om_res, om_res_len); MemoryReadStream readS(om_res, om_res_len);
if (!OMInfo.initialized) { if (!_initialized) {
warning("Error: Object map module not initialized"); warning("Error: Object map module not initialized");
return R_FAILURE; return R_FAILURE;
} }
if (OMInfo.objects_loaded) { if (_objects_loaded) {
OBJECTMAP_Free(); freeMem();
} }
// Obtain object count N and allocate space for N objects // Obtain object count N and allocate space for N objects
OMInfo.n_objects = readS.readUint16LE(); _n_objects = readS.readUint16LE();
OMInfo.object_maps = (R_OBJECTMAP_ENTRY *)malloc(OMInfo.n_objects * sizeof *OMInfo.object_maps); _object_maps = (R_OBJECTMAP_ENTRY *)malloc(_n_objects * sizeof *_object_maps);
if (OMInfo.object_maps == NULL) { if (_object_maps == NULL) {
warning("Error: Memory allocation failed"); warning("Error: Memory allocation failed");
return R_MEM; return R_MEM;
} }
// Load all N objects // Load all N objects
for (i = 0; i < OMInfo.n_objects; i++) { for (i = 0; i < _n_objects; i++) {
object_map = &OMInfo.object_maps[i]; object_map = &_object_maps[i];
object_map->unknown0 = readS.readByte(); object_map->unknown0 = readS.readByte();
object_map->n_clickareas = readS.readByte(); object_map->n_clickareas = readS.readByte();
object_map->flags = readS.readUint16LE(); object_map->flags = readS.readUint16LE();
@ -133,29 +125,29 @@ int OBJECTMAP_Load(const byte *om_res, size_t om_res_len) {
point->x = readS.readSint16LE(); point->x = readS.readSint16LE();
point->y = readS.readSint16LE(); point->y = readS.readSint16LE();
} }
debug(2, "OBJECTMAP_Load(): Read %d points for clickarea %d in object %d.", debug(2, "ObjectMap::load(): Read %d points for clickarea %d in object %d.",
clickarea->n_points, k, object_map->object_num); clickarea->n_points, k, object_map->object_num);
} }
} }
OMInfo.objects_loaded = 1; _objects_loaded = 1;
return R_SUCCESS; return R_SUCCESS;
} }
// Frees all storage allocated for the current object map data // Frees all storage allocated for the current object map data
int OBJECTMAP_Free() { int ObjectMap::freeMem() {
R_OBJECTMAP_ENTRY *object_map; R_OBJECTMAP_ENTRY *object_map;
R_CLICKAREA *clickarea; R_CLICKAREA *clickarea;
int i, k; int i, k;
if (!OMInfo.objects_loaded) { if (!_objects_loaded) {
return R_FAILURE; return R_FAILURE;
} }
for (i = 0; i < OMInfo.n_objects; i++) { for (i = 0; i < _n_objects; i++) {
object_map = &OMInfo.object_maps[i]; object_map = &_object_maps[i];
for (k = 0; k < object_map->n_clickareas; k++) { for (k = 0; k < object_map->n_clickareas; k++) {
clickarea = &object_map->clickareas[k]; clickarea = &object_map->clickareas[k];
free(clickarea->points); free(clickarea->points);
@ -163,17 +155,17 @@ int OBJECTMAP_Free() {
free(object_map->clickareas); free(object_map->clickareas);
} }
if (OMInfo.n_objects) { if (_n_objects) {
free(OMInfo.object_maps); free(_object_maps);
} }
OMInfo.objects_loaded = 0; _objects_loaded = 0;
return R_SUCCESS; return R_SUCCESS;
} }
// Loads an object name list resource // Loads an object name list resource
int OBJECTMAP_LoadNames(const unsigned char *onl_res, size_t onl_res_len) { int ObjectMap::loadNames(const unsigned char *onl_res, size_t onl_res_len) {
int table_len; int table_len;
int n_names; int n_names;
size_t name_offset; size_t name_offset;
@ -182,46 +174,46 @@ int OBJECTMAP_LoadNames(const unsigned char *onl_res, size_t onl_res_len) {
MemoryReadStream readS(onl_res, onl_res_len); MemoryReadStream readS(onl_res, onl_res_len);
if (OMInfo.names_loaded) { if (_names_loaded) {
OBJECTMAP_FreeNames(); freeNames();
} }
table_len = readS.readUint16LE(); table_len = readS.readUint16LE();
n_names = table_len / 2 - 2; n_names = table_len / 2 - 2;
OMInfo.n_names = n_names; _n_names = n_names;
debug(2, "OBJECTMAP_LoadNames: Loading %d object names.", n_names); debug(2, "ObjectMap::loadNames: Loading %d object names.", n_names);
OMInfo.names = (const char **)malloc(n_names * sizeof *OMInfo.names); _names = (const char **)malloc(n_names * sizeof *_names);
if (OMInfo.names == NULL) { if (_names == NULL) {
warning("Error: Memory allocation failed"); warning("Error: Memory allocation failed");
return R_MEM; return R_MEM;
} }
for (i = 0; i < n_names; i++) { for (i = 0; i < n_names; i++) {
name_offset = readS.readUint16LE(); name_offset = readS.readUint16LE();
OMInfo.names[i] = (const char *)(onl_res + name_offset); _names[i] = (const char *)(onl_res + name_offset);
debug(3, "Loaded object name string: %s", OMInfo.names[i]); debug(3, "Loaded object name string: %s", _names[i]);
} }
OMInfo.names_loaded = 1; _names_loaded = 1;
return R_SUCCESS; return R_SUCCESS;
} }
// Frees all storage allocated for the current object name list data // Frees all storage allocated for the current object name list data
int OBJECTMAP_FreeNames() { int ObjectMap::freeNames() {
if (!OMInfo.names_loaded) { if (!_names_loaded) {
return R_FAILURE; return R_FAILURE;
} }
if (OMInfo.n_names) { if (_n_names) {
free(OMInfo.names); free(_names);
} }
OMInfo.names_loaded = 0; _names_loaded = 0;
return R_SUCCESS; return R_SUCCESS;
} }
@ -229,34 +221,34 @@ int OBJECTMAP_FreeNames() {
// name list resource, the funciton sets '*name' to the descriptive string // name list resource, the funciton sets '*name' to the descriptive string
// corresponding to 'object' and returns R_SUCCESS. Otherwise it returns // corresponding to 'object' and returns R_SUCCESS. Otherwise it returns
// R_FAILURE. // R_FAILURE.
int OBJECTMAP_GetName(int object, const char **name) { int ObjectMap::getName(int object, const char **name) {
if (!OMInfo.names_loaded) { if (!_names_loaded) {
return R_FAILURE; return R_FAILURE;
} }
if ((object <= 0) || (object > OMInfo.n_names)) { if ((object <= 0) || (object > _n_names)) {
return R_FAILURE; return R_FAILURE;
} }
*name = OMInfo.names[object - 1]; *name = _names[object - 1];
return R_SUCCESS; return R_SUCCESS;
} }
int OBJECTMAP_GetFlags(int object, uint16 *flags) { int ObjectMap::getFlags(int object, uint16 *flags) {
int i; int i;
if (!OMInfo.names_loaded) { if (!_names_loaded) {
return R_FAILURE; return R_FAILURE;
} }
if ((object <= 0) || (object > OMInfo.n_names)) { if ((object <= 0) || (object > _n_names)) {
return R_FAILURE; return R_FAILURE;
} }
for (i = 0; i < OMInfo.n_objects; i++) { for (i = 0; i < _n_objects; i++) {
if (OMInfo.object_maps[i].object_num == object) { if (_object_maps[i].object_num == object) {
*flags = OMInfo.object_maps[i].flags; *flags = _object_maps[i].flags;
return R_SUCCESS; return R_SUCCESS;
} }
} }
@ -268,22 +260,22 @@ int OBJECTMAP_GetFlags(int object, uint16 *flags) {
// name list resource, the funciton sets '*ep_num' to the entrypoint number // name list resource, the funciton sets '*ep_num' to the entrypoint number
// corresponding to 'object' and returns R_SUCCESS. Otherwise, it returns // corresponding to 'object' and returns R_SUCCESS. Otherwise, it returns
// R_FAILURE. // R_FAILURE.
int OBJECTMAP_GetEPNum(int object, int *ep_num) { int ObjectMap::getEPNum(int object, int *ep_num) {
int i; int i;
if (!OMInfo.names_loaded) { if (!_names_loaded) {
return R_FAILURE; return R_FAILURE;
} }
if ((object < 0) || (object > (OMInfo.n_objects + 1))) { if ((object < 0) || (object > (_n_objects + 1))) {
return R_FAILURE; return R_FAILURE;
} }
for (i = 0; i < OMInfo.n_objects; i++) { for (i = 0; i < _n_objects; i++) {
if (OMInfo.object_maps[i].object_num == object) { if (_object_maps[i].object_num == object) {
*ep_num = OMInfo.object_maps[i].script_num; *ep_num = _object_maps[i].script_num;
return R_SUCCESS; return R_SUCCESS;
} }
} }
@ -293,7 +285,7 @@ int OBJECTMAP_GetEPNum(int object, int *ep_num) {
// Uses Gfx::drawLine to display all clickareas for each object in the // Uses Gfx::drawLine to display all clickareas for each object in the
// currently loaded object map resource. // currently loaded object map resource.
int OBJECTMAP_Draw(R_SURFACE *ds, R_POINT *imouse_pt, int color, int color2) { int ObjectMap::draw(R_SURFACE *ds, R_POINT *imouse_pt, int color, int color2) {
R_OBJECTMAP_ENTRY *object_map; R_OBJECTMAP_ENTRY *object_map;
R_CLICKAREA *clickarea; R_CLICKAREA *clickarea;
@ -308,47 +300,47 @@ int OBJECTMAP_Draw(R_SURFACE *ds, R_POINT *imouse_pt, int color, int color2) {
int pointcount = 0; int pointcount = 0;
int i, k; int i, k;
assert(OMInfo.initialized); assert(_initialized);
if (!OMInfo.objects_loaded) { if (!_objects_loaded) {
return R_FAILURE; return R_FAILURE;
} }
if (imouse_pt != NULL) { if (imouse_pt != NULL) {
if (OBJECTMAP_HitTest(imouse_pt, &object_num) == R_SUCCESS) { if (hitTest(imouse_pt, &object_num) == R_SUCCESS) {
hit_object = 1; hit_object = 1;
} }
} }
for (i = 0; i < OMInfo.n_objects; i++) { for (i = 0; i < _n_objects; i++) {
draw_color = color; draw_color = color;
if (hit_object && (object_num == OMInfo.object_maps[i].object_num)) { if (hit_object && (object_num == _object_maps[i].object_num)) {
snprintf(txt_buf, sizeof txt_buf, "obj %d: ? %d, f %X", snprintf(txt_buf, sizeof txt_buf, "obj %d: ? %d, f %X",
OMInfo.object_maps[i].object_num, _object_maps[i].object_num,
OMInfo.object_maps[i].unknown0, _object_maps[i].unknown0,
OMInfo.object_maps[i].flags); _object_maps[i].flags);
draw_txt = 1; draw_txt = 1;
draw_color = color2; draw_color = color2;
} }
object_map = &OMInfo.object_maps[i]; object_map = &_object_maps[i];
for (k = 0; k < object_map->n_clickareas; k++) { for (k = 0; k < object_map->n_clickareas; k++) {
clickarea = &object_map->clickareas[k]; clickarea = &object_map->clickareas[k];
pointcount = 0; pointcount = 0;
if (clickarea->n_points == 2) { if (clickarea->n_points == 2) {
// 2 points represent a box // 2 points represent a box
_vm->_gfx->drawFrame(ds, &clickarea->points[0], &clickarea->points[1], draw_color); _gfx->drawFrame(ds, &clickarea->points[0], &clickarea->points[1], draw_color);
} else if (clickarea->n_points > 2) { } else if (clickarea->n_points > 2) {
// Otherwise draw a polyline // Otherwise draw a polyline
_vm->_gfx->drawPolyLine(ds, clickarea->points, clickarea->n_points, draw_color); _gfx->drawPolyLine(ds, clickarea->points, clickarea->n_points, draw_color);
} }
} }
} }
if (draw_txt) { if (draw_txt) {
FONT_Draw(SMALL_FONT_ID, ds, txt_buf, 0, 2, 2, FONT_Draw(SMALL_FONT_ID, ds, txt_buf, 0, 2, 2,
_vm->_gfx->getWhite(), _vm->_gfx->getBlack(), FONT_OUTLINE); _gfx->getWhite(), _gfx->getBlack(), FONT_OUTLINE);
} }
return R_SUCCESS; return R_SUCCESS;
@ -379,7 +371,7 @@ static bool MATH_HitTestPoly(R_POINT *points, unsigned int npoints, R_POINT test
return inside_flag; return inside_flag;
} }
int OBJECTMAP_HitTest(R_POINT * imouse_pt, int *object_num) { int ObjectMap::hitTest(R_POINT * imouse_pt, int *object_num) {
R_POINT imouse; R_POINT imouse;
R_OBJECTMAP_ENTRY *object_map; R_OBJECTMAP_ENTRY *object_map;
R_CLICKAREA *clickarea; R_CLICKAREA *clickarea;
@ -394,8 +386,8 @@ int OBJECTMAP_HitTest(R_POINT * imouse_pt, int *object_num) {
imouse.y = imouse_pt->y; imouse.y = imouse_pt->y;
// Loop through all scene objects // Loop through all scene objects
for (i = 0; i < OMInfo.n_objects; i++) { for (i = 0; i < _n_objects; i++) {
object_map = &OMInfo.object_maps[i]; object_map = &_object_maps[i];
// Hit-test all clickareas for this object // Hit-test all clickareas for this object
for (k = 0; k < object_map->n_clickareas; k++) { for (k = 0; k < object_map->n_clickareas; k++) {
@ -426,28 +418,32 @@ int OBJECTMAP_HitTest(R_POINT * imouse_pt, int *object_num) {
return R_FAILURE; return R_FAILURE;
} }
static void CF_object_info(int argc, char *argv[], void *refCon) { void ObjectMap::objectInfo(int argc, char *argv[]) {
int i; int i;
(void)(argc); (void)(argc);
(void)(argv); (void)(argv);
if (!OMInfo.initialized) { if (!_initialized) {
return; return;
} }
CON_Print("%d objects loaded.", OMInfo.n_objects); CON_Print("%d objects loaded.", _n_objects);
for (i = 0; i < OMInfo.n_objects; i++) { for (i = 0; i < _n_objects; i++) {
CON_Print("%s:", OMInfo.names[i]); CON_Print("%s:", _names[i]);
CON_Print("%d. Unk1: %d, flags: %X, name_i: %d, scr_n: %d, ca_ct: %d", i, OMInfo.object_maps[i].unknown0, CON_Print("%d. Unk1: %d, flags: %X, name_i: %d, scr_n: %d, ca_ct: %d", i, _object_maps[i].unknown0,
OMInfo.object_maps[i].flags, _object_maps[i].flags,
OMInfo.object_maps[i].object_num, _object_maps[i].object_num,
OMInfo.object_maps[i].script_num, _object_maps[i].script_num,
OMInfo.object_maps[i].n_clickareas); _object_maps[i].n_clickareas);
} }
return; return;
} }
static void CF_object_info(int argc, char *argv[], void *refCon) {
((ObjectMap *)refCon)->objectInfo(argc, argv);
}
} // End of namespace Saga } // End of namespace Saga

View file

@ -28,6 +28,10 @@
namespace Saga { namespace Saga {
enum R_OBJECT_FLAGS {
R_OBJECT_NORMAL = 0x02
};
struct R_CLICKAREA { struct R_CLICKAREA {
int n_points; int n_points;
R_POINT *points; R_POINT *points;
@ -44,20 +48,36 @@ struct R_OBJECTMAP_ENTRY {
R_CLICKAREA *clickareas; R_CLICKAREA *clickareas;
}; };
struct R_OBJECTMAP_INFO { class Gfx;
int initialized;
int objects_loaded; class ObjectMap{
int n_objects; public:
R_OBJECTMAP_ENTRY *object_maps; int reg(void);
ObjectMap(Gfx *gfx);
~ObjectMap(void);
int load(const byte *om_res, size_t om_res_len);
int freeMem(void);
int loadNames(const byte *onl_res, size_t onl_res_len);
int freeNames();
int getName(int object, const char **name);
int getFlags(int object, uint16 *flags);
int getEPNum(int object, int *ep_num);
int draw(R_SURFACE *draw_surface, R_POINT *imouse_pt, int color, int color2);
int hitTest(R_POINT *imouse_pt, int *object_num);
void objectInfo(int argc, char *argv[]);
private:
int _initialized;
int names_loaded; int _objects_loaded;
int n_names; int _n_objects;
const char **names; R_OBJECTMAP_ENTRY *_object_maps;
int _names_loaded;
int _n_names;
const char **_names;
Gfx *_gfx;
}; };
static void CF_object_info(int argc, char *argv[], void *refCon);
} // End of namespace Saga } // End of namespace Saga
#endif #endif

View file

@ -1,50 +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$
*
*/
// Object map module public header file
#ifndef SAGA_OBJECTMAP_MOD_H__
#define SAGA_OBJECTMAP_MOD_H__
namespace Saga {
enum R_OBJECT_FLAGS {
R_OBJECT_NORMAL = 0x02
};
int OBJECTMAP_Register();
int OBJECTMAP_Init();
int OBJECTMAP_Shutdown();
int OBJECTMAP_Load(const byte *om_res, size_t om_res_len);
int OBJECTMAP_Free();
int OBJECTMAP_LoadNames(const byte *onl_res, size_t onl_res_len);
int OBJECTMAP_FreeNames();
int OBJECTMAP_GetName(int object, const char **name);
int OBJECTMAP_GetFlags(int object, uint16 *flags);
int OBJECTMAP_GetEPNum(int object, int *ep_num);
int OBJECTMAP_Draw(R_SURFACE *draw_surface, R_POINT *imouse_pt, int color, int color2);
int OBJECTMAP_HitTest(R_POINT *imouse_pt, int *object_num);
} // End of namespace Saga
#endif

View file

@ -36,7 +36,7 @@
#include "text_mod.h" #include "text_mod.h"
#include "actionmap.h" #include "actionmap.h"
#include "objectmap_mod.h" #include "objectmap.h"
#include "render.h" #include "render.h"
#include <common/timer.h> #include <common/timer.h>
@ -49,10 +49,11 @@ int Render::reg(void) {
return R_SUCCESS; return R_SUCCESS;
} }
Render::Render(SagaEngine *vm, OSystem *system, Gfx *gfx) { Render::Render(SagaEngine *vm, OSystem *system, Gfx *gfx, ObjectMap *omap) {
_vm = vm; _vm = vm;
_system = system; _system = system;
_gfx = gfx; _gfx = gfx;
_omap = omap;
_initialized = false; _initialized = false;
R_GAME_DISPLAYINFO disp_info; R_GAME_DISPLAYINFO disp_info;
@ -136,7 +137,7 @@ int Render::drawScene() {
// Display scene maps, if applicable // Display scene maps, if applicable
if (getFlags() & RF_OBJECTMAP_TEST) { if (getFlags() & RF_OBJECTMAP_TEST) {
OBJECTMAP_Draw(backbuf_surface, &mouse_pt, _gfx->getWhite(), _gfx->getBlack()); _omap->draw(backbuf_surface, &mouse_pt, _gfx->getWhite(), _gfx->getBlack());
_vm->_actionMap->draw(backbuf_surface, _gfx->matchColor(R_RGB_RED)); _vm->_actionMap->draw(backbuf_surface, _gfx->matchColor(R_RGB_RED));
} }

View file

@ -52,7 +52,7 @@ struct R_BUFFER_INFO {
class Render { class Render {
public: public:
int reg(void); int reg(void);
Render(SagaEngine *vm, OSystem *system, Gfx *gfx); Render(SagaEngine *vm, OSystem *system, Gfx *gfx, ObjectMap *omap);
~Render(void); ~Render(void);
bool initialized(); bool initialized();
int drawScene(void); int drawScene(void);
@ -71,6 +71,7 @@ private:
OSystem *_system; OSystem *_system;
bool _initialized; bool _initialized;
Gfx *_gfx; Gfx *_gfx;
ObjectMap *_omap;
// Module data // Module data
R_SURFACE *_backbuf_surface; R_SURFACE *_backbuf_surface;

View file

@ -53,7 +53,7 @@
#include "sndres.h" #include "sndres.h"
#include "sprite_mod.h" #include "sprite_mod.h"
#include "text_mod.h" #include "text_mod.h"
#include "objectmap_mod.h" #include "objectmap.h"
#include "sound.h" #include "sound.h"
#include "music.h" #include "music.h"
#include "game_mod.h" #include "game_mod.h"
@ -117,7 +117,6 @@ void SagaEngine::go() {
CON_Register(); // Register console cvars first CON_Register(); // Register console cvars first
GAME_Register(); GAME_Register();
OBJECTMAP_Register();
ACTOR_Register(); ACTOR_Register();
SCENE_Register(); SCENE_Register();
@ -154,7 +153,6 @@ void SagaEngine::go() {
FONT_Init(); FONT_Init();
SPRITE_Init(); SPRITE_Init();
_anim = new Anim(this); _anim = new Anim(this);
OBJECTMAP_Init();
_script = new Script(); _script = new Script();
_sdata = new SData(); _sdata = new SData();
INTERFACE_Init(); // requires script module INTERFACE_Init(); // requires script module
@ -190,14 +188,15 @@ void SagaEngine::go() {
GAME_GetDisplayInfo(&disp_info); GAME_GetDisplayInfo(&disp_info);
_gfx = new Gfx(_system, disp_info.logical_w, disp_info.logical_h); _gfx = new Gfx(_system, disp_info.logical_w, disp_info.logical_h);
_render = new Render(this, _system, _gfx); _isoMap = new IsoMap(_gfx);
_actionMap = new ActionMap(this);
_objectMap = new ObjectMap(_gfx);
_render = new Render(this, _system, _gfx, _objectMap);
if (!_render->initialized()) { if (!_render->initialized()) {
return; return;
} }
_isomap = new IsoMap(_gfx);
_actionMap = new ActionMap(this);
// Initialize system specific sound // Initialize system specific sound
_sound = new Sound(this, _mixer, MainData.sound_enabled); _sound = new Sound(this, _mixer, MainData.sound_enabled);
if (!MainData.sound_enabled) { if (!MainData.sound_enabled) {
@ -208,6 +207,7 @@ void SagaEngine::go() {
_render->reg(); _render->reg();
_anim->reg(); _anim->reg();
_actionMap->reg(); _actionMap->reg();
_objectMap->reg();
_previousTicks = _system->get_msecs(); _previousTicks = _system->get_msecs();
@ -247,7 +247,6 @@ void SagaEngine::shutdown() {
ACTOR_Shutdown(); ACTOR_Shutdown();
delete _script; delete _script;
SPRITE_Shutdown(); SPRITE_Shutdown();
OBJECTMAP_Shutdown();
FONT_Shutdown(); FONT_Shutdown();
CON_Shutdown(); CON_Shutdown();
CVAR_Shutdown(); CVAR_Shutdown();
@ -255,6 +254,8 @@ void SagaEngine::shutdown() {
delete _render; delete _render;
delete _actionMap; delete _actionMap;
delete _isoMap;
delete _objectMap;
delete _sndRes; delete _sndRes;
delete _sdata; delete _sdata;
// Shutdown system modules */ // Shutdown system modules */

View file

@ -44,6 +44,7 @@ class Anim;
class Render; class Render;
class ActionMap; class ActionMap;
class IsoMap; class IsoMap;
class ObjectMap;
class Gfx; class Gfx;
class SData; class SData;
class Script; class Script;
@ -95,7 +96,8 @@ public:
Anim *_anim; Anim *_anim;
Render *_render; Render *_render;
ActionMap *_actionMap; ActionMap *_actionMap;
IsoMap *_isomap; IsoMap *_isoMap;
ObjectMap *_objectMap;
Gfx *_gfx; Gfx *_gfx;
SData *_sdata; SData *_sdata;
Script *_script; Script *_script;

View file

@ -34,7 +34,7 @@
#include "actionmap.h" #include "actionmap.h"
#include "isomap.h" #include "isomap.h"
#include "script_mod.h" #include "script_mod.h"
#include "objectmap_mod.h" #include "objectmap.h"
#include "palanim_mod.h" #include "palanim_mod.h"
#include "render.h" #include "render.h"
#include "rscfile_mod.h" #include "rscfile_mod.h"
@ -611,11 +611,11 @@ int ProcessSceneResources() {
break; break;
case SAGA_OBJECT_NAME_LIST: case SAGA_OBJECT_NAME_LIST:
debug(0, "Loading object name list resource..."); debug(0, "Loading object name list resource...");
OBJECTMAP_LoadNames(SceneModule.reslist[i].res_data, SceneModule.reslist[i].res_data_len); _vm->_objectMap->loadNames(SceneModule.reslist[i].res_data, SceneModule.reslist[i].res_data_len);
break; break;
case SAGA_OBJECT_MAP: case SAGA_OBJECT_MAP:
debug(0, "Loading object map resource..."); debug(0, "Loading object map resource...");
if (OBJECTMAP_Load(res_data, if (_vm->_objectMap->load(res_data,
res_data_len) != R_SUCCESS) { res_data_len) != R_SUCCESS) {
warning("Error loading object map resource"); warning("Error loading object map resource");
return R_FAILURE; return R_FAILURE;
@ -636,7 +636,7 @@ int ProcessSceneResources() {
debug(0, "Loading isometric tileset resource."); debug(0, "Loading isometric tileset resource.");
if (_vm->_isomap->loadTileset(res_data, res_data_len) != R_SUCCESS) { if (_vm->_isoMap->loadTileset(res_data, res_data_len) != R_SUCCESS) {
warning("ProcessSceneResources: Error loading isometric tileset resource"); warning("ProcessSceneResources: Error loading isometric tileset resource");
return R_FAILURE; return R_FAILURE;
} }
@ -651,7 +651,7 @@ int ProcessSceneResources() {
debug(0, "Loading isometric metamap resource."); debug(0, "Loading isometric metamap resource.");
if (_vm->_isomap->loadMetamap(res_data, res_data_len) != R_SUCCESS) { if (_vm->_isoMap->loadMetamap(res_data, res_data_len) != R_SUCCESS) {
warning("ProcessSceneResources: Error loading isometric metamap resource"); warning("ProcessSceneResources: Error loading isometric metamap resource");
return R_FAILURE; return R_FAILURE;
} }
@ -666,7 +666,7 @@ int ProcessSceneResources() {
debug(0, "Loading isometric metatileset resource."); debug(0, "Loading isometric metatileset resource.");
if (_vm->_isomap->loadMetaTileset(res_data, res_data_len) != R_SUCCESS) { if (_vm->_isoMap->loadMetaTileset(res_data, res_data_len) != R_SUCCESS) {
warning("ProcessSceneResources: Error loading isometric tileset resource"); warning("ProcessSceneResources: Error loading isometric tileset resource");
return R_FAILURE; return R_FAILURE;
} }
@ -736,7 +736,7 @@ int SCENE_Draw(R_SURFACE *dst_s) {
MAX(disp_info.scene_h, SceneModule.bg.h), NULL, &bg_pt); MAX(disp_info.scene_h, SceneModule.bg.h), NULL, &bg_pt);
break; break;
case R_SCENE_MODE_ISO: case R_SCENE_MODE_ISO:
_vm->_isomap->draw(dst_s); _vm->_isoMap->draw(dst_s);
break; break;
default: default:
// Unknown scene mode // Unknown scene mode
@ -789,7 +789,7 @@ int SCENE_End() {
_vm->_anim->reset(); _vm->_anim->reset();
PALANIM_Free(); PALANIM_Free();
OBJECTMAP_Free(); _vm->_objectMap->freeMem();
_vm->_actionMap->freeMap(); _vm->_actionMap->freeMap();
ys_dll_destroy(SceneModule.anim_list); ys_dll_destroy(SceneModule.anim_list);