From 4e9d4f2f3781ece06693f3953b2ea28b529f9f3c Mon Sep 17 00:00:00 2001 From: NovaRain Date: Mon, 28 Sep 2020 12:04:08 +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/FalloutEngine/EngineUtils.cpp | 7 +-- sfall/FalloutEngine/EngineUtils.h | 2 +- sfall/FalloutEngine/Structs.h | 48 ++++++++++++++----- sfall/Modules/BugFixes.cpp | 4 +- sfall/Modules/Graphics.cpp | 20 ++++++-- sfall/Modules/HeroAppearance.cpp | 2 +- sfall/Modules/Movies.cpp | 2 +- .../Modules/Scripting/Handlers/Interface.cpp | 19 ++------ sfall/main.h | 3 ++ 11 files changed, 65 insertions(+), 47 deletions(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index a882053d..c29cbaca 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -72,7 +72,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 692d7198..8509eda9 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -751,7 +751,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/FalloutEngine/EngineUtils.cpp b/sfall/FalloutEngine/EngineUtils.cpp index 25e6793a..4da1c6cd 100644 --- a/sfall/FalloutEngine/EngineUtils.cpp +++ b/sfall/FalloutEngine/EngineUtils.cpp @@ -289,13 +289,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/EngineUtils.h b/sfall/FalloutEngine/EngineUtils.h index 58de05bc..8f357417 100644 --- a/sfall/FalloutEngine/EngineUtils.h +++ b/sfall/FalloutEngine/EngineUtils.h @@ -133,7 +133,7 @@ DWORD GetMaxCharWidth(); void RedrawObject(GameObject* obj); // Redraws all interface windows -void RefreshGNW(size_t from); +void RefreshGNW(size_t from = 0); UnlistedFrm *LoadUnlistedFrm(char *frmName, unsigned int folderRef); diff --git a/sfall/FalloutEngine/Structs.h b/sfall/FalloutEngine/Structs.h index c97579c2..e5a14ef9 100644 --- a/sfall/FalloutEngine/Structs.h +++ b/sfall/FalloutEngine/Structs.h @@ -280,6 +280,17 @@ struct ElevatorFrms { 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 @@ -289,24 +300,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/Modules/BugFixes.cpp b/sfall/Modules/BugFixes.cpp index 1aa2682f..2c9a08dc 100644 --- a/sfall/Modules/BugFixes.cpp +++ b/sfall/Modules/BugFixes.cpp @@ -925,7 +925,7 @@ static void __declspec(naked) make_path_func_hook() { cmp ebx, [esp + 0x5C - 0x1C + 4]; // target tile je fix; jmp fo::funcoffs::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; @@ -3193,7 +3193,7 @@ void BugFixes::init() 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/Modules/Graphics.cpp b/sfall/Modules/Graphics.cpp index a7c21aa8..a347b19b 100644 --- a/sfall/Modules/Graphics.cpp +++ b/sfall/Modules/Graphics.cpp @@ -50,7 +50,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; @@ -771,7 +771,7 @@ public: if (d3d9Device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET) { ResetDevice(false); DeviceLost = false; - fo::RefreshGNW(0); + fo::RefreshGNW(); } return !DeviceLost; } @@ -1100,8 +1100,18 @@ HRESULT __stdcall InitFakeDirectDrawCreate(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(); @@ -1154,7 +1164,7 @@ void Graphics::init() { 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); } diff --git a/sfall/Modules/HeroAppearance.cpp b/sfall/Modules/HeroAppearance.cpp index b22d731f..f5ba1ab2 100644 --- a/sfall/Modules/HeroAppearance.cpp +++ b/sfall/Modules/HeroAppearance.cpp @@ -510,7 +510,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/Modules/Movies.cpp b/sfall/Modules/Movies.cpp index ea0162b4..946cf785 100644 --- a/sfall/Modules/Movies.cpp +++ b/sfall/Modules/Movies.cpp @@ -216,7 +216,7 @@ static void StopMovie() { aviPlayState = AviState::Stop; Graphics::SetMovieTexture(false); movieInterface.pControl->Stop(); - if (*(DWORD*)FO_VAR_subtitles == 0) fo::RefreshGNW(0); // Note: it is only necessary when in the game + if (*(DWORD*)FO_VAR_subtitles == 0) fo::RefreshGNW(); // Note: it is only necessary when in the game } DWORD FreeMovie(sDSTexture* movie) { diff --git a/sfall/Modules/Scripting/Handlers/Interface.cpp b/sfall/Modules/Scripting/Handlers/Interface.cpp index da9dea33..f565fe4a 100644 --- a/sfall/Modules/Scripting/Handlers/Interface.cpp +++ b/sfall/Modules/Scripting/Handlers/Interface.cpp @@ -470,26 +470,13 @@ static long GetArtFIDFile(long fid, const char* &file) { return direction; } -static fo::FrmFile* LoadArtFile(const char* file, long frameno, long direction, fo::FrmFrameData* &framePtr) { +static fo::FrmFile* LoadArtFile(const char* file, long frame, long direction, fo::FrmFrameData* &framePtr) { fo::FrmFile* frmPtr = nullptr; if (fo::func::load_frame(file, &frmPtr)) { return nullptr; } - framePtr = (fo::FrmFrameData*)&frmPtr->width; - if (direction > 0 && direction < 6) { - BYTE* offsOriFrame = (BYTE*)framePtr; - offsOriFrame += frmPtr->oriFrameOffset[direction]; - framePtr = (fo::FrmFrameData*)offsOriFrame; - } - if (frameno > 0) { - int maxFrames = frmPtr->frames - 1; - if (frameno > maxFrames) frameno = maxFrames; - while (frameno-- > 0) { - BYTE* offsFrame = (BYTE*)framePtr; - offsFrame += framePtr->size + (sizeof(fo::FrmFrameData) - 1); - framePtr = (fo::FrmFrameData*)offsFrame; - } - } + framePtr = frmPtr->GetFrameData(direction, frame); + return frmPtr; } diff --git a/sfall/main.h b/sfall/main.h index 738c5359..8b7f377c 100644 --- a/sfall/main.h +++ b/sfall/main.h @@ -23,8 +23,11 @@ #pragma warning(disable: 4414) // 'function': short jump to function converted to near #endif +#pragma intrinsic(memcpy, memset) + #include #include +#include #include #include #include