mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-31 07:53:36 +00:00
Moved the "router" code into a new Router class. I'm hoping this is
analogous to the SkyAutoRoute class. svn-id: r10754
This commit is contained in:
parent
c38ca923d8
commit
1b52e11d55
@ -893,7 +893,7 @@ int32 OptionsDialog::writeOptionSettings(void) {
|
||||
SaveFile *fp;
|
||||
SaveFileManager *mgr = g_system->get_savefile_manager();
|
||||
|
||||
sprintf(filename, "%s-settings.dat", g_sword2->_game_name);
|
||||
sprintf(filename, "%s-settings.dat", g_sword2->_gameName);
|
||||
|
||||
buff[0] = g_sound->getMusicVolume();
|
||||
buff[1] = g_sound->getSpeechVolume();
|
||||
@ -1435,7 +1435,7 @@ void Gui::restartControl(void) {
|
||||
DEMO = temp_demo_flag;
|
||||
|
||||
// free all the route memory blocks from previous game
|
||||
FreeAllRouteMem();
|
||||
router.freeAllRouteMem();
|
||||
|
||||
// call the same function that first started us up
|
||||
g_sword2->Start_game();
|
||||
@ -1483,7 +1483,7 @@ int32 Gui::readOptionSettings(void) {
|
||||
SaveFile *fp;
|
||||
SaveFileManager *mgr = g_system->get_savefile_manager();
|
||||
|
||||
sprintf(filename, "%s-settings.dat", g_sword2->_game_name);
|
||||
sprintf(filename, "%s-settings.dat", g_sword2->_gameName);
|
||||
|
||||
if (!(fp = mgr->open_savefile(filename, g_sword2->getSavePath(), false)))
|
||||
return 1;
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "bs2/mouse.h"
|
||||
#include "bs2/protocol.h"
|
||||
#include "bs2/resman.h"
|
||||
#include "bs2/router.h" // for PlotWalkGrid()
|
||||
#include "bs2/router.h" // for plotWalkGrid()
|
||||
#include "bs2/speech.h" // for 'officialTextNumber' and
|
||||
// 'speechScriptWaiting'
|
||||
|
||||
@ -358,7 +358,7 @@ void Draw_debug_graphics(void) {
|
||||
// walk-grid
|
||||
|
||||
if (displayWalkGrid)
|
||||
PlotWalkGrid();
|
||||
router.plotWalkGrid();
|
||||
|
||||
// player feet coord marker
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "bs2/debug.h"
|
||||
#include "bs2/interpreter.h"
|
||||
#include "bs2/logic.h"
|
||||
#include "bs2/router.h" // for ClearWalkGridList()
|
||||
#include "bs2/router.h" // for clearWalkGridList()
|
||||
#include "bs2/sound.h"
|
||||
#include "bs2/sync.h"
|
||||
|
||||
@ -237,13 +237,13 @@ void logic::expressChangeSession(uint32 sesh_id) {
|
||||
Init_sync_system();
|
||||
|
||||
// reset walkgrid list (see FN_register_walkgrid)
|
||||
ClearWalkGridList();
|
||||
router.clearWalkGridList();
|
||||
|
||||
// stops all fx & clears the queue
|
||||
Clear_fx_queue();
|
||||
|
||||
// free all the route memory blocks from previous game
|
||||
FreeAllRouteMem();
|
||||
router.freeAllRouteMem();
|
||||
}
|
||||
|
||||
void logic::naturalChangeSession(uint32 sesh_id) {
|
||||
|
1659
sword2/router.cpp
1659
sword2/router.cpp
File diff suppressed because it is too large
Load Diff
186
sword2/router.h
186
sword2/router.h
@ -23,6 +23,14 @@
|
||||
#include "bs2/memory.h"
|
||||
#include "bs2/object.h"
|
||||
|
||||
// This used to be a variable, but it was never set. Actually, it wasn't even
|
||||
// initialised!
|
||||
//
|
||||
// Define this to force the use of slidy router (so solid path not used when
|
||||
// ending walk in ANY direction)
|
||||
//
|
||||
// #define FORCE_SLIDY
|
||||
|
||||
namespace Sword2 {
|
||||
|
||||
#if !defined(__GNUC__)
|
||||
@ -48,7 +56,8 @@ struct _barData {
|
||||
int16 ymax;
|
||||
int16 dx; // x2 - x1
|
||||
int16 dy; // y2 - y1
|
||||
int32 co; // co = (y1 *dx)- (x1*dy) from an equation for a line y*dx = x*dy + co
|
||||
int32 co; // co = (y1 * dx) - (x1 * dy) from an equation for a
|
||||
// line y * dx = x * dy + co
|
||||
} GCC_PACK;
|
||||
|
||||
struct _nodeData {
|
||||
@ -63,22 +72,173 @@ struct _nodeData {
|
||||
#pragma END_PACK_STRUCTS
|
||||
#endif
|
||||
|
||||
int32 RouteFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, int32 y, int32 dir);
|
||||
// because we only have 2 megas in the game!
|
||||
#define TOTAL_ROUTE_SLOTS 2
|
||||
|
||||
void EarlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata);
|
||||
#define MAX_FRAMES_PER_CYCLE 16
|
||||
#define NO_DIRECTIONS 8
|
||||
#define MAX_FRAMES_PER_CHAR (MAX_FRAMES_PER_CYCLE * NO_DIRECTIONS)
|
||||
#define ROUTE_END_FLAG 255
|
||||
|
||||
void AllocateRouteMem(void);
|
||||
_walkData* LockRouteMem(void);
|
||||
void FloatRouteMem(void);
|
||||
void FreeRouteMem(void);
|
||||
void FreeAllRouteMem(void);
|
||||
void AddWalkGrid(int32 gridResource);
|
||||
void RemoveWalkGrid(int32 gridResource);
|
||||
void ClearWalkGridList(void);
|
||||
#define MAX_WALKGRIDS 10
|
||||
|
||||
#define O_WALKANIM_SIZE 600 // max number of nodes in router output
|
||||
#define O_GRID_SIZE 200 // max 200 lines & 200 points
|
||||
#define EXTRA_GRID_SIZE 20 // max 20 lines & 20 points
|
||||
#define O_ROUTE_SIZE 50 // max number of modules in a route
|
||||
|
||||
typedef struct {
|
||||
int32 x;
|
||||
int32 y;
|
||||
int32 dirS;
|
||||
int32 dirD;
|
||||
} _routeData;
|
||||
|
||||
typedef struct {
|
||||
int32 x;
|
||||
int32 y;
|
||||
int32 dir;
|
||||
int32 num;
|
||||
} _pathData;
|
||||
|
||||
class Router {
|
||||
private:
|
||||
// stores pointers to mem blocks containing routes created & used by
|
||||
// megas (NULL if slot not in use)
|
||||
mem *_routeSlots[TOTAL_ROUTE_SLOTS];
|
||||
|
||||
// because extra bars will be copied into here afer walkgrid loaded
|
||||
_barData _bars[O_GRID_SIZE + EXTRA_GRID_SIZE];
|
||||
_nodeData _node[O_GRID_SIZE + EXTRA_GRID_SIZE];
|
||||
|
||||
int32 _walkGridList[MAX_WALKGRIDS];
|
||||
|
||||
int32 _nbars;
|
||||
int32 _nnodes;
|
||||
|
||||
// area for extra route data to block parts of floors and enable
|
||||
// routing round mega charaters
|
||||
|
||||
int32 _nExtraBars;
|
||||
int32 _nExtraNodes;
|
||||
_barData _extraBars[EXTRA_GRID_SIZE];
|
||||
_nodeData _extraNode[EXTRA_GRID_SIZE];
|
||||
|
||||
int32 _startX;
|
||||
int32 _startY;
|
||||
int32 _startDir;
|
||||
int32 _targetX;
|
||||
int32 _targetY;
|
||||
int32 _targetDir;
|
||||
int32 _scaleA;
|
||||
int32 _scaleB;
|
||||
_routeData _route[O_ROUTE_SIZE];
|
||||
_pathData _smoothPath[O_ROUTE_SIZE];
|
||||
_pathData _modularPath[O_ROUTE_SIZE];
|
||||
int32 _routeLength;
|
||||
|
||||
int32 _framesPerStep;
|
||||
int32 _framesPerChar;
|
||||
|
||||
uint8 _nWalkFrames; // no. of frames per walk cycle
|
||||
uint8 _usingStandingTurnFrames; // any standing turn frames?
|
||||
uint8 _usingWalkingTurnFrames; // any walking turn frames?
|
||||
uint8 _usingSlowInFrames; // any slow-in frames?
|
||||
uint8 _usingSlowOutFrames; // any slow-out frames?
|
||||
int32 _dx[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR];
|
||||
int32 _dy[NO_DIRECTIONS + MAX_FRAMES_PER_CHAR];
|
||||
int8 _modX[NO_DIRECTIONS];
|
||||
int8 _modY[NO_DIRECTIONS];
|
||||
int32 _diagonalx;
|
||||
int32 _diagonaly;
|
||||
|
||||
int32 _firstStandFrame;
|
||||
|
||||
int32 _firstStandingTurnLeftFrame;
|
||||
int32 _firstStandingTurnRightFrame;
|
||||
|
||||
int32 _firstWalkingTurnLeftFrame; // left walking turn
|
||||
int32 _firstWalkingTurnRightFrame; // right walking turn
|
||||
|
||||
uint32 _firstSlowInFrame[NO_DIRECTIONS];
|
||||
uint32 _numberOfSlowInFrames[NO_DIRECTIONS];
|
||||
|
||||
uint32 _leadingLeg[NO_DIRECTIONS];
|
||||
|
||||
int32 _firstSlowOutFrame;
|
||||
|
||||
// number of slow-out frames on for each leading-leg in each direction
|
||||
// ie. total number of slow-out frames = (numberOfSlowOutFrames * 2 *
|
||||
// NO_DIRECTIONS)
|
||||
|
||||
int32 _numberOfSlowOutFrames;
|
||||
|
||||
int32 _stepCount;
|
||||
|
||||
int32 _moduleX;
|
||||
int32 _moduleY;
|
||||
int32 _currentDir;
|
||||
int32 _lastCount;
|
||||
int32 _frame;
|
||||
|
||||
uint8 returnSlotNo(uint32 megaId);
|
||||
|
||||
int32 getRoute(void);
|
||||
void extractRoute(void);
|
||||
void loadWalkGrid(void);
|
||||
void setUpWalkGrid(Object_mega *ob_mega, int32 x, int32 y, int32 dir);
|
||||
void loadWalkData(Object_walkdata *ob_walkdata);
|
||||
int32 scan(int32 level);
|
||||
|
||||
int32 newCheck(int32 status, int32 x1, int32 y1, int32 x2, int32 y2);
|
||||
int32 lineCheck(int32 x1, int32 x2, int32 y1, int32 y2);
|
||||
int32 vertCheck(int32 x, int32 y1, int32 y2);
|
||||
int32 horizCheck(int32 x1, int32 y, int32 x2);
|
||||
int32 check(int32 x1, int32 y1, int32 x2, int32 y2);
|
||||
int32 checkTarget(int32 x, int32 y);
|
||||
|
||||
int32 smoothestPath(void);
|
||||
int32 slidyPath(void);
|
||||
|
||||
int32 smoothCheck(int32 best, int32 p, int32 dirS, int32 dirD);
|
||||
|
||||
int32 addSlowInFrames(_walkData *walkAnim);
|
||||
void addSlowOutFrames(_walkData *walkAnim);
|
||||
void slidyWalkAnimator(_walkData *walkAnim);
|
||||
|
||||
#ifndef FORCE_SLIDY
|
||||
int32 solidPath(void);
|
||||
int32 solidWalkAnimator(_walkData *walkAnim);
|
||||
#endif
|
||||
|
||||
#ifdef _SWORD2_DEBUG
|
||||
void plotCross(int16 x, int16 y, uint8 colour);
|
||||
#endif
|
||||
|
||||
public:
|
||||
Router() :
|
||||
_nExtraBars(0), _nExtraNodes(0), _diagonalx(0),
|
||||
_diagonaly(0) {}
|
||||
|
||||
int32 routeFinder(Object_mega *ob_mega, Object_walkdata *ob_walkdata, int32 x, int32 y, int32 dir);
|
||||
|
||||
void earlySlowOut(Object_mega *ob_mega, Object_walkdata *ob_walkdata);
|
||||
|
||||
void allocateRouteMem(void);
|
||||
_walkData* lockRouteMem(void);
|
||||
void floatRouteMem(void);
|
||||
void freeRouteMem(void);
|
||||
void freeAllRouteMem(void);
|
||||
void addWalkGrid(int32 gridResource);
|
||||
void removeWalkGrid(int32 gridResource);
|
||||
void clearWalkGridList(void);
|
||||
|
||||
#ifdef _SWORD2_DEBUG
|
||||
void PlotWalkGrid(void);
|
||||
#endif
|
||||
void plotWalkGrid(void);
|
||||
#endif
|
||||
};
|
||||
|
||||
extern Router router;
|
||||
|
||||
} // End of namespace Sword2
|
||||
|
||||
|
@ -241,7 +241,7 @@ uint32 SaveData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
|
||||
SaveFileManager *mgr = g_system->get_savefile_manager();
|
||||
|
||||
// construct filename
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo);
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo);
|
||||
|
||||
if (!(out = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), true))) {
|
||||
// error: couldn't open file
|
||||
@ -304,7 +304,7 @@ uint32 RestoreData(uint16 slotNo, uint8 *buffer, uint32 bufferSize) {
|
||||
uint32 itemsRead;
|
||||
|
||||
// construct filename
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo);
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo);
|
||||
|
||||
if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
|
||||
// error: couldn't open file
|
||||
@ -469,7 +469,7 @@ uint32 GetSaveDescription(uint16 slotNo, uint8 *description) {
|
||||
SaveFileManager *mgr = g_system->get_savefile_manager();
|
||||
|
||||
// construct filename
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo);
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo);
|
||||
|
||||
if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
|
||||
// error: couldn't open file
|
||||
@ -492,7 +492,7 @@ bool SaveExists(uint16 slotNo) {
|
||||
SaveFile *in;
|
||||
|
||||
// construct filename
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_game_name, slotNo);
|
||||
sprintf(saveFileName, "%s.%.3d", g_sword2->_gameName, slotNo);
|
||||
|
||||
if (!(in = mgr->open_savefile(saveFileName, g_sword2->getSavePath(), false))) {
|
||||
delete mgr;
|
||||
|
@ -272,7 +272,7 @@ uint32 Con_start(uint8 *input) {
|
||||
res_man.close(1);
|
||||
|
||||
// free all the route memory blocks from previous game
|
||||
FreeAllRouteMem();
|
||||
router.freeAllRouteMem();
|
||||
|
||||
// if there was speech text, kill the text block
|
||||
if (speech_text_bloc_no) {
|
||||
|
@ -104,7 +104,7 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
|
||||
g_sword2 = this;
|
||||
_features = detector->_game.features;
|
||||
_gameId = detector->_game.id;
|
||||
_game_name = strdup(detector->_gameFileName.c_str());
|
||||
_gameName = strdup(detector->_gameFileName.c_str());
|
||||
_bootParam = ConfMan.getInt("boot_param");
|
||||
_saveSlot = ConfMan.getInt("save_slot");
|
||||
_debugLevel = ConfMan.getInt("debuglevel");
|
||||
@ -122,6 +122,11 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
|
||||
g_sound = _sound = new Sound(_mixer);
|
||||
}
|
||||
|
||||
Sword2Engine::~Sword2Engine() {
|
||||
free(_gameName);
|
||||
delete _sound;
|
||||
}
|
||||
|
||||
void Sword2Engine::errorString(const char *buf1, char *buf2) {
|
||||
strcpy(buf2, buf1);
|
||||
}
|
||||
|
@ -60,8 +60,14 @@ extern uint8 unencoded_name[];
|
||||
// TODO move stuff into class
|
||||
|
||||
class Sword2Engine : public Engine {
|
||||
private:
|
||||
bool _quit;
|
||||
uint32 _bootParam;
|
||||
int32 _saveSlot;
|
||||
|
||||
public:
|
||||
Sword2Engine(GameDetector *detector, OSystem *syst);
|
||||
~Sword2Engine();
|
||||
void go(void);
|
||||
void parseEvents(void);
|
||||
void Start_game(void);
|
||||
@ -69,7 +75,7 @@ public:
|
||||
GameDetector *_detector;
|
||||
uint32 _features;
|
||||
byte _gameId;
|
||||
char *_game_name; // target name for saves
|
||||
char *_gameName; // target name for saves
|
||||
Sound *_sound;
|
||||
Common::RandomSource _rnd;
|
||||
|
||||
@ -77,12 +83,6 @@ public:
|
||||
uint32 _controlsFontId;
|
||||
uint32 _redFontId;
|
||||
|
||||
private:
|
||||
bool _quit;
|
||||
uint32 _bootParam;
|
||||
int32 _saveSlot;
|
||||
|
||||
public:
|
||||
void errorString(const char *buf_input, char *buf_output);
|
||||
void initialiseFontResourceFlags(void);
|
||||
void initialiseFontResourceFlags(uint8 language);
|
||||
|
@ -101,9 +101,9 @@ int32 FN_walk(int32 *params) {
|
||||
// set up mem for _walkData in route_slots[] & set mega's
|
||||
// 'route_slot_id' accordingly
|
||||
|
||||
AllocateRouteMem();
|
||||
router.allocateRouteMem();
|
||||
|
||||
route = (int8) RouteFinder(ob_mega, ob_walkdata, target_x, target_y, target_dir);
|
||||
route = (int8) router.routeFinder(ob_mega, ob_walkdata, target_x, target_y, target_dir);
|
||||
|
||||
// 0 = can't make route to target
|
||||
// 1 = created route
|
||||
@ -124,7 +124,7 @@ int32 FN_walk(int32 *params) {
|
||||
// (see FN_get_player_savedata() in save_rest.cpp
|
||||
} else {
|
||||
// free up the walkdata mem block
|
||||
FreeRouteMem();
|
||||
router.freeRouteMem();
|
||||
|
||||
// 1 means error, no walk created
|
||||
RESULT = 1;
|
||||
@ -143,7 +143,7 @@ int32 FN_walk(int32 *params) {
|
||||
// ok, thats it - back to script and change screen
|
||||
|
||||
ob_logic->looping = 0; // so script loop stops
|
||||
FreeRouteMem(); // free up the walkdata mem block
|
||||
router.freeRouteMem(); // free up the walkdata mem block
|
||||
|
||||
// must clear in-case on the new screen there's a walk
|
||||
// instruction (which would get cut short)
|
||||
@ -167,7 +167,7 @@ int32 FN_walk(int32 *params) {
|
||||
// get pointer to walkanim & current frame position
|
||||
|
||||
// lock the _walkData array
|
||||
walkAnim = LockRouteMem();
|
||||
walkAnim = router.lockRouteMem();
|
||||
walk_pc = ob_mega->walk_pc;
|
||||
|
||||
// if stopping the walk early, overwrite the next step with a
|
||||
@ -177,7 +177,7 @@ int32 FN_walk(int32 *params) {
|
||||
if (walkAnim[walk_pc].step == 0 && walkAnim[walk_pc + 1].step == 1) {
|
||||
// at the beginning of a step
|
||||
ob_walkdata = (Object_walkdata *) params[3];
|
||||
EarlySlowOut(ob_mega, ob_walkdata);
|
||||
router.earlySlowOut(ob_mega, ob_walkdata);
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ int32 FN_walk(int32 *params) {
|
||||
// '512' is end-marker
|
||||
if (walkAnim[walk_pc + 1].frame == 512) {
|
||||
ob_logic->looping = 0; // so script loop stops
|
||||
FreeRouteMem(); // free up the walkdata mem block
|
||||
router.freeRouteMem(); // free up the walkdata mem block
|
||||
|
||||
// finished walk
|
||||
ob_mega->currently_walking = 0;
|
||||
@ -237,7 +237,7 @@ int32 FN_walk(int32 *params) {
|
||||
ob_mega->walk_pc++;
|
||||
|
||||
// allow _walkData array to float about memory again
|
||||
FloatRouteMem();
|
||||
router.floatRouteMem();
|
||||
|
||||
// stop the script, but repeat this call next cycle
|
||||
return IR_REPEAT;
|
||||
@ -299,7 +299,7 @@ int32 FN_walk_to_anim(int32 *params) {
|
||||
pars[2] = params[2];
|
||||
pars[3] = params[3];
|
||||
|
||||
// walkdata (param 3) is needed for EarlySlowOut if player clicks
|
||||
// walkdata (param 3) is needed for earlySlowOut if player clicks
|
||||
// elsewhere during the walk
|
||||
|
||||
// call FN_walk() with target coords set to anim start position
|
||||
@ -739,7 +739,7 @@ int32 FN_add_walkgrid(int32 *params) {
|
||||
FN_add_to_kill_list(params);
|
||||
}
|
||||
|
||||
AddWalkGrid(params[0]);
|
||||
router.addWalkGrid(params[0]);
|
||||
|
||||
// Touch the grid, getting it into memory.
|
||||
res_man.open(params[0]);
|
||||
@ -755,7 +755,7 @@ int32 FN_add_walkgrid(int32 *params) {
|
||||
int32 FN_remove_walkgrid(int32 *params) {
|
||||
// params: 0 id of walkgrid resource
|
||||
|
||||
RemoveWalkGrid(params[0]);
|
||||
router.removeWalkGrid(params[0]);
|
||||
return IR_CONT;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user