Introduced new namespace, Sword1, removing the "Sword" and "Bs" prefixes in

the process, except for SwordEngine.

Some minor cleanups along the wa, e.g. stdafx.h already includes <stdio.h>,
<stdlib.h> and <math.h> so there shouldn't be any need to do it elsewhere.

svn-id: r12320
This commit is contained in:
Torbjörn Andersson 2004-01-11 15:47:41 +00:00
parent 563d95c576
commit cf0a73f913
35 changed files with 1410 additions and 1319 deletions

View file

@ -24,12 +24,14 @@
/*#include "objectman.h" /*#include "objectman.h"
class SwordLogic; namespace Sword1 {
class SwordCollision { class Logic;
class Collision {
public: public:
SwordCollision(ObjectMan *pObjMan, SwordLogic *pLogic); Collision(ObjectMan *pObjMan, Logic *pLogic);
~SwordCollision(void); ~Collision(void);
void checkCollisions(void); void checkCollisions(void);
void fnBumpOff(void); void fnBumpOff(void);
void fnBumpOn(void); void fnBumpOn(void);
@ -37,8 +39,11 @@ private:
int32 getIntersect(int32 x0, int32 y0, int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3); int32 getIntersect(int32 x0, int32 y0, int32 x1, int32 y1, int32 x2, int32 y2, int32 x3, int32 y3);
int noCol; int noCol;
ObjectMan *_objMan; ObjectMan *_objMan;
SwordLogic *_logic; // for CFN_preset_script Logic *_logic; // for CFN_preset_script
};*/ };
// maybe it's better to make this part of SwordRouter
} // End of namespace Sword1
*/
// maybe it's better to make this part of Router
#endif // BSCOLLISION_H #endif // BSCOLLISION_H

View file

@ -32,8 +32,9 @@
#include "common/util.h" #include "common/util.h"
#include "mouse.h" #include "mouse.h"
#include "music.h" #include "music.h"
#include "sound.h" #include "sound.h"
#include <math.h> // for sqrt()
namespace Sword1 {
#define SAVEFILE_WRITE true #define SAVEFILE_WRITE true
#define SAVEFILE_READ false #define SAVEFILE_READ false
@ -152,7 +153,7 @@ void ControlButton::setSelected(uint8 selected) {
draw(); draw();
} }
SwordControl::SwordControl(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, SwordMouse *pMouse, SwordSound *pSound, SwordMusic *pMusic, const char *savePath) { Control::Control(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic, const char *savePath) {
_resMan = pResMan; _resMan = pResMan;
_objMan = pObjMan; _objMan = pObjMan;
_system = system; _system = system;
@ -163,7 +164,7 @@ SwordControl::SwordControl(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system,
_lStrings = _languageStrings + MIN(SwordEngine::_systemVars.language, (uint8)BS1_SPANISH) * 20; _lStrings = _languageStrings + MIN(SwordEngine::_systemVars.language, (uint8)BS1_SPANISH) * 20;
} }
void SwordControl::askForCd(void) { void Control::askForCd(void) {
_screenBuf = (uint8*)malloc(640 * 480); _screenBuf = (uint8*)malloc(640 * 480);
uint32 fontId = SR_FONT; uint32 fontId = SR_FONT;
if (SwordEngine::_systemVars.language == BS1_CZECH) if (SwordEngine::_systemVars.language == BS1_CZECH)
@ -217,7 +218,7 @@ void SwordControl::askForCd(void) {
free(_screenBuf); free(_screenBuf);
} }
uint8 SwordControl::runPanel(void) { uint8 Control::runPanel(void) {
_mouseDown = false; _mouseDown = false;
_restoreBuf = NULL; _restoreBuf = NULL;
_keyPressed = _numButtons = 0; _keyPressed = _numButtons = 0;
@ -291,11 +292,11 @@ uint8 SwordControl::runPanel(void) {
_system->copy_rect(_screenBuf, 640, 0, 0, 640, 480); _system->copy_rect(_screenBuf, 640, 0, 0, 640, 480);
free(_screenBuf); free(_screenBuf);
_mouse->controlPanel(false); _mouse->controlPanel(false);
_music->startMusic(SwordLogic::_scriptVars[CURRENT_MUSIC], 1); _music->startMusic(Logic::_scriptVars[CURRENT_MUSIC], 1);
return retVal; return retVal;
} }
uint8 SwordControl::getClicks(uint8 mode, uint8 *retVal) { uint8 Control::getClicks(uint8 mode, uint8 *retVal) {
uint8 checkButtons = _numButtons; uint8 checkButtons = _numButtons;
if (mode == BUTTON_VOLUME_PANEL) { if (mode == BUTTON_VOLUME_PANEL) {
handleVolumeClicks(); handleVolumeClicks();
@ -332,7 +333,7 @@ uint8 SwordControl::getClicks(uint8 mode, uint8 *retVal) {
return 0; return 0;
} }
uint8 SwordControl::handleButtonClick(uint8 id, uint8 mode, uint8 *retVal) { uint8 Control::handleButtonClick(uint8 id, uint8 mode, uint8 *retVal) {
switch(mode) { switch(mode) {
case BUTTON_MAIN_PANEL: case BUTTON_MAIN_PANEL:
if (id == BUTTON_RESTART) { if (id == BUTTON_RESTART) {
@ -380,12 +381,12 @@ uint8 SwordControl::handleButtonClick(uint8 id, uint8 mode, uint8 *retVal) {
return 0; return 0;
} }
void SwordControl::deselectSaveslots(void) { void Control::deselectSaveslots(void) {
for (uint8 cnt = 0; cnt < 8; cnt++) for (uint8 cnt = 0; cnt < 8; cnt++)
_buttons[cnt]->setSelected(0); _buttons[cnt]->setSelected(0);
} }
void SwordControl::setupMainPanel(void) { void Control::setupMainPanel(void) {
uint32 panelId; uint32 panelId;
if (SwordEngine::_systemVars.deathScreenFlag == 1) if (SwordEngine::_systemVars.deathScreenFlag == 1)
@ -426,7 +427,7 @@ void SwordControl::setupMainPanel(void) {
} }
} }
void SwordControl::setupSaveRestorePanel(bool saving) { void Control::setupSaveRestorePanel(bool saving) {
FrameHeader *savePanel = _resMan->fetchFrame(_resMan->openFetchRes(SR_WINDOW), 0); FrameHeader *savePanel = _resMan->fetchFrame(_resMan->openFetchRes(SR_WINDOW), 0);
uint16 panelX = (640 - FROM_LE_16(savePanel->width)) / 2; uint16 panelX = (640 - FROM_LE_16(savePanel->width)) / 2;
uint16 panelY = (480 - FROM_LE_16(savePanel->height)) / 2; uint16 panelY = (480 - FROM_LE_16(savePanel->height)) / 2;
@ -446,7 +447,7 @@ void SwordControl::setupSaveRestorePanel(bool saving) {
showSavegameNames(); showSavegameNames();
} }
void SwordControl::setupVolumePanel(void) { void Control::setupVolumePanel(void) {
ControlButton *panel = new ControlButton( 0, 0, SR_VOLUME, 0, _resMan, _screenBuf, _system); ControlButton *panel = new ControlButton( 0, 0, SR_VOLUME, 0, _resMan, _screenBuf, _system);
panel->draw(); panel->draw();
delete panel; delete panel;
@ -467,7 +468,7 @@ void SwordControl::setupVolumePanel(void) {
renderVolumeBar(3, volL, volR); renderVolumeBar(3, volL, volR);
} }
void SwordControl::handleVolumeClicks(void) { void Control::handleVolumeClicks(void) {
if (_mouseDown) { if (_mouseDown) {
uint8 clickedId = 0; uint8 clickedId = 0;
for (uint8 cnt = 1; cnt < 4; cnt++) for (uint8 cnt = 1; cnt < 4; cnt++)
@ -511,7 +512,7 @@ void SwordControl::handleVolumeClicks(void) {
} }
} }
void SwordControl::changeVolume(uint8 id, uint8 action) { void Control::changeVolume(uint8 id, uint8 action) {
// ids: 1 = music, 2 = speech, 3 = sfx // ids: 1 = music, 2 = speech, 3 = sfx
uint8 volL = 0, volR = 0; uint8 volL = 0, volR = 0;
if (id == 1) if (id == 1)
@ -552,7 +553,7 @@ void SwordControl::changeVolume(uint8 id, uint8 action) {
renderVolumeBar(id, volL, volR); renderVolumeBar(id, volL, volR);
} }
bool SwordControl::getConfirm(const uint8 *title) { bool Control::getConfirm(const uint8 *title) {
ControlButton *panel = new ControlButton( 0, 0, SR_CONFIRM, 0, _resMan, _screenBuf, _system); ControlButton *panel = new ControlButton( 0, 0, SR_CONFIRM, 0, _resMan, _screenBuf, _system);
panel->draw(); panel->draw();
delete panel; delete panel;
@ -592,7 +593,7 @@ bool SwordControl::getConfirm(const uint8 *title) {
return retVal == 1; return retVal == 1;
} }
bool SwordControl::keyAccepted(uint8 key) { bool Control::keyAccepted(uint8 key) {
// this routine needs changes for Czech keys... No idea how to do that, though. // this routine needs changes for Czech keys... No idea how to do that, though.
static const char allowedSpecials[] = "éèáàúùäöüÄÖÜß,.:-()?! \"\'"; static const char allowedSpecials[] = "éèáàúùäöüÄÖÜß,.:-()?! \"\'";
if (((key >= 'A') && (key <= 'Z')) || if (((key >= 'A') && (key <= 'Z')) ||
@ -604,7 +605,7 @@ bool SwordControl::keyAccepted(uint8 key) {
return false; return false;
} }
void SwordControl::handleSaveKey(uint8 key) { void Control::handleSaveKey(uint8 key) {
if (_selectedSavegame < 255) { if (_selectedSavegame < 255) {
uint8 len = strlen((char*)_saveNames[_selectedSavegame]); uint8 len = strlen((char*)_saveNames[_selectedSavegame]);
if ((key == 8) && len) // backspace if ((key == 8) && len) // backspace
@ -617,7 +618,7 @@ void SwordControl::handleSaveKey(uint8 key) {
} }
} }
bool SwordControl::saveToFile(void) { bool Control::saveToFile(void) {
if ((_selectedSavegame == 255) || !strlen((char*)_saveNames[_selectedSavegame])) if ((_selectedSavegame == 255) || !strlen((char*)_saveNames[_selectedSavegame]))
return false; // no saveslot selected or no name entered return false; // no saveslot selected or no name entered
saveGameToFile(_selectedSavegame); saveGameToFile(_selectedSavegame);
@ -625,14 +626,14 @@ bool SwordControl::saveToFile(void) {
return true; return true;
} }
bool SwordControl::restoreFromFile(void) { bool Control::restoreFromFile(void) {
if (_selectedSavegame < 255) { if (_selectedSavegame < 255) {
return restoreGameFromFile(_selectedSavegame); return restoreGameFromFile(_selectedSavegame);
} else } else
return false; return false;
} }
void SwordControl::readSavegameDescriptions(void) { void Control::readSavegameDescriptions(void) {
SaveFileManager *mgr = _system->get_savefile_manager(); SaveFileManager *mgr = _system->get_savefile_manager();
SaveFile *inf; SaveFile *inf;
inf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_READ); inf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_READ);
@ -663,7 +664,7 @@ void SwordControl::readSavegameDescriptions(void) {
delete mgr; delete mgr;
} }
void SwordControl::writeSavegameDescriptions(void) { void Control::writeSavegameDescriptions(void) {
SaveFileManager *mgr = _system->get_savefile_manager(); SaveFileManager *mgr = _system->get_savefile_manager();
SaveFile *outf; SaveFile *outf;
outf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_WRITE); outf = mgr->open_savefile("SAVEGAME.INF", _savePath, SAVEFILE_WRITE);
@ -682,7 +683,7 @@ void SwordControl::writeSavegameDescriptions(void) {
delete mgr; delete mgr;
} }
bool SwordControl::savegamesExist(void) { bool Control::savegamesExist(void) {
bool retVal = false; bool retVal = false;
SaveFileManager *mgr = _system->get_savefile_manager(); SaveFileManager *mgr = _system->get_savefile_manager();
SaveFile *inf; SaveFile *inf;
@ -694,7 +695,7 @@ bool SwordControl::savegamesExist(void) {
return retVal; return retVal;
} }
void SwordControl::showSavegameNames(void) { void Control::showSavegameNames(void) {
for (uint8 cnt = 0; cnt < 8; cnt++) { for (uint8 cnt = 0; cnt < 8; cnt++) {
_buttons[cnt]->draw(); _buttons[cnt]->draw();
uint8 textMode = TEXT_LEFT_ALIGN; uint8 textMode = TEXT_LEFT_ALIGN;
@ -707,7 +708,7 @@ void SwordControl::showSavegameNames(void) {
} }
} }
void SwordControl::saveNameSelect(uint8 id, bool saving) { void Control::saveNameSelect(uint8 id, bool saving) {
deselectSaveslots(); deselectSaveslots();
_buttons[id - BUTTON_SAVE_SELECT1]->setSelected(1); _buttons[id - BUTTON_SAVE_SELECT1]->setSelected(1);
uint8 num = (id - BUTTON_SAVE_SELECT1) + _saveScrollPos; uint8 num = (id - BUTTON_SAVE_SELECT1) + _saveScrollPos;
@ -729,7 +730,7 @@ void SwordControl::saveNameSelect(uint8 id, bool saving) {
showSavegameNames(); showSavegameNames();
} }
void SwordControl::saveNameScroll(uint8 scroll, bool saving) { void Control::saveNameScroll(uint8 scroll, bool saving) {
uint16 maxScroll; uint16 maxScroll;
if (saving) if (saving)
maxScroll = 64; maxScroll = 64;
@ -757,7 +758,7 @@ void SwordControl::saveNameScroll(uint8 scroll, bool saving) {
showSavegameNames(); showSavegameNames();
} }
void SwordControl::createButtons(const ButtonInfo *buttons, uint8 num) { void Control::createButtons(const ButtonInfo *buttons, uint8 num) {
for (uint8 cnt = 0; cnt < num; cnt++) { for (uint8 cnt = 0; cnt < num; cnt++) {
_buttons[cnt] = new ControlButton(buttons[cnt].x, buttons[cnt].y, buttons[cnt].resId, buttons[cnt].id, _resMan, _screenBuf, _system); _buttons[cnt] = new ControlButton(buttons[cnt].x, buttons[cnt].y, buttons[cnt].resId, buttons[cnt].id, _resMan, _screenBuf, _system);
_buttons[cnt]->draw(); _buttons[cnt]->draw();
@ -765,13 +766,13 @@ void SwordControl::createButtons(const ButtonInfo *buttons, uint8 num) {
_numButtons = num; _numButtons = num;
} }
void SwordControl::destroyButtons(void) { void Control::destroyButtons(void) {
for (uint8 cnt = 0; cnt < _numButtons; cnt++) for (uint8 cnt = 0; cnt < _numButtons; cnt++)
delete _buttons[cnt]; delete _buttons[cnt];
_numButtons = 0; _numButtons = 0;
} }
uint16 SwordControl::getTextWidth(const uint8 *str) { uint16 Control::getTextWidth(const uint8 *str) {
uint16 width = 0; uint16 width = 0;
while (*str) { while (*str) {
width += FROM_LE_16(_resMan->fetchFrame(_font, *str - 32)->width) - 3; width += FROM_LE_16(_resMan->fetchFrame(_font, *str - 32)->width) - 3;
@ -780,7 +781,7 @@ uint16 SwordControl::getTextWidth(const uint8 *str) {
return width; return width;
} }
void SwordControl::renderText(const uint8 *str, uint16 x, uint16 y, uint8 mode) { void Control::renderText(const uint8 *str, uint16 x, uint16 y, uint8 mode) {
uint8 *font = _font; uint8 *font = _font;
if (mode & TEXT_RED_FONT) if (mode & TEXT_RED_FONT)
font = _redFont; font = _redFont;
@ -811,7 +812,7 @@ void SwordControl::renderText(const uint8 *str, uint16 x, uint16 y, uint8 mode)
_system->copy_rect(_screenBuf + y * SCREEN_WIDTH + x, SCREEN_WIDTH, x, y, (destX - x) + 3, 28); _system->copy_rect(_screenBuf + y * SCREEN_WIDTH + x, SCREEN_WIDTH, x, y, (destX - x) + 3, 28);
} }
void SwordControl::renderVolumeBar(uint8 id, uint8 volL, uint8 volR) { void Control::renderVolumeBar(uint8 id, uint8 volL, uint8 volR) {
uint16 destX = _volumeButtons[id].x + 20; uint16 destX = _volumeButtons[id].x + 20;
uint16 destY = _volumeButtons[id].y + 116; uint16 destY = _volumeButtons[id].y + 116;
@ -831,7 +832,7 @@ void SwordControl::renderVolumeBar(uint8 id, uint8 volL, uint8 volR) {
} }
} }
void SwordControl::saveGameToFile(uint8 slot) { void Control::saveGameToFile(uint8 slot) {
char fName[15]; char fName[15];
uint16 cnt; uint16 cnt;
sprintf(fName, "SAVEGAME.%03d", slot); sprintf(fName, "SAVEGAME.%03d", slot);
@ -846,17 +847,17 @@ void SwordControl::saveGameToFile(uint8 slot) {
for (cnt = 0; cnt < TOTAL_SECTIONS; cnt++) for (cnt = 0; cnt < TOTAL_SECTIONS; cnt++)
outf->writeUint16LE(liveBuf[cnt]); outf->writeUint16LE(liveBuf[cnt]);
BsObject *cpt = _objMan->fetchObject(PLAYER); Object *cpt = _objMan->fetchObject(PLAYER);
SwordLogic::_scriptVars[CHANGE_DIR] = cpt->o_dir; Logic::_scriptVars[CHANGE_DIR] = cpt->o_dir;
SwordLogic::_scriptVars[CHANGE_X] = cpt->o_xcoord; Logic::_scriptVars[CHANGE_X] = cpt->o_xcoord;
SwordLogic::_scriptVars[CHANGE_Y] = cpt->o_ycoord; Logic::_scriptVars[CHANGE_Y] = cpt->o_ycoord;
SwordLogic::_scriptVars[CHANGE_STANCE] = STAND; Logic::_scriptVars[CHANGE_STANCE] = STAND;
SwordLogic::_scriptVars[CHANGE_PLACE] = cpt->o_place; Logic::_scriptVars[CHANGE_PLACE] = cpt->o_place;
for (cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++) for (cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++)
outf->writeUint32LE(SwordLogic::_scriptVars[cnt]); outf->writeUint32LE(Logic::_scriptVars[cnt]);
uint32 playerSize = (sizeof(BsObject) - 12000) / 4; uint32 playerSize = (sizeof(Object) - 12000) / 4;
uint32 *playerRaw = (uint32*)cpt; uint32 *playerRaw = (uint32*)cpt;
for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++) for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++)
outf->writeUint32LE(playerRaw[cnt2]); outf->writeUint32LE(playerRaw[cnt2]);
@ -864,7 +865,7 @@ void SwordControl::saveGameToFile(uint8 slot) {
delete mgr; delete mgr;
} }
bool SwordControl::restoreGameFromFile(uint8 slot) { bool Control::restoreGameFromFile(uint8 slot) {
char fName[15]; char fName[15];
uint16 cnt; uint16 cnt;
sprintf(fName, "SAVEGAME.%03d", slot); sprintf(fName, "SAVEGAME.%03d", slot);
@ -880,7 +881,7 @@ bool SwordControl::restoreGameFromFile(uint8 slot) {
_restoreBuf = (uint8*)malloc( _restoreBuf = (uint8*)malloc(
TOTAL_SECTIONS * 2 + TOTAL_SECTIONS * 2 +
NUM_SCRIPT_VARS * 4 + NUM_SCRIPT_VARS * 4 +
(sizeof(BsObject) - 12000)); (sizeof(Object) - 12000));
uint16 *liveBuf = (uint16*)_restoreBuf; uint16 *liveBuf = (uint16*)_restoreBuf;
uint32 *scriptBuf = (uint32*)(_restoreBuf + 2 * TOTAL_SECTIONS); uint32 *scriptBuf = (uint32*)(_restoreBuf + 2 * TOTAL_SECTIONS);
@ -892,7 +893,7 @@ bool SwordControl::restoreGameFromFile(uint8 slot) {
for (cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++) for (cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++)
scriptBuf[cnt] = inf->readUint32LE(); scriptBuf[cnt] = inf->readUint32LE();
uint32 playerSize = (sizeof(BsObject) - 12000) / 4; uint32 playerSize = (sizeof(Object) - 12000) / 4;
for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++) for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++)
playerBuf[cnt2] = inf->readUint32LE(); playerBuf[cnt2] = inf->readUint32LE();
@ -901,32 +902,32 @@ bool SwordControl::restoreGameFromFile(uint8 slot) {
return true; return true;
} }
void SwordControl::doRestore(void) { void Control::doRestore(void) {
uint8 *bufPos = _restoreBuf; uint8 *bufPos = _restoreBuf;
_objMan->loadLiveList((uint16*)bufPos); _objMan->loadLiveList((uint16*)bufPos);
bufPos += TOTAL_SECTIONS * 2; bufPos += TOTAL_SECTIONS * 2;
for (uint16 cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++) { for (uint16 cnt = 0; cnt < NUM_SCRIPT_VARS; cnt++) {
SwordLogic::_scriptVars[cnt] = *(uint32*)bufPos; Logic::_scriptVars[cnt] = *(uint32*)bufPos;
bufPos += 4; bufPos += 4;
} }
uint32 playerSize = (sizeof(BsObject) - 12000) / 4; uint32 playerSize = (sizeof(Object) - 12000) / 4;
uint32 *playerRaw = (uint32*)_objMan->fetchObject(PLAYER); uint32 *playerRaw = (uint32*)_objMan->fetchObject(PLAYER);
BsObject *cpt = _objMan->fetchObject(PLAYER); Object *cpt = _objMan->fetchObject(PLAYER);
for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++) { for (uint32 cnt2 = 0; cnt2 < playerSize; cnt2++) {
*playerRaw = *(uint32*)bufPos; *playerRaw = *(uint32*)bufPos;
playerRaw++; playerRaw++;
bufPos += 4; bufPos += 4;
} }
free(_restoreBuf); free(_restoreBuf);
SwordLogic::_scriptVars[CHANGE_DIR] = cpt->o_dir; Logic::_scriptVars[CHANGE_DIR] = cpt->o_dir;
SwordLogic::_scriptVars[CHANGE_X] = cpt->o_xcoord; Logic::_scriptVars[CHANGE_X] = cpt->o_xcoord;
SwordLogic::_scriptVars[CHANGE_Y] = cpt->o_ycoord; Logic::_scriptVars[CHANGE_Y] = cpt->o_ycoord;
SwordLogic::_scriptVars[CHANGE_STANCE] = STAND; Logic::_scriptVars[CHANGE_STANCE] = STAND;
SwordLogic::_scriptVars[CHANGE_PLACE] = cpt->o_place; Logic::_scriptVars[CHANGE_PLACE] = cpt->o_place;
SwordEngine::_systemVars.justRestoredGame = 1; SwordEngine::_systemVars.justRestoredGame = 1;
} }
void SwordControl::delay(uint32 msecs) { void Control::delay(uint32 msecs) {
OSystem::Event event; OSystem::Event event;
uint32 endTime = _system->get_msecs() + msecs; uint32 endTime = _system->get_msecs() + msecs;
@ -971,13 +972,13 @@ void SwordControl::delay(uint32 msecs) {
} while (_system->get_msecs() < endTime); } while (_system->get_msecs() < endTime);
} }
const ButtonInfo SwordControl::_deathButtons[3] = { const ButtonInfo Control::_deathButtons[3] = {
{250, 224 + 40, SR_BUTTON, BUTTON_RESTORE_PANEL }, {250, 224 + 40, SR_BUTTON, BUTTON_RESTORE_PANEL },
{250, 260 + 40, SR_BUTTON, BUTTON_RESTART }, {250, 260 + 40, SR_BUTTON, BUTTON_RESTART },
{250, 296 + 40, SR_BUTTON, BUTTON_QUIT } {250, 296 + 40, SR_BUTTON, BUTTON_QUIT }
}; };
const ButtonInfo SwordControl::_panelButtons[7] = { const ButtonInfo Control::_panelButtons[7] = {
{145, 188 + 40, SR_BUTTON, BUTTON_SAVE_PANEL }, {145, 188 + 40, SR_BUTTON, BUTTON_SAVE_PANEL },
{145, 224 + 40, SR_BUTTON, BUTTON_RESTORE_PANEL }, {145, 224 + 40, SR_BUTTON, BUTTON_RESTORE_PANEL },
{145, 260 + 40, SR_BUTTON, BUTTON_RESTART }, {145, 260 + 40, SR_BUTTON, BUTTON_RESTART },
@ -987,7 +988,7 @@ const ButtonInfo SwordControl::_panelButtons[7] = {
{475, 332 + 40, SR_BUTTON, BUTTON_DONE } {475, 332 + 40, SR_BUTTON, BUTTON_DONE }
}; };
const ButtonInfo SwordControl::_saveButtons[16] = { const ButtonInfo Control::_saveButtons[16] = {
{114, 32 + 40, SR_SLAB1, BUTTON_SAVE_SELECT1 }, {114, 32 + 40, SR_SLAB1, BUTTON_SAVE_SELECT1 },
{114, 68 + 40, SR_SLAB2, BUTTON_SAVE_SELECT2 }, {114, 68 + 40, SR_SLAB2, BUTTON_SAVE_SELECT2 },
{114, 104 + 40, SR_SLAB3, BUTTON_SAVE_SELECT3 }, {114, 104 + 40, SR_SLAB3, BUTTON_SAVE_SELECT3 },
@ -1006,14 +1007,14 @@ const ButtonInfo SwordControl::_saveButtons[16] = {
{462, 338 + 40, SR_BUTTON, BUTTON_SAVE_CANCEL} {462, 338 + 40, SR_BUTTON, BUTTON_SAVE_CANCEL}
}; };
const ButtonInfo SwordControl::_volumeButtons[4] = { const ButtonInfo Control::_volumeButtons[4] = {
{ 478, 338 + 40, SR_BUTTON, BUTTON_MAIN_PANEL }, { 478, 338 + 40, SR_BUTTON, BUTTON_MAIN_PANEL },
{ 138, 135, SR_VKNOB, 0 }, { 138, 135, SR_VKNOB, 0 },
{ 273, 135, SR_VKNOB, 0 }, { 273, 135, SR_VKNOB, 0 },
{ 404, 135, SR_VKNOB, 0 }, { 404, 135, SR_VKNOB, 0 },
}; };
const uint8 SwordControl::_languageStrings[8 * 20][43] = { const uint8 Control::_languageStrings[8 * 20][43] = {
// BS1_ENGLISH: // BS1_ENGLISH:
"PAUSED", "PAUSED",
"PLEASE INSERT CD-", "PLEASE INSERT CD-",
@ -1162,3 +1163,5 @@ const uint8 SwordControl::_languageStrings[8 * 20][43] = {
"Fim", "Fim",
"UNIDADE CHEIA!", "UNIDADE CHEIA!",
}; };
} // End of namespace Sword1

View file

@ -25,12 +25,15 @@
#include "scummsys.h" #include "scummsys.h"
#include "sworddefs.h" #include "sworddefs.h"
class OSystem;
namespace Sword1 {
class ObjectMan; class ObjectMan;
class ResMan; class ResMan;
class OSystem; class Mouse;
class SwordMouse; class Music;
class SwordMusic; class Sound;
class SwordSound;
#define MAX_BUTTONS 16 #define MAX_BUTTONS 16
@ -62,10 +65,10 @@ struct ButtonInfo {
uint32 resId, id; uint32 resId, id;
}; };
class SwordControl { class Control {
public: public:
SwordControl(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, SwordMouse *pMouse, SwordSound *pSound, SwordMusic *pMusic, const char *savePath); Control(ResMan *pResMan, ObjectMan *pObjMan, OSystem *system, Mouse *pMouse, Sound *pSound, Music *pMusic, const char *savePath);
~SwordControl(void); ~Control(void);
uint8 runPanel(void); uint8 runPanel(void);
void doRestore(void); void doRestore(void);
void askForCd(void); void askForCd(void);
@ -115,9 +118,9 @@ private:
ObjectMan *_objMan; ObjectMan *_objMan;
ResMan *_resMan; ResMan *_resMan;
OSystem *_system; OSystem *_system;
SwordMouse *_mouse; Mouse *_mouse;
SwordMusic *_music; Music *_music;
SwordSound *_sound; Sound *_sound;
char _savePath[256]; char _savePath[256];
uint8 *_font, *_redFont; uint8 *_font, *_redFont;
uint8 *_screenBuf; uint8 *_screenBuf;
@ -127,6 +130,7 @@ private:
bool _mouseDown; bool _mouseDown;
}; };
} // End of namespace Sword1
#endif //BSCONTROL_H #endif //BSCONTROL_H

View file

@ -1,16 +1,39 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2003-2004 The ScummVM project
*
* 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$
*
*/
#include "stdafx.h" #include "stdafx.h"
#include "debug.h" #include "debug.h"
#include "common/util.h" #include "common/util.h"
void SwordDebug::interpretScript(uint32 id, uint32 level, uint32 script, uint32 pc) { namespace Sword1 {
void Debug::interpretScript(uint32 id, uint32 level, uint32 script, uint32 pc) {
debug(8, "\nInterpreting %d@%d: script %X from %X", id, level, script, pc); debug(8, "\nInterpreting %d@%d: script %X from %X", id, level, script, pc);
} }
void SwordDebug::callMCode(uint32 mcodeNum, uint32 paramCount, int32 a, int32 b, int32 c, int32 d, int32 e, int32 f) { void Debug::callMCode(uint32 mcodeNum, uint32 paramCount, int32 a, int32 b, int32 c, int32 d, int32 e, int32 f) {
debug(9, "mcode: %s(%d, %d, %d, %d, %d, %d) [%d]", _mCodeNames[mcodeNum], a, b, c, d, e, f, paramCount); debug(9, "mcode: %s(%d, %d, %d, %d, %d, %d) [%d]", _mCodeNames[mcodeNum], a, b, c, d, e, f, paramCount);
} }
const char SwordDebug::_mCodeNames[100][35] = { const char Debug::_mCodeNames[100][35] = {
"fnBackground", "fnBackground",
"fnForeground", "fnForeground",
"fnSort", "fnSort",
@ -112,3 +135,5 @@ const char SwordDebug::_mCodeNames[100][35] = {
"fnPurple", "fnPurple",
"fnBlack" "fnBlack"
}; };
} // End of namespace Sword1

View file

@ -24,7 +24,9 @@
#include "scummsys.h" #include "scummsys.h"
class SwordDebug { namespace Sword1 {
class Debug {
public: public:
static void interpretScript(uint32 id, uint32 level, uint32 script, uint32 pc); static void interpretScript(uint32 id, uint32 level, uint32 script, uint32 pc);
static void callMCode(uint32 mcodeNum, uint32 paramCount, int32 a, int32 b, int32 c, int32 d, int32 e, int32 f); static void callMCode(uint32 mcodeNum, uint32 paramCount, int32 a, int32 b, int32 c, int32 d, int32 e, int32 f);
@ -33,5 +35,7 @@ private:
static const char _mCodeNames[100][35]; static const char _mCodeNames[100][35];
}; };
} // End of namespace Sword1
#endif // BSDEBUG_H #endif // BSDEBUG_H

View file

@ -24,6 +24,8 @@
#include "sworddefs.h" #include "sworddefs.h"
#include "common/util.h" #include "common/util.h"
namespace Sword1 {
EventManager::EventManager(void) { EventManager::EventManager(void) {
for (uint8 cnt = 0; cnt < TOTAL_EVENT_SLOTS; cnt++) for (uint8 cnt = 0; cnt < TOTAL_EVENT_SLOTS; cnt++)
_eventPendingList[cnt].delay = _eventPendingList[cnt].eventNumber = 0; _eventPendingList[cnt].delay = _eventPendingList[cnt].eventNumber = 0;
@ -35,7 +37,7 @@ void EventManager::serviceGlobalEventList(void) {
_eventPendingList[slot].delay--; _eventPendingList[slot].delay--;
} }
void EventManager::checkForEvent(BsObject *compact) { void EventManager::checkForEvent(Object *compact) {
for (uint8 objCnt = 0; objCnt < O_TOTAL_EVENTS; objCnt++) { for (uint8 objCnt = 0; objCnt < O_TOTAL_EVENTS; objCnt++) {
if (compact->o_event_list[objCnt].o_event) if (compact->o_event_list[objCnt].o_event)
for (uint8 globCnt = 0; globCnt < TOTAL_EVENT_SLOTS; globCnt++) { for (uint8 globCnt = 0; globCnt < TOTAL_EVENT_SLOTS; globCnt++) {
@ -61,7 +63,7 @@ bool EventManager::eventValid(int32 event) {
return false; return false;
} }
int EventManager::fnCheckForEvent(BsObject *cpt, int32 id, int32 pause) { int EventManager::fnCheckForEvent(Object *cpt, int32 id, int32 pause) {
if (pause) { if (pause) {
cpt->o_pause = pause; cpt->o_pause = pause;
cpt->o_logic = LOGIC_pause_for_event; cpt->o_logic = LOGIC_pause_for_event;
@ -87,7 +89,7 @@ int EventManager::fnCheckForEvent(BsObject *cpt, int32 id, int32 pause) {
return SCRIPT_CONT; return SCRIPT_CONT;
} }
void EventManager::fnIssueEvent(BsObject *compact, int32 id, int32 event, int32 delay) { void EventManager::fnIssueEvent(Object *compact, int32 id, int32 event, int32 delay) {
uint8 evSlot = 0; uint8 evSlot = 0;
while (_eventPendingList[evSlot].delay) while (_eventPendingList[evSlot].delay)
evSlot++; evSlot++;
@ -97,3 +99,4 @@ void EventManager::fnIssueEvent(BsObject *compact, int32 id, int32 event, int32
_eventPendingList[evSlot].eventNumber = event; _eventPendingList[evSlot].eventNumber = event;
} }
} // End of namespace Sword1

View file

@ -24,6 +24,8 @@
#include "object.h" #include "object.h"
namespace Sword1 {
#define TOTAL_EVENT_SLOTS 20 #define TOTAL_EVENT_SLOTS 20
struct GlobalEvent { struct GlobalEvent {
@ -35,12 +37,14 @@ class EventManager {
public: public:
EventManager(void); EventManager(void);
void serviceGlobalEventList(void); void serviceGlobalEventList(void);
void checkForEvent(BsObject *compact); void checkForEvent(Object *compact);
int fnCheckForEvent(BsObject *cpt, int32 id, int32 pause); int fnCheckForEvent(Object *cpt, int32 id, int32 pause);
void fnIssueEvent(BsObject *compact, int32 id, int32 event, int32 delay); void fnIssueEvent(Object *compact, int32 id, int32 event, int32 delay);
bool eventValid(int32 event); bool eventValid(int32 event);
private: private:
GlobalEvent _eventPendingList[TOTAL_EVENT_SLOTS]; GlobalEvent _eventPendingList[TOTAL_EVENT_SLOTS];
}; };
} // End of namespace Sword1
#endif // BSEVENTMAN_H #endif // BSEVENTMAN_H

File diff suppressed because it is too large Load diff

View file

@ -27,175 +27,179 @@
#include "objectman.h" #include "objectman.h"
#include "common/util.h" #include "common/util.h"
namespace Sword1 {
#define NON_ZERO_SCRIPT_VARS 95 #define NON_ZERO_SCRIPT_VARS 95
#define NUM_SCRIPT_VARS 1179 #define NUM_SCRIPT_VARS 1179
class SwordText; class Text;
class SwordSound; class Sound;
class EventManager; class EventManager;
class SwordMenu; class Menu;
class SwordRouter; class Router;
class SwordScreen; class Screen;
class SwordMouse; class Mouse;
class SwordMusic; class Music;
class SwordLogic; class Logic;
typedef int (SwordLogic::*BSMcodeTable)(BsObject *, int32, int32, int32, int32, int32, int32, int32); typedef int (Logic::*BSMcodeTable)(Object *, int32, int32, int32, int32, int32, int32, int32);
class SwordLogic { class Logic {
public: public:
SwordLogic(ObjectMan *pObjMan, ResMan *resMan, SwordScreen *pScreen, SwordMouse *pMouse, SwordSound *pSound, SwordMusic *pMusic, SwordMenu *pMenu); Logic(ObjectMan *pObjMan, ResMan *resMan, Screen *pScreen, Mouse *pMouse, Sound *pSound, Music *pMusic, Menu *pMenu);
~SwordLogic(void); ~Logic(void);
void initialize(void); void initialize(void);
void newScreen(uint32 screen); void newScreen(uint32 screen);
void engine(void); void engine(void);
void updateScreenParams(void); void updateScreenParams(void);
void runMouseScript(BsObject *cpt, int32 scriptId); void runMouseScript(Object *cpt, int32 scriptId);
static uint32 _scriptVars[NUM_SCRIPT_VARS]; static uint32 _scriptVars[NUM_SCRIPT_VARS];
// public for startPositions() // public for startPositions()
int fnAddObject (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnAddObject (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnEnterSection (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnEnterSection (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnPlaySequence (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnPlaySequence (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnMegaSet (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnMegaSet (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnNoSprite (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnNoSprite (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
// public for mouse (menu looking) // public for mouse (menu looking)
int cfnPresetScript (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int cfnPresetScript (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
private: private:
ObjectMan *_objMan; ObjectMan *_objMan;
ResMan *_resMan; ResMan *_resMan;
SwordScreen *_screen; Screen *_screen;
SwordSound *_sound; Sound *_sound;
SwordMouse *_mouse; Mouse *_mouse;
SwordRouter *_router; Router *_router;
SwordText *_textMan; Text *_textMan;
EventManager *_eventMan; EventManager *_eventMan;
SwordMenu *_menu; Menu *_menu;
SwordMusic *_music; Music *_music;
uint32 _newScript; // <= ugly, but I can't avoid it. uint32 _newScript; // <= ugly, but I can't avoid it.
bool _speechRunning, _speechFinished, _textRunning; bool _speechRunning, _speechFinished, _textRunning;
uint8 _speechClickDelay; uint8 _speechClickDelay;
Common::RandomSource _rnd; Common::RandomSource _rnd;
int scriptManager(BsObject *compact, uint32 id); int scriptManager(Object *compact, uint32 id);
void processLogic(BsObject *compact, uint32 id); void processLogic(Object *compact, uint32 id);
int interpretScript(BsObject *compact, int id, Header *scriptModule, int scriptBase, int scriptNum); int interpretScript(Object *compact, int id, Header *scriptModule, int scriptBase, int scriptNum);
int logicWaitTalk(BsObject *compact); int logicWaitTalk(Object *compact);
int logicStartTalk(BsObject *compact); int logicStartTalk(Object *compact);
int logicArAnimate(BsObject *compact, uint32 id); int logicArAnimate(Object *compact, uint32 id);
int speechDriver(BsObject *compact); int speechDriver(Object *compact);
int fullAnimDriver(BsObject *compact); int fullAnimDriver(Object *compact);
int animDriver(BsObject *compact); int animDriver(Object *compact);
static BSMcodeTable _mcodeTable[100]; static BSMcodeTable _mcodeTable[100];
uint16 inRange(uint16 a, uint16 b, uint16 c); uint16 inRange(uint16 a, uint16 b, uint16 c);
//- mcodeTable: //- mcodeTable:
int fnBackground (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnBackground (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnForeground (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnForeground (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSort (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSort (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnAnim (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnAnim (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetFrame (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetFrame (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnFullAnim (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnFullAnim (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnFullSetFrame (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnFullSetFrame (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnFadeDown (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnFadeDown (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnFadeUp (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnFadeUp (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnCheckFade (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnCheckFade (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetSpritePalette(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetSpritePalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetWholePalette(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetWholePalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetFadeTargetPalette(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetFadeTargetPalette(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetPaletteToFade(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetPaletteToFade(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetPaletteToCut(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetPaletteToCut(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnIdle (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnIdle (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnPause (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnPause (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnPauseSeconds (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnPauseSeconds (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnQuit (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnQuit (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnKillId (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnKillId (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSuicide (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSuicide (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnNewScript (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnNewScript (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSubScript (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSubScript (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnRestartScript (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnRestartScript (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetBookmark (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetBookmark (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnGotoBookmark (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnGotoBookmark (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSendSync (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSendSync (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnWaitSync (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnWaitSync (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int cfnClickInteract(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int cfnClickInteract(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int cfnSetScript (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int cfnSetScript (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnInteract (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnInteract (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnIssueEvent (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnIssueEvent (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnCheckForEvent (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnCheckForEvent (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnWipeHands (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnWipeHands (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnISpeak (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnISpeak (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnTheyDo (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnTheyDo (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnTheyDoWeWait (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnTheyDoWeWait (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnWeWait (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnWeWait (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnChangeSpeechText(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnChangeSpeechText(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnTalkError (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnTalkError (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnStartTalk (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnStartTalk (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnCheckForTextLine(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnCheckForTextLine(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnAddTalkWaitStatusBit(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnAddTalkWaitStatusBit(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnRemoveTalkWaitStatusBit(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnRemoveTalkWaitStatusBit(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnNoHuman (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnNoHuman (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnAddHuman (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnAddHuman (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnBlankMouse (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnBlankMouse (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnNormalMouse (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnNormalMouse (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnLockMouse (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnLockMouse (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnUnlockMouse (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnUnlockMouse (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetMousePointer(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetMousePointer(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetMouseLuggage(BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetMouseLuggage(Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnMouseOn (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnMouseOn (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnMouseOff (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnMouseOff (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnChooser (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnChooser (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnEndChooser (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnEndChooser (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnStartMenu (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnStartMenu (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnEndMenu (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnEndMenu (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int cfnReleaseMenu (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int cfnReleaseMenu (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnAddSubject (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnAddSubject (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnRemoveObject (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnRemoveObject (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnLeaveSection (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnLeaveSection (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnChangeFloor (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnChangeFloor (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnWalk (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnWalk (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnTurn (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnTurn (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnStand (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnStand (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnStandAt (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnStandAt (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnFace (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnFace (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnFaceXy (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnFaceXy (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnIsFacing (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnIsFacing (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnGetTo (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnGetTo (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnGetToError (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnGetToError (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnGetPos (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnGetPos (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnGetGamepadXy (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnGetGamepadXy (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnPlayFx (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnPlayFx (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnStopFx (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnStopFx (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnPlayMusic (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnPlayMusic (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnStopMusic (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnStopMusic (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnInnerSpace (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnInnerSpace (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnRandom (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnRandom (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetScreen (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetScreen (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnPreload (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnPreload (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnCheckCD (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnCheckCD (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnRestartGame (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnRestartGame (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnQuitGame (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnQuitGame (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnDeathScreen (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnDeathScreen (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnSetParallax (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnSetParallax (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnTdebug (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnTdebug (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnRedFlash (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnRedFlash (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnBlueFlash (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnBlueFlash (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnYellow (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnYellow (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnGreen (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnGreen (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnPurple (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnPurple (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
int fnBlack (BsObject *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x); int fnBlack (Object *cpt, int32 id, int32 c, int32 d, int32 e, int32 f, int32 z, int32 x);
static const uint32 _scriptVarInit[NON_ZERO_SCRIPT_VARS][2]; static const uint32 _scriptVarInit[NON_ZERO_SCRIPT_VARS][2];
}; };
} // End of namespace Sword1
#endif //BSLOGIC_H #endif //BSLOGIC_H

View file

@ -23,6 +23,8 @@
#include "memman.h" #include "memman.h"
#include "common/util.h" #include "common/util.h"
namespace Sword1 {
MemMan::MemMan(void) { MemMan::MemMan(void) {
_alloced = 0; _alloced = 0;
_memListFree = _memListFreeEnd = NULL; _memListFree = _memListFreeEnd = NULL;
@ -31,7 +33,7 @@ MemMan::MemMan(void) {
MemMan::~MemMan(void) { MemMan::~MemMan(void) {
} }
void MemMan::alloc(BsMemHandle *bsMem, uint32 pSize, uint16 pCond) { void MemMan::alloc(MemHandle *bsMem, uint32 pSize, uint16 pCond) {
_alloced += pSize; _alloced += pSize;
bsMem->data = (void*)malloc(pSize); bsMem->data = (void*)malloc(pSize);
if (!bsMem->data) if (!bsMem->data)
@ -46,7 +48,7 @@ void MemMan::alloc(BsMemHandle *bsMem, uint32 pSize, uint16 pCond) {
checkMemoryUsage(); checkMemoryUsage();
} }
void MemMan::freeNow(BsMemHandle *bsMem) { void MemMan::freeNow(MemHandle *bsMem) {
if (bsMem->cond != MEM_FREED) { if (bsMem->cond != MEM_FREED) {
_alloced -= bsMem->size; _alloced -= bsMem->size;
removeFromFreeList(bsMem); removeFromFreeList(bsMem);
@ -55,7 +57,7 @@ void MemMan::freeNow(BsMemHandle *bsMem) {
} }
} }
void MemMan::setCondition(BsMemHandle *bsMem, uint16 pCond) { void MemMan::setCondition(MemHandle *bsMem, uint16 pCond) {
if ((pCond == MEM_FREED) || (pCond > MEM_DONT_FREE)) if ((pCond == MEM_FREED) || (pCond > MEM_DONT_FREE))
error("MemMan::setCondition: program tried to set illegal memory condition"); error("MemMan::setCondition: program tried to set illegal memory condition");
if (bsMem->cond != pCond) { if (bsMem->cond != pCond) {
@ -89,7 +91,7 @@ void MemMan::checkMemoryUsage(void) {
} }
} }
void MemMan::addToFreeList(BsMemHandle *bsMem) { void MemMan::addToFreeList(MemHandle *bsMem) {
if (bsMem->next || bsMem->prev) { if (bsMem->next || bsMem->prev) {
warning("addToFreeList: mem block is already in freeList"); warning("addToFreeList: mem block is already in freeList");
return; return;
@ -103,7 +105,7 @@ void MemMan::addToFreeList(BsMemHandle *bsMem) {
_memListFreeEnd = _memListFree; _memListFreeEnd = _memListFree;
} }
void MemMan::removeFromFreeList(BsMemHandle *bsMem) { void MemMan::removeFromFreeList(MemHandle *bsMem) {
if (_memListFree == bsMem) if (_memListFree == bsMem)
_memListFree = bsMem->next; _memListFree = bsMem->next;
if (_memListFreeEnd == bsMem) if (_memListFreeEnd == bsMem)
@ -116,7 +118,8 @@ void MemMan::removeFromFreeList(BsMemHandle *bsMem) {
bsMem->next = bsMem->prev = NULL; bsMem->next = bsMem->prev = NULL;
} }
void MemMan::initHandle(BsMemHandle *bsMem) { void MemMan::initHandle(MemHandle *bsMem) {
memset(bsMem, 0, sizeof(BsMemHandle)); memset(bsMem, 0, sizeof(MemHandle));
} }
} // End of namespace Sword1

View file

@ -24,12 +24,14 @@
#include "scummsys.h" #include "scummsys.h"
struct BsMemHandle { namespace Sword1 {
struct MemHandle {
void *data; void *data;
uint32 size; uint32 size;
uint32 refCount; uint32 refCount;
uint16 cond; uint16 cond;
BsMemHandle *next, *prev; MemHandle *next, *prev;
}; };
// mem conditions: // mem conditions:
#define MEM_FREED 0 #define MEM_FREED 0
@ -42,18 +44,20 @@ class MemMan {
public: public:
MemMan(void); MemMan(void);
~MemMan(void); ~MemMan(void);
void alloc(BsMemHandle *bsMem, uint32 pSize, uint16 pCond = MEM_DONT_FREE); void alloc(MemHandle *bsMem, uint32 pSize, uint16 pCond = MEM_DONT_FREE);
void setCondition(BsMemHandle *bsMem, uint16 pCond); void setCondition(MemHandle *bsMem, uint16 pCond);
void freeNow(BsMemHandle *bsMem); void freeNow(MemHandle *bsMem);
void initHandle(BsMemHandle *bsMem); void initHandle(MemHandle *bsMem);
void flush(void); void flush(void);
private: private:
void addToFreeList(BsMemHandle *bsMem); void addToFreeList(MemHandle *bsMem);
void removeFromFreeList(BsMemHandle *bsMem); void removeFromFreeList(MemHandle *bsMem);
void checkMemoryUsage(void); void checkMemoryUsage(void);
uint32 _alloced; //currently allocated memory uint32 _alloced; //currently allocated memory
BsMemHandle *_memListFree; MemHandle *_memListFree;
BsMemHandle *_memListFreeEnd; MemHandle *_memListFreeEnd;
}; };
} // End of namespace Sword1
#endif //MEMMAN_H #endif //MEMMAN_H

View file

@ -29,6 +29,8 @@
#include "screen.h" #include "screen.h"
#include "logic.h" #include "logic.h"
namespace Sword1 {
enum { enum {
MENU_CLOSED, MENU_CLOSED,
MENU_CLOSING, MENU_CLOSING,
@ -36,7 +38,7 @@ enum {
MENU_OPEN MENU_OPEN
}; };
const byte SwordMenu::_fadeEffectTop[64] = { const byte Menu::_fadeEffectTop[64] = {
1, 7, 5, 3, 2, 4, 6, 0, 1, 7, 5, 3, 2, 4, 6, 0,
3, 1, 7, 5, 4, 6, 0, 2, 3, 1, 7, 5, 4, 6, 0, 2,
5, 3, 1, 7, 6, 0, 2, 4, 5, 3, 1, 7, 6, 0, 2, 4,
@ -47,7 +49,7 @@ const byte SwordMenu::_fadeEffectTop[64] = {
1, 7, 5, 3, 2, 4, 6, 0 1, 7, 5, 3, 2, 4, 6, 0
}; };
const byte SwordMenu::_fadeEffectBottom[64] = { const byte Menu::_fadeEffectBottom[64] = {
7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0,
0, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1,
1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2,
@ -58,7 +60,7 @@ const byte SwordMenu::_fadeEffectBottom[64] = {
6, 5, 4, 3, 2, 1, 0, 7 6, 5, 4, 3, 2, 1, 0, 7
}; };
SwordMenuIcon::SwordMenuIcon(uint8 menuType, uint8 menuPos, uint32 resId, uint32 frame, SwordScreen *screen) { MenuIcon::MenuIcon(uint8 menuType, uint8 menuPos, uint32 resId, uint32 frame, Screen *screen) {
_menuType = menuType; _menuType = menuType;
_menuPos = menuPos; _menuPos = menuPos;
_resId = resId; _resId = resId;
@ -67,7 +69,7 @@ SwordMenuIcon::SwordMenuIcon(uint8 menuType, uint8 menuPos, uint32 resId, uint32
_selected = false; _selected = false;
} }
bool SwordMenuIcon::wasClicked(uint16 mouseX, uint16 mouseY) { bool MenuIcon::wasClicked(uint16 mouseX, uint16 mouseY) {
if (((_menuType == MENU_TOP) && (mouseY >= 40)) || ((_menuType == MENU_BOT) && (mouseY < 440))) if (((_menuType == MENU_TOP) && (mouseY >= 40)) || ((_menuType == MENU_BOT) && (mouseY < 440)))
return false; return false;
if ((mouseX >= _menuPos * 40) && (mouseX < (_menuPos + 1) * 40)) if ((mouseX >= _menuPos * 40) && (mouseX < (_menuPos + 1) * 40))
@ -76,17 +78,17 @@ bool SwordMenuIcon::wasClicked(uint16 mouseX, uint16 mouseY) {
return false; return false;
} }
void SwordMenuIcon::setSelect(bool pSel) { void MenuIcon::setSelect(bool pSel) {
_selected = pSel; _selected = pSel;
} }
void SwordMenuIcon::draw(const byte *fadeMask, int8 fadeStatus) { void MenuIcon::draw(const byte *fadeMask, int8 fadeStatus) {
uint16 x = _menuPos * 40; uint16 x = _menuPos * 40;
uint16 y = (_menuType == MENU_TOP)?(0):(440); uint16 y = (_menuType == MENU_TOP)?(0):(440);
_screen->showFrame(x, y, _resId, _frame + (_selected ? 1 : 0), fadeMask, fadeStatus); _screen->showFrame(x, y, _resId, _frame + (_selected ? 1 : 0), fadeMask, fadeStatus);
} }
SwordMenu::SwordMenu(SwordScreen *pScreen, SwordMouse *pMouse) { Menu::Menu(Screen *pScreen, Mouse *pMouse) {
uint8 cnt; uint8 cnt;
_screen = pScreen; _screen = pScreen;
_mouse = pMouse; _mouse = pMouse;
@ -101,7 +103,7 @@ SwordMenu::SwordMenu(SwordScreen *pScreen, SwordMouse *pMouse) {
_inMenu = 0; _inMenu = 0;
} }
void SwordMenu::refreshMenus() { void Menu::refreshMenus() {
if (_objectBarStatus == MENU_OPEN) { if (_objectBarStatus == MENU_OPEN) {
buildMenu(); buildMenu();
for (uint8 cnt = 0; cnt < 16; cnt++) { for (uint8 cnt = 0; cnt < 16; cnt++) {
@ -122,7 +124,7 @@ void SwordMenu::refreshMenus() {
} }
} }
uint8 SwordMenu::checkMenuClick(uint8 menuType) { uint8 Menu::checkMenuClick(uint8 menuType) {
uint16 mouseEvent = _mouse->testEvent(); uint16 mouseEvent = _mouse->testEvent();
if (!mouseEvent) if (!mouseEvent)
return 0; return 0;
@ -132,30 +134,30 @@ uint8 SwordMenu::checkMenuClick(uint8 menuType) {
// Conversation mode. Icons are highlighted on mouse-down, but // Conversation mode. Icons are highlighted on mouse-down, but
// the actual response is made on mouse-up. // the actual response is made on mouse-up.
if (menuType == MENU_BOT) { if (menuType == MENU_BOT) {
if (SwordLogic::_scriptVars[OBJECT_HELD] && (mouseEvent & BS1L_BUTTON_UP)) { if (Logic::_scriptVars[OBJECT_HELD] && (mouseEvent & BS1L_BUTTON_UP)) {
for (uint8 cnt = 0; cnt < SwordLogic::_scriptVars[IN_SUBJECT]; cnt++) { for (uint8 cnt = 0; cnt < Logic::_scriptVars[IN_SUBJECT]; cnt++) {
if (_subjectBar[cnt] == SwordLogic::_scriptVars[OBJECT_HELD]) if (_subjectBar[cnt] == Logic::_scriptVars[OBJECT_HELD])
return cnt + 1; return cnt + 1;
} }
} else if (mouseEvent & BS1L_BUTTON_DOWN) { } else if (mouseEvent & BS1L_BUTTON_DOWN) {
for (uint8 cnt = 0; cnt < SwordLogic::_scriptVars[IN_SUBJECT]; cnt++) { for (uint8 cnt = 0; cnt < Logic::_scriptVars[IN_SUBJECT]; cnt++) {
if (_subjects[cnt]->wasClicked(x, y)) { if (_subjects[cnt]->wasClicked(x, y)) {
SwordLogic::_scriptVars[OBJECT_HELD] = _subjectBar[cnt]; Logic::_scriptVars[OBJECT_HELD] = _subjectBar[cnt];
refreshMenus(); refreshMenus();
break; break;
} }
} }
} }
} else { } else {
if (SwordLogic::_scriptVars[OBJECT_HELD] && (mouseEvent & BS1L_BUTTON_UP)) { if (Logic::_scriptVars[OBJECT_HELD] && (mouseEvent & BS1L_BUTTON_UP)) {
for (uint8 cnt = 0; cnt < _inMenu; cnt++) { for (uint8 cnt = 0; cnt < _inMenu; cnt++) {
if (_menuList[cnt] == SwordLogic::_scriptVars[OBJECT_HELD]) if (_menuList[cnt] == Logic::_scriptVars[OBJECT_HELD])
return cnt + 1; return cnt + 1;
} }
} else if (mouseEvent & BS1L_BUTTON_DOWN) { } else if (mouseEvent & BS1L_BUTTON_DOWN) {
for (uint8 cnt = 0; cnt < _inMenu; cnt++) { for (uint8 cnt = 0; cnt < _inMenu; cnt++) {
if (_objects[cnt]->wasClicked(x, y)) { if (_objects[cnt]->wasClicked(x, y)) {
SwordLogic::_scriptVars[OBJECT_HELD] = _menuList[cnt]; Logic::_scriptVars[OBJECT_HELD] = _menuList[cnt];
refreshMenus(); refreshMenus();
break; break;
} }
@ -168,21 +170,21 @@ uint8 SwordMenu::checkMenuClick(uint8 menuType) {
for (uint8 cnt = 0; cnt < _inMenu; cnt++) { for (uint8 cnt = 0; cnt < _inMenu; cnt++) {
if (_objects[cnt]->wasClicked(x, y)) { if (_objects[cnt]->wasClicked(x, y)) {
if (mouseEvent & BS1R_BUTTON_DOWN) { // looking at item if (mouseEvent & BS1R_BUTTON_DOWN) { // looking at item
SwordLogic::_scriptVars[OBJECT_HELD] = _menuList[cnt]; Logic::_scriptVars[OBJECT_HELD] = _menuList[cnt];
SwordLogic::_scriptVars[MENU_LOOKING] = 1; Logic::_scriptVars[MENU_LOOKING] = 1;
SwordLogic::_scriptVars[DEFAULT_ICON_TEXT] = _objectDefs[_menuList[cnt]].textDesc; Logic::_scriptVars[DEFAULT_ICON_TEXT] = _objectDefs[_menuList[cnt]].textDesc;
} else if (mouseEvent & BS1L_BUTTON_DOWN) { } else if (mouseEvent & BS1L_BUTTON_DOWN) {
if (SwordLogic::_scriptVars[OBJECT_HELD]) { if (Logic::_scriptVars[OBJECT_HELD]) {
if (SwordLogic::_scriptVars[OBJECT_HELD] == _menuList[cnt]) { if (Logic::_scriptVars[OBJECT_HELD] == _menuList[cnt]) {
_mouse->setLuggage(0, 0); _mouse->setLuggage(0, 0);
SwordLogic::_scriptVars[OBJECT_HELD] = 0; // reselected => deselect it Logic::_scriptVars[OBJECT_HELD] = 0; // reselected => deselect it
} else { // the player is clicking another item on this one. } else { // the player is clicking another item on this one.
// run its use-script, if there is one // run its use-script, if there is one
SwordLogic::_scriptVars[SECOND_ITEM] = _menuList[cnt]; Logic::_scriptVars[SECOND_ITEM] = _menuList[cnt];
_mouse->setLuggage(0, 0); _mouse->setLuggage(0, 0);
} }
} else { } else {
SwordLogic::_scriptVars[OBJECT_HELD] = _menuList[cnt]; Logic::_scriptVars[OBJECT_HELD] = _menuList[cnt];
_mouse->setLuggage(_objectDefs[_menuList[cnt]].luggageIconRes, 0); _mouse->setLuggage(_objectDefs[_menuList[cnt]].luggageIconRes, 0);
} }
} }
@ -195,25 +197,25 @@ uint8 SwordMenu::checkMenuClick(uint8 menuType) {
return 0; return 0;
} }
void SwordMenu::buildSubjects(void) { void Menu::buildSubjects(void) {
uint8 cnt; uint8 cnt;
for (cnt = 0; cnt < 16; cnt++) for (cnt = 0; cnt < 16; cnt++)
if (_subjects[cnt]) { if (_subjects[cnt]) {
delete _subjects[cnt]; delete _subjects[cnt];
_subjects[cnt] = NULL; _subjects[cnt] = NULL;
} }
for (cnt = 0; cnt < SwordLogic::_scriptVars[IN_SUBJECT]; cnt++) { for (cnt = 0; cnt < Logic::_scriptVars[IN_SUBJECT]; cnt++) {
uint32 res = _subjectList[(_subjectBar[cnt] & 65535) - BASE_SUBJECT].subjectRes; uint32 res = _subjectList[(_subjectBar[cnt] & 65535) - BASE_SUBJECT].subjectRes;
uint32 frame = _subjectList[(_subjectBar[cnt] & 65535) - BASE_SUBJECT].frameNo; uint32 frame = _subjectList[(_subjectBar[cnt] & 65535) - BASE_SUBJECT].frameNo;
_subjects[cnt] = new SwordMenuIcon(MENU_BOT, cnt, res, frame, _screen); _subjects[cnt] = new MenuIcon(MENU_BOT, cnt, res, frame, _screen);
if (SwordLogic::_scriptVars[OBJECT_HELD]) if (Logic::_scriptVars[OBJECT_HELD])
_subjects[cnt]->setSelect(_subjectBar[cnt] == SwordLogic::_scriptVars[OBJECT_HELD]); _subjects[cnt]->setSelect(_subjectBar[cnt] == Logic::_scriptVars[OBJECT_HELD]);
else else
_subjects[cnt]->setSelect(true); _subjects[cnt]->setSelect(true);
} }
} }
void SwordMenu::refresh(uint8 menuType) { void Menu::refresh(uint8 menuType) {
uint i; uint i;
if (menuType == MENU_TOP) { if (menuType == MENU_TOP) {
@ -259,7 +261,7 @@ void SwordMenu::refresh(uint8 menuType) {
if (_fadeSubject > 0) if (_fadeSubject > 0)
_fadeSubject--; _fadeSubject--;
else { else {
for (i = 0; i < SwordLogic::_scriptVars[IN_SUBJECT]; i++) { for (i = 0; i < Logic::_scriptVars[IN_SUBJECT]; i++) {
delete _subjects[i]; delete _subjects[i];
_subjects[i] = NULL; _subjects[i] = NULL;
} }
@ -269,8 +271,8 @@ void SwordMenu::refresh(uint8 menuType) {
} }
} }
void SwordMenu::buildMenu(void) { void Menu::buildMenu(void) {
uint32 *pockets = SwordLogic::_scriptVars + POCKET_1; uint32 *pockets = Logic::_scriptVars + POCKET_1;
for (uint8 cnt = 0; cnt < _inMenu; cnt++) for (uint8 cnt = 0; cnt < _inMenu; cnt++)
if (_objects[cnt]) { if (_objects[cnt]) {
delete _objects[cnt]; delete _objects[cnt];
@ -283,15 +285,15 @@ void SwordMenu::buildMenu(void) {
_inMenu++; _inMenu++;
} }
for (uint32 menuSlot = 0; menuSlot < _inMenu; menuSlot++) { for (uint32 menuSlot = 0; menuSlot < _inMenu; menuSlot++) {
_objects[menuSlot] = new SwordMenuIcon(MENU_TOP, menuSlot, _objectDefs[_menuList[menuSlot]].bigIconRes, _objectDefs[_menuList[menuSlot]].bigIconFrame, _screen); _objects[menuSlot] = new MenuIcon(MENU_TOP, menuSlot, _objectDefs[_menuList[menuSlot]].bigIconRes, _objectDefs[_menuList[menuSlot]].bigIconFrame, _screen);
uint32 objHeld = SwordLogic::_scriptVars[OBJECT_HELD]; uint32 objHeld = Logic::_scriptVars[OBJECT_HELD];
// check highlighting // check highlighting
if (SwordLogic::_scriptVars[MENU_LOOKING] || _subjectBarStatus == MENU_OPEN) { // either we're in the chooser or we're doing a 'LOOK AT' if (Logic::_scriptVars[MENU_LOOKING] || _subjectBarStatus == MENU_OPEN) { // either we're in the chooser or we're doing a 'LOOK AT'
if ((!objHeld) || (objHeld == _menuList[menuSlot])) if ((!objHeld) || (objHeld == _menuList[menuSlot]))
_objects[menuSlot]->setSelect(true); _objects[menuSlot]->setSelect(true);
} else if (SwordLogic::_scriptVars[SECOND_ITEM]) { // clicked luggage onto 2nd icon - we need to colour-highlight the 2 relevant icons & grey out the rest } else if (Logic::_scriptVars[SECOND_ITEM]) { // clicked luggage onto 2nd icon - we need to colour-highlight the 2 relevant icons & grey out the rest
if ((_menuList[menuSlot] == objHeld) || (_menuList[menuSlot] == SwordLogic::_scriptVars[SECOND_ITEM])) if ((_menuList[menuSlot] == objHeld) || (_menuList[menuSlot] == Logic::_scriptVars[SECOND_ITEM]))
_objects[menuSlot]->setSelect(true); _objects[menuSlot]->setSelect(true);
} else { // this object is selected - ie. GREYED OUT } else { // this object is selected - ie. GREYED OUT
if (objHeld != _menuList[menuSlot]) if (objHeld != _menuList[menuSlot])
@ -300,7 +302,7 @@ void SwordMenu::buildMenu(void) {
} }
} }
void SwordMenu::showMenu(uint8 menuType) { void Menu::showMenu(uint8 menuType) {
if (menuType == MENU_TOP) { if (menuType == MENU_TOP) {
if (_objectBarStatus == MENU_OPEN) { if (_objectBarStatus == MENU_OPEN) {
for (uint8 cnt = 0; cnt < 16; cnt++) { for (uint8 cnt = 0; cnt < 16; cnt++) {
@ -317,21 +319,21 @@ void SwordMenu::showMenu(uint8 menuType) {
} }
} }
void SwordMenu::fnStartMenu(void) { void Menu::fnStartMenu(void) {
SwordLogic::_scriptVars[OBJECT_HELD] = 0; // icon no longer selected Logic::_scriptVars[OBJECT_HELD] = 0; // icon no longer selected
SwordLogic::_scriptVars[SECOND_ITEM] = 0; // second icon no longer selected (after using one on another) Logic::_scriptVars[SECOND_ITEM] = 0; // second icon no longer selected (after using one on another)
SwordLogic::_scriptVars[MENU_LOOKING] = 0; // no longer 'looking at' an icon Logic::_scriptVars[MENU_LOOKING] = 0; // no longer 'looking at' an icon
buildMenu(); buildMenu();
showMenu(MENU_TOP); showMenu(MENU_TOP);
} }
void SwordMenu::fnEndMenu(void) { void Menu::fnEndMenu(void) {
if (_objectBarStatus != MENU_CLOSED) if (_objectBarStatus != MENU_CLOSED)
_objectBarStatus = MENU_CLOSING; _objectBarStatus = MENU_CLOSING;
} }
void SwordMenu::fnChooser(BsObject *compact) { void Menu::fnChooser(Object *compact) {
SwordLogic::_scriptVars[OBJECT_HELD] = 0; Logic::_scriptVars[OBJECT_HELD] = 0;
_mouse->setLuggage(0, 0); _mouse->setLuggage(0, 0);
buildSubjects(); buildSubjects();
compact->o_logic = LOGIC_choose; compact->o_logic = LOGIC_choose;
@ -339,20 +341,20 @@ void SwordMenu::fnChooser(BsObject *compact) {
_subjectBarStatus = MENU_OPENING; _subjectBarStatus = MENU_OPENING;
} }
void SwordMenu::fnEndChooser(void) { void Menu::fnEndChooser(void) {
SwordLogic::_scriptVars[OBJECT_HELD] = 0; Logic::_scriptVars[OBJECT_HELD] = 0;
_subjectBarStatus = MENU_CLOSING; _subjectBarStatus = MENU_CLOSING;
_objectBarStatus = MENU_CLOSING; _objectBarStatus = MENU_CLOSING;
_mouse->controlPanel(false); _mouse->controlPanel(false);
_mouse->setLuggage(0, 0); _mouse->setLuggage(0, 0);
} }
void SwordMenu::checkTopMenu(void) { void Menu::checkTopMenu(void) {
if (_objectBarStatus == MENU_OPEN) if (_objectBarStatus == MENU_OPEN)
checkMenuClick(MENU_TOP); checkMenuClick(MENU_TOP);
} }
int SwordMenu::logicChooser(BsObject *compact) { int Menu::logicChooser(Object *compact) {
uint8 objSelected = 0; uint8 objSelected = 0;
if (_objectBarStatus == MENU_OPEN) if (_objectBarStatus == MENU_OPEN)
objSelected = checkMenuClick(MENU_TOP); objSelected = checkMenuClick(MENU_TOP);
@ -365,11 +367,13 @@ int SwordMenu::logicChooser(BsObject *compact) {
return 0; return 0;
} }
void SwordMenu::fnAddSubject(int32 sub) { void Menu::fnAddSubject(int32 sub) {
_subjectBar[SwordLogic::_scriptVars[IN_SUBJECT]] = sub; _subjectBar[Logic::_scriptVars[IN_SUBJECT]] = sub;
SwordLogic::_scriptVars[IN_SUBJECT]++; Logic::_scriptVars[IN_SUBJECT]++;
} }
void SwordMenu::cfnReleaseMenu(void) { void Menu::cfnReleaseMenu(void) {
_objectBarStatus = MENU_CLOSING; _objectBarStatus = MENU_CLOSING;
} }
} // End of namespace Sword1

View file

@ -25,8 +25,10 @@
#include "sworddefs.h" #include "sworddefs.h"
#include "object.h" #include "object.h"
class SwordScreen; namespace Sword1 {
class SwordMouse;
class Screen;
class Mouse;
class ResMan; class ResMan;
#define MENU_TOP 0 #define MENU_TOP 0
@ -45,9 +47,9 @@ struct MenuObject {
uint32 useScript; uint32 useScript;
}; };
class SwordMenuIcon { class MenuIcon {
public: public:
SwordMenuIcon(uint8 menuType, uint8 menuPos, uint32 resId, uint32 frame, SwordScreen *screen); MenuIcon(uint8 menuType, uint8 menuPos, uint32 resId, uint32 frame, Screen *screen);
bool wasClicked(uint16 mouseX, uint16 mouseY); bool wasClicked(uint16 mouseX, uint16 mouseY);
void setSelect(bool pSel); void setSelect(bool pSel);
void draw(const byte *fadeMask = NULL, int8 fadeStatus = 0); void draw(const byte *fadeMask = NULL, int8 fadeStatus = 0);
@ -56,17 +58,17 @@ private:
uint8 _menuType, _menuPos; uint8 _menuType, _menuPos;
uint32 _resId, _frame; uint32 _resId, _frame;
bool _selected; bool _selected;
SwordScreen *_screen; Screen *_screen;
}; };
class SwordMenu { class Menu {
public: public:
SwordMenu(SwordScreen *pScreen, SwordMouse *pMouse); Menu(Screen *pScreen, Mouse *pMouse);
void fnChooser(BsObject *compact); void fnChooser(Object *compact);
void fnEndChooser(void); void fnEndChooser(void);
void fnAddSubject(int32 sub); void fnAddSubject(int32 sub);
void cfnReleaseMenu(void); void cfnReleaseMenu(void);
int logicChooser(BsObject *compact); int logicChooser(Object *compact);
void engine(void); void engine(void);
void refresh(uint8 menuType); void refresh(uint8 menuType);
void fnStartMenu(void); void fnStartMenu(void);
@ -85,19 +87,21 @@ private:
void refreshMenus(void); void refreshMenus(void);
uint8 checkMenuClick(uint8 menuType); uint8 checkMenuClick(uint8 menuType);
//- lower menu, speech subjects: //- lower menu, speech subjects:
SwordMenuIcon *_subjects[16]; MenuIcon *_subjects[16];
uint32 _subjectBar[16]; uint32 _subjectBar[16];
//- top menu, items //- top menu, items
SwordMenuIcon *_objects[TOTAL_pockets]; MenuIcon *_objects[TOTAL_pockets];
uint32 _menuList[TOTAL_pockets]; uint32 _menuList[TOTAL_pockets];
uint32 _inMenu; uint32 _inMenu;
SwordScreen *_screen; Screen *_screen;
SwordMouse *_mouse; Mouse *_mouse;
static const Subject _subjectList[TOTAL_subjects]; static const Subject _subjectList[TOTAL_subjects];
static const byte _fadeEffectTop[64]; static const byte _fadeEffectTop[64];
static const byte _fadeEffectBottom[64]; static const byte _fadeEffectBottom[64];
}; };
} // End of namespace Sword1
#endif //BSMENU_H #endif //BSMENU_H

View file

@ -31,16 +31,18 @@
#include "swordres.h" #include "swordres.h"
#include "menu.h" #include "menu.h"
SwordMouse::SwordMouse(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) { namespace Sword1 {
Mouse::Mouse(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) {
_resMan = pResMan; _resMan = pResMan;
_objMan = pObjMan; _objMan = pObjMan;
_system = system; _system = system;
_currentPtr = NULL; _currentPtr = NULL;
} }
void SwordMouse::initialize(void) { void Mouse::initialize(void) {
_numObjs = 0; _numObjs = 0;
SwordLogic::_scriptVars[MOUSE_STATUS] = 0; // mouse off and unlocked Logic::_scriptVars[MOUSE_STATUS] = 0; // mouse off and unlocked
_getOff = 0; _getOff = 0;
_inTopMenu = false; _inTopMenu = false;
_mouseOverride = false; _mouseOverride = false;
@ -53,7 +55,7 @@ void SwordMouse::initialize(void) {
createPointer(0, 0); createPointer(0, 0);
} }
void SwordMouse::controlPanel(bool on) { // true on entering cpanel, false when leaving void Mouse::controlPanel(bool on) { // true on entering cpanel, false when leaving
static uint32 savedPtrId = 0; static uint32 savedPtrId = 0;
if (on) { if (on) {
savedPtrId = _currentPtrId; savedPtrId = _currentPtrId;
@ -68,18 +70,18 @@ void SwordMouse::controlPanel(bool on) { // true on entering cpanel, false when
} }
} }
void SwordMouse::useLogicAndMenu(SwordLogic *pLogic, SwordMenu *pMenu) { void Mouse::useLogicAndMenu(Logic *pLogic, Menu *pMenu) {
_logic = pLogic; _logic = pLogic;
_menu = pMenu; _menu = pMenu;
} }
void SwordMouse::addToList(int id, BsObject *compact) { void Mouse::addToList(int id, Object *compact) {
_objList[_numObjs].id = id; _objList[_numObjs].id = id;
_objList[_numObjs].compact = compact; _objList[_numObjs].compact = compact;
_numObjs++; _numObjs++;
} }
void SwordMouse::engine(uint16 x, uint16 y, uint16 eventFlags) { void Mouse::engine(uint16 x, uint16 y, uint16 eventFlags) {
_state = 0; // all mouse events are flushed after one cycle. _state = 0; // all mouse events are flushed after one cycle.
if (_lastState) { // delay all events by one cycle to notice L_button + R_button clicks correctly. if (_lastState) { // delay all events by one cycle to notice L_button + R_button clicks correctly.
_state = _lastState | eventFlags; _state = _lastState | eventFlags;
@ -96,22 +98,22 @@ void SwordMouse::engine(uint16 x, uint16 y, uint16 eventFlags) {
_mouseX = x; _mouseX = x;
_mouseY = y; _mouseY = y;
if (!(SwordLogic::_scriptVars[MOUSE_STATUS] & 1)) { // no human? if (!(Logic::_scriptVars[MOUSE_STATUS] & 1)) { // no human?
_numObjs = 0; _numObjs = 0;
return; // no human, so we don't want the mouse engine return; // no human, so we don't want the mouse engine
} }
if (!SwordLogic::_scriptVars[TOP_MENU_DISABLED]) { if (!Logic::_scriptVars[TOP_MENU_DISABLED]) {
if (y < 40) { // okay, we are in the top menu. if (y < 40) { // okay, we are in the top menu.
if (!_inTopMenu) { // are we just entering it? if (!_inTopMenu) { // are we just entering it?
if (!SwordLogic::_scriptVars[OBJECT_HELD]) if (!Logic::_scriptVars[OBJECT_HELD])
_menu->fnStartMenu(); _menu->fnStartMenu();
setPointer(MSE_POINTER, 0); setPointer(MSE_POINTER, 0);
} }
_menu->checkTopMenu(); _menu->checkTopMenu();
_inTopMenu = true; _inTopMenu = true;
} else if (_inTopMenu) { // we're not in the menu. did we just leave it? } else if (_inTopMenu) { // we're not in the menu. did we just leave it?
if (!SwordLogic::_scriptVars[OBJECT_HELD]) if (!Logic::_scriptVars[OBJECT_HELD])
_menu->fnEndMenu(); _menu->fnEndMenu();
_inTopMenu = false; _inTopMenu = false;
} }
@ -120,8 +122,8 @@ void SwordMouse::engine(uint16 x, uint16 y, uint16 eventFlags) {
_inTopMenu = false; _inTopMenu = false;
} }
SwordLogic::_scriptVars[MOUSE_X] = SwordLogic::_scriptVars[SCROLL_OFFSET_X] + x + 128; Logic::_scriptVars[MOUSE_X] = Logic::_scriptVars[SCROLL_OFFSET_X] + x + 128;
SwordLogic::_scriptVars[MOUSE_Y] = SwordLogic::_scriptVars[SCROLL_OFFSET_Y] + y + 128 - 40; Logic::_scriptVars[MOUSE_Y] = Logic::_scriptVars[SCROLL_OFFSET_Y] + y + 128 - 40;
//- //-
int32 touchedId = 0; int32 touchedId = 0;
@ -130,17 +132,17 @@ void SwordMouse::engine(uint16 x, uint16 y, uint16 eventFlags) {
for (uint16 priority = 0; (priority < 10) && (!touchedId); priority++) { for (uint16 priority = 0; (priority < 10) && (!touchedId); priority++) {
for (uint16 cnt = 0; (cnt < _numObjs) && (!touchedId); cnt++) { for (uint16 cnt = 0; (cnt < _numObjs) && (!touchedId); cnt++) {
if ((_objList[cnt].compact->o_priority == priority) && if ((_objList[cnt].compact->o_priority == priority) &&
(SwordLogic::_scriptVars[MOUSE_X] >= (uint32)_objList[cnt].compact->o_mouse_x1) && (Logic::_scriptVars[MOUSE_X] >= (uint32)_objList[cnt].compact->o_mouse_x1) &&
(SwordLogic::_scriptVars[MOUSE_X] <= (uint32)_objList[cnt].compact->o_mouse_x2) && (Logic::_scriptVars[MOUSE_X] <= (uint32)_objList[cnt].compact->o_mouse_x2) &&
(SwordLogic::_scriptVars[MOUSE_Y] >= (uint32)_objList[cnt].compact->o_mouse_y1) && (Logic::_scriptVars[MOUSE_Y] >= (uint32)_objList[cnt].compact->o_mouse_y1) &&
(SwordLogic::_scriptVars[MOUSE_Y] <= (uint32)_objList[cnt].compact->o_mouse_y2)) { (Logic::_scriptVars[MOUSE_Y] <= (uint32)_objList[cnt].compact->o_mouse_y2)) {
touchedId = _objList[cnt].id; touchedId = _objList[cnt].id;
clicked = cnt; clicked = cnt;
} }
} }
} }
if (touchedId != (int)SwordLogic::_scriptVars[SPECIAL_ITEM]) { //the mouse collision situation has changed in one way or another if (touchedId != (int)Logic::_scriptVars[SPECIAL_ITEM]) { //the mouse collision situation has changed in one way or another
SwordLogic::_scriptVars[SPECIAL_ITEM] = touchedId; Logic::_scriptVars[SPECIAL_ITEM] = touchedId;
if (_getOff) { // there was something else selected before, run its get-off script if (_getOff) { // there was something else selected before, run its get-off script
_logic->runMouseScript(NULL, _getOff); _logic->runMouseScript(NULL, _getOff);
_getOff = 0; _getOff = 0;
@ -153,29 +155,29 @@ void SwordMouse::engine(uint16 x, uint16 y, uint16 eventFlags) {
} }
} }
} else } else
SwordLogic::_scriptVars[SPECIAL_ITEM] = 0; Logic::_scriptVars[SPECIAL_ITEM] = 0;
if (_state & MOUSE_DOWN_MASK) { if (_state & MOUSE_DOWN_MASK) {
if (_inTopMenu) { if (_inTopMenu) {
if (SwordLogic::_scriptVars[SECOND_ITEM]) if (Logic::_scriptVars[SECOND_ITEM])
_logic->runMouseScript(NULL, _menu->_objectDefs[SwordLogic::_scriptVars[SECOND_ITEM]].useScript); _logic->runMouseScript(NULL, _menu->_objectDefs[Logic::_scriptVars[SECOND_ITEM]].useScript);
if (SwordLogic::_scriptVars[MENU_LOOKING]) if (Logic::_scriptVars[MENU_LOOKING])
_logic->cfnPresetScript(NULL, -1, PLAYER, SCR_menu_look, 0, 0, 0, 0); _logic->cfnPresetScript(NULL, -1, PLAYER, SCR_menu_look, 0, 0, 0, 0);
} }
SwordLogic::_scriptVars[MOUSE_BUTTON] = _state & MOUSE_DOWN_MASK; Logic::_scriptVars[MOUSE_BUTTON] = _state & MOUSE_DOWN_MASK;
if (SwordLogic::_scriptVars[SPECIAL_ITEM]) { if (Logic::_scriptVars[SPECIAL_ITEM]) {
BsObject *compact = _objMan->fetchObject(SwordLogic::_scriptVars[SPECIAL_ITEM]); Object *compact = _objMan->fetchObject(Logic::_scriptVars[SPECIAL_ITEM]);
_logic->runMouseScript(compact, compact->o_mouse_click); _logic->runMouseScript(compact, compact->o_mouse_click);
} }
} }
_numObjs = 0; _numObjs = 0;
} }
uint16 SwordMouse::testEvent(void) { uint16 Mouse::testEvent(void) {
return _state; return _state;
} }
void SwordMouse::createPointer(uint32 ptrId, uint32 luggageId) { void Mouse::createPointer(uint32 ptrId, uint32 luggageId) {
if (_currentPtr) { if (_currentPtr) {
free(_currentPtr); free(_currentPtr);
_currentPtr = NULL; _currentPtr = NULL;
@ -230,13 +232,13 @@ void SwordMouse::createPointer(uint32 ptrId, uint32 luggageId) {
} }
} }
void SwordMouse::setPointer(uint32 resId, uint32 rate) { void Mouse::setPointer(uint32 resId, uint32 rate) {
_currentPtrId = resId; _currentPtrId = resId;
_frame = 0; _frame = 0;
createPointer(resId, _currentLuggageId); createPointer(resId, _currentLuggageId);
if ((resId == 0) || (!(SwordLogic::_scriptVars[MOUSE_STATUS] & 1) && (!_mouseOverride))) { if ((resId == 0) || (!(Logic::_scriptVars[MOUSE_STATUS] & 1) && (!_mouseOverride))) {
_system->set_mouse_cursor(NULL, 0, 0, 0, 0); _system->set_mouse_cursor(NULL, 0, 0, 0, 0);
_system->show_mouse(false); _system->show_mouse(false);
} else { } else {
@ -245,14 +247,14 @@ void SwordMouse::setPointer(uint32 resId, uint32 rate) {
} }
} }
void SwordMouse::setLuggage(uint32 resId, uint32 rate) { void Mouse::setLuggage(uint32 resId, uint32 rate) {
_currentLuggageId = resId; _currentLuggageId = resId;
_frame = 0; _frame = 0;
createPointer(_currentPtrId, resId); createPointer(_currentPtrId, resId);
} }
void SwordMouse::animate(void) { void Mouse::animate(void) {
if ((SwordLogic::_scriptVars[MOUSE_STATUS] == 1) || (_mouseOverride && _currentPtr)) { if ((Logic::_scriptVars[MOUSE_STATUS] == 1) || (_mouseOverride && _currentPtr)) {
_frame = (_frame + 1) % _currentPtr->numFrames; _frame = (_frame + 1) % _currentPtr->numFrames;
uint8 *ptrData = (uint8*)_currentPtr + sizeof(MousePtr); uint8 *ptrData = (uint8*)_currentPtr + sizeof(MousePtr);
ptrData += _frame * _currentPtr->sizeX * _currentPtr->sizeY; ptrData += _frame * _currentPtr->sizeX * _currentPtr->sizeY;
@ -260,40 +262,42 @@ void SwordMouse::animate(void) {
} }
} }
void SwordMouse::fnNoHuman(void) { void Mouse::fnNoHuman(void) {
if (SwordLogic::_scriptVars[MOUSE_STATUS] & 2) // locked, can't do anything if (Logic::_scriptVars[MOUSE_STATUS] & 2) // locked, can't do anything
return ; return ;
SwordLogic::_scriptVars[MOUSE_STATUS] = 0; // off & unlocked Logic::_scriptVars[MOUSE_STATUS] = 0; // off & unlocked
setLuggage(0, 0); setLuggage(0, 0);
setPointer(0, 0); setPointer(0, 0);
} }
void SwordMouse::fnAddHuman(void) { void Mouse::fnAddHuman(void) {
if (SwordLogic::_scriptVars[MOUSE_STATUS] & 2) // locked, can't do anything if (Logic::_scriptVars[MOUSE_STATUS] & 2) // locked, can't do anything
return ; return ;
SwordLogic::_scriptVars[MOUSE_STATUS] = 1; Logic::_scriptVars[MOUSE_STATUS] = 1;
SwordLogic::_scriptVars[SPECIAL_ITEM] = 0; Logic::_scriptVars[SPECIAL_ITEM] = 0;
_getOff = SCR_std_off; _getOff = SCR_std_off;
setPointer(MSE_POINTER, 0); setPointer(MSE_POINTER, 0);
} }
void SwordMouse::fnBlankMouse(void) { void Mouse::fnBlankMouse(void) {
setPointer(0, 0); setPointer(0, 0);
} }
void SwordMouse::fnNormalMouse(void) { void Mouse::fnNormalMouse(void) {
setPointer(MSE_POINTER, 0); setPointer(MSE_POINTER, 0);
} }
void SwordMouse::fnLockMouse(void) { void Mouse::fnLockMouse(void) {
SwordLogic::_scriptVars[MOUSE_STATUS] |= 2; Logic::_scriptVars[MOUSE_STATUS] |= 2;
} }
void SwordMouse::fnUnlockMouse(void) { void Mouse::fnUnlockMouse(void) {
SwordLogic::_scriptVars[MOUSE_STATUS] &= 1; Logic::_scriptVars[MOUSE_STATUS] &= 1;
} }
void SwordMouse::giveCoords(uint16 *x, uint16 *y) { void Mouse::giveCoords(uint16 *x, uint16 *y) {
*x = _mouseX; *x = _mouseX;
*y = _mouseY; *y = _mouseY;
} }
} // End of namespace Sword1

View file

@ -26,6 +26,10 @@
#include "sworddefs.h" #include "sworddefs.h"
#include "object.h" #include "object.h"
class OSystem;
namespace Sword1 {
#define MAX_MOUSE 30 #define MAX_MOUSE 30
#define BS1L_BUTTON_DOWN 2 #define BS1L_BUTTON_DOWN 2
@ -38,7 +42,7 @@
struct MouseObj { struct MouseObj {
int id; int id;
BsObject *compact; Object *compact;
}; };
#if !defined(__GNUC__) #if !defined(__GNUC__)
@ -58,18 +62,17 @@ struct MousePtr {
#pragma END_PACK_STRUCTS #pragma END_PACK_STRUCTS
#endif #endif
class SwordLogic; class Logic;
class SwordMenu; class Menu;
class ResMan; class ResMan;
class ObjectMan; class ObjectMan;
class OSystem;
class SwordMouse { class Mouse {
public: public:
SwordMouse(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan); Mouse(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan);
void initialize(void); void initialize(void);
void addToList(int id, BsObject *compact); void addToList(int id, Object *compact);
void useLogicAndMenu(SwordLogic *pLogic, SwordMenu *pMenu); void useLogicAndMenu(Logic *pLogic, Menu *pMenu);
void setLuggage(uint32 resID, uint32 rate); void setLuggage(uint32 resID, uint32 rate);
void setPointer(uint32 resID, uint32 rate); void setPointer(uint32 resID, uint32 rate);
void animate(void); void animate(void);
@ -86,8 +89,8 @@ public:
private: private:
void createPointer(uint32 ptrId, uint32 luggageId); void createPointer(uint32 ptrId, uint32 luggageId);
OSystem *_system; OSystem *_system;
SwordLogic *_logic; Logic *_logic;
SwordMenu *_menu; Menu *_menu;
MouseObj _objList[MAX_MOUSE]; MouseObj _objList[MAX_MOUSE];
ResMan *_resMan; ResMan *_resMan;
ObjectMan *_objMan; ObjectMan *_objMan;
@ -101,4 +104,6 @@ private:
bool _inTopMenu, _mouseOverride; bool _inTopMenu, _mouseOverride;
}; };
} // End of namespace Sword1
#endif //BSMOUSE_H #endif //BSMOUSE_H

View file

@ -25,13 +25,15 @@
#include "common/util.h" #include "common/util.h"
#include "common/file.h" #include "common/file.h"
namespace Sword1 {
// This means fading takes 3 seconds. // This means fading takes 3 seconds.
#define FADE_LENGTH 3 #define FADE_LENGTH 3
// These functions are only called from SwordMusic, so I'm just going to // These functions are only called from Music, so I'm just going to
// assume that if locking is needed it has already been taken care of. // assume that if locking is needed it has already been taken care of.
void SwordMusicHandle::fadeDown() { void MusicHandle::fadeDown() {
if (_fading < 0) if (_fading < 0)
_fading = -_fading; _fading = -_fading;
else if (_fading == 0) else if (_fading == 0)
@ -39,7 +41,7 @@ void SwordMusicHandle::fadeDown() {
_fadeSamples = FADE_LENGTH * getRate(); _fadeSamples = FADE_LENGTH * getRate();
} }
void SwordMusicHandle::fadeUp() { void MusicHandle::fadeUp() {
if (_fading > 0) if (_fading > 0)
_fading = -_fading; _fading = -_fading;
else if (_fading == 0) else if (_fading == 0)
@ -47,11 +49,11 @@ void SwordMusicHandle::fadeUp() {
_fadeSamples = FADE_LENGTH * getRate(); _fadeSamples = FADE_LENGTH * getRate();
} }
bool SwordMusicHandle::endOfData() const { bool MusicHandle::endOfData() const {
return !streaming(); return !streaming();
} }
int SwordMusicHandle::readBuffer(int16 *buffer, const int numSamples) { int MusicHandle::readBuffer(int16 *buffer, const int numSamples) {
int samples; int samples;
for (samples = 0; samples < numSamples && !endOfData(); samples++) { for (samples = 0; samples < numSamples && !endOfData(); samples++) {
int16 sample = _file.readUint16LE(); int16 sample = _file.readUint16LE();
@ -80,7 +82,7 @@ int SwordMusicHandle::readBuffer(int16 *buffer, const int numSamples) {
return samples; return samples;
} }
bool SwordMusicHandle::play(const char *filename, bool loop) { bool MusicHandle::play(const char *filename, bool loop) {
uint8 wavHeader[WAVEHEADERSIZE]; uint8 wavHeader[WAVEHEADERSIZE];
stop(); stop();
_file.open(filename); _file.open(filename);
@ -96,14 +98,14 @@ bool SwordMusicHandle::play(const char *filename, bool loop) {
return true; return true;
} }
void SwordMusicHandle::stop() { void MusicHandle::stop() {
if (_file.isOpen()) if (_file.isOpen())
_file.close(); _file.close();
_fading = 0; _fading = 0;
_looping = false; _looping = false;
} }
SwordMusic::SwordMusic(OSystem *system, SoundMixer *pMixer) { Music::Music(OSystem *system, SoundMixer *pMixer) {
_system = system; _system = system;
_mixer = pMixer; _mixer = pMixer;
_mixer->setupPremix(passMixerFunc, this); _mixer->setupPremix(passMixerFunc, this);
@ -113,7 +115,7 @@ SwordMusic::SwordMusic(OSystem *system, SoundMixer *pMixer) {
_volumeL = _volumeR = 192; _volumeL = _volumeR = 192;
} }
SwordMusic::~SwordMusic() { Music::~Music() {
_mixer->setupPremix(0, 0); _mixer->setupPremix(0, 0);
delete _converter[0]; delete _converter[0];
delete _converter[1]; delete _converter[1];
@ -121,28 +123,28 @@ SwordMusic::~SwordMusic() {
_system->delete_mutex(_mutex); _system->delete_mutex(_mutex);
} }
void SwordMusic::passMixerFunc(void *param, int16 *buf, uint len) { void Music::passMixerFunc(void *param, int16 *buf, uint len) {
((SwordMusic*)param)->mixer(buf, len); ((Music*)param)->mixer(buf, len);
} }
void SwordMusic::mixer(int16 *buf, uint32 len) { void Music::mixer(int16 *buf, uint32 len) {
Common::StackLock lock(_mutex); Common::StackLock lock(_mutex);
for (int i = 0; i < ARRAYSIZE(_handles); i++) for (int i = 0; i < ARRAYSIZE(_handles); i++)
if (_handles[i].streaming() && _converter[i]) if (_handles[i].streaming() && _converter[i])
_converter[i]->flow(_handles[i], buf, len, _volumeL, _volumeR); _converter[i]->flow(_handles[i], buf, len, _volumeL, _volumeR);
} }
void SwordMusic::setVolume(uint8 volL, uint8 volR) { void Music::setVolume(uint8 volL, uint8 volR) {
_volumeL = (st_volume_t)volL; _volumeL = (st_volume_t)volL;
_volumeR = (st_volume_t)volR; _volumeR = (st_volume_t)volR;
} }
void SwordMusic::giveVolume(uint8 *volL, uint8 *volR) { void Music::giveVolume(uint8 *volL, uint8 *volR) {
*volL = (uint8)_volumeL; *volL = (uint8)_volumeL;
*volR = (uint8)_volumeR; *volR = (uint8)_volumeR;
} }
void SwordMusic::startMusic(int32 tuneId, int32 loopFlag) { void Music::startMusic(int32 tuneId, int32 loopFlag) {
Common::StackLock lock(_mutex); Common::StackLock lock(_mutex);
if (strlen(_tuneList[tuneId]) > 0) { if (strlen(_tuneList[tuneId]) > 0) {
int newStream = 0; int newStream = 0;
@ -175,9 +177,11 @@ void SwordMusic::startMusic(int32 tuneId, int32 loopFlag) {
} }
} }
void SwordMusic::fadeDown() { void Music::fadeDown() {
Common::StackLock lock(_mutex); Common::StackLock lock(_mutex);
for (int i = 0; i < ARRAYSIZE(_handles); i++) for (int i = 0; i < ARRAYSIZE(_handles); i++)
if (_handles[i].streaming()) if (_handles[i].streaming())
_handles[i].fadeDown(); _handles[i].fadeDown();
} }
} // End of namespace Sword1

View file

@ -28,13 +28,15 @@
#include "sound/audiostream.h" #include "sound/audiostream.h"
#include "sound/rate.h" #include "sound/rate.h"
class SoundMixer;
namespace Sword1 {
#define TOTAL_TUNES 270 #define TOTAL_TUNES 270
#define WAVEHEADERSIZE 0x2C #define WAVEHEADERSIZE 0x2C
class SoundMixer; class MusicHandle : public AudioStream {
class SwordMusicHandle : public AudioStream {
private: private:
File _file; File _file;
bool _looping; bool _looping;
@ -43,7 +45,7 @@ private:
int _rate; int _rate;
bool _stereo; bool _stereo;
public: public:
SwordMusicHandle() : _looping(false), _fading(0) {} MusicHandle() : _looping(false), _fading(0) {}
virtual int readBuffer(int16 *buffer, const int numSamples); virtual int readBuffer(int16 *buffer, const int numSamples);
bool play(const char *filename, bool loop); bool play(const char *filename, bool loop);
void stop(); void stop();
@ -57,17 +59,17 @@ public:
int getRate() const { return _rate; } int getRate() const { return _rate; }
}; };
class SwordMusic { class Music {
public: public:
SwordMusic(OSystem *system, SoundMixer *pMixer); Music(OSystem *system, SoundMixer *pMixer);
~SwordMusic(); ~Music();
void startMusic(int32 tuneId, int32 loopFlag); void startMusic(int32 tuneId, int32 loopFlag);
void fadeDown(); void fadeDown();
void setVolume(uint8 volL, uint8 volR); void setVolume(uint8 volL, uint8 volR);
void giveVolume(uint8 *volL, uint8 *volR); void giveVolume(uint8 *volL, uint8 *volR);
private: private:
st_volume_t _volumeL, _volumeR; st_volume_t _volumeL, _volumeR;
SwordMusicHandle _handles[2]; MusicHandle _handles[2];
RateConverter *_converter[2]; RateConverter *_converter[2];
OSystem *_system; OSystem *_system;
SoundMixer *_mixer; SoundMixer *_mixer;
@ -77,4 +79,6 @@ private:
static const char _tuneList[TOTAL_TUNES][8]; // in staticres.cpp static const char _tuneList[TOTAL_TUNES][8]; // in staticres.cpp
}; };
} // End of namespace Sword1
#endif // BSMUSIC_H #endif // BSMUSIC_H

View file

@ -24,6 +24,8 @@
#include "scummsys.h" #include "scummsys.h"
namespace Sword1 {
#define O_TOTAL_EVENTS 5 #define O_TOTAL_EVENTS 5
#define O_WALKANIM_SIZE 600 //max number of nodes in router output #define O_WALKANIM_SIZE 600 //max number of nodes in router output
#define O_GRID_SIZE 200 #define O_GRID_SIZE 200
@ -56,7 +58,7 @@ struct WalkData {
int32 dir; int32 dir;
} GCC_PACK; // size = 5*int32 = 20 bytes } GCC_PACK; // size = 5*int32 = 20 bytes
struct BsObject { struct Object {
int32 o_type; // 0 broad description of type - object, floor, etc. int32 o_type; // 0 broad description of type - object, floor, etc.
int32 o_status; // 4 bit flags for logic, graphics, mouse, etc. int32 o_status; // 4 bit flags for logic, graphics, mouse, etc.
int32 o_logic; // 8 logic type int32 o_logic; // 8 logic type
@ -115,11 +117,13 @@ struct BsObject {
}; };
struct CollisionData { struct CollisionData {
BsObject *compact; Object *compact;
int32 w[24]; int32 w[24];
int32 h[24]; int32 h[24];
WalkData route[24]; WalkData route[24];
}; };
} // End of namespace Sword1
#endif //BSOBJECT_H #endif //BSOBJECT_H

View file

@ -27,6 +27,8 @@
#include "swordres.h" #include "swordres.h"
#include "sword1.h" #include "sword1.h"
namespace Sword1 {
ObjectMan::ObjectMan(ResMan *pResourceMan) { ObjectMan::ObjectMan(ResMan *pResourceMan) {
_resMan = pResourceMan; _resMan = pResourceMan;
} }
@ -117,13 +119,13 @@ uint32 ObjectMan::lastTextNumber(int section) {
return result; return result;
} }
BsObject *ObjectMan::fetchObject(uint32 id) { Object *ObjectMan::fetchObject(uint32 id) {
uint8 *addr = _cptData[id / ITM_PER_SEC]; uint8 *addr = _cptData[id / ITM_PER_SEC];
if (!addr) if (!addr)
error("fetchObject: section %d is not open!", id / ITM_PER_SEC); error("fetchObject: section %d is not open!", id / ITM_PER_SEC);
id &= ITM_ID; id &= ITM_ID;
// DON'T do endian conversion here. it's already done. // DON'T do endian conversion here. it's already done.
return (BsObject*)(addr + *(uint32*)(addr + (id + 1)*4)); return (Object*)(addr + *(uint32*)(addr + (id + 1)*4));
} }
uint32 ObjectMan::fetchNoObjects(int section) { uint32 ObjectMan::fetchNoObjects(int section) {
@ -152,3 +154,5 @@ void ObjectMan::loadLiveList(uint16 *src) {
void ObjectMan::saveLiveList(uint16 *dest) { void ObjectMan::saveLiveList(uint16 *dest) {
memcpy(dest, _liveList, TOTAL_SECTIONS * sizeof(uint16)); memcpy(dest, _liveList, TOTAL_SECTIONS * sizeof(uint16));
} }
} // End of namespace Sword1

View file

@ -28,13 +28,15 @@
#include "sworddefs.h" #include "sworddefs.h"
#include "object.h" #include "object.h"
namespace Sword1 {
class ObjectMan { class ObjectMan {
public: public:
ObjectMan(ResMan *pResourceMan); ObjectMan(ResMan *pResourceMan);
~ObjectMan(void); ~ObjectMan(void);
void initialize(void); void initialize(void);
BsObject *fetchObject(uint32 id); Object *fetchObject(uint32 id);
uint32 fetchNoObjects(int section); uint32 fetchNoObjects(int section);
bool sectionAlive(uint16 section); bool sectionAlive(uint16 section);
void megaEntering(uint16 section); void megaEntering(uint16 section);
@ -45,7 +47,7 @@ public:
void unlockText(uint32 textId); void unlockText(uint32 textId);
uint32 lastTextNumber(int section); uint32 lastTextNumber(int section);
void closeSection(uint32 screen); void closeSection(uint32 screen);
void saveLiveList(uint16 *dest); // for loading/saving void saveLiveList(uint16 *dest); // for loading/saving
void loadLiveList(uint16 *src); void loadLiveList(uint16 *src);
@ -57,5 +59,7 @@ private:
uint8 *_cptData[TOTAL_SECTIONS]; uint8 *_cptData[TOTAL_SECTIONS];
}; };
} // End of namespace Sword1
#endif //OBJECTMAN_H #endif //OBJECTMAN_H

View file

@ -21,8 +21,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "scummsys.h" #include "scummsys.h"
#include <stdio.h>
#include <stdlib.h>
#include "memman.h" #include "memman.h"
#include "resman.h" #include "resman.h"
#include "sworddefs.h" #include "sworddefs.h"
@ -30,6 +28,8 @@
#include "common/util.h" #include "common/util.h"
#include "swordres.h" #include "swordres.h"
namespace Sword1 {
#define MAX_PATH_LEN 260 #define MAX_PATH_LEN 260
ResMan::ResMan(const char *resFile, MemMan *pMemoMan) { ResMan::ResMan(const char *resFile, MemMan *pMemoMan) {
@ -48,27 +48,27 @@ void ResMan::loadCluDescript(const char *fileName) {
error("ResMan::loadCluDescript(): File %s not found!", fileName); error("ResMan::loadCluDescript(): File %s not found!", fileName);
_prj.noClu = resFile.readUint32LE(); _prj.noClu = resFile.readUint32LE();
_prj.clu = new BsClu*[_prj.noClu]; _prj.clu = new Clu*[_prj.noClu];
uint32 *cluIndex = (uint32*)malloc(_prj.noClu * 4); uint32 *cluIndex = (uint32*)malloc(_prj.noClu * 4);
resFile.read(cluIndex, _prj.noClu * 4); resFile.read(cluIndex, _prj.noClu * 4);
for (uint32 clusCnt = 0; clusCnt < _prj.noClu; clusCnt++) for (uint32 clusCnt = 0; clusCnt < _prj.noClu; clusCnt++)
if (cluIndex[clusCnt]) { if (cluIndex[clusCnt]) {
BsClu *cluster = _prj.clu[clusCnt] = new BsClu; Clu *cluster = _prj.clu[clusCnt] = new Clu;
resFile.read(cluster->label, MAX_LABEL_SIZE); resFile.read(cluster->label, MAX_LABEL_SIZE);
cluster->noGrp = resFile.readUint32LE(); cluster->noGrp = resFile.readUint32LE();
cluster->grp = new BsGrp*[cluster->noGrp]; cluster->grp = new Grp*[cluster->noGrp];
uint32 *grpIndex = (uint32*)malloc(cluster->noGrp * 4); uint32 *grpIndex = (uint32*)malloc(cluster->noGrp * 4);
resFile.read(grpIndex, cluster->noGrp * 4); resFile.read(grpIndex, cluster->noGrp * 4);
for (uint32 grpCnt = 0; grpCnt < cluster->noGrp; grpCnt++) for (uint32 grpCnt = 0; grpCnt < cluster->noGrp; grpCnt++)
if (grpIndex[grpCnt]) { if (grpIndex[grpCnt]) {
BsGrp *group = cluster->grp[grpCnt] = new BsGrp; Grp *group = cluster->grp[grpCnt] = new Grp;
group->noRes = resFile.readUint32LE(); group->noRes = resFile.readUint32LE();
group->resHandle = new BsMemHandle[group->noRes]; group->resHandle = new MemHandle[group->noRes];
group->offset = new uint32[group->noRes]; group->offset = new uint32[group->noRes];
group->length = new uint32[group->noRes]; group->length = new uint32[group->noRes];
uint32 *resIdIdx = (uint32*)malloc(group->noRes * 4); uint32 *resIdIdx = (uint32*)malloc(group->noRes * 4);
@ -101,9 +101,9 @@ void ResMan::loadCluDescript(const char *fileName) {
void ResMan::freeCluDescript(void) { void ResMan::freeCluDescript(void) {
for (uint32 clusCnt = 0; clusCnt < _prj.noClu; clusCnt++) for (uint32 clusCnt = 0; clusCnt < _prj.noClu; clusCnt++)
if (BsClu *cluster = _prj.clu[clusCnt]) { if (Clu *cluster = _prj.clu[clusCnt]) {
for (uint32 grpCnt = 0; grpCnt < cluster->noGrp; grpCnt++) for (uint32 grpCnt = 0; grpCnt < cluster->noGrp; grpCnt++)
if (BsGrp *group = cluster->grp[grpCnt]) { if (Grp *group = cluster->grp[grpCnt]) {
for (uint32 resCnt = 0; resCnt < group->noRes; resCnt++) for (uint32 resCnt = 0; resCnt < group->noRes; resCnt++)
_memMan->freeNow(group->resHandle + resCnt); _memMan->freeNow(group->resHandle + resCnt);
delete[] group->resHandle; delete[] group->resHandle;
@ -119,9 +119,9 @@ void ResMan::freeCluDescript(void) {
void ResMan::flush(void) { void ResMan::flush(void) {
for (uint32 clusCnt = 0; clusCnt < _prj.noClu; clusCnt++) for (uint32 clusCnt = 0; clusCnt < _prj.noClu; clusCnt++)
if (BsClu *cluster = _prj.clu[clusCnt]) if (Clu *cluster = _prj.clu[clusCnt])
for (uint32 grpCnt = 0; grpCnt < cluster->noGrp; grpCnt++) for (uint32 grpCnt = 0; grpCnt < cluster->noGrp; grpCnt++)
if (BsGrp *group = cluster->grp[grpCnt]) if (Grp *group = cluster->grp[grpCnt])
for (uint32 resCnt = 0; resCnt < group->noRes; resCnt++) for (uint32 resCnt = 0; resCnt < group->noRes; resCnt++)
if (group->resHandle[resCnt].cond != MEM_FREED) { if (group->resHandle[resCnt].cond != MEM_FREED) {
_memMan->setCondition(group->resHandle + resCnt, MEM_CAN_FREE); _memMan->setCondition(group->resHandle + resCnt, MEM_CAN_FREE);
@ -130,7 +130,7 @@ void ResMan::flush(void) {
} }
void *ResMan::fetchRes(uint32 id) { void *ResMan::fetchRes(uint32 id) {
BsMemHandle *memHandle = resHandle(id); MemHandle *memHandle = resHandle(id);
if (!memHandle->data) if (!memHandle->data)
error("fetchRes:: resource %d is not open!", id); error("fetchRes:: resource %d is not open!", id);
return memHandle->data; return memHandle->data;
@ -146,7 +146,7 @@ void ResMan::dumpRes(uint32 id) {
sprintf(outn, "DUMP%08X.BIN", id); sprintf(outn, "DUMP%08X.BIN", id);
FILE *outf = fopen( outn, "wb"); FILE *outf = fopen( outn, "wb");
resOpen(id); resOpen(id);
BsMemHandle *memHandle = resHandle(id); MemHandle *memHandle = resHandle(id);
fwrite(memHandle->data, 1, memHandle->size, outf); fwrite(memHandle->data, 1, memHandle->size, outf);
fclose(outf); fclose(outf);
resClose(id); resClose(id);
@ -157,7 +157,7 @@ Header *ResMan::lockScript(uint32 scrID) {
error("Script id %d not found.\n", scrID); error("Script id %d not found.\n", scrID);
scrID = _scriptList[scrID / ITM_PER_SEC]; scrID = _scriptList[scrID / ITM_PER_SEC];
#ifdef SCUMM_BIG_ENDIAN #ifdef SCUMM_BIG_ENDIAN
BsMemHandle *memHandle = resHandle(scrID); MemHandle *memHandle = resHandle(scrID);
if (memHandle->cond == MEM_FREED) if (memHandle->cond == MEM_FREED)
openScriptResourceBigEndian(scrID); openScriptResourceBigEndian(scrID);
else else
@ -174,7 +174,7 @@ void ResMan::unlockScript(uint32 scrID) {
void *ResMan::cptResOpen(uint32 id) { void *ResMan::cptResOpen(uint32 id) {
#ifdef SCUMM_BIG_ENDIAN #ifdef SCUMM_BIG_ENDIAN
BsMemHandle *memHandle = resHandle(id); MemHandle *memHandle = resHandle(id);
if (memHandle->cond == MEM_FREED) if (memHandle->cond == MEM_FREED)
openCptResourceBigEndian(id); openCptResourceBigEndian(id);
else else
@ -186,7 +186,7 @@ void *ResMan::cptResOpen(uint32 id) {
} }
void ResMan::resOpen(uint32 id) { // load resource ID into memory void ResMan::resOpen(uint32 id) { // load resource ID into memory
BsMemHandle *memHandle = resHandle(id); MemHandle *memHandle = resHandle(id);
if (memHandle->cond == MEM_FREED) { // memory has been freed if (memHandle->cond == MEM_FREED) { // memory has been freed
uint32 size = resLength(id); uint32 size = resLength(id);
_memMan->alloc(memHandle, size); _memMan->alloc(memHandle, size);
@ -206,7 +206,7 @@ void ResMan::resOpen(uint32 id) { // load resource ID into memory
} }
void ResMan::resClose(uint32 id) { void ResMan::resClose(uint32 id) {
BsMemHandle *handle = resHandle(id); MemHandle *handle = resHandle(id);
if (!handle->refCount) { if (!handle->refCount) {
warning("Resource Manager fail: unlocking object with refCount 0. Id: %d\n", id); warning("Resource Manager fail: unlocking object with refCount 0. Id: %d\n", id);
} else { } else {
@ -235,7 +235,7 @@ File *ResMan::openClusterFile(uint32 id) {
return clusFile; return clusFile;
} }
BsMemHandle *ResMan::resHandle(uint32 id) { MemHandle *ResMan::resHandle(uint32 id) {
if ((id >> 16) == 0x0405) if ((id >> 16) == 0x0405)
id = _srIdList[id & 0xFFFF]; id = _srIdList[id & 0xFFFF];
uint8 cluster = (uint8)((id >> 24) - 1); uint8 cluster = (uint8)((id >> 24) - 1);
@ -264,7 +264,7 @@ uint32 ResMan::resOffset(uint32 id) {
void ResMan::openCptResourceBigEndian(uint32 id) { void ResMan::openCptResourceBigEndian(uint32 id) {
resOpen(id); resOpen(id);
BsMemHandle *handle = resHandle(id); MemHandle *handle = resHandle(id);
uint32 totSize = handle->size; uint32 totSize = handle->size;
uint32 *data = (uint32*)((uint8*)handle->data + sizeof(Header)); uint32 *data = (uint32*)((uint8*)handle->data + sizeof(Header));
totSize -= sizeof(Header); totSize -= sizeof(Header);
@ -279,7 +279,7 @@ void ResMan::openCptResourceBigEndian(uint32 id) {
void ResMan::openScriptResourceBigEndian(uint32 id) { void ResMan::openScriptResourceBigEndian(uint32 id) {
resOpen(id); resOpen(id);
BsMemHandle *handle = resHandle(id); MemHandle *handle = resHandle(id);
// uint32 totSize = handle->size; // uint32 totSize = handle->size;
Header *head = (Header*)handle->data; Header *head = (Header*)handle->data;
head->comp_length = FROM_LE_32(head->comp_length); head->comp_length = FROM_LE_32(head->comp_length);
@ -327,3 +327,5 @@ uint32 ResMan::_srIdList[29] = { // the file numbers differ for the control pane
0x04050019, // SR_DEATHPANEL 0x04050019, // SR_DEATHPANEL
0, 0,
}; };
} // End of namespace Sword1

View file

@ -26,24 +26,26 @@
#include "file.h" #include "file.h"
#include "sworddefs.h" #include "sworddefs.h"
namespace Sword1 {
#define MAX_LABEL_SIZE (31+1) #define MAX_LABEL_SIZE (31+1)
struct BsGrp { struct Grp {
uint32 noRes; uint32 noRes;
BsMemHandle *resHandle; MemHandle *resHandle;
uint32 *offset; uint32 *offset;
uint32 *length; uint32 *length;
}; };
struct BsClu { struct Clu {
char label[MAX_LABEL_SIZE]; char label[MAX_LABEL_SIZE];
uint32 noGrp; uint32 noGrp;
BsGrp **grp; Grp **grp;
}; };
struct BsPrj { struct Prj {
uint32 noClu; uint32 noClu;
BsClu **clu; Clu **clu;
}; };
class ResMan { class ResMan {
@ -63,7 +65,7 @@ public:
private: private:
uint32 filesInGroup(uint32 id); uint32 filesInGroup(uint32 id);
uint32 resLength(uint32 id); uint32 resLength(uint32 id);
BsMemHandle *resHandle(uint32 id); MemHandle *resHandle(uint32 id);
uint32 resOffset(uint32 id); uint32 resOffset(uint32 id);
void openCptResourceBigEndian(uint32 id); void openCptResourceBigEndian(uint32 id);
void openScriptResourceBigEndian(uint32 id); void openScriptResourceBigEndian(uint32 id);
@ -71,10 +73,12 @@ private:
File *openClusterFile(uint32 id); File *openClusterFile(uint32 id);
void loadCluDescript(const char *fileName); void loadCluDescript(const char *fileName);
void freeCluDescript(void); void freeCluDescript(void);
BsPrj _prj; Prj _prj;
MemMan *_memMan; MemMan *_memMan;
static const uint32 _scriptList[TOTAL_SECTIONS]; //a table of resource tags static const uint32 _scriptList[TOTAL_SECTIONS]; //a table of resource tags
static uint32 _srIdList[29]; static uint32 _srIdList[29];
}; };
} // End of namespace Sword1
#endif //RESMAN_H #endif //RESMAN_H

View file

@ -28,6 +28,8 @@
#include "objectman.h" #include "objectman.h"
#include "resman.h" #include "resman.h"
namespace Sword1 {
/**************************************************************************** /****************************************************************************
* JROUTER.C polygon router with modular walks * JROUTER.C polygon router with modular walks
* using a tree of modules * using a tree of modules
@ -61,37 +63,6 @@
* *
****************************************************************************/ ****************************************************************************/
/*
* Include Files
*/
/*#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <io.h>
#include <dos.h>
#include <string.h>
#include "coredata.h"
#include "utypes.h"
#include "header.h"
#include "object.h"
#include "varnames.h"
#include "jrouter.h"
#include "svga.h"
#include "protocol.h"
#include "memman.h"
#include "resman.h"
#include "tdebug.h"
#include "blit.h"
#include "line.h"
#include "pc.h"
#include "vblank.h"*/
//#define MAX_FRAMES_PER_CHAR 128
#define NO_DIRECTIONS 8 #define NO_DIRECTIONS 8
#define SLOW_IN 3 #define SLOW_IN 3
#define SLOW_OUT 7 #define SLOW_OUT 7
@ -99,7 +70,7 @@
//#define PLOT_PATHS 1 //#define PLOT_PATHS 1
#undef PLOT_PATHS #undef PLOT_PATHS
SwordRouter::SwordRouter(ObjectMan *pObjMan, ResMan *pResMan) { Router::Router(ObjectMan *pObjMan, ResMan *pResMan) {
_objMan = pObjMan; _objMan = pObjMan;
_resMan = pResMan; _resMan = pResMan;
_numExtraBars = _numExtraNodes = 0; _numExtraBars = _numExtraNodes = 0;
@ -108,21 +79,11 @@ SwordRouter::SwordRouter(ObjectMan *pObjMan, ResMan *pResMan) {
diagonalx = diagonaly = 0; diagonalx = diagonaly = 0;
} }
/*
*
*/
/* /*
* CODE * CODE
*/ */
// ************************************************************************** int32 Router::routeFinder(int32 id, Object *megaObject, int32 x, int32 y, int32 dir)
// **************************************************************************
// **************************************************************************
// **************************************************************************
// **************************************************************************
int32 SwordRouter::routeFinder(int32 id, BsObject *megaObject, int32 x, int32 y, int32 dir)
{ {
/**************************************************************************** /****************************************************************************
* RouteFinder.C polygon router with modular walks * RouteFinder.C polygon router with modular walks
@ -242,14 +203,11 @@ int32 SwordRouter::routeFinder(int32 id, BsObject *megaObject, int32 x, int32 y,
return routeFlag; // send back null route return routeFlag; // send back null route
} }
/******************************************************************************* // ****************************************************************************
******************************************************************************* // * GET A ROUTE
* GET A ROUTE // ****************************************************************************
*******************************************************************************
*******************************************************************************/
int32 Router::GetRoute()
int32 SwordRouter::GetRoute()
{ {
/**************************************************************************** /****************************************************************************
* GetRoute.C extract a path from walk grid * GetRoute.C extract a path from walk grid
@ -303,15 +261,11 @@ int32 SwordRouter::GetRoute()
return routeGot; return routeGot;
} }
// ****************************************************************************
// * THE SLIDY PATH ROUTINES
// ****************************************************************************
/******************************************************************************* int32 Router::SmoothestPath()
*******************************************************************************
* THE SLIDY PATH ROUTINES
*******************************************************************************
*******************************************************************************/
int32 SwordRouter::SmoothestPath()
{ {
/* /*
* This is the second big part of the route finder and the the only bit that tries to be clever * This is the second big part of the route finder and the the only bit that tries to be clever
@ -506,7 +460,7 @@ int32 SwordRouter::SmoothestPath()
int32 SwordRouter::SmoothCheck(int32 best, int32 p, int32 dirS, int32 dirD) int32 Router::SmoothCheck(int32 best, int32 p, int32 dirS, int32 dirD)
/**************************************************************************** /****************************************************************************
* Slip sliding away * Slip sliding away
* This path checker checks to see if a walk that exactly follows the path * This path checker checks to see if a walk that exactly follows the path
@ -667,7 +621,7 @@ int32 SwordRouter::SmoothCheck(int32 best, int32 p, int32 dirS, int32 dirD)
return tempK; return tempK;
} }
int32 SwordRouter::SlidyPath() int32 Router::SlidyPath()
{ {
/**************************************************************************** /****************************************************************************
* SlidyPath creates a path based on part steps with no sliding to get * SlidyPath creates a path based on part steps with no sliding to get
@ -734,7 +688,7 @@ int32 SwordRouter::SlidyPath()
} }
void SwordRouter::SlidyWalkAnimator(WalkData *walkAnim) void Router::SlidyWalkAnimator(WalkData *walkAnim)
/**************************************************************************** /****************************************************************************
* Skidding every where HardWalk creates an animation that exactly fits the * Skidding every where HardWalk creates an animation that exactly fits the
* smoothPath and uses foot slipping to fit whole steps into the route * smoothPath and uses foot slipping to fit whole steps into the route
@ -1143,14 +1097,11 @@ void SwordRouter::SlidyWalkAnimator(WalkData *walkAnim)
return; return;
} }
// ****************************************************************************
// * THE SOLID PATH ROUTINES
// ****************************************************************************
/******************************************************************************* int32 Router::SolidPath()
*******************************************************************************
* THE SOLID PATH ROUTINES
*******************************************************************************
*******************************************************************************/
int32 SwordRouter::SolidPath()
{ {
/**************************************************************************** /****************************************************************************
* SolidPath creates a path based on whole steps with no sliding to get * SolidPath creates a path based on whole steps with no sliding to get
@ -1216,7 +1167,7 @@ int32 SwordRouter::SolidPath()
} }
int32 SwordRouter::SolidWalkAnimator(WalkData *walkAnim) int32 Router::SolidWalkAnimator(WalkData *walkAnim)
{ {
/**************************************************************************** /****************************************************************************
* SolidWalk creates an animation based on whole steps with no sliding to get * SolidWalk creates an animation based on whole steps with no sliding to get
@ -1631,25 +1582,21 @@ int32 SwordRouter::SolidWalkAnimator(WalkData *walkAnim)
return p; return p;
} }
// ****************************************************************************
// * THE SCAN ROUTINES
// ****************************************************************************
/******************************************************************************* int32 Router::Scan(int32 level)
******************************************************************************* /******************************************************************************
* THE SCAN ROUTINES
*******************************************************************************
*******************************************************************************/
int32 SwordRouter::Scan(int32 level)
/*******************************************************************************
* Called successively from RouteFinder until no more changes take place in the * Called successively from RouteFinder until no more changes take place in the
* grid array ie he best path has been found * grid array ie he best path has been found
* *
* Scans through every point in the node array and checks if there is a route * Scans through every point in the node array and checks if there is a route
* between each point and if this route gives a new route. * between each point and if this route gives a new route.
* *
* This routine could probably halve its processing time if it doubled up on the * This routine could probably halve its processing time if it doubled up on
* checks after each route check * the checks after each route check
* *****************************************************************************/
*******************************************************************************/
{ {
int32 i; int32 i;
int32 k; int32 k;
@ -1708,8 +1655,8 @@ int32 SwordRouter::Scan(int32 level)
} }
int32 SwordRouter::NewCheck(int32 status, int32 x1 , int32 y1 , int32 x2 ,int32 y2) int32 Router::NewCheck(int32 status, int32 x1 , int32 y1 , int32 x2 ,int32 y2)
/******************************************************************************* /******************************************************************************
* NewCheck routine checks if the route between two points can be achieved * NewCheck routine checks if the route between two points can be achieved
* without crossing any of the bars in the Bars array. * without crossing any of the bars in the Bars array.
* *
@ -1719,7 +1666,7 @@ int32 SwordRouter::NewCheck(int32 status, int32 x1 , int32 y1 , int32 x2 ,int32
* Note distance doesnt take account of shrinking ??? * Note distance doesnt take account of shrinking ???
* *
* Note Bars array must be properly calculated ie min max dx dy co * Note Bars array must be properly calculated ie min max dx dy co
*******************************************************************************/ *****************************************************************************/
{ {
int32 dx; int32 dx;
int32 dy; int32 dy;
@ -1989,15 +1936,11 @@ int32 SwordRouter::NewCheck(int32 status, int32 x1 , int32 y1 , int32 x2 ,int32
return status; return status;
} }
// ****************************************************************************
// * CHECK ROUTINES
// ****************************************************************************
/******************************************************************************* int32 Router::Check(int32 x1 , int32 y1 , int32 x2 ,int32 y2)
*******************************************************************************
* CHECK ROUTINES
*******************************************************************************
*******************************************************************************/
int32 SwordRouter::Check(int32 x1 , int32 y1 , int32 x2 ,int32 y2)
{ {
//call the fastest line check for the given line //call the fastest line check for the given line
//returns 1 if line didn't cross any bars //returns 1 if line didn't cross any bars
@ -2024,7 +1967,7 @@ int32 SwordRouter::Check(int32 x1 , int32 y1 , int32 x2 ,int32 y2)
} }
int32 SwordRouter::LineCheck(int32 x1 , int32 y1 , int32 x2 ,int32 y2) int32 Router::LineCheck(int32 x1 , int32 y1 , int32 x2 ,int32 y2)
{ {
int32 dirx; int32 dirx;
int32 diry; int32 diry;
@ -2108,8 +2051,7 @@ int32 SwordRouter::LineCheck(int32 x1 , int32 y1 , int32 x2 ,int32 y2)
return linesCrossed; return linesCrossed;
} }
int32 Router::HorizCheck(int32 x1 , int32 y , int32 x2)
int32 SwordRouter::HorizCheck(int32 x1 , int32 y , int32 x2)
{ {
int32 dy; int32 dy;
int32 i; int32 i;
@ -2164,7 +2106,7 @@ int32 SwordRouter::HorizCheck(int32 x1 , int32 y , int32 x2)
} }
int32 SwordRouter::VertCheck(int32 x, int32 y1, int32 y2) int32 Router::VertCheck(int32 x, int32 y1, int32 y2)
{ {
int32 dx; int32 dx;
int32 i; int32 i;
@ -2216,9 +2158,7 @@ int32 SwordRouter::VertCheck(int32 x, int32 y1, int32 y2)
return linesCrossed; return linesCrossed;
} }
int32 SwordRouter::CheckTarget(int32 x , int32 y) int32 Router::CheckTarget(int32 x , int32 y)
/*******************************************************************************
*******************************************************************************/
{ {
int32 dx; int32 dx;
int32 dy; int32 dy;
@ -2294,15 +2234,11 @@ int32 SwordRouter::CheckTarget(int32 x , int32 y)
return onLine; return onLine;
} }
/******************************************************************************* // ****************************************************************************
******************************************************************************* // * THE SETUP ROUTINES
* THE SETUP ROUTINES // ****************************************************************************
*******************************************************************************
*******************************************************************************/
int32 Router::LoadWalkResources(Object *megaObject, int32 x, int32 y, int32 dir)
int32 SwordRouter::LoadWalkResources(BsObject *megaObject, int32 x, int32 y, int32 dir)
{ {
WalkGridHeader floorHeader; WalkGridHeader floorHeader;
int32 i; int32 i;
@ -2312,16 +2248,13 @@ int32 SwordRouter::LoadWalkResources(BsObject *megaObject, int32 x, int32 y, int
int32 floorId; int32 floorId;
int32 walkGridResourceId; int32 walkGridResourceId;
BsObject *floorObject; Object *floorObject;
int32 cnt; int32 cnt;
uint32 cntu; uint32 cntu;
// load in floor grid for current mega // load in floor grid for current mega
floorId = megaObject->o_place; floorId = megaObject->o_place;
//floorObject = (object *) Lock_object(floorId); //floorObject = (object *) Lock_object(floorId);
@ -2415,7 +2348,6 @@ int32 SwordRouter::LoadWalkResources(BsObject *megaObject, int32 x, int32 y, int
nnodes += _numExtraNodes; nnodes += _numExtraNodes;
} }
// copy the mega structure into the local variables for use in all subroutines // copy the mega structure into the local variables for use in all subroutines
startX = megaObject->o_xcoord; startX = megaObject->o_xcoord;
@ -2471,7 +2403,6 @@ int32 SwordRouter::LoadWalkResources(BsObject *megaObject, int32 x, int32 y, int
// mega data ready // mega data ready
// finish setting grid by putting mega node at begining // finish setting grid by putting mega node at begining
// and target node at end and reset current values // and target node at end and reset current values
node[0].x = startX; node[0].x = startX;
@ -2497,14 +2428,11 @@ int32 SwordRouter::LoadWalkResources(BsObject *megaObject, int32 x, int32 y, int
return 1; return 1;
} }
// ****************************************************************************
// * THE ROUTE EXTRACTOR
// ****************************************************************************
/******************************************************************************* void Router::ExtractRoute()
*******************************************************************************
* THE ROUTE EXTRACTOR
*******************************************************************************
*******************************************************************************/
void SwordRouter::ExtractRoute()
/**************************************************************************** /****************************************************************************
* ExtractRoute gets route from the node data after a full scan, route is * ExtractRoute gets route from the node data after a full scan, route is
* written with just the basic way points and direction options for heading * written with just the basic way points and direction options for heading
@ -2611,13 +2539,13 @@ void SwordRouter::ExtractRoute()
#define screen_ad NULL #define screen_ad NULL
#define pixel_size_y 1 #define pixel_size_y 1
#define true_pixel_size_x 1 #define true_pixel_size_x 1
void SwordRouter::RouteLine(int32 x1,int32 y1,int32 x2,int32 y2 ,int32 colour) void Router::RouteLine(int32 x1,int32 y1,int32 x2,int32 y2 ,int32 colour)
{ {
BresenhamLine(x1-128, y1-128, x2-128, y2-128, (uint8*)screen_ad, true_pixel_size_x, pixel_size_y, colour); BresenhamLine(x1-128, y1-128, x2-128, y2-128, (uint8*)screen_ad, true_pixel_size_x, pixel_size_y, colour);
return; return;
} }
void SwordRouter::BresenhamLine(int32 x1,int32 y1,int32 x2,int32 y2, uint8 *screen, int32 width, int32 height, int32 colour) { void Router::BresenhamLine(int32 x1,int32 y1,int32 x2,int32 y2, uint8 *screen, int32 width, int32 height, int32 colour) {
} }
@ -2663,13 +2591,15 @@ int whatTarget(int32 startX, int32 startY, int32 destX, int32 destY) {
return tar_dir; return tar_dir;
} }
void SwordRouter::resetExtraData(void) { void Router::resetExtraData(void) {
_numExtraBars = _numExtraNodes = 0; _numExtraBars = _numExtraNodes = 0;
} }
void SwordRouter::setPlayerTarget(int32 x, int32 y, int32 dir, int32 stance) { void Router::setPlayerTarget(int32 x, int32 y, int32 dir, int32 stance) {
_playerTargetX = x; _playerTargetX = x;
_playerTargetY = y; _playerTargetY = y;
_playerTargetDir = dir; _playerTargetDir = dir;
_playerTargetStance = stance; _playerTargetStance = stance;
} }
} // End of namespace Sword1

View file

@ -25,6 +25,8 @@
#include "scummsys.h" #include "scummsys.h"
#include "object.h" #include "object.h"
namespace Sword1 {
#define EXTRA_GRID_SIZE 20 #define EXTRA_GRID_SIZE 20
#define O_GRID_SIZE 200 #define O_GRID_SIZE 200
@ -87,19 +89,19 @@ struct PathData {
class ObjectMan; class ObjectMan;
class ResMan; class ResMan;
class SwordScreen; class Screen;
extern int whatTarget(int32 startX, int32 startY, int32 destX, int32 destY); extern int whatTarget(int32 startX, int32 startY, int32 destX, int32 destY);
class SwordRouter { class Router {
public: public:
SwordRouter(ObjectMan *pObjMan, ResMan *pResMan); Router(ObjectMan *pObjMan, ResMan *pResMan);
~SwordRouter(void); ~Router(void);
int32 routeFinder(int32 id, BsObject *mega, int32 x, int32 y, int32 dir); int32 routeFinder(int32 id, Object *mega, int32 x, int32 y, int32 dir);
void setPlayerTarget(int32 x, int32 y, int32 dir, int32 stance); void setPlayerTarget(int32 x, int32 y, int32 dir, int32 stance);
void resetExtraData(void); void resetExtraData(void);
// these should be private but are read by SwordScreen for debugging: // these should be private but are read by Screen for debugging:
BarData bars[O_GRID_SIZE+EXTRA_GRID_SIZE]; BarData bars[O_GRID_SIZE+EXTRA_GRID_SIZE];
NodeData node[O_GRID_SIZE+EXTRA_GRID_SIZE]; NodeData node[O_GRID_SIZE+EXTRA_GRID_SIZE];
int32 nbars, nnodes; int32 nbars, nnodes;
@ -148,7 +150,7 @@ private:
int32 slowInFrames, slowOutFrames; int32 slowInFrames, slowOutFrames;
int32 LoadWalkResources(BsObject *mega, int32 x, int32 y, int32 targetDir); int32 LoadWalkResources(Object *mega, int32 x, int32 y, int32 targetDir);
int32 GetRoute(void); int32 GetRoute(void);
int32 CheckTarget(int32 x, int32 y); int32 CheckTarget(int32 x, int32 y);
@ -173,4 +175,6 @@ private:
void BresenhamLine(int32 x1,int32 y1,int32 x2,int32 y2, uint8 *screen, int32 width, int32 height, int32 colour); void BresenhamLine(int32 x1,int32 y1,int32 x2,int32 y2, uint8 *screen, int32 width, int32 height, int32 colour);
}; };
} // End of namespace Sword1
#endif //BSROUTER_H #endif //BSROUTER_H

View file

@ -32,12 +32,14 @@
#include "menu.h" #include "menu.h"
#include "sword1.h" #include "sword1.h"
namespace Sword1 {
#define SCROLL_FRACTION 16 #define SCROLL_FRACTION 16
#define MAX_SCROLL_DISTANCE 8 #define MAX_SCROLL_DISTANCE 8
#define FADE_UP 1 #define FADE_UP 1
#define FADE_DOWN -1 #define FADE_DOWN -1
SwordScreen::SwordScreen(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) { Screen::Screen(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) {
_system = system; _system = system;
_resMan = pResMan; _resMan = pResMan;
_objMan = pObjMan; _objMan = pObjMan;
@ -46,51 +48,51 @@ SwordScreen::SwordScreen(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan) {
_fadingStep = 0; _fadingStep = 0;
} }
void SwordScreen::useTextManager(SwordText *pTextMan) { void Screen::useTextManager(Text *pTextMan) {
_textMan = pTextMan; _textMan = pTextMan;
} }
int32 SwordScreen::inRange(int32 a, int32 b, int32 c) { // return b(!) so that: a <= b <= c int32 Screen::inRange(int32 a, int32 b, int32 c) { // return b(!) so that: a <= b <= c
return (a > b) ? (a) : ((b < c) ? b : c); return (a > b) ? (a) : ((b < c) ? b : c);
} }
void SwordScreen::setScrolling(int16 offsetX, int16 offsetY) { void Screen::setScrolling(int16 offsetX, int16 offsetY) {
if (!SwordLogic::_scriptVars[SCROLL_FLAG]) if (!Logic::_scriptVars[SCROLL_FLAG])
return ; // screen is smaller than 640x400 => no need for scrolling return ; // screen is smaller than 640x400 => no need for scrolling
offsetX = inRange(0, offsetX, SwordLogic::_scriptVars[MAX_SCROLL_OFFSET_X]); offsetX = inRange(0, offsetX, Logic::_scriptVars[MAX_SCROLL_OFFSET_X]);
offsetY = inRange(0, offsetY, SwordLogic::_scriptVars[MAX_SCROLL_OFFSET_Y]); offsetY = inRange(0, offsetY, Logic::_scriptVars[MAX_SCROLL_OFFSET_Y]);
if (SwordLogic::_scriptVars[SCROLL_FLAG] == 2) { // first time on this screen - need absolute scroll immediately! if (Logic::_scriptVars[SCROLL_FLAG] == 2) { // first time on this screen - need absolute scroll immediately!
_oldScrollX = SwordLogic::_scriptVars[SCROLL_OFFSET_X] = (uint32)offsetX; _oldScrollX = Logic::_scriptVars[SCROLL_OFFSET_X] = (uint32)offsetX;
_oldScrollY = SwordLogic::_scriptVars[SCROLL_OFFSET_Y] = (uint32)offsetY; _oldScrollY = Logic::_scriptVars[SCROLL_OFFSET_Y] = (uint32)offsetY;
SwordLogic::_scriptVars[SCROLL_FLAG] = 1; Logic::_scriptVars[SCROLL_FLAG] = 1;
_fullRefresh = true; _fullRefresh = true;
} else if (SwordLogic::_scriptVars[SCROLL_FLAG] == 1) { } else if (Logic::_scriptVars[SCROLL_FLAG] == 1) {
_oldScrollX = SwordLogic::_scriptVars[SCROLL_OFFSET_X]; _oldScrollX = Logic::_scriptVars[SCROLL_OFFSET_X];
_oldScrollY = SwordLogic::_scriptVars[SCROLL_OFFSET_Y]; _oldScrollY = Logic::_scriptVars[SCROLL_OFFSET_Y];
int32 distX = inRange(-MAX_SCROLL_DISTANCE, _oldScrollX - offsetX, MAX_SCROLL_DISTANCE); int32 distX = inRange(-MAX_SCROLL_DISTANCE, _oldScrollX - offsetX, MAX_SCROLL_DISTANCE);
int32 distY = inRange(-MAX_SCROLL_DISTANCE, _oldScrollY - offsetY, MAX_SCROLL_DISTANCE); int32 distY = inRange(-MAX_SCROLL_DISTANCE, _oldScrollY - offsetY, MAX_SCROLL_DISTANCE);
if ((distX != 0) || (distY != 0)) if ((distX != 0) || (distY != 0))
_fullRefresh = true; _fullRefresh = true;
SwordLogic::_scriptVars[SCROLL_OFFSET_X] -= distX; Logic::_scriptVars[SCROLL_OFFSET_X] -= distX;
SwordLogic::_scriptVars[SCROLL_OFFSET_Y] -= distY; Logic::_scriptVars[SCROLL_OFFSET_Y] -= distY;
} }
} }
void SwordScreen::fadeDownPalette(void) { void Screen::fadeDownPalette(void) {
if (!_isBlack) { // don't fade down twice if (!_isBlack) { // don't fade down twice
_fadingStep = 15; _fadingStep = 15;
_fadingDirection = FADE_DOWN; _fadingDirection = FADE_DOWN;
} }
} }
void SwordScreen::fadeUpPalette(void) { void Screen::fadeUpPalette(void) {
_fadingStep = 1; _fadingStep = 1;
_fadingDirection = FADE_UP; _fadingDirection = FADE_UP;
} }
void SwordScreen::fnSetPalette(uint8 start, uint16 length, uint32 id, bool fadeUp) { void Screen::fnSetPalette(uint8 start, uint16 length, uint32 id, bool fadeUp) {
uint8 *palData = (uint8*)_resMan->openFetchRes(id); uint8 *palData = (uint8*)_resMan->openFetchRes(id);
if (start == 0) // force color 0 to black if (start == 0) // force color 0 to black
palData[0] = palData[1] = palData[2] = 0; palData[0] = palData[1] = palData[2] = 0;
@ -110,45 +112,45 @@ void SwordScreen::fnSetPalette(uint8 start, uint16 length, uint32 id, bool fadeU
_system->set_palette(_targetPalette + 4 * start, start, length); _system->set_palette(_targetPalette + 4 * start, start, length);
} }
void SwordScreen::fullRefresh(void) { void Screen::fullRefresh(void) {
_fullRefresh = true; _fullRefresh = true;
_system->set_palette(_targetPalette, 0, 256); _system->set_palette(_targetPalette, 0, 256);
} }
bool SwordScreen::stillFading(void) { bool Screen::stillFading(void) {
return (_fadingStep != 0); return (_fadingStep != 0);
} }
bool SwordScreen::showScrollFrame(void) { bool Screen::showScrollFrame(void) {
if ((!_fullRefresh) || SwordLogic::_scriptVars[NEW_PALETTE] || (!SwordLogic::_scriptVars[SCROLL_FLAG])) if ((!_fullRefresh) || Logic::_scriptVars[NEW_PALETTE] || (!Logic::_scriptVars[SCROLL_FLAG]))
return false; // don't draw an additional frame if we aren't scrolling or have to change the palette return false; // don't draw an additional frame if we aren't scrolling or have to change the palette
if ((_oldScrollX == SwordLogic::_scriptVars[SCROLL_OFFSET_X]) && if ((_oldScrollX == Logic::_scriptVars[SCROLL_OFFSET_X]) &&
(_oldScrollY == SwordLogic::_scriptVars[SCROLL_OFFSET_Y])) (_oldScrollY == Logic::_scriptVars[SCROLL_OFFSET_Y]))
return false; // check again if we *really* are scrolling. return false; // check again if we *really* are scrolling.
uint16 avgScrlX = (uint16)(_oldScrollX + SwordLogic::_scriptVars[SCROLL_OFFSET_X]) / 2; uint16 avgScrlX = (uint16)(_oldScrollX + Logic::_scriptVars[SCROLL_OFFSET_X]) / 2;
uint16 avgScrlY = (uint16)(_oldScrollY + SwordLogic::_scriptVars[SCROLL_OFFSET_Y]) / 2; uint16 avgScrlY = (uint16)(_oldScrollY + Logic::_scriptVars[SCROLL_OFFSET_Y]) / 2;
_system->copy_rect(_screenBuf + avgScrlY * _scrnSizeX + avgScrlX, _scrnSizeX, 0, 40, SCREEN_WIDTH, SCREEN_DEPTH); _system->copy_rect(_screenBuf + avgScrlY * _scrnSizeX + avgScrlX, _scrnSizeX, 0, 40, SCREEN_WIDTH, SCREEN_DEPTH);
_system->update_screen(); _system->update_screen();
return true; return true;
} }
void SwordScreen::updateScreen(void) { void Screen::updateScreen(void) {
if (SwordLogic::_scriptVars[NEW_PALETTE]) { if (Logic::_scriptVars[NEW_PALETTE]) {
_fadingStep = 1; _fadingStep = 1;
_fadingDirection = FADE_UP; _fadingDirection = FADE_UP;
fnSetPalette(0, 184, _roomDefTable[_currentScreen].palettes[0], true); fnSetPalette(0, 184, _roomDefTable[_currentScreen].palettes[0], true);
fnSetPalette(184, 72, _roomDefTable[_currentScreen].palettes[1], true); fnSetPalette(184, 72, _roomDefTable[_currentScreen].palettes[1], true);
SwordLogic::_scriptVars[NEW_PALETTE] = 0; Logic::_scriptVars[NEW_PALETTE] = 0;
} }
if (_fadingStep) { if (_fadingStep) {
fadePalette(); fadePalette();
_system->set_palette(_currentPalette, 0, 256); _system->set_palette(_currentPalette, 0, 256);
} }
uint16 scrlX = (uint16)SwordLogic::_scriptVars[SCROLL_OFFSET_X]; uint16 scrlX = (uint16)Logic::_scriptVars[SCROLL_OFFSET_X];
uint16 scrlY = (uint16)SwordLogic::_scriptVars[SCROLL_OFFSET_Y]; uint16 scrlY = (uint16)Logic::_scriptVars[SCROLL_OFFSET_Y];
if (_fullRefresh) { if (_fullRefresh) {
_fullRefresh = false; _fullRefresh = false;
uint16 copyWidth = SCREEN_WIDTH; uint16 copyWidth = SCREEN_WIDTH;
@ -241,7 +243,7 @@ void SwordScreen::updateScreen(void) {
_system->update_screen(); _system->update_screen();
} }
void SwordScreen::newScreen(uint32 screen) { void Screen::newScreen(uint32 screen) {
uint8 cnt; uint8 cnt;
// set sizes and scrolling, initialize/load screengrid, force screen refresh // set sizes and scrolling, initialize/load screengrid, force screen refresh
_currentScreen = screen; _currentScreen = screen;
@ -252,15 +254,15 @@ void SwordScreen::newScreen(uint32 screen) {
if ((_scrnSizeX % SCRNGRID_X) || (_scrnSizeY % SCRNGRID_Y)) if ((_scrnSizeX % SCRNGRID_X) || (_scrnSizeY % SCRNGRID_Y))
error("Illegal screensize: %d: %d/%d", screen, _scrnSizeX, _scrnSizeY); error("Illegal screensize: %d: %d/%d", screen, _scrnSizeX, _scrnSizeY);
if ((_scrnSizeX > SCREEN_WIDTH) || (_scrnSizeY > SCREEN_DEPTH)) { if ((_scrnSizeX > SCREEN_WIDTH) || (_scrnSizeY > SCREEN_DEPTH)) {
SwordLogic::_scriptVars[SCROLL_FLAG] = 2; Logic::_scriptVars[SCROLL_FLAG] = 2;
SwordLogic::_scriptVars[MAX_SCROLL_OFFSET_X] = _scrnSizeX - SCREEN_WIDTH; Logic::_scriptVars[MAX_SCROLL_OFFSET_X] = _scrnSizeX - SCREEN_WIDTH;
SwordLogic::_scriptVars[MAX_SCROLL_OFFSET_Y] = _scrnSizeY - SCREEN_DEPTH; Logic::_scriptVars[MAX_SCROLL_OFFSET_Y] = _scrnSizeY - SCREEN_DEPTH;
} else { } else {
SwordLogic::_scriptVars[SCROLL_FLAG] = 0; Logic::_scriptVars[SCROLL_FLAG] = 0;
SwordLogic::_scriptVars[MAX_SCROLL_OFFSET_X] = 0; Logic::_scriptVars[MAX_SCROLL_OFFSET_X] = 0;
SwordLogic::_scriptVars[MAX_SCROLL_OFFSET_Y] = 0; Logic::_scriptVars[MAX_SCROLL_OFFSET_Y] = 0;
SwordLogic::_scriptVars[SCROLL_OFFSET_X] = 0; Logic::_scriptVars[SCROLL_OFFSET_X] = 0;
SwordLogic::_scriptVars[SCROLL_OFFSET_Y] = 0; Logic::_scriptVars[SCROLL_OFFSET_Y] = 0;
} }
_screenBuf = (uint8*)malloc(_scrnSizeX * _scrnSizeY); _screenBuf = (uint8*)malloc(_scrnSizeX * _scrnSizeY);
_screenGrid = (uint8*)malloc(_gridSizeX * _gridSizeY); _screenGrid = (uint8*)malloc(_gridSizeX * _gridSizeY);
@ -287,7 +289,7 @@ void SwordScreen::newScreen(uint32 screen) {
_fullRefresh = true; _fullRefresh = true;
} }
void SwordScreen::quitScreen(void) { void Screen::quitScreen(void) {
uint8 cnt; uint8 cnt;
for (cnt = 0; cnt < _roomDefTable[_currentScreen].totalLayers; cnt++) for (cnt = 0; cnt < _roomDefTable[_currentScreen].totalLayers; cnt++)
_resMan->resClose(_roomDefTable[_currentScreen].layers[cnt]); _resMan->resClose(_roomDefTable[_currentScreen].layers[cnt]);
@ -299,7 +301,7 @@ void SwordScreen::quitScreen(void) {
_resMan->resClose(_roomDefTable[_currentScreen].parallax[1]); _resMan->resClose(_roomDefTable[_currentScreen].parallax[1]);
} }
void SwordScreen::draw(void) { void Screen::draw(void) {
uint8 cnt; uint8 cnt;
if (_currentScreen == 54) { if (_currentScreen == 54) {
// rm54 has a BACKGROUND parallax layer in parallax[0] // rm54 has a BACKGROUND parallax layer in parallax[0]
@ -339,8 +341,8 @@ void SwordScreen::draw(void) {
_backLength = _sortLength = _foreLength = 0; _backLength = _sortLength = _foreLength = 0;
} }
void SwordScreen::processImage(uint32 id) { void Screen::processImage(uint32 id) {
BsObject *compact; Object *compact;
FrameHeader *frameHead; FrameHeader *frameHead;
int scale; int scale;
@ -419,7 +421,7 @@ void SwordScreen::processImage(uint32 id) {
free(tonyBuf); free(tonyBuf);
} }
void SwordScreen::verticalMask(uint16 x, uint16 y, uint16 bWidth, uint16 bHeight) { void Screen::verticalMask(uint16 x, uint16 y, uint16 bWidth, uint16 bHeight) {
if (_roomDefTable[_currentScreen].totalLayers <= 1) if (_roomDefTable[_currentScreen].totalLayers <= 1)
return; return;
@ -457,7 +459,7 @@ void SwordScreen::verticalMask(uint16 x, uint16 y, uint16 bWidth, uint16 bHeight
} }
} }
void SwordScreen::blitBlockClear(uint16 x, uint16 y, uint8 *data) { void Screen::blitBlockClear(uint16 x, uint16 y, uint8 *data) {
uint8 *dest = _screenBuf + (y * SCRNGRID_Y) * _scrnSizeX + (x * SCRNGRID_X); uint8 *dest = _screenBuf + (y * SCRNGRID_Y) * _scrnSizeX + (x * SCRNGRID_X);
for (uint8 cnty = 0; cnty < SCRNGRID_Y; cnty++) { for (uint8 cnty = 0; cnty < SCRNGRID_Y; cnty++) {
for (uint8 cntx = 0; cntx < SCRNGRID_X; cntx++) for (uint8 cntx = 0; cntx < SCRNGRID_X; cntx++)
@ -468,7 +470,7 @@ void SwordScreen::blitBlockClear(uint16 x, uint16 y, uint8 *data) {
} }
} }
void SwordScreen::renderParallax(uint8 *data) { void Screen::renderParallax(uint8 *data) {
ParallaxHeader *header = (ParallaxHeader*)data; ParallaxHeader *header = (ParallaxHeader*)data;
uint32 *lineIndexes = (uint32*)(data + sizeof(ParallaxHeader)); uint32 *lineIndexes = (uint32*)(data + sizeof(ParallaxHeader));
assert((FROM_LE_16(header->sizeX) >= SCREEN_WIDTH) && (FROM_LE_16(header->sizeY) >= SCREEN_DEPTH)); assert((FROM_LE_16(header->sizeX) >= SCREEN_WIDTH) && (FROM_LE_16(header->sizeY) >= SCREEN_DEPTH));
@ -479,10 +481,10 @@ void SwordScreen::renderParallax(uint8 *data) {
uint16 scrnWidth, scrnHeight; uint16 scrnWidth, scrnHeight;
// we have to render more than the visible screen part for displaying scroll frames // we have to render more than the visible screen part for displaying scroll frames
scrnScrlX = MIN((uint32)_oldScrollX, SwordLogic::_scriptVars[SCROLL_OFFSET_X]); scrnScrlX = MIN((uint32)_oldScrollX, Logic::_scriptVars[SCROLL_OFFSET_X]);
scrnWidth = SCREEN_WIDTH + ABS((int32)_oldScrollX - (int32)SwordLogic::_scriptVars[SCROLL_OFFSET_X]); scrnWidth = SCREEN_WIDTH + ABS((int32)_oldScrollX - (int32)Logic::_scriptVars[SCROLL_OFFSET_X]);
scrnScrlY = MIN((uint32)_oldScrollY, SwordLogic::_scriptVars[SCROLL_OFFSET_Y]); scrnScrlY = MIN((uint32)_oldScrollY, Logic::_scriptVars[SCROLL_OFFSET_Y]);
scrnHeight = SCREEN_DEPTH + ABS((int32)_oldScrollY - (int32)SwordLogic::_scriptVars[SCROLL_OFFSET_Y]); scrnHeight = SCREEN_DEPTH + ABS((int32)_oldScrollY - (int32)Logic::_scriptVars[SCROLL_OFFSET_Y]);
if (_scrnSizeX != SCREEN_WIDTH) { if (_scrnSizeX != SCREEN_WIDTH) {
double scrlfx = (FROM_LE_16(header->sizeX) - SCREEN_WIDTH) / ((double)(_scrnSizeX - SCREEN_WIDTH)); double scrlfx = (FROM_LE_16(header->sizeX) - SCREEN_WIDTH) / ((double)(_scrnSizeX - SCREEN_WIDTH));
@ -549,7 +551,7 @@ void SwordScreen::renderParallax(uint8 *data) {
} }
} }
void SwordScreen::drawSprite(uint8 *sprData, uint16 sprX, uint16 sprY, uint16 sprWidth, uint16 sprHeight, uint16 sprPitch) { void Screen::drawSprite(uint8 *sprData, uint16 sprX, uint16 sprY, uint16 sprWidth, uint16 sprHeight, uint16 sprPitch) {
uint8 *dest = _screenBuf + (sprY * _scrnSizeX) + sprX; uint8 *dest = _screenBuf + (sprY * _scrnSizeX) + sprX;
for (uint16 cnty = 0; cnty < sprHeight; cnty++) { for (uint16 cnty = 0; cnty < sprHeight; cnty++) {
for (uint16 cntx = 0; cntx < sprWidth; cntx++) for (uint16 cntx = 0; cntx < sprWidth; cntx++)
@ -561,7 +563,7 @@ void SwordScreen::drawSprite(uint8 *sprData, uint16 sprX, uint16 sprY, uint16 sp
} }
// nearest neighbor filter: // nearest neighbor filter:
void SwordScreen::fastShrink(uint8 *src, uint32 width, uint32 height, uint32 scale, uint8 *dest) { void Screen::fastShrink(uint8 *src, uint32 width, uint32 height, uint32 scale, uint8 *dest) {
uint32 resHeight = (height * scale) >> 8; uint32 resHeight = (height * scale) >> 8;
uint32 resWidth = (width * scale) >> 8; uint32 resWidth = (width * scale) >> 8;
uint32 step = 0x10000 / scale; uint32 step = 0x10000 / scale;
@ -600,14 +602,14 @@ void SwordScreen::fastShrink(uint8 *src, uint32 width, uint32 height, uint32 sca
} }
} }
void SwordScreen::addToGraphicList(uint8 listId, uint32 objId) { void Screen::addToGraphicList(uint8 listId, uint32 objId) {
if (listId == 0) { if (listId == 0) {
_foreList[_foreLength++] = objId; _foreList[_foreLength++] = objId;
if (_foreLength > MAX_FORE) if (_foreLength > MAX_FORE)
error("foreList exceeded!"); error("foreList exceeded!");
} }
if (listId == 1) { if (listId == 1) {
BsObject *cpt = _objMan->fetchObject(objId); Object *cpt = _objMan->fetchObject(objId);
_sortList[_sortLength].id = objId; _sortList[_sortLength].id = objId;
_sortList[_sortLength].y = cpt->o_anim_y; // gives feet coords if boxed mega, otherwise top of sprite box _sortList[_sortLength].y = cpt->o_anim_y; // gives feet coords if boxed mega, otherwise top of sprite box
if (!(cpt->o_status & STAT_SHRINK)) { // not a boxed mega using shrinking if (!(cpt->o_status & STAT_SHRINK)) { // not a boxed mega using shrinking
@ -627,7 +629,7 @@ void SwordScreen::addToGraphicList(uint8 listId, uint32 objId) {
} }
} }
void SwordScreen::decompressTony(uint8 *src, uint32 compSize, uint8 *dest) { void Screen::decompressTony(uint8 *src, uint32 compSize, uint8 *dest) {
uint8 *endOfData = src + compSize; uint8 *endOfData = src + compSize;
while (src < endOfData) { while (src < endOfData) {
uint8 numFlat = *src++; uint8 numFlat = *src++;
@ -645,7 +647,7 @@ void SwordScreen::decompressTony(uint8 *src, uint32 compSize, uint8 *dest) {
} }
} }
void SwordScreen::decompressRLE7(uint8 *src, uint32 compSize, uint8 *dest) { void Screen::decompressRLE7(uint8 *src, uint32 compSize, uint8 *dest) {
uint8 *compBufEnd = src + compSize; uint8 *compBufEnd = src + compSize;
while (src < compBufEnd) { while (src < compBufEnd) {
uint8 code = *src++; uint8 code = *src++;
@ -659,7 +661,7 @@ void SwordScreen::decompressRLE7(uint8 *src, uint32 compSize, uint8 *dest) {
} }
} }
void SwordScreen::decompressRLE0(uint8 *src, uint32 compSize, uint8 *dest) { void Screen::decompressRLE0(uint8 *src, uint32 compSize, uint8 *dest) {
uint8 *srcBufEnd = src + compSize; uint8 *srcBufEnd = src + compSize;
while (src < srcBufEnd) { while (src < srcBufEnd) {
uint8 color = *src++; uint8 color = *src++;
@ -673,7 +675,7 @@ void SwordScreen::decompressRLE0(uint8 *src, uint32 compSize, uint8 *dest) {
} }
} }
void SwordScreen::fadePalette(void) { void Screen::fadePalette(void) {
if (_fadingStep == 16) if (_fadingStep == 16)
memcpy(_currentPalette, _targetPalette, 256 * 4); memcpy(_currentPalette, _targetPalette, 256 * 4);
else if ((_fadingStep == 1) && (_fadingDirection == FADE_DOWN)) { else if ((_fadingStep == 1) && (_fadingDirection == FADE_DOWN)) {
@ -690,13 +692,13 @@ void SwordScreen::fadePalette(void) {
_isBlack = true; _isBlack = true;
} }
void SwordScreen::fnSetParallax(uint32 screen, uint32 resId) { void Screen::fnSetParallax(uint32 screen, uint32 resId) {
if ((screen == _currentScreen) && (resId != _roomDefTable[screen].parallax[0])) if ((screen == _currentScreen) && (resId != _roomDefTable[screen].parallax[0]))
warning("fnSetParallax: setting parallax for current room!!"); warning("fnSetParallax: setting parallax for current room!!");
_roomDefTable[screen].parallax[0] = resId; _roomDefTable[screen].parallax[0] = resId;
} }
void SwordScreen::spriteClipAndSet(uint16 *pSprX, uint16 *pSprY, uint16 *pSprWidth, uint16 *pSprHeight, uint16 *incr) { void Screen::spriteClipAndSet(uint16 *pSprX, uint16 *pSprY, uint16 *pSprWidth, uint16 *pSprHeight, uint16 *incr) {
int16 sprX = *pSprX - SCREEN_LEFT_EDGE; int16 sprX = *pSprX - SCREEN_LEFT_EDGE;
int16 sprY = *pSprY - SCREEN_TOP_EDGE; int16 sprY = *pSprY - SCREEN_TOP_EDGE;
int16 sprW = *pSprWidth; int16 sprW = *pSprWidth;
@ -751,13 +753,13 @@ void SwordScreen::spriteClipAndSet(uint16 *pSprX, uint16 *pSprY, uint16 *pSprWid
} }
} }
void SwordScreen::fnFlash(uint8 color) { void Screen::fnFlash(uint8 color) {
warning("stub: SwordScreen::fnFlash(%d)", color); warning("stub: Screen::fnFlash(%d)", color);
} }
// ------------------- SwordMenu screen interface --------------------------- // ------------------- Menu screen interface ---------------------------
void SwordScreen::showFrame(uint16 x, uint16 y, uint32 resId, uint32 frameNo, const byte *fadeMask, int8 fadeStatus) { void Screen::showFrame(uint16 x, uint16 y, uint32 resId, uint32 frameNo, const byte *fadeMask, int8 fadeStatus) {
uint8 frame[40 * 40]; uint8 frame[40 * 40];
int i, j; int i, j;
@ -790,17 +792,17 @@ void SwordScreen::showFrame(uint16 x, uint16 y, uint32 resId, uint32 frameNo, co
// ------------------- router debugging code -------------------------------- // ------------------- router debugging code --------------------------------
void SwordScreen::vline(uint16 x, uint16 y1, uint16 y2) { void Screen::vline(uint16 x, uint16 y1, uint16 y2) {
for (uint16 cnty = y1; cnty <= y2; cnty++) for (uint16 cnty = y1; cnty <= y2; cnty++)
_screenBuf[x + _scrnSizeX * cnty] = 0; _screenBuf[x + _scrnSizeX * cnty] = 0;
} }
void SwordScreen::hline(uint16 x1, uint16 x2, uint16 y) { void Screen::hline(uint16 x1, uint16 x2, uint16 y) {
for (uint16 cntx = x1; cntx <= x2; cntx++) for (uint16 cntx = x1; cntx <= x2; cntx++)
_screenBuf[y * _scrnSizeX + cntx] = 0; _screenBuf[y * _scrnSizeX + cntx] = 0;
} }
void SwordScreen::bsubline_1(uint16 x1, uint16 y1, uint16 x2, uint16 y2) { void Screen::bsubline_1(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
int x, y, ddx, ddy, e; int x, y, ddx, ddy, e;
ddx = ABS(x2 - x1); ddx = ABS(x2 - x1);
ddy = ABS(y2 - y1) << 1; ddy = ABS(y2 - y1) << 1;
@ -824,7 +826,7 @@ void SwordScreen::bsubline_1(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
} }
} }
void SwordScreen::bsubline_2(uint16 x1, uint16 y1, uint16 x2, uint16 y2) { void Screen::bsubline_2(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
int x, y, ddx, ddy, e; int x, y, ddx, ddy, e;
ddx = ABS(x2 - x1) << 1; ddx = ABS(x2 - x1) << 1;
ddy = ABS(y2 - y1); ddy = ABS(y2 - y1);
@ -848,7 +850,7 @@ void SwordScreen::bsubline_2(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
} }
} }
void SwordScreen::bsubline_3(uint16 x1, uint16 y1, uint16 x2, uint16 y2) { void Screen::bsubline_3(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
int x, y, ddx, ddy, e; int x, y, ddx, ddy, e;
ddx = ABS(x1 - x2) << 1; ddx = ABS(x1 - x2) << 1;
ddy = ABS(y2 - y1); ddy = ABS(y2 - y1);
@ -872,7 +874,7 @@ void SwordScreen::bsubline_3(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
} }
} }
void SwordScreen::bsubline_4(uint16 x1, uint16 y1, uint16 x2, uint16 y2) { void Screen::bsubline_4(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
int x, y, ddx, ddy, e; int x, y, ddx, ddy, e;
ddy = ABS(y2 - y1) << 1; ddy = ABS(y2 - y1) << 1;
ddx = ABS(x1 - x2); ddx = ABS(x1 - x2);
@ -896,7 +898,7 @@ void SwordScreen::bsubline_4(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
} }
} }
void SwordScreen::drawLine(uint16 x1, uint16 y1, uint16 x2, uint16 y2) { void Screen::drawLine(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
if ((x1 == x2) && (y1 == y2)) { if ((x1 == x2) && (y1 == y2)) {
_screenBuf[x1 + y1 * _scrnSizeX] = 0; _screenBuf[x1 + y1 * _scrnSizeX] = 0;
} }
@ -922,3 +924,5 @@ void SwordScreen::drawLine(uint16 x1, uint16 y1, uint16 x2, uint16 y2) {
bsubline_3(x1, y1, x2, y2); bsubline_3(x1, y1, x2, y2);
} }
} }
} // End of namespace Sword1

View file

@ -24,6 +24,10 @@
#include "sworddefs.h" #include "sworddefs.h"
class OSystem;
namespace Sword1 {
#define MAX_FORE 20 #define MAX_FORE 20
#define MAX_BACK 20 #define MAX_BACK 20
#define MAX_SORT 20 #define MAX_SORT 20
@ -57,15 +61,14 @@ struct RoomDef {
class ResMan; class ResMan;
class ObjectMan; class ObjectMan;
class SwordText; // Text objects use sprites that are created internally at run-time class Text; // Text objects use sprites that are created internally at run-time
// the buffer belongs to SwordText, so we need a reference here. // the buffer belongs to Text, so we need a reference here.
class OSystem;
class SwordScreen { class Screen {
public: public:
SwordScreen(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan); Screen(OSystem *system, ResMan *pResMan, ObjectMan *pObjMan);
void useTextManager(SwordText *pTextMan); void useTextManager(Text *pTextMan);
~SwordScreen(void); ~Screen(void);
void draw(void); void draw(void);
void quitScreen(void); void quitScreen(void);
@ -114,7 +117,7 @@ private:
OSystem *_system; OSystem *_system;
ResMan *_resMan; ResMan *_resMan;
ObjectMan *_objMan; ObjectMan *_objMan;
SwordText *_textMan; Text *_textMan;
uint16 _currentScreen; uint16 _currentScreen;
uint8 *_screenBuf; uint8 *_screenBuf;
@ -143,5 +146,7 @@ private:
// mainloop that no further fading is necessary. // mainloop that no further fading is necessary.
}; };
} // End of namespace Sword1
#endif //BSSCREEN_H #endif //BSSCREEN_H

View file

@ -26,10 +26,12 @@
#include "logic.h" #include "logic.h"
#include "sword1.h" #include "sword1.h"
namespace Sword1 {
#define SOUND_SPEECH_ID 1 #define SOUND_SPEECH_ID 1
#define SPEECH_FLAGS (SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_LITTLE_ENDIAN) #define SPEECH_FLAGS (SoundMixer::FLAG_16BITS | SoundMixer::FLAG_AUTOFREE | SoundMixer::FLAG_LITTLE_ENDIAN)
SwordSound::SwordSound(const char *searchPath, SoundMixer *mixer, ResMan *pResMan) { Sound::Sound(const char *searchPath, SoundMixer *mixer, ResMan *pResMan) {
strcpy(_filePath, searchPath); strcpy(_filePath, searchPath);
_mixer = mixer; _mixer = mixer;
_resMan = pResMan; _resMan = pResMan;
@ -39,7 +41,7 @@ SwordSound::SwordSound(const char *searchPath, SoundMixer *mixer, ResMan *pResMa
_speechVolL = _speechVolR = _sfxVolL = _sfxVolR = 192; _speechVolL = _speechVolR = _sfxVolL = _sfxVolR = 192;
} }
int SwordSound::addToQueue(int32 fxNo) { int Sound::addToQueue(int32 fxNo) {
bool alreadyInQueue = false; bool alreadyInQueue = false;
for (uint8 cnt = 0; (cnt < _endOfQueue) && (!alreadyInQueue); cnt++) for (uint8 cnt = 0; (cnt < _endOfQueue) && (!alreadyInQueue); cnt++)
if (_fxQueue[cnt].id == (uint32)fxNo) if (_fxQueue[cnt].id == (uint32)fxNo)
@ -61,10 +63,10 @@ int SwordSound::addToQueue(int32 fxNo) {
return 0; return 0;
} }
void SwordSound::engine(void) { void Sound::engine(void) {
// first of all, add any random sfx to the queue... // first of all, add any random sfx to the queue...
for (uint16 cnt = 0; cnt < TOTAL_FX_PER_ROOM; cnt++) { for (uint16 cnt = 0; cnt < TOTAL_FX_PER_ROOM; cnt++) {
uint16 fxNo = _roomsFixedFx[SwordLogic::_scriptVars[SCREEN]][cnt]; uint16 fxNo = _roomsFixedFx[Logic::_scriptVars[SCREEN]][cnt];
if (fxNo) { if (fxNo) {
if (_fxList[fxNo].type == FX_RANDOM) { if (_fxList[fxNo].type == FX_RANDOM) {
if (_rnd.getRandomNumber(_fxList[fxNo].delay) == 0) if (_rnd.getRandomNumber(_fxList[fxNo].delay) == 0)
@ -90,8 +92,7 @@ void SwordSound::engine(void) {
} }
} }
void SwordSound::fnStopFx(int32 fxNo) { void Sound::fnStopFx(int32 fxNo) {
_mixer->stopID(fxNo); _mixer->stopID(fxNo);
for (uint8 cnt = 0; cnt < _endOfQueue; cnt++) for (uint8 cnt = 0; cnt < _endOfQueue; cnt++)
if (_fxQueue[cnt].id == (uint32)fxNo) { if (_fxQueue[cnt].id == (uint32)fxNo) {
@ -105,16 +106,16 @@ void SwordSound::fnStopFx(int32 fxNo) {
debug(8, "fnStopFx: id not found in queue"); debug(8, "fnStopFx: id not found in queue");
} }
bool SwordSound::amISpeaking(void) { bool Sound::amISpeaking(void) {
_waveVolPos++; _waveVolPos++;
return _waveVolume[_waveVolPos - 1]; return _waveVolume[_waveVolPos - 1];
} }
bool SwordSound::speechFinished(void) { bool Sound::speechFinished(void) {
return !_speechHandle.isActive(); return !_speechHandle.isActive();
} }
void SwordSound::newScreen(uint32 screen) { void Sound::newScreen(uint32 screen) {
if (_currentCowFile != SwordEngine::_systemVars.currentCD) { if (_currentCowFile != SwordEngine::_systemVars.currentCD) {
if (_currentCowFile) if (_currentCowFile)
closeCowSystem(); closeCowSystem();
@ -122,17 +123,17 @@ void SwordSound::newScreen(uint32 screen) {
} }
} }
void SwordSound::quitScreen(void) { void Sound::quitScreen(void) {
// stop all running SFX // stop all running SFX
while (_endOfQueue) while (_endOfQueue)
fnStopFx(_fxQueue[0].id); fnStopFx(_fxQueue[0].id);
} }
void SwordSound::playSample(QueueElement *elem) { void Sound::playSample(QueueElement *elem) {
uint8 *sampleData = (uint8*)_resMan->fetchRes(_fxList[elem->id].sampleId); uint8 *sampleData = (uint8*)_resMan->fetchRes(_fxList[elem->id].sampleId);
for (uint16 cnt = 0; cnt < MAX_ROOMS_PER_FX; cnt++) { for (uint16 cnt = 0; cnt < MAX_ROOMS_PER_FX; cnt++) {
if (_fxList[elem->id].roomVolList[cnt].roomNo) { if (_fxList[elem->id].roomVolList[cnt].roomNo) {
if ((_fxList[elem->id].roomVolList[cnt].roomNo == (int)SwordLogic::_scriptVars[SCREEN]) || if ((_fxList[elem->id].roomVolList[cnt].roomNo == (int)Logic::_scriptVars[SCREEN]) ||
(_fxList[elem->id].roomVolList[cnt].roomNo == -1)) { (_fxList[elem->id].roomVolList[cnt].roomNo == -1)) {
uint8 volL = (_fxList[elem->id].roomVolList[cnt].leftVol * 10 * _sfxVolL) / 255; uint8 volL = (_fxList[elem->id].roomVolList[cnt].leftVol * 10 * _sfxVolL) / 255;
@ -154,9 +155,9 @@ void SwordSound::playSample(QueueElement *elem) {
} }
} }
bool SwordSound::startSpeech(uint16 roomNo, uint16 localNo) { bool Sound::startSpeech(uint16 roomNo, uint16 localNo) {
if (_cowHeader == NULL) { if (_cowHeader == NULL) {
warning("SwordSound::startSpeech: COW file isn't open!"); warning("Sound::startSpeech: COW file isn't open!");
return false; return false;
} }
@ -176,7 +177,7 @@ bool SwordSound::startSpeech(uint16 roomNo, uint16 localNo) {
return false; return false;
} }
int16 *SwordSound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) { int16 *Sound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) {
uint8 *fBuf = (uint8*)malloc(cSize); uint8 *fBuf = (uint8*)malloc(cSize);
_cowFile.seek(index); _cowFile.seek(index);
_cowFile.read(fBuf, cSize); _cowFile.read(fBuf, cSize);
@ -210,13 +211,13 @@ int16 *SwordSound::uncompressSpeech(uint32 index, uint32 cSize, uint32 *size) {
return dstData; return dstData;
} else { } else {
free(fBuf); free(fBuf);
warning("SwordSound::uncompressSpeech(): DATA tag not found in wave header"); warning("Sound::uncompressSpeech(): DATA tag not found in wave header");
*size = 0; *size = 0;
return NULL; return NULL;
} }
} }
void SwordSound::calcWaveVolume(int16 *data, uint32 length) { void Sound::calcWaveVolume(int16 *data, uint32 length) {
int16 *blkPos = data + 918; int16 *blkPos = data + 918;
for (uint32 cnt = 0; cnt < WAVE_VOL_TAB_LENGTH; cnt++) for (uint32 cnt = 0; cnt < WAVE_VOL_TAB_LENGTH; cnt++)
_waveVolume[cnt] = false; _waveVolume[cnt] = false;
@ -241,11 +242,11 @@ void SwordSound::calcWaveVolume(int16 *data, uint32 length) {
} }
} }
void SwordSound::stopSpeech(void) { void Sound::stopSpeech(void) {
_mixer->stopID(SOUND_SPEECH_ID); _mixer->stopID(SOUND_SPEECH_ID);
} }
void SwordSound::initCowSystem(void) { void Sound::initCowSystem(void) {
char cowName[25]; char cowName[25];
/* look for speech1/2.clu in the data dir /* look for speech1/2.clu in the data dir
and speech/speech.clu (running from cd or using cd layout) and speech/speech.clu (running from cd or using cd layout)
@ -264,10 +265,10 @@ void SwordSound::initCowSystem(void) {
_cowHeader[cnt] = _cowFile.readUint32LE(); _cowHeader[cnt] = _cowFile.readUint32LE();
_currentCowFile = SwordEngine::_systemVars.currentCD; _currentCowFile = SwordEngine::_systemVars.currentCD;
} else } else
warning("SwordSound::initCowSystem: Can't open SPEECH%d.CLU", SwordEngine::_systemVars.currentCD); warning("Sound::initCowSystem: Can't open SPEECH%d.CLU", SwordEngine::_systemVars.currentCD);
} }
void SwordSound::closeCowSystem(void) { void Sound::closeCowSystem(void) {
if (_cowFile.isOpen()) if (_cowFile.isOpen())
_cowFile.close(); _cowFile.close();
if (_cowHeader) if (_cowHeader)
@ -276,3 +277,4 @@ void SwordSound::closeCowSystem(void) {
_currentCowFile = 0; _currentCowFile = 0;
} }
} // End of namespace Sword1

View file

@ -28,6 +28,10 @@
#include "sound/mixer.h" #include "sound/mixer.h"
#include "common/util.h" #include "common/util.h"
class SoundMixer;
namespace Sword1 {
#define TOTAL_FX_PER_ROOM 7 // total loop & random fx per room (see fx_list.c) #define TOTAL_FX_PER_ROOM 7 // total loop & random fx per room (see fx_list.c)
#define MAX_ROOMS_PER_FX 7 // max no. of rooms in the fx's room,vol list #define MAX_ROOMS_PER_FX 7 // max no. of rooms in the fx's room,vol list
#define MAX_FXQ_LENGTH 32 // max length of sound queue - ie. max number of fx that can be stored up/playing together #define MAX_FXQ_LENGTH 32 // max length of sound queue - ie. max number of fx that can be stored up/playing together
@ -50,15 +54,14 @@ struct FxDef {
RoomVol roomVolList[MAX_ROOMS_PER_FX]; RoomVol roomVolList[MAX_ROOMS_PER_FX];
}; };
class SoundMixer;
class ResMan; class ResMan;
#define WAVE_VOL_TAB_LENGTH 480 #define WAVE_VOL_TAB_LENGTH 480
#define WAVE_VOL_THRESHOLD 190000 //120000 #define WAVE_VOL_THRESHOLD 190000 //120000
class SwordSound { class Sound {
public: public:
SwordSound(const char *searchPath, SoundMixer *mixer, ResMan *pResMan); Sound(const char *searchPath, SoundMixer *mixer, ResMan *pResMan);
~SwordSound(void); ~Sound(void);
void setSpeechVol(uint8 volL, uint8 volR) { _speechVolL = volL; _speechVolR = volR; }; void setSpeechVol(uint8 volL, uint8 volR) { _speechVolL = volL; _speechVolR = volR; };
void setSfxVol(uint8 volL, uint8 volR) { _sfxVolL = volL; _sfxVolR = volR; }; void setSfxVol(uint8 volL, uint8 volR) { _sfxVolL = volL; _sfxVolR = volR; };
void giveSpeechVol(uint8 *volL, uint8 *volR) { *volL = _speechVolL; *volR = _speechVolR; }; void giveSpeechVol(uint8 *volL, uint8 *volR) { *volL = _speechVolL; *volR = _speechVolR; };
@ -103,4 +106,6 @@ private:
static const FxDef _fxList[312]; static const FxDef _fxList[312];
}; };
} // End of namespace Sword1
#endif //BSSOUND_H #endif //BSSOUND_H

View file

@ -30,6 +30,8 @@
#include "sound.h" #include "sound.h"
#include "sword1.h" #include "sword1.h"
namespace Sword1 {
const uint8 SwordEngine::_cdList[TOTAL_SECTIONS] = { const uint8 SwordEngine::_cdList[TOTAL_SECTIONS] = {
0, // 0 inventory 0, // 0 inventory
@ -199,7 +201,7 @@ const uint8 SwordEngine::_cdList[TOTAL_SECTIONS] = {
1, // 146 ALBERT'S TEXT - on CD1 1, // 146 ALBERT'S TEXT - on CD1
}; };
const MenuObject SwordMenu::_objectDefs[TOTAL_pockets + 1] = { const MenuObject Menu::_objectDefs[TOTAL_pockets + 1] = {
{ // 0 can't use { // 0 can't use
0, 0, 0, 0, 0 0, 0, 0, 0, 0
}, },
@ -569,7 +571,7 @@ const MenuObject SwordMenu::_objectDefs[TOTAL_pockets + 1] = {
} }
}; };
const Subject SwordMenu::_subjectList[TOTAL_subjects] = { const Subject Menu::_subjectList[TOTAL_subjects] = {
{ // 256 { // 256
0, // subject_res 0, // subject_res
0 // subject_frame 0 // subject_frame
@ -1541,7 +1543,7 @@ const uint32 ObjectMan::_textList[TOTAL_SECTIONS][7] = {
}; };
RoomDef SwordScreen::_roomDefTable[TOTAL_ROOMS] = { // these are NOT const RoomDef Screen::_roomDefTable[TOTAL_ROOMS] = { // these are NOT const
{ {
0, //total_layers --- room 0 NOT USED 0, //total_layers --- room 0 NOT USED
0, //size_x = width 0, //size_x = width
@ -2584,7 +2586,7 @@ RoomDef SwordScreen::_roomDefTable[TOTAL_ROOMS] = { // these are NOT const
} }
}; };
const char SwordMusic::_tuneList[TOTAL_TUNES][8] = { const char Music::_tuneList[TOTAL_TUNES][8] = {
"", // 0 SPARE "", // 0 SPARE
"1m2", // DONE 1 George picks up the newspaper "1m2", // DONE 1 George picks up the newspaper
"1m3", // DONE 2 In the alley for the first time "1m3", // DONE 2 In the alley for the first time
@ -2887,7 +2889,7 @@ const char SwordMusic::_tuneList[TOTAL_TUNES][8] = {
"rm3d", // DONE 269 ONe the scene change after the Grand Master says, "George, we have watched you..." This one might need a bit of fiddling to get it to match to the fisticuffs. "rm3d", // DONE 269 ONe the scene change after the Grand Master says, "George, we have watched you..." This one might need a bit of fiddling to get it to match to the fisticuffs.
}; };
const FxDef SwordSound::_fxList[312] = { const FxDef Sound::_fxList[312] = {
// 0 // 0
{ {
0, // sampleId 0, // sampleId
@ -6440,7 +6442,7 @@ const FxDef SwordSound::_fxList[312] = {
// NB. There must be a list for each room number, even if location doesn't exist in game // NB. There must be a list for each room number, even if location doesn't exist in game
const uint16 SwordSound::_roomsFixedFx[TOTAL_ROOMS][TOTAL_FX_PER_ROOM] = const uint16 Sound::_roomsFixedFx[TOTAL_ROOMS][TOTAL_FX_PER_ROOM] =
{ {
{0}, // 0 {0}, // 0
@ -6561,3 +6563,5 @@ const uint16 SwordSound::_roomsFixedFx[TOTAL_ROOMS][TOTAL_FX_PER_ROOM] =
{0}, // 98 {0}, // 98
{0}, // 99 {0}, // 99
}; };
} // End of namespace Sword1

File diff suppressed because it is too large Load diff

View file

@ -19,22 +19,26 @@
* *
*/ */
#include <stdio.h> #ifndef BSSWORD1_H
#define BSSWORD1_H
#include "base/engine.h" #include "base/engine.h"
#include "common/util.h" #include "common/util.h"
#include "base/gameDetector.h" #include "base/gameDetector.h"
#include "sworddefs.h" #include "sworddefs.h"
class SwordScreen; namespace Sword1 {
class SwordSound;
class SwordLogic; class Screen;
class SwordMouse; class Sound;
class Logic;
class Mouse;
class ResMan; class ResMan;
class MemMan; class MemMan;
class ObjectMan; class ObjectMan;
class SwordMenu; class Menu;
class SwordMusic; class Music;
class SwordControl; class Control;
struct SystemVars { struct SystemVars {
bool runningFromCd; bool runningFromCd;
@ -46,8 +50,8 @@ struct SystemVars {
bool forceRestart; bool forceRestart;
bool wantFade; // when true => fade during scene change, else cut. bool wantFade; // when true => fade during scene change, else cut.
uint8 playSpeech; uint8 playSpeech;
uint8 showText; uint8 showText;
uint8 language; uint8 language;
}; };
class SwordEngine : public Engine { class SwordEngine : public Engine {
@ -74,12 +78,16 @@ private:
MemMan *_memMan; MemMan *_memMan;
ResMan *_resMan; ResMan *_resMan;
ObjectMan *_objectMan; ObjectMan *_objectMan;
SwordScreen *_screen; Screen *_screen;
SwordMouse *_mouse; Mouse *_mouse;
SwordLogic *_logic; Logic *_logic;
SwordSound *_sound; Sound *_sound;
SwordMenu *_menu; Menu *_menu;
SwordMusic *_music; Music *_music;
SwordControl *_control; Control *_control;
static const uint8 _cdList[TOTAL_SECTIONS]; static const uint8 _cdList[TOTAL_SECTIONS];
}; };
} // End of namespace Sword1
#endif //BSSWORD1_H

View file

@ -3,6 +3,8 @@
#include "scummsys.h" #include "scummsys.h"
namespace Sword1 {
#define LOOPED 1 #define LOOPED 1
#define FRAME_RATE 12 // number of frames per second (max rate) #define FRAME_RATE 12 // number of frames per second (max rate)
@ -1554,4 +1556,6 @@ enum ScriptVariableNames {
#define SCR_menu_look (0*0x10000 + 24) #define SCR_menu_look (0*0x10000 + 24)
#define SCR_icon_combine_script (0*0x10000 + 25) #define SCR_icon_combine_script (0*0x10000 + 25)
} // End of namespace Sword1
#endif //SWORDDEFS_H #endif //SWORDDEFS_H

View file

@ -22,6 +22,8 @@
#ifndef SWORDRES_H #ifndef SWORDRES_H
#define SWORDRES_H #define SWORDRES_H
namespace Sword1 {
// scripts // scripts
// standard // standard
#define SCRIPT0 0x01000000 #define SCRIPT0 0x01000000
@ -5215,4 +5217,6 @@
#define ROSTLK79CDT 0x0E090011 #define ROSTLK79CDT 0x0E090011
// 18 entities in TXTs, 18 in datafiles. // 18 entities in TXTs, 18 in datafiles.
} // End of namespace Sword1
#endif //SWORDRES_H #endif //SWORDRES_H

View file

@ -27,6 +27,8 @@
#include "swordres.h" #include "swordres.h"
#include "sworddefs.h" #include "sworddefs.h"
namespace Sword1 {
#define OVERLAP 3 #define OVERLAP 3
#define SPACE ' ' #define SPACE ' '
#define BORDER_COL 200 #define BORDER_COL 200
@ -35,7 +37,7 @@
#define MAX_LINES 30 #define MAX_LINES 30
SwordText::SwordText(ObjectMan *pObjMan, ResMan *pResMan, bool czechVersion) { Text::Text(ObjectMan *pObjMan, ResMan *pResMan, bool czechVersion) {
_objMan = pObjMan; _objMan = pObjMan;
_resMan = pResMan; _resMan = pResMan;
_textCount = 0; _textCount = 0;
@ -48,17 +50,17 @@ SwordText::SwordText(ObjectMan *pObjMan, ResMan *pResMan, bool czechVersion) {
_textBlocks[0] = _textBlocks[1] = NULL; _textBlocks[0] = _textBlocks[1] = NULL;
} }
SwordText::~SwordText(void) { Text::~Text(void) {
if (_textBlocks[0]) if (_textBlocks[0])
free(_textBlocks[0]); free(_textBlocks[0]);
if (_textBlocks[1]) if (_textBlocks[1])
free(_textBlocks[1]); free(_textBlocks[1]);
} }
uint32 SwordText::lowTextManager(uint8 *ascii, int32 width, uint8 pen) { uint32 Text::lowTextManager(uint8 *ascii, int32 width, uint8 pen) {
_textCount++; _textCount++;
if (_textCount > MAX_TEXT_OBS) if (_textCount > MAX_TEXT_OBS)
error("SwordText::lowTextManager: MAX_TEXT_OBS exceeded!"); error("Text::lowTextManager: MAX_TEXT_OBS exceeded!");
uint32 textObjId = (TEXT_sect * ITM_PER_SEC) - 1; uint32 textObjId = (TEXT_sect * ITM_PER_SEC) - 1;
do { do {
textObjId++; textObjId++;
@ -71,7 +73,7 @@ uint32 SwordText::lowTextManager(uint8 *ascii, int32 width, uint8 pen) {
return textObjId; return textObjId;
} }
void SwordText::makeTextSprite(uint8 slot, uint8 *text, uint16 maxWidth, uint8 pen) { void Text::makeTextSprite(uint8 slot, uint8 *text, uint16 maxWidth, uint8 pen) {
LineInfo lines[MAX_LINES]; LineInfo lines[MAX_LINES];
uint16 numLines = analyzeSentence(text, maxWidth, lines); uint16 numLines = analyzeSentence(text, maxWidth, lines);
@ -82,7 +84,7 @@ void SwordText::makeTextSprite(uint8 slot, uint8 *text, uint16 maxWidth, uint8 p
sprWidth = lines[lineCnt].width; sprWidth = lines[lineCnt].width;
uint16 sprHeight = _charHeight * numLines; uint16 sprHeight = _charHeight * numLines;
uint32 sprSize = sprWidth * sprHeight; uint32 sprSize = sprWidth * sprHeight;
assert(!_textBlocks[slot]); // if this triggers, the speechDriver failed to call SwordText::releaseText. assert(!_textBlocks[slot]); // if this triggers, the speechDriver failed to call Text::releaseText.
_textBlocks[slot] = (FrameHeader*)malloc(sprSize + sizeof(FrameHeader)); _textBlocks[slot] = (FrameHeader*)malloc(sprSize + sizeof(FrameHeader));
memcpy( _textBlocks[slot]->runTimeComp, "Nu ", 4); memcpy( _textBlocks[slot]->runTimeComp, "Nu ", 4);
@ -103,13 +105,13 @@ void SwordText::makeTextSprite(uint8 slot, uint8 *text, uint16 maxWidth, uint8 p
} }
} }
uint16 SwordText::charWidth(uint8 ch) { uint16 Text::charWidth(uint8 ch) {
if (ch < SPACE) if (ch < SPACE)
ch = 64; ch = 64;
return FROM_LE_16(_resMan->fetchFrame(_font, ch - SPACE)->width); return FROM_LE_16(_resMan->fetchFrame(_font, ch - SPACE)->width);
} }
uint16 SwordText::analyzeSentence(uint8 *text, uint16 maxWidth, LineInfo *line) { uint16 Text::analyzeSentence(uint8 *text, uint16 maxWidth, LineInfo *line) {
uint16 lineNo = 0; uint16 lineNo = 0;
bool firstWord = true; bool firstWord = true;
@ -149,7 +151,7 @@ uint16 SwordText::analyzeSentence(uint8 *text, uint16 maxWidth, LineInfo *line)
return lineNo+1; // return no of lines return lineNo+1; // return no of lines
} }
uint16 SwordText::copyChar(uint8 ch, uint8 *sprPtr, uint16 sprWidth, uint8 pen) { uint16 Text::copyChar(uint8 ch, uint8 *sprPtr, uint16 sprWidth, uint8 pen) {
FrameHeader *chFrame = _resMan->fetchFrame(_font, ch - SPACE); FrameHeader *chFrame = _resMan->fetchFrame(_font, ch - SPACE);
uint8 *chData = ((uint8*)chFrame) + sizeof(FrameHeader); uint8 *chData = ((uint8*)chFrame) + sizeof(FrameHeader);
uint8 *dest = sprPtr; uint8 *dest = sprPtr;
@ -166,7 +168,7 @@ uint16 SwordText::copyChar(uint8 ch, uint8 *sprPtr, uint16 sprWidth, uint8 pen)
return FROM_LE_16(chFrame->width); return FROM_LE_16(chFrame->width);
} }
FrameHeader *SwordText::giveSpriteData(uint32 textTarget) { FrameHeader *Text::giveSpriteData(uint32 textTarget) {
// textTarget is the resource ID of the Compact linking the textdata. // textTarget is the resource ID of the Compact linking the textdata.
// that's 0x950000 for slot 0 and 0x950001 for slot 1. easy, huh? :) // that's 0x950000 for slot 0 and 0x950001 for slot 1. easy, huh? :)
textTarget &= ITM_ID; textTarget &= ITM_ID;
@ -175,7 +177,7 @@ FrameHeader *SwordText::giveSpriteData(uint32 textTarget) {
return _textBlocks[textTarget]; return _textBlocks[textTarget];
} }
void SwordText::releaseText(uint32 id) { void Text::releaseText(uint32 id) {
id &= ITM_ID; id &= ITM_ID;
assert(id <= 1); assert(id <= 1);
if (_textBlocks[id]) { if (_textBlocks[id]) {
@ -184,3 +186,5 @@ void SwordText::releaseText(uint32 id) {
_textCount--; _textCount--;
} }
} }
} // End of namespace Sword1

View file

@ -22,10 +22,13 @@
#ifndef BSTEXT_H #ifndef BSTEXT_H
#define BSTEXT_H #define BSTEXT_H
#define MAX_TEXT_OBS 2
#include "object.h" #include "object.h"
#include "sworddefs.h" #include "sworddefs.h"
namespace Sword1 {
#define MAX_TEXT_OBS 2
class ObjectMan; class ObjectMan;
class ResMan; class ResMan;
@ -34,10 +37,10 @@ struct LineInfo {
uint16 length; // length of line in characters uint16 length; // length of line in characters
}; };
class SwordText { class Text {
public: public:
SwordText(ObjectMan *pObjMan, ResMan *pResMan, bool czechVersion); Text(ObjectMan *pObjMan, ResMan *pResMan, bool czechVersion);
~SwordText(void); ~Text(void);
FrameHeader *giveSpriteData(uint32 textTarget); FrameHeader *giveSpriteData(uint32 textTarget);
uint32 lowTextManager(uint8 *text, int32 width, uint8 pen); uint32 lowTextManager(uint8 *text, int32 width, uint8 pen);
void releaseText(uint32 id); void releaseText(uint32 id);
@ -55,4 +58,6 @@ private:
FrameHeader *_textBlocks[MAX_TEXT_OBS]; FrameHeader *_textBlocks[MAX_TEXT_OBS];
}; };
} // End of namespace Sword1
#endif //BSTEXT_H #endif //BSTEXT_H