Dumped most of the remaining "driver" code into a new "Display" class. This

touches a lot of the code, of course, and adds yet another global variable
(temporarily, I hope), but everything still seems to work.

Knock on wood.

svn-id: r10806
This commit is contained in:
Torbjörn Andersson 2003-10-15 06:40:31 +00:00
parent f74a0c18aa
commit 8b42d65a7e
31 changed files with 949 additions and 1142 deletions

View File

@ -776,14 +776,14 @@ int32 FN_play_sequence(int32 *params) {
// now clear the screen in case the Sequence was quitted (using ESC) // now clear the screen in case the Sequence was quitted (using ESC)
// rather than fading down to black // rather than fading down to black
EraseBackBuffer(); g_display->clearScene();
// zero the entire palette in case we're about to fade up! // zero the entire palette in case we're about to fade up!
_palEntry pal[256]; _palEntry pal[256];
memset(pal, 0, 256 * sizeof(_palEntry)); memset(pal, 0, 256 * sizeof(_palEntry));
BS2_SetPalette(0, 256, (uint8 *) pal, RDPAL_INSTANT); g_display->setPalette(0, 256, (uint8 *) pal, RDPAL_INSTANT);
debug(5, "FN_play_sequence FINISHED"); debug(5, "FN_play_sequence FINISHED");

View File

@ -108,7 +108,6 @@ void Send_fore_par1_frames(void);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
void Build_display(void) { void Build_display(void) {
bool end;
#ifdef _SWORD2_DEBUG #ifdef _SWORD2_DEBUG
uint8 pal[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0 }; uint8 pal[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0 };
#endif #endif
@ -133,25 +132,21 @@ void Build_display(void) {
// there is a valid screen to run // there is a valid screen to run
if (!console_status && this_screen.background_layer_id) { if (!console_status && this_screen.background_layer_id) {
// set the scroll position // set the scroll position
SetScrollTarget(this_screen.scroll_offset_x, this_screen.scroll_offset_y); g_display->setScrollTarget(this_screen.scroll_offset_x, this_screen.scroll_offset_y);
// increment the mouse frame // increment the mouse frame
AnimateMouse(); g_display->animateMouse();
StartRenderCycle(); g_display->startRenderCycle();
while (1) { while (1) {
// START OF RENDER CYCLE
// ---------------------------------------------------
// clear the back buffer, before building up the new // clear the back buffer, before building up the new
// screen from the back forwards // screen from the back forwards
// FIXME: I'm not convinced that this is needed. Isn't // FIXME: I'm not convinced that this is needed. Isn't
// the whole screen redrawn each time? // the whole screen redrawn each time?
// EraseBackBuffer(); // g_display->clearScene();
// ---------------------------------------------------
// first background parallax + related anims // first background parallax + related anims
// open the screen resource // open the screen resource
@ -159,7 +154,7 @@ void Build_display(void) {
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
if (screenLayerTable->bg_parallax[0]) { if (screenLayerTable->bg_parallax[0]) {
RenderParallax(FetchBackgroundParallaxLayer(file, 0), 0); g_display->renderParallax(FetchBackgroundParallaxLayer(file, 0), 0);
// release the screen resource before cacheing // release the screen resource before cacheing
// the sprites // the sprites
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
@ -169,7 +164,6 @@ void Build_display(void) {
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
} }
// ---------------------------------------------------
// second background parallax + related anims // second background parallax + related anims
// open the screen resource // open the screen resource
@ -177,7 +171,7 @@ void Build_display(void) {
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
if (screenLayerTable->bg_parallax[1]) { if (screenLayerTable->bg_parallax[1]) {
RenderParallax(FetchBackgroundParallaxLayer(file, 1), 1); g_display->renderParallax(FetchBackgroundParallaxLayer(file, 1), 1);
// release the screen resource before cacheing // release the screen resource before cacheing
// the sprites // the sprites
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
@ -187,16 +181,14 @@ void Build_display(void) {
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
} }
// ---------------------------------------------------
// normal backround layer (just the one!) // normal backround layer (just the one!)
// open the screen resource // open the screen resource
file = res_man.open(this_screen.background_layer_id); file = res_man.open(this_screen.background_layer_id);
RenderParallax(FetchBackgroundLayer(file), 2); g_display->renderParallax(FetchBackgroundLayer(file), 2);
// release the screen resource // release the screen resource
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
// ---------------------------------------------------
// sprites & layers // sprites & layers
Send_back_frames(); // background sprites Send_back_frames(); // background sprites
@ -204,7 +196,6 @@ void Build_display(void) {
Send_sort_frames(); // sorted sprites & layers Send_sort_frames(); // sorted sprites & layers
Send_fore_frames(); // foreground sprites Send_fore_frames(); // foreground sprites
// ---------------------------------------------------
// first foreground parallax + related anims // first foreground parallax + related anims
// open the screen resource // open the screen resource
@ -212,7 +203,7 @@ void Build_display(void) {
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
if (screenLayerTable->fg_parallax[0]) { if (screenLayerTable->fg_parallax[0]) {
RenderParallax(FetchForegroundParallaxLayer(file, 0), 3); g_display->renderParallax(FetchForegroundParallaxLayer(file, 0), 3);
// release the screen resource before cacheing // release the screen resource before cacheing
// the sprites // the sprites
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
@ -222,7 +213,6 @@ void Build_display(void) {
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
} }
//----------------------------------------------------
// second foreground parallax + related anims // second foreground parallax + related anims
// open the screen resource // open the screen resource
@ -230,7 +220,7 @@ void Build_display(void) {
screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader)); screenLayerTable = (_multiScreenHeader *) ((uint8 *) file + sizeof(_standardHeader));
if (screenLayerTable->fg_parallax[1]) { if (screenLayerTable->fg_parallax[1]) {
RenderParallax(FetchForegroundParallaxLayer(file, 1), 4); g_display->renderParallax(FetchForegroundParallaxLayer(file, 1), 4);
// release the screen resource before cacheing // release the screen resource before cacheing
// the sprites // the sprites
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
@ -240,29 +230,24 @@ void Build_display(void) {
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
} }
// ---------------------------------------------------
// walkgrid, mouse & player markers & mouse area // walkgrid, mouse & player markers & mouse area
// rectangle // rectangle
Draw_debug_graphics(); Draw_debug_graphics();
// ---------------------------------------------------
// text blocks // text blocks
// speech blocks and headup debug text // speech blocks and headup debug text
fontRenderer.printTextBlocs(); fontRenderer.printTextBlocs();
// ---------------------------------------------------
// menu bar & icons // menu bar & icons
ProcessMenu(); g_display->processMenu();
// ---------------------------------------------------
// ready - blit to screen // ready - blit to screen
ServiceWindows(); g_display->updateDisplay();
//----------------------------------------------------
// update our fps reading // update our fps reading
frameCount++; frameCount++;
@ -273,20 +258,16 @@ void Build_display(void) {
cycleTime = SVM_timeGetTime() + 1000; cycleTime = SVM_timeGetTime() + 1000;
} }
// --------------------------------------------------- // Check if we've got time to render the screen again
// check if we've got time to render the screen again
// this cycle (so drivers can smooth out the scrolling // this cycle (so drivers can smooth out the scrolling
// in between normal game cycles) // in between normal game cycles)
//
EndRenderCycle(&end); // If we haven't got time to render again this cycle,
// if we haven't got time to render again this cycle,
// drop out of 'render cycle' while-loop // drop out of 'render cycle' while-loop
if (end)
break;
// --------------------------------------------------- if (g_display->endRenderCycle())
} // END OF RENDER CYCLE break;
}
} }
#ifdef _SWORD2_DEBUG #ifdef _SWORD2_DEBUG
else if (console_status) { else if (console_status) {
@ -302,13 +283,13 @@ void Build_display(void) {
spriteInfo.data = console_sprite->ad; spriteInfo.data = console_sprite->ad;
spriteInfo.colourTable = 0; spriteInfo.colourTable = 0;
rv = DrawSprite(&spriteInfo); rv = g_display->drawSprite(&spriteInfo);
if (rv) if (rv)
error("Driver Error %.8x (drawing console)", rv); error("Driver Error %.8x (drawing console)", rv);
} else{ } else{
StartConsole(); StartConsole();
// force the palette // force the palette
BS2_SetPalette(0, 3, pal, RDPAL_INSTANT); g_display->setPalette(0, 3, pal, RDPAL_INSTANT);
Print_to_console("no valid screen?"); Print_to_console("no valid screen?");
} }
#endif #endif
@ -329,24 +310,24 @@ void DisplayMsg(uint8 *text, int time) {
warning("DisplayMsg: %s", (char *) text); warning("DisplayMsg: %s", (char *) text);
if (GetFadeStatus() != RDFADE_BLACK) { if (g_display->getFadeStatus() != RDFADE_BLACK) {
FadeDown((float) 0.75); g_display->fadeDown();
WaitForFade(); g_display->waitForFade();
} }
Set_mouse(0); Set_mouse(0);
Set_luggage(0); Set_luggage(0);
CloseMenuImmediately(); g_display->closeMenuImmediately();
EraseBackBuffer(); g_display->clearScene();
text_spr = fontRenderer.makeTextSprite(text, 640, 187, g_sword2->_speechFontId); text_spr = fontRenderer.makeTextSprite(text, 640, 187, g_sword2->_speechFontId);
frame = (_frameHeader *) text_spr->ad; frame = (_frameHeader *) text_spr->ad;
spriteInfo.x = screenWide / 2 - frame->width / 2; spriteInfo.x = g_display->_screenWide / 2 - frame->width / 2;
if (!time) if (!time)
spriteInfo.y = screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; spriteInfo.y = g_display->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP;
else else
spriteInfo.y = 400 - frame->height; spriteInfo.y = 400 - frame->height;
spriteInfo.w = frame->width; spriteInfo.w = frame->width;
@ -359,33 +340,34 @@ void DisplayMsg(uint8 *text, int time) {
spriteInfo.data = text_spr->ad + sizeof(_frameHeader); spriteInfo.data = text_spr->ad + sizeof(_frameHeader);
spriteInfo.colourTable = 0; spriteInfo.colourTable = 0;
rv = DrawSprite(&spriteInfo); rv = g_display->drawSprite(&spriteInfo);
if (rv) if (rv)
error("Driver Error %.8x (in DisplayMsg)", rv); error("Driver Error %.8x (in DisplayMsg)", rv);
memcpy((char *) oldPal, (char *) palCopy, 256 * sizeof(_palEntry)); memcpy((char *) oldPal, (char *) g_display->_palCopy, 256 * sizeof(_palEntry));
memset(pal, 0, 256 * sizeof(_palEntry)); memset(pal, 0, 256 * sizeof(_palEntry));
pal[187].red = 255; pal[187].red = 255;
pal[187].green = 255; pal[187].green = 255;
pal[187].blue = 255; pal[187].blue = 255;
BS2_SetPalette(0, 256, (uint8 *) pal, RDPAL_FADE); g_display->setPalette(0, 256, (uint8 *) pal, RDPAL_FADE);
FadeUp((float) 0.75); g_display->fadeUp();
memory.freeMemory(text_spr); memory.freeMemory(text_spr);
WaitForFade(); g_display->waitForFade();
uint32 targetTime = SVM_timeGetTime() + (time * 1000); uint32 targetTime = SVM_timeGetTime() + (time * 1000);
rv = DrawSprite(&spriteInfo); // Keep the message there even when the user task swaps. // Keep the message there even when the user task swaps.
rv = g_display->drawSprite(&spriteInfo);
if (rv) if (rv)
error("Driver Error %.8x (in DisplayMsg)", rv); error("Driver Error %.8x (in DisplayMsg)", rv);
sleepUntil(targetTime); sleepUntil(targetTime);
BS2_SetPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE); g_display->setPalette(0, 256, (uint8 *) oldPal, RDPAL_FADE);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -394,13 +376,13 @@ void DisplayMsg(uint8 *text, int time) {
// //
void RemoveMsg(void) { void RemoveMsg(void) {
FadeDown((float) 0.75); g_display->fadeDown();
WaitForFade(); g_display->waitForFade();
EraseBackBuffer(); g_display->clearScene();
// FadeUp((float) 0.75); // g_display->fadeUp();
// removed by JEL (08oct97) to prevent "eye" smacker corruption when // removed by JEL (08oct97) to prevent "eye" smacker corruption when
// restarting game from CD2 and also to prevent palette flicker when // restarting game from CD2 and also to prevent palette flicker when
// restoring game to a different CD since the "insert CD" message uses // restoring game to a different CD since the "insert CD" message uses
@ -516,7 +498,7 @@ void Process_layer(uint32 layer_number) {
#endif #endif
//------------------------------------------ //------------------------------------------
rv = DrawSprite(&spriteInfo); rv = g_display->drawSprite(&spriteInfo);
if (rv) if (rv)
error("Driver Error %.8x in Process_layer(%d)", rv, layer_number); error("Driver Error %.8x in Process_layer(%d)", rv, layer_number);
@ -559,7 +541,7 @@ void Process_image(buildit *build_unit) {
// but the same compression can be decompressed using the // but the same compression can be decompressed using the
// RLE256 routines! // RLE256 routines!
// NOTE: If this restriction refers to DrawSprite(), I don't // NOTE: If this restriction refers to drawSprite(), I don't
// think we have it any more. But I'm not sure. // think we have it any more. But I'm not sure.
if (build_unit->scale || anim_head->blend || build_unit->shadingFlag) if (build_unit->scale || anim_head->blend || build_unit->shadingFlag)
@ -649,7 +631,7 @@ void Process_image(buildit *build_unit) {
// } // }
// #endif // #endif
rv = DrawSprite(&spriteInfo); rv = g_display->drawSprite(&spriteInfo);
if (rv) if (rv)
error("Driver Error %.8x with sprite %s (%d) in Process_image", error("Driver Error %.8x with sprite %s (%d) in Process_image",
rv, FetchObjectName(build_unit->anim_resource), rv, FetchObjectName(build_unit->anim_resource),
@ -933,14 +915,14 @@ void Start_new_palette(void) {
// if the screen is still fading down then wait for black - could // if the screen is still fading down then wait for black - could
// happen when everythings cached into a large memory model // happen when everythings cached into a large memory model
WaitForFade(); g_display->waitForFade();
// open the screen file // open the screen file
screenFile = res_man.open(this_screen.background_layer_id); screenFile = res_man.open(this_screen.background_layer_id);
UpdatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(screenFile)); g_display->updatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(screenFile));
BS2_SetPalette(0, 256, FetchPalette(screenFile), RDPAL_FADE); g_display->setPalette(0, 256, FetchPalette(screenFile), RDPAL_FADE);
// indicating that it's a screen palette // indicating that it's a screen palette
lastPaletteRes = 0; lastPaletteRes = 0;
@ -949,8 +931,7 @@ void Start_new_palette(void) {
res_man.close(this_screen.background_layer_id); res_man.close(this_screen.background_layer_id);
// start fade up // start fade up
// FadeUp((float) 1.75); g_display->fadeUp();
FadeUp((float) 0.75);
// reset // reset
this_screen.new_palette = 0; this_screen.new_palette = 0;
@ -980,17 +961,17 @@ int32 FN_fade_down(int32 *params) {
// NONE means up! can only be called when screen is fully faded up - // NONE means up! can only be called when screen is fully faded up -
// multiple calls wont have strange effects // multiple calls wont have strange effects
if (GetFadeStatus() == RDFADE_NONE) if (g_display->getFadeStatus() == RDFADE_NONE)
FadeDown((float) 0.75); g_display->fadeDown();
return IR_CONT; return IR_CONT;
} }
int32 FN_fade_up(int32 *params) { int32 FN_fade_up(int32 *params) {
WaitForFade(); g_display->waitForFade();
if (GetFadeStatus() == RDFADE_BLACK) if (g_display->getFadeStatus() == RDFADE_BLACK)
FadeUp((float) 0.75); g_display->fadeUp();
return IR_CONT; return IR_CONT;
} }
@ -1076,9 +1057,9 @@ void SetFullPalette(int32 palRes) {
file[3] = 0; file[3] = 0;
// not yet in separate palette files // not yet in separate palette files
// UpdatePaletteMatchTable(file + (256 * 4)); // g_display->updatePaletteMatchTable(file + (256 * 4));
BS2_SetPalette(0, 256, file, RDPAL_INSTANT); g_display->setPalette(0, 256, file, RDPAL_INSTANT);
if (palRes != CONTROL_PANEL_PALETTE) { // (James 03sep97) if (palRes != CONTROL_PANEL_PALETTE) { // (James 03sep97)
// indicating that it's a separate palette resource // indicating that it's a separate palette resource
@ -1092,9 +1073,9 @@ void SetFullPalette(int32 palRes) {
if (this_screen.background_layer_id) { if (this_screen.background_layer_id) {
// open the screen file // open the screen file
file = res_man.open(this_screen.background_layer_id); file = res_man.open(this_screen.background_layer_id);
UpdatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(file)); g_display->updatePaletteMatchTable((uint8 *) FetchPaletteMatchTable(file));
BS2_SetPalette(0, 256, FetchPalette(file), RDPAL_INSTANT); g_display->setPalette(0, 256, FetchPalette(file), RDPAL_INSTANT);
// indicating that it's a screen palette // indicating that it's a screen palette
lastPaletteRes = 0; lastPaletteRes = 0;
@ -1115,7 +1096,7 @@ int32 FN_change_shadows(int32 *params) {
// if last screen was using a shading mask (see below) // if last screen was using a shading mask (see below)
if (this_screen.mask_flag) { if (this_screen.mask_flag) {
rv = CloseLightMask(); rv = g_display->closeLightMask();
if (rv) if (rv)
error("Driver Error %.8x [%s line %u]", rv); error("Driver Error %.8x [%s line %u]", rv);

View File

@ -164,7 +164,7 @@ void Init_console(void) {
con_width = screenWide; //max across con_width = screenWide; //max across
// Force a palatte for the console. // Force a palatte for the console.
BS2_SetPalette(CON_PEN, 1, white, RDPAL_INSTANT); g_display->setPalette(CON_PEN, 1, white, RDPAL_INSTANT);
console_sprite = memory.alloc(con_width * (CON_lines * con_chr_height), MEM_float, UID_con_sprite); console_sprite = memory.alloc(con_width * (CON_lines * con_chr_height), MEM_float, UID_con_sprite);
@ -213,7 +213,7 @@ uint32 Tconsole(uint32 mode) {
StartConsole(); StartConsole();
while (1) { while (1) {
ServiceWindows(); g_display->updateDisplay();
if (breakOut) if (breakOut)
break; break;
@ -460,7 +460,7 @@ uint32 Parse_user_input(void) {
case 18: // S (same as START) case 18: // S (same as START)
Con_start(&input[1][0]); Con_start(&input[1][0]);
// force the palette // force the palette
BS2_SetPalette(187, 1, pal, RDPAL_INSTANT); g_display->setPalette(187, 1, pal, RDPAL_INSTANT);
return 0; return 0;
case 9: // INFO case 9: // INFO
displayDebugText = 1 - displayDebugText; displayDebugText = 1 - displayDebugText;
@ -729,7 +729,7 @@ void Con_help(void) {
Build_display(); Build_display();
do { do {
ServiceWindows(); g_display->updateDisplay();
} while (!KeyWaiting()); } while (!KeyWaiting());
ReadKey(&c); ReadKey(&c);
@ -803,8 +803,8 @@ void Con_fatal_error(const char *format, ...) {
char buf[150]; char buf[150];
uint8 white[4] = { 255, 255, 255, 0 }; uint8 white[4] = { 255, 255, 255, 0 };
// set text colour in case screen is faded down! (James 05mar97) // set text colour in case screen is faded down!
BS2_SetPalette(CON_PEN, 1, white, RDPAL_INSTANT); g_display->setPalette(CON_PEN, 1, white, RDPAL_INSTANT);
va_start(arg_ptr,format); va_start(arg_ptr,format);
_vsnprintf(buf, 150, format, arg_ptr); _vsnprintf(buf, 150, format, arg_ptr);
@ -912,7 +912,7 @@ void Con_list_savegames(void) {
Build_display(); Build_display();
do { do {
ServiceWindows(); g_display->updateDisplay();
} while (!KeyWaiting()); } while (!KeyWaiting());
ReadKey(&c); ReadKey(&c);

View File

@ -74,7 +74,7 @@ public:
sprite.data = (uint8 *) (head + 1); sprite.data = (uint8 *) (head + 1);
sprite.w = head->width; sprite.w = head->width;
sprite.h = head->height; sprite.h = head->height;
CreateSurface(&sprite, &_glyph[i]._data); g_display->createSurface(&sprite, &_glyph[i]._data);
_glyph[i]._width = head->width; _glyph[i]._width = head->width;
_glyph[i]._height = head->height; _glyph[i]._height = head->height;
} }
@ -84,7 +84,7 @@ public:
~FontRendererGui() { ~FontRendererGui() {
for (int i = 0; i < SIZE_OF_CHAR_SET; i++) for (int i = 0; i < SIZE_OF_CHAR_SET; i++)
DeleteSurface(_glyph[i]._data); g_display->deleteSurface(_glyph[i]._data);
} }
void fetchText(int textId, char *buf) { void fetchText(int textId, char *buf) {
@ -143,7 +143,7 @@ void FontRendererGui::drawText(char *text, int x, int y, int alignment) {
sprite.w = _glyph[text[i] - 32]._width; sprite.w = _glyph[text[i] - 32]._width;
sprite.h = _glyph[text[i] - 32]._height; sprite.h = _glyph[text[i] - 32]._height;
DrawSurface(&sprite, _glyph[text[i] - 32]._data); g_display->drawSurface(&sprite, _glyph[text[i] - 32]._data);
sprite.x += (_glyph[(int) text[i] - 32]._width - CHARACTER_OVERLAP); sprite.x += (_glyph[(int) text[i] - 32]._width - CHARACTER_OVERLAP);
} }
@ -186,7 +186,7 @@ public:
virtual ~Widget() { virtual ~Widget() {
for (int i = 0; i < _numStates; i++) { for (int i = 0; i < _numStates; i++) {
if (_surfaces[i]._original) if (_surfaces[i]._original)
DeleteSurface(_surfaces[i]._surface); g_display->deleteSurface(_surfaces[i]._surface);
} }
free(_sprites); free(_sprites);
free(_surfaces); free(_surfaces);
@ -228,7 +228,7 @@ public:
} }
virtual void paint(Common::Rect *clipRect = NULL) { virtual void paint(Common::Rect *clipRect = NULL) {
DrawSurface(&_sprites[_state], _surfaces[_state]._surface, clipRect); g_display->drawSurface(&_sprites[_state], _surfaces[_state]._surface, clipRect);
} }
virtual void onMouseEnter() {} virtual void onMouseEnter() {}
@ -291,7 +291,7 @@ void Widget::createSurfaceImage(int state, uint32 res, int x, int y, uint32 pc)
// Points to just after frame header, ie. start of sprite data // Points to just after frame header, ie. start of sprite data
_sprites[state].data = (uint8 *) (frame_head + 1); _sprites[state].data = (uint8 *) (frame_head + 1);
CreateSurface(&_sprites[state], &_surfaces[state]._surface); g_display->createSurface(&_sprites[state], &_surfaces[state]._surface);
_surfaces[state]._original = true; _surfaces[state]._original = true;
// Release the anim resource // Release the anim resource
@ -339,7 +339,7 @@ public:
virtual void onAction(Widget *widget, int result = 0) {} virtual void onAction(Widget *widget, int result = 0) {}
virtual void paint() { virtual void paint() {
EraseBackBuffer(); g_display->clearScene();
for (int i = 0; i < _numWidgets; i++) for (int i = 0; i < _numWidgets; i++)
_widgets[i]->paint(); _widgets[i]->paint();
} }
@ -362,12 +362,11 @@ int Dialog::run() {
while (!_finish) { while (!_finish) {
// So that the menu icons will reach their full size // So that the menu icons will reach their full size
ProcessMenu(); g_display->processMenu();
g_display->updateDisplay();
ServiceWindows(); int16 newMouseX = g_display->_mouseX;
int16 newMouseY = g_display->_mouseY + 40;
int16 newMouseX = mousex;
int16 newMouseY = mousey + 40;
_mouseEvent *me = MouseEvent(); _mouseEvent *me = MouseEvent();
_keyboardEvent ke; _keyboardEvent ke;
@ -388,7 +387,7 @@ int Dialog::run() {
_widgets[i]->onMouseEnter(); _widgets[i]->onMouseEnter();
if (oldHit && !newHit) if (oldHit && !newHit)
_widgets[i]->onMouseExit(); _widgets[i]->onMouseExit();
if (mousex != oldMouseX || mousey != oldMouseY) if (g_display->_mouseX != oldMouseX || g_display->_mouseY != oldMouseY)
_widgets[i]->onMouseMove(newMouseX, newMouseY); _widgets[i]->onMouseMove(newMouseX, newMouseY);
if (me) { if (me) {
@ -788,8 +787,8 @@ public:
_musicSlider->setValue(g_sound->getMusicVolume()); _musicSlider->setValue(g_sound->getMusicVolume());
_speechSlider->setValue(g_sound->getSpeechVolume()); _speechSlider->setValue(g_sound->getSpeechVolume());
_fxSlider->setValue(g_sound->getFxVolume()); _fxSlider->setValue(g_sound->getFxVolume());
_gfxSlider->setValue(GetRenderType()); _gfxSlider->setValue(g_display->getRenderLevel());
_gfxPreview->setState(GetRenderType()); _gfxPreview->setState(g_display->getRenderLevel());
} }
~OptionsDialog() { ~OptionsDialog() {
@ -901,7 +900,7 @@ int32 OptionsDialog::writeOptionSettings(void) {
buff[3] = g_sound->isMusicMute(); buff[3] = g_sound->isMusicMute();
buff[4] = g_sound->isSpeechMute(); buff[4] = g_sound->isSpeechMute();
buff[5] = g_sound->isFxMute(); buff[5] = g_sound->isFxMute();
buff[6] = GetRenderType(); buff[6] = g_display->getRenderLevel();
buff[7] = gui._subtitles; buff[7] = gui._subtitles;
buff[8] = gui._pointerTextSelected; buff[8] = gui._pointerTextSelected;
buff[9] = gui._stereoReversed; buff[9] = gui._stereoReversed;
@ -1352,7 +1351,7 @@ void SaveLoadDialog::saveLoadError(char* text) {
while (1) { while (1) {
_mouseEvent *me; _mouseEvent *me;
ServiceWindows(); g_display->updateDisplay();
if (KeyWaiting()) { if (KeyWaiting()) {
_keyboardEvent ke; _keyboardEvent ke;
@ -1396,7 +1395,6 @@ void Gui::quitControl(void) {
// close engine systems down // close engine systems down
Close_game(); Close_game();
CloseAppWindow();
exit(0); exit(0);
} }
@ -1410,13 +1408,13 @@ void Gui::restartControl(void) {
return; return;
} }
// Stop music instantly! (James 22aug97) // Stop music instantly!
Kill_music(); Kill_music();
//in case we were dead - well we're not anymore! //in case we were dead - well we're not anymore!
DEAD = 0; DEAD = 0;
EraseBackBuffer(); g_display->clearScene();
// restart the game // restart the game
// clear all memory and reset the globals // clear all memory and reset the globals
@ -1450,9 +1448,9 @@ void Gui::restartControl(void) {
// FN_register_frame) // FN_register_frame)
Reset_mouse_list(); Reset_mouse_list();
CloseMenuImmediately(); g_display->closeMenuImmediately();
// FOR THE DEMO - FORCE THE SCROLLING TO BE RESET! (James29may97) // FOR THE DEMO - FORCE THE SCROLLING TO BE RESET!
// - this is taken from FN_init_background // - this is taken from FN_init_background
// switch on scrolling (2 means first time on screen) // switch on scrolling (2 means first time on screen)
@ -1525,33 +1523,7 @@ void Gui::optionControl(void) {
} }
void Gui::updateGraphicsLevel(uint8 newLevel) { void Gui::updateGraphicsLevel(uint8 newLevel) {
switch (newLevel) { g_display->setRenderLevel(newLevel);
case 0:
// Lowest setting: no graphics fx
ClearTransFx();
ClearShadowFx();
ClearBltFx();
break;
case 1:
// Medium-low setting: transparency-blending
SetTransFx();
ClearShadowFx();
ClearBltFx();
break;
case 2:
// Medium-high setting: transparency-blending + shading
SetTransFx();
SetShadowFx();
ClearBltFx();
break;
case 3:
// Highest setting: transparency-blending + shading +
// edge-blending + improved stretching
SetTransFx();
SetShadowFx();
SetBltFx();
break;
}
// update our global variable - which needs to be checked when dimming // update our global variable - which needs to be checked when dimming
// the palette in PauseGame() in sword2.cpp (since palette-matching // the palette in PauseGame() in sword2.cpp (since palette-matching

View File

@ -29,49 +29,15 @@ namespace Sword2 {
#define MAX_MOUSE_EVENTS 16 #define MAX_MOUSE_EVENTS 16
#define MOUSEFLASHFRAME 6 #define MOUSEFLASHFRAME 6
#if !defined(__GNUC__)
#pragma START_PACK_STRUCTS
#endif
struct _mouseAnim {
uint8 runTimeComp; // type of runtime compression used for the
// frame data
uint8 noAnimFrames; // number of frames in the anim
int8 xHotSpot;
int8 yHotSpot;
uint8 mousew;
uint8 mouseh;
} GCC_PACK;
#if !defined(__GNUC__)
#pragma END_PACK_STRUCTS
#endif
int16 mousex;
int16 mousey;
static uint8 mouseBacklog = 0; static uint8 mouseBacklog = 0;
static uint8 mouseLogPos = 0; static uint8 mouseLogPos = 0;
static uint8 mouseFrame;
static uint8 *mouseSprite = NULL;
static _mouseAnim *mouseAnim = NULL;
static _mouseAnim *luggageAnim = NULL;
static _mouseEvent mouseLog[MAX_MOUSE_EVENTS]; static _mouseEvent mouseLog[MAX_MOUSE_EVENTS];
static int32 *mouseOffsets;
static int32 *luggageOffset;
// This is the maximum mouse cursor size in the SDL backend void Display::resetRenderEngine(void) {
_parallaxScrollX = 0;
#define MAX_MOUSE_W 80 _parallaxScrollY = 0;
#define MAX_MOUSE_H 80 _scrollX = 0;
_scrollY = 0;
byte _mouseData[MAX_MOUSE_W * MAX_MOUSE_H];
void ResetRenderEngine(void) {
parallaxScrollx = 0;
parallaxScrolly = 0;
scrollx = 0;
scrolly = 0;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -96,7 +62,7 @@ void LogMouseEvent(uint16 buttons) {
// 0xFF. That means that parts of the mouse cursor that weren't meant to be // 0xFF. That means that parts of the mouse cursor that weren't meant to be
// transparent may be now. // transparent may be now.
int32 DecompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pitch, int xOff = 0, int yOff = 0) { void Display::decompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pitch, int xOff, int yOff) {
int32 size = width * height; int32 size = width * height;
int32 i = 0; int32 i = 0;
int x = 0; int x = 0;
@ -119,12 +85,10 @@ int32 DecompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pit
i += *comp++; i += *comp++;
} }
} }
return RD_OK;
} }
void DrawMouse(void) { void Display::drawMouse(void) {
if (!mouseAnim && !luggageAnim) if (!_mouseAnim && !_luggageAnim)
return; return;
// When an object is used in the game, the mouse cursor should be a // When an object is used in the game, the mouse cursor should be a
@ -140,27 +104,27 @@ void DrawMouse(void) {
int deltaX = 0; int deltaX = 0;
int deltaY = 0; int deltaY = 0;
if (mouseAnim) { if (_mouseAnim) {
hotspot_x = mouseAnim->xHotSpot; hotspot_x = _mouseAnim->xHotSpot;
hotspot_y = mouseAnim->yHotSpot; hotspot_y = _mouseAnim->yHotSpot;
mouse_width = mouseAnim->mousew; mouse_width = _mouseAnim->mousew;
mouse_height = mouseAnim->mouseh; mouse_height = _mouseAnim->mouseh;
} }
if (luggageAnim) { if (_luggageAnim) {
if (!mouseAnim) { if (!_mouseAnim) {
hotspot_x = luggageAnim->xHotSpot; hotspot_x = _luggageAnim->xHotSpot;
hotspot_y = luggageAnim->yHotSpot; hotspot_y = _luggageAnim->yHotSpot;
} }
if (luggageAnim->mousew > mouse_width) if (_luggageAnim->mousew > mouse_width)
mouse_width = luggageAnim->mousew; mouse_width = _luggageAnim->mousew;
if (luggageAnim->mouseh > mouse_height) if (_luggageAnim->mouseh > mouse_height)
mouse_height = luggageAnim->mouseh; mouse_height = _luggageAnim->mouseh;
} }
if (mouseAnim && luggageAnim) { if (_mouseAnim && _luggageAnim) {
deltaX = mouseAnim->xHotSpot - luggageAnim->xHotSpot; deltaX = _mouseAnim->xHotSpot - _luggageAnim->xHotSpot;
deltaY = mouseAnim->yHotSpot - luggageAnim->yHotSpot; deltaY = _mouseAnim->yHotSpot - _luggageAnim->yHotSpot;
} }
assert(deltaX >= 0); assert(deltaX >= 0);
@ -184,12 +148,12 @@ void DrawMouse(void) {
memset(_mouseData, 0xFF, mouse_width * mouse_height); memset(_mouseData, 0xFF, mouse_width * mouse_height);
if (luggageAnim) if (_luggageAnim)
DecompressMouse(_mouseData, (uint8 *) luggageAnim + READ_LE_UINT32(luggageOffset), luggageAnim->mousew, decompressMouse(_mouseData, (uint8 *) _luggageAnim + READ_LE_UINT32(_luggageOffset), _luggageAnim->mousew,
luggageAnim->mouseh, mouse_width, deltaX, deltaY); _luggageAnim->mouseh, mouse_width, deltaX, deltaY);
if (mouseAnim) if (_mouseAnim)
DecompressMouse(_mouseData, mouseSprite, mouseAnim->mousew, mouseAnim->mouseh, mouse_width); decompressMouse(_mouseData, _mouseSprite, _mouseAnim->mousew, _mouseAnim->mouseh, mouse_width);
g_system->set_mouse_cursor(_mouseData, mouse_width, mouse_height, hotspot_x, hotspot_y); g_system->set_mouse_cursor(_mouseData, mouse_width, mouse_height, hotspot_x, hotspot_y);
} }
@ -222,19 +186,19 @@ uint8 CheckForMouseEvents(void) {
* Animates the current mouse pointer * Animates the current mouse pointer
*/ */
int32 AnimateMouse(void) { int32 Display::animateMouse(void) {
uint8 prevMouseFrame = mouseFrame; uint8 prevMouseFrame = _mouseFrame;
if (!mouseAnim) if (!_mouseAnim)
return RDERR_UNKNOWN; return RDERR_UNKNOWN;
if (++mouseFrame == mouseAnim->noAnimFrames) if (++_mouseFrame == _mouseAnim->noAnimFrames)
mouseFrame = MOUSEFLASHFRAME; _mouseFrame = MOUSEFLASHFRAME;
mouseSprite = (uint8 *) mouseAnim + READ_LE_UINT32(mouseOffsets + mouseFrame); _mouseSprite = (uint8 *) _mouseAnim + READ_LE_UINT32(_mouseOffsets + _mouseFrame);
if (mouseFrame != prevMouseFrame) if (_mouseFrame != prevMouseFrame)
DrawMouse(); drawMouse();
return RD_OK; return RD_OK;
} }
@ -247,32 +211,32 @@ int32 AnimateMouse(void) {
* or not there is a lead-in animation * or not there is a lead-in animation
*/ */
int32 SetMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) { int32 Display::setMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) {
if (mouseAnim) { if (_mouseAnim) {
free(mouseAnim); free(_mouseAnim);
mouseAnim = NULL; _mouseAnim = NULL;
} }
if (ma) { if (ma) {
if (mouseFlash == RDMOUSE_FLASH) if (mouseFlash == RDMOUSE_FLASH)
mouseFrame = 0; _mouseFrame = 0;
else else
mouseFrame = MOUSEFLASHFRAME; _mouseFrame = MOUSEFLASHFRAME;
mouseAnim = (_mouseAnim *) malloc(size); _mouseAnim = (struct _mouseAnim *) malloc(size);
if (!mouseAnim) if (!_mouseAnim)
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
memcpy((uint8 *) mouseAnim, ma, size); memcpy((uint8 *) _mouseAnim, ma, size);
mouseOffsets = (int32 *) ((uint8 *) mouseAnim + sizeof(_mouseAnim)); _mouseOffsets = (int32 *) ((uint8 *) _mouseAnim + sizeof(struct _mouseAnim));
AnimateMouse(); animateMouse();
DrawMouse(); drawMouse();
g_system->show_mouse(true); g_system->show_mouse(true);
} else { } else {
if (luggageAnim) if (_luggageAnim)
DrawMouse(); drawMouse();
else else
g_system->show_mouse(false); g_system->show_mouse(false);
} }
@ -287,27 +251,27 @@ int32 SetMouseAnim(uint8 *ma, int32 size, int32 mouseFlash) {
* @param size the size of the animation data * @param size the size of the animation data
*/ */
int32 SetLuggageAnim(uint8 *ma, int32 size) { int32 Display::setLuggageAnim(uint8 *ma, int32 size) {
if (luggageAnim) { if (_luggageAnim) {
free(luggageAnim); free(_luggageAnim);
luggageAnim = NULL; _luggageAnim = NULL;
} }
if (ma) { if (ma) {
luggageAnim = (_mouseAnim *) malloc(size); _luggageAnim = (struct _mouseAnim *) malloc(size);
if (!luggageAnim) if (!_luggageAnim)
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
memcpy((uint8 *) luggageAnim, ma, size); memcpy((uint8 *) _luggageAnim, ma, size);
luggageOffset = (int32 *) ((uint8 *) luggageAnim + sizeof(_mouseAnim)); _luggageOffset = (int32 *) ((uint8 *) _luggageAnim + sizeof(struct _mouseAnim));
AnimateMouse(); animateMouse();
DrawMouse(); drawMouse();
g_system->show_mouse(true); g_system->show_mouse(true);
} else { } else {
if (mouseAnim) if (_mouseAnim)
DrawMouse(); drawMouse();
else else
g_system->show_mouse(false); g_system->show_mouse(false);
} }

View File

@ -22,11 +22,7 @@
namespace Sword2 { namespace Sword2 {
extern int16 mousex; // Mouse x coordinate
extern int16 mousey; // Mouse y coordinate
extern void LogMouseEvent(uint16 buttons); extern void LogMouseEvent(uint16 buttons);
extern int32 DrawMouse(void);
} // End of namespace Sword2 } // End of namespace Sword2

View File

@ -30,118 +30,90 @@
namespace Sword2 { namespace Sword2 {
byte *lpBackBuffer; Display::Display(int16 width, int16 height)
: _iconCount(0), _needFullRedraw(false), _fadeStatus(RDFADE_NONE),
_mouseSprite(NULL), _mouseAnim(NULL), _luggageAnim(NULL),
_layer(0), _renderAverageTime(60), _lightMask(NULL),
_screenWide(width), _screenDeep(height) {
// Game screen metrics int i, j;
int16 screenDeep;
int16 screenWide;
// Scroll variables. scrollx and scrolly hold the current scroll position, _buffer = (byte *) malloc(width * height);
if (!_buffer)
error("Could not initialise display");
int16 scrollx;
int16 scrolly;
int32 renderCaps = 0;
/**
* Initialise the display with the sizes passed in.
* @return RD_OK, or an error code if the display cannot be set up.
*/
int32 InitialiseDisplay(int16 width, int16 height) {
g_system->init_size(width, height); g_system->init_size(width, height);
screenWide = width; for (i = 0; i < ARRAYSIZE(_blockSurfaces); i++)
screenDeep = height; _blockSurfaces[i] = NULL;
lpBackBuffer = (byte *) malloc(screenWide * screenDeep); for (i = 0; i < 2; i++) {
if (!lpBackBuffer) for (j = 0; j < RDMENU_MAXPOCKETS; j++) {
return RDERR_OUTOFMEMORY; _icons[i][j] = NULL;
_pocketStatus[i][j] = 0;
}
return RD_OK; _menuStatus[i] = RDMENU_HIDDEN;
} }
// FIXME: Clean up this mess. I don't want to add any new flags, but some of
// them should be renamed. Or maybe we should abandon the whole renderCaps
// thing and simply check the numeric value of the graphics quality setting
// instead.
// Note that SetTransFx() actually clears a bit. That's intentional.
void SetTransFx(void) {
renderCaps &= ~RDBLTFX_ALLHARDWARE;
}
void ClearTransFx(void) {
renderCaps |= RDBLTFX_ALLHARDWARE;
}
/**
* Sets the edge blend and arithmetic stretching effects.
*/
void SetBltFx(void) {
renderCaps |= (RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH);
}
/**
* Clears the edge blend and arithmetic stretching effects.
*/
void ClearBltFx(void) {
renderCaps &= ~(RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH);
}
void SetShadowFx(void) {
renderCaps |= RDBLTFX_SHADOWBLEND;
}
void ClearShadowFx(void) {
renderCaps &= ~RDBLTFX_SHADOWBLEND;
} }
/** /**
* @return the graphics detail setting * @return the graphics detail setting
*/ */
int32 GetRenderType(void) { int8 Display::getRenderLevel(void) {
if (renderCaps & RDBLTFX_ALLHARDWARE) return _renderLevel;
return 0;
if (renderCaps & (RDBLTFX_EDGEBLEND | RDBLTFX_ARITHMETICSTRETCH))
return 3;
if (renderCaps & RDBLTFX_SHADOWBLEND)
return 2;
return 1;
} }
void Display::setRenderLevel(int8 level) {
_renderLevel = level;
switch (_renderLevel) {
case 0:
// Lowest setting: no fancy stuff
_renderCaps = 0;
break;
case 1:
// Medium-low setting: transparency-blending
_renderCaps = RDBLTFX_SPRITEBLEND;
break;
case 2:
// Medium-high setting: transparency-blending + shading
_renderCaps = RDBLTFX_SPRITEBLEND | RDBLTFX_SHADOWBLEND;
break;
case 3:
// Highest setting: transparency-blending + shading +
// edge-blending + improved stretching
_renderCaps = RDBLTFX_SPRITEBLEND | RDBLTFX_SHADOWBLEND | RDBLTFX_EDGEBLEND;
break;
}
}
/** /**
* Fill the screen buffer with palette colour zero. Note that it does not * Fill the screen buffer with palette colour zero. Note that it does not
* touch the menu areas of the screen. * touch the menu areas of the screen.
*/ */
int32 EraseBackBuffer( void ) { void Display::clearScene(void) {
memset(lpBackBuffer + MENUDEEP * screenWide, 0, screenWide * RENDERDEEP); memset(_buffer + MENUDEEP * _screenWide, 0, _screenWide * RENDERDEEP);
return RD_OK;
} }
void MoviePlayer::openTextObject(_movieTextObject *obj) { void MoviePlayer::openTextObject(_movieTextObject *obj) {
if (obj->textSprite) if (obj->textSprite)
CreateSurface(obj->textSprite, &_textSurface); g_display->createSurface(obj->textSprite, &_textSurface);
} }
void MoviePlayer::closeTextObject(_movieTextObject *obj) { void MoviePlayer::closeTextObject(_movieTextObject *obj) {
if (_textSurface) { if (_textSurface) {
DeleteSurface(_textSurface); g_display->deleteSurface(_textSurface);
_textSurface = NULL; _textSurface = NULL;
} }
} }
void MoviePlayer::drawTextObject(_movieTextObject *obj) { void MoviePlayer::drawTextObject(_movieTextObject *obj) {
if (obj->textSprite && _textSurface) if (obj->textSprite && _textSurface)
DrawSurface(obj->textSprite, _textSurface); g_display->drawSurface(obj->textSprite, _textSurface);
} }
/** /**
@ -161,14 +133,14 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu
uint8 oldPal[1024]; uint8 oldPal[1024];
uint8 tmpPal[1024]; uint8 tmpPal[1024];
EraseBackBuffer(); g_display->clearScene();
// HACK: Draw instructions // HACK: Draw instructions
// //
// I'm using the the menu area, because that's unlikely to be // I'm using the the menu area, because that's unlikely to be
// touched by anything else during the cutscene. // touched by anything else during the cutscene.
memset(lpBackBuffer, 0, screenWide * MENUDEEP); memset(g_display->_buffer, 0, g_display->_screenWide * MENUDEEP);
uint8 msg[] = "Cutscene - Press ESC to exit"; uint8 msg[] = "Cutscene - Press ESC to exit";
mem *data = fontRenderer.makeTextSprite(msg, 640, 255, g_sword2->_speechFontId); mem *data = fontRenderer.makeTextSprite(msg, 640, 255, g_sword2->_speechFontId);
@ -176,16 +148,16 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu
_spriteInfo msgSprite; _spriteInfo msgSprite;
uint8 *msgSurface; uint8 *msgSurface;
msgSprite.x = screenWide / 2 - frame->width / 2; msgSprite.x = g_display->_screenWide / 2 - frame->width / 2;
msgSprite.y = RDMENU_MENUDEEP / 2 - frame->height / 2; msgSprite.y = RDMENU_MENUDEEP / 2 - frame->height / 2;
msgSprite.w = frame->width; msgSprite.w = frame->width;
msgSprite.h = frame->height; msgSprite.h = frame->height;
msgSprite.type = RDSPR_DISPLAYALIGN | RDSPR_NOCOMPRESSION | RDSPR_TRANS; msgSprite.type = RDSPR_DISPLAYALIGN | RDSPR_NOCOMPRESSION | RDSPR_TRANS;
msgSprite.data = data->ad + sizeof(_frameHeader); msgSprite.data = data->ad + sizeof(_frameHeader);
CreateSurface(&msgSprite, &msgSurface); g_display->createSurface(&msgSprite, &msgSurface);
DrawSurface(&msgSprite, msgSurface); g_display->drawSurface(&msgSprite, msgSurface);
DeleteSurface(msgSurface); g_display->deleteSurface(msgSurface);
memory.freeMemory(data); memory.freeMemory(data);
// In case the cutscene has a long lead-in, start just before // In case the cutscene has a long lead-in, start just before
@ -201,12 +173,12 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu
// The text should probably be colored the same as the rest of // The text should probably be colored the same as the rest of
// the in-game text. // the in-game text.
memcpy(oldPal, palCopy, 1024); memcpy(oldPal, g_display->_palCopy, 1024);
memset(tmpPal, 0, 1024); memset(tmpPal, 0, 1024);
tmpPal[255 * 4 + 0] = 255; tmpPal[255 * 4 + 0] = 255;
tmpPal[255 * 4 + 1] = 255; tmpPal[255 * 4 + 1] = 255;
tmpPal[255 * 4 + 2] = 255; tmpPal[255 * 4 + 2] = 255;
BS2_SetPalette(0, 256, tmpPal, RDPAL_INSTANT); g_display->setPalette(0, 256, tmpPal, RDPAL_INSTANT);
PlayingSoundHandle handle = 0; PlayingSoundHandle handle = 0;
@ -217,7 +189,7 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu
break; break;
if (frameCounter == text[textCounter]->startFrame) { if (frameCounter == text[textCounter]->startFrame) {
EraseBackBuffer(); g_display->clearScene();
openTextObject(text[textCounter]); openTextObject(text[textCounter]);
drawTextObject(text[textCounter]); drawTextObject(text[textCounter]);
if (text[textCounter]->speech) { if (text[textCounter]->speech) {
@ -227,13 +199,13 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu
if (frameCounter == text[textCounter]->endFrame) { if (frameCounter == text[textCounter]->endFrame) {
closeTextObject(text[textCounter]); closeTextObject(text[textCounter]);
EraseBackBuffer(); g_display->clearScene();
textCounter++; textCounter++;
} }
frameCounter++; frameCounter++;
ServiceWindows(); g_display->updateDisplay();
_keyboardEvent ke; _keyboardEvent ke;
@ -252,17 +224,17 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu
closeTextObject(text[textCounter]); closeTextObject(text[textCounter]);
EraseBackBuffer(); g_display->clearScene();
SetNeedRedraw(); g_display->setNeedFullRedraw();
// HACK: Remove the instructions created above // HACK: Remove the instructions created above
Common::Rect r; Common::Rect r;
memset(lpBackBuffer, 0, screenWide * MENUDEEP); memset(g_display->_buffer, 0, g_display->_screenWide * MENUDEEP);
r.left = r.top = 0; r.left = r.top = 0;
r.right = screenWide; r.right = g_display->_screenWide;
r.bottom = MENUDEEP; r.bottom = MENUDEEP;
UploadRect(&r); g_display->updateRect(&r);
// FIXME: For now, only play the lead-out music for cutscenes // FIXME: For now, only play the lead-out music for cutscenes
// that have subtitles. // that have subtitles.
@ -270,7 +242,7 @@ int32 MoviePlayer::play(char *filename, _movieTextObject *text[], uint8 *musicOu
if (!skipCutscene) if (!skipCutscene)
g_sound->playLeadOut(musicOut); g_sound->playLeadOut(musicOut);
BS2_SetPalette(0, 256, oldPal, RDPAL_INSTANT); g_display->setPalette(0, 256, oldPal, RDPAL_INSTANT);
} }
// Lead-in and lead-out music are, as far as I can tell, only used for // Lead-in and lead-out music are, as far as I can tell, only used for

View File

@ -24,7 +24,40 @@
namespace Sword2 { namespace Sword2 {
extern byte *lpBackBuffer; // This is the maximum mouse cursor size in the SDL backend
#define MAX_MOUSE_W 80
#define MAX_MOUSE_H 80
#define RENDERAVERAGETOTAL 4
#define BLOCKWIDTH 64
#define BLOCKHEIGHT 64
#define MAXLAYERS 5
#define PALTABLESIZE 64 * 64 * 64
// Maximum scaled size of a sprite
#define SCALE_MAXWIDTH 512
#define SCALE_MAXHEIGHT 512
#if !defined(__GNUC__)
#pragma START_PACK_STRUCTS
#endif
struct _mouseAnim {
uint8 runTimeComp; // type of runtime compression used for the
// frame data
uint8 noAnimFrames; // number of frames in the anim
int8 xHotSpot;
int8 yHotSpot;
uint8 mousew;
uint8 mouseh;
} GCC_PACK;
#if !defined(__GNUC__)
#pragma END_PACK_STRUCTS
#endif
class MoviePlayer { class MoviePlayer {
private: private:
@ -38,6 +71,173 @@ public:
int32 play(char *filename, _movieTextObject *text[], uint8 *musicOut); int32 play(char *filename, _movieTextObject *text[], uint8 *musicOut);
}; };
typedef struct {
byte data[BLOCKWIDTH * BLOCKHEIGHT];
bool transparent;
} BlockSurface;
class Display {
friend class MoviePlayer;
private:
byte *_buffer;
int32 _renderCaps;
int8 _renderLevel;
uint8 _menuStatus[2];
byte *_icons[2][RDMENU_MAXPOCKETS];
uint8 _pocketStatus[2][RDMENU_MAXPOCKETS];
uint8 _iconCount;
bool _needFullRedraw;
uint8 _paletteMatch[PALTABLESIZE];
uint8 _fadePalette[256][4];
uint8 _fadeStatus;
int32 _fadeStartTime;
int32 _fadeTotalTime;
byte _mouseData[MAX_MOUSE_W * MAX_MOUSE_H];
uint8 _mouseFrame;
uint8 *_mouseSprite;
struct _mouseAnim *_mouseAnim;
struct _mouseAnim *_luggageAnim;
int32 *_mouseOffsets;
int32 *_luggageOffset;
// Scroll variables. _scrollX and _scrollY hold the current scroll
// position, and _scrollXTarget and _scrollYTarget are the target
// position for the end of the game cycle.
int16 _scrollX;
int16 _scrollY;
int16 _scrollXTarget;
int16 _scrollYTarget;
int16 _scrollXOld;
int16 _scrollYOld;
int16 _parallaxScrollX; // current x offset to link a sprite to the
// parallax layer
int16 _parallaxScrollY; // current y offset to link a sprite to the
// parallax layer
int16 _locationWide;
int16 _locationDeep;
uint16 _layer;
int32 _initialTime;
int32 _startTime;
int32 _totalTime;
int32 _renderAverageTime;
int32 _framesPerGameCycle;
bool _renderTooSlow;
uint8 _xBlocks[MAXLAYERS];
uint8 _yBlocks[MAXLAYERS];
// An array of sub-blocks, one for each of the parallax layers.
BlockSurface **_blockSurfaces[MAXLAYERS];
uint16 _xScale[SCALE_MAXWIDTH];
uint16 _yScale[SCALE_MAXHEIGHT];
uint8 *_lightMask;
void clearIconArea(int menu, int pocket, Common::Rect *r);
void decompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pitch, int xOff = 0, int yOff = 0);
void drawMouse(void);
uint8 getMatch(uint8 r, uint8 g, uint8 b);
void fadeServer(void);
void squashImage(byte *dst, uint16 dstPitch, uint16 dstWidth,
uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth,
uint16 srcHeight, byte *backbuf);
void stretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth,
uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth,
uint16 srcHeight, byte *backbuf);
void updateRect(Common::Rect *r);
void blitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect);
void mirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h);
int32 decompressRLE256(uint8 *dest, uint8 *source, int32 decompSize);
void unwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable);
int32 decompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable);
public:
Display(int16 width, int16 height);
// Game screen metrics
int16 _screenWide;
int16 _screenDeep;
int16 _mouseX;
int16 _mouseY;
uint8 _palCopy[256][4];
int8 getRenderLevel(void);
void setRenderLevel(int8 level);
void clearScene(void);
void processMenu(void);
int32 showMenu(uint8 menu);
int32 hideMenu(uint8 menu);
int32 setMenuIcon(uint8 menu, uint8 pocket, uint8 *icon);
void closeMenuImmediately(void);
void updateDisplay(void);
void setWindowName(const char *windowName);
void setNeedFullRedraw(void);
void setPalette(int16 startEntry, int16 noEntries, uint8 *palette, uint8 setNow);
void updatePaletteMatchTable(uint8 *data);
uint8 quickMatch(uint8 r, uint8 g, uint8 b);
int32 fadeUp(float time = 0.75);
int32 fadeDown(float time = 0.75);
uint8 getFadeStatus(void);
void dimPalette(void);
void waitForFade(void);
int32 setMouseAnim(uint8 *ma, int32 size, int32 mouseFlash);
int32 setLuggageAnim(uint8 *la, int32 size);
int32 animateMouse(void);
void resetRenderEngine(void);
void setScrollTarget(int16 sx, int16 sy);
void initialiseRenderCycle(void);
void startRenderCycle(void);
bool endRenderCycle(void);
void renderParallax(_parallax *p, int16 layer);
void setLocationMetrics(uint16 w, uint16 h);
int32 initialiseBackgroundLayer(_parallax *p);
void closeBackgroundLayer(void);
#ifdef _SWORD2_DEBUG
void plotPoint(uint16 x, uint16 y, uint8 colour);
void drawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint8 colour);
#endif
int32 createSurface(_spriteInfo *s, uint8 **surface);
void drawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect = NULL);
void deleteSurface(uint8 *surface);
int32 drawSprite(_spriteInfo *s);
int32 openLightMask(_spriteInfo *s);
int32 closeLightMask(void);
};
} // End of namespace Sword2 } // End of namespace Sword2
#endif #endif

View File

@ -245,7 +245,7 @@ void Sound::playLeadOut(uint8 *leadOut) {
} }
while (_fx[i]._handle) { while (_fx[i]._handle) {
ServiceWindows(); g_display->updateDisplay();
g_system->delay_msecs(30); g_system->delay_msecs(30);
} }
} }

View File

@ -176,18 +176,9 @@ namespace Sword2 {
#define RDPAL_INSTANT 1 #define RDPAL_INSTANT 1
//Blitting FX defines //Blitting FX defines
#define RDBLTFX_MOUSEBLT 0x01 #define RDBLTFX_SPRITEBLEND 0x01
#define RDBLTFX_FGPARALLAX 0x02 #define RDBLTFX_SHADOWBLEND 0x02
#define RDBLTFX_ARITHMETICSTRETCH 0x04 #define RDBLTFX_EDGEBLEND 0x04
#define RDBLTFX_EDGEBLEND 0x08
#define RDBLTFX_SHADOWBLEND 0x10
#define RDBLTFX_FLATALPHA 0x20
#define RDBLTFX_GRADEDALPHA 0x40
#define RDBLTFX_ALLHARDWARE 0x80
// Maximum scaled size of a sprite
#define SCALE_MAXWIDTH 512
#define SCALE_MAXHEIGHT 512
// //
// Structure definitions // Structure definitions
@ -275,29 +266,6 @@ typedef struct {
// ------------------- // -------------------
// //
//-----------------------------------------------------------------------------
// Display functions - from d_draw.c
//-----------------------------------------------------------------------------
extern int32 InitialiseDisplay(int16 width, int16 height);
extern int32 EraseBackBuffer(void);
extern void SetTransFx(void);
extern void ClearTransFx(void);
extern void SetBltFx(void);
extern void ClearBltFx(void);
extern void ClearShadowFx(void);
extern void SetShadowFx(void);
extern int32 GetRenderType(void);
extern int32 PlaySmacker(char *filename, _movieTextObject *textObjects[], uint8 *musicOut);
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Windows OS functions - from rdwin.c
//-----------------------------------------------------------------------------
extern int32 CloseAppWindow(void);
extern int32 ServiceWindows(void);
extern void SetWindowName(const char *windowName);
//-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Language functions - from language.c // Language functions - from language.c
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -305,28 +273,11 @@ extern int32 GetLanguageVersion(uint8 *version);
extern int32 SetLanguageVersion(uint8 version); extern int32 SetLanguageVersion(uint8 version);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Palette functions - from palette.c
//-----------------------------------------------------------------------------
extern int32 BS2_SetPalette(int16 startEntry, int16 noEntries, uint8 *palette, uint8 setNow);
extern int32 UpdatePaletteMatchTable(uint8 *data);
extern uint8 QuickMatch(uint8 r, uint8 g, uint8 b);
extern int32 FadeUp(float time);
extern int32 FadeDown(float time);
extern uint8 GetFadeStatus(void);
extern int32 DimPalette(void);
extern void WaitForFade(void);
//-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Mouse functions - from mouse.c // Mouse functions - from mouse.c
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern _mouseEvent *MouseEvent(void); extern _mouseEvent *MouseEvent(void);
extern int32 SetMouseAnim(uint8 *ma, int32 size, int32 mouseFlash); uint8 CheckForMouseEvents(void);
extern int32 SetLuggageAnim(uint8 *la, int32 size);
extern int32 AnimateMouse(void);
uint8 CheckForMouseEvents(void); // (James23july97)
extern void ResetRenderEngine(void);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -336,42 +287,6 @@ extern bool KeyWaiting(void);
extern int32 ReadKey(_keyboardEvent *ke); extern int32 ReadKey(_keyboardEvent *ke);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Sprite functions - from sprite.c
//-----------------------------------------------------------------------------
extern int32 DrawSprite(_spriteInfo *s);
extern int32 CreateSurface(_spriteInfo *s, uint8 **surface);
extern void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect = NULL);
extern void DeleteSurface(uint8 *surface);
extern int32 OpenLightMask(_spriteInfo *s);
extern int32 CloseLightMask(void);
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Screen drawing and scrolling function - from render.c
//-----------------------------------------------------------------------------
extern int32 SetScrollTarget(int16 sx, int16 sy);
extern int32 InitialiseRenderCycle(void);
extern int32 StartRenderCycle(void);
extern int32 EndRenderCycle(bool *end);
extern int32 RenderParallax(_parallax *p, int16 layer);
extern int32 SetLocationMetrics(uint16 w, uint16 h);
extern int32 PlotPoint(uint16 x, uint16 y, uint8 colour);
extern int32 DrawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint8 colour);
extern int32 InitialiseBackgroundLayer(_parallax *p);
extern int32 CloseBackgroundLayer(void);
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Menubar control and drawing functions - from menu.c
//-----------------------------------------------------------------------------
extern int32 ProcessMenu(void);
extern int32 ShowMenu(uint8 menu);
extern int32 HideMenu(uint8 menu);
extern int32 SetMenuIcon(uint8 menu, uint8 pocket, uint8 *icon);
extern uint8 GetMenuStatus(uint8 menu);
extern int32 CloseMenuImmediately(void);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Misc functions - from misc.cpp // Misc functions - from misc.cpp
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -380,14 +295,6 @@ extern void SVM_SetFileAttributes(char *file, uint32 atrib);
extern void SVM_DeleteFile(char *file); extern void SVM_DeleteFile(char *file);
extern int32 SVM_GetVolumeInformation(char *cdPath, char *sCDName, uint32 maxPath, uint8 *, uint32 *dwMaxCompLength, uint32 *dwFSFlags, uint8 *, uint32 a); extern int32 SVM_GetVolumeInformation(char *cdPath, char *sCDName, uint32 maxPath, uint8 *, uint32 *dwMaxCompLength, uint32 *dwFSFlags, uint8 *, uint32 a);
//-----------------------------------------------------------------------------
extern int16 screenWide; // Width of the screen display
extern int16 screenDeep; // Height of the screen display
extern int16 mousex; // Mouse screen x coordinate
extern int16 mousey; // Mouse screen y coordinate
extern int32 renderCaps; // Flags which determine how to render the scene.
extern uint8 palCopy[256][4]; // Current palette.
} // End of namespace Sword2 } // End of namespace Sword2
#endif #endif

View File

@ -29,23 +29,7 @@ namespace Sword2 {
#define MENUDEEP 40 #define MENUDEEP 40
#define MAXMENUANIMS 8 #define MAXMENUANIMS 8
static uint8 menuStatus[2] = { void Display::clearIconArea(int menu, int pocket, Common::Rect *r) {
RDMENU_HIDDEN, RDMENU_HIDDEN
};
static byte *icons[2][RDMENU_MAXPOCKETS] = {
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
static uint8 pocketStatus[2][RDMENU_MAXPOCKETS] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
static uint8 iconCount = 0;
void ClearIconArea(int menu, int pocket, Common::Rect *r) {
byte *dst; byte *dst;
int i; int i;
@ -54,11 +38,11 @@ void ClearIconArea(int menu, int pocket, Common::Rect *r) {
r->left = RDMENU_ICONSTART + pocket * (RDMENU_ICONWIDE + RDMENU_ICONSPACING); r->left = RDMENU_ICONSTART + pocket * (RDMENU_ICONWIDE + RDMENU_ICONSPACING);
r->right = r->left + RDMENU_ICONWIDE; r->right = r->left + RDMENU_ICONWIDE;
dst = lpBackBuffer + r->top * screenWide + r->left; dst = _buffer + r->top * _screenWide + r->left;
for (i = 0; i < RDMENU_ICONDEEP; i++) { for (i = 0; i < RDMENU_ICONDEEP; i++) {
memset(dst, 0, RDMENU_ICONWIDE); memset(dst, 0, RDMENU_ICONWIDE);
dst += screenWide; dst += _screenWide;
} }
} }
@ -68,7 +52,7 @@ void ClearIconArea(int menu, int pocket, Common::Rect *r) {
* system is. * system is.
*/ */
int32 ProcessMenu(void) { void Display::processMenu(void) {
byte *src, *dst; byte *src, *dst;
uint8 menu; uint8 menu;
uint8 i, j; uint8 i, j;
@ -90,84 +74,84 @@ int32 ProcessMenu(void) {
delta = 250; delta = 250;
frameCount = 1; frameCount = 1;
} else { } else {
frameCount = (uint8) ((iconCount + 8) * delta / 750); frameCount = (uint8) ((_iconCount + 8) * delta / 750);
lastTime += frameCount * 750 / (iconCount + 8); lastTime += frameCount * 750 / (_iconCount + 8);
} }
} }
while (frameCount-- > 0) { while (frameCount-- > 0) {
for (menu = RDMENU_TOP; menu <= RDMENU_BOTTOM; menu++) { for (menu = RDMENU_TOP; menu <= RDMENU_BOTTOM; menu++) {
if (menuStatus[menu] == RDMENU_OPENING) { if (_menuStatus[menu] == RDMENU_OPENING) {
// The menu is opening, so process it here // The menu is opening, so process it here
complete = 1; complete = 1;
// Propagate the animation from the first icon. // Propagate the animation from the first icon.
for (i = RDMENU_MAXPOCKETS - 1; i > 0; i--) { for (i = RDMENU_MAXPOCKETS - 1; i > 0; i--) {
pocketStatus[menu][i] = pocketStatus[menu][i - 1]; _pocketStatus[menu][i] = _pocketStatus[menu][i - 1];
if (pocketStatus[menu][i] != MAXMENUANIMS) if (_pocketStatus[menu][i] != MAXMENUANIMS)
complete = 0; complete = 0;
} }
if (pocketStatus[menu][i] != MAXMENUANIMS) if (_pocketStatus[menu][i] != MAXMENUANIMS)
complete = 0; complete = 0;
// ... and animate the first icon // ... and animate the first icon
if (pocketStatus[menu][0] != MAXMENUANIMS) if (_pocketStatus[menu][0] != MAXMENUANIMS)
pocketStatus[menu][0]++; _pocketStatus[menu][0]++;
// Check to see if the menu is fully open // Check to see if the menu is fully open
if (complete) if (complete)
menuStatus[menu] = RDMENU_SHOWN; _menuStatus[menu] = RDMENU_SHOWN;
} else if (menuStatus[menu] == RDMENU_CLOSING) { } else if (_menuStatus[menu] == RDMENU_CLOSING) {
// The menu is closing, so process it here // The menu is closing, so process it here
complete = 1; complete = 1;
// Propagate the animation from the first icon. // Propagate the animation from the first icon.
for (i = RDMENU_MAXPOCKETS - 1; i > 0; i--) { for (i = RDMENU_MAXPOCKETS - 1; i > 0; i--) {
if (icons[menu][i] && pocketStatus[menu][i] != 0 && pocketStatus[menu][i - 1] == 0) { if (_icons[menu][i] && _pocketStatus[menu][i] != 0 && _pocketStatus[menu][i - 1] == 0) {
ClearIconArea(menu, i, &r1); clearIconArea(menu, i, &r1);
UploadRect(&r1); updateRect(&r1);
} }
pocketStatus[menu][i] = pocketStatus[menu][i - 1]; _pocketStatus[menu][i] = _pocketStatus[menu][i - 1];
if (pocketStatus[menu][i] != 0) if (_pocketStatus[menu][i] != 0)
complete = 0; complete = 0;
} }
if (pocketStatus[menu][i] != 0) if (_pocketStatus[menu][i] != 0)
complete = 0; complete = 0;
// ... and animate the first icon // ... and animate the first icon
if (pocketStatus[menu][0] != 0) { if (_pocketStatus[menu][0] != 0) {
pocketStatus[menu][0]--; _pocketStatus[menu][0]--;
if (pocketStatus[menu][0] == 0) { if (_pocketStatus[menu][0] == 0) {
ClearIconArea(menu, 0, &r1); clearIconArea(menu, 0, &r1);
UploadRect(&r1); updateRect(&r1);
} }
} }
// Check to see if the menu is fully closed // Check to see if the menu is fully closed
if (complete) if (complete)
menuStatus[menu] = RDMENU_HIDDEN; _menuStatus[menu] = RDMENU_HIDDEN;
} }
} }
} }
// Does the menu need to be drawn? // Does the menu need to be drawn?
for (menu = RDMENU_TOP; menu <= RDMENU_BOTTOM; menu++) { for (menu = RDMENU_TOP; menu <= RDMENU_BOTTOM; menu++) {
if (menuStatus[menu] != RDMENU_HIDDEN) { if (_menuStatus[menu] != RDMENU_HIDDEN) {
// Draw the menu here. // Draw the menu here.
curx = RDMENU_ICONSTART + RDMENU_ICONWIDE / 2; curx = RDMENU_ICONSTART + RDMENU_ICONWIDE / 2;
cury = (MENUDEEP / 2) + (RENDERDEEP + MENUDEEP) * menu; cury = (MENUDEEP / 2) + (RENDERDEEP + MENUDEEP) * menu;
for (i = 0; i < RDMENU_MAXPOCKETS; i++) { for (i = 0; i < RDMENU_MAXPOCKETS; i++) {
if (icons[menu][i]) { if (_icons[menu][i]) {
// Since we no longer clear the screen // Since we no longer clear the screen
// after each frame we need to clear // after each frame we need to clear
// the icon area. // the icon area.
ClearIconArea(menu, i, &r1); clearIconArea(menu, i, &r1);
if (pocketStatus[menu][i] == MAXMENUANIMS) { if (_pocketStatus[menu][i] == MAXMENUANIMS) {
xoff = (RDMENU_ICONWIDE / 2); xoff = (RDMENU_ICONWIDE / 2);
r2.left = curx - xoff; r2.left = curx - xoff;
r2.right = r2.left + RDMENU_ICONWIDE; r2.right = r2.left + RDMENU_ICONWIDE;
@ -175,30 +159,30 @@ int32 ProcessMenu(void) {
r2.top = cury - yoff; r2.top = cury - yoff;
r2.bottom = r2.top + RDMENU_ICONDEEP; r2.bottom = r2.top + RDMENU_ICONDEEP;
} else { } else {
xoff = (RDMENU_ICONWIDE / 2) * pocketStatus[menu][i] / MAXMENUANIMS; xoff = (RDMENU_ICONWIDE / 2) * _pocketStatus[menu][i] / MAXMENUANIMS;
r2.left = curx - xoff; r2.left = curx - xoff;
r2.right = curx + xoff; r2.right = curx + xoff;
yoff = (RDMENU_ICONDEEP / 2) * pocketStatus[menu][i] / MAXMENUANIMS; yoff = (RDMENU_ICONDEEP / 2) * _pocketStatus[menu][i] / MAXMENUANIMS;
r2.top = cury - yoff; r2.top = cury - yoff;
r2.bottom = cury + yoff; r2.bottom = cury + yoff;
} }
if (xoff != 0 && yoff != 0) { if (xoff != 0 && yoff != 0) {
dst = lpBackBuffer + r2.top * screenWide + r2.left; dst = _buffer + r2.top * _screenWide + r2.left;
src = icons[menu][i]; src = _icons[menu][i];
if (pocketStatus[menu][i] != MAXMENUANIMS) { if (_pocketStatus[menu][i] != MAXMENUANIMS) {
SquashImage( squashImage(
dst, screenWide, r2.right - r2.left, r2.bottom - r2.top, dst, _screenWide, r2.right - r2.left, r2.bottom - r2.top,
src, RDMENU_ICONWIDE, RDMENU_ICONWIDE, RDMENU_ICONDEEP, NULL); src, RDMENU_ICONWIDE, RDMENU_ICONWIDE, RDMENU_ICONDEEP, NULL);
} else { } else {
for (j = 0; j < RDMENU_ICONDEEP; j++) { for (j = 0; j < RDMENU_ICONDEEP; j++) {
memcpy(dst, src, RDMENU_ICONWIDE); memcpy(dst, src, RDMENU_ICONWIDE);
src += RDMENU_ICONWIDE; src += RDMENU_ICONWIDE;
dst += screenWide; dst += _screenWide;
} }
} }
UploadRect(&r1); updateRect(&r1);
} }
} }
curx += (RDMENU_ICONSPACING + RDMENU_ICONWIDE); curx += (RDMENU_ICONSPACING + RDMENU_ICONWIDE);
@ -207,8 +191,6 @@ int32 ProcessMenu(void) {
} }
} }
} }
return RD_OK;
} }
/** /**
@ -217,17 +199,17 @@ int32 ProcessMenu(void) {
* @return RD_OK, or an error code * @return RD_OK, or an error code
*/ */
int32 ShowMenu(uint8 menu) { int32 Display::showMenu(uint8 menu) {
// Check for invalid menu parameter // Check for invalid menu parameter
if (menu > RDMENU_BOTTOM) if (menu > RDMENU_BOTTOM)
return RDERR_INVALIDMENU; return RDERR_INVALIDMENU;
// Check that the menu is not currently shown, or in the process of // Check that the menu is not currently shown, or in the process of
// being shown. // being shown.
if (menuStatus[menu] == RDMENU_SHOWN || menuStatus[menu] == RDMENU_OPENING) if (_menuStatus[menu] == RDMENU_SHOWN || _menuStatus[menu] == RDMENU_OPENING)
return RDERR_INVALIDCOMMAND; return RDERR_INVALIDCOMMAND;
menuStatus[menu] = RDMENU_OPENING; _menuStatus[menu] = RDMENU_OPENING;
return RD_OK; return RD_OK;
} }
@ -237,17 +219,17 @@ int32 ShowMenu(uint8 menu) {
* @return RD_OK, or an error code * @return RD_OK, or an error code
*/ */
int32 HideMenu(uint8 menu) { int32 Display::hideMenu(uint8 menu) {
// Check for invalid menu parameter // Check for invalid menu parameter
if (menu > RDMENU_BOTTOM) if (menu > RDMENU_BOTTOM)
return RDERR_INVALIDMENU; return RDERR_INVALIDMENU;
// Check that the menu is not currently hidden, or in the process of // Check that the menu is not currently hidden, or in the process of
// being hidden. // being hidden.
if (menuStatus[menu] == RDMENU_HIDDEN || menuStatus[menu] == RDMENU_CLOSING) if (_menuStatus[menu] == RDMENU_HIDDEN || _menuStatus[menu] == RDMENU_CLOSING)
return RDERR_INVALIDCOMMAND; return RDERR_INVALIDCOMMAND;
menuStatus[menu] = RDMENU_CLOSING; _menuStatus[menu] = RDMENU_CLOSING;
return RD_OK; return RD_OK;
} }
@ -255,26 +237,25 @@ int32 HideMenu(uint8 menu) {
* This function hides both menus immediately. * This function hides both menus immediately.
*/ */
int32 CloseMenuImmediately(void) { void Display::closeMenuImmediately(void) {
Common::Rect r; Common::Rect r;
int i; int i;
menuStatus[0] = RDMENU_HIDDEN; _menuStatus[0] = RDMENU_HIDDEN;
menuStatus[1] = RDMENU_HIDDEN; _menuStatus[1] = RDMENU_HIDDEN;
for (i = 0; i < RDMENU_MAXPOCKETS; i++) { for (i = 0; i < RDMENU_MAXPOCKETS; i++) {
if (icons[0][i]) { if (_icons[0][i]) {
ClearIconArea(0, i, &r); clearIconArea(0, i, &r);
UploadRect(&r); updateRect(&r);
} }
if (icons[1][i]) { if (_icons[1][i]) {
ClearIconArea(1, i, &r); clearIconArea(1, i, &r);
UploadRect(&r); updateRect(&r);
} }
} }
memset(pocketStatus, 0, sizeof(uint8) * 2 * RDMENU_MAXPOCKETS); memset(_pocketStatus, 0, sizeof(uint8) * 2 * RDMENU_MAXPOCKETS);
return RD_OK;
} }
/** /**
@ -285,11 +266,9 @@ int32 CloseMenuImmediately(void) {
* @return RD_OK, or an error code * @return RD_OK, or an error code
*/ */
int32 SetMenuIcon(uint8 menu, uint8 pocket, uint8 *icon) { int32 Display::setMenuIcon(uint8 menu, uint8 pocket, uint8 *icon) {
Common::Rect r; Common::Rect r;
debug(5, "stub SetMenuIcon( %d, %d )", menu, pocket);
// Check for invalid menu parameter. // Check for invalid menu parameter.
if (menu > RDMENU_BOTTOM) if (menu > RDMENU_BOTTOM)
return RDERR_INVALIDMENU; return RDERR_INVALIDMENU;
@ -299,33 +278,24 @@ int32 SetMenuIcon(uint8 menu, uint8 pocket, uint8 *icon) {
return RDERR_INVALIDPOCKET; return RDERR_INVALIDPOCKET;
// If there is an icon in the requested menu/pocket, clear it out. // If there is an icon in the requested menu/pocket, clear it out.
if (icons[menu][pocket]) { if (_icons[menu][pocket]) {
iconCount--; _iconCount--;
free(icons[menu][pocket]); free(_icons[menu][pocket]);
icons[menu][pocket] = NULL; _icons[menu][pocket] = NULL;
ClearIconArea(menu, pocket, &r); clearIconArea(menu, pocket, &r);
UploadRect(&r); updateRect(&r);
} }
// Only put the icon in the pocket if it is not NULL // Only put the icon in the pocket if it is not NULL
if (icon != NULL) { if (icon != NULL) {
iconCount++; _iconCount++;
icons[menu][pocket] = (uint8 *) malloc(RDMENU_ICONWIDE * RDMENU_ICONDEEP); _icons[menu][pocket] = (uint8 *) malloc(RDMENU_ICONWIDE * RDMENU_ICONDEEP);
if (icons[menu][pocket] == NULL) if (_icons[menu][pocket] == NULL)
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
memcpy(icons[menu][pocket], icon, RDMENU_ICONWIDE * RDMENU_ICONDEEP); memcpy(_icons[menu][pocket], icon, RDMENU_ICONWIDE * RDMENU_ICONDEEP);
} }
return RD_OK; return RD_OK;
} }
/**
* @return The status of the menu
*/
uint8 GetMenuStatus(uint8 menu) {
if (menu > RDMENU_BOTTOM)
return RDMENU_HIDDEN;
return menuStatus[menu];
}
} // End of namespace Sword2 } // End of namespace Sword2

View File

@ -20,54 +20,31 @@
#include "stdafx.h" #include "stdafx.h"
#include "common/util.h" #include "common/util.h"
#include "base/engine.h" #include "base/engine.h"
#include "bs2/sword2.h"
#include "bs2/driver/d_draw.h" #include "bs2/driver/d_draw.h"
#include "bs2/driver/driver96.h" #include "bs2/driver/driver96.h"
#include "bs2/sword2.h"
namespace Sword2 { namespace Sword2 {
#define PALTABLESIZE 64 * 64 * 64 uint8 Display::getMatch(uint8 r, uint8 g, uint8 b) {
uint8 palCopy[256][4];
static uint8 fadePalette[256][4];
static uint8 paletteMatch[PALTABLESIZE];
static uint8 fadeStatus = RDFADE_NONE;
static int32 fadeStartTime;
static int32 fadeTotalTime;
// --------------------------------------------------------------------------
// int32 RestorePalette(void)
//
// This function restores the palette, and should be called whenever the
// screen mode changes, or something like that.
// --------------------------------------------------------------------------
int32 RestorePalette(void) {
g_system->set_palette((const byte *) palCopy, 0, 256);
return RD_OK;
}
uint8 GetMatch(uint8 r, uint8 g, uint8 b) {
int32 diff; int32 diff;
int32 min; int32 min;
int16 diffred, diffgreen, diffblue; int16 diffred, diffgreen, diffblue;
int16 i; int16 i;
uint8 minIndex; uint8 minIndex;
diffred = palCopy[0][0] - r; diffred = _palCopy[0][0] - r;
diffgreen = palCopy[0][1] - g; diffgreen = _palCopy[0][1] - g;
diffblue = palCopy[0][2] - b; diffblue = _palCopy[0][2] - b;
diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue; diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue;
min = diff; min = diff;
minIndex = 0; minIndex = 0;
if (diff > 0) { if (diff > 0) {
for (i = 1; i < 256; i++) { for (i = 1; i < 256; i++) {
diffred = palCopy[i][0] - r; diffred = _palCopy[i][0] - r;
diffgreen = palCopy[i][1] - g; diffgreen = _palCopy[i][1] - g;
diffblue = palCopy[i][2] - b; diffblue = _palCopy[i][2] - b;
diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue; diff = diffred * diffred + diffgreen * diffgreen + diffblue * diffblue;
if (diff < min) { if (diff < min) {
@ -90,7 +67,7 @@ uint8 GetMatch(uint8 r, uint8 g, uint8 b) {
* from the current palCopy * from the current palCopy
*/ */
int32 UpdatePaletteMatchTable(uint8 *data) { void Display::updatePaletteMatchTable(uint8 *data) {
if (!data) { if (!data) {
int16 red, green, blue; int16 red, green, blue;
uint8 *p; uint8 *p;
@ -99,20 +76,18 @@ int32 UpdatePaletteMatchTable(uint8 *data) {
// FIXME: Does this case ever happen? // FIXME: Does this case ever happen?
p = &paletteMatch[0]; p = &_paletteMatch[0];
for (red = 0; red < 256; red += 4) { for (red = 0; red < 256; red += 4) {
for (green = 0; green < 256; green += 4) { for (green = 0; green < 256; green += 4) {
for (blue = 0; blue < 256; blue += 4) { for (blue = 0; blue < 256; blue += 4) {
*p++ = GetMatch((uint8) red, (uint8) green, (uint8) blue); *p++ = getMatch((uint8) red, (uint8) green, (uint8) blue);
} }
} }
} }
} else { } else {
// The provided data is the new palette match table // The provided data is the new palette match table
memcpy(paletteMatch, data, PALTABLESIZE); memcpy(_paletteMatch, data, PALTABLESIZE);
} }
return RD_OK;
} }
/** /**
@ -126,8 +101,8 @@ int32 UpdatePaletteMatchTable(uint8 *data) {
// FIXME: This used to be inlined - probably a good idea - but the // FIXME: This used to be inlined - probably a good idea - but the
// linker complained when I tried to use it in sprite.cpp. // linker complained when I tried to use it in sprite.cpp.
uint8 QuickMatch(uint8 r, uint8 g, uint8 b) { uint8 Display::quickMatch(uint8 r, uint8 g, uint8 b) {
return paletteMatch[((int32) (r >> 2) << 12) + ((int32) (g >> 2) << 6) + (b >> 2)]; return _paletteMatch[((int32) (r >> 2) << 12) + ((int32) (g >> 2) << 6) + (b >> 2)];
} }
/** /**
@ -137,27 +112,22 @@ uint8 QuickMatch(uint8 r, uint8 g, uint8 b) {
* @param colourTable the new colour entries * @param colourTable the new colour entries
*/ */
int32 BS2_SetPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, uint8 fadeNow) { void Display::setPalette(int16 startEntry, int16 noEntries, uint8 *colourTable, uint8 fadeNow) {
if (noEntries == 0) { if (noEntries) {
RestorePalette(); memcpy(&_palCopy[startEntry][0], colourTable, noEntries * 4);
return RD_OK; if (fadeNow == RDPAL_INSTANT)
} g_system->set_palette((const byte *) _palCopy, startEntry, noEntries);
} else
memcpy(&palCopy[startEntry][0], colourTable, noEntries * 4); g_system->set_palette((const byte *) _palCopy, 0, 256);
if (fadeNow == RDPAL_INSTANT)
g_system->set_palette((byte *) palCopy, startEntry, noEntries);
return RD_OK;
} }
int32 DimPalette(void) { void Display::dimPalette(void) {
byte *p = (byte *) palCopy; byte *p = (byte *) _palCopy;
for (int i = 0; i < 256 * 4; i++) for (int i = 0; i < 256 * 4; i++)
p[i] /= 2; p[i] /= 2;
g_system->set_palette(p, 0, 256); g_system->set_palette(p, 0, 256);
return RD_OK;
} }
/** /**
@ -165,13 +135,13 @@ int32 DimPalette(void) {
* @param time the time it will take the palette to fade up * @param time the time it will take the palette to fade up
*/ */
int32 FadeUp(float time) { int32 Display::fadeUp(float time) {
if (fadeStatus != RDFADE_BLACK && fadeStatus != RDFADE_NONE) if (getFadeStatus() != RDFADE_BLACK && getFadeStatus() != RDFADE_NONE)
return RDERR_FADEINCOMPLETE; return RDERR_FADEINCOMPLETE;
fadeTotalTime = (int32) (time * 1000); _fadeTotalTime = (int32) (time * 1000);
fadeStatus = RDFADE_UP; _fadeStatus = RDFADE_UP;
fadeStartTime = SVM_timeGetTime(); _fadeStartTime = SVM_timeGetTime();
return RD_OK; return RD_OK;
} }
@ -181,13 +151,13 @@ int32 FadeUp(float time) {
* @param time the time it will take the palette to fade down * @param time the time it will take the palette to fade down
*/ */
int32 FadeDown(float time) { int32 Display::fadeDown(float time) {
if (fadeStatus != RDFADE_BLACK && fadeStatus != RDFADE_NONE) if (getFadeStatus() != RDFADE_BLACK && getFadeStatus() != RDFADE_NONE)
return RDERR_FADEINCOMPLETE; return RDERR_FADEINCOMPLETE;
fadeTotalTime = (int32) (time * 1000); _fadeTotalTime = (int32) (time * 1000);
fadeStatus = RDFADE_DOWN; _fadeStatus = RDFADE_DOWN;
fadeStartTime = SVM_timeGetTime(); _fadeStartTime = SVM_timeGetTime();
return RD_OK; return RD_OK;
} }
@ -198,20 +168,20 @@ int32 FadeDown(float time) {
* (not faded), or RDFADE_BLACK (completely faded down) * (not faded), or RDFADE_BLACK (completely faded down)
*/ */
uint8 GetFadeStatus(void) { uint8 Display::getFadeStatus(void) {
return fadeStatus; return _fadeStatus;
} }
void WaitForFade(void) { void Display::waitForFade(void) {
while (GetFadeStatus() != RDFADE_NONE && GetFadeStatus() != RDFADE_BLACK) { while (getFadeStatus() != RDFADE_NONE && getFadeStatus() != RDFADE_BLACK) {
ServiceWindows(); updateDisplay();
g_system->delay_msecs(20); g_system->delay_msecs(20);
} }
} }
void FadeServer() { void Display::fadeServer(void) {
static int32 previousTime = 0; static int32 previousTime = 0;
const byte *newPalette = (const byte *) fadePalette; const byte *newPalette = (const byte *) _fadePalette;
int32 currentTime; int32 currentTime;
int16 fadeMultiplier; int16 fadeMultiplier;
int16 i; int16 i;
@ -221,7 +191,7 @@ void FadeServer() {
// actually update the screen. // actually update the screen.
// If we're not in the process of fading, do nothing. // If we're not in the process of fading, do nothing.
if (fadeStatus != RDFADE_UP && fadeStatus != RDFADE_DOWN) if (getFadeStatus() != RDFADE_UP && getFadeStatus() != RDFADE_DOWN)
return; return;
// I don't know if this is necessary, but let's limit how often the // I don't know if this is necessary, but let's limit how often the
@ -232,28 +202,28 @@ void FadeServer() {
previousTime = currentTime; previousTime = currentTime;
if (fadeStatus == RDFADE_UP) { if (getFadeStatus() == RDFADE_UP) {
if (currentTime >= fadeStartTime + fadeTotalTime) { if (currentTime >= _fadeStartTime + _fadeTotalTime) {
fadeStatus = RDFADE_NONE; _fadeStatus = RDFADE_NONE;
newPalette = (const byte *) palCopy; newPalette = (const byte *) _palCopy;
} else { } else {
fadeMultiplier = (int16) (((int32) (currentTime - fadeStartTime) * 256) / fadeTotalTime); fadeMultiplier = (int16) (((int32) (currentTime - _fadeStartTime) * 256) / _fadeTotalTime);
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8; _fadePalette[i][0] = (_palCopy[i][0] * fadeMultiplier) >> 8;
fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8; _fadePalette[i][1] = (_palCopy[i][1] * fadeMultiplier) >> 8;
fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8; _fadePalette[i][2] = (_palCopy[i][2] * fadeMultiplier) >> 8;
} }
} }
} else { } else {
if (currentTime >= fadeStartTime + fadeTotalTime) { if (currentTime >= _fadeStartTime + _fadeTotalTime) {
fadeStatus = RDFADE_BLACK; _fadeStatus = RDFADE_BLACK;
memset(fadePalette, 0, sizeof(fadePalette)); memset(_fadePalette, 0, sizeof(_fadePalette));
} else { } else {
fadeMultiplier = (int16) (((int32) (fadeTotalTime - (currentTime - fadeStartTime)) * 256) / fadeTotalTime); fadeMultiplier = (int16) (((int32) (_fadeTotalTime - (currentTime - _fadeStartTime)) * 256) / _fadeTotalTime);
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
fadePalette[i][0] = (palCopy[i][0] * fadeMultiplier) >> 8; _fadePalette[i][0] = (_palCopy[i][0] * fadeMultiplier) >> 8;
fadePalette[i][1] = (palCopy[i][1] * fadeMultiplier) >> 8; _fadePalette[i][1] = (_palCopy[i][1] * fadeMultiplier) >> 8;
fadePalette[i][2] = (palCopy[i][2] * fadeMultiplier) >> 8; _fadePalette[i][2] = (_palCopy[i][2] * fadeMultiplier) >> 8;
} }
} }
} }

View File

@ -22,11 +22,6 @@
namespace Sword2 { namespace Sword2 {
extern uint8 paletteMatch[64*64*64];
extern int32 RestorePalette(void);
extern void FadeServer();
} // End of namespace Sword2 } // End of namespace Sword2
#endif #endif

View File

@ -44,8 +44,8 @@ void Sword2Engine::parseEvents() {
WriteKey(event.kbd.ascii, event.kbd.keycode, event.kbd.flags); WriteKey(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
break; break;
case OSystem::EVENT_MOUSEMOVE: case OSystem::EVENT_MOUSEMOVE:
mousex = event.mouse.x; g_display->_mouseX = event.mouse.x;
mousey = event.mouse.y - MENUDEEP; g_display->_mouseY = event.mouse.y - MENUDEEP;
break; break;
case OSystem::EVENT_LBUTTONDOWN: case OSystem::EVENT_LBUTTONDOWN:
LogMouseEvent(RD_LEFTBUTTONDOWN); LogMouseEvent(RD_LEFTBUTTONDOWN);
@ -61,7 +61,6 @@ void Sword2Engine::parseEvents() {
break; break;
case OSystem::EVENT_QUIT: case OSystem::EVENT_QUIT:
Close_game(); Close_game();
CloseAppWindow();
break; break;
default: default:
break; break;
@ -69,24 +68,8 @@ void Sword2Engine::parseEvents() {
} }
} }
/** void Display::setNeedFullRedraw() {
* Quit the game. _needFullRedraw = true;
*/
int32 CloseAppWindow(void) {
warning("stub CloseAppWindow");
/*
DestroyWindow(hwnd);
*/
// just quit for now
g_system->quit();
return RD_OK;
}
static bool _needRedraw = false;
void SetNeedRedraw() {
_needRedraw = true;
} }
/** /**
@ -94,29 +77,27 @@ void SetNeedRedraw() {
* windows and the interface it provides. * windows and the interface it provides.
*/ */
int32 ServiceWindows(void) { void Display::updateDisplay(void) {
g_sword2->parseEvents(); g_sword2->parseEvents();
FadeServer(); fadeServer();
// FIXME: We re-render the entire picture area of the screen for each // FIXME: We re-render the entire picture area of the screen for each
// frame, which is pretty horrible. // frame, which is pretty horrible.
if (_needRedraw) { if (_needFullRedraw) {
g_system->copy_rect(lpBackBuffer + MENUDEEP * screenWide, screenWide, 0, MENUDEEP, screenWide, screenDeep - 2 * MENUDEEP); g_system->copy_rect(_buffer + MENUDEEP * _screenWide, _screenWide, 0, MENUDEEP, _screenWide, _screenDeep - 2 * MENUDEEP);
_needRedraw = false; _needFullRedraw = false;
} }
// We still need to update because of fades, menu animations, etc. // We still need to update because of fades, menu animations, etc.
g_system->update_screen(); g_system->update_screen();
return RD_OK;
} }
/** /**
* Set the window title * Set the window title
*/ */
void SetWindowName(const char *windowName) { void Display::setWindowName(const char *windowName) {
OSystem::Property prop; OSystem::Property prop;
prop.caption = windowName; prop.caption = windowName;

View File

@ -22,8 +22,6 @@
namespace Sword2 { namespace Sword2 {
extern void SetNeedRedraw(void);
} // End of namespace Sword2 } // End of namespace Sword2
#endif #endif

View File

@ -28,60 +28,18 @@
namespace Sword2 { namespace Sword2 {
#define MILLISECSPERCYCLE 83 #define MILLISECSPERCYCLE 83
// Scroll variables. scrollx and scrolly hold the current scroll position, #define BLOCKWBITS 6
// and scrollxTarget and scrollyTarget are the target position for the end #define BLOCKHBITS 6
// of the game cycle.
extern int16 scrollx; void Display::updateRect(Common::Rect *r) {
extern int16 scrolly; g_system->copy_rect(_buffer + r->top * _screenWide + r->left,
int16 parallaxScrollx; _screenWide, r->left, r->top, r->right - r->left,
int16 parallaxScrolly; r->bottom - r->top);
int16 locationWide;
int16 locationDeep;
static int16 scrollxTarget;
static int16 scrollyTarget;
static int16 scrollxOld;
static int16 scrollyOld;
static uint16 layer = 0;
#define RENDERAVERAGETOTAL 4
static int32 renderCountIndex = 0;
static int32 renderTimeLog[RENDERAVERAGETOTAL] = { 60, 60, 60, 60 };
static int32 initialTime;
static int32 startTime;
static int32 totalTime;
static int32 renderAverageTime = 60;
static int32 framesPerGameCycle;
static int32 renderTooSlow;
#define BLOCKWIDTH 64
#define BLOCKHEIGHT 64
#define BLOCKWBITS 6
#define BLOCKHBITS 6
#define MAXLAYERS 5
static uint8 xblocks[MAXLAYERS];
static uint8 yblocks[MAXLAYERS];
// blockSurfaces stores an array of sub-blocks for each of the parallax layers.
typedef struct {
byte data[BLOCKWIDTH * BLOCKHEIGHT];
bool transparent;
} BlockSurface;
static BlockSurface **blockSurfaces[MAXLAYERS] = { 0, 0, 0, 0, 0 };
void UploadRect(Common::Rect *r) {
g_system->copy_rect(lpBackBuffer + r->top * screenWide + r->left,
screenWide, r->left, r->top, r->right - r->left, r->bottom - r->top);
} }
void BlitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect) { void Display::blitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect) {
if (r->top > clip_rect->bottom || r->left > clip_rect->right || r->bottom <= clip_rect->top || r->right <= clip_rect->left) if (r->top > clip_rect->bottom || r->left > clip_rect->right || r->bottom <= clip_rect->top || r->right <= clip_rect->left)
return; return;
@ -100,7 +58,7 @@ void BlitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect)
if (r->right > clip_rect->right) if (r->right > clip_rect->right)
r->right = clip_rect->right; r->right = clip_rect->right;
byte *dst = lpBackBuffer + r->top * screenWide + r->left; byte *dst = _buffer + r->top * _screenWide + r->left;
int i, j; int i, j;
if (s->transparent) { if (s->transparent) {
@ -110,23 +68,20 @@ void BlitBlockSurface(BlockSurface *s, Common::Rect *r, Common::Rect *clip_rect)
dst[j] = src[j]; dst[j] = src[j];
} }
src += BLOCKWIDTH; src += BLOCKWIDTH;
dst += screenWide; dst += _screenWide;
} }
} else { } else {
for (i = 0; i < r->bottom - r->top; i++) { for (i = 0; i < r->bottom - r->top; i++) {
memcpy(dst, src, r->right - r->left); memcpy(dst, src, r->right - r->left);
src += BLOCKWIDTH; src += BLOCKWIDTH;
dst += screenWide; dst += _screenWide;
} }
} }
// UploadRect(r); // UploadRect(r);
SetNeedRedraw(); g_display->setNeedFullRedraw();
} }
static uint16 xScale[SCALE_MAXWIDTH];
static uint16 yScale[SCALE_MAXHEIGHT];
// I've made the scaling two separate functions because there were cases from // I've made the scaling two separate functions because there were cases from
// DrawSprite() where it wasn't obvious if the sprite should grow or shrink, // DrawSprite() where it wasn't obvious if the sprite should grow or shrink,
// which caused crashes. // which caused crashes.
@ -140,7 +95,7 @@ static uint16 yScale[SCALE_MAXHEIGHT];
// be drawn. This is only used at the highest graphics detail setting (and not // be drawn. This is only used at the highest graphics detail setting (and not
// always even then) and is used to help anti-alias the image. // always even then) and is used to help anti-alias the image.
void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { void Display::squashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) {
int32 ince, incne, d; int32 ince, incne, d;
int16 x, y; int16 x, y;
@ -150,7 +105,7 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
incne = 2 * (dstWidth - srcWidth); incne = 2 * (dstWidth - srcWidth);
d = 2 * dstWidth - srcWidth; d = 2 * dstWidth - srcWidth;
x = y = 0; x = y = 0;
xScale[y] = x; _xScale[y] = x;
while (x < srcWidth) { while (x < srcWidth) {
if (d <= 0) { if (d <= 0) {
@ -161,7 +116,7 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
x++; x++;
y++; y++;
} }
xScale[y] = x; _xScale[y] = x;
} }
// Work out the y-scale // Work out the y-scale
@ -170,7 +125,7 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
incne = 2 * (dstHeight - srcHeight); incne = 2 * (dstHeight - srcHeight);
d = 2 * dstHeight - srcHeight; d = 2 * dstHeight - srcHeight;
x = y = 0; x = y = 0;
yScale[y] = x; _yScale[y] = x;
while (x < srcHeight) { while (x < srcHeight) {
if (d <= 0) { if (d <= 0) {
@ -181,7 +136,7 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
x++; x++;
y++; y++;
} }
yScale[y] = x; _yScale[y] = x;
} }
// Copy the image (with or without anti-aliasing) // Copy the image (with or without anti-aliasing)
@ -198,19 +153,19 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
int blue = 0; int blue = 0;
int i, j; int i, j;
for (j = yScale[y]; j < yScale[y + 1]; j++) { for (j = _yScale[y]; j < _yScale[y + 1]; j++) {
for (i = xScale[x]; i < xScale[x + 1]; i++) { for (i = _xScale[x]; i < _xScale[x + 1]; i++) {
p = src[j * srcPitch + i]; p = src[j * srcPitch + i];
if (p) { if (p) {
red += palCopy[p][0]; red += _palCopy[p][0];
green += palCopy[p][1]; green += _palCopy[p][1];
blue += palCopy[p][2]; blue += _palCopy[p][2];
p1 = p; p1 = p;
spriteCount++; spriteCount++;
} else { } else {
red += palCopy[backbuf[x]][0]; red += _palCopy[backbuf[x]][0];
green += palCopy[backbuf[x]][1]; green += _palCopy[backbuf[x]][1];
blue += palCopy[backbuf[x]][2]; blue += _palCopy[backbuf[x]][2];
} }
count++; count++;
} }
@ -220,22 +175,22 @@ void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
else if (spriteCount == 1) else if (spriteCount == 1)
dst[x] = p1; dst[x] = p1;
else else
dst[x] = QuickMatch((uint8) (red / count), (uint8) (green / count), (uint8) (blue / count)); dst[x] = quickMatch((uint8) (red / count), (uint8) (green / count), (uint8) (blue / count));
} }
dst += dstPitch; dst += dstPitch;
backbuf += screenWide; backbuf += _screenWide;
} }
} else { } else {
for (y = 0; y < dstHeight; y++) { for (y = 0; y < dstHeight; y++) {
for (x = 0; x < dstWidth; x++) { for (x = 0; x < dstWidth; x++) {
dst[x] = src[yScale[y] * srcPitch + xScale[x]]; dst[x] = src[_yScale[y] * srcPitch + _xScale[x]];
} }
dst += dstPitch; dst += dstPitch;
} }
} }
} }
void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { void Display::stretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) {
byte *origDst = dst; byte *origDst = dst;
int32 ince, incne, d; int32 ince, incne, d;
int16 x, y, i, j, k; int16 x, y, i, j, k;
@ -246,7 +201,7 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
incne = 2 * (srcWidth - dstWidth); incne = 2 * (srcWidth - dstWidth);
d = 2 * srcWidth - dstWidth; d = 2 * srcWidth - dstWidth;
x = y = 0; x = y = 0;
xScale[y] = x; _xScale[y] = x;
while (x < dstWidth) { while (x < dstWidth) {
if (d <= 0) { if (d <= 0) {
@ -256,7 +211,7 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
d += incne; d += incne;
x++; x++;
y++; y++;
xScale[y] = x; _xScale[y] = x;
} }
} }
@ -266,7 +221,7 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
incne = 2 * (srcHeight - dstHeight); incne = 2 * (srcHeight - dstHeight);
d = 2 * srcHeight - dstHeight; d = 2 * srcHeight - dstHeight;
x = y = 0; x = y = 0;
yScale[y] = x; _yScale[y] = x;
while (x < dstHeight) { while (x < dstHeight) {
if (d <= 0) { if (d <= 0) {
d += ince; d += ince;
@ -275,17 +230,17 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
d += incne; d += incne;
x++; x++;
y++; y++;
yScale[y] = x; _yScale[y] = x;
} }
} }
// Copy the image // Copy the image
for (y = 0; y < srcHeight; y++) { for (y = 0; y < srcHeight; y++) {
for (j = yScale[y]; j < yScale[y + 1]; j++) { for (j = _yScale[y]; j < _yScale[y + 1]; j++) {
k = 0; k = 0;
for (x = 0; x < srcWidth; x++) { for (x = 0; x < srcWidth; x++) {
for (i = xScale[x]; i < xScale[x + 1]; i++) { for (i = _xScale[x]; i < _xScale[x + 1]; i++) {
dst[k++] = src[y * srcPitch + x]; dst[k++] = src[y * srcPitch + x];
} }
} }
@ -342,16 +297,16 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
count++; count++;
if (count) { if (count) {
int red = palCopy[pt[0]][0] << 2; int red = _palCopy[pt[0]][0] << 2;
int green = palCopy[pt[0]][1] << 2; int green = _palCopy[pt[0]][1] << 2;
int blue = palCopy[pt[0]][2] << 2; int blue = _palCopy[pt[0]][2] << 2;
for (i = 1; i < 5; i++) { for (i = 1; i < 5; i++) {
red += palCopy[pt[i]][0]; red += _palCopy[pt[i]][0];
green += palCopy[pt[i]][1]; green += _palCopy[pt[i]][1];
blue += palCopy[pt[i]][2]; blue += _palCopy[pt[i]][2];
} }
*dst++ = QuickMatch((uint8) (red >> 3), (uint8) (green >> 3), (uint8) (blue >> 3)); *dst++ = quickMatch((uint8) (red >> 3), (uint8) (green >> 3), (uint8) (blue >> 3));
} else } else
*dst++ = 0; *dst++ = 0;
src++; src++;
@ -373,27 +328,7 @@ void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight,
} }
} }
int32 RestoreBackgroundLayer(_parallax *p, int16 l) #ifdef _SWORD2_DEBUG
{
int16 oldLayer = layer;
debug(2, "RestoreBackgroundLayer %d", l);
layer = l;
if (blockSurfaces[l]) {
for (int i = 0; i < xblocks[l] * yblocks[l]; i++) {
if (blockSurfaces[l][i])
free(blockSurfaces[l][i]);
}
free(blockSurfaces[l]);
blockSurfaces[l] = NULL;
}
InitialiseBackgroundLayer(p);
layer = oldLayer;
return RD_OK;
}
/** /**
* Plots a point relative to the top left corner of the screen. This is only * Plots a point relative to the top left corner of the screen. This is only
* used for debugging. * used for debugging.
@ -402,17 +337,15 @@ int32 RestoreBackgroundLayer(_parallax *p, int16 l)
* @param colour colour of the point * @param colour colour of the point
*/ */
int32 PlotPoint(uint16 x, uint16 y, uint8 colour) { void Display::plotPoint(uint16 x, uint16 y, uint8 colour) {
uint8 *buf = lpBackBuffer + 40 * RENDERWIDE; uint8 *buf = _buffer + 40 * RENDERWIDE;
int16 newx, newy; int16 newx, newy;
newx = x - scrollx; newx = x - _scrollX;
newy = y - scrolly; newy = y - _scrollY;
if (newx >= 0 && newx < RENDERWIDE && newy >= 0 && newy < RENDERDEEP) if (newx >= 0 && newx < RENDERWIDE && newy >= 0 && newy < RENDERDEEP)
buf[newy * RENDERWIDE + newx] = colour; buf[newy * RENDERWIDE + newx] = colour;
return RD_OK;
} }
/** /**
@ -425,8 +358,8 @@ int32 PlotPoint(uint16 x, uint16 y, uint8 colour) {
*/ */
// Uses Bressnham's incremental algorithm! // Uses Bressnham's incremental algorithm!
int32 DrawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) { void Display::drawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) {
uint8 *buf = lpBackBuffer + 40 * RENDERWIDE; uint8 *buf = _buffer + 40 * RENDERWIDE;
int dx, dy; int dx, dy;
int dxmod, dymod; int dxmod, dymod;
int ince, incne; int ince, incne;
@ -434,10 +367,10 @@ int32 DrawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) {
int x, y; int x, y;
int addTo; int addTo;
x1 -= scrollx; x1 -= _scrollX;
y1 -= scrolly; y1 -= _scrollY;
x0 -= scrollx; x0 -= _scrollX;
y0 -= scrolly; y0 -= _scrollY;
// Lock the surface if we're rendering to the back buffer. // Lock the surface if we're rendering to the back buffer.
@ -579,9 +512,8 @@ int32 DrawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) {
} }
} }
} }
return RD_OK;
} }
#endif
/** /**
* This function tells the driver the size of the background screen for the * This function tells the driver the size of the background screen for the
@ -590,11 +522,9 @@ int32 DrawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) {
* @param h height of the current location * @param h height of the current location
*/ */
int32 SetLocationMetrics(uint16 w, uint16 h) { void Display::setLocationMetrics(uint16 w, uint16 h) {
locationWide = w; _locationWide = w;
locationDeep = h; _locationDeep = h;
return RD_OK;
} }
/** /**
@ -602,45 +532,43 @@ int32 SetLocationMetrics(uint16 w, uint16 h) {
* parallax can be either foreground, background or the main screen. * parallax can be either foreground, background or the main screen.
*/ */
int32 RenderParallax(_parallax *p, int16 l) { void Display::renderParallax(_parallax *p, int16 l) {
int16 x, y; int16 x, y;
Common::Rect r; Common::Rect r;
if (locationWide == screenWide) if (_locationWide == _screenWide)
x = 0; x = 0;
else else
x = ((int32) ((p->w - screenWide) * scrollx) / (int32) (locationWide - screenWide)); x = ((int32) ((p->w - _screenWide) * _scrollX) / (int32) (_locationWide - _screenWide));
if (locationDeep == (screenDeep - MENUDEEP * 2)) if (_locationDeep == _screenDeep - MENUDEEP * 2)
y = 0; y = 0;
else else
y = ((int32) ((p->h - (screenDeep - MENUDEEP * 2)) * scrolly) / (int32) (locationDeep - (screenDeep - MENUDEEP * 2))); y = ((int32) ((p->h - (_screenDeep - MENUDEEP * 2)) * _scrollY) / (int32) (_locationDeep - (_screenDeep - MENUDEEP * 2)));
Common::Rect clip_rect; Common::Rect clip_rect;
// Leave enough space for the top and bottom menues // Leave enough space for the top and bottom menues
clip_rect.left = 0; clip_rect.left = 0;
clip_rect.right = screenWide; clip_rect.right = _screenWide;
clip_rect.top = MENUDEEP; clip_rect.top = MENUDEEP;
clip_rect.bottom = screenDeep - MENUDEEP; clip_rect.bottom = _screenDeep - MENUDEEP;
for (int j = 0; j < yblocks[l]; j++) { for (int j = 0; j < _yBlocks[l]; j++) {
for (int i = 0; i < xblocks[l]; i++) { for (int i = 0; i < _xBlocks[l]; i++) {
if (blockSurfaces[l][i + j * xblocks[l]]) { if (_blockSurfaces[l][i + j * _xBlocks[l]]) {
r.left = i * BLOCKWIDTH - x; r.left = i * BLOCKWIDTH - x;
r.right = r.left + BLOCKWIDTH; r.right = r.left + BLOCKWIDTH;
r.top = j * BLOCKHEIGHT - y + 40; r.top = j * BLOCKHEIGHT - y + 40;
r.bottom = r.top + BLOCKHEIGHT; r.bottom = r.top + BLOCKHEIGHT;
BlitBlockSurface(blockSurfaces[l][i + j * xblocks[l]], &r, &clip_rect); blitBlockSurface(_blockSurfaces[l][i + j * _xBlocks[l]], &r, &clip_rect);
} }
} }
} }
parallaxScrollx = scrollx - x; _parallaxScrollX = _scrollX - x;
parallaxScrolly = scrolly - y; _parallaxScrollY = _scrollY - y;
return RD_OK;
} }
// Uncomment this when benchmarking the drawing routines. // Uncomment this when benchmarking the drawing routines.
@ -650,10 +578,9 @@ int32 RenderParallax(_parallax *p, int16 l) {
* Initialises the timers before the render loop is entered. * Initialises the timers before the render loop is entered.
*/ */
int32 InitialiseRenderCycle(void) { void Display::initialiseRenderCycle(void) {
initialTime = SVM_timeGetTime(); _initialTime = SVM_timeGetTime();
totalTime = initialTime + MILLISECSPERCYCLE; _totalTime = _initialTime + MILLISECSPERCYCLE;
return RD_OK;
} }
/** /**
@ -661,24 +588,23 @@ int32 InitialiseRenderCycle(void) {
* render cycle. * render cycle.
*/ */
int32 StartRenderCycle(void) { void Display::startRenderCycle(void) {
scrollxOld = scrollx; _scrollXOld = _scrollX;
scrollyOld = scrolly; _scrollYOld = _scrollY;
startTime = SVM_timeGetTime(); _startTime = SVM_timeGetTime();
if (startTime + renderAverageTime >= totalTime) { if (_startTime + _renderAverageTime >= _totalTime) {
scrollx = scrollxTarget; _scrollX = _scrollXTarget;
scrolly = scrollyTarget; _scrollY = _scrollYTarget;
renderTooSlow = 1; _renderTooSlow = true;
} else { } else {
scrollx = (int16) (scrollxOld + ((scrollxTarget - scrollxOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime)); _scrollX = (int16) (_scrollXOld + ((_scrollXTarget - _scrollXOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
scrolly = (int16) (scrollyOld + ((scrollyTarget - scrollyOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime)); _scrollY = (int16) (_scrollYOld + ((_scrollYTarget - _scrollYOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
renderTooSlow = 0; _renderTooSlow = false;
} }
framesPerGameCycle = 0; _framesPerGameCycle = 0;
return RD_OK;
} }
/** /**
@ -687,52 +613,56 @@ int32 StartRenderCycle(void) {
* terminated, or false if it should continue * terminated, or false if it should continue
*/ */
int32 EndRenderCycle(bool *end) { bool Display::endRenderCycle(void) {
static int32 renderTimeLog[4] = { 60, 60, 60, 60 };
static int32 renderCountIndex = 0;
int32 time; int32 time;
time = SVM_timeGetTime(); time = SVM_timeGetTime();
renderTimeLog[renderCountIndex] = time - startTime; renderTimeLog[renderCountIndex] = time - _startTime;
startTime = time; _startTime = time;
renderAverageTime = (renderTimeLog[0] + renderTimeLog[1] + renderTimeLog[2] + renderTimeLog[3]) >> 2; _renderAverageTime = (renderTimeLog[0] + renderTimeLog[1] + renderTimeLog[2] + renderTimeLog[3]) >> 2;
framesPerGameCycle++; _framesPerGameCycle++;
if (++renderCountIndex == RENDERAVERAGETOTAL) if (++renderCountIndex == RENDERAVERAGETOTAL)
renderCountIndex = 0; renderCountIndex = 0;
if (renderTooSlow) { if (_renderTooSlow) {
*end = true; initialiseRenderCycle();
InitialiseRenderCycle(); return true;
} else if (startTime + renderAverageTime >= totalTime) {
*end = true;
totalTime += MILLISECSPERCYCLE;
initialTime = time;
#ifdef LIMIT_FRAME_RATE
} else if (scrollxTarget == scrollx && scrollyTarget == scrolly) {
// If we have already reached the scroll target sleep for the
// rest of the render cycle.
*end = true;
sleepUntil(totalTime);
initialTime = SVM_timeGetTime();
totalTime += MILLISECSPERCYCLE;
#endif
} else {
*end = false;
// This is an attempt to ensure that we always reach the scroll
// target. Otherwise the game frequently tries to pump out new
// interpolation frames without ever getting anywhere.
if (ABS(scrollx - scrollxTarget) <= 1 && ABS(scrolly - scrollyTarget) <= 1) {
scrollx = scrollxTarget;
scrolly = scrollyTarget;
} else {
scrollx = (int16) (scrollxOld + ((scrollxTarget - scrollxOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime));
scrolly = (int16) (scrollyOld + ((scrollyTarget - scrollyOld) * (startTime - initialTime + renderAverageTime)) / (totalTime - initialTime));
}
} }
return RD_OK; if (_startTime + _renderAverageTime >= _totalTime) {
_totalTime += MILLISECSPERCYCLE;
_initialTime = time;
return true;
}
#ifdef LIMIT_FRAME_RATE
if (_scrollXTarget == _scrollX && _scrollYTarget == _scrollY) {
// If we have already reached the scroll target sleep for the
// rest of the render cycle.
sleepUntil(_totalTime);
_initialTime = SVM_timeGetTime();
_totalTime += MILLISECSPERCYCLE;
return true;
}
#endif
// This is an attempt to ensure that we always reach the scroll target.
// Otherwise the game frequently tries to pump out new interpolation
// frames without ever getting anywhere.
if (ABS(_scrollX - _scrollXTarget) <= 1 && ABS(_scrollY - _scrollYTarget) <= 1) {
_scrollX = _scrollXTarget;
_scrollY = _scrollYTarget;
} else {
_scrollX = (int16) (_scrollXOld + ((_scrollXTarget - _scrollXOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
_scrollY = (int16) (_scrollYOld + ((_scrollYTarget - _scrollYOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
}
return false;
} }
/** /**
@ -741,11 +671,9 @@ int32 EndRenderCycle(bool *end) {
* position in the allotted time. * position in the allotted time.
*/ */
int32 SetScrollTarget(int16 sx, int16 sy) { void Display::setScrollTarget(int16 sx, int16 sy) {
scrollxTarget = sx; _scrollXTarget = sx;
scrollyTarget = sy; _scrollYTarget = sy;
return RD_OK;
} }
/** /**
@ -753,7 +681,7 @@ int32 SetScrollTarget(int16 sx, int16 sy) {
* or a NULL pointer in order of background parallax to foreground parallax. * or a NULL pointer in order of background parallax to foreground parallax.
*/ */
int32 InitialiseBackgroundLayer(_parallax *p) { int32 Display::initialiseBackgroundLayer(_parallax *p) {
uint8 *memchunk; uint8 *memchunk;
uint8 zeros; uint8 zeros;
uint16 count; uint16 count;
@ -764,29 +692,29 @@ int32 InitialiseBackgroundLayer(_parallax *p) {
_parallaxLine line; _parallaxLine line;
uint8 *pLine; uint8 *pLine;
debug(2, "InitialiseBackgroundLayer"); debug(2, "initialiseBackgroundLayer");
// This function is called to re-initialise the layers if they have // This function is called to re-initialise the layers if they have
// been lost. We know this if the layers have already been assigned. // been lost. We know this if the layers have already been assigned.
if (layer == MAXLAYERS) if (_layer == MAXLAYERS)
CloseBackgroundLayer(); closeBackgroundLayer();
if (!p) { if (!p) {
layer++; _layer++;
return RD_OK; return RD_OK;
} }
xblocks[layer] = (p->w + BLOCKWIDTH - 1) >> BLOCKWBITS; _xBlocks[_layer] = (p->w + BLOCKWIDTH - 1) >> BLOCKWBITS;
yblocks[layer] = (p->h + BLOCKHEIGHT - 1) >> BLOCKHBITS; _yBlocks[_layer] = (p->h + BLOCKHEIGHT - 1) >> BLOCKHBITS;
blockSurfaces[layer] = (BlockSurface **) calloc(xblocks[layer] * yblocks[layer], sizeof(BlockSurface *)); _blockSurfaces[_layer] = (BlockSurface **) calloc(_xBlocks[_layer] * _yBlocks[_layer], sizeof(BlockSurface *));
if (!blockSurfaces[layer]) if (!_blockSurfaces[_layer])
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
// Decode the parallax layer into a large chunk of memory // Decode the parallax layer into a large chunk of memory
memchunk = (uint8 *) malloc(xblocks[layer] * BLOCKWIDTH * yblocks[layer] * BLOCKHEIGHT); memchunk = (uint8 *) malloc(_xBlocks[_layer] * BLOCKWIDTH * _yBlocks[_layer] * BLOCKHEIGHT);
if (!memchunk) if (!memchunk)
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
@ -835,11 +763,11 @@ int32 InitialiseBackgroundLayer(_parallax *p) {
// Now create the surfaces! // Now create the surfaces!
for (i = 0; i < xblocks[layer] * yblocks[layer]; i++) { for (i = 0; i < _xBlocks[_layer] * _yBlocks[_layer]; i++) {
bool block_has_data = false; bool block_has_data = false;
bool block_is_transparent = false; bool block_is_transparent = false;
data = memchunk + (p->w * BLOCKHEIGHT * (i / xblocks[layer])) + BLOCKWIDTH * (i % xblocks[layer]); data = memchunk + (p->w * BLOCKHEIGHT * (i / _xBlocks[_layer])) + BLOCKWIDTH * (i % _xBlocks[_layer]);
for (j = 0; j < BLOCKHEIGHT; j++) { for (j = 0; j < BLOCKHEIGHT; j++) {
for (k = 0; k < BLOCKWIDTH; k++) { for (k = 0; k < BLOCKWIDTH; k++) {
@ -853,24 +781,24 @@ int32 InitialiseBackgroundLayer(_parallax *p) {
// Only assign a surface to the block if it contains data. // Only assign a surface to the block if it contains data.
if (block_has_data) { if (block_has_data) {
blockSurfaces[layer][i] = (BlockSurface *) malloc(sizeof(BlockSurface)); _blockSurfaces[_layer][i] = (BlockSurface *) malloc(sizeof(BlockSurface));
// Copy the data into the surfaces. // Copy the data into the surfaces.
dst = blockSurfaces[layer][i]->data; dst = _blockSurfaces[_layer][i]->data;
for (j = 0; j < BLOCKHEIGHT; j++) { for (j = 0; j < BLOCKHEIGHT; j++) {
memcpy(dst, data, BLOCKWIDTH); memcpy(dst, data, BLOCKWIDTH);
data += p->w; data += p->w;
dst += BLOCKWIDTH; dst += BLOCKWIDTH;
} }
blockSurfaces[layer][i]->transparent = block_is_transparent; _blockSurfaces[_layer][i]->transparent = block_is_transparent;
} else } else
blockSurfaces[layer][i] = NULL; _blockSurfaces[_layer][i] = NULL;
} }
free(memchunk); free(memchunk);
layer++; _layer++;
return RD_OK; return RD_OK;
} }
@ -879,21 +807,20 @@ int32 InitialiseBackgroundLayer(_parallax *p) {
* Should be called once after leaving the room to free up memory. * Should be called once after leaving the room to free up memory.
*/ */
int32 CloseBackgroundLayer(void) { void Display::closeBackgroundLayer(void) {
debug(2, "CloseBackgroundLayer"); debug(2, "CloseBackgroundLayer");
for (int j = 0; j < MAXLAYERS; j++) { for (int j = 0; j < MAXLAYERS; j++) {
if (blockSurfaces[j]) { if (_blockSurfaces[j]) {
for (int i = 0; i < xblocks[j] * yblocks[j]; i++) for (int i = 0; i < _xBlocks[j] * _yBlocks[j]; i++)
if (blockSurfaces[j][i]) if (_blockSurfaces[j][i])
free(blockSurfaces[j][i]); free(_blockSurfaces[j][i]);
free(blockSurfaces[j]); free(_blockSurfaces[j]);
blockSurfaces[j] = NULL; _blockSurfaces[j] = NULL;
} }
} }
layer = 0; _layer = 0;
return RD_OK;
} }
} // End of namespace Sword2 } // End of namespace Sword2

View File

@ -33,20 +33,6 @@ typedef struct {
uint16 offset; uint16 offset;
} _parallaxLine; } _parallaxLine;
extern int16 scrollx; // current x offset into background of display
extern int16 scrolly; // current y offset into background of display
extern int16 parallaxScrollx; // current x offset to link a sprite to the
// parallax layer
extern int16 parallaxScrolly; // current y offset to link a sprite to the
// parallax layer
extern int16 locationWide;
extern int16 locationDeep;
void SquashImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf);
void StretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf);
void UploadRect(Common::Rect *r);
} // End of namespace Sword2 } // End of namespace Sword2
#endif #endif

View File

@ -27,8 +27,6 @@
namespace Sword2 { namespace Sword2 {
static uint8 *lightMask = 0;
/** /**
* This function takes a sprite and creates a mirror image of it. * This function takes a sprite and creates a mirror image of it.
* @param dst destination buffer * @param dst destination buffer
@ -37,17 +35,13 @@ static uint8 *lightMask = 0;
* @param h height of the sprite * @param h height of the sprite
*/ */
int32 MirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h) { void Display::mirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h) {
int16 x, y; for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
*dst++ = *(src + w - x - 1); *dst++ = *(src + w - x - 1);
} }
src += w; src += w;
} }
return RD_OK;
} }
/** /**
@ -58,7 +52,7 @@ int32 MirrorSprite(uint8 *dst, uint8 *src, int16 w, int16 h) {
* @param decompSize the expected size of the decompressed sprite * @param decompSize the expected size of the decompressed sprite
*/ */
int32 DecompressRLE256(uint8 *dest, uint8 *source, int32 decompSize) { int32 Display::decompressRLE256(uint8 *dest, uint8 *source, int32 decompSize) {
// PARAMETERS: // PARAMETERS:
// source points to the start of the sprite data for input // source points to the start of the sprite data for input
// decompSize gives size of decompressed data in bytes // decompSize gives size of decompressed data in bytes
@ -138,7 +132,7 @@ int32 DecompressRLE256(uint8 *dest, uint8 *source, int32 decompSize) {
* Unwinds a run of 16-colour data into 256-colour palette data. * Unwinds a run of 16-colour data into 256-colour palette data.
*/ */
void UnwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable) { void Display::unwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable) {
// for each pair of pixels // for each pair of pixels
while (blockSize > 1) { while (blockSize > 1) {
// 1st colour = number in table at position given by upper // 1st colour = number in table at position given by upper
@ -173,7 +167,7 @@ void UnwindRaw16(uint8 *dest, uint8 *source, uint8 blockSize, uint8 *colTable) {
* @param colTable mapping from the 16 encoded colours to the current palette * @param colTable mapping from the 16 encoded colours to the current palette
*/ */
int32 DecompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable) { int32 Display::decompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTable) {
uint8 headerByte; // block header byte uint8 headerByte; // block header byte
uint8 *endDest = dest + decompSize; // pointer to byte after end of decomp buffer uint8 *endDest = dest + decompSize; // pointer to byte after end of decomp buffer
int32 rv; int32 rv;
@ -223,7 +217,7 @@ int32 DecompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTa
// copy the next 'headerByte' pixels from source to // copy the next 'headerByte' pixels from source to
// destination (NB. 2 pixels per byte) // destination (NB. 2 pixels per byte)
UnwindRaw16(dest, source, headerByte, colTable); unwindRaw16(dest, source, headerByte, colTable);
// increment destination pointer to just after this // increment destination pointer to just after this
// block // block
@ -253,7 +247,7 @@ int32 DecompressRLE16(uint8 *dest, uint8 *source, int32 decompSize, uint8 *colTa
* @return RD_OK, or an error code * @return RD_OK, or an error code
*/ */
int32 CreateSurface(_spriteInfo *s, uint8 **sprite) { int32 Display::createSurface(_spriteInfo *s, uint8 **sprite) {
uint8 *newSprite; uint8 *newSprite;
*sprite = (uint8 *) malloc(s->w * s->h); *sprite = (uint8 *) malloc(s->w * s->h);
@ -264,12 +258,12 @@ int32 CreateSurface(_spriteInfo *s, uint8 **sprite) {
memcpy(*sprite, s->data, s->w * s->h); memcpy(*sprite, s->data, s->w * s->h);
} else { } else {
if ((s->type >> 8) == (RDSPR_RLE16 >> 8)) { if ((s->type >> 8) == (RDSPR_RLE16 >> 8)) {
if (DecompressRLE16(*sprite, s->data, s->w * s->h, s->colourTable)) { if (decompressRLE16(*sprite, s->data, s->w * s->h, s->colourTable)) {
free(*sprite); free(*sprite);
return RDERR_DECOMPRESSION; return RDERR_DECOMPRESSION;
} }
} else { } else {
if (DecompressRLE256(*sprite, s->data, s->w * s->h)) { if (decompressRLE256(*sprite, s->data, s->w * s->h)) {
free(*sprite); free(*sprite);
return RDERR_DECOMPRESSION; return RDERR_DECOMPRESSION;
} }
@ -281,7 +275,7 @@ int32 CreateSurface(_spriteInfo *s, uint8 **sprite) {
free(*sprite); free(*sprite);
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
} }
MirrorSprite(newSprite, *sprite, s->w, s->h); mirrorSprite(newSprite, *sprite, s->w, s->h);
free(*sprite); free(*sprite);
*sprite = newSprite; *sprite = newSprite;
} }
@ -297,7 +291,7 @@ int32 CreateSurface(_spriteInfo *s, uint8 **sprite) {
* @param clipRect the clipping rectangle * @param clipRect the clipping rectangle
*/ */
void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) { void Display::drawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) {
Common::Rect rd, rs; Common::Rect rd, rs;
uint16 x, y, srcPitch; uint16 x, y, srcPitch;
uint8 *src, *dst; uint8 *src, *dst;
@ -313,8 +307,8 @@ void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) {
rd.top = s->y; rd.top = s->y;
rd.left = s->x; rd.left = s->x;
} else { } else {
rd.top = s->y - scrolly; rd.top = s->y - _scrollY;
rd.left = s->x - scrollx; rd.left = s->x - _scrollX;
} }
rd.right = rd.left + rs.right; rd.right = rd.left + rs.right;
@ -344,7 +338,7 @@ void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) {
} }
src = surface + rs.top * srcPitch + rs.left; src = surface + rs.top * srcPitch + rs.left;
dst = lpBackBuffer + screenWide * rd.top + rd.left; dst = _buffer + _screenWide * rd.top + rd.left;
// Surfaces are always transparent. // Surfaces are always transparent.
@ -354,18 +348,18 @@ void DrawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect) {
dst[x] = src[x]; dst[x] = src[x];
} }
src += srcPitch; src += srcPitch;
dst += screenWide; dst += _screenWide;
} }
UploadRect(&rd); updateRect(&rd);
SetNeedRedraw(); setNeedFullRedraw();
} }
/** /**
* Destroys a surface. * Destroys a surface.
*/ */
void DeleteSurface(uint8 *surface) { void Display::deleteSurface(uint8 *surface) {
free(surface); free(surface);
} }
@ -390,7 +384,7 @@ void DeleteSurface(uint8 *surface) {
// FIXME: I'm sure this could be optimized. There's plenty of data copying and // FIXME: I'm sure this could be optimized. There's plenty of data copying and
// mallocing here. // mallocing here.
int32 DrawSprite(_spriteInfo *s) { int32 Display::drawSprite(_spriteInfo *s) {
uint8 *src, *dst; uint8 *src, *dst;
uint8 *sprite, *newSprite; uint8 *sprite, *newSprite;
uint8 *backbuf = NULL; uint8 *backbuf = NULL;
@ -414,12 +408,12 @@ int32 DrawSprite(_spriteInfo *s) {
if (!sprite) if (!sprite)
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
if ((s->type >> 8) == (RDSPR_RLE16 >> 8)) { if ((s->type >> 8) == (RDSPR_RLE16 >> 8)) {
if (DecompressRLE16(sprite, s->data, s->w * s->h, s->colourTable)) { if (decompressRLE16(sprite, s->data, s->w * s->h, s->colourTable)) {
free(sprite); free(sprite);
return RDERR_DECOMPRESSION; return RDERR_DECOMPRESSION;
} }
} else { } else {
if (DecompressRLE256(sprite, s->data, s->w * s->h)) { if (decompressRLE256(sprite, s->data, s->w * s->h)) {
free(sprite); free(sprite);
return RDERR_DECOMPRESSION; return RDERR_DECOMPRESSION;
} }
@ -433,7 +427,7 @@ int32 DrawSprite(_spriteInfo *s) {
free(sprite); free(sprite);
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
} }
MirrorSprite(newSprite, sprite, s->w, s->h); mirrorSprite(newSprite, sprite, s->w, s->h);
if (freeSprite) if (freeSprite)
free(sprite); free(sprite);
sprite = newSprite; sprite = newSprite;
@ -445,8 +439,8 @@ int32 DrawSprite(_spriteInfo *s) {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
if (!(s->type & RDSPR_DISPLAYALIGN)) { if (!(s->type & RDSPR_DISPLAYALIGN)) {
s->x += parallaxScrollx; s->x += _parallaxScrollX;
s->y += parallaxScrolly; s->y += _parallaxScrollY;
} }
s->y += 40; s->y += 40;
@ -474,8 +468,8 @@ int32 DrawSprite(_spriteInfo *s) {
rd.left = s->x; rd.left = s->x;
if (!(s->type & RDSPR_DISPLAYALIGN)) { if (!(s->type & RDSPR_DISPLAYALIGN)) {
rd.top -= scrolly; rd.top -= _scrollY;
rd.left -= scrollx; rd.left -= _scrollX;
} }
rd.right = rd.left + rs.right; rd.right = rd.left + rs.right;
@ -515,8 +509,8 @@ int32 DrawSprite(_spriteInfo *s) {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
if (scale != 256) { if (scale != 256) {
if ((renderCaps & RDBLTFX_ARITHMETICSTRETCH) && !clipped) if ((_renderCaps & RDBLTFX_EDGEBLEND) && !clipped)
backbuf = lpBackBuffer + screenWide * rd.top + rd.left; backbuf = _buffer + _screenWide * rd.top + rd.left;
if (s->scaledWidth > SCALE_MAXWIDTH || s->scaledHeight > SCALE_MAXHEIGHT) { if (s->scaledWidth > SCALE_MAXWIDTH || s->scaledHeight > SCALE_MAXHEIGHT) {
@ -533,14 +527,14 @@ int32 DrawSprite(_spriteInfo *s) {
} }
if (scale < 256) { if (scale < 256) {
SquashImage(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, backbuf); squashImage(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, backbuf);
} else { } else {
if (s->scale > 512) { if (s->scale > 512) {
if (freeSprite) if (freeSprite)
free(sprite); free(sprite);
return RDERR_INVALIDSCALING; return RDERR_INVALIDSCALING;
} }
StretchImage(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, backbuf); stretchImage(newSprite, s->scaledWidth, s->scaledWidth, s->scaledHeight, sprite, s->w, s->w, s->h, backbuf);
} }
if (freeSprite) if (freeSprite)
@ -557,7 +551,7 @@ int32 DrawSprite(_spriteInfo *s) {
// and which is used to simulate light and shadows. Scaled sprites // and which is used to simulate light and shadows. Scaled sprites
// (actors, presumably) are always affected. // (actors, presumably) are always affected.
if ((renderCaps & RDBLTFX_SHADOWBLEND) && lightMask && (scale != 256 || (s->type & RDSPR_SHADOW))) { if ((_renderCaps & RDBLTFX_SHADOWBLEND) && _lightMask && (scale != 256 || (s->type & RDSPR_SHADOW))) {
uint8 *lightMap; uint8 *lightMap;
if (!freeSprite) { if (!freeSprite) {
@ -568,19 +562,19 @@ int32 DrawSprite(_spriteInfo *s) {
} }
src = sprite + rs.top * srcPitch + rs.left; src = sprite + rs.top * srcPitch + rs.left;
lightMap = lightMask + (rd.top + scrolly - 40) * locationWide + rd.left + scrollx; lightMap = _lightMask + (rd.top + _scrollY - 40) * _locationWide + rd.left + _scrollX;
for (i = 0; i < rs.height(); i++) { for (i = 0; i < rs.height(); i++) {
for (j = 0; j < rs.width(); j++) { for (j = 0; j < rs.width(); j++) {
if (src[j] && lightMap[j]) { if (src[j] && lightMap[j]) {
uint8 r = ((32 - lightMap[j]) * palCopy[src[j]][0]) >> 5; uint8 r = ((32 - lightMap[j]) * _palCopy[src[j]][0]) >> 5;
uint8 g = ((32 - lightMap[j]) * palCopy[src[j]][1]) >> 5; uint8 g = ((32 - lightMap[j]) * _palCopy[src[j]][1]) >> 5;
uint8 b = ((32 - lightMap[j]) * palCopy[src[j]][2]) >> 5; uint8 b = ((32 - lightMap[j]) * _palCopy[src[j]][2]) >> 5;
src[j] = QuickMatch(r, g, b); src[j] = quickMatch(r, g, b);
} }
} }
src += srcPitch; src += srcPitch;
lightMap += locationWide; lightMap += _locationWide;
} }
} }
@ -589,17 +583,17 @@ int32 DrawSprite(_spriteInfo *s) {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
src = sprite + rs.top * srcPitch + rs.left; src = sprite + rs.top * srcPitch + rs.left;
dst = lpBackBuffer + screenWide * rd.top + rd.left; dst = _buffer + _screenWide * rd.top + rd.left;
if (s->type & RDSPR_BLEND) { if (s->type & RDSPR_BLEND) {
if (renderCaps & RDBLTFX_ALLHARDWARE) { if (!(_renderCaps & RDBLTFX_SPRITEBLEND)) {
for (i = 0; i < rs.height(); i++) { for (i = 0; i < rs.height(); i++) {
for (j = 0; j < rs.width(); j++) { for (j = 0; j < rs.width(); j++) {
if (src[j] && ((i & 1) == (j & 1))) if (src[j] && ((i & 1) == (j & 1)))
dst[j] = src[j]; dst[j] = src[j];
} }
src += srcPitch; src += srcPitch;
dst += screenWide; dst += _screenWide;
} }
} else { } else {
if (s->blend & 0x01) { if (s->blend & 0x01) {
@ -607,14 +601,14 @@ int32 DrawSprite(_spriteInfo *s) {
for (i = 0; i < rs.height(); i++) { for (i = 0; i < rs.height(); i++) {
for (j = 0; j < rs.width(); j++) { for (j = 0; j < rs.width(); j++) {
if (src[j]) { if (src[j]) {
uint8 r = (palCopy[src[j]][0] * red + palCopy[dst[j]][0] * (8 - red)) >> 3; uint8 r = (_palCopy[src[j]][0] * red + _palCopy[dst[j]][0] * (8 - red)) >> 3;
uint8 g = (palCopy[src[j]][1] * red + palCopy[dst[j]][1] * (8 - red)) >> 3; uint8 g = (_palCopy[src[j]][1] * red + _palCopy[dst[j]][1] * (8 - red)) >> 3;
uint8 b = (palCopy[src[j]][2] * red + palCopy[dst[j]][2] * (8 - red)) >> 3; uint8 b = (_palCopy[src[j]][2] * red + _palCopy[dst[j]][2] * (8 - red)) >> 3;
dst[j] = QuickMatch(r, g, b); dst[j] = quickMatch(r, g, b);
} }
} }
src += srcPitch; src += srcPitch;
dst += screenWide; dst += _screenWide;
} }
} else if (s->blend & 0x02) { } else if (s->blend & 0x02) {
debug(2, "DrawSprite: s->blend & 0x02"); debug(2, "DrawSprite: s->blend & 0x02");
@ -631,20 +625,20 @@ int32 DrawSprite(_spriteInfo *s) {
// Does anyone know where this case was used // Does anyone know where this case was used
// anyway? // anyway?
red = palCopy[s->blend >> 8][0]; red = _palCopy[s->blend >> 8][0];
green = palCopy[s->blend >> 8][0]; green = _palCopy[s->blend >> 8][0];
blue = palCopy[s->blend >> 8][0]; blue = _palCopy[s->blend >> 8][0];
for (i = 0; i < rs.height(); i++) { for (i = 0; i < rs.height(); i++) {
for (j = 0; j < rs.width(); j++) { for (j = 0; j < rs.width(); j++) {
if (src[j]) { if (src[j]) {
uint8 r = (src[j] * red + (16 - src[j]) * palCopy[dst[j]][0]) >> 4; uint8 r = (src[j] * red + (16 - src[j]) * _palCopy[dst[j]][0]) >> 4;
uint8 g = (src[j] * green + (16 - src[j]) * palCopy[dst[j]][1]) >> 4; uint8 g = (src[j] * green + (16 - src[j]) * _palCopy[dst[j]][1]) >> 4;
uint8 b = (src[j] * blue + (16 - src[j]) * palCopy[dst[j]][2]) >> 4; uint8 b = (src[j] * blue + (16 - src[j]) * _palCopy[dst[j]][2]) >> 4;
dst[j] = QuickMatch(r, g, b); dst[j] = quickMatch(r, g, b);
} }
} }
src += srcPitch; src += srcPitch;
dst += screenWide; dst += _screenWide;
} }
} else { } else {
warning("DrawSprite: Invalid blended sprite"); warning("DrawSprite: Invalid blended sprite");
@ -661,13 +655,13 @@ int32 DrawSprite(_spriteInfo *s) {
dst[j] = src[j]; dst[j] = src[j];
} }
src += srcPitch; src += srcPitch;
dst += screenWide; dst += _screenWide;
} }
} else { } else {
for (i = 0; i < rs.height(); i++) { for (i = 0; i < rs.height(); i++) {
memcpy(dst, src, rs.width()); memcpy(dst, src, rs.width());
src += srcPitch; src += srcPitch;
dst += screenWide; dst += _screenWide;
} }
} }
} }
@ -675,8 +669,8 @@ int32 DrawSprite(_spriteInfo *s) {
if (freeSprite) if (freeSprite)
free(sprite); free(sprite);
// UploadRect(&rd); // updateRect(&rd);
SetNeedRedraw(); setNeedFullRedraw();
return RD_OK; return RD_OK;
} }
@ -685,20 +679,20 @@ int32 DrawSprite(_spriteInfo *s) {
* Opens the light masking sprite for a room. * Opens the light masking sprite for a room.
*/ */
int32 OpenLightMask(_spriteInfo *s) { int32 Display::openLightMask(_spriteInfo *s) {
// FIXME: The light mask is only needed on higher graphics detail // FIXME: The light mask is only needed on higher graphics detail
// settings, so to save memory we could simply ignore it on lower // settings, so to save memory we could simply ignore it on lower
// settings. But then we need to figure out how to ensure that it // settings. But then we need to figure out how to ensure that it
// is properly loaded if the user changes the settings in mid-game. // is properly loaded if the user changes the settings in mid-game.
if (lightMask) if (_lightMask)
return RDERR_NOTCLOSED; return RDERR_NOTCLOSED;
lightMask = (uint8 *) malloc(s->w * s->h); _lightMask = (uint8 *) malloc(s->w * s->h);
if (!lightMask) if (!_lightMask)
return RDERR_OUTOFMEMORY; return RDERR_OUTOFMEMORY;
if (DecompressRLE256(lightMask, s->data, s->w * s->h)) if (decompressRLE256(_lightMask, s->data, s->w * s->h))
return RDERR_DECOMPRESSION; return RDERR_DECOMPRESSION;
return RD_OK; return RD_OK;
@ -708,12 +702,12 @@ int32 OpenLightMask(_spriteInfo *s) {
* Closes the light masking sprite for a room. * Closes the light masking sprite for a room.
*/ */
int32 CloseLightMask(void) { int32 Display::closeLightMask(void) {
if (!lightMask) if (!_lightMask)
return RDERR_NOTOPEN; return RDERR_NOTOPEN;
free(lightMask); free(_lightMask);
lightMask = 0; _lightMask = NULL;
return RD_OK; return RD_OK;
} }

View File

@ -31,7 +31,7 @@
#include "bs2/protocol.h" #include "bs2/protocol.h"
#include "bs2/resman.h" #include "bs2/resman.h"
#include "bs2/sound.h" #include "bs2/sound.h"
#include "bs2/sword2.h" // for CloseGame() #include "bs2/sword2.h"
namespace Sword2 { namespace Sword2 {
@ -269,25 +269,25 @@ int32 FN_flash(int32 *params) {
// what colour? // what colour?
switch (params[0]) { switch (params[0]) {
case WHITE: case WHITE:
BS2_SetPalette(0, 1, white, RDPAL_INSTANT); g_display->setPalette(0, 1, white, RDPAL_INSTANT);
break; break;
case RED: case RED:
BS2_SetPalette(0, 1, red, RDPAL_INSTANT); g_display->setPalette(0, 1, red, RDPAL_INSTANT);
break; break;
case GREEN: case GREEN:
BS2_SetPalette(0, 1, green, RDPAL_INSTANT); g_display->setPalette(0, 1, green, RDPAL_INSTANT);
break; break;
case BLUE: case BLUE:
BS2_SetPalette(0, 1, blue, RDPAL_INSTANT); g_display->setPalette(0, 1, blue, RDPAL_INSTANT);
break; break;
} }
// There used to be a busy-wait loop here, so I don't know how long // There used to be a busy-wait loop here, so I don't know how long
// the delay was meant to be. Probably doesn't matter much. // the delay was meant to be. Probably doesn't matter much.
ServiceWindows(); g_display->updateDisplay();
g_system->delay_msecs(250); g_system->delay_msecs(250);
BS2_SetPalette(0, 1, black, RDPAL_INSTANT); g_display->setPalette(0, 1, black, RDPAL_INSTANT);
#endif #endif
return IR_CONT; return IR_CONT;
@ -305,19 +305,19 @@ int32 FN_colour(int32 *params) {
// what colour? // what colour?
switch (params[0]) { switch (params[0]) {
case BLACK: case BLACK:
BS2_SetPalette(0, 1, black, RDPAL_INSTANT); g_display->setPalette(0, 1, black, RDPAL_INSTANT);
break; break;
case WHITE: case WHITE:
BS2_SetPalette(0, 1, white, RDPAL_INSTANT); g_display->setPalette(0, 1, white, RDPAL_INSTANT);
break; break;
case RED: case RED:
BS2_SetPalette(0, 1, red, RDPAL_INSTANT); g_display->setPalette(0, 1, red, RDPAL_INSTANT);
break; break;
case GREEN: case GREEN:
BS2_SetPalette(0, 1, green, RDPAL_INSTANT); g_display->setPalette(0, 1, green, RDPAL_INSTANT);
break; break;
case BLUE: case BLUE:
BS2_SetPalette(0, 1, blue, RDPAL_INSTANT); g_display->setPalette(0, 1, blue, RDPAL_INSTANT);
break; break;
} }
#endif #endif
@ -396,17 +396,17 @@ int32 FN_play_credits(int32 *params) {
g_sound->muteSpeech(1); g_sound->muteSpeech(1);
g_sound->stopMusic(); g_sound->stopMusic();
memcpy(oldPal, palCopy, 1024); memcpy(oldPal, g_display->_palCopy, 1024);
memset(tmpPal, 0, 1024); memset(tmpPal, 0, 1024);
WaitForFade(); g_display->waitForFade();
FadeDown(0.75); g_display->fadeDown();
WaitForFade(); g_display->waitForFade();
tmpPal[4] = 255; tmpPal[4] = 255;
tmpPal[5] = 255; tmpPal[5] = 255;
tmpPal[6] = 255; tmpPal[6] = 255;
BS2_SetPalette(0, 256, tmpPal, RDPAL_INSTANT); g_display->setPalette(0, 256, tmpPal, RDPAL_INSTANT);
// Play the credits music. Is it enough with just one // Play the credits music. Is it enough with just one
// repetition of it? // repetition of it?
@ -419,17 +419,17 @@ int32 FN_play_credits(int32 *params) {
debug(0, "Credits music length: ~%d ms", music_length); debug(0, "Credits music length: ~%d ms", music_length);
CloseMenuImmediately(); g_display->closeMenuImmediately();
while (g_sound->musicTimeRemaining()) { while (g_sound->musicTimeRemaining()) {
EraseBackBuffer(); g_display->clearScene();
SetNeedRedraw(); g_display->setNeedFullRedraw();
// FIXME: Draw the credits text. The actual text // FIXME: Draw the credits text. The actual text
// messages are stored in credits.clu, and I'm guessing // messages are stored in credits.clu, and I'm guessing
// that credits.bmp or font.clu may be the font. // that credits.bmp or font.clu may be the font.
ServiceWindows(); g_display->updateDisplay();
_keyboardEvent ke; _keyboardEvent ke;
@ -442,11 +442,11 @@ int32 FN_play_credits(int32 *params) {
FN_stop_music(NULL); FN_stop_music(NULL);
g_sound->restoreMusicState(); g_sound->restoreMusicState();
BS2_SetPalette(0, 256, oldPal, RDPAL_FADE); g_display->setPalette(0, 256, oldPal, RDPAL_FADE);
FadeUp(0.75); g_display->fadeUp();
ServiceWindows(); g_display->updateDisplay();
Build_display(); Build_display();
WaitForFade(); g_display->waitForFade();
g_sound->muteFx(0); g_sound->muteFx(0);
g_sound->muteSpeech(0); g_sound->muteSpeech(0);
@ -457,7 +457,6 @@ int32 FN_play_credits(int32 *params) {
if (g_sword2->_gameId == GID_SWORD2_DEMO) { if (g_sword2->_gameId == GID_SWORD2_DEMO) {
Close_game(); // close engine systems down Close_game(); // close engine systems down
CloseAppWindow();
exit(0); // quit the game exit(0); // quit the game
} }

View File

@ -18,6 +18,7 @@
*/ */
#include "stdafx.h" #include "stdafx.h"
#include "bs2/sword2.h"
#include "bs2/driver/driver96.h" #include "bs2/driver/driver96.h"
#include "bs2/defs.h" #include "bs2/defs.h"
#include "bs2/icons.h" #include "bs2/icons.h"
@ -207,23 +208,22 @@ void Build_menu(void) {
if (icon_coloured) if (icon_coloured)
icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP);
SetMenuIcon(RDMENU_BOTTOM, j, icon); g_display->setMenuIcon(RDMENU_BOTTOM, j, icon);
res_man.close(res); res_man.close(res);
} else { } else {
// no icon here // no icon here
SetMenuIcon(RDMENU_BOTTOM, j, NULL); g_display->setMenuIcon(RDMENU_BOTTOM, j, NULL);
debug(5, " NULL for %d", j); debug(5, " NULL for %d", j);
} }
} }
ShowMenu(RDMENU_BOTTOM); g_display->showMenu(RDMENU_BOTTOM);
} }
void Build_system_menu(void) { void Build_system_menu(void) {
// start a fresh top system menu // start a fresh top system menu
uint8 *icon; uint8 *icon;
int j;
uint32 icon_list[5] = { uint32 icon_list[5] = {
OPTIONS_ICON, OPTIONS_ICON,
@ -236,7 +236,7 @@ void Build_system_menu(void) {
// build them all high in full colour - when one is clicked on all the // build them all high in full colour - when one is clicked on all the
// rest will grey out // rest will grey out
for (j = 0; j < ARRAYSIZE(icon_list); j++) { for (int j = 0; j < ARRAYSIZE(icon_list); j++) {
icon = res_man.open(icon_list[j]) + sizeof(_standardHeader); icon = res_man.open(icon_list[j]) + sizeof(_standardHeader);
// The only case when an icon is grayed is when the player // The only case when an icon is grayed is when the player
@ -245,11 +245,11 @@ void Build_system_menu(void) {
if (!DEAD || icon_list[j] != SAVE_ICON) if (!DEAD || icon_list[j] != SAVE_ICON)
icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP);
SetMenuIcon(RDMENU_TOP, j, icon); g_display->setMenuIcon(RDMENU_TOP, j, icon);
res_man.close(icon_list[j]); res_man.close(icon_list[j]);
} }
ShowMenu(RDMENU_TOP); g_display->showMenu(RDMENU_TOP);
} }
} // End of namespace Sword2 } // End of namespace Sword2

View File

@ -26,6 +26,7 @@
// up to 2 foreground parallax layers // up to 2 foreground parallax layers
#include "stdafx.h" #include "stdafx.h"
#include "bs2/sword2.h"
#include "bs2/build_display.h" #include "bs2/build_display.h"
#include "bs2/debug.h" #include "bs2/debug.h"
#include "bs2/header.h" #include "bs2/header.h"
@ -67,11 +68,11 @@ int32 FN_init_background(int32 *params) {
#endif #endif
// if the screen is still fading down then wait for black // if the screen is still fading down then wait for black
WaitForFade(); g_display->waitForFade();
// if last screen was using a shading mask (see below) // if last screen was using a shading mask (see below)
if (this_screen.mask_flag) { if (this_screen.mask_flag) {
rv = CloseLightMask(); rv = g_display->closeLightMask();
if (rv) if (rv)
error("Driver Error %.8x", rv); error("Driver Error %.8x", rv);
} }
@ -80,7 +81,7 @@ int32 FN_init_background(int32 *params) {
// for drivers: close the previous screen if one is open // for drivers: close the previous screen if one is open
if (this_screen.background_layer_id) if (this_screen.background_layer_id)
CloseBackgroundLayer(); g_display->closeBackgroundLayer();
this_screen.background_layer_id = params[0]; // set the res id this_screen.background_layer_id = params[0]; // set the res id
this_screen.new_palette = params[1]; // yes or no - palette is taken from layer file this_screen.new_palette = params[1]; // yes or no - palette is taken from layer file
@ -102,7 +103,7 @@ int32 FN_init_background(int32 *params) {
debug(5, "res test layers=%d width=%d depth=%d", screen_head->noLayers, screen_head->width, screen_head->height); debug(5, "res test layers=%d width=%d depth=%d", screen_head->noLayers, screen_head->width, screen_head->height);
//initialise the driver back buffer //initialise the driver back buffer
SetLocationMetrics(screen_head->width, screen_head->height); g_display->setLocationMetrics(screen_head->width, screen_head->height);
if (screen_head->noLayers) { if (screen_head->noLayers) {
for (int i = 0; i < screen_head->noLayers; i++) { for (int i = 0; i < screen_head->noLayers; i++) {
@ -124,7 +125,7 @@ int32 FN_init_background(int32 *params) {
// using the screen size setup the scrolling variables // using the screen size setup the scrolling variables
// if layer is larger than physical screen // if layer is larger than physical screen
if (screen_head->width > screenWide || screen_head->height > screenDeep) { if (screen_head->width > g_display->_screenWide || screen_head->height > g_display->_screenDeep) {
// switch on scrolling (2 means first time on screen) // switch on scrolling (2 means first time on screen)
this_screen.scroll_flag = 2; this_screen.scroll_flag = 2;
@ -139,9 +140,9 @@ int32 FN_init_background(int32 *params) {
// calc max allowed offsets (to prevent scrolling off edge) - // calc max allowed offsets (to prevent scrolling off edge) -
// MOVE TO NEW_SCREEN in GTM_CORE.C !! // MOVE TO NEW_SCREEN in GTM_CORE.C !!
// NB. min scroll offsets are both zero // NB. min scroll offsets are both zero
this_screen.max_scroll_offset_x = screen_head->width-screenWide; this_screen.max_scroll_offset_x = screen_head->width - g_display->_screenWide;
// 'screenDeep' includes the menu's, so take away 80 pixels // 'screenDeep' includes the menu's, so take away 80 pixels
this_screen.max_scroll_offset_y = screen_head->height - (screenDeep - (RDMENU_MENUDEEP * 2)); this_screen.max_scroll_offset_y = screen_head->height - (g_display->_screenDeep - (RDMENU_MENUDEEP * 2));
} else { } else {
// layer fits on physical screen - scrolling not required // layer fits on physical screen - scrolling not required
this_screen.scroll_flag = 0; // switch off scrolling this_screen.scroll_flag = 0; // switch off scrolling
@ -151,7 +152,7 @@ int32 FN_init_background(int32 *params) {
// no inter-cycle scroll between new screens (see setScrollTarget in // no inter-cycle scroll between new screens (see setScrollTarget in
// build display) // build display)
ResetRenderEngine(); g_display->resetRenderEngine();
// these are the physical screen coords where the system // these are the physical screen coords where the system
// will try to maintain George's actual feet coords // will try to maintain George's actual feet coords
@ -175,7 +176,7 @@ int32 FN_init_background(int32 *params) {
spriteInfo.data = FetchShadingMask(file); spriteInfo.data = FetchShadingMask(file);
spriteInfo.colourTable = 0; spriteInfo.colourTable = 0;
rv = OpenLightMask(&spriteInfo); rv = g_display->openLightMask(&spriteInfo);
if (rv) if (rv)
error("Driver Error %.8x", rv); error("Driver Error %.8x", rv);
@ -219,22 +220,22 @@ void SetUpBackgroundLayers(void) {
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (screenLayerTable->bg_parallax[i]) if (screenLayerTable->bg_parallax[i])
InitialiseBackgroundLayer(FetchBackgroundParallaxLayer(file, i)); g_display->initialiseBackgroundLayer(FetchBackgroundParallaxLayer(file, i));
else else
InitialiseBackgroundLayer(NULL); g_display->initialiseBackgroundLayer(NULL);
} }
// Normal backround layer // Normal backround layer
InitialiseBackgroundLayer(FetchBackgroundLayer(file)); g_display->initialiseBackgroundLayer(FetchBackgroundLayer(file));
// Foreground parallax layers // Foreground parallax layers
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (screenLayerTable->fg_parallax[i]) if (screenLayerTable->fg_parallax[i])
InitialiseBackgroundLayer(FetchForegroundParallaxLayer(file, i)); g_display->initialiseBackgroundLayer(FetchForegroundParallaxLayer(file, i));
else else
InitialiseBackgroundLayer(NULL); g_display->initialiseBackgroundLayer(NULL);
} }
// close the screen file // close the screen file

View File

@ -18,6 +18,7 @@
*/ */
#include "stdafx.h" #include "stdafx.h"
#include "bs2/sword2.h"
#include "bs2/build_display.h" #include "bs2/build_display.h"
#include "bs2/console.h" #include "bs2/console.h"
#include "bs2/debug.h" #include "bs2/debug.h"
@ -347,8 +348,8 @@ uint32 logic::examineRunList(void) {
Build_display(); Build_display();
do { do {
ServiceWindows(); g_display->updateDisplay();
} while(!KeyWaiting()); } while (!KeyWaiting());
// kill the key we just pressed // kill the key we just pressed
ReadKey(&ke); ReadKey(&ke);

View File

@ -525,7 +525,7 @@ void FontRenderer::printTextBlocs(void) {
spriteInfo.data = _blocList[j].text_mem->ad + sizeof(_frameHeader); spriteInfo.data = _blocList[j].text_mem->ad + sizeof(_frameHeader);
spriteInfo.colourTable = 0; spriteInfo.colourTable = 0;
rv = DrawSprite(&spriteInfo); rv = g_display->drawSprite(&spriteInfo);
if (rv) if (rv)
error("Driver Error %.8x in Print_text_blocs", rv); error("Driver Error %.8x in Print_text_blocs", rv);
} }
@ -603,7 +603,7 @@ void Sword2Engine::initialiseFontResourceFlags(void) {
// GERMAN: "Baphomet's Fluch II" // GERMAN: "Baphomet's Fluch II"
// default: "Some game or other, part 86" // default: "Some game or other, part 86"
SetWindowName((char *) textLine); g_display->setWindowName((char *) textLine);
// now ok to close the text file // now ok to close the text file
res_man.close(TEXT_RES); res_man.close(TEXT_RES);

View File

@ -18,6 +18,7 @@
*/ */
#include "stdafx.h" #include "stdafx.h"
#include "bs2/sword2.h"
#include "bs2/build_display.h" #include "bs2/build_display.h"
#include "bs2/console.h" #include "bs2/console.h"
#include "bs2/header.h" #include "bs2/header.h"
@ -102,8 +103,8 @@ void MemoryManager::displayMemory(void) {
Build_display(); Build_display();
do { do {
ServiceWindows(); g_display->updateDisplay();
} while(!KeyWaiting()); } while (!KeyWaiting());
ReadKey(&ke); //kill the key we just pressed ReadKey(&ke); //kill the key we just pressed
if (ke.keycode == 27) //ESC if (ke.keycode == 27) //ESC

View File

@ -157,7 +157,7 @@ void Mouse_engine(void) {
System_menu_mouse(); System_menu_mouse();
break; break;
case MOUSE_holding: case MOUSE_holding:
if (mousey < 400) { if (g_display->_mouseY < 400) {
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
debug(5, " releasing"); debug(5, " releasing");
} }
@ -182,10 +182,10 @@ void System_menu_mouse(void) {
}; };
// can't close when player is dead // can't close when player is dead
if (mousey > 0 && !DEAD) { if (g_display->_mouseY > 0 && !DEAD) {
// close menu // close menu
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
HideMenu(RDMENU_TOP); g_display->hideMenu(RDMENU_TOP);
return; return;
} }
@ -194,9 +194,9 @@ void System_menu_mouse(void) {
if (me && (me->buttons & RD_LEFTBUTTONDOWN)) { if (me && (me->buttons & RD_LEFTBUTTONDOWN)) {
// clicked on a top mouse pointer? // clicked on a top mouse pointer?
if (mousex >= 24 && mousex < 640 - 24 && mousey < 0) { if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24 && g_display->_mouseY < 0) {
// which are we over? // which are we over?
hit = (mousex - 24) / 40; hit = (g_display->_mouseX - 24) / 40;
// no save when dead // no save when dead
if (icon_list[hit] == SAVE_ICON && DEAD) if (icon_list[hit] == SAVE_ICON && DEAD)
@ -210,7 +210,7 @@ void System_menu_mouse(void) {
// change all others to grey // change all others to grey
if (j != hit) { if (j != hit) {
icon = res_man.open(icon_list[j]) + sizeof(_standardHeader); icon = res_man.open(icon_list[j]) + sizeof(_standardHeader);
SetMenuIcon(RDMENU_TOP, j, icon); g_display->setMenuIcon(RDMENU_TOP, j, icon);
res_man.close( icon_list[j] ); res_man.close( icon_list[j] );
} }
} }
@ -235,9 +235,9 @@ void System_menu_mouse(void) {
// clear the screen & set up the new palette // clear the screen & set up the new palette
// for the menus // for the menus
EraseBackBuffer(); g_display->clearScene();
ProcessMenu(); g_display->processMenu();
ResetRenderEngine(); g_display->resetRenderEngine();
// call the relevent screen // call the relevent screen
switch (hit) { switch (hit) {
@ -261,7 +261,7 @@ void System_menu_mouse(void) {
// Menu stays open on death screen // Menu stays open on death screen
if (!DEAD) { if (!DEAD) {
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
HideMenu(RDMENU_TOP); g_display->hideMenu(RDMENU_TOP);
} else { } else {
Set_mouse(NORMAL_MOUSE_ID); Set_mouse(NORMAL_MOUSE_ID);
Build_system_menu(); Build_system_menu();
@ -270,8 +270,8 @@ void System_menu_mouse(void) {
// clear the screen & restore the location // clear the screen & restore the location
// palette // palette
EraseBackBuffer(); g_display->clearScene();
ProcessMenu(); g_display->processMenu();
// reset game palette, but not after a // reset game palette, but not after a
// successful restore or restart! // successful restore or restart!
@ -319,10 +319,10 @@ void Drag_mouse(void) {
_mouseEvent *me; _mouseEvent *me;
uint32 pos; uint32 pos;
if (mousey < 400 && !menu_status) { if (g_display->_mouseY < 400 && !menu_status) {
// close menu // close menu
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
HideMenu(RDMENU_BOTTOM); g_display->hideMenu(RDMENU_BOTTOM);
return; return;
} }
@ -358,8 +358,8 @@ void Drag_mouse(void) {
// these might be required by the action script about // these might be required by the action script about
// to be run // to be run
MOUSE_X = (uint32) mousex + this_screen.scroll_offset_x; MOUSE_X = (uint32) g_display->_mouseX + this_screen.scroll_offset_x;
MOUSE_Y = (uint32) mousey + this_screen.scroll_offset_y; MOUSE_Y = (uint32) g_display->_mouseY + this_screen.scroll_offset_y;
// for scripts to know what's been clicked (21jan97). // for scripts to know what's been clicked (21jan97).
// First used for 'room_13_turning_script' in object // First used for 'room_13_turning_script' in object
@ -373,14 +373,14 @@ void Drag_mouse(void) {
// Hide menu - back to normal menu mode // Hide menu - back to normal menu mode
HideMenu(RDMENU_BOTTOM); g_display->hideMenu(RDMENU_BOTTOM);
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
} else { } else {
// better check for combine/cancel // better check for combine/cancel
// cancel puts us back in Menu_mouse mode // cancel puts us back in Menu_mouse mode
if (mousex >= 24 && mousex < 640 - 24) { if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) {
// which are we over? // which are we over?
pos = (mousex - 24) / 40; pos = (g_display->_mouseX - 24) / 40;
//clicked on something - what button? //clicked on something - what button?
if (master_menu_list[pos].icon_resource) { if (master_menu_list[pos].icon_resource) {
@ -432,10 +432,10 @@ void Menu_mouse(void) {
_mouseEvent *me; _mouseEvent *me;
uint32 pos; uint32 pos;
if (mousey < 400 && !menu_status) { if (g_display->_mouseY < 400 && !menu_status) {
// close menu // close menu
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
HideMenu(RDMENU_BOTTOM); g_display->hideMenu(RDMENU_BOTTOM);
return; return;
} }
@ -448,9 +448,9 @@ void Menu_mouse(void) {
// there's a mouse event to be processed // there's a mouse event to be processed
// now check if we've clicked on an actual icon // now check if we've clicked on an actual icon
if (mousex >= 24 && mousex < 640 - 24) { if (g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) {
// which are we over? // which are we over?
pos = (mousex - 24) / 40; pos = (g_display->_mouseX - 24) / 40;
// clicked on something - what button? // clicked on something - what button?
if (master_menu_list[pos].icon_resource) { if (master_menu_list[pos].icon_resource) {
@ -518,7 +518,7 @@ void Normal_mouse(void) {
_mouseEvent *me; _mouseEvent *me;
// no save in big-object menu lock situation // no save in big-object menu lock situation
if (mousey < 0 && !menu_status && !mouse_mode_locked && !OBJECT_HELD) { if (g_display->_mouseY < 0 && !menu_status && !mouse_mode_locked && !OBJECT_HELD) {
mouse_mode = MOUSE_system_menu; mouse_mode = MOUSE_system_menu;
if (mouse_touching) { if (mouse_touching) {
@ -533,7 +533,7 @@ void Normal_mouse(void) {
return; return;
} }
if (mousey > 399 && !menu_status && !mouse_mode_locked) { if (g_display->_mouseY > 399 && !menu_status && !mouse_mode_locked) {
// If an object is being held, i.e. if the mouse cursor has a // If an object is being held, i.e. if the mouse cursor has a
// luggage, we should be use dragging mode instead of inventory // luggage, we should be use dragging mode instead of inventory
// menu mode. // menu mode.
@ -578,8 +578,8 @@ void Normal_mouse(void) {
if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) { if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN))) {
// set both (x1,y1) and (x2,y2) to this point // set both (x1,y1) and (x2,y2) to this point
rect_x1 = rect_x2 = (uint32) mousex + this_screen.scroll_offset_x; rect_x1 = rect_x2 = (uint32) g_display->_mouseX + this_screen.scroll_offset_x;
rect_y1 = rect_y2 = (uint32) mousey + this_screen.scroll_offset_y; rect_y1 = rect_y2 = (uint32) g_display->_mouseY + this_screen.scroll_offset_y;
draggingRectangle = 1; draggingRectangle = 1;
} }
} else if (draggingRectangle == 1) { } else if (draggingRectangle == 1) {
@ -591,8 +591,8 @@ void Normal_mouse(void) {
draggingRectangle = 2; draggingRectangle = 2;
} else { } else {
// drag rectangle // drag rectangle
rect_x2 = (uint32) mousex + this_screen.scroll_offset_x; rect_x2 = (uint32) g_display->_mouseX + this_screen.scroll_offset_x;
rect_y2 = (uint32) mousey + this_screen.scroll_offset_y; rect_y2 = (uint32) g_display->_mouseY + this_screen.scroll_offset_y;
} }
} else { } else {
// currently locked to avoid knocking out of place // currently locked to avoid knocking out of place
@ -642,8 +642,8 @@ void Normal_mouse(void) {
} }
// these might be required by the action script about to be run // these might be required by the action script about to be run
MOUSE_X = (uint32) mousex + this_screen.scroll_offset_x; MOUSE_X = (uint32) g_display->_mouseX + this_screen.scroll_offset_x;
MOUSE_Y = (uint32) mousey + this_screen.scroll_offset_y; MOUSE_Y = (uint32) g_display->_mouseY + this_screen.scroll_offset_y;
// only left button // only left button
if (mouse_touching == EXIT_CLICK_ID && (me->buttons & RD_LEFTBUTTONDOWN)) { if (mouse_touching == EXIT_CLICK_ID && (me->buttons & RD_LEFTBUTTONDOWN)) {
@ -701,7 +701,7 @@ void Mouse_on_off(void) {
// don't detect objects that are hidden behind the menu bars (ie. in // don't detect objects that are hidden behind the menu bars (ie. in
// the scrolled-off areas of the screen) // the scrolled-off areas of the screen)
if (mousey < 0 || mousey > 399) { if (g_display->_mouseY < 0 || g_display->_mouseY > 399) {
pointer_type = 0; pointer_type = 0;
mouse_touching = 0; mouse_touching = 0;
} else { } else {
@ -799,14 +799,14 @@ void Set_mouse(uint32 res) {
// loop // loop
if (res == NORMAL_MOUSE_ID) if (res == NORMAL_MOUSE_ID)
SetMouseAnim(icon, len, RDMOUSE_NOFLASH); g_display->setMouseAnim(icon, len, RDMOUSE_NOFLASH);
else else
SetMouseAnim(icon, len, RDMOUSE_FLASH); g_display->setMouseAnim(icon, len, RDMOUSE_FLASH);
res_man.close(res); res_man.close(res);
} else { } else {
// blank cursor // blank cursor
SetMouseAnim(NULL, 0, 0); g_display->setMouseAnim(NULL, 0, 0);
} }
} }
@ -820,11 +820,11 @@ void Set_luggage(uint32 res) {
icon = res_man.open(res) + sizeof(_standardHeader); icon = res_man.open(res) + sizeof(_standardHeader);
len = res_man._resList[res]->size - sizeof(_standardHeader); len = res_man._resList[res]->size - sizeof(_standardHeader);
SetLuggageAnim(icon, len); g_display->setLuggageAnim(icon, len);
res_man.close(res); res_man.close(res);
} else } else
SetLuggageAnim(NULL, 0); g_display->setLuggageAnim(NULL, 0);
} }
uint32 Check_mouse_list(void) { uint32 Check_mouse_list(void) {
@ -838,10 +838,10 @@ uint32 Check_mouse_list(void) {
// mouse-detection-box // mouse-detection-box
if (mouse_list[j].priority == priority && if (mouse_list[j].priority == priority &&
mousex + this_screen.scroll_offset_x >= mouse_list[j].x1 && g_display->_mouseX + this_screen.scroll_offset_x >= mouse_list[j].x1 &&
mousex + this_screen.scroll_offset_x <= mouse_list[j].x2 && g_display->_mouseX + this_screen.scroll_offset_x <= mouse_list[j].x2 &&
mousey + this_screen.scroll_offset_y >= mouse_list[j].y1 && g_display->_mouseY + this_screen.scroll_offset_y >= mouse_list[j].y1 &&
mousey + this_screen.scroll_offset_y <= mouse_list[j].y2) { g_display->_mouseY + this_screen.scroll_offset_y <= mouse_list[j].y2) {
// record id // record id
mouse_touching = mouse_list[j].id; mouse_touching = mouse_list[j].id;
@ -1017,7 +1017,8 @@ void CreatePointerText(uint32 textId, uint32 pointerRes) {
// line reference number // line reference number
pointer_text_bloc_no = fontRenderer.buildNewBloc( pointer_text_bloc_no = fontRenderer.buildNewBloc(
text + 2, mousex + xOffset, mousey + yOffset, text + 2, g_display->_mouseX + xOffset,
g_display->_mouseY + yOffset,
POINTER_TEXT_WIDTH, POINTER_TEXT_PEN, POINTER_TEXT_WIDTH, POINTER_TEXT_PEN,
RDSPR_TRANS | RDSPR_DISPLAYALIGN, RDSPR_TRANS | RDSPR_DISPLAYALIGN,
g_sword2->_speechFontId, justification); g_sword2->_speechFontId, justification);
@ -1054,12 +1055,12 @@ int32 FN_no_human(int32 *params) {
// dont hide menu in conversations // dont hide menu in conversations
if (TALK_FLAG == 0) if (TALK_FLAG == 0)
HideMenu(RDMENU_BOTTOM); g_display->hideMenu(RDMENU_BOTTOM);
if (mouse_mode == MOUSE_system_menu) { if (mouse_mode == MOUSE_system_menu) {
// close menu // close menu
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
HideMenu(RDMENU_TOP); g_display->hideMenu(RDMENU_TOP);
} }
// script continue // script continue
@ -1117,7 +1118,7 @@ int32 FN_add_human(int32 *params) {
} }
// if mouse is over menu area // if mouse is over menu area
if (mousey > 399) { if (g_display->_mouseY > 399) {
if (mouse_mode != MOUSE_holding) { if (mouse_mode != MOUSE_holding) {
// VITAL - reset things & rebuild the menu // VITAL - reset things & rebuild the menu
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
@ -1292,7 +1293,7 @@ int32 FN_set_scroll_right_mouse(int32 *params) {
// Highest priority // Highest priority
ob_mouse->x1 = this_screen.scroll_offset_x + screenWide - SCROLL_MOUSE_WIDTH; ob_mouse->x1 = this_screen.scroll_offset_x + g_display->_screenWide - SCROLL_MOUSE_WIDTH;
ob_mouse->y1 = 0; ob_mouse->y1 = 0;
ob_mouse->x2 = this_screen.screen_wide - 1; ob_mouse->x2 = this_screen.screen_wide - 1;
ob_mouse->y2 = this_screen.screen_deep - 1; ob_mouse->y2 = this_screen.screen_deep - 1;
@ -1327,7 +1328,7 @@ int32 FN_set_object_held(int32 *params) {
// appropriate to keep it displayed // appropriate to keep it displayed
int32 FN_remove_chooser(int32 *params) { int32 FN_remove_chooser(int32 *params) {
HideMenu(RDMENU_BOTTOM); g_display->hideMenu(RDMENU_BOTTOM);
return IR_CONT; return IR_CONT;
} }
@ -1336,8 +1337,8 @@ int32 FN_disable_menu(int32 *params) {
mouse_mode_locked = 1; mouse_mode_locked = 1;
mouse_mode = MOUSE_normal; mouse_mode = MOUSE_normal;
HideMenu(RDMENU_TOP); g_display->hideMenu(RDMENU_TOP);
HideMenu(RDMENU_BOTTOM); g_display->hideMenu(RDMENU_BOTTOM);
return IR_CONT; return IR_CONT;
} }

View File

@ -18,6 +18,7 @@
*/ */
#include "stdafx.h" #include "stdafx.h"
#include "bs2/sword2.h"
#include "bs2/driver/driver96.h" #include "bs2/driver/driver96.h"
#include "bs2/build_display.h" #include "bs2/build_display.h"
#include "bs2/console.h" #include "bs2/console.h"
@ -32,7 +33,6 @@
#include "bs2/protocol.h" #include "bs2/protocol.h"
#include "bs2/resman.h" #include "bs2/resman.h"
#include "bs2/sound.h" // for Clear_fx_queue() called from cacheNewCluster() #include "bs2/sound.h" // for Clear_fx_queue() called from cacheNewCluster()
#include "bs2/sword2.h" // for CloseGame()
#include "bs2/router.h" #include "bs2/router.h"
namespace Sword2 { namespace Sword2 {
@ -961,8 +961,8 @@ void ResourceManager::killAll(uint8 wantInfo) {
Build_display(); Build_display();
do { do {
ServiceWindows(); g_display->updateDisplay();
} while(!KeyWaiting()); } while (!KeyWaiting());
ReadKey(&ke); ReadKey(&ke);
if (ke.keycode == 27) if (ke.keycode == 27)
@ -1033,8 +1033,8 @@ void ResourceManager::killAllObjects(uint8 wantInfo) {
Build_display(); Build_display();
do { do {
ServiceWindows(); g_display->updateDisplay();
} while(!KeyWaiting()); } while (!KeyWaiting());
ReadKey(&ke); //kill the key we just pressed ReadKey(&ke); //kill the key we just pressed
@ -1106,28 +1106,28 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
char buf[1024]; char buf[1024];
sprintf(buf, "%sClusters\\%s", _cdPath, _resourceFiles[newCluster]); sprintf(buf, "%sClusters\\%s", _cdPath, _resourceFiles[newCluster]);
WaitForFade(); g_display->waitForFade();
if (GetFadeStatus() != RDFADE_BLACK) { if (g_display->getFadeStatus() != RDFADE_BLACK) {
FadeDown((float) 0.75); g_display->fadeDown();
WaitForFade(); g_display->waitForFade();
} }
EraseBackBuffer(); g_display->clearScene();
Set_mouse(0); Set_mouse(0);
Set_luggage(0); //tw28Aug Set_luggage(0);
uint8 *bgfile; uint8 *bgfile;
bgfile = res_man.open(2950); // open the screen resource bgfile = res_man.open(2950); // open the screen resource
InitialiseBackgroundLayer(NULL); g_display->initialiseBackgroundLayer(NULL);
InitialiseBackgroundLayer(NULL); g_display->initialiseBackgroundLayer(NULL);
InitialiseBackgroundLayer(FetchBackgroundLayer(bgfile)); g_display->initialiseBackgroundLayer(FetchBackgroundLayer(bgfile));
InitialiseBackgroundLayer(NULL); g_display->initialiseBackgroundLayer(NULL);
InitialiseBackgroundLayer(NULL); g_display->initialiseBackgroundLayer(NULL);
BS2_SetPalette(0, 256, FetchPalette(bgfile), RDPAL_FADE); g_display->setPalette(0, 256, FetchPalette(bgfile), RDPAL_FADE);
RenderParallax(FetchBackgroundLayer(bgfile), 2); g_display->renderParallax(FetchBackgroundLayer(bgfile), 2);
res_man.close(2950); // release the screen resource res_man.close(2950); // release the screen resource
// Git rid of read-only status, if it is set. // Git rid of read-only status, if it is set.
@ -1153,8 +1153,8 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
frame = (_frameHeader*) text_spr->ad; frame = (_frameHeader*) text_spr->ad;
textSprite.x = screenWide /2 - frame->width / 2; textSprite.x = g_display->_screenWide /2 - frame->width / 2;
textSprite.y = screenDeep /2 - frame->height / 2 - RDMENU_MENUDEEP; textSprite.y = g_display->_screenDeep /2 - frame->height / 2 - RDMENU_MENUDEEP;
textSprite.w = frame->width; textSprite.w = frame->width;
textSprite.h = frame->height; textSprite.h = frame->height;
textSprite.scale = 0; textSprite.scale = 0;
@ -1194,18 +1194,17 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
int16 textX = textSprite.x; int16 textX = textSprite.x;
int16 textY = textSprite.y; int16 textY = textSprite.y;
DrawSprite(&barSprite); g_display->drawSprite(&barSprite);
barSprite.x = barX; barSprite.x = barX;
barSprite.y = barY; barSprite.y = barY;
textSprite.data = text_spr->ad + sizeof(_frameHeader); textSprite.data = text_spr->ad + sizeof(_frameHeader);
DrawSprite(&textSprite); g_display->drawSprite(&textSprite);
textSprite.x = textX; textSprite.x = textX;
textSprite.y = textY; textSprite.y = textY;
FadeUp((float) 0.75); g_display->fadeUp();
g_display->waitForFade();
WaitForFade();
uint32 size = inFile.size(); uint32 size = inFile.size();
@ -1227,19 +1226,19 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
step = 0; step = 0;
// open the screen resource // open the screen resource
bgfile = res_man.open(2950); bgfile = res_man.open(2950);
RenderParallax(FetchBackgroundLayer(bgfile), 2); g_display->renderParallax(FetchBackgroundLayer(bgfile), 2);
// release the screen resource // release the screen resource
res_man.close(2950); res_man.close(2950);
loadingBar = res_man.open(2951); loadingBar = res_man.open(2951);
frame = FetchFrameHeader(loadingBar, fr); frame = FetchFrameHeader(loadingBar, fr);
barSprite.data = (uint8 *) (frame + 1); barSprite.data = (uint8 *) (frame + 1);
res_man.close(2951); res_man.close(2951);
DrawSprite(&barSprite); g_display->drawSprite(&barSprite);
barSprite.x = barX; barSprite.x = barX;
barSprite.y = barY; barSprite.y = barY;
textSprite.data = text_spr->ad + sizeof(_frameHeader); textSprite.data = text_spr->ad + sizeof(_frameHeader);
DrawSprite(&textSprite); g_display->drawSprite(&textSprite);
textSprite.x = textX; textSprite.x = textX;
textSprite.y = textY; textSprite.y = textY;
@ -1247,7 +1246,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
} else } else
step++; step++;
ServiceWindows(); g_display->updateDisplay();
} while ((read % BUFFERSIZE) == 0); } while ((read % BUFFERSIZE) == 0);
if (read != size) { if (read != size) {
@ -1258,11 +1257,11 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
outFile.close(); outFile.close();
memory.freeMemory(text_spr); memory.freeMemory(text_spr);
EraseBackBuffer(); g_display->clearScene();
FadeDown((float) 0.75); g_display->fadeDown();
WaitForFade(); g_display->waitForFade();
FadeUp((float) 0.75); g_display->fadeUp();
// Git rid of read-only status. // Git rid of read-only status.
SVM_SetFileAttributes(_resourceFiles[newCluster], FILE_ATTRIBUTE_NORMAL); SVM_SetFileAttributes(_resourceFiles[newCluster], FILE_ATTRIBUTE_NORMAL);
@ -1379,8 +1378,8 @@ void ResourceManager::getCd(int cd) {
frame = (_frameHeader*) text_spr->ad; frame = (_frameHeader*) text_spr->ad;
spriteInfo.x = screenWide / 2 - frame->width / 2; spriteInfo.x = g_display->_screenWide / 2 - frame->width / 2;
spriteInfo.y = screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP; spriteInfo.y = g_display->_screenDeep / 2 - frame->height / 2 - RDMENU_MENUDEEP;
spriteInfo.w = frame->width; spriteInfo.w = frame->width;
spriteInfo.h = frame->height; spriteInfo.h = frame->height;
spriteInfo.scale = 0; spriteInfo.scale = 0;
@ -1418,10 +1417,10 @@ void ResourceManager::getCd(int cd) {
} }
} }
ServiceWindows(); g_display->updateDisplay();
EraseBackBuffer(); g_display->clearScene();
DrawSprite(&spriteInfo); // Keep the message there even when the user task swaps. g_display->drawSprite(&spriteInfo); // Keep the message there even when the user task swaps.
spriteInfo.y = oldY; // Drivers change the y co-ordinate, don't know why... spriteInfo.y = oldY; // Drivers change the y co-ordinate, don't know why...
spriteInfo.x = oldX; spriteInfo.x = oldX;
} while (!done); } while (!done);

View File

@ -220,17 +220,17 @@ int32 FN_choose(int32 *params) {
if (j < IN_SUBJECT) { if (j < IN_SUBJECT) {
debug(5, " ICON res %d for %d", subject_list[j].res, j); debug(5, " ICON res %d for %d", subject_list[j].res, j);
icon = res_man.open(subject_list[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP; icon = res_man.open(subject_list[j].res) + sizeof(_standardHeader) + RDMENU_ICONWIDE * RDMENU_ICONDEEP;
SetMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon);
res_man.close(subject_list[j].res); res_man.close(subject_list[j].res);
} else { } else {
//no icon here //no icon here
debug(5, " NULL for %d", j); debug(5, " NULL for %d", j);
SetMenuIcon(RDMENU_BOTTOM, (uint8) j, NULL); g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, NULL);
} }
} }
// start menus appearing // start menus appearing
ShowMenu(RDMENU_BOTTOM); g_display->showMenu(RDMENU_BOTTOM);
// lets have the mouse pointer back // lets have the mouse pointer back
Set_mouse(NORMAL_MOUSE_ID); Set_mouse(NORMAL_MOUSE_ID);
@ -253,9 +253,9 @@ int32 FN_choose(int32 *params) {
// if so then end the choose, highlight only the // if so then end the choose, highlight only the
// chosen, blank the mouse and return the ref code * 8 // chosen, blank the mouse and return the ref code * 8
if (mousey > 399 && mousex >= 24 && mousex < 640 - 24) { if (g_display->_mouseY > 399 && g_display->_mouseX >= 24 && g_display->_mouseX < 640 - 24) {
//which are we over? //which are we over?
hit = (mousex - 24) / 40; hit = (g_display->_mouseX - 24) / 40;
//clicked on something - what button? //clicked on something - what button?
if (hit < IN_SUBJECT) { if (hit < IN_SUBJECT) {
@ -268,7 +268,7 @@ int32 FN_choose(int32 *params) {
// change all others to grey // change all others to grey
if (j != hit) { if (j != hit) {
icon = res_man.open( subject_list[j].res ) + sizeof(_standardHeader); icon = res_man.open( subject_list[j].res ) + sizeof(_standardHeader);
SetMenuIcon(RDMENU_BOTTOM, (uint8) j, icon); g_display->setMenuIcon(RDMENU_BOTTOM, (uint8) j, icon);
res_man.close(subject_list[j].res); res_man.close(subject_list[j].res);
} }
} }
@ -338,9 +338,9 @@ int32 FN_end_conversation(int32 *params) {
debug(5, "FN_end_conversation"); debug(5, "FN_end_conversation");
HideMenu(RDMENU_BOTTOM); g_display->hideMenu(RDMENU_BOTTOM);
if (mousey > 399) { if (g_display->_mouseY > 399) {
// will wait for cursor to move off the bottom menu // will wait for cursor to move off the bottom menu
mouse_mode = MOUSE_holding; mouse_mode = MOUSE_holding;
debug(5, " holding"); debug(5, " holding");
@ -1302,7 +1302,7 @@ int32 FN_i_speak(int32 *params) {
#ifdef _SWORD2_DEBUG #ifdef _SWORD2_DEBUG
// so that we can go to the options panel while text & speech is // so that we can go to the options panel while text & speech is
// being tested // being tested
if (SYSTEM_TESTING_TEXT == 0 || mousey > 0) { if (SYSTEM_TESTING_TEXT == 0 || g_display->_mouseY > 0) {
#endif #endif
me = MouseEvent(); me = MouseEvent();

View File

@ -196,8 +196,8 @@ uint32 Con_print_start_menu(void) {
do { do {
// Service windows // Service windows
ServiceWindows(); g_display->updateDisplay();
} while(!KeyWaiting()); } while (!KeyWaiting());
// kill the key we just pressed // kill the key we just pressed
ReadKey(&ke); ReadKey(&ke);

View File

@ -96,6 +96,7 @@ uint8 stepOneCycle = 0; // for use while game paused
Sword2Engine *g_sword2 = NULL; Sword2Engine *g_sword2 = NULL;
Sound *g_sound = NULL; Sound *g_sound = NULL;
Display *g_display = NULL;
Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst) Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
: Engine(detector, syst) { : Engine(detector, syst) {
@ -120,11 +121,13 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
_mixer->setMusicVolume(256); _mixer->setMusicVolume(256);
g_sound = _sound = new Sound(_mixer); g_sound = _sound = new Sound(_mixer);
g_display = _display = new Display(640, 480);
} }
Sword2Engine::~Sword2Engine() { Sword2Engine::~Sword2Engine() {
free(_targetName); free(_targetName);
delete _sound; delete _sound;
delete _display;
} }
void Sword2Engine::errorString(const char *buf1, char *buf2) { void Sword2Engine::errorString(const char *buf1, char *buf2) {
@ -199,7 +202,6 @@ int32 Sword2Engine::InitialiseGame(void) {
void Close_game() { void Close_game() {
debug(5, "Close_game() STARTING:"); debug(5, "Close_game() STARTING:");
EraseBackBuffer();
// Stop music instantly! // Stop music instantly!
Kill_music(); Kill_music();
@ -207,6 +209,8 @@ void Close_game() {
// free the memory again // free the memory again
memory.exit(); memory.exit();
res_man.exit(); res_man.exit();
g_system->quit();
} }
int32 GameCycle(void) { int32 GameCycle(void) {
@ -250,8 +254,6 @@ int32 GameCycle(void) {
} }
void Sword2Engine::go() { void Sword2Engine::go() {
uint32 rv;
uint8 breakOut = 0;
_keyboardEvent ke; _keyboardEvent ke;
// Call the application "Revolution" until the resource manager is // Call the application "Revolution" until the resource manager is
@ -262,21 +264,12 @@ void Sword2Engine::go() {
// manager until a window has been created as any errors are displayed // manager until a window has been created as any errors are displayed
// via a window, thus time becomes a loop. // via a window, thus time becomes a loop.
debug(5, "CALLING: InitialiseDisplay");
rv = InitialiseDisplay(640, 480);
if (rv != RD_OK) {
// ReportDriverError(rv);
CloseAppWindow();
return;
}
debug(5, "CALLING: readOptionSettings"); debug(5, "CALLING: readOptionSettings");
gui.readOptionSettings(); gui.readOptionSettings();
debug(5, "CALLING: InitialiseGame"); debug(5, "CALLING: InitialiseGame");
if (InitialiseGame()) { if (InitialiseGame()) {
CloseAppWindow(); Close_game();
return; return;
} }
@ -291,11 +284,11 @@ void Sword2Engine::go() {
} else } else
Start_game(); Start_game();
debug(5, "CALLING: InitialiseRenderCycle"); debug(5, "CALLING: initialiseRenderCycle");
InitialiseRenderCycle(); g_display->initialiseRenderCycle();
while (1) { while (1) {
ServiceWindows(); g_display->updateDisplay();
#ifdef _SWORD2_DEBUG #ifdef _SWORD2_DEBUG
// FIXME: If we want this, we should re-work it to use the backend's // FIXME: If we want this, we should re-work it to use the backend's
@ -304,10 +297,6 @@ void Sword2Engine::go() {
// GrabScreenShot(); // GrabScreenShot();
#endif #endif
// if we are closing down the game, break out of main game loop
if (breakOut)
break;
#ifdef _SWORD2_DEBUG #ifdef _SWORD2_DEBUG
if (console_status) { if (console_status) {
if (One_console()) { if (One_console()) {
@ -408,7 +397,6 @@ void Sword2Engine::go() {
} }
Close_game(); //close engine systems down Close_game(); //close engine systems down
CloseAppWindow();
return; //quit the game return; //quit the game
} }
@ -465,8 +453,8 @@ void sleepUntil(int32 time) {
g_sword2->parseEvents(); g_sword2->parseEvents();
// Make sure menu animations and fades don't suffer // Make sure menu animations and fades don't suffer
ProcessMenu(); g_display->processMenu();
ServiceWindows(); g_display->updateDisplay();
g_system->delay_msecs(10); g_system->delay_msecs(10);
} }
@ -481,8 +469,8 @@ void PauseGame(void) {
// now ok to close the text file // now ok to close the text file
// res_man.close(3258); // res_man.close(3258);
// don't allow Pause while screen fading or while black (James 03sep97) // don't allow Pause while screen fading or while black
if (GetFadeStatus() != RDFADE_NONE) if (g_display->getFadeStatus() != RDFADE_NONE)
return; return;
PauseAllSound(); PauseAllSound();
@ -492,8 +480,8 @@ void PauseGame(void) {
// mouse_mode=MOUSE_normal; // mouse_mode=MOUSE_normal;
//this is the only place allowed to do it this way // this is the only place allowed to do it this way
SetLuggageAnim(NULL, 0); g_display->setLuggageAnim(NULL, 0);
// blank cursor // blank cursor
Set_mouse(0); Set_mouse(0);
@ -513,7 +501,7 @@ void PauseGame(void) {
// dim the palette during the pause (James26jun97) // dim the palette during the pause (James26jun97)
if (stepOneCycle == 0) if (stepOneCycle == 0)
DimPalette(); g_display->dimPalette();
gamePaused = 1; gamePaused = 1;
} }

View File

@ -26,6 +26,7 @@
#include "common/rect.h" #include "common/rect.h"
#include "common/str.h" #include "common/str.h"
#include "bs2/driver/d_sound.h" #include "bs2/driver/d_sound.h"
#include "bs2/driver/d_draw.h"
enum BSGameId { enum BSGameId {
GID_SWORD2 = GID_SWORD2_FIRST, GID_SWORD2 = GID_SWORD2_FIRST,
@ -77,6 +78,7 @@ public:
byte _gameId; byte _gameId;
char *_targetName; // target name for saves char *_targetName; // target name for saves
Sound *_sound; Sound *_sound;
Display *_display;
Common::RandomSource _rnd; Common::RandomSource _rnd;
uint32 _speechFontId; uint32 _speechFontId;
@ -90,6 +92,7 @@ public:
extern Sword2Engine *g_sword2; extern Sword2Engine *g_sword2;
extern Sound *g_sound; extern Sound *g_sound;
extern Display *g_display;
} // End of namespace Sword2 } // End of namespace Sword2

View File

@ -23,6 +23,7 @@
// on them // on them
#include "stdafx.h" #include "stdafx.h"
#include "bs2/sword2.h"
#include "bs2/console.h" #include "bs2/console.h"
#include "bs2/defs.h" #include "bs2/defs.h"
#include "bs2/events.h" #include "bs2/events.h"
@ -137,7 +138,7 @@ int32 FN_walk(int32 *params) {
// resource // resource
ob_graph->anim_resource = ob_mega->megaset_res; ob_graph->anim_resource = ob_mega->megaset_res;
} else if (EXIT_FADING && GetFadeStatus() == RDFADE_BLACK) { } else if (EXIT_FADING && g_display->getFadeStatus() == RDFADE_BLACK) {
// double clicked an exit so quit the walk when screen is black // double clicked an exit so quit the walk when screen is black
// ok, thats it - back to script and change screen // ok, thats it - back to script and change screen