mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Removed unnecessary code in Graphics.cpp
Replaced the D3DFMT_A8 texture format with D3DFMT_L8. Minor edits to documents. Updated version number.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
[Highlighting]
|
||||
|
||||
; DX scancode of a key to press to highlight items on the ground
|
||||
; 42 - SHIFT key
|
||||
Key=42
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
;sfall configuration settings
|
||||
;v4.2.8
|
||||
;v4.2.9
|
||||
|
||||
[Main]
|
||||
;Change to 1 if you want to use command line args to tell sfall to use another ini file.
|
||||
@@ -78,7 +78,7 @@ WindowData=0
|
||||
TextureFilter=1
|
||||
|
||||
;Set to 1 to do the palette conversion on the GPU
|
||||
;Set to 2 to do the palette conversion on the CPU
|
||||
;Set to 2 to do the palette conversion on the CPU (used for compatibility with old video cards)
|
||||
;Set to 0 to pick automatically
|
||||
;GPU is faster, but requires v2.0 pixel shader support
|
||||
GPUBlt=0
|
||||
|
||||
@@ -439,7 +439,8 @@ What you can do:
|
||||
- add AP costs for all inventory movement including reloading
|
||||
- apply or remove some special scripted effects depending on PC's armor
|
||||
|
||||
int arg0 - Target slot (0 - main backpack, 1 - left hand, 2 - right hand, 3 - armor slot, 4 - weapon, when reloading it by dropping ammo, 5 - container, like bag/backpack, 6 - dropping on the ground, 7 - picking up item, 8 - dropping item on the character portrait)
|
||||
int arg0 - Target slot (0 - main backpack, 1 - left hand, 2 - right hand, 3 - armor slot, 4 - weapon, when reloading it by dropping ammo, 5 - container, like bag/backpack, 6 - dropping on the ground,
|
||||
7 - picking up item, 8 - dropping item on the character portrait)
|
||||
Item arg1 - Item being moved
|
||||
Item arg2 - Item being replaced, weapon being reloaded, or container being filled (can be 0)
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ was made as a dirty easy hack to allow dynamically change some explosion paramet
|
||||
- changed radius will be reset each time the player reloads the game.
|
||||
|
||||
> array get_explosion_damage(itemPid)
|
||||
- returns array of the minimum and maximum damage of the explosive item.
|
||||
- returns an array of the minimum and maximum damage of the explosive item.
|
||||
|
||||
> void set_dynamite_damage(minDmg, maxDmg)
|
||||
- sets the minimum and maximum damage for Dynamite.
|
||||
@@ -360,7 +360,7 @@ Some utility/math functions are available:
|
||||
- it will include any hidden, dead or system objects (like cursor), so make sure to check properly when iterating
|
||||
|
||||
> array party_member_list(int includeHidden)
|
||||
- returns array of all current party members (0 - only critter-type, alive and visible will be returned, 1 - all object, including Trunk, etc.)
|
||||
- returns an array of all current party members (0 - only critter-type, alive and visible will be returned, 1 - all object, including Trunk, etc.)
|
||||
|
||||
> array path_find_to(object objFrom, int tileTo, int blockingType)
|
||||
- returns the shortest path to a given tile using given blocking function as an array of tile directions (0..5) to move on each step
|
||||
|
||||
+59
-91
@@ -92,19 +92,19 @@ IDirect3DDevice9* d3d9Device = 0;
|
||||
static IDirect3DTexture9* mainTex = 0;
|
||||
static IDirect3DTexture9* sTex1 = 0;
|
||||
static IDirect3DTexture9* sTex2 = 0;
|
||||
static IDirect3DTexture9* movieTex;
|
||||
|
||||
static IDirect3DSurface9* sSurf1 = 0;
|
||||
static IDirect3DSurface9* sSurf2 = 0;
|
||||
static IDirect3DSurface9* backBuffer = 0;
|
||||
|
||||
static IDirect3DVertexBuffer9* vBuffer;
|
||||
static IDirect3DVertexBuffer9* vBuffer2;
|
||||
static IDirect3DVertexBuffer9* movieBuffer;
|
||||
static IDirect3DVertexBuffer9* vertexOrigRes;
|
||||
static IDirect3DVertexBuffer9* vertexSfallRes;
|
||||
static IDirect3DVertexBuffer9* vertexMovie;
|
||||
|
||||
static IDirect3DTexture9* gpuPalette;
|
||||
static IDirect3DTexture9* movieTex;
|
||||
|
||||
static ID3DXEffect* gpuBltEffect;
|
||||
|
||||
static const char* gpuEffect =
|
||||
"texture image;"
|
||||
"texture palette;"
|
||||
@@ -122,30 +122,29 @@ static const char* gpuEffect =
|
||||
|
||||
// shader for displaying head textures
|
||||
"float4 P1( in float2 Tex : TEXCOORD0 ) : COLOR0 {"
|
||||
"float backdrop = tex2D(s0, Tex).a;"
|
||||
"float backdrop = tex2D(s0, Tex).r;"
|
||||
"float3 result;"
|
||||
"if (abs(backdrop - 1.0) < 0.001) {" // (48.0 / 255.0) // 48 - key index color
|
||||
"result = tex2D(s2, saturate((Tex - corner) / size));"
|
||||
"} else {"
|
||||
"result = tex1D(s1, backdrop);"
|
||||
"result = float3(result.b, result.g, result.r);"
|
||||
"result = tex1D(s1, backdrop).bgr;" // get color in palette and swap R <> B
|
||||
"}"
|
||||
// blend highlights
|
||||
"if (showhl) {"
|
||||
"float4 h = tex2D(s3, saturate((Tex - cornerhl) / sizehl));"
|
||||
"result = saturate(result + h);" // saturate(result * (1 - h.a) * h.rgb * h.a)"
|
||||
"}"
|
||||
"return float4(result.r, result.g, result.b, 1);"
|
||||
// blend highlights
|
||||
"if (showhl) {"
|
||||
"float4 h = tex2D(s3, saturate((Tex - cornerhl) / sizehl));"
|
||||
"result = saturate(result + h);" // saturate(result * (1 - h.a) * h.rgb * h.a)"
|
||||
"}"
|
||||
"return float4(result, 1);"
|
||||
"}"
|
||||
|
||||
"technique T1"
|
||||
"{"
|
||||
"pass p1 { PixelShader = compile ps_2_0 P1(); }"
|
||||
"}"
|
||||
|
||||
// main shader
|
||||
"float4 P0( in float2 Tex : TEXCOORD0 ) : COLOR0 {"
|
||||
"float3 result = tex1D(s1, tex2D(s0, Tex).a);" // get color in palette
|
||||
"return float4(result.b, result.g, result.r, 1);" // swap R <> B
|
||||
"float3 result = tex1D(s1, tex2D(s0, Tex).r);" // get color in palette
|
||||
"return float4(result.bgr, 1);" // swap R <> B
|
||||
"}"
|
||||
|
||||
"technique T0"
|
||||
@@ -279,10 +278,10 @@ static void ResetDevice(bool createNew) {
|
||||
mainTexLock = false;
|
||||
}
|
||||
|
||||
if (d3d9Device->CreateTexture(ResWidth, ResHeight, 1, D3DUSAGE_DYNAMIC, Graphics::GPUBlt ? D3DFMT_A8 : D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &mainTex, 0) != D3D_OK) {
|
||||
if (d3d9Device->CreateTexture(ResWidth, ResHeight, 1, D3DUSAGE_DYNAMIC, Graphics::GPUBlt ? D3DFMT_L8 : D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &mainTex, 0) != D3D_OK) { // D3DFMT_A8 - not supported on some older video cards
|
||||
d3d9Device->CreateTexture(ResWidth, ResHeight, 1, D3DUSAGE_DYNAMIC, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &mainTex, 0);
|
||||
Graphics::GPUBlt = 0;
|
||||
MessageBoxA(window, "GPU does not support the D3DFMT_A8 texture format.\nNow CPU is used to convert the palette.",
|
||||
MessageBoxA(window, "GPU does not support the D3DFMT_L8 texture format.\nNow CPU is used to convert the palette.",
|
||||
"Texture format error", MB_TASKMODAL | MB_ICONWARNING);
|
||||
}
|
||||
|
||||
@@ -304,11 +303,11 @@ static void ResetDevice(bool createNew) {
|
||||
ShaderVertices[3].y = ResHeight - 0.5f;
|
||||
ShaderVertices[3].x = ResWidth - 0.5f;
|
||||
|
||||
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vBuffer, 0);
|
||||
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vertexOrigRes, 0);
|
||||
void* vertexPointer;
|
||||
vBuffer->Lock(0, 0, &vertexPointer, 0);
|
||||
vertexOrigRes->Lock(0, 0, &vertexPointer, 0);
|
||||
CopyMemory(vertexPointer, ShaderVertices, sizeof(ShaderVertices));
|
||||
vBuffer->Unlock();
|
||||
vertexOrigRes->Unlock();
|
||||
|
||||
VertexFormat shaderVertices[4] = {
|
||||
ShaderVertices[0],
|
||||
@@ -322,16 +321,16 @@ static void ResetDevice(bool createNew) {
|
||||
shaderVertices[3].y = (float)gHeight - 0.5f;
|
||||
shaderVertices[3].x = (float)gWidth - 0.5f;
|
||||
|
||||
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vBuffer2, 0);
|
||||
vBuffer2->Lock(0, 0, &vertexPointer, 0);
|
||||
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vertexSfallRes, 0);
|
||||
vertexSfallRes->Lock(0, 0, &vertexPointer, 0);
|
||||
CopyMemory(vertexPointer, shaderVertices, sizeof(shaderVertices));
|
||||
vBuffer2->Unlock();
|
||||
vertexSfallRes->Unlock();
|
||||
|
||||
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &movieBuffer, 0);
|
||||
d3d9Device->CreateVertexBuffer(4 * sizeof(VertexFormat), D3DUSAGE_WRITEONLY | (software ? D3DUSAGE_SOFTWAREPROCESSING : 0), _VERTEXFORMAT, D3DPOOL_DEFAULT, &vertexMovie, 0);
|
||||
|
||||
d3d9Device->SetFVF(_VERTEXFORMAT);
|
||||
d3d9Device->SetTexture(0, mainTex);
|
||||
d3d9Device->SetStreamSource(0, vBuffer, 0, sizeof(VertexFormat));
|
||||
d3d9Device->SetStreamSource(0, vertexOrigRes, 0, sizeof(VertexFormat));
|
||||
|
||||
//d3d9Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false); // default false
|
||||
//d3d9Device->SetRenderState(D3DRS_ALPHATESTENABLE, false); // default false
|
||||
@@ -403,9 +402,9 @@ static void Present() {
|
||||
SAFERELEASE(sSurf2);
|
||||
SAFERELEASE(sTex1);
|
||||
SAFERELEASE(sTex2);
|
||||
SAFERELEASE(vBuffer);
|
||||
SAFERELEASE(vBuffer2);
|
||||
SAFERELEASE(movieBuffer);
|
||||
SAFERELEASE(vertexOrigRes);
|
||||
SAFERELEASE(vertexSfallRes);
|
||||
SAFERELEASE(vertexMovie);
|
||||
SAFERELEASE(gpuPalette);
|
||||
Graphics::ReleaseMovieTexture();
|
||||
if (gpuBltEffect) gpuBltEffect->OnLostDevice();
|
||||
@@ -417,37 +416,32 @@ static void Refresh() {
|
||||
if (DeviceLost) return;
|
||||
|
||||
d3d9Device->BeginScene();
|
||||
d3d9Device->SetStreamSource(0, vBuffer, 0, sizeof(VertexFormat));
|
||||
d3d9Device->SetStreamSource(0, vertexOrigRes, 0, sizeof(VertexFormat));
|
||||
d3d9Device->SetRenderTarget(0, sSurf1);
|
||||
d3d9Device->SetTexture(0, mainTex);
|
||||
|
||||
UINT passes;
|
||||
if ((textureFilter || ScriptShaders::Count()) && Graphics::GPUBlt) {
|
||||
if (Graphics::GPUBlt) {
|
||||
// converts the palette in mainTex to RGB colors on the target surface (sSurf1/sTex1)
|
||||
gpuBltEffect->Begin(&passes, 0);
|
||||
gpuBltEffect->BeginPass(0);
|
||||
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
gpuBltEffect->EndPass();
|
||||
gpuBltEffect->End();
|
||||
|
||||
d3d9Device->StretchRect(sSurf1, 0, sSurf2, 0, D3DTEXF_NONE); // copy sSurf1 to sSurf2
|
||||
d3d9Device->SetTexture(0, sTex2);
|
||||
} else {
|
||||
d3d9Device->SetTexture(0, mainTex);
|
||||
if (ScriptShaders::Count()) {
|
||||
d3d9Device->StretchRect(sSurf1, 0, sSurf2, 0, D3DTEXF_NONE); // copy sSurf1 to sSurf2
|
||||
d3d9Device->SetTexture(0, sTex2);
|
||||
} else {
|
||||
d3d9Device->SetTexture(0, sTex1);
|
||||
}
|
||||
}
|
||||
ScriptShaders::Refresh(sSurf1, sSurf2, sTex2);
|
||||
|
||||
d3d9Device->SetStreamSource(0, vBuffer2, 0, sizeof(VertexFormat));
|
||||
d3d9Device->SetStreamSource(0, vertexSfallRes, 0, sizeof(VertexFormat));
|
||||
d3d9Device->SetRenderTarget(0, backBuffer);
|
||||
|
||||
if (!textureFilter && !ScriptShaders::Count() && Graphics::GPUBlt) {
|
||||
gpuBltEffect->Begin(&passes, 0);
|
||||
gpuBltEffect->BeginPass(0);
|
||||
}
|
||||
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
if (!textureFilter && !ScriptShaders::Count() && Graphics::GPUBlt) {
|
||||
gpuBltEffect->EndPass();
|
||||
gpuBltEffect->End();
|
||||
}
|
||||
|
||||
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); // render square with a texture image (mainTex/sTex1/sTex2) to the backBuffer
|
||||
d3d9Device->EndScene();
|
||||
Present();
|
||||
}
|
||||
@@ -530,9 +524,9 @@ void Graphics::SetMovieTexture(bool state) {
|
||||
}
|
||||
|
||||
void* vertexPointer;
|
||||
movieBuffer->Lock(0, 0, &vertexPointer, 0);
|
||||
vertexMovie->Lock(0, 0, &vertexPointer, 0);
|
||||
CopyMemory(vertexPointer, shaderVertices, sizeof(shaderVertices));
|
||||
movieBuffer->Unlock();
|
||||
vertexMovie->Unlock();
|
||||
|
||||
PlayAviMovie = true;
|
||||
}
|
||||
@@ -550,7 +544,7 @@ void Graphics::ShowMovieFrame(IDirect3DTexture9* tex) {
|
||||
} else {
|
||||
d3d9Device->SetTexture(0, mainTex);
|
||||
}
|
||||
d3d9Device->SetStreamSource(0, vBuffer2, 0, sizeof(VertexFormat));
|
||||
d3d9Device->SetStreamSource(0, vertexSfallRes, 0, sizeof(VertexFormat));
|
||||
|
||||
// for showing subtitles
|
||||
if (Graphics::GPUBlt) {
|
||||
@@ -566,7 +560,7 @@ void Graphics::ShowMovieFrame(IDirect3DTexture9* tex) {
|
||||
}
|
||||
// for avi movie
|
||||
d3d9Device->SetTexture(0, movieTex);
|
||||
d3d9Device->SetStreamSource(0, movieBuffer, 0, sizeof(VertexFormat));
|
||||
d3d9Device->SetStreamSource(0, vertexMovie, 0, sizeof(VertexFormat));
|
||||
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
|
||||
d3d9Device->EndScene();
|
||||
@@ -690,38 +684,7 @@ public:
|
||||
//mainTexLock = false;
|
||||
//if (Graphics::PlayAviMovie) return DD_OK; // Blt method is not executed during avi playback because the sfShowFrame_ function is blocked
|
||||
|
||||
if (!DeviceLost) {
|
||||
d3d9Device->SetTexture(0, mainTex);
|
||||
|
||||
d3d9Device->BeginScene();
|
||||
UINT passes;
|
||||
if (textureFilter && Graphics::GPUBlt) { // fixes color palette distortion of movie images when texture filtering and GPUBlt are enabled
|
||||
d3d9Device->SetStreamSource(0, vBuffer, 0, sizeof(VertexFormat));
|
||||
d3d9Device->SetRenderTarget(0, sSurf1);
|
||||
|
||||
gpuBltEffect->Begin(&passes, 0);
|
||||
gpuBltEffect->BeginPass(0);
|
||||
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
gpuBltEffect->EndPass();
|
||||
gpuBltEffect->End();
|
||||
|
||||
d3d9Device->SetTexture(0, sTex1);
|
||||
d3d9Device->SetRenderTarget(0, backBuffer);
|
||||
}
|
||||
d3d9Device->SetStreamSource(0, vBuffer2, 0, sizeof(VertexFormat));
|
||||
|
||||
if (!textureFilter && Graphics::GPUBlt) {
|
||||
gpuBltEffect->Begin(&passes, 0);
|
||||
gpuBltEffect->BeginPass(0);
|
||||
}
|
||||
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
||||
if (!textureFilter && Graphics::GPUBlt) {
|
||||
gpuBltEffect->EndPass();
|
||||
gpuBltEffect->End();
|
||||
}
|
||||
d3d9Device->EndScene();
|
||||
Present();
|
||||
}
|
||||
Refresh();
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
@@ -799,12 +762,12 @@ public:
|
||||
mainTexLock = true;
|
||||
|
||||
D3DLOCKED_RECT dRect;
|
||||
mainTex->LockRect(0, &dRect, 0, 0);
|
||||
mainTex->LockRect(0, &dRect, 0, D3DLOCK_DISCARD);
|
||||
|
||||
DWORD* pBits = (DWORD*)dRect.pBits;
|
||||
int pitch = (dRect.Pitch / 4) - ResWidth;
|
||||
|
||||
BYTE* target = lockTarget;
|
||||
|
||||
int height = ResHeight;
|
||||
while (height--) {
|
||||
int width = ResWidth;
|
||||
@@ -815,6 +778,7 @@ public:
|
||||
}
|
||||
pBits += pitch;
|
||||
}
|
||||
|
||||
mainTex->UnlockRect(0);
|
||||
mainTexLock = false;
|
||||
return DD_OK;
|
||||
@@ -836,7 +800,7 @@ public:
|
||||
mainTexLock = true;
|
||||
|
||||
D3DLOCKED_RECT dRect;
|
||||
mainTex->LockRect(0, &dRect, lockRect, 0);
|
||||
mainTex->LockRect(0, &dRect, lockRect, (lockRect) ? 0 : D3DLOCK_DISCARD);
|
||||
|
||||
DWORD* pBits = (DWORD*)dRect.pBits;
|
||||
int pitch = dRect.Pitch / 4;
|
||||
@@ -845,16 +809,20 @@ public:
|
||||
BYTE* target = (BYTE*)lockSurface;
|
||||
int width = (lockRect->right - lockRect->left);
|
||||
int height = (lockRect->bottom - lockRect->top);
|
||||
|
||||
while (height--) {
|
||||
int w = width;
|
||||
while (w--) pBits[w] = palette[target[w]].xRGB;
|
||||
pBits += pitch;
|
||||
target += ResWidth;
|
||||
}
|
||||
|
||||
lockRect = 0;
|
||||
} else {
|
||||
pitch -= ResWidth;
|
||||
BYTE* target = lockTarget;
|
||||
int height = ResHeight;
|
||||
|
||||
// slow copy method
|
||||
while (height--) {
|
||||
int width = ResWidth;
|
||||
@@ -923,7 +891,7 @@ public:
|
||||
|
||||
if (Graphics::GPUBlt) {
|
||||
D3DLOCKED_RECT rect;
|
||||
if (gpuPalette && !FAILED(gpuPalette->LockRect(0, &rect, 0, D3DLOCK_DISCARD))) {
|
||||
if (!FAILED(gpuPalette->LockRect(0, &rect, 0, D3DLOCK_DISCARD))) {
|
||||
CopyMemory(rect.pBits, palette, 256 * 4);
|
||||
gpuPalette->UnlockRect(0);
|
||||
}
|
||||
@@ -934,7 +902,7 @@ public:
|
||||
palette[i].B = palette[i].R;
|
||||
palette[i].R = clr;
|
||||
}
|
||||
primaryDDSurface->SetPalette(0); // update
|
||||
primaryDDSurface->SetPalette(0); // update texture
|
||||
if (FakeDirectDrawSurface::IsPlayMovie) return DD_OK; // prevents flickering at the beginning of playback (w/o HRP & GPUBlt=2)
|
||||
}
|
||||
if (!Graphics::PlayAviMovie) {
|
||||
@@ -969,13 +937,13 @@ public:
|
||||
SAFERELEASE(mainTex);
|
||||
SAFERELEASE(sTex1);
|
||||
SAFERELEASE(sTex2);
|
||||
SAFERELEASE(vBuffer);
|
||||
SAFERELEASE(vBuffer2);
|
||||
SAFERELEASE(vertexOrigRes);
|
||||
SAFERELEASE(vertexSfallRes);
|
||||
SAFERELEASE(d3d9Device);
|
||||
SAFERELEASE(d3d9);
|
||||
SAFERELEASE(gpuPalette);
|
||||
SAFERELEASE(gpuBltEffect);
|
||||
SAFERELEASE(movieBuffer);
|
||||
SAFERELEASE(vertexMovie);
|
||||
|
||||
delete this;
|
||||
return 0;
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@
|
||||
|
||||
#define VERSION_MAJOR 4
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_BUILD 8
|
||||
#define VERSION_REV 1
|
||||
#define VERSION_BUILD 9
|
||||
#define VERSION_REV 0
|
||||
|
||||
#define VERSION_STRING "4.2.8.1"
|
||||
#define VERSION_STRING "4.2.9"
|
||||
|
||||
Reference in New Issue
Block a user