Skip to content

Commit

Permalink
PRINCE: intro works much beter. Still some synchronization issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Zbróg committed Nov 2, 2013
1 parent 9250a6f commit e72742d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
10 changes: 4 additions & 6 deletions engines/prince/prince.cpp
Expand Up @@ -85,7 +85,7 @@ Graphics::Surface *loadCursor(const char *curName)
PrinceEngine::PrinceEngine(OSystem *syst, const PrinceGameDescription *gameDesc) :
Engine(syst), _gameDescription(gameDesc), _graph(NULL), _script(NULL),
_locationNr(0), _debugger(NULL), _objectList(NULL), _mobList(NULL), _midiPlayer(NULL),
_cameraX(0), _newCameraX(0) {
_cameraX(0), _newCameraX(0), _frameNr(0) {

// Debug/console setup
DebugMan.addDebugChannel(DebugChannel::kScript, "script", "Prince Script debug channel");
Expand Down Expand Up @@ -479,6 +479,7 @@ void PrinceEngine::drawScreen() {

//if (_objectList)
// _graph->drawTransparent(_objectList->getSurface());

hotspot();

showTexts();
Expand All @@ -490,10 +491,6 @@ void PrinceEngine::drawScreen() {

void PrinceEngine::mainLoop() {

//loadLocation(1);
//changeCursor(1);
//CursorMan.showMouse(true);

while (!shouldQuit()) {
uint32 currentTime = _system->getMillis();

Expand Down Expand Up @@ -524,8 +521,8 @@ void PrinceEngine::mainLoop() {
if (shouldQuit())
return;

_script->step();
drawScreen();
_script->step();

// Calculate the frame delay based off a desired frame time
int delay = 1000/15 - int32(_system->getMillis() - currentTime);
Expand All @@ -534,6 +531,7 @@ void PrinceEngine::mainLoop() {
_system->delayMillis(delay);

_cameraX = _newCameraX;
++_frameNr;
}
}

Expand Down
2 changes: 2 additions & 0 deletions engines/prince/prince.h
Expand Up @@ -110,6 +110,8 @@ class PrinceEngine : public Engine {
static const uint8 MAXTEXTS = 32;
Text _textSlots[MAXTEXTS];

uint64 _frameNr;

private:
bool playNextFrame();
void keyHandler(Common::Event event);
Expand Down
46 changes: 35 additions & 11 deletions engines/prince/script.cpp
Expand Up @@ -31,13 +31,16 @@
#include "common/stream.h"
#include "common/archive.h"

#include "audio/decoders/wave.h"
#include "audio/audiostream.h"

namespace Prince {

static const uint16 NUM_OPCODES = 144;

Script::Script(PrinceEngine *vm) :
_code(NULL), _stacktop(0), _vm(vm), _opcodeNF(false),
_waitFlag(0) {
_waitFlag(0), _voiceStream(NULL) {
}

Script::~Script() {
Expand Down Expand Up @@ -70,7 +73,7 @@ void Script::debugScript(const char *s, ...) {
str += Common::String::format("op %04d: ", _lastOpcode);
//debugC(10, DebugChannel::kScript, "PrinceEngine::Script %s %s", str.c_str(), buf);

debug("PrinceEngine::Script %s %s", str.c_str(), buf);
debug("PrinceEngine::Script frame %ld %s %s", _vm->_frameNr, str.c_str(), buf);
}

void Script::step() {
Expand Down Expand Up @@ -164,6 +167,12 @@ void Script::O_PLAYSAMPLE() {
uint16 sampleId = readScript16bits();
uint16 loopType = readScript16bits();
debugScript("O_PLAYSAMPLE sampleId %d loopType %d", sampleId, loopType);

if (_voiceStream) {

Audio::RewindableAudioStream *audioStream = Audio::makeWAVStream(_voiceStream, DisposeAfterUse::YES);
_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, audioStream, sampleId);
}
}

void Script::O_PUTOBJECT() {
Expand Down Expand Up @@ -621,22 +630,36 @@ void Script::O_PRINTAT() {
}

void Script::O_ZOOMIN() {}

void Script::O_ZOOMOUT() {}

void Script::O_SETSTRINGOFFSET() {}

void Script::O_GETOBJDATA() {}

void Script::O_SETOBJDATA() {}

void Script::O_SWAPOBJECTS() {}

void Script::O_CHANGEHEROSET() {}

void Script::O_ADDSTRING() {}

void Script::O_SUBSTRING() {}

void Script::O_INITDIALOG() {}

void Script::O_ENABLEDIALOGOPT() {}

void Script::O_DISABLEDIALOGOPT() {}

void Script::O_SHOWDIALOGBOX() {}

void Script::O_STOPSAMPLE() {
uint16 slot = readScript16bits();
debugScript("O_STOPSAMPLE slot %d", slot);

_vm->_mixer->stopID(slot);
}

void Script::O_BACKANIMRANGE() {
Expand Down Expand Up @@ -826,32 +849,33 @@ void Script::SetVoice(uint32 slot) {
const Common::String streamName = Common::String::format("%03d-01.WAV", _currentString);
debugScript("Loading wav %s slot %d", streamName.c_str(), slot);

Common::SeekableReadStream *voiceStream = SearchMan.createReadStreamForMember(streamName);
if (!voiceStream) {
_voiceStream = SearchMan.createReadStreamForMember(streamName);
if (!_voiceStream) {
error("Can't open %s", streamName.c_str());
}
uint32 id = voiceStream->readUint32LE();
uint32 id = _voiceStream->readUint32LE();
if (id != 0x46464952) {
error("It's not RIFF file %s", streamName.c_str());
return;
}

voiceStream->skip(0x20);
id = voiceStream->readUint32LE();
_voiceStream->skip(0x20);
id = _voiceStream->readUint32LE();
if (id != 0x61746164) {
error("No data section in %s id %04x", streamName.c_str(), id);
return;
}

id = voiceStream->readUint32LE();
id = _voiceStream->readUint32LE();
debugScript("SetVoice slot %d time %04x", slot, id);
id <<= 3;
id /= 22050;
id += 2;

_vm->_textSlots[slot]._time = voiceStream->readUint32LE();
_vm->_textSlots[slot]._time = id;

debugScript("SetVoice slot %d time %04x", slot, _vm->_textSlots[slot]._time);
delete voiceStream;
debugScript("SetVoice slot %d time %04x", slot, id);
_voiceStream->seek(0);
}

void Script::O_SETVOICEH() {
Expand Down
4 changes: 4 additions & 0 deletions engines/prince/script.h
Expand Up @@ -25,6 +25,8 @@

#include "common/random.h"

#include "audio/mixer.h"

namespace Common {
class SeekableReadStream;
}
Expand Down Expand Up @@ -60,9 +62,11 @@ class Script {
uint8 _stacktop;
uint8 _savedStacktop;
uint32 _waitFlag;
Audio::SoundHandle _soundHandle;

const byte * _string;
uint32 _currentString;
Common::SeekableReadStream *_voiceStream;

// Helper functions
void checkPC(uint32 address);
Expand Down

0 comments on commit e72742d

Please sign in to comment.