bool Console::Cmd_DecompileScript(int argc, const char **argv) { if (argc >= 2) { uint index = atoi(argv[1]); Common::Array<Resources::Script *> scripts = listAllLocationScripts(); if (index < scripts.size()) { Resources::Script *script = scripts[index]; Tools::Decompiler *decompiler = new Tools::Decompiler(script); if (decompiler->getError() != "") { debugPrintf("Decompilation failure: %s\n", decompiler->getError().c_str()); } debug("Script %d - %s:", index, script->getName().c_str()); decompiler->printDecompiled(); delete decompiler; return true; } else { debugPrintf("Invalid index %d, only %d indices available\n", index, scripts.size()); } } else { debugPrintf("Too few args\n"); } debugPrintf("Decompile a script. Use listScripts to get an id\n"); debugPrintf("Usage :\n"); debugPrintf("decompileScript [id]\n"); return true; }
bool Console::Cmd_ForceScript(int argc, const char **argv) { uint index = 0; if (argc >= 2) { index = atoi(argv[1]); Common::Array<Resources::Script *> scripts = listAllLocationScripts(); if (index < scripts.size() ) { Resources::Script *script = scripts[index]; script->enable(true); script->goToNextCommand(); // Skip the begin command to avoid checks script->execute(Resources::Script::kCallModePlayerAction); return true; } else { debugPrintf("Invalid index %d, only %d indices available\n", index, scripts.size()); } } else { debugPrintf("Too few args\n"); } debugPrintf("Force the execution of a script. Use listScripts to get an id\n"); debugPrintf("Usage :\n"); debugPrintf("forceScript [id]\n"); return true; }
void VisualText::createTexture() { // Get the font and required metrics const Graphics::Font *font = StarkFontProvider->getScaledFont(_fontType, _fontCustomIndex); uint scaledLineHeight = StarkFontProvider->getScaledFontHeight(_fontType, _fontCustomIndex); uint originalLineHeight = StarkFontProvider->getOriginalFontHeight(_fontType, _fontCustomIndex); uint maxScaledLineWidth = StarkFontProvider->scaleWidthOriginalToCurrent(_originalRect.width()); // Word wrap the text and compute the scaled and original resolution bounding boxes Common::Rect scaledRect; Common::Array<Common::String> lines; scaledRect.right = scaledRect.left + font->wordWrapText(_text, maxScaledLineWidth, lines); scaledRect.bottom = scaledRect.top + scaledLineHeight * lines.size(); _originalRect.bottom = _originalRect.top + originalLineHeight * lines.size(); // Create a surface to render to Graphics::Surface surface; surface.create(scaledRect.width(), scaledRect.height(), _gfx->getScreenFormat()); surface.fillRect(scaledRect, _backgroundColor); // Render the lines to the surface for (uint i = 0; i < lines.size(); i++) { font->drawString(&surface, lines[i], 0, scaledLineHeight * i, scaledRect.width(), _color); } // Create a texture from the surface _texture = _gfx->createTexture(&surface); surface.free(); }
bool Console::Cmd_EnableScript(int argc, const char **argv) { uint index = 0; if (argc >= 2) { index = atoi(argv[1]); bool value = true; if (argc >= 3) { value = atoi(argv[2]); } Common::Array<Resources::Script *> scripts = listAllLocationScripts(); if (index < scripts.size() ) { Resources::Script *script = scripts[index]; script->enable(value); return true; } else { debugPrintf("Invalid index %d, only %d indices available\n", index, scripts.size()); } } else { debugPrintf("Too few args\n"); } debugPrintf("Enable or disable a script. Use listScripts to get an id\n"); debugPrintf("Usage :\n"); debugPrintf("enableScript [id] (value)\n"); return true; }
void VisualText::createTexture() { Common::CodePage codePage = StarkSettings->getTextCodePage(); Common::U32String unicodeText = Common::convertToU32String(_text.c_str(), codePage); // Get the font and required metrics const Graphics::Font *font = StarkFontProvider->getScaledFont(_fontType, _fontCustomIndex); uint scaledLineHeight = StarkFontProvider->getScaledFontHeight(_fontType, _fontCustomIndex); uint originalLineHeight = StarkFontProvider->getOriginalFontHeight(_fontType, _fontCustomIndex); uint maxScaledLineWidth = StarkGfx->scaleWidthOriginalToCurrent(_targetWidth); // Word wrap the text Common::Array<Common::U32String> lines; font->wordWrapText(unicodeText, maxScaledLineWidth, lines); // Use the actual font bounding box to prevent text from being cut off Common::Rect scaledRect; if (!lines.empty()) { scaledRect = font->getBoundingBox(lines[0]); for (uint i = 1; i < lines.size(); i++) { scaledRect.extend(font->getBoundingBox(lines[i], 0, scaledLineHeight * i)); } } // Make sure lines have approximately consistent height regardless of the characters they use scaledRect.bottom = MAX<int16>(scaledRect.bottom, scaledLineHeight * lines.size()); if (!isBlank()) { _originalRect.right = StarkGfx->scaleWidthCurrentToOriginal(scaledRect.right); _originalRect.bottom = originalLineHeight * lines.size(); } else { // For Empty text, preserve the original width and height for being used as clicking area _originalRect.right = _targetWidth; _originalRect.bottom = _targetHeight; } // Create a surface to render to Graphics::Surface surface; surface.create(scaledRect.right, scaledRect.bottom, Gfx::Driver::getRGBAPixelFormat()); uint32 color = surface.format.ARGBToColor( _color.a, _color.r, _color.g, _color.b ); uint32 bgColor = surface.format.ARGBToColor( _backgroundColor.a, _backgroundColor.r, _backgroundColor.g, _backgroundColor.b ); surface.fillRect(Common::Rect(surface.w, surface.h), bgColor); // Render the lines to the surface for (uint i = 0; i < lines.size(); i++) { font->drawString(&surface, lines[i], 0, scaledLineHeight * i, surface.w, color, _align); } // Create a texture from the surface _texture = _gfx->createTexture(&surface); _texture->setSamplingFilter(Gfx::Texture::kNearest); surface.free(); }
void Graphics::renderPolygonEdge(Common::Array<Common::Point> &points, byte colour) { ::Graphics::Surface *surf = _vm->_system->lockScreen(); for (unsigned int i = 0; i < points.size(); i++) { if (i + 1 < points.size()) surf->drawLine(points[i].x, points[i].y, points[i + 1].x, points[i + 1].y, colour); else surf->drawLine(points[i].x, points[i].y, points[0].x, points[0].y, colour); } _vm->_system->unlockScreen(); }
bool Console::Cmd_GiveItem(int argc, const char **argv) { if (argc != 2) { debugPrintf("Usage: %s <ID | name>\n", argv[0]); return true; } Common::List<Item>::iterator item; char *end; uint id = strtoul(argv[1], &end, 0); if (*end != 0) { Common::Array<Item *> matches; Common::String name = toAppleWord(argv[1]); if (!_engine->_nouns.contains(name)) { debugPrintf("Item '%s' not found\n", argv[1]); return true; } byte noun = _engine->_nouns[name]; for (item = _engine->_state.items.begin(); item != _engine->_state.items.end(); ++item) { if (item->noun == noun) matches.push_back(&*item); } if (matches.size() == 0) { debugPrintf("Item '%s' not found\n", argv[1]); return true; } if (matches.size() > 1) { debugPrintf("Multiple matches found, please use item ID:\n"); for (uint i = 0; i < matches.size(); ++i) printItem(*matches[i]); return true; } matches[0]->room = IDI_ANY; debugPrintf("OK\n"); return true; } for (item = _engine->_state.items.begin(); item != _engine->_state.items.end(); ++item) if (item->id == id) { item->room = IDI_ANY; debugPrintf("OK\n"); return true; } debugPrintf("Item %i not found\n", id); return true; }
void DirectorEngine::loadSharedCastsFrom(Common::String filename) { Archive *shardcst; if (getVersion() < 4) { shardcst = new RIFFArchive(); } else { shardcst = new RIFXArchive(); } shardcst->openFile(filename); Score *castScore = new Score(this); Common::SeekableSubReadStreamEndian *castStream = shardcst->getResource(MKTAG('V','W','C','R'), 1024); castScore->loadCastData(*castStream); *_sharedCasts = castScore->_casts; Common::Array<uint16> dib = shardcst->getResourceIDList(MKTAG('D','I','B',' ')); if (dib.size() != 0) { Common::Array<uint16>::iterator iterator; for (iterator = dib.begin(); iterator != dib.end(); ++iterator) { debug(3, "Shared DIB %d", *iterator); _sharedDIB->setVal(*iterator, shardcst->getResource(MKTAG('D','I','B',' '), *iterator)); } } Common::Array<uint16> stxt = shardcst->getResourceIDList(MKTAG('S','T','X','T')); if (stxt.size() != 0) { Common::Array<uint16>::iterator iterator; for (iterator = stxt.begin(); iterator != stxt.end(); ++iterator) { debug(3, "Shared STXT %d", *iterator); _sharedSTXT->setVal(*iterator, shardcst->getResource(MKTAG('S','T','X','T'), *iterator)); } } Common::Array<uint16> bmp = shardcst->getResourceIDList(MKTAG('B','I','T','D')); if (bmp.size() != 0) { Common::Array<uint16>::iterator iterator; for (iterator = bmp.begin(); iterator != bmp.end(); ++iterator) { _sharedBMP->setVal(*iterator, shardcst->getResource(MKTAG('B','I','T','D'), *iterator)); } } Common::Array<uint16> sound = shardcst->getResourceIDList(MKTAG('S','N','D',' ')); if (stxt.size() != 0) { Common::Array<uint16>::iterator iterator; for (iterator = sound.begin(); iterator != sound.end(); ++iterator) { _sharedSound->setVal(*iterator, shardcst->getResource(MKTAG('S','N','D',' '), *iterator)); } } }
void OpenGLGraphicsManager::displayMessageOnOSD(const char *msg) { #ifdef USE_OSD // HACK: Actually no client code should use graphics functions from // another thread. But the MT-32 emulator still does, thus we need to // make sure this doesn't happen while a updateScreen call is done. Common::StackLock lock(_osdMutex); // Slip up the lines. Common::Array<Common::String> osdLines; Common::StringTokenizer tokenizer(msg, "\n"); while (!tokenizer.empty()) { osdLines.push_back(tokenizer.nextToken()); } // Do the actual drawing like the SDL backend. const Graphics::Font *font = getFontOSD(); Graphics::Surface *dst = _osd->getSurface(); _osd->fill(0); _osd->flagDirty(); // Determine a rect which would contain the message string (clipped to the // screen dimensions). const int vOffset = 6; const int lineSpacing = 1; const int lineHeight = font->getFontHeight() + 2 * lineSpacing; int width = 0; int height = lineHeight * osdLines.size() + 2 * vOffset; for (uint i = 0; i < osdLines.size(); i++) { width = MAX(width, font->getStringWidth(osdLines[i]) + 14); } // Clip the rect width = MIN<int>(width, dst->w); height = MIN<int>(height, dst->h); int dstX = (dst->w - width) / 2; int dstY = (dst->h - height) / 2; // Draw a dark gray rect. const uint32 color = dst->format.RGBToColor(40, 40, 40); dst->fillRect(Common::Rect(dstX, dstY, dstX + width, dstY + height), color); // Render the message, centered, and in white const uint32 white = dst->format.RGBToColor(255, 255, 255); for (uint i = 0; i < osdLines.size(); ++i) { font->drawString(dst, osdLines[i], dstX, dstY + i * lineHeight + vOffset + lineSpacing, width, white, Graphics::kTextAlignCenter); } // Init the OSD display parameters. _osdAlpha = kOSDInitialAlpha; _osdFadeStartTime = g_system->getMillis() + kOSDFadeOutDelay; #endif }
BaseSurface *BaseFontTT::renderTextToTexture(const WideString &text, int width, TTextAlign align, int maxHeight, int &textOffset) { //TextLineList lines; // TODO: Use WideString-conversion here. //WrapText(text, width, maxHeight, lines); Common::Array<Common::String> lines; _font->wordWrapText(text, width, lines); while (maxHeight > 0 && lines.size() * _lineHeight > maxHeight) { lines.pop_back(); } if (lines.size() == 0) { return nullptr; } Graphics::TextAlign alignment = Graphics::kTextAlignInvalid; if (align == TAL_LEFT) { alignment = Graphics::kTextAlignLeft; } else if (align == TAL_CENTER) { alignment = Graphics::kTextAlignCenter; } else if (align == TAL_RIGHT) { alignment = Graphics::kTextAlignRight; } debugC(kWintermuteDebugFont, "%s %d %d %d %d", text.c_str(), RGBCOLGetR(_layers[0]->_color), RGBCOLGetG(_layers[0]->_color), RGBCOLGetB(_layers[0]->_color), RGBCOLGetA(_layers[0]->_color)); // void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const; Graphics::Surface *surface = new Graphics::Surface(); if (_deletableFont) { // We actually have a TTF surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24)); } else { // We are using a fallback, they can't do 32bpp surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0)); } uint32 useColor = 0xffffffff; Common::Array<Common::String>::iterator it; int heightOffset = 0; for (it = lines.begin(); it != lines.end(); ++it) { _font->drawString(surface, *it, 0, heightOffset, width, useColor, alignment); heightOffset += (int)_lineHeight; } BaseSurface *retSurface = _gameRef->_renderer->createSurface(); Graphics::Surface *convertedSurface = surface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24)); retSurface->putSurface(*convertedSurface, true); convertedSurface->free(); surface->free(); delete surface; delete convertedSurface; return retSurface; // TODO: _isUnderline, _isBold, _isItalic, _isStriked }
PECursorManager::PECursorManager(const Common::String &appName) { Common::PEResources exe; if (!exe.loadFromEXE(appName)) { // Not all have cursors anyway, so this is not a problem return; } const Common::Array<Common::WinResourceID> cursorGroups = exe.getNameList(Common::kPEGroupCursor); _cursors.resize(cursorGroups.size()); for (uint i = 0; i < cursorGroups.size(); i++) { _cursors[i].id = cursorGroups[i].getID(); _cursors[i].cursorGroup = Graphics::WinCursorGroup::createCursorGroup(exe, cursorGroups[i]); } }
void Inventory::loadFromState() { Common::Array<uint16> items = _vm->_state->getInventory(); _inventory.clear(); for (uint i = 0; i < items.size(); i++) addItem(items[i], true); }
void ThemeEngine::drawTab(const Common::Rect &r, int tabHeight, int tabWidth, const Common::Array<Common::String> &tabs, int active, uint16 hints, int titleVPad, WidgetStateInfo state) { if (!ready()) return; queueDD(kDDTabBackground, Common::Rect(r.left, r.top, r.right, r.top + tabHeight)); for (int i = 0; i < (int)tabs.size(); ++i) { if (i == active) continue; if (r.left + i * tabWidth > r.right || r.left + (i + 1) * tabWidth > r.right) continue; Common::Rect tabRect(r.left + i * tabWidth, r.top, r.left + (i + 1) * tabWidth, r.top + tabHeight); queueDD(kDDTabInactive, tabRect); queueDDText(getTextData(kDDTabInactive), getTextColor(kDDTabInactive), tabRect, tabs[i], false, false, _widgets[kDDTabInactive]->_textAlignH, _widgets[kDDTabInactive]->_textAlignV); } if (active >= 0 && (r.left + active * tabWidth < r.right) && (r.left + (active + 1) * tabWidth < r.right)) { Common::Rect tabRect(r.left + active * tabWidth, r.top, r.left + (active + 1) * tabWidth, r.top + tabHeight); const uint16 tabLeft = active * tabWidth; const uint16 tabRight = MAX(r.right - tabRect.right, 0); queueDD(kDDTabActive, tabRect, (tabLeft << 16) | (tabRight & 0xFFFF)); queueDDText(getTextData(kDDTabActive), getTextColor(kDDTabActive), tabRect, tabs[active], false, false, _widgets[kDDTabActive]->_textAlignH, _widgets[kDDTabActive]->_textAlignV); } }
void StateProvider::writeResourceTree(Resources::Object *resource, Common::WriteStream *stream, bool current) { // Explicit scope to control the lifespan of the memory stream { Common::MemoryWriteStreamDynamic resourceStream(DisposeAfterUse::YES); ResourceSerializer serializer(nullptr, &resourceStream, kSaveVersion); // Serialize the resource to a memory stream if (current) { resource->saveLoadCurrent(&serializer); } else { resource->saveLoad(&serializer); } // Write the resource to the target stream stream->writeByte(resource->getType().get()); stream->writeByte(resource->getSubType()); stream->writeUint32LE(resourceStream.size()); stream->write(resourceStream.getData(), resourceStream.size()); } // Serialize the resource children Common::Array<Resources::Object *> children = resource->listChildren<Resources::Object>(); for (uint i = 0; i < children.size(); i++) { writeResourceTree(children[i], stream, current); } }
void StateProvider::readResourceTree(Resources::Object *resource, Common::SeekableReadStream *stream, bool current, uint32 version) { // Read the resource to the source stream /* byte type = */ stream->readByte(); /* byte subType = */ stream->readByte(); uint32 size = stream->readUint32LE(); if (size > 0) { Common::SeekableReadStream *resourceStream = stream->readStream(size); ResourceSerializer serializer(resourceStream, nullptr, version); // Deserialize the resource state from stream if (current) { resource->saveLoadCurrent(&serializer); } else { resource->saveLoad(&serializer); } delete resourceStream; } // Deserialize the resource children Common::Array<Resources::Object *> children = resource->listChildren<Resources::Object>(); for (uint i = 0; i < children.size(); i++) { readResourceTree(children[i], stream, current, version); } }
bool LabEngine::checkConditions(const Common::Array<int16> &condition) { for (unsigned int i = 0; i < condition.size(); ++i) if (!_conditions->in(condition[i])) return false; return true; }
void bringWordtoTop(char *str, int wordnum) { // This function reorders the words on the given pred.dic line // by moving the word at position 'wordnum' to the front (that is, right behind // right behind the numerical code word at the start of the line). Common::Array<Common::String> words; char buf[MAXLINELEN]; if (!str) return; strncpy(buf, str, MAXLINELEN); buf[MAXLINELEN - 1] = 0; char *word = strtok(buf, " "); if (!word) { debug("Invalid dictionary line"); return; } words.push_back(word); while ((word = strtok(NULL, " ")) != NULL) words.push_back(word); words.insert_at(1, words.remove_at(wordnum + 1)); Common::String tmp; for (uint8 i = 0; i < words.size(); i++) tmp += words[i] + " "; tmp.deleteLastChar(); memcpy(str, tmp.c_str(), strlen(str)); }
void listSavegames(Common::Array<SavegameDesc> &saves) { Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager(); // Load all saves Common::StringList saveNames = saveFileMan->listSavefiles(((SciEngine *)g_engine)->getSavegamePattern()); for (Common::StringList::const_iterator iter = saveNames.begin(); iter != saveNames.end(); ++iter) { Common::String filename = *iter; Common::SeekableReadStream *in; if ((in = saveFileMan->openForLoading(filename))) { SavegameMetadata meta; if (!get_savegame_metadata(in, &meta)) { // invalid delete in; continue; } delete in; SavegameDesc desc; desc.id = strtol(filename.end() - 3, NULL, 10); desc.date = meta.savegame_date; desc.time = meta.savegame_time; debug(3, "Savegame in file %s ok, id %d", filename.c_str(), desc.id); saves.push_back(desc); } } // Sort the list by creation date of the saves qsort(saves.begin(), saves.size(), sizeof(SavegameDesc), _savegame_index_struct_compare); }
void FloorEdge::addNeighboursFromFace(const FloorFace *face) { Common::Array<FloorEdge *> faceEdges = face->getEdges(); for (uint i = 0; i < faceEdges.size(); i++) { if (faceEdges[i] != this) { _neighbours.push_back(faceEdges[i]); } } }
bool CPetRemote::loadGlyphs(const Common::Array<uint> &indexes) { for (uint idx = 0; idx < indexes.size(); ++idx) { if (!loadGlyph(indexes[idx])) return false; } return true; }
MessageDialog::MessageDialog(const Common::String &message, const char *defaultButton, const char *altButton) : Dialog(30, 20, 260, 124) { const int screenW = g_system->getOverlayWidth(); const int screenH = g_system->getOverlayHeight(); int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0); int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0); // First, determine the size the dialog needs. For this we have to break // down the string into lines, and taking the maximum of their widths. // Using this, and accounting for the space the button(s) need, we can set // the real size of the dialog Common::Array<Common::String> lines; int lineCount, okButtonPos, cancelButtonPos; int maxlineWidth = g_gui.getFont().wordWrapText(message, screenW - 2 * 20, lines); // Calculate the desired dialog size (maxing out at 300*180 for now) if (altButton) _w = MAX(maxlineWidth, (2 * buttonWidth) + 10) + 20; else _w = MAX(maxlineWidth, buttonWidth) + 20; lineCount = lines.size(); _h = 16; if (defaultButton || altButton) _h += buttonHeight + 8; // Limit the number of lines so that the dialog still fits on the screen. if (lineCount > (screenH - 20 - _h) / kLineHeight) { lineCount = (screenH - 20 - _h) / kLineHeight; } _h += lineCount * kLineHeight; // Center the dialog _x = (screenW - _w) / 2; _y = (screenH - _h) / 2; // Each line is represented by one static text item. for (int i = 0; i < lineCount; i++) { new StaticTextWidget(this, 10, 10 + i * kLineHeight, maxlineWidth, kLineHeight, lines[i], Graphics::kTextAlignCenter); } if (defaultButton && altButton) { okButtonPos = (_w - (buttonWidth * 2)) / 2; cancelButtonPos = ((_w - (buttonWidth * 2)) / 2) + buttonWidth + 10; } else { okButtonPos = cancelButtonPos = (_w - buttonWidth) / 2; } if (defaultButton) new ButtonWidget(this, okButtonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, defaultButton, 0, kOkCmd, Common::ASCII_RETURN); // Confirm dialog if (altButton) new ButtonWidget(this, cancelButtonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, altButton, 0, kCancelCmd, Common::ASCII_ESCAPE); // Cancel dialog }
// Print a list of all registered commands (and variables, if any), // nicely word-wrapped. bool Debugger::Cmd_Help(int argc, const char **argv) { #ifndef USE_TEXT_CONSOLE const int charsPerLine = _debuggerDialog->getCharsPerLine(); #elif defined(USE_READLINE) int charsPerLine, rows; rl_get_screen_size(&rows, &charsPerLine); #else // Can we do better? const int charsPerLine = 80; #endif int width, size; uint i; DebugPrintf("Commands are:\n"); // Obtain a list of sorted command names Common::Array<Common::String> cmds; CommandsMap::const_iterator iter, e = _cmds.end(); for (iter = _cmds.begin(); iter != e; ++iter) { cmds.push_back(iter->_key); } sort(cmds.begin(), cmds.end()); // Print them all width = 0; for (i = 0; i < cmds.size(); i++) { size = cmds[i].size() + 1; if ((width + size) >= charsPerLine) { DebugPrintf("\n"); width = size; } else width += size; DebugPrintf("%s ", cmds[i].c_str()); } DebugPrintf("\n"); if (!_dvars.empty()) { DebugPrintf("\n"); DebugPrintf("Variables are:\n"); width = 0; for (i = 0; i < _dvars.size(); i++) { size = _dvars[i].name.size() + 1; if ((width + size) >= charsPerLine) { DebugPrintf("\n"); width = size; } else width += size; DebugPrintf("%s ", _dvars[i].name.c_str()); } DebugPrintf("\n"); } return true; }
bool Console::Cmd_ListLocations(int argc, const char **argv) { ArchiveLoader *archiveLoader = new ArchiveLoader(); // Temporarily replace the global archive loader with our instance ArchiveLoader *gameArchiveLoader = StarkArchiveLoader; StarkArchiveLoader = archiveLoader; archiveLoader->load("x.xarc"); Resources::Root *root = archiveLoader->useRoot<Resources::Root>("x.xarc"); // Find all the levels Common::Array<Resources::Level *> levels = root->listChildren<Resources::Level>(); // Loop over the levels for (uint i = 0; i < levels.size(); i++) { Resources::Level *level = levels[i]; Common::String levelArchive = archiveLoader->buildArchiveName(level); debugPrintf("%s - %s\n", levelArchive.c_str(), level->getName().c_str()); // Load the detailed level archive archiveLoader->load(levelArchive); level = archiveLoader->useRoot<Resources::Level>(levelArchive); Common::Array<Resources::Location *> locations = level->listChildren<Resources::Location>(); // Loop over the locations for (uint j = 0; j < locations.size(); j++) { Resources::Location *location = locations[j]; Common::String roomArchive = archiveLoader->buildArchiveName(level, location); debugPrintf("%s - %s\n", roomArchive.c_str(), location->getName().c_str()); } archiveLoader->returnRoot(levelArchive); archiveLoader->unloadUnused(); } // Restore the global archive loader StarkArchiveLoader = gameArchiveLoader; delete archiveLoader; return true; }
void MaterialData::initEMI(Common::SeekableReadStream *data) { Common::Array<Common::String> texFileNames; char readFileName[64]; if (_fname.hasSuffix(".sur")) { // This expects that we want all the materials in the sur-file TextSplitter *ts = new TextSplitter(data); ts->setLineNumber(2); // Skip copyright-line ts->expectString("version\t1.0"); if (ts->checkString("name:")) ts->scanString("name:%s", 1, readFileName); while(!ts->checkString("END_OF_SECTION")) { ts->scanString("tex:%s", 1, readFileName); Common::String mFileName(readFileName); texFileNames.push_back(mFileName); } Common::SeekableReadStream *texData; _textures = new Texture[texFileNames.size()]; for (uint i = 0; i < texFileNames.size(); i++) { warning("SUR-file texture: %s", texFileNames[i].c_str()); texData = g_resourceloader->openNewStreamFile(texFileNames[i].c_str(), true); if (!texData) { warning("Couldn't find tex-file: %s", texFileNames[i].c_str()); _textures[i]._width = 0; _textures[i]._height = 0; _textures[i]._texture = new int(1); // HACK to avoid initializing. continue; } loadTGA(texData, _textures + i); delete texData; } _numImages = texFileNames.size(); delete ts; return; } else if(_fname.hasSuffix(".tga")) { _numImages = 1; _textures = new Texture(); loadTGA(data, _textures); // texFileNames.push_back(filename); return; } else { warning("Unknown material-format: %s", _fname.c_str()); } }
void DirectorEngine::loadSharedCastsFrom(Common::String filename) { Archive *shardcst = createArchive(); debugC(1, kDebugLoading, "Loading Shared cast '%s'", filename.c_str()); shardcst->openFile(filename); _sharedDIB = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>; _sharedSTXT = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>; _sharedSound = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>; _sharedBMP = new Common::HashMap<int, Common::SeekableSubReadStreamEndian *>; Score *castScore = new Score(this, shardcst); castScore->loadConfig(*shardcst->getResource(MKTAG('V','W','C','F'), 1024)); castScore->loadCastData(*shardcst->getResource(MKTAG('V','W','C','R'), 1024)); _sharedCasts = &castScore->_casts; Common::Array<uint16> dib = shardcst->getResourceIDList(MKTAG('D','I','B',' ')); if (dib.size() != 0) { debugC(3, kDebugLoading, "Loading %d DIBs", dib.size()); for (Common::Array<uint16>::iterator iterator = dib.begin(); iterator != dib.end(); ++iterator) { debugC(3, kDebugLoading, "Shared DIB %d", *iterator); _sharedDIB->setVal(*iterator, shardcst->getResource(MKTAG('D','I','B',' '), *iterator)); } } Common::Array<uint16> stxt = shardcst->getResourceIDList(MKTAG('S','T','X','T')); if (stxt.size() != 0) { debugC(3, kDebugLoading, "Loading %d STXTs", stxt.size()); for (Common::Array<uint16>::iterator iterator = stxt.begin(); iterator != stxt.end(); ++iterator) { debugC(3, kDebugLoading, "Shared STXT %d", *iterator); _sharedSTXT->setVal(*iterator, shardcst->getResource(MKTAG('S','T','X','T'), *iterator)); } } Common::Array<uint16> bmp = shardcst->getResourceIDList(MKTAG('B','I','T','D')); if (bmp.size() != 0) { debugC(3, kDebugLoading, "Loading %d BITDs", bmp.size()); for (Common::Array<uint16>::iterator iterator = bmp.begin(); iterator != bmp.end(); ++iterator) { _sharedBMP->setVal(*iterator, shardcst->getResource(MKTAG('B','I','T','D'), *iterator)); } } Common::Array<uint16> sound = shardcst->getResourceIDList(MKTAG('S','N','D',' ')); if (stxt.size() != 0) { debugC(3, kDebugLoading, "Loading %d SNDs", sound.size()); for (Common::Array<uint16>::iterator iterator = sound.begin(); iterator != sound.end(); ++iterator) { _sharedSound->setVal(*iterator, shardcst->getResource(MKTAG('S','N','D',' '), *iterator)); } } }
void reverseArray(Common::Array<T> &arr) { const uint size = arr.size(); if (size < 2) return; for (uint i = 0; i <= (size / 2 - 1); ++i) { SWAP(arr[i], arr[size - i - 1]); } }
void CSTimeModule::bubbleTextDrawProc(Feature *feature) { Common::Rect bounds = feature->_data.bounds; bounds.grow(-5); const Graphics::Font &font = _vm->getInterface()->getDialogFont(); uint height = font.getFontHeight(); Common::Array<Common::String> lines; font.wordWrapText(_vm->getInterface()->getCurrBubbleText(), bounds.width(), lines); Graphics::Surface *screen = _vm->_system->lockScreen(); for (int x = -2; x < 2; x++) for (int y = -1; y < 3; y++) for (uint i = 0; i < lines.size(); i++) font.drawString(screen, lines[i], bounds.left + x, bounds.top + y + i*height, bounds.width(), 241, Graphics::kTextAlignCenter); for (uint i = 0; i < lines.size(); i++) font.drawString(screen, lines[i], bounds.left, bounds.top + i*height, bounds.width(), 32, Graphics::kTextAlignCenter); _vm->_system->unlockScreen(); }
Database::Database(Myst3Engine *vm) : _vm(vm), _currentRoomID(0), _executableVersion(0), _currentRoomData(0) { _executableVersion = _vm->getExecutableVersion(); if (_executableVersion != 0) { debug("Initializing database from %s (Platform: %s) (%s)", _executableVersion->executable, getPlatformDescription(_vm->getPlatform()), _executableVersion->description); } else { error("Could not find any executable to load"); } // Load the ages and rooms description Common::SeekableSubReadStreamEndian *file = openDatabaseFile(); file->seek(_executableVersion->ageTableOffset); _ages = loadAges(*file); for (uint i = 0; i < _ages.size(); i++) { file->seek(_ages[i].roomsOffset); // Read the room offset table Common::Array<uint32> roomsOffsets; for (uint j = 0; j < _ages[i].roomCount; j++) { uint32 offset = file->readUint32() - _executableVersion->baseOffset; roomsOffsets.push_back(offset); } // Load the rooms for (uint j = 0; j < roomsOffsets.size(); j++) { file->seek(roomsOffsets[j]); _ages[i].rooms.push_back(loadRoomDescription(*file)); } } file->seek(_executableVersion->nodeInitScriptOffset); _nodeInitScript = loadOpcodes(*file); file->seek(_executableVersion->soundNamesOffset); loadSoundNames(file); // TODO: Remove once the offset table is complete if (!_executableVersion->ambientCuesOffset) { error("The description for this executable (%s, %s) does not contain the ambient cues offset. Please contact the ResidualVM team.", _executableVersion->executable, _executableVersion->description); } file->seek(_executableVersion->ambientCuesOffset); loadAmbientCues(file); preloadCommonRooms(file); initializeZipBitIndexTable(file); delete file; }
Node *Tree::aStarSearch_singlePass() { float currentT = 0.0; Node *retNode = NULL; static int maxTime = 0; if (_currentChildIndex == 1) { maxTime = _ai->getPlayerMaxTime(); } if (_currentChildIndex) { if (!(_currentMap->size())) { retNode = _currentNode; return retNode; } _currentNode = _currentMap->front()->node; _currentMap->erase(_currentMap->begin()); } if ((_currentNode->getDepth() < _maxDepth) && (Node::getNodeCount() < _maxNodes) && ((!maxTime) || (_ai->getTimerValue(3) < maxTime))) { // Generate nodes _currentChildIndex = _currentNode->generateChildren(); if (_currentChildIndex) { Common::Array<Node *> vChildren = _currentNode->getChildren(); if (!vChildren.size() && !_currentMap->size()) { _currentChildIndex = 0; retNode = _currentNode; } for (Common::Array<Node *>::iterator i = vChildren.begin(); i != vChildren.end(); i++) { IContainedObject *pTemp = (*i)->getContainedObject(); currentT = pTemp->calcT(); if (currentT == SUCCESS) { retNode = *i; i = vChildren.end() - 1; } else { _currentMap->insert(new TreeNode(currentT, (*i))); } } if (!(_currentMap->size()) && (currentT != SUCCESS)) { assert(_currentNode != NULL); retNode = _currentNode; } } } else { retNode = _currentNode; } return retNode; }
bool Console::Cmd_DumpKnowledge(int argc, const char **argv) { Resources::Level *level = StarkGlobal->getCurrent()->getLevel(); Resources::Location *location = StarkGlobal->getCurrent()->getLocation(); Common::Array<Resources::Knowledge *> knowledge = level->listChildrenRecursive<Resources::Knowledge>(); knowledge.insert_at(knowledge.size(), location->listChildrenRecursive<Resources::Knowledge>()); Common::Array<Resources::Knowledge *>::iterator it; for (it = knowledge.begin(); it != knowledge.end(); ++it) { (*it)->print(); } return true; }