ref: d47f683491b2c3d88214c0b8d2aa60605e68b137
parent: 2c9fbc765ecf0e399224b1968c2e61860a555ef4
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Aug 13 00:36:05 EDT 2019
Ported the Windows version's surface regeneration Has the same imperfections: if you regenerate the surfaces while a text box is open (and while using Courier New I guess), the text will regenerate with smaller spaces.
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -7,7 +7,11 @@
#include "../../WindowsWrapper.h"
+#include "../../Draw.h"
+#include "../../Ending.h"
#include "../../Font.h"
+#include "../../MapName.h"
+#include "../../TextScr.h"
typedef struct Backend_Surface
{
@@ -300,7 +304,10 @@
void Backend_HandleDeviceLoss(void)
{
// All of our textures have been lost, so regenerate them
- // TODO
+ RestoreSurfaces();
+ RestoreStripper();
+ RestoreMapName();
+ RestoreTextScript();
}
void Backend_HandleWindowResize(void)
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -1,3 +1,5 @@
+#include "Draw.h"
+
#include <stddef.h>
#include <stdio.h>
#ifdef WINDOWS
@@ -10,7 +12,6 @@
#include "WindowsWrapper.h"
#include "CommonDefines.h"
-#include "Draw.h"
#include "Font.h"
#include "Resource.h"
#include "Tags.h"
@@ -31,6 +32,16 @@
static FontObject *gFont;
+// This doesn't exist in the Linux port, so none of these symbol names are accurate
+static struct
+{
+ unsigned char type;
+ unsigned int width;
+ unsigned int height;
+ BOOL bSystem; // Basically a 'do not regenerate' flag
+ char name[0x20];
+} surface_metadata[SURFACE_ID_MAX];
+
#define FRAMERATE 20
BOOL Flip_SystemTask(HWND hWnd)
@@ -73,6 +84,8 @@
{
(void)lColourDepth; // There's no way I'm supporting a bunch of different colour depths
+ memset(surface_metadata, 0, sizeof(surface_metadata));
+
switch (lMagnification)
{
case 0:
@@ -117,6 +130,8 @@
Backend_Deinit();
SDL_FreeFormat(rgb24_pixel_format);
+
+ memset(surface_metadata, 0, sizeof(surface_metadata));
}
static BOOL IsEnableBitmap(SDL_RWops *fp)
@@ -140,12 +155,12 @@
Backend_FreeSurface(surf[s]);
surf[s] = NULL;
}
+
+ memset(&surface_metadata[s], 0, sizeof(surface_metadata[0]));
}
BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSystem)
{
- (void)bSystem;
-
BOOL success = FALSE;
#ifdef FIX_BUGS
@@ -168,9 +183,19 @@
surf[surf_no] = Backend_CreateSurface(bxsize * magnification, bysize * magnification);
if (surf[surf_no] == NULL)
+ {
printf("Failed to create backend surface %d\n", surf_no);
+ }
else
+ {
+ surface_metadata[surf_no].type = 1;
+ surface_metadata[surf_no].width = bxsize;
+ surface_metadata[surf_no].height = bysize;
+ surface_metadata[surf_no].bSystem = bSystem;
+ strcpy(surface_metadata[surf_no].name, "generic");
+
success = TRUE;
+ }
}
}
@@ -177,7 +202,7 @@
return success;
}
-static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface)
+static BOOL LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, BOOL create_surface, const char *name, unsigned char type)
{
BOOL success = FALSE;
@@ -257,6 +282,18 @@
Backend_UnlockSurface(surf[surf_no]);
SDL_FreeSurface(converted_surface);
+
+ surface_metadata[surf_no].type = type;
+
+ if (create_surface)
+ {
+ surface_metadata[surf_no].width = surface->w;
+ surface_metadata[surf_no].height = surface->h;
+ surface_metadata[surf_no].bSystem = FALSE;
+ }
+
+ strcpy(surface_metadata[surf_no].name, name);
+
success = TRUE;
}
}
@@ -288,7 +325,7 @@
}
else
{
- if (LoadBitmap(fp, surf_no, create_surface))
+ if (LoadBitmap(fp, surf_no, create_surface, name, 3))
return TRUE;
}
}
@@ -298,7 +335,7 @@
fp = SDL_RWFromFile(path, "rb");
if (fp)
{
- if (LoadBitmap(fp, surf_no, create_surface))
+ if (LoadBitmap(fp, surf_no, create_surface, name, 3))
return TRUE;
}
@@ -318,7 +355,7 @@
// But hey, if I ever need to create an RWops from an array that's -32768 bytes long, they've got me covered!
SDL_RWops *fp = SDL_RWFromConstMem(data, size);
- if (LoadBitmap(fp, surf_no, create_surface))
+ if (LoadBitmap(fp, surf_no, create_surface, res, 2))
return TRUE;
}
@@ -454,8 +491,40 @@
const unsigned char col_blue = (unsigned char)((col >> 16) & 0xFF);
Backend_ColourFill(surf[surf_no], &destRect, col_red, col_green, col_blue);
+
+ surface_metadata[surf_no].type = 1;
}
+void RestoreSurfaces() // Guessed function name - this doesn't exist in the Linux port
+{
+ RECT rect;
+
+ for (int i = 0; i < SURFACE_ID_MAX; ++i)
+ {
+ if (surf[i] && !surface_metadata[i].bSystem)
+ {
+ switch (surface_metadata[i].type)
+ {
+ case 1:
+ rect.left = 0;
+ rect.top = 0;
+ rect.right = surface_metadata[i].width;
+ rect.bottom = surface_metadata[i].height;
+ CortBox2(&rect, 0, (Surface_Ids)i);
+ break;
+
+ case 2:
+ ReloadBitmap_Resource(surface_metadata[i].name, (Surface_Ids)i);
+ break;
+
+ case 3:
+ ReloadBitmap_File(surface_metadata[i].name, (Surface_Ids)i);
+ break;
+ }
+ }
+ }
+}
+
#ifdef WINDOWS
static unsigned char* GetFontFromWindows(size_t *data_size, const char *font_name, unsigned int fontWidth, unsigned int fontHeight)
{
@@ -571,6 +640,8 @@
UnloadFont(gFont);
gFont = NULL;
}
+
+// These functions are new
void HandleDeviceLoss()
{
--- a/src/Draw.h
+++ b/src/Draw.h
@@ -67,6 +67,7 @@
unsigned long GetCortBoxColor(unsigned long col);
void CortBox(const RECT *rect, unsigned long col);
void CortBox2(const RECT *rect, unsigned long col, Surface_Ids surf_no);
+void RestoreSurfaces();
void InitTextObject(const char *font_name);
void PutText(int x, int y, const char *text, unsigned long color);
void PutText2(int x, int y, const char *text, unsigned long color, Surface_Ids surf_no);
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -1487,3 +1487,12 @@
g_GameFlags |= 4;
return 1;
}
+
+void RestoreTextScript()
+{
+ for (int i = 0; i < 4; ++i)
+ {
+ CortBox2(&gRect_line, 0x000000, (Surface_Ids)(i + SURFACE_ID_TEXT_LINE1));
+ PutText2(0, 0, &text[i * 0x40], RGB(0xFF, 0xFF, 0xFE), (Surface_Ids)(i + SURFACE_ID_TEXT_LINE1));
+ }
+}
--- a/src/TextScr.h
+++ b/src/TextScr.h
@@ -65,3 +65,4 @@
void StopTextScript();
void PutTextScript();
int TextScriptProc();
+void RestoreTextScript();