aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/gob/util.cpp')
-rw-r--r--engines/gob/util.cpp466
1 files changed, 222 insertions, 244 deletions
diff --git a/engines/gob/util.cpp b/engines/gob/util.cpp
index fc85cf3e73..1b0e01727d 100644
--- a/engines/gob/util.cpp
+++ b/engines/gob/util.cpp
@@ -20,15 +20,19 @@
* $Id$
*
*/
+
+#include "common/stdafx.h"
+#include "common/events.h"
+
#include "gob/gob.h"
-#include "gob/global.h"
-#include "gob/timer.h"
#include "gob/util.h"
+#include "gob/global.h"
+#include "gob/dataio.h"
#include "gob/draw.h"
#include "gob/game.h"
-#include "gob/inter.h"
-
-#include "common/events.h"
+#include "gob/imd.h"
+#include "gob/sound.h"
+#include "gob/video.h"
namespace Gob {
@@ -40,6 +44,80 @@ Util::Util(GobEngine *vm) : _vm(vm) {
_keyBufferTail = 0;
}
+uint32 Util::getTimeKey(void) {
+ return g_system->getMillis();
+}
+
+int16 Util::getRandom(int16 max) {
+ return _vm->_rnd.getRandomNumber(max - 1);
+}
+
+void Util::beep(int16 freq) {
+ if (_vm->_global->_soundFlags == 0)
+ return;
+
+ _vm->_snd->speakerOn(freq, 50);
+}
+
+void Util::delay(uint16 msecs) {
+ g_system->delayMillis(msecs);
+}
+
+void Util::longDelay(uint16 msecs) {
+ uint32 time = g_system->getMillis() + msecs;
+ do {
+ _vm->_video->waitRetrace(_vm->_global->_videoMode);
+ processInput();
+ delay(15);
+ } while (!_vm->_quitRequested && (g_system->getMillis() < time));
+}
+
+void Util::initInput(void) {
+ _mouseButtons = 0;
+ _keyBufferHead = _keyBufferTail = 0;
+}
+
+void Util::processInput() {
+ Common::Event event;
+ Common::EventManager *eventMan = g_system->getEventManager();
+
+ while (eventMan->pollEvent(event)) {
+ switch (event.type) {
+ case Common::EVENT_LBUTTONDOWN:
+ _mouseButtons |= 1;
+ break;
+ case Common::EVENT_RBUTTONDOWN:
+ _mouseButtons |= 2;
+ break;
+ case Common::EVENT_LBUTTONUP:
+ _mouseButtons &= ~1;
+ break;
+ case Common::EVENT_RBUTTONUP:
+ _mouseButtons &= ~2;
+ break;
+ case Common::EVENT_KEYDOWN:
+ addKeyToBuffer(event.kbd.keycode);
+ break;
+ case Common::EVENT_KEYUP:
+ break;
+ case Common::EVENT_QUIT:
+ _vm->_quitRequested = true;
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+void Util::clearKeyBuf(void) {
+ processInput();
+ _keyBufferHead = _keyBufferTail = 0;
+}
+
+bool Util::keyBufferEmpty() {
+ return (_keyBufferHead == _keyBufferTail);
+}
+
void Util::addKeyToBuffer(int16 key) {
if ((_keyBufferHead + 1) % KEYBUFSIZE == _keyBufferTail) {
warning("key buffer overflow");
@@ -50,10 +128,6 @@ void Util::addKeyToBuffer(int16 key) {
_keyBufferHead = (_keyBufferHead + 1) % KEYBUFSIZE;
}
-bool Util::keyBufferEmpty() {
- return (_keyBufferHead == _keyBufferTail);
-}
-
bool Util::getKeyFromBuffer(int16& key) {
if (_keyBufferHead == _keyBufferTail) return false;
@@ -63,50 +137,37 @@ bool Util::getKeyFromBuffer(int16& key) {
return true;
}
-
-void Util::initInput(void) {
- _mouseButtons = 0;
- _keyBufferHead = _keyBufferTail = 0;
-}
-
-void Util::waitKey(void) {
- // FIXME: wrong function name? This functions clears the keyboard buffer.
- processInput();
- _keyBufferHead = _keyBufferTail = 0;
-}
-
int16 Util::translateKey(int16 key) {
- struct keyS {
+ static struct keyS {
int16 from;
int16 to;
} keys[] = {
- {8, 0x0e08}, // Backspace
- {32, 0x3920}, // Space
- {13, 0x1C0D}, // Enter
- {27, 0x011b}, // ESC
- {127, 0x5300}, // Del
- {273, 0x4800}, // Up arrow
- {274, 0x5000}, // Down arrow
- {275, 0x4D00}, // Right arrow
- {276, 0x4B00}, // Left arrow
- {282, 0x3b00}, // F1
- {283, 0x3c00}, // F2
- {284, 0x3d00}, // F3
- {285, 0x3E00}, // F4
- {286, 0x011b}, // F5
- {287, 0x4000}, // F6
- {288, 0x4100}, // F7
- {289, 0x4200}, // F8
- {290, 0x4300}, // F9
- {291, 0x4400} // F10
+ {8, 0x0E08}, // Backspace
+ {32, 0x3920}, // Space
+ {13, 0x1C0D}, // Enter
+ {27, 0x011B}, // ESC
+ {127, 0x5300}, // Del
+ {273, 0x4800}, // Up arrow
+ {274, 0x5000}, // Down arrow
+ {275, 0x4D00}, // Right arrow
+ {276, 0x4B00}, // Left arrow
+ {282, 0x3B00}, // F1
+ {283, 0x3C00}, // F2
+ {284, 0x3D00}, // F3
+ {285, 0x3E00}, // F4
+ {286, 0x011B}, // F5
+ {287, 0x4000}, // F6
+ {288, 0x4100}, // F7
+ {289, 0x4200}, // F8
+ {290, 0x4300}, // F9
+ {291, 0x4400} // F10
};
- int i;
- for (i = 0; i < ARRAYSIZE(keys); i++)
+ for (int i = 0; i < ARRAYSIZE(keys); i++)
if (key == keys[i].from)
return keys[i].to;
- if (key < 32 || key >= 128)
+ if ((key < 32) || (key >= 128))
return 0;
return key;
@@ -133,41 +194,6 @@ int16 Util::checkKey(void) {
return translateKey(key);
}
-int16 Util::getRandom(int16 max) {
- return _vm->_rnd.getRandomNumber(max - 1);
-}
-
-void Util::processInput() {
- Common::Event event;
- Common::EventManager *eventMan = g_system->getEventManager();
- while (eventMan->pollEvent(event)) {
- switch (event.type) {
- case Common::EVENT_LBUTTONDOWN:
- _mouseButtons |= 1;
- break;
- case Common::EVENT_RBUTTONDOWN:
- _mouseButtons |= 2;
- break;
- case Common::EVENT_LBUTTONUP:
- _mouseButtons &= ~1;
- break;
- case Common::EVENT_RBUTTONUP:
- _mouseButtons &= ~2;
- break;
- case Common::EVENT_KEYDOWN:
- addKeyToBuffer(event.kbd.keycode);
- break;
- case Common::EVENT_KEYUP:
- break;
- case Common::EVENT_QUIT:
- _vm->_quitRequested = true;
- break;
- default:
- break;
- }
- }
-}
-
void Util::getMouseState(int16 *pX, int16 *pY, int16 *pButtons) {
Common::Point mouse = g_system->getEventManager()->getMousePos();
*pX = mouse.x;
@@ -181,52 +207,60 @@ void Util::setMousePos(int16 x, int16 y) {
g_system->warpMouse(x, y);
}
-void Util::longDelay(uint16 msecs) {
- uint32 time = g_system->getMillis() + msecs;
+void Util::waitMouseUp(void) {
do {
- _vm->_video->waitRetrace(_vm->_global->_videoMode);
processInput();
- delay(15);
- } while (!_vm->_quitRequested && (g_system->getMillis() < time));
-}
-
-void Util::delay(uint16 msecs) {
- g_system->delayMillis(msecs);
-}
-
-void Util::beep(int16 freq) {
- if (_vm->_global->_soundFlags == 0)
- return;
-
- _vm->_snd->speakerOn(freq, 50);
+ if (_mouseButtons != 0)
+ delay(10);
+ } while (_mouseButtons != 0);
}
-uint32 Util::getTimeKey(void) {
- return g_system->getMillis();
-}
+void Util::waitMouseDown(void) {
+ int16 x;
+ int16 y;
+ int16 buttons;
-void Util::waitMouseUp(void) {
do {
processInput();
- if (_mouseButtons != 0) delay(10);
- } while (_mouseButtons != 0);
+ getMouseState(&x, &y, &buttons);
+ if (buttons == 0)
+ delay(10);
+ } while (buttons == 0);
}
-void Util::waitMouseDown(void) {
+void Util::waitMouseRelease(char drawMouse) {
+ int16 buttons;
+ int16 mouseX;
+ int16 mouseY;
+
do {
- processInput();
- if (_mouseButtons == 0) delay(10);
- } while (_mouseButtons == 0);
+ _vm->_game->checkKeys(&mouseX, &mouseY, &buttons, drawMouse);
+ if (drawMouse != 0)
+ _vm->_draw->animateCursor(2);
+ delay(10);
+ } while (buttons != 0);
}
-/* NOT IMPLEMENTED */
-int16 Util::calcDelayTime() {
- return 0;
+void Util::forceMouseUp(void) {
+ _vm->_game->_mouseButtons = 0;
+ _mouseButtons = 0;
}
-/* NOT IMPLEMENTED */
-void Util::checkJoystick() {
- _vm->_global->_useJoystick = 0;
+void Util::clearPalette(void) {
+ int16 i;
+ byte colors[768];
+
+ _vm->validateVideoMode(_vm->_global->_videoMode);
+
+ if (_vm->_global->_setAllPalette) {
+ for (i = 0; i < 768; i++)
+ colors[i] = 0;
+ g_system->setPalette(colors, 0, 256);
+ return;
+ }
+
+ for (i = 0; i < 16; i++)
+ _vm->_video->setPalElem(i, 0, 0, 0, 0, _vm->_global->_videoMode);
}
void Util::setFrameRate(int16 rate) {
@@ -235,7 +269,7 @@ void Util::setFrameRate(int16 rate) {
_vm->_global->_frameWaitTime = 1000 / rate;
_vm->_global->_startFrameTime = getTimeKey();
- _vm->_game->_dword_2F2B6 = 0;
+ _vm->_imdPlayer->_frameDelay = 0;
}
void Util::waitEndFrame() {
@@ -244,42 +278,43 @@ void Util::waitEndFrame() {
_vm->_video->waitRetrace(_vm->_global->_videoMode);
time = getTimeKey() - _vm->_global->_startFrameTime;
- if (time > 1000 || time < 0) {
+ if ((time > 1000) || (time < 0)) {
_vm->_global->_startFrameTime = getTimeKey();
- _vm->_game->_dword_2F2B6 = 0;
+ _vm->_imdPlayer->_frameDelay = 0;
return;
}
+
if (_vm->_global->_frameWaitTime - time > 0) {
- _vm->_game->_dword_2F2B6 = 0;
- delay(_vm->_global->_frameWaitTime - _vm->_game->_dword_2F2B6 - time);
+ _vm->_imdPlayer->_frameDelay = 0;
+ delay(_vm->_global->_frameWaitTime - _vm->_imdPlayer->_frameDelay - time);
}
- _vm->_global->_startFrameTime = getTimeKey();
- _vm->_game->_dword_2F2B6 = time - _vm->_global->_frameWaitTime;
-}
-int16 joy_getState() {
- return 0;
+ _vm->_global->_startFrameTime = getTimeKey();
+ _vm->_imdPlayer->_frameDelay = time - _vm->_global->_frameWaitTime;
}
-int16 joy_calibrate() {
- return 0;
+void Util::setScrollOffset(int16 x, int16 y) {
+ processInput();
+ _vm->_video->_scrollOffsetX = x >= 0 ? x : _vm->_draw->_scrollOffsetX;
+ _vm->_video->_scrollOffsetY = y >= 0 ? y : _vm->_draw->_scrollOffsetY;
+ _vm->_video->waitRetrace(_vm->_global->_videoMode);
}
Video::FontDesc *Util::loadFont(const char *path) {
Video::FontDesc *fontDesc = new Video::FontDesc;
char *data;
- if (fontDesc == 0)
+ if (!fontDesc)
return 0;
- data = _vm->_dataio->getData(path);
- if (data == 0) {
+ data = _vm->_dataIO->getData(path);
+ if (!data) {
delete fontDesc;
return 0;
}
fontDesc->dataPtr = data + 4;
- fontDesc->itemWidth = data[0] & 0x7f;
+ fontDesc->itemWidth = data[0] & 0x7F;
fontDesc->itemHeight = data[1];
fontDesc->startItem = data[2];
fontDesc->endItem = data[3];
@@ -289,85 +324,90 @@ Video::FontDesc *Util::loadFont(const char *path) {
fontDesc->bitWidth = fontDesc->itemWidth;
if (data[0] & 0x80)
- fontDesc->extraData =
- data + 4 + fontDesc->itemSize * (fontDesc->endItem -
- fontDesc->startItem + 1);
+ fontDesc->extraData = data + 4 + fontDesc->itemSize *
+ (fontDesc->endItem - fontDesc->startItem + 1);
else
fontDesc->extraData = 0;
+
return fontDesc;
}
-void Util::freeFont(Video::FontDesc * fontDesc) {
+void Util::freeFont(Video::FontDesc *fontDesc) {
delete[] (fontDesc->dataPtr - 4);
delete fontDesc;
}
-void Util::clearPalette(void) {
- int16 i;
- byte colors[768];
-
- if ((_vm->_global->_videoMode != 0x13) && (_vm->_global->_videoMode != 0x14))
- error("clearPalette: Video mode 0x%x is not supported!",
- _vm->_global->_videoMode);
-
- if (_vm->_global->_setAllPalette) {
- for (i = 0; i < 768; i++)
- colors[i] = 0;
- g_system->setPalette(colors, 0, 256);
-
- return;
- }
-
- for (i = 0; i < 16; i++)
- _vm->_video->setPalElem(i, 0, 0, 0, 0, _vm->_global->_videoMode);
-}
-
void Util::insertStr(const char *str1, char *str2, int16 pos) {
- int16 len1;
- int16 i;
- int16 from;
-
- i = strlen(str2);
- len1 = strlen(str1);
- if (pos < i)
- from = pos;
- else
- from = i;
+ int len1 = strlen(str1);
+ int len2 = strlen(str2);
+ int from = MIN((int) pos, len2);
- for (; i >= from; i--)
+ for (int i = len2; i >= from; i--)
str2[len1 + i] = str2[i];
-
- for (i = 0; i < len1; i++)
+ for (int i = 0; i < len1; i++)
str2[i + from] = str1[i];
}
void Util::cutFromStr(char *str, int16 from, int16 cutlen) {
- int16 len;
- int16 i;
+ int len = strlen(str);
- //log_write("cutFromStr: str = %s, ", str);
- len = strlen(str);
if (from >= len)
return;
- if (from + cutlen > len) {
+ if ((from + cutlen) > len) {
str[from] = 0;
- //log_write("res = %s\n", str);
return;
}
- i = from;
+ int i = from;
do {
str[i] = str[i + cutlen];
i++;
} while (str[i] != 0);
- //log_write("res = %s\n", str);
}
-void Util::listInsertFront(List * list, void *data) {
+static const char trStr1[] =
+ " ' + - :0123456789: <=> abcdefghijklmnopqrstuvwxyz "
+ "abcdefghijklmnopqrstuvwxyz ";
+static const char trStr2[] =
+ " ueaaaaceeeiii ooouu aioun"
+ " ";
+static const char trStr3[] = " ";
+
+void Util::prepareStr(char *str) {
+ char *start, *end;
+ char buf[300];
+
+ strcpy(buf, trStr1);
+ strcat(buf, trStr2);
+ strcat(buf, trStr3);
+
+ for (size_t i = 0; i < strlen(str); i++)
+ str[i] = buf[str[i] - 32];
+
+ while (str[0] == ' ')
+ cutFromStr(str, 0, 1);
+
+ while ((strlen(str) > 0) && (str[strlen(str) - 1] == ' '))
+ cutFromStr(str, strlen(str) - 1, 1);
+
+ start = strchr(str, ' ');
+
+ while (start) {
+ if (start[1] == ' ') {
+ cutFromStr(str, start - str, 1);
+ continue;
+ }
+
+ end = strchr(start + 1, ' ');
+ start = end ? end + 1 : 0;
+ }
+}
+
+void Util::listInsertFront(List *list, void *data) {
ListNode *node;
node = new ListNode;
- if (list->pHead != 0) {
+ if (list->pHead) {
node->pData = data;
node->pNext = list->pHead;
node->pPrev = 0;
@@ -382,7 +422,7 @@ void Util::listInsertFront(List * list, void *data) {
}
}
-void Util::listInsertBack(List * list, void *data) {
+void Util::listInsertBack(List *list, void *data) {
ListNode *node;
if (list->pHead != 0) {
@@ -397,12 +437,11 @@ void Util::listInsertBack(List * list, void *data) {
node->pNext = 0;
list->pTail->pNext = node;
list->pTail = node;
- } else {
+ } else
listInsertFront(list, data);
- }
}
-void Util::listDropFront(List * list) {
+void Util::listDropFront(List *list) {
if (list->pHead->pNext == 0) {
delete list->pHead;
list->pHead = 0;
@@ -414,77 +453,16 @@ void Util::listDropFront(List * list) {
}
}
-void Util::deleteList(List * list) {
- while (list->pHead != 0) {
+void Util::deleteList(List *list) {
+ while (list->pHead)
listDropFront(list);
- }
delete list;
}
-static const char trStr1[] =
- " ' + - :0123456789: <=> abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz ";
-static const char trStr2[] =
- " ueaaaaceeeiii ooouu aioun ";
-static const char trStr3[] = " ";
-
-void Util::prepareStr(char *str) {
- uint16 i;
- char *start, *end;
- char buf[300];
-
- strcpy(buf, trStr1);
- strcat(buf, trStr2);
- strcat(buf, trStr3);
-
- for (i = 0; i < strlen(str); i++)
- str[i] = buf[str[i] - 32];
-
- while (str[0] == ' ')
- cutFromStr(str, 0, 1);
-
- while (strlen(str) > 0 && str[strlen(str) - 1] == ' ')
- cutFromStr(str, strlen(str) - 1, 1);
-
- start = strchr(str, ' ');
-
- while (start != 0) {
- if (*(start+1) == ' ') {
- cutFromStr(str, start - str, 1);
- continue;
- }
-
- end = strchr(start + 1, ' ');
- if (end != 0)
- start = end + 1;
- else
- start = 0;
- }
-}
-
-void Util::waitMouseRelease(char drawMouse) {
- int16 buttons;
- int16 mouseX;
- int16 mouseY;
-
- do {
- _vm->_game->checkKeys(&mouseX, &mouseY, &buttons, drawMouse);
- if (drawMouse != 0)
- _vm->_draw->animateCursor(2);
- delay(10);
- } while (buttons != 0);
-}
-
-void Util::forceMouseUp(void) {
- _vm->_game->_mouseButtons = 0;
- _mouseButtons = 0;
-}
-
-void Util::setScrollOffset(int16 x, int16 y) {
- processInput();
- _vm->_video->_scrollOffsetX = x >= 0 ? x : _vm->_draw->_scrollOffsetX;
- _vm->_video->_scrollOffsetY = y >= 0 ? y : _vm->_draw->_scrollOffsetY;
- _vm->_video->waitRetrace(_vm->_global->_videoMode);
+/* NOT IMPLEMENTED */
+void Util::checkJoystick() {
+ _vm->_global->_useJoystick = 0;
}
} // End of namespace Gob