aboutsummaryrefslogtreecommitdiff
path: root/engines/mortevielle
diff options
context:
space:
mode:
authorPaul Gilbert2012-01-17 23:52:36 +1100
committerStrangerke2012-04-06 08:19:49 +0200
commitd0129ad88bda4d1aa39f8e778c42343b4c0030f6 (patch)
treec85e84eb93857fda3b5c1e648db5475de51293c5 /engines/mortevielle
parent8c423fd790cfb200852d5de4a707817f07489195 (diff)
downloadscummvm-rg350-d0129ad88bda4d1aa39f8e778c42343b4c0030f6.tar.gz
scummvm-rg350-d0129ad88bda4d1aa39f8e778c42343b4c0030f6.tar.bz2
scummvm-rg350-d0129ad88bda4d1aa39f8e778c42343b4c0030f6.zip
MORTEVIELLE: Implemented a basic event handler.
Diffstat (limited to 'engines/mortevielle')
-rw-r--r--engines/mortevielle/graphics.cpp8
-rw-r--r--engines/mortevielle/keyboard.cpp2
-rw-r--r--engines/mortevielle/mor2.cpp3
-rw-r--r--engines/mortevielle/mort.cpp12
-rw-r--r--engines/mortevielle/mort.h2
-rw-r--r--engines/mortevielle/mortevielle.cpp77
-rw-r--r--engines/mortevielle/mortevielle.h12
-rw-r--r--engines/mortevielle/ovd1.cpp3
-rw-r--r--engines/mortevielle/var_mor.cpp4
9 files changed, 105 insertions, 18 deletions
diff --git a/engines/mortevielle/graphics.cpp b/engines/mortevielle/graphics.cpp
index 8e4ad338df..e6035bb114 100644
--- a/engines/mortevielle/graphics.cpp
+++ b/engines/mortevielle/graphics.cpp
@@ -66,7 +66,7 @@ void PaletteManager::setPalette(const int *palette, uint idx, uint size) {
*/
void PaletteManager::setDefaultPalette() {
/*
- int defaultPalette[16] = { 0, 1, 2, 3, 4, 5, 7, 20, 56, 57, 58, 59, 60, 61, 62, 63 };
+ int defaultPalette[16] = { 0, 1, 2, 3, 4, 5, 20, 7, 56, 57, 58, 59, 60, 61, 62, 63 };
setPalette(defaultPalette, 0, 16);
*/
// TODO: Replace with proper palette
@@ -933,9 +933,6 @@ void ScreenSurface::drawPicture(GfxSurface &surface, int x, int y) {
++pDest;
}
}
-
- // TODO: Remove this once we have a proper game loop
- updateScreen();
}
/**
@@ -986,9 +983,6 @@ void ScreenSurface::drawBox(int x, int y, int dx, int dy, int col) {
destSurface.vLine(1, 2, destSurface.h - 3, col);
destSurface.vLine(dx - 1, 2, destSurface.h - 3, col);
destSurface.vLine(dx - 2, 2, destSurface.h - 3, col);
-
- // TODO: Remove this once we have a proper game loop
- updateScreen();
}
diff --git a/engines/mortevielle/keyboard.cpp b/engines/mortevielle/keyboard.cpp
index dae117e110..4eba4c4a0d 100644
--- a/engines/mortevielle/keyboard.cpp
+++ b/engines/mortevielle/keyboard.cpp
@@ -49,6 +49,7 @@ int testou() {
case '\23' :
sonoff = ! sonoff;
break;
+ /* Prevent changing graphics mode
case '\1':
case '\3':
case '\5' : {
@@ -69,6 +70,7 @@ int testou() {
return testou_result;
}
break;
+ */
case '\26' :
if ((c_zzz == 1) && (c_zzz == 2)) {
zzuul(&adcfiec[161 * 16], ((822 * 128) - (161 * 16)) / 64);
diff --git a/engines/mortevielle/mor2.cpp b/engines/mortevielle/mor2.cpp
index 1c2936d188..2f0793643c 100644
--- a/engines/mortevielle/mor2.cpp
+++ b/engines/mortevielle/mor2.cpp
@@ -31,6 +31,7 @@
#include "mortevielle/keyboard.h"
#include "mortevielle/menu.h"
#include "mortevielle/mor.h"
+#include "mortevielle/mortevielle.h"
#include "mortevielle/mouse.h"
#include "mortevielle/outtext.h"
#include "mortevielle/parole2.h"
@@ -275,6 +276,7 @@ void mfouen()
void atf3f8(int &key) {
do {
key = testou();
+ CHECK_QUIT;
} while (!((key == 61) || (key == 66)));
}
@@ -394,6 +396,7 @@ void sparl(float adr, float rep) {
do {
parole(repint, haut[caff - 69], 0);
atf3f8(key);
+ CHECK_QUIT;
} while (!(key == 66));
hirs();
show_mouse();
diff --git a/engines/mortevielle/mort.cpp b/engines/mortevielle/mort.cpp
index e24e9b58f9..fc592f98fe 100644
--- a/engines/mortevielle/mort.cpp
+++ b/engines/mortevielle/mort.cpp
@@ -26,6 +26,7 @@
*/
#include "mortevielle/mort.h"
+#include "mortevielle/mortevielle.h"
#include "mortevielle/var_mor.h" /* les variables */ //Translation: Variables
#include "mortevielle/asm.h"
#include "mortevielle/keyboard.h" /* la gestion du clavier */ //Translation: Keyboard manager
@@ -57,6 +58,8 @@ void divers(int np, bool b) {
do {
parole(np, 0, 0);
atf3f8(key);
+ CHECK_QUIT;
+
if (newgd != gd) {
gd = newgd;
hirs();
@@ -67,7 +70,7 @@ void divers(int np, bool b) {
/* NIVEAU 0 */
-int mortevielle_main(int argc, const char *argv[]) {
+void mortevielle_main() {
/*init_debug;*/
/* ecri_seg;*/
//pio_initialize(argc, argv);
@@ -116,9 +119,12 @@ int mortevielle_main(int argc, const char *argv[]) {
aff50(false);
mlec = 0;
divers(142, false);
+ CHECK_QUIT;
ani50();
divers(143, true);
+ CHECK_QUIT;
+
suite();
music();
adzon();
@@ -137,10 +143,6 @@ int mortevielle_main(int argc, const char *argv[]) {
do {
tjouer();
} while (!arret);
- hide_mouse();
- clrscr;
- /*out_debug;*/
- return EXIT_SUCCESS;
}
} // End of namespace Mortevielle
diff --git a/engines/mortevielle/mort.h b/engines/mortevielle/mort.h
index 8523774da6..d313e32b78 100644
--- a/engines/mortevielle/mort.h
+++ b/engines/mortevielle/mort.h
@@ -32,7 +32,7 @@ namespace Mortevielle {
extern void divers(int np, bool b);
/* NIVEAU 0 */
-extern int mortevielle_main(int argc, const char *argv[]);
+extern void mortevielle_main();
} // End of namespace Mortevielle
diff --git a/engines/mortevielle/mortevielle.cpp b/engines/mortevielle/mortevielle.cpp
index 8346c3f9e7..6797a7e649 100644
--- a/engines/mortevielle/mortevielle.cpp
+++ b/engines/mortevielle/mortevielle.cpp
@@ -28,6 +28,7 @@
#include "graphics/pixelformat.h"
#include "mortevielle/mortevielle.h"
#include "mortevielle/mort.h"
+#include "mortevielle/mouse.h"
#include "mortevielle/var_mor.h"
namespace Mortevielle {
@@ -37,6 +38,7 @@ MortevielleEngine *g_vm;
MortevielleEngine::MortevielleEngine(OSystem *system, const ADGameDescription *gameDesc):
Engine(system), _gameDescription(gameDesc) {
g_vm = this;
+ _lastGameFrame = 0;
}
MortevielleEngine::~MortevielleEngine() {
@@ -113,6 +115,78 @@ Common::ErrorCode MortevielleEngine::loadMortDat() {
return Common::kNoError;
}
+bool MortevielleEngine::keyPressed() {
+ // Check for any pending key presses
+ handleEvents();
+
+ // Check if it's time to draw the next frame
+ if (g_system->getMillis() > (_lastGameFrame + GAME_FRAME_DELAY)) {
+ _lastGameFrame = g_system->getMillis();
+
+ g_vm->_screenSurface.updateScreen();
+ }
+
+ // Delay briefly to keep CPU usage down
+ g_system->delayMillis(5);
+
+ // Return if there are any pending key presses
+ return !_keypresses.empty();
+}
+
+int MortevielleEngine::getChar() {
+ // If there isn't any pending keypress, wait until there is
+ while (!shouldQuit() && _keypresses.empty()) {
+ keypressed();
+ }
+
+ // Return the top keypress
+ return shouldQuit() ? 0 : _keypresses.pop();
+}
+
+bool MortevielleEngine::handleEvents() {
+ Common::Event event;
+ if (!g_system->getEventManager()->pollEvent(event))
+ return false;
+
+ switch (event.type) {
+ case Common::EVENT_LBUTTONDOWN:
+ case Common::EVENT_LBUTTONUP:
+ case Common::EVENT_RBUTTONDOWN:
+ case Common::EVENT_RBUTTONUP:
+ case Common::EVENT_MBUTTONDOWN:
+ case Common::EVENT_MBUTTONUP:
+ case Common::EVENT_MOUSEMOVE:
+ x_s = event.mouse.x;
+ y_s = event.mouse.y;
+ break;
+
+ case Common::EVENT_KEYDOWN:
+ addKeypress(event);
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+/**
+ * Add the specified key to the event queue
+ */
+void MortevielleEngine::addKeypress(Common::Event &evt) {
+ // Check for control keypresses
+ if (evt.kbd.hasFlags(Common::KBD_CTRL) && (evt.kbd.keycode >= Common::KEYCODE_a) &&
+ (evt.kbd.keycode <= Common::KEYCODE_z)) {
+ _keypresses.push(evt.kbd.keycode - Common::KEYCODE_a + 1);
+ return;
+ }
+
+ // Handle function keys
+ if ((evt.kbd.keycode >= Common::KEYCODE_F1) && (evt.kbd.keycode <= Common::KEYCODE_F12)) {
+ _keypresses.push(59 + evt.kbd.keycode - Common::KEYCODE_F1);
+ }
+}
+
/*-------------------------------------------------------------------------*/
Common::Error MortevielleEngine::run() {
@@ -125,8 +199,7 @@ Common::Error MortevielleEngine::run() {
_paletteManager.setDefaultPalette();
// Dispatch to the game's main routine
- const char *argv[] = { "" };
- mortevielle_main(1, argv);
+ mortevielle_main();
return Common::kNoError;
}
diff --git a/engines/mortevielle/mortevielle.h b/engines/mortevielle/mortevielle.h
index 816a4360cc..c00561d54d 100644
--- a/engines/mortevielle/mortevielle.h
+++ b/engines/mortevielle/mortevielle.h
@@ -23,8 +23,10 @@
#ifndef MORTEVIELLE_H
#define MORTEVIELLE_H
+#include "common/events.h"
#include "common/file.h"
#include "common/rect.h"
+#include "common/stack.h"
#include "engines/advancedDetector.h"
#include "engines/engine.h"
#include "common/error.h"
@@ -42,14 +44,19 @@ enum {
#define SCREEN_HEIGHT 400
#define MORT_DAT_REQUIRED_VERSION 1
#define MORT_DAT "mort.dat"
+#define GAME_FRAME_DELAY (1000 / 50)
class MortevielleEngine : public Engine {
private:
const ADGameDescription *_gameDescription;
+ Common::Stack<int> _keypresses;
+ uint32 _lastGameFrame;
Common::ErrorCode initialise();
Common::ErrorCode loadMortDat();
void loadFont(Common::File &f);
+ bool handleEvents();
+ void addKeypress(Common::Event &evt);
public:
ScreenSurface _screenSurface;
PaletteManager _paletteManager;
@@ -59,10 +66,15 @@ public:
virtual bool hasFeature(EngineFeature f) const;
virtual Common::Error run();
uint32 getGameFlags() const;
+
+ bool keyPressed();
+ int getChar();
};
extern MortevielleEngine *g_vm;
+#define CHECK_QUIT if (g_vm->shouldQuit()) { return; }
+
} // End of namespace Mortevielle
#endif
diff --git a/engines/mortevielle/ovd1.cpp b/engines/mortevielle/ovd1.cpp
index 89dde415df..50d7e0fe54 100644
--- a/engines/mortevielle/ovd1.cpp
+++ b/engines/mortevielle/ovd1.cpp
@@ -246,9 +246,10 @@ void ani50() {
output(delig);
} while (!(cy == 20));
ix = 0;
- do {
+/* do {
ix = ix + 1;
} while (!(keypressed() | (ix == 5e5)));
+*/
crep = 998;
textcolor(1);
gotoxy(1, 21);
diff --git a/engines/mortevielle/var_mor.cpp b/engines/mortevielle/var_mor.cpp
index 5cca06f011..1b742a75e2 100644
--- a/engines/mortevielle/var_mor.cpp
+++ b/engines/mortevielle/var_mor.cpp
@@ -372,10 +372,10 @@ int get_random_number(int minval, int maxval) {
}
bool keypressed() {
- return false; // Hardcoded currently for no keypress pending
+ return g_vm->keyPressed();
}
char get_ch() {
- return '\0'; // hardcoded currently for no keypress
+ return g_vm->getChar();
}
void palette(int v1) {