Skip to content

Commit

Permalink
ZVISION: Move some event/rendering code out of the main engine code
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegr committed Dec 26, 2014
1 parent 4258750 commit 5a72eea
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 122 deletions.
37 changes: 32 additions & 5 deletions engines/zvision/core/events.cpp
Expand Up @@ -39,6 +39,33 @@

namespace ZVision {

void ZVision::pushKeyToCheatBuf(uint8 key) {
for (int i = 0; i < KEYBUF_SIZE - 1; i++)
_cheatBuffer[i] = _cheatBuffer[i + 1];

_cheatBuffer[KEYBUF_SIZE - 1] = key;
}

bool ZVision::checkCode(const char *code) {
int codeLen = strlen(code);

if (codeLen > KEYBUF_SIZE)
return false;

for (int i = 0; i < codeLen; i++)
if (code[i] != _cheatBuffer[KEYBUF_SIZE - codeLen + i] && code[i] != '?')
return false;

return true;
}

uint8 ZVision::getBufferedKey(uint8 pos) {
if (pos >= KEYBUF_SIZE)
return 0;
else
return _cheatBuffer[KEYBUF_SIZE - pos - 1];
}

void ZVision::shortKeys(Common::Event event) {
if (event.kbd.hasFlags(Common::KBD_CTRL)) {
switch (event.kbd.keycode) {
Expand Down Expand Up @@ -70,11 +97,11 @@ void ZVision::cheatCodes(uint8 key) {
if (getGameId() == GID_GRANDINQUISITOR) {
if (checkCode("IMNOTDEAF")) {
// Unknown cheat
showDebugMsg(Common::String::format("IMNOTDEAF cheat or debug, not implemented"));
_renderManager->showDebugMsg(Common::String::format("IMNOTDEAF cheat or debug, not implemented"));
}

if (checkCode("3100OPB")) {
showDebugMsg(Common::String::format("Current location: %c%c%c%c",
_renderManager->showDebugMsg(Common::String::format("Current location: %c%c%c%c",
_scriptManager->getStateValue(StateKey_World),
_scriptManager->getStateValue(StateKey_Room),
_scriptManager->getStateValue(StateKey_Node),
Expand All @@ -101,7 +128,7 @@ void ZVision::cheatCodes(uint8 key) {
}

if (checkCode("77MASSAVE")) {
showDebugMsg(Common::String::format("Current location: %c%c%c%c",
_renderManager->showDebugMsg(Common::String::format("Current location: %c%c%c%c",
_scriptManager->getStateValue(StateKey_World),
_scriptManager->getStateValue(StateKey_Room),
_scriptManager->getStateValue(StateKey_Node),
Expand Down Expand Up @@ -131,13 +158,13 @@ void ZVision::cheatCodes(uint8 key) {
}

if (checkCode("FRAME"))
showDebugMsg(Common::String::format("FPS: ???, not implemented"));
_renderManager->showDebugMsg(Common::String::format("FPS: ???, not implemented"));

if (checkCode("XYZZY"))
_scriptManager->setStateValue(StateKey_DebugCheats, 1 - _scriptManager->getStateValue(StateKey_DebugCheats));

if (checkCode("COMPUTERARCH"))
showDebugMsg(Common::String::format("COMPUTERARCH: var-viewer not implemented"));
_renderManager->showDebugMsg(Common::String::format("COMPUTERARCH: var-viewer not implemented"));

if (_scriptManager->getStateValue(StateKey_DebugCheats) == 1)
if (checkCode("GO????"))
Expand Down
82 changes: 80 additions & 2 deletions engines/zvision/graphics/render_manager.cpp
Expand Up @@ -39,7 +39,7 @@

namespace ZVision {

RenderManager::RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat)
RenderManager::RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat, bool doubleFPS)
: _engine(engine),
_system(engine->_system),
_workingWidth(workingWindow.width()),
Expand All @@ -51,7 +51,8 @@ RenderManager::RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowH
_backgroundWidth(0),
_backgroundHeight(0),
_backgroundOffset(0),
_renderTable(_workingWidth, _workingHeight) {
_renderTable(_workingWidth, _workingHeight),
_doubleFPS(doubleFPS) {

_backgroundSurface.create(_workingWidth, _workingHeight, _pixelFormat);
_effectSurface.create(_workingWidth, _workingHeight, _pixelFormat);
Expand Down Expand Up @@ -1013,4 +1014,81 @@ void RenderManager::bkgFill(uint8 r, uint8 g, uint8 b) {
}
#endif

void RenderManager::timedMessage(const Common::String &str, uint16 milsecs) {
uint16 msgid = createSubArea();
updateSubArea(msgid, str);
processSubs(0);
renderSceneToScreen();
deleteSubArea(msgid, milsecs);
}

bool RenderManager::askQuestion(const Common::String &str) {
uint16 msgid = createSubArea();
updateSubArea(msgid, str);
processSubs(0);
renderSceneToScreen();
_engine->stopClock();

int result = 0;

while (result == 0) {
Common::Event evnt;
while (_engine->getEventManager()->pollEvent(evnt)) {
if (evnt.type == Common::EVENT_KEYDOWN) {
switch (evnt.kbd.keycode) {
case Common::KEYCODE_y:
result = 2;
break;
case Common::KEYCODE_n:
result = 1;
break;
default:
break;
}
}
}
_system->updateScreen();
if (_doubleFPS)
_system->delayMillis(33);
else
_system->delayMillis(66);
}
deleteSubArea(msgid);
_engine->startClock();
return result == 2;
}

void RenderManager::delayedMessage(const Common::String &str, uint16 milsecs) {
uint16 msgid = createSubArea();
updateSubArea(msgid, str);
processSubs(0);
renderSceneToScreen();
_engine->stopClock();

uint32 stopTime = _system->getMillis() + milsecs;
while (_system->getMillis() < stopTime) {
Common::Event evnt;
while (_engine->getEventManager()->pollEvent(evnt)) {
if (evnt.type == Common::EVENT_KEYDOWN &&
(evnt.kbd.keycode == Common::KEYCODE_SPACE ||
evnt.kbd.keycode == Common::KEYCODE_RETURN ||
evnt.kbd.keycode == Common::KEYCODE_ESCAPE))
break;
}
_system->updateScreen();
if (_doubleFPS)
_system->delayMillis(33);
else
_system->delayMillis(66);
}
deleteSubArea(msgid);
_engine->startClock();
}

void RenderManager::showDebugMsg(const Common::String &msg, int16 delay) {
uint16 msgid = createSubArea();
updateSubArea(msgid, msg);
deleteSubArea(msgid, delay);
}

} // End of namespace ZVision
8 changes: 7 additions & 1 deletion engines/zvision/graphics/render_manager.h
Expand Up @@ -48,7 +48,7 @@ namespace ZVision {

class RenderManager {
public:
RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat);
RenderManager(ZVision *engine, uint32 windowWidth, uint32 windowHeight, const Common::Rect workingWindow, const Graphics::PixelFormat pixelFormat, bool doubleFPS);
~RenderManager();

private:
Expand Down Expand Up @@ -137,6 +137,7 @@ class RenderManager {
// Visual effects list
EffectsList _effects;

bool _doubleFPS;

public:
void initialize();
Expand Down Expand Up @@ -334,6 +335,11 @@ class RenderManager {
// Fill background surface by color
void bkgFill(uint8 r, uint8 g, uint8 b);
#endif

bool askQuestion(const Common::String &str);
void delayedMessage(const Common::String &str, uint16 milsecs);
void timedMessage(const Common::String &str, uint16 milsecs);
void showDebugMsg(const Common::String &msg, int16 delay = 3000);
};

} // End of namespace ZVision
Expand Down
7 changes: 4 additions & 3 deletions engines/zvision/scripting/controls/save_control.cpp
Expand Up @@ -30,6 +30,7 @@
#include "zvision/text/string_manager.h"

#include "zvision/file/save_manager.h"
#include "zvision/graphics/render_manager.h"

#include "common/str.h"
#include "common/stream.h"
Expand Down Expand Up @@ -97,18 +98,18 @@ bool SaveControl::process(uint32 deltaTimeInMillis) {
if (inp->getText().size() > 0) {
bool toSave = true;
if (iter->exist)
if (!_engine->askQuestion(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVEEXIST)))
if (!_engine->getRenderManager()->askQuestion(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVEEXIST)))
toSave = false;

if (toSave) {
// FIXME: At this point, the screen shows the save control, so the save game thumbnails will always
// show the save control
_engine->getSaveManager()->saveGameBuffered(iter->saveId, inp->getText());
_engine->delayedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVED), 2000);
_engine->getRenderManager()->delayedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVED), 2000);
_engine->getScriptManager()->changeLocation(_engine->getScriptManager()->getLastMenuLocation());
}
} else {
_engine->timedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVEEMPTY), 2000);
_engine->getRenderManager()->timedMessage(_engine->getStringManager()->getTextLine(StringManager::ZVISION_STR_SAVEEMPTY), 2000);
}
} else {
_engine->getSaveManager()->loadGame(iter->saveId);
Expand Down
108 changes: 2 additions & 106 deletions engines/zvision/zvision.cpp
Expand Up @@ -190,7 +190,7 @@ void ZVision::initialize() {

// Create managers
_scriptManager = new ScriptManager(this);
_renderManager = new RenderManager(this, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _resourcePixelFormat);
_renderManager = new RenderManager(this, WINDOW_WIDTH, WINDOW_HEIGHT, _workingWindow, _resourcePixelFormat, _doubleFPS);
_saveManager = new SaveManager(this);
_stringManager = new StringManager(this);
_cursorManager = new CursorManager(this, _resourcePixelFormat);
Expand Down Expand Up @@ -265,77 +265,6 @@ Common::Error ZVision::run() {
return Common::kNoError;
}

bool ZVision::askQuestion(const Common::String &str) {
uint16 msgid = _renderManager->createSubArea();
_renderManager->updateSubArea(msgid, str);
_renderManager->processSubs(0);
_renderManager->renderSceneToScreen();
_clock.stop();

int result = 0;

while (result == 0) {
Common::Event evnt;
while (_eventMan->pollEvent(evnt)) {
if (evnt.type == Common::EVENT_KEYDOWN) {
switch (evnt.kbd.keycode) {
case Common::KEYCODE_y:
result = 2;
break;
case Common::KEYCODE_n:
result = 1;
break;
default:
break;
}
}
}
_system->updateScreen();
if (_doubleFPS)
_system->delayMillis(33);
else
_system->delayMillis(66);
}
_renderManager->deleteSubArea(msgid);
_clock.start();
return result == 2;
}

void ZVision::delayedMessage(const Common::String &str, uint16 milsecs) {
uint16 msgid = _renderManager->createSubArea();
_renderManager->updateSubArea(msgid, str);
_renderManager->processSubs(0);
_renderManager->renderSceneToScreen();
_clock.stop();

uint32 stopTime = _system->getMillis() + milsecs;
while (_system->getMillis() < stopTime) {
Common::Event evnt;
while (_eventMan->pollEvent(evnt)) {
if (evnt.type == Common::EVENT_KEYDOWN &&
(evnt.kbd.keycode == Common::KEYCODE_SPACE ||
evnt.kbd.keycode == Common::KEYCODE_RETURN ||
evnt.kbd.keycode == Common::KEYCODE_ESCAPE))
break;
}
_system->updateScreen();
if (_doubleFPS)
_system->delayMillis(33);
else
_system->delayMillis(66);
}
_renderManager->deleteSubArea(msgid);
_clock.start();
}

void ZVision::timedMessage(const Common::String &str, uint16 milsecs) {
uint16 msgid = _renderManager->createSubArea();
_renderManager->updateSubArea(msgid, str);
_renderManager->processSubs(0);
_renderManager->renderSceneToScreen();
_renderManager->deleteSubArea(msgid, milsecs);
}

void ZVision::pauseEngineIntern(bool pause) {
_mixer->pauseAll(pause);

Expand Down Expand Up @@ -506,44 +435,11 @@ uint16 ZVision::getMenuBarEnable() {
}

bool ZVision::ifQuit() {
if (askQuestion(_stringManager->getTextLine(StringManager::ZVISION_STR_EXITPROMT))) {
if (_renderManager->askQuestion(_stringManager->getTextLine(StringManager::ZVISION_STR_EXITPROMT))) {
quitGame();
return true;
}
return false;
}

void ZVision::pushKeyToCheatBuf(uint8 key) {
for (int i = 0; i < KEYBUF_SIZE - 1; i++)
_cheatBuffer[i] = _cheatBuffer[i + 1];

_cheatBuffer[KEYBUF_SIZE - 1] = key;
}

bool ZVision::checkCode(const char *code) {
int codeLen = strlen(code);

if (codeLen > KEYBUF_SIZE)
return false;

for (int i = 0; i < codeLen; i++)
if (code[i] != _cheatBuffer[KEYBUF_SIZE - codeLen + i] && code[i] != '?')
return false;

return true;
}

uint8 ZVision::getBufferedKey(uint8 pos) {
if (pos >= KEYBUF_SIZE)
return 0;
else
return _cheatBuffer[KEYBUF_SIZE - pos - 1];
}

void ZVision::showDebugMsg(const Common::String &msg, int16 delay) {
uint16 msgid = _renderManager->createSubArea();
_renderManager->updateSubArea(msgid, msg);
_renderManager->deleteSubArea(msgid, delay);
}

} // End of namespace ZVision
13 changes: 8 additions & 5 deletions engines/zvision/zvision.h
Expand Up @@ -164,6 +164,14 @@ class ZVision : public Engine {

uint8 getZvisionKey(Common::KeyCode scummKeyCode);

void startClock() {
_clock.start();
}

void stopClock() {
_clock.stop();
}

/**
* Play a video until it is finished. This is a blocking call. It will call
* _clock.stop() when the video starts and _clock.start() when the video finishes.
Expand All @@ -181,10 +189,6 @@ class ZVision : public Engine {
Common::String generateSaveFileName(uint slot);
Common::String generateAutoSaveFileName();

bool askQuestion(const Common::String &str);
void delayedMessage(const Common::String &str, uint16 milsecs);
void timedMessage(const Common::String &str, uint16 milsecs);

void setRenderDelay(uint);
bool canRender();

Expand All @@ -197,7 +201,6 @@ class ZVision : public Engine {
bool ifQuit();

void checkBorders();
void showDebugMsg(const Common::String &msg, int16 delay = 3000);

// Engine features
bool hasFeature(EngineFeature f) const;
Expand Down

0 comments on commit 5a72eea

Please sign in to comment.