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;
}
int Actor::StoA(Point *actor, const Point *screen) {
actor->x = (screen->x * R_ACTOR_LMULT);
actor->y = (screen->y * R_ACTOR_LMULT);
int Actor::StoA(Point *actor, const Point screen) {
actor->x = (screen.x * R_ACTOR_LMULT);
actor->y = (screen.y * R_ACTOR_LMULT);
return R_SUCCESS;
}

View file

@ -197,7 +197,7 @@ class Actor {
int drawList();
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 moveRelative(int index, Point *move_pt);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -134,7 +134,7 @@ int Render::drawScene() {
// Display scene maps, if applicable
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));
}
@ -167,7 +167,7 @@ int Render::drawScene() {
// Update user interface
_vm->_interface->update(&mouse_pt, UPDATE_MOUSEMOVE);
_vm->_interface->update(mouse_pt, UPDATE_MOUSEMOVE);
// Display text formatting test, if applicable
if (_flags & RF_TEXT_TEST) {