Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCI32: Transitions (kSetShowStyle, kSetScroll) #791

Closed
wants to merge 8 commits into from
13 changes: 13 additions & 0 deletions engines/sci/console.cpp
Expand Up @@ -2080,6 +2080,10 @@ bool Console::cmdPrintSegmentTable(int argc, const char **argv) {
case SEG_TYPE_STRING:
debugPrintf("T SCI32 strings (%d)", (*(StringTable *)mobj).entries_used);
break;

case SEG_TYPE_BITMAP:
debugPrintf("T SCI32 bitmaps (%d)", (*(BitmapTable *)mobj).entries_used);
break;
#endif

default:
Expand Down Expand Up @@ -2214,6 +2218,9 @@ bool Console::segmentInfo(int nr) {
case SEG_TYPE_ARRAY:
debugPrintf("SCI32 arrays\n");
break;
case SEG_TYPE_BITMAP:
debugPrintf("SCI32 bitmaps\n");
break;
#endif

default :
Expand Down Expand Up @@ -2815,6 +2822,12 @@ bool Console::cmdViewReference(int argc, const char **argv) {
hexDumpReg(array->getRawData(), array->getSize(), 4, 0, true);
break;
}
case SEG_TYPE_BITMAP: {
debugPrintf("SCI32 bitmap:\n");
const SciBitmap *bitmap = _engine->_gamestate->_segMan->lookupBitmap(reg);
Common::hexdump((const byte *) bitmap->getRawData(), bitmap->getRawSize(), 16, 0);
break;
}
#endif
default: {
const SegmentRef block = _engine->_gamestate->_segMan->dereference(reg);
Expand Down
29 changes: 19 additions & 10 deletions engines/sci/engine/gc.cpp
Expand Up @@ -143,22 +143,31 @@ AddrSet *findAllActiveReferences(EngineState *s) {
const Common::Array<SegmentObj *> &heap = s->_segMan->getSegments();
uint heapSize = heap.size();

// Init: Explicitly loaded scripts
for (uint i = 1; i < heapSize; i++) {
if (heap[i] && heap[i]->getType() == SEG_TYPE_SCRIPT) {
Script *script = (Script *)heap[i];
if (heap[i]) {
// Init: Explicitly loaded scripts
if (heap[i]->getType() == SEG_TYPE_SCRIPT) {
Script *script = (Script *)heap[i];

if (script->getLockers()) { // Explicitly loaded?
wm.pushArray(script->listObjectReferences());
if (script->getLockers()) { // Explicitly loaded?
wm.pushArray(script->listObjectReferences());
}
}
}
}

#ifdef ENABLE_SCI32
// Init: ScrollWindows
if (g_sci->_gfxControls32)
wm.pushArray(g_sci->_gfxControls32->listObjectReferences());
// Init: Explicitly opted-out bitmaps
else if (heap[i]->getType() == SEG_TYPE_BITMAP) {
BitmapTable *bt = static_cast<BitmapTable *>(heap[i]);

for (uint j = 0; j < bt->_table.size(); j++) {
if (bt->_table[j].data && bt->_table[j].data->getShouldGC() == false) {
wm.push(make_reg(i, j));
}
}
}
#endif
}
}

debugC(kDebugLevelGC, "[GC] -- Finished explicitly loaded scripts, done with root set");

Expand Down
1 change: 1 addition & 0 deletions engines/sci/engine/kernel.cpp
Expand Up @@ -408,6 +408,7 @@ uint16 Kernel::findRegType(reg_t reg) {
#ifdef ENABLE_SCI32
case SEG_TYPE_ARRAY:
case SEG_TYPE_STRING:
case SEG_TYPE_BITMAP:
#endif
result |= SIG_TYPE_REFERENCE;
break;
Expand Down
4 changes: 2 additions & 2 deletions engines/sci/engine/kernel_tables.h
Expand Up @@ -772,7 +772,7 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(EditText), SIG_EVERYWHERE, "o", NULL, NULL },
{ MAP_CALL(MakeSaveCatName), SIG_EVERYWHERE, "rr", NULL, NULL },
{ MAP_CALL(MakeSaveFileName), SIG_EVERYWHERE, "rri", NULL, NULL },
{ MAP_CALL(SetScroll), SIG_EVERYWHERE, "oiiiii(i)", NULL, NULL },
{ MAP_CALL(SetScroll), SIG_EVERYWHERE, "oiiii(i)(i)", NULL, NULL },
{ MAP_CALL(PalCycle), SIG_EVERYWHERE, "(.*)", kPalCycle_subops, NULL },

// SCI2 Empty functions
Expand Down Expand Up @@ -823,7 +823,7 @@ static SciKernelMapEntry s_kernelMap[] = {
{ MAP_CALL(Robot), SIG_EVERYWHERE, "(.*)", NULL, NULL },
{ MAP_CALL(Save), SIG_EVERYWHERE, "i(.*)", kSave_subops, NULL },
{ MAP_CALL(Text), SIG_SINCE_SCI21MID, SIGFOR_ALL, "i(.*)", kText_subops, NULL },
{ MAP_CALL(AddPicAt), SIG_EVERYWHERE, "oiii", NULL, NULL },
{ MAP_CALL(AddPicAt), SIG_EVERYWHERE, "oiii(i)(i)", NULL, NULL },
{ MAP_CALL(GetWindowsOption), SIG_EVERYWHERE, "i", NULL, NULL },
{ MAP_CALL(WinHelp), SIG_EVERYWHERE, "(.*)", NULL, NULL },
{ MAP_CALL(GetConfig), SIG_EVERYWHERE, "ro", NULL, NULL },
Expand Down
64 changes: 29 additions & 35 deletions engines/sci/engine/kgraphics32.cpp
Expand Up @@ -56,6 +56,7 @@
#include "sci/graphics/palette32.h"
#include "sci/graphics/remap32.h"
#include "sci/graphics/text32.h"
#include "sci/graphics/transitions32.h"
#endif

namespace Sci {
Expand Down Expand Up @@ -123,8 +124,9 @@ reg_t kAddPicAt(EngineState *s, int argc, reg_t *argv) {
int16 x = argv[2].toSint16();
int16 y = argv[3].toSint16();
bool mirrorX = argc > 4 ? argv[4].toSint16() : false;
bool deleteDuplicate = argc > 5 ? argv[5].toSint16() : true;

g_sci->_gfxFrameout->kernelAddPicAt(planeObj, pictureId, x, y, mirrorX);
g_sci->_gfxFrameout->kernelAddPicAt(planeObj, pictureId, x, y, mirrorX, deleteDuplicate);
return s->r_acc;
}

Expand All @@ -139,7 +141,7 @@ reg_t kFrameOut(EngineState *s, int argc, reg_t *argv) {
}

reg_t kSetPalStyleRange(EngineState *s, int argc, reg_t *argv) {
g_sci->_gfxFrameout->kernelSetPalStyleRange(argv[0].toUint16(), argv[1].toUint16());
g_sci->_gfxTransitions32->kernelSetPalStyleRange(argv[0].toUint16(), argv[1].toUint16());
return s->r_acc;
}

Expand Down Expand Up @@ -195,14 +197,14 @@ reg_t kCreateTextBitmap(EngineState *s, int argc, reg_t *argv) {

if (subop == 0) {
TextAlign alignment = (TextAlign)readSelectorValue(segMan, object, SELECTOR(mode));
return g_sci->_gfxText32->createFontBitmap(width, height, rect, text, foreColor, backColor, skipColor, fontId, alignment, borderColor, dimmed, true);
return g_sci->_gfxText32->createFontBitmap(width, height, rect, text, foreColor, backColor, skipColor, fontId, alignment, borderColor, dimmed, true, true);
} else {
CelInfo32 celInfo;
celInfo.type = kCelTypeView;
celInfo.resourceId = readSelectorValue(segMan, object, SELECTOR(view));
celInfo.loopNo = readSelectorValue(segMan, object, SELECTOR(loop));
celInfo.celNo = readSelectorValue(segMan, object, SELECTOR(cel));
return g_sci->_gfxText32->createFontBitmap(celInfo, rect, text, foreColor, backColor, fontId, skipColor, borderColor, dimmed);
return g_sci->_gfxText32->createFontBitmap(celInfo, rect, text, foreColor, backColor, fontId, skipColor, borderColor, dimmed, true);
}
}

Expand Down Expand Up @@ -310,7 +312,7 @@ reg_t kSetShowStyle(EngineState *s, int argc, reg_t *argv) {
// NOTE: The order of planeObj and showStyle are reversed
// because this is how SCI3 called the corresponding method
// on the KernelMgr
g_sci->_gfxFrameout->kernelSetShowStyle(argc, planeObj, type, seconds, back, priority, animate, refFrame, pFadeArray, divisions, blackScreen);
g_sci->_gfxTransitions32->kernelSetShowStyle(argc, planeObj, type, seconds, back, priority, animate, refFrame, pFadeArray, divisions, blackScreen);

return s->r_acc;
}
Expand Down Expand Up @@ -534,13 +536,14 @@ reg_t kBitmapCreate(EngineState *s, int argc, reg_t *argv) {
int16 scaledHeight = argc > 5 ? argv[5].toSint16() : g_sci->_gfxText32->_scaledHeight;
bool useRemap = argc > 6 ? argv[6].toSint16() : false;

BitmapResource bitmap(s->_segMan, width, height, skipColor, 0, 0, scaledWidth, scaledHeight, 0, useRemap);
reg_t bitmapId;
SciBitmap &bitmap = *s->_segMan->allocateBitmap(&bitmapId, width, height, skipColor, 0, 0, scaledWidth, scaledHeight, 0, useRemap, true);
memset(bitmap.getPixels(), backColor, width * height);
return bitmap.getObject();
return bitmapId;
}

reg_t kBitmapDestroy(EngineState *s, int argc, reg_t *argv) {
s->_segMan->freeHunkEntry(argv[0]);
s->_segMan->freeBitmap(argv[0]);
return s->r_acc;
}

Expand All @@ -550,7 +553,7 @@ reg_t kBitmapDrawLine(EngineState *s, int argc, reg_t *argv) {
}

reg_t kBitmapDrawView(EngineState *s, int argc, reg_t *argv) {
BitmapResource bitmap(argv[0]);
SciBitmap &bitmap = *s->_segMan->lookupBitmap(argv[0]);
CelObjView view(argv[1].toUint16(), argv[2].toSint16(), argv[3].toSint16());

const int16 x = argc > 4 ? argv[4].toSint16() : 0;
Expand Down Expand Up @@ -580,7 +583,7 @@ reg_t kBitmapDrawView(EngineState *s, int argc, reg_t *argv) {
reg_t kBitmapDrawText(EngineState *s, int argc, reg_t *argv) {
// called e.g. from TextButton::createBitmap() in Torin's Passage, script 64894

BitmapResource bitmap(argv[0]);
SciBitmap &bitmap = *s->_segMan->lookupBitmap(argv[0]);
Common::String text = s->_segMan->getString(argv[1]);
Common::Rect textRect(
argv[2].toSint16(),
Expand All @@ -604,18 +607,18 @@ reg_t kBitmapDrawText(EngineState *s, int argc, reg_t *argv) {
// Then clips. But this seems stupid.
textRect.clip(Common::Rect(bitmap.getWidth(), bitmap.getHeight()));

reg_t textBitmapObject = g_sci->_gfxText32->createFontBitmap(textRect.width(), textRect.height(), Common::Rect(textRect.width(), textRect.height()), text, foreColor, backColor, skipColor, fontId, alignment, borderColor, dimmed, false);
reg_t textBitmapObject = g_sci->_gfxText32->createFontBitmap(textRect.width(), textRect.height(), Common::Rect(textRect.width(), textRect.height()), text, foreColor, backColor, skipColor, fontId, alignment, borderColor, dimmed, false, false);
CelObjMem textCel(textBitmapObject);
textCel.draw(bitmap.getBuffer(), textRect, Common::Point(textRect.left, textRect.top), false);
s->_segMan->freeHunkEntry(textBitmapObject);
s->_segMan->freeBitmap(textBitmapObject);

return s->r_acc;
}

reg_t kBitmapDrawColor(EngineState *s, int argc, reg_t *argv) {
// called e.g. from TextView::init() and TextView::draw() in Torin's Passage, script 64890

BitmapResource bitmap(argv[0]);
SciBitmap &bitmap = *s->_segMan->lookupBitmap(argv[0]);
Common::Rect fillRect(
argv[1].toSint16(),
argv[2].toSint16(),
Expand All @@ -640,7 +643,7 @@ reg_t kBitmapInvert(EngineState *s, int argc, reg_t *argv) {
}

reg_t kBitmapSetDisplace(EngineState *s, int argc, reg_t *argv) {
BitmapResource bitmap(argv[0]);
SciBitmap &bitmap = *s->_segMan->lookupBitmap(argv[0]);
bitmap.setDisplace(Common::Point(argv[1].toSint16(), argv[2].toSint16()));
return s->r_acc;
}
Expand Down Expand Up @@ -760,28 +763,19 @@ reg_t kDeleteLine(EngineState *s, int argc, reg_t *argv) {
return s->r_acc;
}

// Used by LSL6hires intro (room 110)
reg_t kSetScroll(EngineState *s, int argc, reg_t *argv) {
// Called in the intro of LSL6 hires (room 110)
// The end effect of this is the same as the old screen scroll transition

// 7 parameters
reg_t planeObject = argv[0];
//int16 x = argv[1].toSint16();
//int16 y = argv[2].toSint16();
uint16 pictureId = argv[3].toUint16();
// param 4: int (0 in LSL6, probably scroll direction? The picture in LSL6 scrolls down)
// param 5: int (first call is 1, then the subsequent one is 0 in LSL6)
// param 6: optional int (0 in LSL6)

// Set the new picture directly for now
//writeSelectorValue(s->_segMan, planeObject, SELECTOR(left), x);
//writeSelectorValue(s->_segMan, planeObject, SELECTOR(top), y);
writeSelectorValue(s->_segMan, planeObject, SELECTOR(picture), pictureId);
// and update our draw list
g_sci->_gfxFrameout->kernelUpdatePlane(planeObject);

// TODO
return kStub(s, argc, argv);
const reg_t plane = argv[0];
const int16 deltaX = argv[1].toSint16();
const int16 deltaY = argv[2].toSint16();
const GuiResourceId pictureId = argv[3].toUint16();
const bool animate = argv[4].toUint16();
// NOTE: speed was accepted as an argument, but then never actually used
// const int16 speed = argc > 5 ? (bool)argv[5].toSint16() : -1;
const bool mirrorX = argc > 6 ? (bool)argv[6].toUint16() : false;

g_sci->_gfxTransitions32->kernelSetScroll(plane, deltaX, deltaY, pictureId, animate, mirrorX);
return s->r_acc;
}

// Used by SQ6, script 900, the datacorder reprogramming puzzle (from room 270)
Expand Down
45 changes: 45 additions & 0 deletions engines/sci/engine/savegame.cpp
Expand Up @@ -158,6 +158,24 @@ void syncWithSerializer(Common::Serializer &s, SciString &obj) {
obj.setValue(i, value);
}
}

void syncWithSerializer(Common::Serializer &s, SciBitmap *&obj) {
bool hasEntry;
if (s.isSaving()) {
hasEntry = obj != nullptr;
}
s.syncAsByte(hasEntry);

if (hasEntry) {
if (s.isLoading()) {
obj = new SciBitmap;
}

obj->saveLoadWithSerializer(s);
} else {
obj = nullptr;
}
}
#endif

#pragma mark -
Expand Down Expand Up @@ -273,6 +291,8 @@ void SegManager::saveLoadWithSerializer(Common::Serializer &s) {
} else if (type == SEG_TYPE_STRING) {
// Set the correct segment for SCI32 strings
_stringSegId = i;
} else if (s.getVersion() >= 36 && type == SEG_TYPE_BITMAP) {
_bitmapSegId = i;
#endif
}

Expand Down Expand Up @@ -687,6 +707,31 @@ void StringTable::saveLoadWithSerializer(Common::Serializer &ser) {

sync_Table<StringTable>(ser, *this);
}

void BitmapTable::saveLoadWithSerializer(Common::Serializer &ser) {
if (ser.getVersion() < 36) {
return;
}

sync_Table(ser, *this);
}

void SciBitmap::saveLoadWithSerializer(Common::Serializer &s) {
if (s.getVersion() < 36) {
return;
}

s.syncAsByte(_gc);
s.syncAsUint32LE(_dataSize);
if (s.isLoading()) {
_data = (byte *)malloc(_dataSize);
}
s.syncBytes(_data, _dataSize);

if (s.isLoading()) {
_buffer = Buffer(getWidth(), getHeight(), getPixels());
}
}
#endif

void GfxPalette::palVarySaveLoadPalette(Common::Serializer &s, Palette *palette) {
Expand Down
3 changes: 2 additions & 1 deletion engines/sci/engine/savegame.h
Expand Up @@ -37,6 +37,7 @@ struct EngineState;
*
* Version - new/changed feature
* =============================
* 36 - SCI32 bitmap segment
* 35 - SCI32 remap
* 34 - SCI32 palettes, and store play time in ticks
* 33 - new overridePriority flag in MusicEntry
Expand All @@ -60,7 +61,7 @@ struct EngineState;
*/

enum {
CURRENT_SAVEGAME_VERSION = 35,
CURRENT_SAVEGAME_VERSION = 36,
MINIMUM_SAVEGAME_VERSION = 14
};

Expand Down