Permalink
Browse files

fix matrices not being initalised to Identity in d3d9 backend of C cl…

…ient
  • Loading branch information...
UnknownShadow200 committed Dec 7, 2017
1 parent fe8580a commit 1bcf89b2121183cb837a105af653d89ac028b5b0
Showing with 32 additions and 44 deletions.
  1. +2 −8 ClassicalSharp/Map/WorldEnv.cs
  2. +12 −12 src/Client/D3D9Api.c
  3. +9 −3 src/Client/Entity.c
  4. +7 −5 src/Client/Entity.h
  5. +0 −14 src/Client/Inventory.h
  6. +2 −2 src/Client/World.c
@@ -117,23 +117,17 @@ public sealed class WorldEnv {
/// <summary> Sets sides block to the given block, and raises
/// EnvVariableChanged event with variable 'SidesBlock'. </summary>
public void SetSidesBlock(BlockID block) {
if (block == Block.Invalid) block = Block.Bedrock; // some server software wrongly uses this value
if (block == SidesBlock) return;
if (block == Block.MaxDefinedBlock) {
Utils.LogDebug("Tried to set sides block to an invalid block: " + block);
block = Block.Bedrock;
}
SidesBlock = block;
game.WorldEvents.RaiseEnvVariableChanged(EnvVar.SidesBlock);
}
/// <summary> Sets edge block to the given block, and raises
/// EnvVariableChanged event with variable 'EdgeBlock'. </summary>
public void SetEdgeBlock(BlockID block) {
if (block == Block.Invalid) block = Block.StillWater; // some server software wrongly uses this value
if (block == EdgeBlock) return;
if (block == Block.MaxDefinedBlock) {
Utils.LogDebug("Tried to set edge block to an invalid block: " + block);
block = Block.StillWater;
}
EdgeBlock = block;
game.WorldEvents.RaiseEnvVariableChanged(EnvVar.EdgeBlock);
}
View
@@ -15,11 +15,8 @@
/* Maximum number of matrices that go on a stack. */
#define MatrixStack_Capacity 4
typedef struct MatrixStack_ {
/* Raw array of matrices.*/
Matrix Stack[MatrixStack_Capacity];
/* Current active matrix. */
Int32 Index;
/* Type of transformation this stack is for. */
UInt32 Index;
D3DTRANSFORMSTATETYPE Type;
} MatrixStack;
@@ -29,7 +26,7 @@ D3DFORMAT d3d9_viewFormats[4] = { D3DFMT_X8R8G8B8, D3DFMT_R8G8B8, D3DFMT_R5G6B5,
D3DBLEND d3d9_blendFuncs[6] = { D3DBLEND_ZERO, D3DBLEND_ONE, D3DBLEND_SRCALPHA, D3DBLEND_INVSRCALPHA, D3DBLEND_DESTALPHA, D3DBLEND_INVDESTALPHA };
D3DCMPFUNC d3d9_compareFuncs[8] = { D3DCMP_ALWAYS, D3DCMP_NOTEQUAL, D3DCMP_NEVER, D3DCMP_LESS, D3DCMP_LESSEQUAL, D3DCMP_EQUAL, D3DCMP_GREATEREQUAL, D3DCMP_GREATER };
D3DFOGMODE d3d9_modes[3] = { D3DFOG_LINEAR, D3DFOG_EXP, D3DFOG_EXP2 };
Int32 d3d9_formatMappings[2] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 };
UInt32 d3d9_formatMappings[2] = { D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX2 };
bool d3d9_vsync;
IDirect3D9* d3d;
@@ -139,6 +136,11 @@ void D3D9_RecreateDevice(void) {
GfxCommon_RecreateContext();
}
void MatrixStack_Init(MatrixStack* stack, UInt32 type) {
stack->Type = type;
stack->Stack[0] = Matrix_Identity;
}
void Gfx_Init(void) {
Gfx_MinZNear = 0.05f;
@@ -168,16 +170,14 @@ void Gfx_Init(void) {
Gfx_MaxTextureDimensions = min(caps.MaxTextureWidth, caps.MaxTextureHeight);
Gfx_CustomMipmapsLevels = true;
viewStack.Type = D3DTS_VIEW;
projStack.Type = D3DTS_PROJECTION;
texStack.Type = D3DTS_TEXTURE0;
/* TODO: Can we do this at compile time? */
MatrixStack_Init(&viewStack, D3DTS_VIEW);
MatrixStack_Init(&projStack, D3DTS_PROJECTION);
MatrixStack_Init(&texStack, D3DTS_TEXTURE0);
D3D9_SetDefaultRenderStates();
GfxCommon_Init();
}
void Gfx_Free(void) {
GfxCommon_Free();
}
void Gfx_Free(void) { GfxCommon_Free(); }
void D3D9_SetTextureData(IDirect3DTexture9* texture, Bitmap* bmp, Int32 lvl) {
D3DLOCKED_RECT rect;
View
@@ -12,6 +12,9 @@
#include "GraphicsAPI.h"
#include "Intersection.h"
const UInt8* NameMode_Names[4] = { "Hovered", "All", "AllHovered", "AllUnscaled" };
const UInt8* ShadowMode_Names[4] = { "None", "SnapToBlock", "Circle", "CircleAll" };
Real32 LocationUpdate_Clamp(Real32 degrees) {
degrees = Math_Mod(degrees, 360.0f);
if (degrees < 0) degrees += 360.0f;
@@ -297,9 +300,12 @@ void Entities_Init(void) {
Event_RegisterVoid(&GfxEvents_ContextRecreated, Entities_ContextRecreated);
Event_RegisterVoid(&ChatEvents_FontChanged, Entities_ChatFontChanged);
Entities_NameMode = Options_GetEnum(OptionsKey.NamesMode, NameMode.Hovered);
Entities_NameMode = Options_GetEnum(OptionsKey_NamesMode, NAME_MODE_HOVERED,
NameMode_Names, Array_NumElements(NameMode_Names));
if (Game_ClassicMode) Entities_NameMode = NAME_MODE_HOVERED;
Entities_ShadowMode = Options_GetEnum(OptionsKey.EntityShadow, EntityShadow.None);
Entities_ShadowMode = Options_GetEnum(OptionsKey_EntityShadow, SHADOW_MODE_NONE,
ShadowMode_Names, Array_NumElements(ShadowMode_Names));
if (Game_ClassicMode) Entities_ShadowMode = SHADOW_MODE_NONE;
}
@@ -328,7 +334,7 @@ void Entities_Remove(EntityID id) {
EntityID Entities_GetCloset(Entity* src) {
Vector3 eyePos = Entity_GetEyePosition(src);
Vector3 dir = Vector3_GetDirVector(src->HeadY * MATH_DEG2RAD, src->HeadX * MATH_DEG2RAD);
float closestDist = float.PositiveInfinity;
Real32 closestDist = float.PositiveInfinity;
EntityID targetId = ENTITIES_SELF_ID;
UInt32 i;
View
@@ -28,12 +28,14 @@ UInt32 Entities_NameMode;
#define NAME_MODE_ALL 1
#define NAME_MODE_ALL_HOVERED 2
#define NAME_MODE_ALL_UNSCALED 3
extern const UInt8* NameMode_Names[4];
UInt32 Entities_ShadowMode;
#define SHADOW_MODE_NONE 0
#define SHADOW_MODE_SNAP_TO_BLOCK 1
#define SHADOW_MODE_CIRCLE 2
#define SHADOW_MODE_CIRCLE_ALL 3
extern const UInt8* ShadowMode_Names[4];
typedef bool (*TouchesAny_Condition)(BlockID block);
@@ -62,11 +64,6 @@ typedef struct Entity_ {
Real32 HeadX, HeadY, RotX, RotY, RotZ;
Vector3 Velocity, OldVelocity;
GfxResourceID TextureId, MobTextureId;
AnimatedComp Anim;
UInt8 SkinType;
Real32 uScale, vScale;
IModel* Model;
UInt8 ModelNameRaw[String_BufferSize(ENTITY_MAX_MODEL_LENGTH)];
BlockID ModelBlock; /* BlockID, if model name was originally a vaid block id. */
@@ -75,7 +72,12 @@ typedef struct Entity_ {
Vector3 Size;
Matrix Transform;
UInt8 SkinType;
bool NoShade;
GfxResourceID TextureId, MobTextureId;
Real32 uScale, vScale;
AnimatedComp Anim;
/* TODO: SHOULD THESE BE A SEPARATE VTABLE STRUCT? (only need 1 shared pointer that way) */
void (*Tick)(struct Entity_* entity, ScheduledTask* task);
View
@@ -16,31 +16,17 @@ BlockID Inventory_Table[INVENTORY_HOTBARS * INVENTORY_BLOCKS_PER_HOTBAR];
BlockID Inventory_Map[BLOCK_COUNT];
IGameComponent Inventory_MakeComponent(void);
/* Index of selected block within the current hotbar. */
Int32 Inventory_SelectedIndex;
/* Offset within Inventory_Table for the first block of the current hotbar. */
Int32 Inventory_Offset;
/* Gets block at given index within the current hotbar. */
#define Inventory_Get(idx) (Inventory_Table[Inventory_Offset + (idx)])
/* Sets block at given index within the current hotbar */
#define Inventory_Set(idx, block) Inventory_Table[Inventory_Offset + (idx)] = block
/* Block currently selected by the player. */
#define Inventory_SelectedBlock Inventory_Get(Inventory_SelectedIndex)
/* Whether the player is allowed to change the held / selected block. */
bool Inventory_CanChangeHeldBlock;
/* Gets whether player can change selected block, showing message in chat if not. */
bool Inventory_CanChangeSelected(void);
/* Sets index of the selected block within the current hotbar.
Fails if the server has forbidden user from changing the held block. */
void Inventory_SetSelectedIndex(Int32 index);
/* Sets offset within Inventory_Table for the first block of the current hotbar.
Fails if the server has forbidden user from changing the held block. */
void Inventory_SetOffset(Int32 offset);
/* Sets the block currently selected by the player.
Fails if the server has forbidden user from changing the held block. */
void Inventory_SetSelectedBlock(BlockID block);
/* Sets default mapping for every block. */
void Inventory_SetDefaultMapping(void);
void Inventory_AddDefault(BlockID block);
View
@@ -142,12 +142,12 @@ void WorldEnv_ResetLight(void) {
void WorldEnv_SetEdgeBlock(BlockID block) {
if (block == BLOCK_INVALID) return;
if (block == BLOCK_INVALID) block = BLOCK_STILL_WATER; /* some server software wrongly uses this value */
WorldEnv_Set(block, WorldEnv_EdgeBlock, EnvVar_EdgeBlock);
}
void WorldEnv_SetSidesBlock(BlockID block) {
if (block == BLOCK_INVALID) return;
if (block == BLOCK_INVALID) block = BLOCK_BEDROCK; /* some server software wrongly uses this value */
WorldEnv_Set(block, WorldEnv_SidesBlock, EnvVar_SidesBlock);
}

0 comments on commit 1bcf89b

Please sign in to comment.