STARK: Add shortcuts to use the singleton services

This commit is contained in:
Bastien Bouclet 2015-07-16 20:04:00 +02:00
parent 5bbddfa171
commit 18d3344f87
27 changed files with 134 additions and 235 deletions

View file

@ -111,42 +111,32 @@ bool Console::Cmd_DumpArchive(int argc, const char **argv) {
} }
bool Console::Cmd_DumpRoot(int argc, const char **argv) { bool Console::Cmd_DumpRoot(int argc, const char **argv) {
Global *global = StarkServices::instance().global; StarkGlobal->getRoot()->print();
global->getRoot()->print();
return true; return true;
} }
bool Console::Cmd_DumpGlobal(int argc, const char **argv) { bool Console::Cmd_DumpGlobal(int argc, const char **argv) {
Global *global = StarkServices::instance().global; StarkGlobal->getLevel()->print();
global->getLevel()->print();
return true; return true;
} }
bool Console::Cmd_DumpStatic(int argc, const char **argv) { bool Console::Cmd_DumpStatic(int argc, const char **argv) {
StaticProvider *staticProvider = StarkServices::instance().staticProvider; StarkStaticProvider->getLevel()->print();
staticProvider->getLevel()->print();
return true; return true;
} }
bool Console::Cmd_DumpLevel(int argc, const char **argv) { bool Console::Cmd_DumpLevel(int argc, const char **argv) {
Global *global = StarkServices::instance().global; StarkGlobal->getCurrent()->getLevel()->print();
global->getCurrent()->getLevel()->print();
return true; return true;
} }
bool Console::Cmd_DumpKnowledge(int argc, const char **argv) { bool Console::Cmd_DumpKnowledge(int argc, const char **argv) {
Global *global = StarkServices::instance().global; Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
Resources::Level *level = global->getCurrent()->getLevel();
Resources::Location *location = global->getCurrent()->getLocation();
Common::Array<Resources::Knowledge*> knowledge = level->listChildrenRecursive<Resources::Knowledge>(); Common::Array<Resources::Knowledge*> knowledge = level->listChildrenRecursive<Resources::Knowledge>();
knowledge.insert_at(knowledge.size(), location->listChildrenRecursive<Resources::Knowledge>()); knowledge.insert_at(knowledge.size(), location->listChildrenRecursive<Resources::Knowledge>());
Common::Array<Resources::Knowledge*>::iterator it; Common::Array<Resources::Knowledge*>::iterator it;
@ -164,10 +154,8 @@ bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) {
index = atoi(argv[1]); index = atoi(argv[1]);
type = argv[2][0]; type = argv[2][0];
if (type == 'b' || type == 'i') { if (type == 'b' || type == 'i') {
Global *global = StarkServices::instance().global; Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
Resources::Level *level = global->getCurrent()->getLevel();
Resources::Location *location = global->getCurrent()->getLocation();
Common::Array<Resources::Knowledge*> knowledgeArr = level->listChildrenRecursive<Resources::Knowledge>(); Common::Array<Resources::Knowledge*> knowledgeArr = level->listChildrenRecursive<Resources::Knowledge>();
knowledgeArr.insert_at(knowledgeArr.size(), location->listChildrenRecursive<Resources::Knowledge>()); knowledgeArr.insert_at(knowledgeArr.size(), location->listChildrenRecursive<Resources::Knowledge>());
if (index < knowledgeArr.size() ) { if (index < knowledgeArr.size() ) {
@ -196,10 +184,8 @@ bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) {
} }
bool Console::Cmd_ListScripts(int argc, const char **argv) { bool Console::Cmd_ListScripts(int argc, const char **argv) {
Global *global = StarkServices::instance().global; Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
Resources::Level *level = global->getCurrent()->getLevel();
Resources::Location *location = global->getCurrent()->getLocation();
Common::Array<Resources::Script*> scriptArr = level->listChildrenRecursive<Resources::Script>(); Common::Array<Resources::Script*> scriptArr = level->listChildrenRecursive<Resources::Script>();
scriptArr.insert_at(scriptArr.size(), location->listChildrenRecursive<Resources::Script>()); scriptArr.insert_at(scriptArr.size(), location->listChildrenRecursive<Resources::Script>());
Common::Array<Resources::Script*>::iterator it; Common::Array<Resources::Script*>::iterator it;
@ -215,14 +201,13 @@ bool Console::Cmd_EnableScript(int argc, const char **argv) {
if (argc >= 2) { if (argc >= 2) {
index = atoi(argv[1]); index = atoi(argv[1]);
Global *global = StarkServices::instance().global;
bool value = true; bool value = true;
if (argc >= 3) { if (argc >= 3) {
value = atoi(argv[2]); value = atoi(argv[2]);
} }
Resources::Level *level = global->getCurrent()->getLevel(); Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = global->getCurrent()->getLocation(); Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
Common::Array<Resources::Script*> scriptArr = level->listChildrenRecursive<Resources::Script>(); Common::Array<Resources::Script*> scriptArr = level->listChildrenRecursive<Resources::Script>();
scriptArr.insert_at(scriptArr.size(), location->listChildrenRecursive<Resources::Script>()); scriptArr.insert_at(scriptArr.size(), location->listChildrenRecursive<Resources::Script>());
if (index < scriptArr.size() ) { if (index < scriptArr.size() ) {
@ -247,14 +232,13 @@ bool Console::Cmd_ForceScript(int argc, const char **argv) {
if (argc >= 2) { if (argc >= 2) {
index = atoi(argv[1]); index = atoi(argv[1]);
Global *global = StarkServices::instance().global;
bool value = true; bool value = true;
if (argc >= 3) { if (argc >= 3) {
value = atoi(argv[2]); value = atoi(argv[2]);
} }
Resources::Level *level = global->getCurrent()->getLevel(); Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = global->getCurrent()->getLocation(); Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
Common::Array<Resources::Script*> scriptArr = level->listChildrenRecursive<Resources::Script>(); Common::Array<Resources::Script*> scriptArr = level->listChildrenRecursive<Resources::Script>();
scriptArr.insert_at(scriptArr.size(), location->listChildrenRecursive<Resources::Script>()); scriptArr.insert_at(scriptArr.size(), location->listChildrenRecursive<Resources::Script>());
if (index < scriptArr.size() ) { if (index < scriptArr.size() ) {
@ -278,16 +262,13 @@ bool Console::Cmd_ForceScript(int argc, const char **argv) {
bool Console::Cmd_DumpLocation(int argc, const char **argv) { bool Console::Cmd_DumpLocation(int argc, const char **argv) {
Global *global = StarkServices::instance().global; StarkGlobal->getCurrent()->getLocation()->print();
global->getCurrent()->getLocation()->print();
return true; return true;
} }
bool Console::Cmd_ListInventory(int argc, const char **argv) { bool Console::Cmd_ListInventory(int argc, const char **argv) {
Global *global = StarkServices::instance().global; StarkGlobal->printInventory(argc != 2);
global->printInventory(argc != 2);
return true; return true;
} }
@ -299,8 +280,7 @@ bool Console::Cmd_EnableInventoryItem(int argc, const char **argv) {
debugPrintf("changeLocation [level] [location]\n"); debugPrintf("changeLocation [level] [location]\n");
return true; return true;
} }
Global *global = StarkServices::instance().global; StarkGlobal->enableInventoryItem(atoi(argv[1]));
global->enableInventoryItem(atoi(argv[1]));
return true; return true;
} }
@ -309,8 +289,8 @@ bool Console::Cmd_ListLocations(int argc, const char **argv) {
ArchiveLoader *archiveLoader = new ArchiveLoader(); ArchiveLoader *archiveLoader = new ArchiveLoader();
// Temporarily replace the global archive loader with our instance // Temporarily replace the global archive loader with our instance
ArchiveLoader *gameArchiveLoader = StarkServices::instance().archiveLoader; ArchiveLoader *gameArchiveLoader = StarkArchiveLoader;
StarkServices::instance().archiveLoader = archiveLoader; StarkArchiveLoader = archiveLoader;
archiveLoader->load("x.xarc"); archiveLoader->load("x.xarc");
Resources::Root *root = archiveLoader->useRoot<Resources::Root>("x.xarc"); Resources::Root *root = archiveLoader->useRoot<Resources::Root>("x.xarc");
@ -344,7 +324,7 @@ bool Console::Cmd_ListLocations(int argc, const char **argv) {
} }
// Restore the global archive loader // Restore the global archive loader
StarkServices::instance().archiveLoader = gameArchiveLoader; StarkArchiveLoader = gameArchiveLoader;
delete archiveLoader; delete archiveLoader;
@ -362,8 +342,7 @@ bool Console::Cmd_ChangeLocation(int argc, const char **argv) {
uint levelIndex = strtol(argv[1] , nullptr, 16); uint levelIndex = strtol(argv[1] , nullptr, 16);
uint locationIndex = strtol(argv[2] , nullptr, 16); uint locationIndex = strtol(argv[2] , nullptr, 16);
ResourceProvider *resourceProvider = StarkServices::instance().resourceProvider; StarkResourceProvider->requestLocationChange(levelIndex, locationIndex);
resourceProvider->requestLocationChange(levelIndex, locationIndex);
return false; return false;
} }
@ -378,8 +357,7 @@ bool Console::Cmd_ChangeChapter(int argc, const char **argv) {
uint32 value = atoi(argv[1]); uint32 value = atoi(argv[1]);
Global *global = StarkServices::instance().global; StarkGlobal->setCurrentChapter(value);
global->setCurrentChapter(value);
return true; return true;
} }
@ -391,8 +369,7 @@ bool Console::Cmd_SelectDialogOption(int argc, const char **argv) {
debugPrintf("selectDialogOption [option]\n"); debugPrintf("selectDialogOption [option]\n");
return true; return true;
} }
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer; StarkDialogPlayer->selectOption(atoi(argv[1]));
dialogPlayer->selectOption(atoi(argv[1]));
return false; return false;
} }
@ -405,8 +382,7 @@ bool Console::Cmd_Location(int argc, const char **argv) {
return true; return true;
} }
Global *global = StarkServices::instance().global; Current *current = StarkGlobal->getCurrent();
Current *current = global->getCurrent();
debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex()); debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex());
@ -421,8 +397,7 @@ bool Console::Cmd_Chapter(int argc, const char **argv) {
return true; return true;
} }
Global *global = StarkServices::instance().global; int32 value = StarkGlobal->getCurrentChapter();
int32 value = global->getCurrentChapter();
debugPrintf("chapter: %d\n", value); debugPrintf("chapter: %d\n", value);

View file

@ -60,10 +60,9 @@ void Cursor::setCursorType(CursorType type) {
_cursorImage = nullptr; _cursorImage = nullptr;
return; return;
} }
StaticProvider *staticProvider = StarkServices::instance().staticProvider;
// TODO: This is just a quick solution to get anything drawn. // TODO: This is just a quick solution to get anything drawn.
_cursorImage = staticProvider->getCursorImage(_currentCursorType); _cursorImage = StarkStaticProvider->getCursorImage(_currentCursorType);
} }
void Cursor::setCursorImage(VisualImageXMG *image) { void Cursor::setCursorImage(VisualImageXMG *image) {

View file

@ -51,8 +51,6 @@ Common::String OpenGLSActorRenderer::faceHash(const FaceNode *face) const {
} }
void OpenGLSActorRenderer::render(Gfx::Driver *gfx, const Math::Vector3d position, float direction) { void OpenGLSActorRenderer::render(Gfx::Driver *gfx, const Math::Vector3d position, float direction) {
Scene *scene = StarkServices::instance().scene;
if (_meshIsDirty) { if (_meshIsDirty) {
// Update the OpenGL Buffer Objects if required // Update the OpenGL Buffer Objects if required
clearVertices(); clearVertices();
@ -65,8 +63,8 @@ void OpenGLSActorRenderer::render(Gfx::Driver *gfx, const Math::Vector3d positio
gfx->set3DMode(); gfx->set3DMode();
Math::Matrix4 model = getModelMatrix(position, direction); Math::Matrix4 model = getModelMatrix(position, direction);
Math::Matrix4 view = scene->getViewMatrix(); Math::Matrix4 view = StarkScene->getViewMatrix();
Math::Matrix4 projection = scene->getProjectionMatrix(); Math::Matrix4 projection = StarkScene->getProjectionMatrix();
Math::Matrix4 mvp = projection * view * model; Math::Matrix4 mvp = projection * view * model;
mvp.transpose(); mvp.transpose();

View file

@ -48,9 +48,6 @@ void ResourceReference::addPathElement(Resources::Type type, uint16 index) {
} }
Resources::Object *ResourceReference::resolve() const { Resources::Object *ResourceReference::resolve() const {
ResourceProvider *resourceProvider = StarkServices::instance().resourceProvider;
Global *global = StarkServices::instance().global;
Resources::Object *resource = nullptr; Resources::Object *resource = nullptr;
for (uint i = 0; i < _path.size(); i++) { for (uint i = 0; i < _path.size(); i++) {
PathElement element = _path[i]; PathElement element = _path[i];
@ -58,13 +55,13 @@ Resources::Object *ResourceReference::resolve() const {
switch (element.getType().get()) { switch (element.getType().get()) {
case Resources::Type::kLevel: case Resources::Type::kLevel:
if (element.getIndex()) { if (element.getIndex()) {
resource = resourceProvider->getLevel(element.getIndex()); resource = StarkResourceProvider->getLevel(element.getIndex());
} else { } else {
resource = global->getLevel(); resource = StarkGlobal->getLevel();
} }
break; break;
case Resources::Type::kLocation: case Resources::Type::kLocation:
resource = resourceProvider->getLocation(resource->getIndex(), element.getIndex()); resource = StarkResourceProvider->getLocation(resource->getIndex(), element.getIndex());
break; break;
default: default:
resource = resource->findChildWithIndex(element.getType(), element.getIndex()); resource = resource->findChildWithIndex(element.getType(), element.getIndex());

View file

@ -203,12 +203,9 @@ void AnimVideo::readData(Formats::XRCReadStream *stream) {
void AnimVideo::onAllLoaded() { void AnimVideo::onAllLoaded() {
if (!_smacker) { if (!_smacker) {
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader; Common::SeekableReadStream *stream = StarkArchiveLoader->getExternalFile(_smackerFile, _archiveName);
Gfx::Driver *gfx = StarkServices::instance().gfx;
Common::SeekableReadStream *stream = archiveLoader->getExternalFile(_smackerFile, _archiveName); _smacker = new VisualSmacker(StarkGfx);
_smacker = new VisualSmacker(gfx);
_smacker->load(stream); _smacker->load(stream);
} }
} }
@ -222,8 +219,7 @@ void AnimVideo::onGameLoop() {
return; return;
} }
Global *global = StarkServices::instance().global; _smacker->update(StarkGlobal->getMillisecondsPerGameloop());
_smacker->update(global->getMillisecondsPerGameloop());
} }
Visual *AnimVideo::getVisual() { Visual *AnimVideo::getVisual() {
@ -268,8 +264,7 @@ AnimSkeleton::AnimSkeleton(Object *parent, byte subType, uint16 index, const Com
_seletonAnim(nullptr), _seletonAnim(nullptr),
_currentTime(0), _currentTime(0),
_totalTime(0) { _totalTime(0) {
Gfx::Driver *gfx = StarkServices::instance().gfx; _visual = StarkGfx->createActorRenderer();
_visual = gfx->createActorRenderer();
} }
void AnimSkeleton::applyToItem(Item *item) { void AnimSkeleton::applyToItem(Item *item) {
@ -324,10 +319,7 @@ void AnimSkeleton::readData(Formats::XRCReadStream *stream) {
} }
void AnimSkeleton::onPostRead() { void AnimSkeleton::onPostRead() {
// Get the archive loader service ArchiveReadStream *stream = StarkArchiveLoader->getFile(_animFilename, _archiveName);
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader;
ArchiveReadStream *stream = archiveLoader->getFile(_animFilename, _archiveName);
_seletonAnim = new SkeletonAnim(); _seletonAnim = new SkeletonAnim();
_seletonAnim->createFromStream(stream); _seletonAnim->createFromStream(stream);
@ -346,9 +338,7 @@ void AnimSkeleton::onGameLoop() {
Anim::onGameLoop(); Anim::onGameLoop();
if (isInUse() && _totalTime) { if (isInUse() && _totalTime) {
Global *global = StarkServices::instance().global; _currentTime = (_currentTime + StarkGlobal->getMillisecondsPerGameloop()) % _totalTime;
_currentTime = (_currentTime + global->getMillisecondsPerGameloop()) % _totalTime;
_visual->setTime(_currentTime); _visual->setTime(_currentTime);
} }
} }

View file

@ -64,10 +64,7 @@ void AnimScript::onGameLoop() {
return; return;
} }
Global *global = StarkServices::instance().global; while (_msecsToNextUpdate <= (int32)StarkGlobal->getMillisecondsPerGameloop()) {
Common::RandomSource *randomSource = StarkServices::instance().randomSource;
while (_msecsToNextUpdate <= (int32)global->getMillisecondsPerGameloop()) {
AnimScriptItem *item = _items[_nextItemIndex]; AnimScriptItem *item = _items[_nextItemIndex];
_msecsToNextUpdate += item->getDuration(); _msecsToNextUpdate += item->getDuration();
@ -87,13 +84,13 @@ void AnimScript::onGameLoop() {
uint32 startFrame = item->getOperand() >> 16; uint32 startFrame = item->getOperand() >> 16;
uint32 endFrame = item->getOperand() & 0xFFFF; uint32 endFrame = item->getOperand() & 0xFFFF;
uint32 frame = randomSource->getRandomNumberRng(startFrame, endFrame); uint32 frame = StarkRandomSource->getRandomNumberRng(startFrame, endFrame);
_anim->selectFrame(frame); _anim->selectFrame(frame);
goToNextItem(); goToNextItem();
break; break;
} }
case AnimScriptItem::kSleepRandomDuration: { case AnimScriptItem::kSleepRandomDuration: {
uint duration = randomSource->getRandomNumber(item->getOperand()); uint duration = StarkRandomSource->getRandomNumber(item->getOperand());
_msecsToNextUpdate += duration; _msecsToNextUpdate += duration;
goToNextItem(); goToNextItem();
break; break;
@ -107,7 +104,7 @@ void AnimScript::onGameLoop() {
} }
} }
_msecsToNextUpdate -= global->getMillisecondsPerGameloop(); _msecsToNextUpdate -= StarkGlobal->getMillisecondsPerGameloop();
} }
void AnimScript::setCurrentIndex(uint32 index) { void AnimScript::setCurrentIndex(uint32 index) {

View file

@ -45,10 +45,7 @@ void BonesMesh::readData(Formats::XRCReadStream *stream) {
} }
void BonesMesh::onPostRead() { void BonesMesh::onPostRead() {
// Get the archive loader service ArchiveReadStream *stream = StarkArchiveLoader->getFile(_filename, _archiveName);
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader;
ArchiveReadStream *stream = archiveLoader->getFile(_filename, _archiveName);
_actor = new Actor(); _actor = new Actor();
_actor->readFromStream(stream); _actor->readFromStream(stream);

View file

@ -73,8 +73,7 @@ void Camera::onEnterLocation() {
Object::onEnterLocation(); Object::onEnterLocation();
// Setup the camera // Setup the camera
Scene *scene = StarkServices::instance().scene; StarkScene->initCamera(_position, _lookDirection, _fov, _viewSize, _nearClipPlane, _farClipPlane);
scene->initCamera(_position, _lookDirection, _fov, _viewSize, _nearClipPlane, _farClipPlane);
// Scroll the camera to its initial position // Scroll the camera to its initial position
Location *location = findParent<Location>(); Location *location = findParent<Location>();

View file

@ -196,10 +196,8 @@ Command *Command::opScriptCall(Script *script, const ResourceReference &scriptRe
} }
Command *Command::opDialogCall(Script *script, const ResourceReference &dialogRef, int32 suspend) { Command *Command::opDialogCall(Script *script, const ResourceReference &dialogRef, int32 suspend) {
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer;
Dialog *dialog = dialogRef.resolve<Dialog>(); Dialog *dialog = dialogRef.resolve<Dialog>();
dialogPlayer->run(dialog); StarkDialogPlayer->run(dialog);
if (suspend) { if (suspend) {
script->suspend(dialog); script->suspend(dialog);
@ -216,12 +214,10 @@ Command *Command::opSetInteractiveMode(bool enabled) {
} }
Command *Command::opLocationGoTo(const Common::String &level, const Common::String &location, const ResourceReference &bookmarkRef, int32 direction) { Command *Command::opLocationGoTo(const Common::String &level, const Common::String &location, const ResourceReference &bookmarkRef, int32 direction) {
ResourceProvider *resourceProvider = StarkServices::instance().resourceProvider;
uint levelIndex = strtol(level.c_str(), nullptr, 16); uint levelIndex = strtol(level.c_str(), nullptr, 16);
uint locationIndex = strtol(location.c_str(), nullptr, 16); uint locationIndex = strtol(location.c_str(), nullptr, 16);
resourceProvider->requestLocationChange(levelIndex, locationIndex); StarkResourceProvider->requestLocationChange(levelIndex, locationIndex);
resourceProvider->setNextLocationPosition(bookmarkRef, direction); StarkResourceProvider->setNextLocationPosition(bookmarkRef, direction);
return nullptr; return nullptr;
} }
@ -251,8 +247,7 @@ Command *Command::opGameLoop(int32 unknown) {
} }
Command *Command::opPauseRandom(Script *script, const ResourceReference &ref) { Command *Command::opPauseRandom(Script *script, const ResourceReference &ref) {
Common::RandomSource *randomSource = StarkServices::instance().randomSource; float randomFactor = StarkRandomSource->getRandomNumber(10000) / 10000.0;
float randomFactor = randomSource->getRandomNumber(10000) / 10000.0;
Knowledge *duration = ref.resolve<Knowledge>(); Knowledge *duration = ref.resolve<Knowledge>();
script->pause(randomFactor * duration->getIntegerValue()); script->pause(randomFactor * duration->getIntegerValue());
@ -262,18 +257,20 @@ Command *Command::opPauseRandom(Script *script, const ResourceReference &ref) {
Command *Command::opExit2DLocation(Script *script) { Command *Command::opExit2DLocation(Script *script) {
warning("(TODO: Implement) Exit 2D Location"); warning("(TODO: Implement) Exit 2D Location");
StarkServices::instance().resourceProvider->returnToPushedLocation();
StarkResourceProvider->returnToPushedLocation();
return nullptr; return nullptr;
} }
Command *Command::opGoto2DLocation(const Common::String &level, const Common::String &location) { Command *Command::opGoto2DLocation(const Common::String &level, const Common::String &location) {
ResourceProvider *resourceProvider = StarkServices::instance().resourceProvider;
warning("TODO: Implement) opGoto2DLocation"); warning("TODO: Implement) opGoto2DLocation");
// TODO: This needs to be handled differently, to allow exiting. // TODO: This needs to be handled differently, to allow exiting.
uint levelIndex = strtol(level.c_str(), nullptr, 16); uint levelIndex = strtol(level.c_str(), nullptr, 16);
uint locationIndex = strtol(location.c_str(), nullptr, 16); uint locationIndex = strtol(location.c_str(), nullptr, 16);
resourceProvider->pushAndChangeLocation(levelIndex, locationIndex); StarkResourceProvider->pushAndChangeLocation(levelIndex, locationIndex);
return nullptr; return nullptr;
} }
@ -398,10 +395,10 @@ Command *Command::opShowPlay(Script *script, const ResourceReference &ref, int32
assert(_arguments.size() == 3); assert(_arguments.size() == 3);
Speech *speechObj = ref.resolve<Speech>(); Speech *speechObj = ref.resolve<Speech>();
assert(speechObj->getType().get() == Type::kSpeech); assert(speechObj->getType().get() == Type::kSpeech);
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer;
dialogPlayer->playSingle(speechObj);
warning("(TODO: Implement) opShowPlay(%s %d) %s : %s", speechObj->getName().c_str(), suspend, speechObj->getPhrase().c_str(), ref.describe().c_str()); warning("(TODO: Implement) opShowPlay(%s %d) %s : %s", speechObj->getName().c_str(), suspend, speechObj->getPhrase().c_str(), ref.describe().c_str());
StarkDialogPlayer->playSingle(speechObj);
if (suspend) { if (suspend) {
script->suspend(speechObj); script->suspend(speechObj);
return this; // Stay on the same command while suspended return this; // Stay on the same command while suspended
@ -507,7 +504,7 @@ Command *Command::opScrollSet(const ResourceReference &scrollRef) {
Command *Command::opPlayFullMotionVideo(Script *script, const ResourceReference &movieRef, int32 unknown) { Command *Command::opPlayFullMotionVideo(Script *script, const ResourceReference &movieRef, int32 unknown) {
FMV *movie = movieRef.resolve<FMV>(); FMV *movie = movieRef.resolve<FMV>();
warning("(TODO: Implement) opPlayFullMotionVideo(%s) : %s - %d", movie->getName().c_str(), movieRef.describe().c_str(), unknown); warning("(TODO: Implement) opPlayFullMotionVideo(%s) : %s - %d", movie->getName().c_str(), movieRef.describe().c_str(), unknown);
StarkServices::instance().userInterface->notifyFMVRequest(movie->getFilename()); StarkUserInterface->notifyFMVRequest(movie->getFilename());
// TODO: Is this unconditional suspension? // TODO: Is this unconditional suspension?
script->suspend(movie); script->suspend(movie);
return this; // Stay on the same command while suspended return this; // Stay on the same command while suspended
@ -598,8 +595,7 @@ Command *Command::opSpeakWithoutTalking(Script *script, const ResourceReference
warning("(TODO: Implement) opSpeakWithoutTalking(%s, %d) : %s", speech->getName().c_str(), suspend, speechRef.describe().c_str()); warning("(TODO: Implement) opSpeakWithoutTalking(%s, %d) : %s", speech->getName().c_str(), suspend, speechRef.describe().c_str());
// TODO: Complete // TODO: Complete
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer; StarkDialogPlayer->playSingle(speech);
dialogPlayer->playSingle(speech);
if (suspend) { if (suspend) {
script->suspend(speech); script->suspend(speech);
@ -663,8 +659,7 @@ Command *Command::opIsScriptActive(const ResourceReference &scriptRef) {
} }
Command *Command::opIsRandom(int32 chance) { Command *Command::opIsRandom(int32 chance) {
Common::RandomSource *randomSource = StarkServices::instance().randomSource; int32 value = StarkRandomSource->getRandomNumber(100);
int32 value = randomSource->getRandomNumber(100);
return nextCommandIf(value < chance); return nextCommandIf(value < chance);
} }

View file

@ -131,8 +131,6 @@ Dialog::Topic::Topic() :
} }
int32 Dialog::Topic::getNextReplyIndex() const { int32 Dialog::Topic::getNextReplyIndex() const {
Global *global = StarkServices::instance().global;
uint32 nextIndex = _currentReplyIndex + 1; uint32 nextIndex = _currentReplyIndex + 1;
if (nextIndex >= _replies.size()) { if (nextIndex >= _replies.size()) {
@ -146,7 +144,7 @@ int32 Dialog::Topic::getNextReplyIndex() const {
} }
} }
uint32 currentChapter = global->getCurrentChapter(); uint32 currentChapter = StarkGlobal->getCurrentChapter();
// Skip replies from previous chapters // Skip replies from previous chapters
while (_replies[nextIndex]._maxChapter < currentChapter && nextIndex < _replies.size()) { while (_replies[nextIndex]._maxChapter < currentChapter && nextIndex < _replies.size()) {

View file

@ -180,13 +180,9 @@ void ImageSub23::initVisual() {
return; // No file to load return; // No file to load
} }
// Get the archive loader service Common::ReadStream *stream = StarkArchiveLoader->getFile(_filename, _archiveName);
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader;
Gfx::Driver *gfx = StarkServices::instance().gfx;
Common::ReadStream *stream = archiveLoader->getFile(_filename, _archiveName); VisualImageXMG *xmg = new VisualImageXMG(StarkGfx);
VisualImageXMG *xmg = new VisualImageXMG(gfx);
xmg->load(stream); xmg->load(stream);
xmg->setHotSpot(_hotspot); xmg->setHotSpot(_hotspot);

View file

@ -453,8 +453,7 @@ void FloorPositionedItem::setFloorFaceIndex(int32 faceIndex) {
} }
void FloorPositionedItem::placeOnBookmark(Bookmark *target) { void FloorPositionedItem::placeOnBookmark(Bookmark *target) {
Global *global = StarkServices::instance().global; Floor *floor = StarkGlobal->getCurrent()->getFloor();
Floor *floor = global->getCurrent()->getFloor();
_position3D = target->getPosition(); _position3D = target->getPosition();
@ -474,8 +473,7 @@ void FloorPositionedItem::setDirection(uint direction) {
} }
float FloorPositionedItem::getSortKey() const { float FloorPositionedItem::getSortKey() const {
Global *global = StarkServices::instance().global; Floor *floor = StarkGlobal->getCurrent()->getFloor();
Floor *floor = global->getCurrent()->getFloor();
if (_floorFaceIndex == -1) { if (_floorFaceIndex == -1) {
// warning("Undefined floor face index for item '%s'", getName().c_str()); // warning("Undefined floor face index for item '%s'", getName().c_str());

View file

@ -70,8 +70,6 @@ Common::Point Location::getScrollPosition() const {
} }
void Location::setScrollPosition(const Common::Point &position) { void Location::setScrollPosition(const Common::Point &position) {
Scene *scene = StarkServices::instance().scene;
_scroll.x = CLIP<int16>(position.x, 0, _maxScroll.x); _scroll.x = CLIP<int16>(position.x, 0, _maxScroll.x);
_scroll.y = CLIP<int16>(position.y, 0, _maxScroll.y); _scroll.y = CLIP<int16>(position.y, 0, _maxScroll.y);
@ -84,7 +82,7 @@ void Location::setScrollPosition(const Common::Point &position) {
// Reconfigure the camera // Reconfigure the camera
Common::Rect viewport(640, 365); Common::Rect viewport(640, 365);
viewport.translate(_scroll.x, _scroll.y); viewport.translate(_scroll.x, _scroll.y);
scene->scrollCamera(viewport); StarkScene->scrollCamera(viewport);
} }
void Location::printData() { void Location::printData() {

View file

@ -126,8 +126,6 @@ void Script::enable(bool value) {
} }
bool Script::shouldExecute(uint32 callMode) { bool Script::shouldExecute(uint32 callMode) {
Global *global = StarkServices::instance().global;
if ((!isEnabled() && isOnBegin()) || !_nextCommand) { if ((!isEnabled() && isOnBegin()) || !_nextCommand) {
return false; // Don't execute disabled scripts return false; // Don't execute disabled scripts
} }
@ -163,7 +161,7 @@ bool Script::shouldExecute(uint32 callMode) {
return false; // Wrong script type return false; // Wrong script type
} }
uint32 currentChapter = global->getCurrentChapter(); uint32 currentChapter = StarkGlobal->getCurrentChapter();
if (currentChapter < _minChapter || currentChapter >= _maxChapter) { if (currentChapter < _minChapter || currentChapter >= _maxChapter) {
return false; // Wrong chapter return false; // Wrong chapter
} }
@ -178,8 +176,7 @@ bool Script::isSuspended() {
void Script::updateSuspended() { void Script::updateSuspended() {
if (_pauseTimeLeft >= 0) { if (_pauseTimeLeft >= 0) {
// Decrease the remaining pause time // Decrease the remaining pause time
Global *global = StarkServices::instance().global; _pauseTimeLeft -= StarkGlobal->getMillisecondsPerGameloop();
_pauseTimeLeft -= global->getMillisecondsPerGameloop();
} else { } else {
_pauseTimeLeft = -1; _pauseTimeLeft = -1;
} }
@ -188,16 +185,14 @@ void Script::updateSuspended() {
// Check if the suspending resource is still active // Check if the suspending resource is still active
switch (_suspendingResource->getType().get()) { switch (_suspendingResource->getType().get()) {
case Type::kDialog: { case Type::kDialog: {
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer; if (!StarkDialogPlayer->isRunning()) {
if (!dialogPlayer->isRunning()) {
// Resume the script execution if the dialog is complete // Resume the script execution if the dialog is complete
_suspendingResource = nullptr; _suspendingResource = nullptr;
} }
break; break;
} }
case Type::kFMV: { case Type::kFMV: {
UserInterface *ui = StarkServices::instance().userInterface; if (!StarkUserInterface->isPlayingFMV()) {
if (!ui->isPlayingFMV()) {
// Resume the script execution if the dialog is complete // Resume the script execution if the dialog is complete
_suspendingResource = nullptr; _suspendingResource = nullptr;
} }

View file

@ -53,13 +53,10 @@ Sound::Sound(Object *parent, byte subType, uint16 index, const Common::String &n
} }
Audio::RewindableAudioStream *Sound::makeAudioStream() { Audio::RewindableAudioStream *Sound::makeAudioStream() {
// Get the archive loader service
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader;
Audio::RewindableAudioStream *audioStream = nullptr; Audio::RewindableAudioStream *audioStream = nullptr;
// First try the .iss / isn files // First try the .iss / isn files
Common::SeekableReadStream *stream = archiveLoader->getExternalFile(_filename, _archiveName); Common::SeekableReadStream *stream = StarkArchiveLoader->getExternalFile(_filename, _archiveName);
if (stream) { if (stream) {
audioStream = Formats::makeISSStream(stream, DisposeAfterUse::YES); audioStream = Formats::makeISSStream(stream, DisposeAfterUse::YES);
} }
@ -72,7 +69,7 @@ Audio::RewindableAudioStream *Sound::makeAudioStream() {
filename = Common::String(_filename.c_str(), _filename.size() - 4) + ".ovs"; filename = Common::String(_filename.c_str(), _filename.size() - 4) + ".ovs";
} }
stream = archiveLoader->getExternalFile(filename, _archiveName); stream = StarkArchiveLoader->getExternalFile(filename, _archiveName);
if (stream) { if (stream) {
audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES); audioStream = Audio::makeVorbisStream(stream, DisposeAfterUse::YES);
} }

View file

@ -64,8 +64,7 @@ void Speech::stop() {
} }
bool Speech::characterIsApril() const { bool Speech::characterIsApril() const {
Global *global = StarkServices::instance().global; int32 aprilCharacterIndex = StarkGlobal->getApril()->getCharacterIndex();
int32 aprilCharacterIndex = global->getApril()->getCharacterIndex();
return _character == aprilCharacterIndex; return _character == aprilCharacterIndex;
} }

View file

@ -51,13 +51,9 @@ void TextureSet::readData(Formats::XRCReadStream *stream) {
} }
void TextureSet::onPostRead() { void TextureSet::onPostRead() {
// Get the required services Common::ReadStream *stream = StarkArchiveLoader->getFile(_filename, _archiveName);
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader;
Gfx::Driver *gfxDriver = StarkServices::instance().gfx;
Common::ReadStream *stream = archiveLoader->getFile(_filename, _archiveName); Formats::TextureSetReader *reader = new Formats::TextureSetReader(StarkGfx);
Formats::TextureSetReader *reader = new Formats::TextureSetReader(gfxDriver);
_textureSet = reader->read(stream); _textureSet = reader->read(stream);

View file

@ -51,8 +51,7 @@ GameInterface::~GameInterface() {
} }
void GameInterface::skipCurrentSpeeches() { void GameInterface::skipCurrentSpeeches() {
Global *global = StarkServices::instance().global; Current *current = StarkGlobal->getCurrent();
Current *current = global->getCurrent();
if (!current) { if (!current) {
return; // No current location, nothing to do return; // No current location, nothing to do
@ -60,7 +59,7 @@ void GameInterface::skipCurrentSpeeches() {
// Get all speeches // Get all speeches
Common::Array<Resources::Speech *> speeches; Common::Array<Resources::Speech *> speeches;
speeches.push_back(global->getLevel()->listChildrenRecursive<Resources::Speech>()); speeches.push_back(StarkGlobal->getLevel()->listChildrenRecursive<Resources::Speech>());
speeches.push_back(current->getLevel()->listChildrenRecursive<Resources::Speech>()); speeches.push_back(current->getLevel()->listChildrenRecursive<Resources::Speech>());
speeches.push_back(current->getLocation()->listChildrenRecursive<Resources::Speech>()); speeches.push_back(current->getLocation()->listChildrenRecursive<Resources::Speech>());
@ -74,8 +73,7 @@ void GameInterface::skipCurrentSpeeches() {
} }
void GameInterface::scrollLocation(int32 dX, int32 dY) { void GameInterface::scrollLocation(int32 dX, int32 dY) {
Global *global = StarkServices::instance().global; Current *current = StarkGlobal->getCurrent();
Current *current = global->getCurrent();
if (!current) { if (!current) {
return; // No current location, nothing to do return; // No current location, nothing to do
@ -90,14 +88,12 @@ void GameInterface::scrollLocation(int32 dX, int32 dY) {
} }
void GameInterface::walkTo(const Common::Point &mouse) { void GameInterface::walkTo(const Common::Point &mouse) {
Global *global = StarkServices::instance().global; Resources::Floor *floor = StarkGlobal->getCurrent()->getFloor();
Scene *scene = StarkServices::instance().scene; Resources::MeshItem *april = StarkGlobal->getCurrent()->getInteractive();
Resources::Floor *floor = global->getCurrent()->getFloor();
Resources::MeshItem *april = global->getCurrent()->getInteractive();
Math::Vector3d origin, direction, intersection; Math::Vector3d origin, direction, intersection;
scene->makeRayFromMouse(mouse, origin, direction); StarkScene->makeRayFromMouse(mouse, origin, direction);
int32 floorFace = floor->findFaceHitByRay(origin, direction, intersection); int32 floorFace = floor->findFaceHitByRay(origin, direction, intersection);
if (april && floorFace >= 0) { if (april && floorFace >= 0) {
// TODO: Complete, for now we just teleport to the target location // TODO: Complete, for now we just teleport to the target location
@ -108,8 +104,7 @@ void GameInterface::walkTo(const Common::Point &mouse) {
VisualImageXMG *GameInterface::getActionImage(uint32 itemIndex, bool active) { VisualImageXMG *GameInterface::getActionImage(uint32 itemIndex, bool active) {
// Lookup the action's item in the inventory // Lookup the action's item in the inventory
Global *global = StarkServices::instance().global; Resources::KnowledgeSet *inventory = StarkGlobal->getLevel()->findChildWithSubtype<Resources::KnowledgeSet>(Resources::KnowledgeSet::kInventory, true);
Resources::KnowledgeSet *inventory = global->getLevel()->findChildWithSubtype<Resources::KnowledgeSet>(Resources::KnowledgeSet::kInventory, true);
// Get the visual for the action // Get the visual for the action
Resources::InventoryItem *action = inventory->findChildWithIndex<Resources::InventoryItem>(itemIndex); Resources::InventoryItem *action = inventory->findChildWithIndex<Resources::InventoryItem>(itemIndex);
@ -120,8 +115,7 @@ VisualImageXMG *GameInterface::getActionImage(uint32 itemIndex, bool active) {
VisualImageXMG *GameInterface::getCursorImage(uint32 itemIndex) { VisualImageXMG *GameInterface::getCursorImage(uint32 itemIndex) {
// Lookup the item's item in the inventory // Lookup the item's item in the inventory
Global *global = StarkServices::instance().global; Resources::KnowledgeSet *inventory = StarkGlobal->getLevel()->findChildWithSubtype<Resources::KnowledgeSet>(Resources::KnowledgeSet::kInventory, true);
Resources::KnowledgeSet *inventory = global->getLevel()->findChildWithSubtype<Resources::KnowledgeSet>(Resources::KnowledgeSet::kInventory, true);
// Get the visual for the item // Get the visual for the item
Resources::InventoryItem *item = inventory->findChildWithIndex<Resources::InventoryItem>(itemIndex); Resources::InventoryItem *item = inventory->findChildWithIndex<Resources::InventoryItem>(itemIndex);

View file

@ -75,6 +75,18 @@ public:
UserInterface *userInterface; UserInterface *userInterface;
}; };
/** Shortcuts for accessing the services. */
#define StarkArchiveLoader StarkServices::instance().archiveLoader
#define StarkDialogPlayer StarkServices::instance().dialogPlayer
#define StarkGfx StarkServices::instance().gfx
#define StarkGlobal StarkServices::instance().global
#define StarkResourceProvider StarkServices::instance().resourceProvider
#define StarkRandomSource StarkServices::instance().randomSource
#define StarkScene StarkServices::instance().scene
#define StarkStaticProvider StarkServices::instance().staticProvider
#define StarkGameInterface StarkServices::instance().gameInterface
#define StarkUserInterface StarkServices::instance().userInterface
} // End of namespace Stark } // End of namespace Stark
#endif // STARK_SERVICES_SERVICES_H #endif // STARK_SERVICES_SERVICES_H

View file

@ -79,8 +79,7 @@ void UserInterface::init() {
} }
void UserInterface::update() { void UserInterface::update() {
StaticProvider *staticProvider = StarkServices::instance().staticProvider; StarkStaticProvider->onGameLoop();
staticProvider->onGameLoop();
// Check for UI mouse overs // Check for UI mouse overs
for (uint i = 0; i < _windows.size(); i++) { for (uint i = 0; i < _windows.size(); i++) {

View file

@ -45,9 +45,8 @@ namespace Stark {
ActionMenu::ActionMenu(Gfx::Driver *gfx, Cursor *cursor) : ActionMenu::ActionMenu(Gfx::Driver *gfx, Cursor *cursor) :
Window(gfx, cursor) { Window(gfx, cursor) {
StaticProvider *staticProvider = StarkServices::instance().staticProvider;
// TODO: Shouldn't use a function called getCursorImage for this, also unhardcode // TODO: Shouldn't use a function called getCursorImage for this, also unhardcode
_background = staticProvider->getCursorImage(5); _background = StarkStaticProvider->getCursorImage(5);
_unscaled = true; _unscaled = true;
_item = nullptr; _item = nullptr;
@ -66,8 +65,6 @@ ActionMenu::~ActionMenu() {
} }
void ActionMenu::open(Resources::ItemVisual *item, const Common::Point &itemRelativePos) { void ActionMenu::open(Resources::ItemVisual *item, const Common::Point &itemRelativePos) {
GameInterface *game = StarkServices::instance().gameInterface;
_visible = true; _visible = true;
Common::Point screenMousePos = _cursor->getMousePosition(true); Common::Point screenMousePos = _cursor->getMousePosition(true);
@ -81,9 +78,9 @@ void ActionMenu::open(Resources::ItemVisual *item, const Common::Point &itemRela
Resources::ActionArray possible; Resources::ActionArray possible;
if (_fromInventory) { if (_fromInventory) {
possible = game->getActionsPossibleForObject(_item); possible = StarkGameInterface->getActionsPossibleForObject(_item);
} else { } else {
possible = game->getActionsPossibleForObject(_item, _itemRelativePos); possible = StarkGameInterface->getActionsPossibleForObject(_item, _itemRelativePos);
} }
for (uint i = 0; i < possible.size(); i++) { for (uint i = 0; i < possible.size(); i++) {
@ -102,7 +99,6 @@ void ActionMenu::close() {
} }
void ActionMenu::onRender() { void ActionMenu::onRender() {
GameInterface *game = StarkServices::instance().gameInterface;
Common::Point mousePos = getRelativeMousePosition(); Common::Point mousePos = getRelativeMousePosition();
_background->render(Common::Point(0, 0), false); _background->render(Common::Point(0, 0), false);
@ -110,7 +106,7 @@ void ActionMenu::onRender() {
for (uint i = 0; i < ARRAYSIZE(_buttons); i++) { for (uint i = 0; i < ARRAYSIZE(_buttons); i++) {
if (_buttons[i].enabled) { if (_buttons[i].enabled) {
bool active = _buttons[i].rect.contains(mousePos); bool active = _buttons[i].rect.contains(mousePos);
VisualImageXMG *visual = game->getActionImage(_buttons[i].action, active); VisualImageXMG *visual = StarkGameInterface->getActionImage(_buttons[i].action, active);
visual->render(Common::Point(_buttons[i].rect.left, _buttons[i].rect.top), false); visual->render(Common::Point(_buttons[i].rect.left, _buttons[i].rect.top), false);
} }
} }
@ -147,8 +143,6 @@ void ActionMenu::onMouseMove(const Common::Point &pos) {
} }
void ActionMenu::onClick(const Common::Point &pos) { void ActionMenu::onClick(const Common::Point &pos) {
GameInterface *game = StarkServices::instance().gameInterface;
for (uint i = 0; i < ARRAYSIZE(_buttons); i++) { for (uint i = 0; i < ARRAYSIZE(_buttons); i++) {
if (_buttons[i].enabled && _buttons[i].rect.contains(pos)) { if (_buttons[i].enabled && _buttons[i].rect.contains(pos)) {
@ -156,9 +150,9 @@ void ActionMenu::onClick(const Common::Point &pos) {
_inventory->setSelectedInventoryItem(_item->getIndex()); _inventory->setSelectedInventoryItem(_item->getIndex());
} else { } else {
if (_fromInventory) { if (_fromInventory) {
game->itemDoAction(_item, _buttons[i].action); StarkGameInterface->itemDoAction(_item, _buttons[i].action);
} else { } else {
game->itemDoActionAt(_item, _buttons[i].action, _itemRelativePos); StarkGameInterface->itemDoActionAt(_item, _buttons[i].action, _itemRelativePos);
} }
} }

View file

@ -33,12 +33,11 @@ namespace Stark {
ClickText::ClickText(const Common::String &text, Common::Point pos) ClickText::ClickText(const Common::String &text, Common::Point pos)
: _position(pos), : _position(pos),
_text(text) { _text(text) {
Gfx::Driver *gfx = StarkServices::instance().gfx; _visualPassive = new VisualText(StarkGfx);
_visualPassive = new VisualText(gfx);
_visualPassive->setText(_text); _visualPassive->setText(_text);
_visualPassive->setColor(0xFFFF0000); _visualPassive->setColor(0xFFFF0000);
_visualActive = new VisualText(gfx); _visualActive = new VisualText(StarkGfx);
_visualActive->setText(_text); _visualActive->setText(_text);
_visualActive->setColor(0xFF00FF00); _visualActive->setColor(0xFF00FF00);

View file

@ -43,10 +43,9 @@ DialogPanel::DialogPanel(Gfx::Driver *gfx, Cursor *cursor) :
_visible = true; _visible = true;
StaticProvider *staticProvider = StarkServices::instance().staticProvider;
// TODO: Un-hardcode // TODO: Un-hardcode
_activeBackGroundTexture = staticProvider->getCursorImage(20); _activeBackGroundTexture = StarkStaticProvider->getCursorImage(20);
_passiveBackGroundTexture = staticProvider->getCursorImage(21); _passiveBackGroundTexture = StarkStaticProvider->getCursorImage(21);
} }
DialogPanel::~DialogPanel() { DialogPanel::~DialogPanel() {
@ -77,17 +76,16 @@ void DialogPanel::onRender() {
} }
// Update the dialog engine // Update the dialog engine
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer; StarkDialogPlayer->update();
dialogPlayer->update();
// Check if a new speech can be played // Check if a new speech can be played
if (dialogPlayer->isSpeechReady()) { if (StarkDialogPlayer->isSpeechReady()) {
_currentSpeech = dialogPlayer->acquireReadySpeech(); _currentSpeech = StarkDialogPlayer->acquireReadySpeech();
_currentSpeech->playSound(); _currentSpeech->playSound();
updateSubtitleVisual(); updateSubtitleVisual();
} }
if (_options.empty() && dialogPlayer->areOptionsAvailable()) { if (_options.empty() && StarkDialogPlayer->areOptionsAvailable()) {
updateDialogOptions(); updateDialogOptions();
} }
@ -117,8 +115,7 @@ void DialogPanel::updateSubtitleVisual() {
void DialogPanel::updateDialogOptions() { void DialogPanel::updateDialogOptions() {
clearOptions(); clearOptions();
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer; Common::Array<DialogPlayer::Option> options = StarkDialogPlayer->listOptions();
Common::Array<DialogPlayer::Option> options = dialogPlayer->listOptions();
int pos = 0; int pos = 0;
for (uint i = 0; i < options.size(); i++) { for (uint i = 0; i < options.size(); i++) {
@ -148,8 +145,7 @@ void DialogPanel::onClick(const Common::Point &pos) {
if (!_options.empty() && _options.size() > 0) { if (!_options.empty() && _options.size() > 0) {
for (uint i = 0; i < _options.size(); i++) { for (uint i = 0; i < _options.size(); i++) {
if (_options[i]->containsPoint(pos)) { if (_options[i]->containsPoint(pos)) {
DialogPlayer *dialogPlayer = StarkServices::instance().dialogPlayer; StarkDialogPlayer->selectOption(i);
dialogPlayer->selectOption(i);
clearOptions(); clearOptions();
return; return;

View file

@ -49,9 +49,7 @@ FMVPlayer::~FMVPlayer() {
void FMVPlayer::play(const Common::String &name) { void FMVPlayer::play(const Common::String &name) {
// TODO: Clear existing // TODO: Clear existing
ArchiveLoader *archiveLoader = StarkServices::instance().archiveLoader; Common::SeekableReadStream *stream = StarkArchiveLoader->getExternalFile(name, "Global/");
Common::SeekableReadStream *stream = archiveLoader->getExternalFile(name, "Global/");
if (!stream) { if (!stream) {
warning("Could not open %s", name.c_str()); warning("Could not open %s", name.c_str());
return; return;

View file

@ -50,10 +50,8 @@ GameWindow::GameWindow(Gfx::Driver *gfx, Cursor *cursor, ActionMenu *actionMenu,
} }
void GameWindow::onRender() { void GameWindow::onRender() {
Global *global = StarkServices::instance().global;
// List the items to render // List the items to render
_renderEntries = global->getCurrent()->getLocation()->listRenderEntries(); _renderEntries = StarkGlobal->getCurrent()->getLocation()->listRenderEntries();
// Render all the scene items // Render all the scene items
Gfx::RenderEntryArray::iterator element = _renderEntries.begin(); Gfx::RenderEntryArray::iterator element = _renderEntries.begin();
@ -67,10 +65,7 @@ void GameWindow::onRender() {
} }
void GameWindow::onMouseMove(const Common::Point &pos) { void GameWindow::onMouseMove(const Common::Point &pos) {
GameInterface *game = StarkServices::instance().gameInterface; _renderEntries = StarkGlobal->getCurrent()->getLocation()->listRenderEntries();
Global *global = StarkServices::instance().global;
_renderEntries = global->getCurrent()->getLocation()->listRenderEntries();
int16 selectedInventoryItem = _inventory->getSelectedInventoryItem(); int16 selectedInventoryItem = _inventory->getSelectedInventoryItem();
int16 singlePossibleAction = -1; int16 singlePossibleAction = -1;
@ -80,7 +75,7 @@ void GameWindow::onMouseMove(const Common::Point &pos) {
Common::String mouseHint; Common::String mouseHint;
if (selectedInventoryItem != -1) { if (selectedInventoryItem != -1) {
VisualImageXMG *cursorImage = game->getCursorImage(selectedInventoryItem); VisualImageXMG *cursorImage = StarkGameInterface->getCursorImage(selectedInventoryItem);
_cursor->setCursorImage(cursorImage); _cursor->setCursorImage(cursorImage);
} else if (_objectUnderCursor) { } else if (_objectUnderCursor) {
switch (singlePossibleAction) { switch (singlePossibleAction) {
@ -97,12 +92,12 @@ void GameWindow::onMouseMove(const Common::Point &pos) {
_cursor->setCursorType(Cursor::kHand); _cursor->setCursorType(Cursor::kHand);
break; break;
default: default:
VisualImageXMG *cursorImage = game->getCursorImage(singlePossibleAction); VisualImageXMG *cursorImage = StarkGameInterface->getCursorImage(singlePossibleAction);
_cursor->setCursorImage(cursorImage); _cursor->setCursorImage(cursorImage);
break; break;
} }
mouseHint = game->getItemTitle(_objectUnderCursor, true, _objectRelativePosition); mouseHint = StarkGameInterface->getItemTitle(_objectUnderCursor, true, _objectRelativePosition);
} else { } else {
// Not an object // Not an object
_cursor->setCursorType(Cursor::kDefault); _cursor->setCursorType(Cursor::kDefault);
@ -111,8 +106,6 @@ void GameWindow::onMouseMove(const Common::Point &pos) {
} }
void GameWindow::onClick(const Common::Point &pos) { void GameWindow::onClick(const Common::Point &pos) {
GameInterface *game = StarkServices::instance().gameInterface;
_actionMenu->close(); _actionMenu->close();
int16 selectedInventoryItem = _inventory->getSelectedInventoryItem(); int16 selectedInventoryItem = _inventory->getSelectedInventoryItem();
@ -122,13 +115,13 @@ void GameWindow::onClick(const Common::Point &pos) {
if (_objectUnderCursor) { if (_objectUnderCursor) {
if (singlePossibleAction != -1) { if (singlePossibleAction != -1) {
game->itemDoActionAt(_objectUnderCursor, singlePossibleAction, _objectRelativePosition); StarkGameInterface->itemDoActionAt(_objectUnderCursor, singlePossibleAction, _objectRelativePosition);
} else if (selectedInventoryItem == -1) { } else if (selectedInventoryItem == -1) {
_actionMenu->open(_objectUnderCursor, _objectRelativePosition); _actionMenu->open(_objectUnderCursor, _objectRelativePosition);
} }
} else { } else {
// The walk code expects unscaled absolute mouse coordinates // The walk code expects unscaled absolute mouse coordinates
game->walkTo(_cursor->getMousePosition(true)); StarkGameInterface->walkTo(_cursor->getMousePosition(true));
} }
} }
@ -143,8 +136,6 @@ void GameWindow::onRightClick(const Common::Point &pos) {
} }
void GameWindow::checkObjectAtPos(Common::Point pos, int16 selectedInventoryItem, int16 &singlePossibleAction) { void GameWindow::checkObjectAtPos(Common::Point pos, int16 selectedInventoryItem, int16 &singlePossibleAction) {
GameInterface *game = StarkServices::instance().gameInterface;
_objectUnderCursor = nullptr; _objectUnderCursor = nullptr;
singlePossibleAction = -1; singlePossibleAction = -1;
@ -157,24 +148,24 @@ void GameWindow::checkObjectAtPos(Common::Point pos, int16 selectedInventoryItem
} }
} }
if (!_objectUnderCursor || !game->itemHasActionAt(_objectUnderCursor, _objectRelativePosition, -1)) { if (!_objectUnderCursor || !StarkGameInterface->itemHasActionAt(_objectUnderCursor, _objectRelativePosition, -1)) {
// Only consider items with runnable scripts // Only consider items with runnable scripts
_objectUnderCursor = nullptr; _objectUnderCursor = nullptr;
return; return;
} }
int32 defaultAction = game->itemGetDefaultActionAt(_objectUnderCursor, _objectRelativePosition); int32 defaultAction = StarkGameInterface->itemGetDefaultActionAt(_objectUnderCursor, _objectRelativePosition);
if (defaultAction != -1) { if (defaultAction != -1) {
// Use the default action if there is one // Use the default action if there is one
singlePossibleAction = defaultAction; singlePossibleAction = defaultAction;
} else if (selectedInventoryItem != -1) { } else if (selectedInventoryItem != -1) {
// Use the selected inventory item if there is one // Use the selected inventory item if there is one
if (game->itemHasActionAt(_objectUnderCursor, _objectRelativePosition, selectedInventoryItem)) { if (StarkGameInterface->itemHasActionAt(_objectUnderCursor, _objectRelativePosition, selectedInventoryItem)) {
singlePossibleAction = selectedInventoryItem; singlePossibleAction = selectedInventoryItem;
} }
} else { } else {
// Otherwise, use stock actions // Otherwise, use stock actions
Resources::ActionArray actionsPossible = game->getStockActionsPossibleForObject(_objectUnderCursor, _objectRelativePosition); Resources::ActionArray actionsPossible = StarkGameInterface->getStockActionsPossibleForObject(_objectUnderCursor, _objectRelativePosition);
if (actionsPossible.size() == 1) { if (actionsPossible.size() == 1) {
singlePossibleAction = actionsPossible[0]; singlePossibleAction = actionsPossible[0];

View file

@ -48,8 +48,7 @@ InventoryWindow::InventoryWindow(Gfx::Driver *gfx, Cursor *cursor, ActionMenu *a
_position = Common::Rect(Gfx::Driver::kGameViewportWidth, Gfx::Driver::kGameViewportHeight); _position = Common::Rect(Gfx::Driver::kGameViewportWidth, Gfx::Driver::kGameViewportHeight);
_position.translate(0, Gfx::Driver::kTopBorderHeight); _position.translate(0, Gfx::Driver::kTopBorderHeight);
StaticProvider *staticProvider = StarkServices::instance().staticProvider; Resources::Anim *backgroundAnim = StarkStaticProvider->getUIItem(StaticProvider::kInventoryBg);
Resources::Anim *backgroundAnim = staticProvider->getUIItem(StaticProvider::kInventoryBg);
_backgroundTexture = backgroundAnim->getVisual()->get<VisualImageXMG>(); _backgroundTexture = backgroundAnim->getVisual()->get<VisualImageXMG>();
// Center the background in the window // Center the background in the window
@ -93,8 +92,7 @@ Common::Rect InventoryWindow::getItemRect(uint32 slot, VisualImageXMG *image) co
} }
void InventoryWindow::onRender() { void InventoryWindow::onRender() {
Global *global = StarkServices::instance().global; _renderEntries = StarkGlobal->getInventory()->getInventoryRenderEntries();
_renderEntries = global->getInventory()->getInventoryRenderEntries();
_backgroundTexture->render(Common::Point(_backgroundRect.left, _backgroundRect.top), false); _backgroundTexture->render(Common::Point(_backgroundRect.left, _backgroundRect.top), false);
@ -109,8 +107,6 @@ void InventoryWindow::onRender() {
} }
void InventoryWindow::checkObjectAtPos(Common::Point pos, Resources::ItemVisual **item, int16 selectedInventoryItem, int16 &singlePossibleAction) { void InventoryWindow::checkObjectAtPos(Common::Point pos, Resources::ItemVisual **item, int16 selectedInventoryItem, int16 &singlePossibleAction) {
GameInterface *game = StarkServices::instance().gameInterface;
*item = nullptr; *item = nullptr;
singlePossibleAction = -1; singlePossibleAction = -1;
@ -132,14 +128,14 @@ void InventoryWindow::checkObjectAtPos(Common::Point pos, Resources::ItemVisual
if (selectedInventoryItem == -1) { if (selectedInventoryItem == -1) {
Resources::ActionArray actionsPossible; Resources::ActionArray actionsPossible;
actionsPossible = game->getStockActionsPossibleForObject(*item); actionsPossible = StarkGameInterface->getStockActionsPossibleForObject(*item);
if (actionsPossible.empty()) { if (actionsPossible.empty()) {
// The item can still be taken // The item can still be taken
singlePossibleAction = Resources::PATTable::kActionUse; singlePossibleAction = Resources::PATTable::kActionUse;
} }
} else { } else {
if (game->itemHasAction(*item, selectedInventoryItem)) { if (StarkGameInterface->itemHasAction(*item, selectedInventoryItem)) {
singlePossibleAction = selectedInventoryItem; singlePossibleAction = selectedInventoryItem;
} }
} }
@ -158,15 +154,12 @@ void InventoryWindow::onMouseMove(const Common::Point &pos) {
_cursor->setCursorType(Cursor::kDefault); _cursor->setCursorType(Cursor::kDefault);
} }
} else { } else {
GameInterface *game = StarkServices::instance().gameInterface; VisualImageXMG *cursorImage = StarkGameInterface->getCursorImage(_selectedInventoryItem);
VisualImageXMG *cursorImage = game->getCursorImage(_selectedInventoryItem);
_cursor->setCursorImage(cursorImage); _cursor->setCursorImage(cursorImage);
} }
} }
void InventoryWindow::onClick(const Common::Point &pos) { void InventoryWindow::onClick(const Common::Point &pos) {
GameInterface *game = StarkServices::instance().gameInterface;
_actionMenu->close(); _actionMenu->close();
Resources::ItemVisual *clickedItem = nullptr; Resources::ItemVisual *clickedItem = nullptr;
@ -180,7 +173,7 @@ void InventoryWindow::onClick(const Common::Point &pos) {
if (clickedItemAction == Resources::PATTable::kActionUse) { if (clickedItemAction == Resources::PATTable::kActionUse) {
setSelectedInventoryItem(clickedItem->getIndex()); setSelectedInventoryItem(clickedItem->getIndex());
} else { } else {
game->itemDoAction(clickedItem, clickedItemAction); StarkGameInterface->itemDoAction(clickedItem, clickedItemAction);
} }
} else { } else {
// Multiple actions are possible // Multiple actions are possible

View file

@ -40,13 +40,12 @@ TopMenu::TopMenu(Gfx::Driver *gfx, Cursor *cursor) :
_position = Common::Rect(Gfx::Driver::kOriginalWidth, Gfx::Driver::kTopBorderHeight); _position = Common::Rect(Gfx::Driver::kOriginalWidth, Gfx::Driver::kTopBorderHeight);
_visible = true; _visible = true;
StaticProvider *staticProvider = StarkServices::instance().staticProvider;
// TODO: The animations on these should be driven by the engine internally, so we probably shouldn't be holding // TODO: The animations on these should be driven by the engine internally, so we probably shouldn't be holding
// image references here? // image references here?
// TODO: Unhardcode // TODO: Unhardcode
_inventoryButton = new Button("Inventory", staticProvider->getUIItem(StaticProvider::kInventory), Common::Point(0, 0)); _inventoryButton = new Button("Inventory", StarkStaticProvider->getUIItem(StaticProvider::kInventory), Common::Point(0, 0));
_exitButton = new Button("Exit", staticProvider->getUIItem(StaticProvider::kQuit), Common::Point(600, 0)); _exitButton = new Button("Exit", StarkStaticProvider->getUIItem(StaticProvider::kQuit), Common::Point(600, 0));
_diaryButton = new Button("Diary", staticProvider->getUIItem(StaticProvider::kDiaryNormal), Common::Point(560, 0)); _diaryButton = new Button("Diary", StarkStaticProvider->getUIItem(StaticProvider::kDiaryNormal), Common::Point(560, 0));
} }
TopMenu::~TopMenu() { TopMenu::~TopMenu() {
@ -81,11 +80,11 @@ void TopMenu::onClick(const Common::Point &pos) {
if (_exitButton->containsPoint(pos)) { if (_exitButton->containsPoint(pos)) {
// TODO: Ask // TODO: Ask
StarkServices::instance().userInterface->notifyShouldExit(); StarkUserInterface->notifyShouldExit();
} }
if (_inventoryButton->containsPoint(pos)) { if (_inventoryButton->containsPoint(pos)) {
StarkServices::instance().userInterface->notifyShouldOpenInventory(); StarkUserInterface->notifyShouldOpenInventory();
} }
} }