More de-C'fying. Pass Point object instead of direct reference.

svn-id: r15458
This commit is contained in:
Eugene Sandulenko 2004-10-07 23:26:41 +00:00
parent 4dc49e713b
commit bf905b2eeb
8 changed files with 59 additions and 70 deletions

View file

@ -1022,9 +1022,9 @@ int Actor::AtoS(Point *screen, const Point *actor) {
return R_SUCCESS; return R_SUCCESS;
} }
int Actor::StoA(Point *actor, const Point *screen) { int Actor::StoA(Point *actor, const Point screen) {
actor->x = (screen->x * R_ACTOR_LMULT); actor->x = (screen.x * R_ACTOR_LMULT);
actor->y = (screen->y * R_ACTOR_LMULT); actor->y = (screen.y * R_ACTOR_LMULT);
return R_SUCCESS; return R_SUCCESS;
} }

View file

@ -197,7 +197,7 @@ class Actor {
int drawList(); int drawList();
int AtoS(Point *logical, const Point *actor); int AtoS(Point *logical, const Point *actor);
int StoA(Point *actor, const Point *screen); int StoA(Point *actor, const Point screen);
int move(int index, Point *move_pt); int move(int index, Point *move_pt);
int moveRelative(int index, Point *move_pt); int moveRelative(int index, Point *move_pt);

View file

@ -35,7 +35,7 @@ namespace Saga {
int SagaEngine::processInput() { int SagaEngine::processInput() {
OSystem::Event event; OSystem::Event event;
Point imouse_pt; Point imousePt;
while (g_system->pollEvent(event)) { while (g_system->pollEvent(event)) {
int in_char; int in_char;
@ -113,13 +113,13 @@ int SagaEngine::processInput() {
case OSystem::EVENT_LBUTTONDOWN: case OSystem::EVENT_LBUTTONDOWN:
_mousePos.x = event.mouse.x; _mousePos.x = event.mouse.x;
_mousePos.y = event.mouse.y; _mousePos.y = event.mouse.y;
imouse_pt = _mousePos; imousePt = _mousePos;
_vm->_interface->update(&imouse_pt, UPDATE_MOUSECLICK); _vm->_interface->update(imousePt, UPDATE_MOUSECLICK);
break; break;
case OSystem::EVENT_MOUSEMOVE: case OSystem::EVENT_MOUSEMOVE:
_mousePos.x = event.mouse.x; _mousePos.x = event.mouse.x;
_mousePos.y = event.mouse.y; _mousePos.y = event.mouse.y;
imouse_pt = _mousePos; imousePt = _mousePos;
break; break;
case OSystem::EVENT_QUIT: case OSystem::EVENT_QUIT:
g_system->quit(); g_system->quit();

View file

@ -303,21 +303,19 @@ int Interface::draw() {
return R_SUCCESS; return R_SUCCESS;
} }
int Interface::update(Point *imouse_pt, int update_flag) { int Interface::update(Point imousePt, int update_flag) {
R_GAME_DISPLAYINFO g_di; R_GAME_DISPLAYINFO g_di;
R_SURFACE *back_buf; R_SURFACE *back_buf;
int imouse_x, imouse_y; int imouse_x, imouse_y;
assert(imouse_pt != NULL);
if (!_active) { if (!_active) {
return R_SUCCESS; return R_SUCCESS;
} }
imouse_x = imouse_pt->x; imouse_x = imousePt.x;
imouse_y = imouse_pt->y; imouse_y = imousePt.y;
back_buf = _vm->_gfx->getBackBuffer(); back_buf = _vm->_gfx->getBackBuffer();
@ -328,17 +326,17 @@ int Interface::update(Point *imouse_pt, int update_flag) {
if (imouse_y < g_di.scene_h) { if (imouse_y < g_di.scene_h) {
// Mouse is in playfield space // Mouse is in playfield space
if (update_flag == UPDATE_MOUSEMOVE) { if (update_flag == UPDATE_MOUSEMOVE) {
handlePlayfieldUpdate(back_buf, imouse_pt); handlePlayfieldUpdate(back_buf, imousePt);
} else if (update_flag == UPDATE_MOUSECLICK) { } else if (update_flag == UPDATE_MOUSECLICK) {
handlePlayfieldClick(back_buf, imouse_pt); handlePlayfieldClick(back_buf, imousePt);
} }
} }
// Update command space // Update command space
if (update_flag == UPDATE_MOUSEMOVE) { if (update_flag == UPDATE_MOUSEMOVE) {
handleCommandUpdate(back_buf, imouse_pt); handleCommandUpdate(back_buf, imousePt);
} else if (update_flag == UPDATE_MOUSECLICK) { } else if (update_flag == UPDATE_MOUSECLICK) {
handleCommandClick(back_buf, imouse_pt); handleCommandClick(back_buf, imousePt);
} }
drawStatusBar(back_buf); drawStatusBar(back_buf);
@ -371,7 +369,7 @@ int Interface::drawStatusBar(R_SURFACE *ds) {
return R_SUCCESS; return R_SUCCESS;
} }
int Interface::handleCommandClick(R_SURFACE *ds, Point *imouse_pt) { int Interface::handleCommandClick(R_SURFACE *ds, Point imousePt) {
int hit_button; int hit_button;
int ibutton_num; int ibutton_num;
@ -384,7 +382,7 @@ int Interface::handleCommandClick(R_SURFACE *ds, Point *imouse_pt) {
int old_set_button; int old_set_button;
int set_button; int set_button;
hit_button = hitTest(imouse_pt, &ibutton_num); hit_button = hitTest(imousePt, &ibutton_num);
if (hit_button != R_SUCCESS) { if (hit_button != R_SUCCESS) {
// Clicking somewhere other than a button doesn't do anything // Clicking somewhere other than a button doesn't do anything
return R_SUCCESS; return R_SUCCESS;
@ -422,7 +420,7 @@ int Interface::handleCommandClick(R_SURFACE *ds, Point *imouse_pt) {
return R_SUCCESS; return R_SUCCESS;
} }
int Interface::handleCommandUpdate(R_SURFACE *ds, Point *imouse_pt) { int Interface::handleCommandUpdate(R_SURFACE *ds, Point imousePt) {
int hit_button; int hit_button;
int ibutton_num; int ibutton_num;
@ -436,7 +434,7 @@ int Interface::handleCommandUpdate(R_SURFACE *ds, Point *imouse_pt) {
int color; int color;
int i; int i;
hit_button = hitTest(imouse_pt, &ibutton_num); hit_button = hitTest(imousePt, &ibutton_num);
if (hit_button == R_SUCCESS) { if (hit_button == R_SUCCESS) {
// Hovering over a command panel button // Hovering over a command panel button
@ -476,27 +474,26 @@ int Interface::handleCommandUpdate(R_SURFACE *ds, Point *imouse_pt) {
return R_SUCCESS; return R_SUCCESS;
} }
int Interface::handlePlayfieldClick(R_SURFACE *ds, Point *imouse_pt) { int Interface::handlePlayfieldClick(R_SURFACE *ds, Point imousePt) {
int hit_object; int objectNum;
int object_num;
uint16 object_flags = 0; uint16 object_flags = 0;
int script_num; int script_num;
Point iactor_pt; Point iactor_pt;
hit_object = _vm->_scene->_objectMap->hitTest(imouse_pt, &object_num); objectNum = _vm->_scene->_objectMap->hitTest(imousePt);
if (hit_object != R_SUCCESS) { if (objectNum == -1) {
// Player clicked on empty spot - walk here regardless of verb // Player clicked on empty spot - walk here regardless of verb
_vm->_actor->StoA(&iactor_pt, imouse_pt); _vm->_actor->StoA(&iactor_pt, imousePt);
_vm->_actor->walkTo(0, &iactor_pt, 0, NULL); _vm->_actor->walkTo(0, &iactor_pt, 0, NULL);
return R_SUCCESS; return R_SUCCESS;
} }
object_flags = _vm->_scene->_objectMap->getFlags(object_num); object_flags = _vm->_scene->_objectMap->getFlags(objectNum);
if (object_flags & R_OBJECT_NORMAL) { if (object_flags & R_OBJECT_NORMAL) {
if ((script_num = _vm->_scene->_objectMap->getEPNum(object_num)) != -1) { if ((script_num = _vm->_scene->_objectMap->getEPNum(objectNum)) != -1) {
// Set active verb in script module // Set active verb in script module
_vm->_sdata->putWord(4, 4, I_VerbData[_activeVerb].s_verb); _vm->_sdata->putWord(4, 4, I_VerbData[_activeVerb].s_verb);
@ -507,35 +504,33 @@ int Interface::handlePlayfieldClick(R_SURFACE *ds, Point *imouse_pt) {
} }
} else { } else {
// Not a normal scene object - walk to it as if it weren't there // Not a normal scene object - walk to it as if it weren't there
_vm->_actor->StoA(&iactor_pt, imouse_pt); _vm->_actor->StoA(&iactor_pt, imousePt);
_vm->_actor->walkTo(0, &iactor_pt, 0, NULL); _vm->_actor->walkTo(0, &iactor_pt, 0, NULL);
} }
return R_SUCCESS; return R_SUCCESS;
} }
int Interface::handlePlayfieldUpdate(R_SURFACE *ds, Point *imouse_pt) { int Interface::handlePlayfieldUpdate(R_SURFACE *ds, Point imousePt) {
const char *object_name; const char *object_name;
int object_num; int objectNum;
uint16 object_flags = 0; uint16 object_flags = 0;
char new_status[R_STATUS_TEXT_LEN]; char new_status[R_STATUS_TEXT_LEN];
int hit_object;
new_status[0] = 0; new_status[0] = 0;
hit_object = _vm->_scene->_objectMap->hitTest(imouse_pt, &object_num); objectNum = _vm->_scene->_objectMap->hitTest(imousePt);
if (hit_object != R_SUCCESS) { if (objectNum == -1) {
// Cursor over nothing - just display current verb // Cursor over nothing - just display current verb
setStatusText(I_VerbData[_activeVerb].verb_str); setStatusText(I_VerbData[_activeVerb].verb_str);
return R_SUCCESS; return R_SUCCESS;
} }
object_flags = _vm->_scene->_objectMap->getFlags(object_num); object_flags = _vm->_scene->_objectMap->getFlags(objectNum);
object_name = _vm->_scene->_objectMap->getName(object_num); object_name = _vm->_scene->_objectMap->getName(objectNum);
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
@ -551,7 +546,7 @@ int Interface::handlePlayfieldUpdate(R_SURFACE *ds, Point *imouse_pt) {
return R_SUCCESS; return R_SUCCESS;
} }
int Interface::hitTest(Point *imouse_pt, int *ibutton) { int Interface::hitTest(Point imousePt, int *ibutton) {
R_INTERFACE_BUTTON *buttons; R_INTERFACE_BUTTON *buttons;
int nbuttons; int nbuttons;
@ -567,8 +562,8 @@ int Interface::hitTest(Point *imouse_pt, int *ibutton) {
ybase = _cPanel.y; ybase = _cPanel.y;
for (i = 0; i < nbuttons; i++) { for (i = 0; i < nbuttons; i++) {
if ((imouse_pt->x >= (xbase + buttons[i].x1)) && (imouse_pt->x < (xbase + buttons[i].x2)) && if ((imousePt.x >= (xbase + buttons[i].x1)) && (imousePt.x < (xbase + buttons[i].x2)) &&
(imouse_pt->y >= (ybase + buttons[i].y1)) && (imouse_pt->y < (ybase + buttons[i].y2))) { (imousePt.y >= (ybase + buttons[i].y1)) && (imousePt.y < (ybase + buttons[i].y2))) {
*ibutton = i; *ibutton = i;
return R_SUCCESS; return R_SUCCESS;
} }

View file

@ -160,16 +160,16 @@ class Interface {
int deactivate(); int deactivate();
int setStatusText(const char *new_txt); int setStatusText(const char *new_txt);
int draw(); int draw();
int update(Point *imouse_pt, int update_flag); int update(Point imousePt, int update_flag);
private: private:
int hitTest(Point *imouse_pt, int *ibutton); int hitTest(Point imousePt, int *ibutton);
int drawStatusBar(R_SURFACE *ds); int drawStatusBar(R_SURFACE *ds);
int handleCommandUpdate(R_SURFACE *ds, Point *imouse_pt); int handleCommandUpdate(R_SURFACE *ds, Point imousePt);
int handleCommandClick(R_SURFACE *ds, Point *imouse_pt); int handleCommandClick(R_SURFACE *ds, Point imousePt);
int handlePlayfieldUpdate(R_SURFACE *ds, Point *imouse_pt); int handlePlayfieldUpdate(R_SURFACE *ds, Point imousePt);
int handlePlayfieldClick(R_SURFACE *ds, Point *imouse_pt); int handlePlayfieldClick(R_SURFACE *ds, Point imousePt);
private: private:
SagaEngine *_vm; SagaEngine *_vm;

View file

@ -40,6 +40,7 @@ namespace Saga {
ObjectMap::ObjectMap(SagaEngine *vm) : _vm(vm) { ObjectMap::ObjectMap(SagaEngine *vm) : _vm(vm) {
_objectsLoaded = false; _objectsLoaded = false;
_namesLoaded = false; _namesLoaded = false;
_nNames = 0;
} }
// Shuts down the object map module, destroys module allocation context // Shuts down the object map module, destroys module allocation context
@ -213,6 +214,7 @@ const uint16 ObjectMap::getFlags(int object) {
int i; int i;
assert(_namesLoaded); assert(_namesLoaded);
debug(0, "object: %d nnames: %d", object, _nNames);
assert((object > 0) && (object <= _nNames)); assert((object > 0) && (object <= _nNames));
for (i = 0; i < _nObjects; i++) { for (i = 0; i < _nObjects; i++) {
@ -245,7 +247,7 @@ const int ObjectMap::getEPNum(int object) {
// 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, Point *imouse_pt, int color, int color2) { int ObjectMap::draw(R_SURFACE *ds, Point imousePt, int color, int color2) {
R_OBJECTMAP_ENTRY *object_map; R_OBJECTMAP_ENTRY *object_map;
R_CLICKAREA *clickarea; R_CLICKAREA *clickarea;
@ -254,7 +256,7 @@ int ObjectMap::draw(R_SURFACE *ds, Point *imouse_pt, int color, int color2) {
int draw_color = color; int draw_color = color;
int draw_txt = 0; int draw_txt = 0;
int hit_object = 0; bool hitObject = false;
int objectNum = 0; int objectNum = 0;
int pointcount = 0; int pointcount = 0;
@ -264,15 +266,13 @@ int ObjectMap::draw(R_SURFACE *ds, Point *imouse_pt, int color, int color2) {
return R_FAILURE; return R_FAILURE;
} }
if (imouse_pt != NULL) { if ((objectNum = hitTest(imousePt)) != -1) {
if (hitTest(imouse_pt, &objectNum) == R_SUCCESS) { hitObject = true;
hit_object = 1;
}
} }
for (i = 0; i < _nObjects; i++) { for (i = 0; i < _nObjects; i++) {
draw_color = color; draw_color = color;
if (hit_object && (objectNum == _objectMaps[i].objectNum)) { if (hitObject && (objectNum == _objectMaps[i].objectNum)) {
snprintf(txt_buf, sizeof txt_buf, "obj %d: v %d, f %X", snprintf(txt_buf, sizeof txt_buf, "obj %d: v %d, f %X",
_objectMaps[i].objectNum, _objectMaps[i].objectNum,
_objectMaps[i].defaultVerb, _objectMaps[i].defaultVerb,
@ -329,7 +329,7 @@ static bool MATH_HitTestPoly(Point *points, unsigned int npoints, Point test_poi
return inside_flag; return inside_flag;
} }
int ObjectMap::hitTest(Point *imouse_pt, int *objectNum) { int ObjectMap::hitTest(Point imousePt) {
Point imouse; Point imouse;
R_OBJECTMAP_ENTRY *object_map; R_OBJECTMAP_ENTRY *object_map;
R_CLICKAREA *clickarea; R_CLICKAREA *clickarea;
@ -338,10 +338,8 @@ int ObjectMap::hitTest(Point *imouse_pt, int *objectNum) {
int i, k; int i, k;
assert((imouse_pt != NULL) && (objectNum != NULL)); imouse.x = imousePt.x;
imouse.y = imousePt.y;
imouse.x = imouse_pt->x;
imouse.y = imouse_pt->y;
// Loop through all scene objects // Loop through all scene objects
for (i = 0; i < _nObjects; i++) { for (i = 0; i < _nObjects; i++) {
@ -358,22 +356,18 @@ int ObjectMap::hitTest(Point *imouse_pt, int *objectNum) {
if ((imouse.x > points[0].x) && (imouse.x <= points[1].x) && if ((imouse.x > points[0].x) && (imouse.x <= points[1].x) &&
(imouse.y > points[0].y) && (imouse.y > points[0].y) &&
(imouse.y <= points[1].y)) { (imouse.y <= points[1].y)) {
*objectNum = object_map->objectNum; return object_map->objectNum;
return R_SUCCESS;
} }
} else if (n_points > 2) { } else if (n_points > 2) {
// Hit-test a polygon // Hit-test a polygon
if (MATH_HitTestPoly(points, n_points, imouse)) { if (MATH_HitTestPoly(points, n_points, imouse)) {
*objectNum = object_map->objectNum; return object_map->objectNum;
return R_SUCCESS;
} }
} }
} }
} }
*objectNum = 0; return -1;
return R_FAILURE;
} }
void ObjectMap::info(void) { void ObjectMap::info(void) {

View file

@ -63,8 +63,8 @@ public:
const char *getName(int object); const char *getName(int object);
const uint16 getFlags(int object); const uint16 getFlags(int object);
const int getEPNum(int object); const int getEPNum(int object);
int draw(R_SURFACE *draw_surface, Point *imousePt, int color, int color2); int draw(R_SURFACE *draw_surface, Point imousePt, int color, int color2);
int hitTest(Point *imouse_pt, int *object_num); int hitTest(Point imousePt);
void info(void); void info(void);
private: private:

View file

@ -134,7 +134,7 @@ int Render::drawScene() {
// Display scene maps, if applicable // Display scene maps, if applicable
if (getFlags() & RF_OBJECTMAP_TEST) { if (getFlags() & RF_OBJECTMAP_TEST) {
_vm->_scene->_objectMap->draw(backbuf_surface, &mouse_pt, _vm->_gfx->getWhite(), _vm->_gfx->getBlack()); _vm->_scene->_objectMap->draw(backbuf_surface, mouse_pt, _vm->_gfx->getWhite(), _vm->_gfx->getBlack());
_vm->_scene->_actionMap->draw(backbuf_surface, _vm->_gfx->matchColor(R_RGB_RED)); _vm->_scene->_actionMap->draw(backbuf_surface, _vm->_gfx->matchColor(R_RGB_RED));
} }
@ -167,7 +167,7 @@ int Render::drawScene() {
// Update user interface // Update user interface
_vm->_interface->update(&mouse_pt, UPDATE_MOUSEMOVE); _vm->_interface->update(mouse_pt, UPDATE_MOUSEMOVE);
// Display text formatting test, if applicable // Display text formatting test, if applicable
if (_flags & RF_TEXT_TEST) { if (_flags & RF_TEXT_TEST) {