void GfxCompare::kernelBaseSetter(reg_t object) { if (lookupSelector(_segMan, object, SELECTOR(brLeft), NULL, NULL) == kSelectorVariable) { int16 x = readSelectorValue(_segMan, object, SELECTOR(x)); int16 y = readSelectorValue(_segMan, object, SELECTOR(y)); int16 z = (SELECTOR(z) > -1) ? readSelectorValue(_segMan, object, SELECTOR(z)) : 0; int16 yStep = readSelectorValue(_segMan, object, SELECTOR(yStep)); GuiResourceId viewId = readSelectorValue(_segMan, object, SELECTOR(view)); int16 loopNo = readSelectorValue(_segMan, object, SELECTOR(loop)); int16 celNo = readSelectorValue(_segMan, object, SELECTOR(cel)); uint16 scaleSignal = 0; if (getSciVersion() >= SCI_VERSION_1_1) scaleSignal = readSelectorValue(_segMan, object, SELECTOR(scaleSignal)); Common::Rect celRect; GfxView *tmpView = _cache->getView(viewId); if (!tmpView->isScaleable()) scaleSignal = 0; if (scaleSignal & kScaleSignalDoScaling) { celRect = getNSRect(object); } else { tmpView->getCelRect(loopNo, celNo, x, y, z, celRect); } celRect.bottom = y + 1; celRect.top = celRect.bottom - yStep; writeSelectorValue(_segMan, object, SELECTOR(brLeft), celRect.left); writeSelectorValue(_segMan, object, SELECTOR(brRight), celRect.right); writeSelectorValue(_segMan, object, SELECTOR(brTop), celRect.top); writeSelectorValue(_segMan, object, SELECTOR(brBottom), celRect.bottom); } }
reg_t kListEachElementDo(EngineState *s, int argc, reg_t *argv) { List *list = s->_segMan->lookupList(argv[0]); Node *curNode = s->_segMan->lookupNode(list->first); reg_t curObject; Selector slc = argv[1].toUint16(); ObjVarRef address; while (curNode) { // We get the next node here as the current node might be gone after the invoke reg_t nextNode = curNode->succ; curObject = curNode->value; // First, check if the target selector is a variable if (lookupSelector(s->_segMan, curObject, slc, &address, NULL) == kSelectorVariable) { // This can only happen with 3 params (list, target selector, variable) if (argc != 3) { error("kListEachElementDo: Attempted to modify a variable selector with %d params", argc); } else { writeSelector(s->_segMan, curObject, slc, argv[2]); } } else { invokeSelector(s, curObject, slc, argc, argv, argc - 2, argv + 2); } curNode = s->_segMan->lookupNode(nextNode); } return s->r_acc; }
reg_t kListFirstTrue(EngineState *s, int argc, reg_t *argv) { const reg_t listReg = argv[0]; List *list = s->_segMan->lookupList(listReg); Node *curNode = s->_segMan->lookupNode(list->first); Selector slc = argv[1].toUint16(); ObjVarRef address; s->r_acc = NULL_REG; ++list->numRecursions; if (list->numRecursions >= ARRAYSIZE(list->nextNodes)) { error("Too much recursion in kListFirstTrue"); } while (curNode) { // We get the next node here as the current node might be deleted by the // invoke. In the case that the next node is also deleted, kDeleteKey // needs to be able to adjust the location of the next node, which is // why it is stored on the list instead of on the stack list->nextNodes[list->numRecursions] = curNode->succ; reg_t curObject = curNode->value; // First, check if the target selector is a variable if (lookupSelector(s->_segMan, curObject, slc, &address, NULL) == kSelectorVariable) { // If it's a variable selector, check its value. // Example: script 64893 in Torin, MenuHandler::isHilited checks // all children for variable selector 0x03ba (bHilited). if (!readSelector(s->_segMan, curObject, slc).isNull()) { s->r_acc = curObject; break; } } else { invokeSelector(s, curObject, slc, argc, argv, argc - 2, argv + 2); // Check if the call above leads to a game restore, in which case // the segment manager will be reset, and the original list will // be invalidated if (s->abortScriptProcessing == kAbortLoadGame) return s->r_acc; // Check if the result is true if (!s->r_acc.isNull()) { s->r_acc = curObject; break; } } curNode = s->_segMan->lookupNode(list->nextNodes[list->numRecursions]); } if (s->_segMan->isValidAddr(listReg, SEG_TYPE_LISTS)) { --list->numRecursions; } return s->r_acc; }
reg_t readSelector(SegManager *segMan, reg_t object, Selector selectorId) { ObjVarRef address; if (lookupSelector(segMan, object, selectorId, &address, NULL) != kSelectorVariable) return NULL_REG; else return *address.getPointer(segMan); }
reg_t kListEachElementDo(EngineState *s, int argc, reg_t *argv) { const reg_t listReg = argv[0]; List *list = s->_segMan->lookupList(listReg); Node *curNode = s->_segMan->lookupNode(list->first); Selector slc = argv[1].toUint16(); ObjVarRef address; ++list->numRecursions; if (list->numRecursions >= ARRAYSIZE(list->nextNodes)) { error("Too much recursion in kListEachElementDo"); } while (curNode) { // We get the next node here as the current node might be deleted by the // invoke. In the case that the next node is also deleted, kDeleteKey // needs to be able to adjust the location of the next node, which is // why it is stored on the list instead of on the stack list->nextNodes[list->numRecursions] = curNode->succ; reg_t curObject = curNode->value; // First, check if the target selector is a variable if (lookupSelector(s->_segMan, curObject, slc, &address, NULL) == kSelectorVariable) { // This can only happen with 3 params (list, target selector, variable) if (argc != 3) { error("kListEachElementDo: Attempted to modify a variable selector with %d params", argc); } else { writeSelector(s->_segMan, curObject, slc, argv[2]); } } else { invokeSelector(s, curObject, slc, argc, argv, argc - 2, argv + 2); // Check if the call above leads to a game restore, in which case // the segment manager will be reset, and the original list will // be invalidated if (s->abortScriptProcessing == kAbortLoadGame) return s->r_acc; } curNode = s->_segMan->lookupNode(list->nextNodes[list->numRecursions]); } if (s->_segMan->isValidAddr(listReg, SEG_TYPE_LISTS)) { --list->numRecursions; } return s->r_acc; }
void writeSelector(SegManager *segMan, reg_t object, Selector selectorId, reg_t value) { ObjVarRef address; if ((selectorId < 0) || (selectorId > (int)g_sci->getKernel()->getSelectorNamesSize())) { error("Attempt to write to invalid selector %d of" " object at %04x:%04x.", selectorId, PRINT_REG(object)); return; } if (lookupSelector(segMan, object, selectorId, &address, NULL) != kSelectorVariable) error("Selector '%s' of object at %04x:%04x could not be" " written to", g_sci->getKernel()->getSelectorName(selectorId).c_str(), PRINT_REG(object)); else *address.getPointer(segMan) = value; }
void GfxCompare::kernelBaseSetter(reg_t object) { if (lookupSelector(_segMan, object, SELECTOR(brLeft), NULL, NULL) == kSelectorVariable) { int16 x = readSelectorValue(_segMan, object, SELECTOR(x)); int16 y = readSelectorValue(_segMan, object, SELECTOR(y)); int16 z = (SELECTOR(z) > -1) ? readSelectorValue(_segMan, object, SELECTOR(z)) : 0; int16 yStep = readSelectorValue(_segMan, object, SELECTOR(yStep)); GuiResourceId viewId = readSelectorValue(_segMan, object, SELECTOR(view)); int16 loopNo = readSelectorValue(_segMan, object, SELECTOR(loop)); int16 celNo = readSelectorValue(_segMan, object, SELECTOR(cel)); // HACK: Ignore invalid views for now (perhaps unimplemented text views?) if (viewId == 0xFFFF) // invalid view return; uint16 scaleSignal = 0; if (getSciVersion() >= SCI_VERSION_1_1) { scaleSignal = readSelectorValue(_segMan, object, SELECTOR(scaleSignal)); } Common::Rect celRect; GfxView *tmpView = _cache->getView(viewId); if (!tmpView->isScaleable()) scaleSignal = 0; if (scaleSignal & kScaleSignalDoScaling) { celRect = getNSRect(object); } else { if (tmpView->isSci2Hires()) tmpView->adjustToUpscaledCoordinates(y, x); tmpView->getCelRect(loopNo, celNo, x, y, z, celRect); if (tmpView->isSci2Hires()) { tmpView->adjustBackUpscaledCoordinates(celRect.top, celRect.left); tmpView->adjustBackUpscaledCoordinates(celRect.bottom, celRect.right); } } celRect.bottom = y + 1; celRect.top = celRect.bottom - yStep; writeSelectorValue(_segMan, object, SELECTOR(brLeft), celRect.left); writeSelectorValue(_segMan, object, SELECTOR(brRight), celRect.right); writeSelectorValue(_segMan, object, SELECTOR(brTop), celRect.top); writeSelectorValue(_segMan, object, SELECTOR(brBottom), celRect.bottom); } }
reg_t kListAllTrue(EngineState *s, int argc, reg_t *argv) { List *list = s->_segMan->lookupList(argv[0]); Node *curNode = s->_segMan->lookupNode(list->first); reg_t curObject; Selector slc = argv[1].toUint16(); ObjVarRef address; s->r_acc = TRUE_REG; ++list->numRecursions; if (list->numRecursions >= ARRAYSIZE(list->nextNodes)) { error("Too much recursion in kListAllTrue"); } while (curNode) { // We get the next node here as the current node might be deleted by the // invoke. In the case that the next node is also deleted, kDeleteKey // needs to be able to adjust the location of the next node, which is // why it is stored on the list instead of on the stack list->nextNodes[list->numRecursions] = curNode->succ; curObject = curNode->value; // First, check if the target selector is a variable if (lookupSelector(s->_segMan, curObject, slc, &address, NULL) == kSelectorVariable) { // If it's a variable selector, check its value s->r_acc = readSelector(s->_segMan, curObject, slc); } else { invokeSelector(s, curObject, slc, argc, argv, argc - 2, argv + 2); } // Check if the result isn't true if (s->r_acc.isNull()) break; curNode = s->_segMan->lookupNode(list->nextNodes[list->numRecursions]); } --list->numRecursions; return s->r_acc; }
void GfxCompare::kernelSetNowSeen(reg_t objectReference) { GfxView *view = NULL; Common::Rect celRect(0, 0); GuiResourceId viewId = (GuiResourceId)readSelectorValue(_segMan, objectReference, SELECTOR(view)); int16 loopNo = readSelectorValue(_segMan, objectReference, SELECTOR(loop)); int16 celNo = readSelectorValue(_segMan, objectReference, SELECTOR(cel)); int16 x = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(x)); int16 y = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(y)); int16 z = 0; if (SELECTOR(z) > -1) z = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(z)); view = _cache->getView(viewId); view->getCelRect(loopNo, celNo, x, y, z, celRect); if (lookupSelector(_segMan, objectReference, SELECTOR(nsTop), NULL, NULL) == kSelectorVariable) { setNSRect(objectReference, celRect); } }
void GfxCompare::kernelSetNowSeen(reg_t objectReference) { GfxView *view = NULL; Common::Rect celRect(0, 0); GuiResourceId viewId = (GuiResourceId)readSelectorValue(_segMan, objectReference, SELECTOR(view)); // HACK: Ignore invalid views for now (perhaps unimplemented text views?) if (viewId == 0xFFFF) // invalid view return; int16 loopNo = readSelectorValue(_segMan, objectReference, SELECTOR(loop)); int16 celNo = readSelectorValue(_segMan, objectReference, SELECTOR(cel)); int16 x = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(x)); int16 y = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(y)); int16 z = 0; if (SELECTOR(z) > -1) z = (int16)readSelectorValue(_segMan, objectReference, SELECTOR(z)); view = _cache->getView(viewId); #ifdef ENABLE_SCI32 if (view->isSci2Hires()) view->adjustToUpscaledCoordinates(y, x); else if (getSciVersion() == SCI_VERSION_2_1) _coordAdjuster->fromScriptToDisplay(y, x); #endif view->getCelRect(loopNo, celNo, x, y, z, celRect); #ifdef ENABLE_SCI32 if (view->isSci2Hires()) { view->adjustBackUpscaledCoordinates(celRect.top, celRect.left); view->adjustBackUpscaledCoordinates(celRect.bottom, celRect.right); } else if (getSciVersion() == SCI_VERSION_2_1) { _coordAdjuster->fromDisplayToScript(celRect.top, celRect.left); _coordAdjuster->fromDisplayToScript(celRect.bottom, celRect.right); } #endif if (lookupSelector(_segMan, objectReference, SELECTOR(nsTop), NULL, NULL) == kSelectorVariable) { setNSRect(objectReference, celRect); } }
reg_t GameFeatures::getDetectionAddr(const Common::String &objName, Selector slc, int methodNum) { // Get address of target object reg_t objAddr = _segMan->findObjectByName(objName, 0); reg_t addr; if (objAddr.isNull()) { error("getDetectionAddr: %s object couldn't be found", objName.c_str()); return NULL_REG; } if (methodNum == -1) { if (lookupSelector(_segMan, objAddr, slc, NULL, &addr) != kSelectorMethod) { error("getDetectionAddr: target selector is not a method of object %s", objName.c_str()); return NULL_REG; } } else { addr = _segMan->getObject(objAddr)->getFunction(methodNum); } return addr; }
void GfxFrameout::kernelUpdateScreenItem(reg_t object) { // Ignore invalid items if (!_segMan->isObject(object)) { warning("kernelUpdateScreenItem: Attempt to update an invalid object (%04x:%04x)", PRINT_REG(object)); return; } FrameoutEntry *itemEntry = findScreenItem(object); if (!itemEntry) { warning("kernelUpdateScreenItem: invalid object %04x:%04x", PRINT_REG(object)); return; } itemEntry->viewId = readSelectorValue(_segMan, object, SELECTOR(view)); itemEntry->loopNo = readSelectorValue(_segMan, object, SELECTOR(loop)); itemEntry->celNo = readSelectorValue(_segMan, object, SELECTOR(cel)); itemEntry->x = readSelectorValue(_segMan, object, SELECTOR(x)); itemEntry->y = readSelectorValue(_segMan, object, SELECTOR(y)); itemEntry->z = readSelectorValue(_segMan, object, SELECTOR(z)); itemEntry->priority = readSelectorValue(_segMan, object, SELECTOR(priority)); if (readSelectorValue(_segMan, object, SELECTOR(fixPriority)) == 0) itemEntry->priority = itemEntry->y; itemEntry->signal = readSelectorValue(_segMan, object, SELECTOR(signal)); itemEntry->scaleSignal = readSelectorValue(_segMan, object, SELECTOR(scaleSignal)); if (itemEntry->scaleSignal & kScaleSignalDoScaling32) { itemEntry->scaleX = readSelectorValue(_segMan, object, SELECTOR(scaleX)); itemEntry->scaleY = readSelectorValue(_segMan, object, SELECTOR(scaleY)); } else { itemEntry->scaleX = 128; itemEntry->scaleY = 128; } itemEntry->visible = true; // Check if the entry can be hidden if (lookupSelector(_segMan, object, SELECTOR(visible), NULL, NULL) != kSelectorNone) itemEntry->visible = readSelectorValue(_segMan, object, SELECTOR(visible)); }
void GuestAdditions::syncTorinVolumeFromScummVM(const int16 musicVolume, const int16 sfxVolume, const int16 speechVolume) const { _state->variables[VAR_GLOBAL][kGlobalVarTorinMusicVolume] = make_reg(0, musicVolume); _state->variables[VAR_GLOBAL][kGlobalVarTorinSFXVolume] = make_reg(0, sfxVolume); _state->variables[VAR_GLOBAL][kGlobalVarTorinSpeechVolume] = make_reg(0, speechVolume); // Calling `reSyncVol` on all sounds is necessary to propagate the // volume change to existing sounds, and matches how game scripts // propagate volume changes when the in-game volume sliders are moved const reg_t soundsId = _state->variables[VAR_GLOBAL][kGlobalVarSounds]; if (!soundsId.isNull()) { const Selector selector = SELECTOR(reSyncVol); List *sounds = _segMan->lookupList(readSelector(_segMan, soundsId, SELECTOR(elements))); reg_t soundId = sounds->first; while (!soundId.isNull()) { Node *sound = _segMan->lookupNode(soundId); const reg_t &soundObj = sound->value; if (_segMan->isHeapObject(soundObj) && lookupSelector(_segMan, soundObj, selector, nullptr, nullptr) != kSelectorNone) { invokeSelector(sound->value, SELECTOR(reSyncVol)); } soundId = sound->succ; } } }
reg_t kListFirstTrue(EngineState *s, int argc, reg_t *argv) { List *list = s->_segMan->lookupList(argv[0]); Node *curNode = s->_segMan->lookupNode(list->first); reg_t curObject; Selector slc = argv[1].toUint16(); ObjVarRef address; s->r_acc = NULL_REG; // reset the accumulator while (curNode) { reg_t nextNode = curNode->succ; curObject = curNode->value; // First, check if the target selector is a variable if (lookupSelector(s->_segMan, curObject, slc, &address, NULL) == kSelectorVariable) { // If it's a variable selector, check its value. // Example: script 64893 in Torin, MenuHandler::isHilited checks // all children for variable selector 0x03ba (bHilited). if (!readSelector(s->_segMan, curObject, slc).isNull()) return curObject; } else { invokeSelector(s, curObject, slc, argc, argv, argc - 2, argv + 2); // Check if the result is true if (!s->r_acc.isNull()) return curObject; } curNode = s->_segMan->lookupNode(nextNode); } // No selector returned true return NULL_REG; }
void GfxFrameout::kernelFrameout() { if (g_sci->_robotDecoder->isVideoLoaded()) { bool skipVideo = false; RobotDecoder *videoDecoder = g_sci->_robotDecoder; uint16 x = videoDecoder->getPos().x; uint16 y = videoDecoder->getPos().y; if (videoDecoder->hasDirtyPalette()) videoDecoder->setSystemPalette(); while (!g_engine->shouldQuit() && !videoDecoder->endOfVideo() && !skipVideo) { if (videoDecoder->needsUpdate()) { const Graphics::Surface *frame = videoDecoder->decodeNextFrame(); if (frame) { g_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); if (videoDecoder->hasDirtyPalette()) videoDecoder->setSystemPalette(); g_system->updateScreen(); } } Common::Event event; while (g_system->getEventManager()->pollEvent(event)) { if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) skipVideo = true; } g_system->delayMillis(10); } return; } _palette->palVaryUpdate(); for (PlaneList::iterator it = _planes.begin(); it != _planes.end(); it++) { reg_t planeObject = it->object; uint16 planeLastPriority = it->lastPriority; // Update priority here, sq6 sets it w/o UpdatePlane uint16 planePriority = it->priority = readSelectorValue(_segMan, planeObject, SELECTOR(priority)); it->lastPriority = planePriority; if (planePriority == 0xffff) { // Plane currently not meant to be shown // If plane was shown before, delete plane rect if (planePriority != planeLastPriority) _paint32->fillRect(it->planeRect, 0); continue; } if (it->planeBack) _paint32->fillRect(it->planeRect, it->planeBack); GuiResourceId planeMainPictureId = it->pictureId; _coordAdjuster->pictureSetDisplayArea(it->planeRect); _palette->drewPicture(planeMainPictureId); FrameoutList itemList; // Copy screen items of the current frame to the list of items to be drawn for (FrameoutList::iterator listIterator = _screenItems.begin(); listIterator != _screenItems.end(); listIterator++) { reg_t itemPlane = readSelector(_segMan, (*listIterator)->object, SELECTOR(plane)); if (planeObject == itemPlane) { kernelUpdateScreenItem((*listIterator)->object); // TODO: Why is this necessary? itemList.push_back(*listIterator); } } for (PlanePictureList::iterator pictureIt = _planePictures.begin(); pictureIt != _planePictures.end(); pictureIt++) { if (pictureIt->object == planeObject) { GfxPicture *planePicture = pictureIt->picture; // Allocate memory for picture cels pictureIt->pictureCels = new FrameoutEntry[planePicture->getSci32celCount()]; // Add following cels to the itemlist FrameoutEntry *picEntry = pictureIt->pictureCels; int planePictureCels = planePicture->getSci32celCount(); for (int pictureCelNr = 0; pictureCelNr < planePictureCels; pictureCelNr++) { picEntry->celNo = pictureCelNr; picEntry->object = NULL_REG; picEntry->picture = planePicture; picEntry->y = planePicture->getSci32celY(pictureCelNr); picEntry->x = planePicture->getSci32celX(pictureCelNr); picEntry->picStartX = pictureIt->startX; picEntry->priority = planePicture->getSci32celPriority(pictureCelNr); itemList.push_back(picEntry); picEntry++; } } } // Now sort our itemlist Common::sort(itemList.begin(), itemList.end(), sortHelper); // warning("Plane %s", _segMan->getObjectName(planeObject)); for (FrameoutList::iterator listIterator = itemList.begin(); listIterator != itemList.end(); listIterator++) { FrameoutEntry *itemEntry = *listIterator; if (itemEntry->object.isNull()) { // Picture cel data itemEntry->y = ((itemEntry->y * _screen->getHeight()) / scriptsRunningHeight); itemEntry->x = ((itemEntry->x * _screen->getWidth()) / scriptsRunningWidth); itemEntry->picStartX = ((itemEntry->picStartX * _screen->getWidth()) / scriptsRunningWidth); // Out of view int16 pictureCelStartX = itemEntry->picStartX + itemEntry->x; int16 pictureCelEndX = pictureCelStartX + itemEntry->picture->getSci32celWidth(itemEntry->celNo); int16 planeStartX = it->planeOffsetX; int16 planeEndX = planeStartX + it->planeRect.width(); if (pictureCelEndX < planeStartX) continue; if (pictureCelStartX > planeEndX) continue; int16 pictureOffsetX = it->planeOffsetX; int16 pictureX = itemEntry->x; if ((it->planeOffsetX) || (itemEntry->picStartX)) { if (it->planeOffsetX <= itemEntry->picStartX) { pictureX += itemEntry->picStartX - it->planeOffsetX; pictureOffsetX = 0; } else { pictureOffsetX = it->planeOffsetX - itemEntry->picStartX; } } itemEntry->picture->drawSci32Vga(itemEntry->celNo, pictureX, itemEntry->y, pictureOffsetX, it->planePictureMirrored); // warning("picture cel %d %d", itemEntry->celNo, itemEntry->priority); } else if (itemEntry->viewId != 0xFFFF) { GfxView *view = _cache->getView(itemEntry->viewId); // warning("view %s %04x:%04x", _segMan->getObjectName(itemEntry->object), PRINT_REG(itemEntry->object)); if (view->isSci2Hires()) { int16 dummyX = 0; _screen->adjustToUpscaledCoordinates(itemEntry->y, itemEntry->x); _screen->adjustToUpscaledCoordinates(itemEntry->z, dummyX); } else if (getSciVersion() == SCI_VERSION_2_1) { itemEntry->y = (itemEntry->y * _screen->getHeight()) / scriptsRunningHeight; itemEntry->x = (itemEntry->x * _screen->getWidth()) / scriptsRunningWidth; itemEntry->z = (itemEntry->z * _screen->getHeight()) / scriptsRunningHeight; } // Adjust according to current scroll position itemEntry->x -= it->planeOffsetX; uint16 useInsetRect = readSelectorValue(_segMan, itemEntry->object, SELECTOR(useInsetRect)); if (useInsetRect) { itemEntry->celRect.top = readSelectorValue(_segMan, itemEntry->object, SELECTOR(inTop)); itemEntry->celRect.left = readSelectorValue(_segMan, itemEntry->object, SELECTOR(inLeft)); itemEntry->celRect.bottom = readSelectorValue(_segMan, itemEntry->object, SELECTOR(inBottom)) + 1; itemEntry->celRect.right = readSelectorValue(_segMan, itemEntry->object, SELECTOR(inRight)) + 1; if (view->isSci2Hires()) { _screen->adjustToUpscaledCoordinates(itemEntry->celRect.top, itemEntry->celRect.left); _screen->adjustToUpscaledCoordinates(itemEntry->celRect.bottom, itemEntry->celRect.right); } itemEntry->celRect.translate(itemEntry->x, itemEntry->y); // TODO: maybe we should clip the cels rect with this, i'm not sure // the only currently known usage is game menu of gk1 } else { if ((itemEntry->scaleX == 128) && (itemEntry->scaleY == 128)) view->getCelRect(itemEntry->loopNo, itemEntry->celNo, itemEntry->x, itemEntry->y, itemEntry->z, itemEntry->celRect); else view->getCelScaledRect(itemEntry->loopNo, itemEntry->celNo, itemEntry->x, itemEntry->y, itemEntry->z, itemEntry->scaleX, itemEntry->scaleY, itemEntry->celRect); Common::Rect nsRect = itemEntry->celRect; // Translate back to actual coordinate within scrollable plane nsRect.translate(it->planeOffsetX, 0); if (view->isSci2Hires()) { _screen->adjustBackUpscaledCoordinates(nsRect.top, nsRect.left); _screen->adjustBackUpscaledCoordinates(nsRect.bottom, nsRect.right); } else if (getSciVersion() == SCI_VERSION_2_1) { nsRect.top = (nsRect.top * scriptsRunningHeight) / _screen->getHeight(); nsRect.left = (nsRect.left * scriptsRunningWidth) / _screen->getWidth(); nsRect.bottom = (nsRect.bottom * scriptsRunningHeight) / _screen->getHeight(); nsRect.right = (nsRect.right * scriptsRunningWidth) / _screen->getWidth(); } writeSelectorValue(_segMan, itemEntry->object, SELECTOR(nsLeft), nsRect.left); writeSelectorValue(_segMan, itemEntry->object, SELECTOR(nsTop), nsRect.top); writeSelectorValue(_segMan, itemEntry->object, SELECTOR(nsRight), nsRect.right); writeSelectorValue(_segMan, itemEntry->object, SELECTOR(nsBottom), nsRect.bottom); } int16 screenHeight = _screen->getHeight(); int16 screenWidth = _screen->getWidth(); if (view->isSci2Hires()) { screenHeight = _screen->getDisplayHeight(); screenWidth = _screen->getDisplayWidth(); } if (itemEntry->celRect.bottom < 0 || itemEntry->celRect.top >= screenHeight) continue; if (itemEntry->celRect.right < 0 || itemEntry->celRect.left >= screenWidth) continue; Common::Rect clipRect, translatedClipRect; clipRect = itemEntry->celRect; if (view->isSci2Hires()) { clipRect.clip(it->upscaledPlaneClipRect); translatedClipRect = clipRect; translatedClipRect.translate(it->upscaledPlaneRect.left, it->upscaledPlaneRect.top); } else { clipRect.clip(it->planeClipRect); translatedClipRect = clipRect; translatedClipRect.translate(it->planeRect.left, it->planeRect.top); } if (!clipRect.isEmpty()) { if ((itemEntry->scaleX == 128) && (itemEntry->scaleY == 128)) view->draw(itemEntry->celRect, clipRect, translatedClipRect, itemEntry->loopNo, itemEntry->celNo, 255, 0, view->isSci2Hires()); else view->drawScaled(itemEntry->celRect, clipRect, translatedClipRect, itemEntry->loopNo, itemEntry->celNo, 255, itemEntry->scaleX, itemEntry->scaleY); } } else { // Most likely a text entry // This draws text the "SCI0-SCI11" way. In SCI2, text is prerendered in kCreateTextBitmap // TODO: rewrite this the "SCI2" way (i.e. implement the text buffer to draw inside kCreateTextBitmap) if (lookupSelector(_segMan, itemEntry->object, SELECTOR(text), NULL, NULL) == kSelectorVariable) { reg_t stringObject = readSelector(_segMan, itemEntry->object, SELECTOR(text)); // The object in the text selector of the item can be either a raw string // or a Str object. In the latter case, we need to access the object's data // selector to get the raw string. if (_segMan->isHeapObject(stringObject)) stringObject = readSelector(_segMan, stringObject, SELECTOR(data)); Common::String text = _segMan->getString(stringObject); GfxFont *font = _cache->getFont(readSelectorValue(_segMan, itemEntry->object, SELECTOR(font))); bool dimmed = readSelectorValue(_segMan, itemEntry->object, SELECTOR(dimmed)); uint16 foreColor = readSelectorValue(_segMan, itemEntry->object, SELECTOR(fore)); itemEntry->y = ((itemEntry->y * _screen->getHeight()) / scriptsRunningHeight); itemEntry->x = ((itemEntry->x * _screen->getWidth()) / scriptsRunningWidth); uint16 startX = itemEntry->x + it->planeRect.left; uint16 curY = itemEntry->y + it->planeRect.top; const char *txt = text.c_str(); // HACK. The plane sometimes doesn't contain the correct width. This // hack breaks the dialog options when speaking with Grace, but it's // the best we got up to now. This happens because of the unimplemented // kTextWidth function in SCI32. // TODO: Remove this once kTextWidth has been implemented. uint16 w = it->planeRect.width() >= 20 ? it->planeRect.width() : _screen->getWidth() - 10; int16 charCount; // Upscale the coordinates/width if the fonts are already upscaled if (_screen->fontIsUpscaled()) { startX = startX * _screen->getDisplayWidth() / _screen->getWidth(); curY = curY * _screen->getDisplayHeight() / _screen->getHeight(); w = w * _screen->getDisplayWidth() / _screen->getWidth(); } while (*txt) { charCount = GetLongest(txt, w, font); if (charCount == 0) break; uint16 curX = startX; for (int i = 0; i < charCount; i++) { unsigned char curChar = txt[i]; font->draw(curChar, curY, curX, foreColor, dimmed); curX += font->getCharWidth(curChar); } curY += font->getHeight(); txt += charCount; while (*txt == ' ') txt++; // skip over breaking spaces } } } } for (PlanePictureList::iterator pictureIt = _planePictures.begin(); pictureIt != _planePictures.end(); pictureIt++) { if (pictureIt->object == planeObject) { delete[] pictureIt->pictureCels; pictureIt->pictureCels = 0; } } } _screen->copyToScreen(); g_sci->getEngineState()->_throttleTrigger = true; }
bool Object::initBaseObject(SegManager *segMan, reg_t addr, bool doInitSuperClass) { const Object *baseObj = segMan->getObject(getSpeciesSelector()); if (baseObj) { uint originalVarCount = _variables.size(); if (_variables.size() != baseObj->getVarCount()) _variables.resize(baseObj->getVarCount()); // Copy base from species class, as we need its selector IDs _baseObj = baseObj->_baseObj; assert(_baseObj); if (doInitSuperClass) initSuperClass(segMan, addr); if (_variables.size() != originalVarCount) { // These objects are probably broken. // An example is 'witchCage' in script 200 in KQ5 (#3034714), // but also 'girl' in script 216 and 'door' in script 22. // In LSL3 a number of sound objects trigger this right away. // SQ4-floppy's bug #3037938 also seems related. // The effect is that a number of its method selectors may be // treated as variable selectors, causing unpredictable effects. int objScript = segMan->getScript(_pos.getSegment())->getScriptNumber(); // We have to do a little bit of work to get the name of the object // before any relocations are done. reg_t nameReg = getNameSelector(); const char *name; if (nameReg.isNull()) { name = "<no name>"; } else { nameReg.setSegment(_pos.getSegment()); name = segMan->derefString(nameReg); if (!name) name = "<invalid name>"; } debugC(kDebugLevelVM, "Object %04x:%04x (name %s, script %d) " "varnum doesn't match baseObj's: obj %d, base %d", PRINT_REG(_pos), name, objScript, originalVarCount, baseObj->getVarCount()); #if 0 // We enumerate the methods selectors which could be hidden here if (getSciVersion() <= SCI_VERSION_2_1) { const SegmentRef objRef = segMan->dereference(baseObj->_pos); assert(objRef.isRaw); uint segBound = objRef.maxSize/2 - baseObj->getVarCount(); const byte* buf = (const byte *)baseObj->_baseVars; if (!buf) { // While loading this may happen due to objects being loaded // out of order, and we can't proceed then, unfortunately. segBound = 0; } for (uint i = baseObj->getVarCount(); i < originalVarCount && i < segBound; ++i) { uint16 slc = READ_SCI11ENDIAN_UINT16(buf + 2*i); // Skip any numbers which happen to be varselectors too bool found = false; for (uint j = 0; j < baseObj->getVarCount() && !found; ++j) found = READ_SCI11ENDIAN_UINT16(buf + 2*j) == slc; if (found) continue; // Skip any selectors which aren't method selectors, // so couldn't be mistaken for varselectors if (lookupSelector(segMan, _pos, slc, 0, 0) != kSelectorMethod) continue; warning(" Possibly affected selector: %02x (%s)", slc, g_sci->getKernel()->getSelectorName(slc).c_str()); } } #endif } return true; } return false; }
void GfxFrameout::kernelFrameout() { if (g_sci->_robotDecoder->isVideoLoaded()) { showVideo(); return; } _palette->palVaryUpdate(); for (PlaneList::iterator it = _planes.begin(); it != _planes.end(); it++) { reg_t planeObject = it->object; // Draw any plane lines, if they exist // These are drawn on invisible planes as well. (e.g. "invisiblePlane" in LSL6 hires) // FIXME: Lines aren't always drawn (e.g. when the narrator speaks in LSL6 hires). // Perhaps something is painted over them? for (PlaneLineList::iterator it2 = it->lines.begin(); it2 != it->lines.end(); ++it2) { Common::Point startPoint = it2->startPoint; Common::Point endPoint = it2->endPoint; _coordAdjuster->kernelLocalToGlobal(startPoint.x, startPoint.y, it->object); _coordAdjuster->kernelLocalToGlobal(endPoint.x, endPoint.y, it->object); _screen->drawLine(startPoint, endPoint, it2->color, it2->priority, it2->control); } int16 planeLastPriority = it->lastPriority; // Update priority here, sq6 sets it w/o UpdatePlane int16 planePriority = it->priority = readSelectorValue(_segMan, planeObject, SELECTOR(priority)); it->lastPriority = planePriority; if (planePriority < 0) { // Plane currently not meant to be shown // If plane was shown before, delete plane rect if (planePriority != planeLastPriority) _paint32->fillRect(it->planeRect, 0); continue; } // There is a race condition lurking in SQ6, which causes the game to hang in the intro, when teleporting to Polysorbate LX. // Since I first wrote the patch, the race has stopped occurring for me though. // I'll leave this for investigation later, when someone can reproduce. //if (it->pictureId == kPlanePlainColored) // FIXME: This is what SSCI does, and fixes the intro of LSL7, but breaks the dialogs in GK1 (adds black boxes) if (it->pictureId == kPlanePlainColored && (it->planeBack || g_sci->getGameId() != GID_GK1)) _paint32->fillRect(it->planeRect, it->planeBack); _coordAdjuster->pictureSetDisplayArea(it->planeRect); // Invoking drewPicture() with an invalid picture ID in SCI32 results in // invalidating the palVary palette when a palVary effect is active. This // is quite obvious in QFG4, where the day time palette is incorrectly // shown when exiting the caves, and the correct night time palette // flashes briefly each time that kPalVaryInit is called. if (it->pictureId != 0xFFFF) _palette->drewPicture(it->pictureId); FrameoutList itemList; createPlaneItemList(planeObject, itemList); for (FrameoutList::iterator listIterator = itemList.begin(); listIterator != itemList.end(); listIterator++) { FrameoutEntry *itemEntry = *listIterator; if (!itemEntry->visible) continue; if (itemEntry->object.isNull()) { // Picture cel data _coordAdjuster->fromScriptToDisplay(itemEntry->y, itemEntry->x); _coordAdjuster->fromScriptToDisplay(itemEntry->picStartY, itemEntry->picStartX); if (!isPictureOutOfView(itemEntry, it->planeRect, it->planeOffsetX, it->planeOffsetY)) drawPicture(itemEntry, it->planeOffsetX, it->planeOffsetY, it->planePictureMirrored); } else { GfxView *view = (itemEntry->viewId != 0xFFFF) ? _cache->getView(itemEntry->viewId) : NULL; int16 dummyX = 0; if (view && view->isSci2Hires()) { view->adjustToUpscaledCoordinates(itemEntry->y, itemEntry->x); view->adjustToUpscaledCoordinates(itemEntry->z, dummyX); } else if (getSciVersion() >= SCI_VERSION_2_1) { _coordAdjuster->fromScriptToDisplay(itemEntry->y, itemEntry->x); _coordAdjuster->fromScriptToDisplay(itemEntry->z, dummyX); } // Adjust according to current scroll position itemEntry->x -= it->planeOffsetX; itemEntry->y -= it->planeOffsetY; uint16 useInsetRect = readSelectorValue(_segMan, itemEntry->object, SELECTOR(useInsetRect)); if (useInsetRect) { itemEntry->celRect.top = readSelectorValue(_segMan, itemEntry->object, SELECTOR(inTop)); itemEntry->celRect.left = readSelectorValue(_segMan, itemEntry->object, SELECTOR(inLeft)); itemEntry->celRect.bottom = readSelectorValue(_segMan, itemEntry->object, SELECTOR(inBottom)); itemEntry->celRect.right = readSelectorValue(_segMan, itemEntry->object, SELECTOR(inRight)); if (view && view->isSci2Hires()) { view->adjustToUpscaledCoordinates(itemEntry->celRect.top, itemEntry->celRect.left); view->adjustToUpscaledCoordinates(itemEntry->celRect.bottom, itemEntry->celRect.right); } itemEntry->celRect.translate(itemEntry->x, itemEntry->y); // TODO: maybe we should clip the cels rect with this, i'm not sure // the only currently known usage is game menu of gk1 } else if (view) { // Process global scaling, if needed. // TODO: Seems like SCI32 always processes global scaling for scaled objects // TODO: We can only process symmetrical scaling for now (i.e. same value for scaleX/scaleY) if ((itemEntry->scaleSignal & kScaleSignalDoScaling32) && !(itemEntry->scaleSignal & kScaleSignalDisableGlobalScaling32) && (itemEntry->scaleX == itemEntry->scaleY) && itemEntry->scaleX != 128) applyGlobalScaling(itemEntry, it->planeRect, view->getHeight(itemEntry->loopNo, itemEntry->celNo)); if ((itemEntry->scaleX == 128) && (itemEntry->scaleY == 128)) view->getCelRect(itemEntry->loopNo, itemEntry->celNo, itemEntry->x, itemEntry->y, itemEntry->z, itemEntry->celRect); else view->getCelScaledRect(itemEntry->loopNo, itemEntry->celNo, itemEntry->x, itemEntry->y, itemEntry->z, itemEntry->scaleX, itemEntry->scaleY, itemEntry->celRect); Common::Rect nsRect = itemEntry->celRect; // Translate back to actual coordinate within scrollable plane nsRect.translate(it->planeOffsetX, it->planeOffsetY); if (g_sci->getGameId() == GID_PHANTASMAGORIA2) { // HACK: Some (?) objects in Phantasmagoria 2 have no NS rect. Skip them for now. // TODO: Remove once we figure out how Phantasmagoria 2 draws objects on screen. if (lookupSelector(_segMan, itemEntry->object, SELECTOR(nsLeft), NULL, NULL) != kSelectorVariable) continue; } if (view && view->isSci2Hires()) { view->adjustBackUpscaledCoordinates(nsRect.top, nsRect.left); view->adjustBackUpscaledCoordinates(nsRect.bottom, nsRect.right); g_sci->_gfxCompare->setNSRect(itemEntry->object, nsRect); } else if (getSciVersion() >= SCI_VERSION_2_1 && _resMan->detectHires()) { _coordAdjuster->fromDisplayToScript(nsRect.top, nsRect.left); _coordAdjuster->fromDisplayToScript(nsRect.bottom, nsRect.right); g_sci->_gfxCompare->setNSRect(itemEntry->object, nsRect); } } // Don't attempt to draw sprites that are outside the visible // screen area. An example is the random people walking in // Jackson Square in GK1. if (itemEntry->celRect.bottom < 0 || itemEntry->celRect.top >= _screen->getDisplayHeight() || itemEntry->celRect.right < 0 || itemEntry->celRect.left >= _screen->getDisplayWidth()) continue; Common::Rect clipRect, translatedClipRect; clipRect = itemEntry->celRect; if (view && view->isSci2Hires()) { clipRect.clip(it->upscaledPlaneClipRect); translatedClipRect = clipRect; translatedClipRect.translate(it->upscaledPlaneRect.left, it->upscaledPlaneRect.top); } else { // QFG4 passes invalid rectangles when a battle is starting if (!clipRect.isValidRect()) continue; clipRect.clip(it->planeClipRect); translatedClipRect = clipRect; translatedClipRect.translate(it->planeRect.left, it->planeRect.top); } if (view) { if (!clipRect.isEmpty()) { if ((itemEntry->scaleX == 128) && (itemEntry->scaleY == 128)) view->draw(itemEntry->celRect, clipRect, translatedClipRect, itemEntry->loopNo, itemEntry->celNo, 255, 0, view->isSci2Hires()); else view->drawScaled(itemEntry->celRect, clipRect, translatedClipRect, itemEntry->loopNo, itemEntry->celNo, 255, itemEntry->scaleX, itemEntry->scaleY); } } // Draw text, if it exists if (lookupSelector(_segMan, itemEntry->object, SELECTOR(text), NULL, NULL) == kSelectorVariable) { g_sci->_gfxText32->drawTextBitmap(itemEntry->x, itemEntry->y, it->planeRect, itemEntry->object); } } } for (PlanePictureList::iterator pictureIt = _planePictures.begin(); pictureIt != _planePictures.end(); pictureIt++) { if (pictureIt->object == planeObject) { delete[] pictureIt->pictureCels; pictureIt->pictureCels = 0; } } } showCurrentScrollText(); _screen->copyToScreen(); g_sci->getEngineState()->_throttleTrigger = true; }
SciVersion GameFeatures::detectGfxFunctionsType() { if (_gfxFunctionsType == SCI_VERSION_NONE) { if (getSciVersion() == SCI_VERSION_0_EARLY) { // Old SCI0 games always used old graphics functions _gfxFunctionsType = SCI_VERSION_0_EARLY; } else if (getSciVersion() >= SCI_VERSION_01) { // SCI01 and newer games always used new graphics functions _gfxFunctionsType = SCI_VERSION_0_LATE; } else { // SCI0 late // Check if the game is using an overlay bool searchRoomObj = false; reg_t rmObjAddr = _segMan->findObjectByName("Rm"); if (SELECTOR(overlay) != -1) { // The game has an overlay selector, check how it calls kDrawPic // to determine the graphics functions type used if (lookupSelector(_segMan, rmObjAddr, SELECTOR(overlay), NULL, NULL) == kSelectorMethod) { if (!autoDetectGfxFunctionsType()) { warning("Graphics functions detection failed, taking an educated guess"); // Try detecting the graphics function types from the // existence of the motionCue selector (which is a bit // of a hack) if (_kernel->findSelector("motionCue") != -1) _gfxFunctionsType = SCI_VERSION_0_LATE; else _gfxFunctionsType = SCI_VERSION_0_EARLY; } } else { // The game has an overlay selector, but it's not a method // of the Rm object (like in Hoyle 1 and 2), so search for // other methods searchRoomObj = true; } } else { // The game doesn't have an overlay selector, so search for it // manually searchRoomObj = true; } if (searchRoomObj) { // If requested, check if any method of the Rm object is calling // kDrawPic, as the overlay selector might be missing in demos bool found = false; const Object *obj = _segMan->getObject(rmObjAddr); for (uint m = 0; m < obj->getMethodCount(); m++) { found = autoDetectGfxFunctionsType(m); if (found) break; } if (!found) { // No method of the Rm object is calling kDrawPic, thus the // game doesn't have overlays and is using older graphics // functions _gfxFunctionsType = SCI_VERSION_0_EARLY; } } } debugC(1, kDebugLevelVM, "Detected graphics functions type: %s", getSciVersionDesc(_gfxFunctionsType)); } return _gfxFunctionsType; }
reg_t kRespondsTo(EngineState *s, int argc, reg_t *argv) { reg_t obj = argv[0]; int selector = argv[1].toUint16(); return make_reg(0, s->_segMan->isHeapObject(obj) && lookupSelector(s->_segMan, obj, selector, NULL, NULL) != kSelectorNone); }