Add 'classic arm model' as an option. (Thanks Daeslender)

This commit is contained in:
UnknownShadow200 2017-08-19 20:37:27 +10:00
parent c97752dcbb
commit c80278857b
9 changed files with 149 additions and 40 deletions

View File

@ -19,6 +19,7 @@ namespace ClassicalSharp.Gui.Screens {
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
@ -29,6 +30,8 @@ namespace ClassicalSharp.Gui.Screens {
protected override void ContextRecreated() {
widgets = new Widget[] {
// Column 1
MakeBool(-1, -150, "Classic arm model", OptionsKey.SimpleArmsAnim,
OnWidgetClick, g => g.ClassicArmModel, (g, v) => g.ClassicArmModel = v),
MakeBool(-1, -100, "Classic arms anim", OptionsKey.SimpleArmsAnim, true,
OnWidgetClick, g => !g.SimpleArmsAnim, (g, v) => g.SimpleArmsAnim = !v),
MakeBool(-1, -50, "Classic gui textures", OptionsKey.UseClassicGui,
@ -39,11 +42,11 @@ namespace ClassicalSharp.Gui.Screens {
OnWidgetClick, g => g.UseClassicOptions, (g, v) => g.UseClassicOptions = v),
// Column 2
MakeBool(1, -100, "Allow custom blocks", OptionsKey.AllowCustomBlocks,
MakeBool(1, -150, "Allow custom blocks", OptionsKey.AllowCustomBlocks,
OnWidgetClick, g => g.AllowCustomBlocks, (g, v) => g.AllowCustomBlocks = v),
MakeBool(1, -50, "Use CPE", OptionsKey.UseCPE,
MakeBool(1, -100, "Use CPE", OptionsKey.UseCPE,
OnWidgetClick, g => g.UseCPE, (g, v) => g.UseCPE = v),
MakeBool(1, 0, "Use server textures", OptionsKey.AllowServerTextures,
MakeBool(1, -50, "Use server textures", OptionsKey.AllowServerTextures,
OnWidgetClick, g => g.AllowServerTextures, (g, v) => g.AllowServerTextures = v),
TextWidget.Create(game, "&eButtons on the right require a client restart", regularFont)

View File

@ -115,10 +115,10 @@ namespace ClassicalSharp.Model {
public ArmModel(Game window) : base(window) { }
public override void CreateParts() {
if (game.ClassicMode) {
if (game.ClassicArmModel) {
// TODO: Position's not quite right.
// Matrix4.Translate(out m, -6 / 16f + 0.2f, -12 / 16f - 0.20f, 0);
// is better, but that breaks the animation
// is better, but that breaks the dig animation
Matrix4.Translate(out m, -6 / 16f, -12 / 16f - 0.10f, 0);
} else {
Matrix4.Translate(out m, -6 / 16f + 0.10f, -12 / 16f - 0.26f, 0);
@ -146,7 +146,7 @@ namespace ClassicalSharp.Model {
part.RotY -= 4 / 16.0f;
Rotate = RotateOrder.YZX;
if (game.ClassicMode) {
if (game.ClassicArmModel) {
DrawRotate(0, -90 * Utils.Deg2Rad, 120 * Utils.Deg2Rad, part, false);
} else {
DrawRotate(-20 * Utils.Deg2Rad, -70 * Utils.Deg2Rad, 135 * Utils.Deg2Rad, part, false);

View File

@ -166,6 +166,7 @@ namespace ClassicalSharp {
UseCPE = Options.GetBool(OptionsKey.UseCPE, true);
SimpleArmsAnim = Options.GetBool(OptionsKey.SimpleArmsAnim, false);
ChatLogging = Options.GetBool(OptionsKey.ChatLogging, true);
ClassicArmModel = Options.GetBool(OptionsKey.ClassicArmModel, ClassicMode);
ViewBobbing = Options.GetBool(OptionsKey.ViewBobbing, true);
FpsLimitMethod method = Options.GetEnum(OptionsKey.FpsLimit, FpsLimitMethod.LimitVSync);

View File

@ -154,6 +154,9 @@ namespace ClassicalSharp {
/// <summary> Whether players should animate using simple swinging parallel to their bodies. </summary>
public bool SimpleArmsAnim;
/// <summary> Whether the arm model should use the classic position. </summary>
public bool ClassicArmModel;
/// <summary> Whether mouse rotation on the y axis should be inverted. </summary>
public bool InvertMouse;

View File

@ -64,6 +64,7 @@ namespace ClassicalSharp {
public const string UseClassicTabList = "nostalgia-classictablist";
public const string UseClassicOptions = "nostalgia-classicoptions";
public const string AllowClassicHacks = "nostalgia-hacks";
public const string ClassicArmModel = "nostalgia-classicarm";
}
public enum FpsLimitMethod {
LimitVSync, Limit30FPS, Limit60FPS, Limit120FPS, LimitNone,

View File

@ -4,15 +4,17 @@
#include "GraphicsEnums.h"
#include "Platform.h"
#include "Window.h"
#include "GraphicsCommon.h"
#ifdef USE_DX
bool d3d9_vsync;
IDirect3D9* d3d;
IDirect3DDevice9* device;
MatrixStack* curStack;
MatrixStack viewStack, projStack, texStack;
DWORD createFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
D3DFORMAT viewFormat, depthFormat;
D3DFORMAT d3d9_viewFormat, d3d9_depthFormat;
#define D3D9_SetRenderState(raw, state, name) \
ReturnCode hresult = IDirect3DDevice9_SetRenderState(device, state, raw); \
@ -66,20 +68,19 @@ void Gfx_Init(void) {
createFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
res = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, winHandle, createFlags, &args, &device);
}
if (!ErrorHandler_Check(res)) {
ErrorHandler_FailWithCode(res, "Failed to create Direct3D9 device");
}
ErrorHandler_CheckOrFail(res, "Creating Direct3D9 device");
viewStack.Type = D3DTS_VIEW;
projStack.Type = D3DTS_PROJECTION;
texStack.Type = D3DTS_TEXTURE0;
SetDefaultRenderStates();
InitDynamicBuffers();
D3D9_SetDefaultRenderStates();
GfxCommon_Init();
}
void Gfx_Free(void) {
UInt8 logMsgBuffer[String_BufferSize(63)];
String logMsg = String_FromRawBuffer(logMsgBuffer, 63);
GfxCommon_Free();
Int32 i;
for (i = 0; i < d3d9_texturesCapacity; i++) {
@ -118,8 +119,8 @@ void D3D9_FindCompatibleFormat(void) {
Int32 count = sizeof(d3d9_viewFormats) / sizeof(d3d9_viewFormats[0]);
Int32 i;
for (i = 0; i < count; i++) {
viewFormat = d3d9_viewFormats[i];
if (IDirect3D9_CheckDeviceType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, viewFormat, viewFormat, true)) break;
d3d9_viewFormat = d3d9_viewFormats[i];
if (IDirect3D9_CheckDeviceType(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3d9_viewFormat, d3d9_viewFormat, true)) break;
if (i == count - 1) {
ErrorHandler_Fail("Unable to create a back buffer with sufficient precision.");
@ -128,8 +129,8 @@ void D3D9_FindCompatibleFormat(void) {
count = sizeof(d3d9_depthFormats) / sizeof(d3d9_depthFormats[0]);
for (i = 0; i < count; i++) {
depthFormat = d3d9_depthFormats[i];
if (IDirect3D9_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, viewFormat, viewFormat, depthFormat)) break;
d3d9_depthFormat = d3d9_depthFormats[i];
if (IDirect3D9_CheckDepthStencilMatch(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, d3d9_viewFormat, d3d9_viewFormat, d3d9_depthFormat)) break;
if (i == count - 1) {
ErrorHandler_Fail("Unable to create a depth buffer with sufficient precision.");
@ -137,20 +138,6 @@ void D3D9_FindCompatibleFormat(void) {
}
}
D3D9_GetPresentArgs(Int32 width, Int32 height, D3DPRESENT_PARAMETERS* args) {
Platform_MemSet(args, 0, sizeof(D3DPRESENT_PARAMETERS));
args->AutoDepthStencilFormat = depthFormat;
args->BackBufferWidth = width;
args->BackBufferHeight = height;
args->BackBufferFormat = viewFormat;
args->BackBufferCount = 1;
args->EnableAutoDepthStencil = true;
args->PresentationInterval = vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
args->SwapEffect = D3DSWAPEFFECT_DISCARD;
args->Windowed = true;
return args;
}
GfxResourceID Gfx_CreateTexture(Bitmap* bmp, bool managedPool) {
IDirect3DTexture9* texture;
@ -247,7 +234,9 @@ void Gfx_SetFogDensity(Real32 value) {
D3D9_SetRenderState(raw, D3DRS_FOGDENSITY, "D3D9_SetFogDensity");
}
Real32 d3d9_fogStart = -1.0f;
void Gfx_SetFogStart(Real32 value) {
d3d9_fogStart = value;
UInt32 raw = *(UInt32*)&value;
D3D9_SetRenderState(raw, D3DRS_FOGSTART, "D3D9_SetFogStart");
}
@ -261,12 +250,12 @@ void Gfx_SetFogEnd(Real32 value) {
D3D9_SetRenderState(raw, D3DRS_FOGEND, "D3D9_SetFogEnd");
}
D3DFOGMODE fogTableMode = D3DFOG_NONE;
D3DFOGMODE d3d9_fogTableMode = D3DFOG_NONE;
void Gfx_SetFogMode(Fog fogMode) {
D3DFOGMODE mode = d3d9_modes[fogMode];
if (mode == fogTableMode) return;
if (mode == d3d9_fogTableMode) return;
fogTableMode = mode;
d3d9_fogTableMode = mode;
D3D9_SetRenderState(mode, D3DRS_FOGTABLEMODE, "D3D9_SetFogMode");
}
@ -288,9 +277,9 @@ D3DCMPFUNC d3d9_alphaTestFunc = 0;
Int32 d3d9_alphaTestRef = 0;
void Gfx_SetAlphaTestFunc(CompareFunc compareFunc, Real32 refValue) {
d3d9_alphaTestFunc = d3d9_compareFuncs[compareFunc];
D3D9_SetRenderState(d3d9_alphaTestFunc, D3DRS_ALPHAFUNC, "D3D9_SetAlphaTestFunc");
D3D9_SetRenderState(d3d9_alphaTestFunc, D3DRS_ALPHAFUNC, "D3D9_SetAlphaTest_Func");
d3d9_alphaTestRef = (Int32)(refValue * 255);
D3D9_SetRenderState2(d3d9_alphaTestRef, D3DRS_ALPHAREF, "D3D9_SetAlphaTestFunc2");
D3D9_SetRenderState2(d3d9_alphaTestRef, D3DRS_ALPHAREF, "D3D9_SetAlphaTest_Ref");
}
bool d3d9_alphaBlend = false;
@ -298,16 +287,16 @@ void Gfx_SetAlphaBlending(bool enabled) {
if (d3d9_alphaBlend == enabled) return;
d3d9_alphaBlend = enabled;
D3D9_SetRenderState((UInt32)enabled, D3DRS_ALPHABLENDENABLE, "D3D9_SetAlphaBlend");
D3D9_SetRenderState((UInt32)enabled, D3DRS_ALPHABLENDENABLE, "D3D9_SetAlphaBlending");
}
D3DBLEND d3d9_srcBlendFunc = 0;
D3DBLEND d3d9_dstBlendFunc = 0;
void Gfx_SetAlphaBlendFunc(BlendFunc srcBlendFunc, BlendFunc dstBlendFunc) {
d3d9_srcBlendFunc = d3d9_blendFuncs[srcBlendFunc];
D3D9_SetRenderState(d3d9_srcBlendFunc, D3DRS_SRCBLEND, "D3D9_SetAlphaBlendFunc");
D3D9_SetRenderState(d3d9_srcBlendFunc, D3DRS_SRCBLEND, "D3D9_SetAlphaBlendFunc_Src");
d3d9_dstBlendFunc = d3d9_blendFuncs[dstBlendFunc];
D3D9_SetRenderState2(d3d9_dstBlendFunc, D3DRS_DESTBLEND, "D3D9_SetAlphaBlendFunc2");
D3D9_SetRenderState2(d3d9_dstBlendFunc, D3DRS_DESTBLEND, "D3D9_SetAlphaBlendFunc_Dst");
}
void Gfx_SetAlphaArgBlend(bool enabled) {
@ -613,4 +602,102 @@ GfxResourceID D3D9_GetOrExpand(void*** resourcesPtr, Int32* capacity, void* reso
newResources[oldLength] = resource;
return oldLength;
}
void Gfx_BeginFrame(void) {
IDirect3DDevice9_BeginScene(device);
}
void Gfx_EndFrame(void) {
IDirect3DDevice9_EndScene(device);
ReturnCode code = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
if (code >= 0) return;
if (code != D3DERR_DEVICELOST) {
ErrorHandler_FailWithCode(code, "D3D9_EndFrame");
}
/* TODO: Make sure this actually works on all graphics cards.*/
String reason = String_FromConstant(" (Direct3D9 device lost)");
GfxCommon_LoseContext(&reason);
D3D9_LoopUntilRetrieved();
D3D9_RecreateDevice();
}
void Gfx_OnWindowResize(void) {
String reason = String_FromConstant(" (resizing window)");
GfxCommon_LoseContext(&reason);
D3D9_RecreateDevice();
}
void D3D9_LoopUntilRetrieved(void) {
ScheduledTask task = new ScheduledTask();
task.Interval = 1.0 / 60;
task.Callback = LostContextFunction;
while (true) {
Platform_ThreadSleep(16);
ReturnCode code = IDirect3DDevice9_TestCooperativeLevel(device);
if (code == D3DERR_DEVICENOTRESET) return;
task.Callback(task);
}
}
void D3D9_GetPresentArgs(Int32 width, Int32 height, D3DPRESENT_PARAMETERS* args) {
Platform_MemSet(args, 0, sizeof(D3DPRESENT_PARAMETERS));
args->AutoDepthStencilFormat = d3d9_depthFormat;
args->BackBufferWidth = width;
args->BackBufferHeight = height;
args->BackBufferFormat = d3d9_viewFormat;
args->BackBufferCount = 1;
args->EnableAutoDepthStencil = true;
args->PresentationInterval = d3d9_vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
args->SwapEffect = D3DSWAPEFFECT_DISCARD;
args->Windowed = true;
}
void D3D9_RecreateDevice(void) {
D3DPRESENT_PARAMETERS args;
Size2D size = Window_GetClientSize();
D3D9_GetPresentArgs(size.Width, size.Height, &args);
while (IDirect3DDevice9_Reset(device, &args) == D3DERR_DEVICELOST) {
D3D9_LoopUntilRetrieved();
}
D3D9_SetDefaultRenderStates();
D3D9_RestoreRenderStates();
GfxCommon_RecreateContext();
}
void D3D9_SetDefaultRenderStates(void) {
Gfx_SetFaceCulling(false);
D3D9_SetRenderState(D3DRS_COLORVERTEX, false, "D3D9_ColorVertex");
D3D9_SetRenderState2(D3DRS_LIGHTING, false, "D3D9_Lighting");
D3D9_SetRenderState2(D3DRS_SPECULARENABLE, false, "D3D9_SpecularEnable");
D3D9_SetRenderState2(D3DRS_LOCALVIEWER, false, "D3D9_LocalViewer");
D3D9_SetRenderState2(D3DRS_DEBUGMONITORTOKEN, false, "D3D9_DebugMonitor");
}
void D3D9_RestoreRenderStates(void) {
UInt32 raw;
D3D9_SetRenderState(D3DRS_ALPHATESTENABLE, d3d9_alphaTest, "D3D9_AlphaTest");
D3D9_SetRenderState2(D3DRS_ALPHABLENDENABLE, d3d9_alphaBlend, "D3D9_AlphaBlend");
D3D9_SetRenderState2(D3DRS_ALPHAFUNC, d3d9_alphaTestFunc, "D3D9_AlphaTestFunc");
D3D9_SetRenderState2(D3DRS_ALPHAREF, d3d9_alphaTestRef, "D3D9_AlphaRefFunc");
D3D9_SetRenderState2(D3DRS_SRCBLEND, d3d9_srcBlendFunc, "D3D9_AlphaSrcBlend");
D3D9_SetRenderState2(D3DRS_DESTBLEND, d3d9_dstBlendFunc, "D3D9_AlphaDstBlend");
D3D9_SetRenderState2(D3DRS_FOGENABLE, d3d9_fogEnable, "D3D9_Fog");
D3D9_SetRenderState2(D3DRS_FOGCOLOR, d3d9_fogCol, "D3D9_FogColor");
D3D9_SetRenderState2(D3DRS_FOGDENSITY, d3d9_fogDensity, "D3D9_FogDensity");
raw = *(UInt32*)&d3d9_fogStart;
D3D9_SetRenderState2(D3DRS_FOGSTART, raw, "D3D9_FogStart");
raw = *(UInt32*)&d3d9_fogEnd;
D3D9_SetRenderState2(D3DRS_FOGEND, raw, "D3D9_FogEnd");
D3D9_SetRenderState2(D3DRS_FOGTABLEMODE, d3d9_fogTableMode, "D3D9_FogMode");
D3D9_SetRenderState2(D3DRS_ZFUNC, d3d9_depthTestFunc, "D3D9_DepthTestFunc");
D3D9_SetRenderState2(D3DRS_ZENABLE, d3d9_depthTest, "D3D9_DepthTest");
D3D9_SetRenderState2(D3DRS_ZWRITEENABLE, d3d9_depthWrite, "D3D9_DepthWrite");
}
#endif

View File

@ -34,8 +34,6 @@ Int32 d3d9_formatMappings[2] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFV
static void D3D9_FindCompatibleFormat(void);
static D3D9_GetPresentArgs(Int32 width, Int32 height, D3DPRESENT_PARAMETERS* args);
static void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp);
static void D3D9_SetVbData(IDirect3DVertexBuffer9* buffer, void* data, Int32 size, const UInt8* lockMsg, const UInt8* unlockMsg, Int32 lockFlags);
@ -48,4 +46,15 @@ static void D3D9_DeleteResource(void** resources, Int32 capacity, GfxResourceID*
static void D3D9_FreeResource(void* resource, GfxResourceID id);
static Int32 D3D9_GetOrExpand(void*** resourcesPtr, Int32* capacity, void* resource, Int32 expSize);
static void D3D9_LoopUntilRetrieved(void);
static void D3D9_GetPresentArgs(Int32 width, Int32 height, D3DPRESENT_PARAMETERS* args);
static void D3D9_RecreateDevice(void);
static void D3D9_SetDefaultRenderStates(void);
static void D3D9_RestoreRenderStates(void);
#endif

View File

@ -63,6 +63,9 @@ bool Game_ShowAxisLines;
/* Whether players should animate using simple swinging parallel to their bodies. */
bool Game_SimpleArmsAnim;
/* Whether the arm model should use the classic position. */
bool Game_ClassicArmModel;
/* Whether mouse rotation on the y axis should be inverted. */
bool Game_InvertMouse;

View File

@ -66,4 +66,6 @@ typedef UInt8 FpsLimitMethod;
#define OptionsKey_UseClassicTabList "nostalgia-classictablist"
#define OptionsKey_UseClassicOptions "nostalgia-classicoptions"
#define OptionsKey_AllowClassicHacks "nostalgia-hacks"
#define OptionsKey_ClassicArmModel "nostalgia-classicarm"
#endif
#endif