less reliant on Block.Invalid

This commit is contained in:
UnknownShadow200 2017-05-05 20:17:12 +10:00
parent 6427db3f25
commit 734f27a9b9
6 changed files with 33 additions and 9 deletions

View file

@ -53,13 +53,13 @@ namespace ClassicalSharp.Commands {
"&e will repeatedly cuboid, without needing to be typed in again.", "&e will repeatedly cuboid, without needing to be typed in again.",
}; };
} }
BlockID block = Block.Invalid; int block = -1;
Vector3I mark1, mark2; Vector3I mark1, mark2;
bool persist = false; bool persist = false;
public override void Execute(string[] args) { public override void Execute(string[] args) {
game.UserEvents.BlockChanged -= BlockChanged; game.UserEvents.BlockChanged -= BlockChanged;
block = Block.Invalid; block = -1;
mark1 = new Vector3I(int.MaxValue); mark1 = new Vector3I(int.MaxValue);
mark2 = new Vector3I(int.MaxValue); mark2 = new Vector3I(int.MaxValue);
persist = false; persist = false;
@ -116,8 +116,8 @@ namespace ClassicalSharp.Commands {
Vector3I max = Vector3I.Max(mark1, mark2); Vector3I max = Vector3I.Max(mark1, mark2);
if (!game.World.IsValidPos(min) || !game.World.IsValidPos(max)) return; if (!game.World.IsValidPos(min) || !game.World.IsValidPos(max)) return;
BlockID toPlace = block; BlockID toPlace = (BlockID)block;
if (toPlace == Block.Invalid) toPlace = game.Inventory.Selected; if (block == -1) toPlace = game.Inventory.Selected;
for (int y = min.Y; y <= max.Y; y++) for (int y = min.Y; y <= max.Y; y++)
for (int z = min.Z; z <= max.Z; z++) for (int z = min.Z; z <= max.Z; z++)

View file

@ -199,6 +199,7 @@
<ClCompile Include="Compiler.c" /> <ClCompile Include="Compiler.c" />
<ClCompile Include="DefaultSet.c" /> <ClCompile Include="DefaultSet.c" />
<ClCompile Include="Bitmap.c" /> <ClCompile Include="Bitmap.c" />
<ClCompile Include="Direct3D9Api.c" />
<ClCompile Include="FastColour.c" /> <ClCompile Include="FastColour.c" />
<ClCompile Include="GraphicsCommon.c" /> <ClCompile Include="GraphicsCommon.c" />
<ClCompile Include="Matrix.c" /> <ClCompile Include="Matrix.c" />

View file

@ -185,5 +185,8 @@
<ClCompile Include="GraphicsCommon.c"> <ClCompile Include="GraphicsCommon.c">
<Filter>Source Files\Graphics</Filter> <Filter>Source Files\Graphics</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Direct3D9Api.c">
<Filter>Source Files\Graphics</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

20
src/Client/Direct3D9Api.c Normal file
View file

@ -0,0 +1,20 @@
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
#include "GraphicsAPI.h"
#include <d3d9.h>
#include <d3d9caps.h>
#include <d3d9types.h>
#define USE_DX true
#ifdef USE_DX
void Gfx_Init(Game* game) {
}
D3DPRIMITIVETYPE modeMappings[2] = { D3DPT_TRIANGLELIST, D3DPT_LINELIST };
D3DFORMAT depthFormats[6] = { D3DFMT_D32, D3DFMT_D24X8, D3DFMT_D24S8, D3DFMT_D24X4S4, D3DFMT_D16, D3DFMT_D15S1 };
D3DFORMAT viewFormats[4] = { D3DFMT_X8R8G8B8, D3DFMT_R8G8B8, D3DFMT_R5G6B5, D3DFMT_X1R5G5B5 };
D3DBLEND blendFuncs[6] = { D3DBLEND_ZERO, D3DBLEND_ONE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, D3DBLEND_DESTALPHA, D3DBLEND_INVDESTALPHA };
D3DCMPFUNC compareFuncs[8] = { D3DCMP_ALWAYS, D3DCMP_NOTEQUAL, D3DCMP_NEVER, D3DCMP_LESS, D3DCMP_LESSEQUAL, D3DCMP_EQUAL, D3DCMP_GREATEREQUAL, D3DCMP_GREATER };
D3DFOGMODE modes[3] = { D3DFOG_LINEAR, D3DFOG_EXP, D3DFOG_EXP2 };
Int32 formatMappings[2] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 };
#endif

View file

@ -13,7 +13,7 @@
/* Initalises this graphics API. */ /* Initalises this graphics API. */
void Gfx_Init(); void Gfx_Init(Game* game);
/* Maximum supported length of a dimension (width and height) of a 2D texture. */ /* Maximum supported length of a dimension (width and height) of a 2D texture. */
Int32 Gfx_MaxTextureDimensions; Int32 Gfx_MaxTextureDimensions;
@ -154,7 +154,7 @@ void Gfx_DrawVb(Int32 drawMode, Int32 startVertex, Int32 vCount);
void Gfx_DrawIndexedVb(Int32 drawMode, Int32 indicesCount, Int32 startIndex); void Gfx_DrawIndexedVb(Int32 drawMode, Int32 indicesCount, Int32 startIndex);
/* Optimised version of DrawIndexedVb for VertexFormat_Pos3fTex2fCol4b */ /* Optimised version of DrawIndexedVb for VertexFormat_Pos3fTex2fCol4b */
void Gfx_DrawIndexedVb_TrisT2fC4b(Int32 indicesCount, Int32 offsetVertex, Int32 startIndex); void Gfx_DrawIndexedVb_TrisT2fC4b_Range(Int32 indicesCount, Int32 offsetVertex, Int32 startIndex);
/* Optimised version of DrawIndexedVb for VertexFormat_Pos3fTex2fCol4b */ /* Optimised version of DrawIndexedVb for VertexFormat_Pos3fTex2fCol4b */
void Gfx_DrawIndexedVb_TrisT2fC4b(Int32 indicesCount, Int32 startIndex); void Gfx_DrawIndexedVb_TrisT2fC4b(Int32 indicesCount, Int32 startIndex);
@ -211,7 +211,7 @@ Max of 32 strings, check if string is included by checking length > 0*/
String Gfx_ApiInfo[32]; String Gfx_ApiInfo[32];
/* Loads an orthographic projection matrix for the given height.*/ /* Loads an orthographic projection matrix for the given height.*/
void LoadOrthoMatrix(float width, float height); void Gfx_LoadOrthoMatrix(Real32 width, Real32 height);
/* Sets the appropriate alpha testing/blending states necessary to render the given block. */ /* Sets the appropriate alpha testing/blending states necessary to render the given block. */
void Gfx_SetupAlphaState(UInt8 draw); void Gfx_SetupAlphaState(UInt8 draw);

View file

@ -19,7 +19,7 @@ void GfxCommon_LoseContext(String reason) {
Platform_Log(reason); Platform_Log(reason);
if (ContextLost != null) ContextLost(); if (ContextLost != null) ContextLost();
GfxCommon_Recreate(); GfxCommon_Free();
} }
void GfxCommon_RecreateContext() { void GfxCommon_RecreateContext() {
@ -75,7 +75,7 @@ void GfxCommon_Draw2DTexture(Texture* tex, FastColour col) {
} }
void GfxCommon_Make2DQuad(Texture* tex, FastColour col, VertexP3fT2fC4b** vertices) { void GfxCommon_Make2DQuad(Texture* tex, FastColour col, VertexP3fT2fC4b** vertices) {
float x1 = tex->X, y1 = tex->Y, x2 = tex->X + tex->Width, y2 = tex->Y + tex->Height; Real32 x1 = tex->X, y1 = tex->Y, x2 = tex->X + tex->Width, y2 = tex->Y + tex->Height;
#if USE_DX #if USE_DX
// NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx", // NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx",
// i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this. // i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this.