Skip to content

Commit

Permalink
Code edits to Graphics.cpp & Logging.cpp
Browse files Browse the repository at this point in the history
Minor edits to other code/documents.
Updated version number.
  • Loading branch information
NovaRain committed Feb 17, 2022
1 parent 5fcf4aa commit b1323fc
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 75 deletions.
2 changes: 1 addition & 1 deletion artifacts/ddraw.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;sfall configuration settings
;v3.8.33
;v3.8.33.1

[Main]
;Set to 1 if you want to use command line arguments to tell sfall to use another ini file
Expand Down
2 changes: 1 addition & 1 deletion artifacts/scripting/hookscripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ When using `critter_dmg` function, this script will also run. In that case weapo
Does not run for critters in the knockdown/out state.

```
Item arg0 - The pid of the weapon performing the attack. (May be -1 if the attack is unarmed)
int arg0 - The pid of the weapon performing the attack. (May be -1 if the attack is unarmed)
Critter arg1 - The attacker
Critter arg2 - The target
int arg3 - The amount of damage
Expand Down
2 changes: 1 addition & 1 deletion sfall/CRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace sfall
static const DWORD ExpectedSize = 1189888;
static const DWORD ExpectedCRC[] = {
0xE1680293, // US 1.02d
0xEF34F989 // US 1.02d + HRP
0xEF34F989 // US 1.02d + HRP by Mash
};

static void inline ExitMessageFail(const char* a) {
Expand Down
12 changes: 12 additions & 0 deletions sfall/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,24 @@ void dlog(const char* a, int type) {
}
}

void dlog(const std::string& a, int type) {
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
OutLog(a);
}
}

void dlogr(const char* a, int type) {
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
OutLogN(a);
}
}

void dlogr(const std::string& a, int type) {
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
OutLogN(a);
}
}

void dlog_f(const char* fmt, int type, ...) {
if (type == DL_MAIN || (isDebug && (type & DebugTypes))) {
va_list args;
Expand Down
3 changes: 3 additions & 0 deletions sfall/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@

#ifndef NO_SFALL_DEBUG
#include <stdio.h>
#include <string>

namespace sfall
{

void dlog(const char* msg, int type);
void dlog(const std::string& msg, int type);
void dlogr(const char* msg, int type);
void dlogr(const std::string& msg, int type);
void dlog_f(const char* fmt, int type, ...);

#ifndef NDEBUG
Expand Down
73 changes: 6 additions & 67 deletions sfall/Modules/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ static void ResetDevice(bool create) {
static D3DFORMAT textureFormat = D3DFMT_X8R8G8B8;

if (create) {
DWORD mThreadFlags = (dShowMovies) ? D3DCREATE_MULTITHREADED : 0;
DWORD deviceFlags = D3DCREATE_FPU_PRESERVE;
if (dShowMovies) deviceFlags |= D3DCREATE_MULTITHREADED;

dlog("Creating D3D9 Device...", DL_MAIN);
if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | mThreadFlags, &params, &d3d9Device))) { // D3DCREATE_PUREDEVICE
if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | mThreadFlags, &params, &d3d9Device))) {
if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING | deviceFlags, &params, &d3d9Device))) { // D3DCREATE_PUREDEVICE
if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | deviceFlags, &params, &d3d9Device))) {
d3d9Device = nullptr;
dlogr(" Failed!", DL_MAIN);
return;
Expand All @@ -223,7 +224,7 @@ static void ResetDevice(bool create) {
ShaderVersion = ((caps.PixelShaderVersion & 0x0000FF00) >> 8) * 10 + (caps.PixelShaderVersion & 0xFF);

bool npow2 = ((caps.TextureCaps & D3DPTEXTURECAPS_POW2) != 0); //(caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
if (npow2) dlogr("Warning: The graphics card does not support non-power-of-two textures.", DL_MAIN);
if (npow2) dlog("Warning: The graphics card does not support non-power-of-two textures.", DL_MAIN);

// Use: 0 - only CPU, 1 - force GPU, 2 - Auto Mode (GPU or switch to CPU)
if (Graphics::GPUBlt == 2 && ShaderVersion < 20) Graphics::GPUBlt = 0;
Expand Down Expand Up @@ -1028,7 +1029,7 @@ class FakeDirectDraw : IDirectDraw {

HRESULT __stdcall RestoreDisplayMode() { // called from GNW95_reset_mode_
#ifdef NDEBUG
ShowWindow(window, SW_HIDE);
if (!Graphics::IsWindowedMode) ShowWindow(window, SW_HIDE);
#endif
return DD_OK;
}
Expand Down Expand Up @@ -1342,13 +1343,6 @@ static __declspec(naked) void palette_fade_to_hook() {
}
}

//#pragma pack(push, 1)
//struct BMPHEADER {
// BITMAPFILEHEADER bFile;
// BITMAPINFOHEADER bInfo;
//};
//#pragma pack(pop)

long __stdcall SaveScreen(const char* file) {
IDirect3DSurface9* surface;
d3d9Device->CreateOffscreenPlainSurface(gWidth, gHeight, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, 0);
Expand All @@ -1371,61 +1365,6 @@ long __stdcall SaveScreen(const char* file) {
surface->Release();
buffer->Release();

/* BMP 24-bit
long bmpExtraSize = gWidth * 3 % 4;
if (bmpExtraSize != 0) bmpExtraSize = 4 - bmpExtraSize;
DWORD sizeImage = gWidth * gHeight * 3;
sizeImage += gHeight * bmpExtraSize;
BMPHEADER bmpHeader;
std::memset(&bmpHeader, 0, sizeof(BMPHEADER));
bmpHeader.bFile.bfType = 'BM';
bmpHeader.bFile.bfSize = sizeImage + sizeof(BMPHEADER);
bmpHeader.bFile.bfOffBits = sizeof(BMPHEADER);
bmpHeader.bInfo.biSize = sizeof(BITMAPINFOHEADER);
bmpHeader.bInfo.biWidth = gWidth;
bmpHeader.bInfo.biHeight = 0 - gHeight;
bmpHeader.bInfo.biPlanes = 1;
bmpHeader.bInfo.biBitCount = 24;
bmpHeader.bInfo.biCompression = BI_RGB;
bmpHeader.bInfo.biSizeImage = sizeImage;
BYTE* bmpImageData = new BYTE[sizeImage];
BYTE* dData = bmpImageData;
D3DLOCKED_RECT lockRect;
surface->LockRect(&lockRect, 0, 0);
BYTE* lockData = (BYTE*)lockRect.pBits;
// 32-bit to 24-bit
for (size_t h = 0; h < gHeight; h++) {
BYTE* sData = lockData;
for (size_t x = 0; x < gWidth; x++) {
*dData++ = *sData++;
*dData++ = *sData++;
*dData++ = *sData++;
sData++;
}
lockData += lockRect.Pitch;
dData += bmpExtraSize;
}
surface->UnlockRect();
surface->Release();
HANDLE hFile = CreateFileA(file, GENERIC_WRITE, 0, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0);
bool resultOK = (hFile != INVALID_HANDLE_VALUE);
if (resultOK) {
DWORD dwWritten;
WriteFile(hFile, &bmpHeader, sizeof(BMPHEADER), &dwWritten, 0);
WriteFile(hFile, bmpImageData, sizeImage, &dwWritten, 0);
CloseHandle(hFile);
}
delete[] bmpImageData;*/

return (resultOK) ? 0 : 1;
}

Expand Down
2 changes: 1 addition & 1 deletion sfall/Modules/Movies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ bool Movies::DirectShowMovies() {
Graphics::AviMovieWidthFit = (allowDShowMovies >= 2);
MakeJump(0x44E690, gmovie_play_hack);
HookCall(0x44E993, gmovie_play_hook_stop);
/* NOTE: At this address 0x487781 (movieStart_), HRP changes the callback procedure to display mve frames. */
/* NOTE: At this address 0x487781 (movieStart_), HRP by Mash changes the callback procedure to display mve frames. */
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion sfall/Modules/Scripting/Handlers/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void op_get_year(OpcodeContext& ctx) {

void __declspec(naked) op_eax_available() {
__asm {
xor edx, edx
xor edx, edx; // EAX support has been removed since 2.1a
_J_RET_VAL_TYPE(VAR_TYPE_INT);
}
}
Expand Down
2 changes: 1 addition & 1 deletion sfall/Modules/Scripting/Handlers/Misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void op_set_palette(OpcodeContext&);
//numbers subgame functions
void __declspec() op_nb_create_char();

void __declspec() op_hero_select_win() ;
void __declspec() op_hero_select_win();

void __declspec() op_set_hero_style();

Expand Down
4 changes: 2 additions & 2 deletions sfall/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
#define VERSION_MAJOR 3
#define VERSION_MINOR 8
#define VERSION_BUILD 33
#define VERSION_REV 0
#define VERSION_REV 1

#define VERSION_STRING "3.8.33"
#define VERSION_STRING "3.8.33.1"

0 comments on commit b1323fc

Please sign in to comment.