From 49c4bb2479fec3cfe5a2fed918437deb8862cd53 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Mon, 28 Sep 2020 12:07:12 +0800 Subject: [PATCH] Some code refactoring Added a value of 2 to TextureFilter option. --- artifacts/ddraw.ini | 3 +- artifacts/scripting/sfall function notes.txt | 2 +- sfall/BugFixes.cpp | 4 +- sfall/FalloutEngine.cpp | 7 +-- sfall/FalloutEngine.h | 2 +- sfall/FalloutStructs.h | 48 ++++++++++++++------ sfall/Graphics.cpp | 20 ++++++-- sfall/HeroAppearance.cpp | 2 +- sfall/Movies.cpp | 2 +- sfall/main.h | 2 + 10 files changed, 61 insertions(+), 31 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 4f35881a..2719522e 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -56,7 +56,8 @@ WindowData=0 ;You can specify multiple shader files, separated by commas ;GlobalShaderFile=global.fx -;Set to 1 to enable linear texture filtering +;Set to 1 to automatically enable linear texture filtering when the scale factor is not an integer +;Set to 2 to force-enable linear texture filtering ;This can be used in conjunction with the GlobalShaderFile option TextureFilter=1 diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index bf5b735d..16633e02 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -657,7 +657,7 @@ optional arguments: - x/y: offset relative to the top-left corner of the window optional arguments: - frame: frame number, the first frame starts from zero -- param: an array which specifies additional parameters: +- param: an array which specifies additional parameters, where: index 0 - sprite direction for multi-directional FRM index 1/index 2 - the new width/height to scale the image to. Pass -1 to use the original width/height diff --git a/sfall/BugFixes.cpp b/sfall/BugFixes.cpp index 1cf9acc1..ae6b6930 100644 --- a/sfall/BugFixes.cpp +++ b/sfall/BugFixes.cpp @@ -908,7 +908,7 @@ static void __declspec(naked) make_path_func_hook() { cmp ebx, [esp + 0x5C - 0x1C + 4]; // target tile je fix; jmp anim_can_use_door_; -fix: +fix: // replace the target tile (where the multihex object is located) with the current tile mov ebx, [esp + 0x5C - 0x14 + 4]; // current tile mov [esp + 0x5C - 0x1C + 4], ebx; // target tile retn; @@ -3180,7 +3180,7 @@ void BugFixesInit() HookCall(0x4A22DF, ResetPlayer_hook); // Fix for add_mult_objs_to_inven only adding 500 of an object when the value of the "count" argument is over 99999 - SafeWrite32(0x45A2A0, 0x1869F); // 99999 + SafeWrite32(0x45A2A0, 99999); // Fix for being at incorrect hex after map change when the exit hex in source map is at the same position as // some exit hex in destination map diff --git a/sfall/FalloutEngine.cpp b/sfall/FalloutEngine.cpp index b8003820..68d770c8 100644 --- a/sfall/FalloutEngine.cpp +++ b/sfall/FalloutEngine.cpp @@ -1416,13 +1416,8 @@ long wmGetCurrentTerrainType() { // copy the area from the interface buffer to the data array void SurfaceCopyToMem(long fromX, long fromY, long width, long height, long fromWidth, BYTE* fromSurface, BYTE* toMem) { fromSurface += fromY * fromWidth + fromX; - long i = 0; - for (long h = 0; h < height; h++) { - /*for (long w = 0; w < width; w++) { - toMem[i++] = fromSurface[w]; - }*/ + for (long i = 0, h = 0; h < height; h++, i += width) { std::memcpy(&toMem[i], fromSurface, width); - i += width; fromSurface += fromWidth; } } diff --git a/sfall/FalloutEngine.h b/sfall/FalloutEngine.h index 7beb995e..51562398 100644 --- a/sfall/FalloutEngine.h +++ b/sfall/FalloutEngine.h @@ -1333,6 +1333,6 @@ DWORD __stdcall GetMaxCharWidth(); void RedrawObject(TGameObj* obj); // Redraws all interface windows -void RefreshGNW(size_t from); +void RefreshGNW(size_t from = 0); UNLSTDfrm *LoadUnlistedFrm(char *frmName, unsigned int folderRef); diff --git a/sfall/FalloutStructs.h b/sfall/FalloutStructs.h index 5a92922d..3f72868c 100644 --- a/sfall/FalloutStructs.h +++ b/sfall/FalloutStructs.h @@ -250,6 +250,17 @@ struct sElevatorFrms { DWORD buttons; }; +// structures for holding frms loaded with fallout2 functions +typedef class FrmFrameData { // sizeof 12 + 1 byte +public: + WORD width; + WORD height; + DWORD size; // width * height + WORD x; + WORD y; + BYTE data[1]; // begin frame image data +} FrmFrameData; + struct FrmFile { long id; //0x00 short fps; //0x04 @@ -259,24 +270,35 @@ struct FrmFile { short yshift[6]; //0x16 long oriFrameOffset[6]; //0x22 long frameAreaSize; //0x3a - short width; //0x3e + union { //0x3e + FrmFrameData *frameData; + short width; + }; short height; //0x40 long frameSize; //0x42 short xoffset; //0x46 short yoffset; //0x48 - BYTE pixels[80 * 36]; //0x4a -}; + union { //0x4a + BYTE *pixelData; + BYTE pixels[80 * 36]; // for tiles FRM + }; -//structures for holding frms loaded with fallout2 functions -typedef class FrmFrameData { // sizeof 12 + 1 byte -public: - WORD width; - WORD height; - DWORD size; // width * height - WORD x; - WORD y; - BYTE data[1]; // begin frame data -} FrmFrameData; + // Returns a pointer to the data of the frame in the direction + FrmFrameData* GetFrameData(long dir, long frame) { + BYTE* offsDirectionFrame = (BYTE*)&frameData; + if (dir > 0 && dir < 6) { + offsDirectionFrame += oriFrameOffset[dir]; + } + if (frame > 0) { + int maxFrames = frames - 1; + if (frame > maxFrames) frame = maxFrames; + while (frame-- > 0) { + offsDirectionFrame += ((FrmFrameData*)offsDirectionFrame)->size + (sizeof(FrmFrameData) - 1); + } + } + return (FrmFrameData*)offsDirectionFrame; + } +}; #pragma pack(push, 2) typedef class FrmHeaderData { // sizeof 62 diff --git a/sfall/Graphics.cpp b/sfall/Graphics.cpp index 94932f5f..39f3a4e4 100644 --- a/sfall/Graphics.cpp +++ b/sfall/Graphics.cpp @@ -46,7 +46,7 @@ static DWORD yoffset; static bool DeviceLost = false; static bool mainTexLock = false; -static bool textureFilter = true; +static char textureFilter; // 1 - auto, 2 - force static DDSURFACEDESC surfaceDesc; static DDSURFACEDESC mveDesc; @@ -896,7 +896,7 @@ public: if (d3d9Device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) { ResetDevice(false); DeviceLost = false; - RefreshGNW(0); + RefreshGNW(); } return !DeviceLost; } @@ -1228,8 +1228,18 @@ HRESULT __stdcall FakeDirectDrawCreate2(void*, IDirectDraw** b, void*) { rcpres[0] = 1.0f / (float)gWidth; rcpres[1] = 1.0f / (float)gHeight; - // Disable texture filtering if the set resolutions are equal - textureFilter = (textureFilter && (ResWidth != gWidth || ResHeight != gHeight)); + if (textureFilter) { + float wScale = (float)gWidth / ResWidth; + float hScale = (float)gHeight / ResHeight; + if (wScale == 1.0f && hScale == 1.0f) textureFilter = 0; // disable texture filtering if the set resolutions are equal + if (textureFilter == 1) { + int ws = static_cast(wScale); + int hs = static_cast(hScale); + if (ws == wScale && hs == hScale) { + textureFilter = 0; // disable for integer scales + } + } + } *b = (IDirectDraw*)new FakeDirectDraw(); @@ -1293,7 +1303,7 @@ void GraphicsInit() { SafeWrite8(0x50FB6B, '2'); // Set call DirectDrawCreate2 HookCall(0x44260C, game_init_hook); - textureFilter = (GetConfigInt("Graphics", "TextureFilter", 1) != 0); + textureFilter = GetConfigInt("Graphics", "TextureFilter", 1); dlogr(" Done", DL_INIT); for each (const std::string& shaderFile in GetConfigList("Graphics", "GlobalShaderFile", "", 1024)) { diff --git a/sfall/HeroAppearance.cpp b/sfall/HeroAppearance.cpp index d5443843..ef8d57b6 100644 --- a/sfall/HeroAppearance.cpp +++ b/sfall/HeroAppearance.cpp @@ -543,7 +543,7 @@ static void surface_draw(long width, long height, long fromWidth, long fromX, lo toBuff += toY * toWidth + toX; for (long h = 0; h < height; h++) { - for (long w = 0; w < width; w++) toBuff[w] = fromBuff[w]; + std::memcpy(toBuff, fromBuff, width); fromBuff += fromWidth; toBuff += toWidth; } diff --git a/sfall/Movies.cpp b/sfall/Movies.cpp index cda2806c..480aa93d 100644 --- a/sfall/Movies.cpp +++ b/sfall/Movies.cpp @@ -217,7 +217,7 @@ static void StopMovie() { aviPlayState = AVISTATE_Stop; Gfx_SetMovieTexture(false); movieInterface.pControl->Stop(); - if (*(DWORD*)_subtitles == 0) RefreshGNW(0); // Note: it is only necessary when in the game + if (*(DWORD*)_subtitles == 0) RefreshGNW(); // Note: it is only necessary when in the game } DWORD FreeMovie(sDSTexture* movie) { diff --git a/sfall/main.h b/sfall/main.h index 971cff61..3722b1ed 100644 --- a/sfall/main.h +++ b/sfall/main.h @@ -23,6 +23,8 @@ #pragma warning(disable: 4414) // 'function': short jump to function converted to near #endif +#pragma intrinsic(memcpy, memset) + #include #include #include