byte *Sword2Engine::fetchScreenHeader(byte *screenFile) { if (isPsx()) { // In PSX version there's no MultiScreenHeader, so just skip resource header return screenFile + ResHeader::size(); } else { MultiScreenHeader mscreenHeader; mscreenHeader.read(screenFile + ResHeader::size()); return screenFile + ResHeader::size() + mscreenHeader.screen; } }
byte *Sword2Engine::fetchPaletteMatchTable(byte *screenFile) { if (isPsx()) return NULL; MultiScreenHeader mscreenHeader; mscreenHeader.read(screenFile + ResHeader::size()); return screenFile + ResHeader::size() + mscreenHeader.paletteTable; }
byte *Sword2Engine::fetchLayerHeader(byte *screenFile, uint16 layerNo) { #ifdef SWORD2_DEBUG ScreenHeader screenHead; screenHead.read(fetchScreenHeader(screenFile)); assert(layerNo < screenHead.noLayers); #endif if (isPsx()) { return screenFile + ResHeader::size() + ScreenHeader::size() + 2 + 0x400 + layerNo * LayerHeader::size(); } else { MultiScreenHeader mscreenHeader; mscreenHeader.read(screenFile + ResHeader::size()); return screenFile + ResHeader::size() + mscreenHeader.layers + layerNo * LayerHeader::size(); } }
byte *Sword2Engine::fetchPalette(byte *screenFile) { byte *palette; if(isPsx()) { // PSX version doesn't have a "MultiScreenHeader", instead there's a ScreenHeader and a tag palette = screenFile + ResHeader::size() + ScreenHeader::size() + 2; } else { MultiScreenHeader mscreenHeader; mscreenHeader.read(screenFile + ResHeader::size()); palette = screenFile + ResHeader::size() + mscreenHeader.palette; } // Always set colour 0 to black, because while most background screen // palettes have a bright colour 0 it should come out as black in the // game. palette[0] = 0; palette[1] = 0; palette[2] = 0; palette[3] = 0; return palette; }
void Screen::buildDisplay() { if (_thisScreen.new_palette) { // start the layer palette fading up startNewPalette(); // should be reset to zero at start of each screen change _largestLayerArea = 0; _largestSpriteArea = 0; } // Does this ever happen? if (!_thisScreen.background_layer_id) return; // there is a valid screen to run setScrollTarget(_thisScreen.scroll_offset_x, _thisScreen.scroll_offset_y); _vm->_mouse->animateMouse(); startRenderCycle(); byte *file = _vm->_resman->openResource(_thisScreen.background_layer_id); MultiScreenHeader screenLayerTable; memset(&screenLayerTable, 0, sizeof(screenLayerTable)); if (!Sword2Engine::isPsx()) // On PSX version, there would be nothing to read here screenLayerTable.read(file + ResHeader::size()); // Render at least one frame, but if the screen is scrolling, and if // there is time left, we will render extra frames to smooth out the // scrolling. do { // first background parallax + related anims if (Sword2Engine::isPsx() || screenLayerTable.bg_parallax[0]) { // No need to check on PSX version renderParallax(_vm->fetchBackgroundParallaxLayer(file, 0), 0); drawBackPar0Frames(); } // second background parallax + related anims if (!Sword2Engine::isPsx() && screenLayerTable.bg_parallax[1]) { // Nothing here in PSX version renderParallax(_vm->fetchBackgroundParallaxLayer(file, 1), 1); drawBackPar1Frames(); } // normal backround layer (just the one!) renderParallax(_vm->fetchBackgroundLayer(file), 2); // sprites & layers drawBackFrames(); // background sprites drawSortFrames(file); // sorted sprites & layers drawForeFrames(); // foreground sprites // first foreground parallax + related anims if (Sword2Engine::isPsx() || screenLayerTable.fg_parallax[0]) { renderParallax(_vm->fetchForegroundParallaxLayer(file, 0), 3); drawForePar0Frames(); } // second foreground parallax + related anims if (!Sword2Engine::isPsx() && screenLayerTable.fg_parallax[1]) { renderParallax(_vm->fetchForegroundParallaxLayer(file, 1), 4); drawForePar1Frames(); } _vm->_debugger->drawDebugGraphics(); _vm->_fontRenderer->printTextBlocs(); _vm->_mouse->processMenu(); updateDisplay(); _frameCount++; if (getTick() > _cycleTime) { _fps = _frameCount; _frameCount = 0; _cycleTime = getTick() + 1000; } } while (!endRenderCycle()); _vm->_resman->closeResource(_thisScreen.background_layer_id); }