diff --git a/src/Client/Client.vcxproj b/src/Client/Client.vcxproj
index 66a64fd1e..c7191dde2 100644
--- a/src/Client/Client.vcxproj
+++ b/src/Client/Client.vcxproj
@@ -207,6 +207,7 @@
+
diff --git a/src/Client/Client.vcxproj.filters b/src/Client/Client.vcxproj.filters
index 265a05251..4185015f1 100644
--- a/src/Client/Client.vcxproj.filters
+++ b/src/Client/Client.vcxproj.filters
@@ -73,6 +73,9 @@
{a912f0d5-3ceb-4e7e-ba4e-28170c634047}
+
+ {03efa5de-9e49-4185-bb40-fa5e5a2846e6}
+
@@ -230,5 +233,8 @@
Source Files\Graphics
+
+ Source Files\Events
+
\ No newline at end of file
diff --git a/src/Client/D3D9Api.h b/src/Client/D3D9Api.h
index fb6abdcb7..e8c7596f1 100644
--- a/src/Client/D3D9Api.h
+++ b/src/Client/D3D9Api.h
@@ -4,6 +4,25 @@
#include
#include
+/* Abstracts Direct3D9 3D graphics rendering API.
+ Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
+*/
+
+/* Maximum number of matrices that go on a stack. */
+#define MatrixStack_Capacity 24
+
+typedef struct MatrixStack {
+
+ /* Raw array of matrices.*/
+ Matrix Stack[MatrixStack_Capacity];
+
+ /* Current active matrix. */
+ Int32 Index;
+
+ /* Type of transformation this stack is for. */
+ D3DTRANSFORMSTATETYPE TransformType;
+} MatrixStack;
+
D3DPRIMITIVETYPE d3d9_modeMappings[2] = { D3DPT_TRIANGLELIST, D3DPT_LINELIST };
D3DFORMAT d3d9_depthFormats[6] = { D3DFMT_D32, D3DFMT_D24X8, D3DFMT_D24S8, D3DFMT_D24X4S4, D3DFMT_D16, D3DFMT_D15S1 };
D3DFORMAT d3d9_viewFormats[4] = { D3DFMT_X8R8G8B8, D3DFMT_R8G8B8, D3DFMT_R5G6B5, D3DFMT_X1R5G5B5 };
diff --git a/src/Client/EventHandler.c b/src/Client/EventHandler.c
new file mode 100644
index 000000000..e94d33c21
--- /dev/null
+++ b/src/Client/EventHandler.c
@@ -0,0 +1,49 @@
+#include "EventHandler.h"
+#include "ErrorHandler.h"
+
+void EventHandler_Register(void** handlers, Int32* count, void* handler) {
+ for (int i = 0; i < *count; i++) {
+ if (handlers[i] == handler) return;
+ }
+
+ if (*count == EventHandler_Size) {
+ ErrorHandler_Fail(String_FromConstant("Unable to add another event handler"));
+ } else {
+ handlers[*count] = handler;
+ *count++;
+ }
+}
+
+void EventHandler_Unregister(void** handlers, Int32* count, void* handler) {
+ for (int i = 0; i < *count; i++) {
+ if (handlers[i] != handler) continue;
+
+ // Remove this event handler from the list
+ for (int j = i; j < *count - 1; j++) {
+ handlers[j] = handlers[j + 1];
+ }
+ handlers[*count - 1] = NULL;
+
+ *count--;
+ return;
+ }
+}
+
+
+void EventHandler_Raise_Void(Event_Void* handlers, Int32 handlersCount) {
+ for (int i = 0; i < handlersCount; i++) {
+ handlers[i]();
+ }
+}
+
+void EventHandler_Raise_Int32(Event_Int32* handlers, Int32 handlersCount, Int32 arg) {
+ for (int i = 0; i < handlersCount; i++) {
+ handlers[i](arg);
+ }
+}
+
+void EventHandler_Raise_Float32(Event_Float32* handlers, Int32 handlersCount, Real32 arg) {
+ for (int i = 0; i < handlersCount; i++) {
+ handlers[i](arg);
+ }
+}
\ No newline at end of file
diff --git a/src/Client/GraphicsAPI.h b/src/Client/GraphicsAPI.h
index 3f6d6f6dd..d50698b39 100644
--- a/src/Client/GraphicsAPI.h
+++ b/src/Client/GraphicsAPI.h
@@ -58,7 +58,7 @@ void Gfx_BindTexture(Int32 texId);
void Gfx_DeleteTexture(Int32* texId);
/* Sets whether texturing is applied when rasterizing primitives. */
-bool Gfx_SetTexturing(bool enabled);
+void Gfx_SetTexturing(bool enabled);
/* Sets whether fog is currently enabled. */
diff --git a/src/Client/Platform.h b/src/Client/Platform.h
index efad12b8f..8f3f1b3c1 100644
--- a/src/Client/Platform.h
+++ b/src/Client/Platform.h
@@ -31,6 +31,9 @@ void Platform_MemCpy(void* dst, void* src, UInt32 numBytes);
/* Logs a message to console (if attached). Implictly puts each entry on a newline. */
void Platform_Log(String message);
+/* Generates a new random uuid / guid. */
+void Platform_NewUuid(UInt8* uuid);
+
/* Returns whether a file with the given name exists. */
bool Platform_FileExists(String path);
diff --git a/src/Client/World.c b/src/Client/World.c
index fc3b83439..ee74ae5f3 100644
--- a/src/Client/World.c
+++ b/src/Client/World.c
@@ -3,11 +3,12 @@
#include "ErrorHandler.h"
#include "String.h"
#include "WorldEnv.h"
+#include "Platform.h"
void World_Reset() {
World_Width = 0; World_Height = 0; World_Length = 0;
World_Blocks = NULL; World_BlocksSize = 0;
- World_Uuid = Guid.NewGuid();
+ Platform_NewUuid(World_Uuid);
}
void World_SetNewMap(BlockID* blocks, Int32 blocksSize, Int32 width, Int32 height, Int32 length) {
@@ -22,8 +23,8 @@ void World_SetNewMap(BlockID* blocks, Int32 blocksSize, Int32 width, Int32 heigh
if (WorldEnv_EdgeHeight == -1) {
WorldEnv_EdgeHeight = height / 2;
}
- if (WorldEnv_CloudHeight == -1) {
- WorldEnv_CloudHeight = height + 2;
+ if (WorldEnv_CloudsHeight == -1) {
+ WorldEnv_CloudsHeight = height + 2;
}
}
diff --git a/src/Client/WorldEvents.h b/src/Client/WorldEvents.h
index 638236e30..d7f8f04d3 100644
--- a/src/Client/WorldEvents.h
+++ b/src/Client/WorldEvents.h
@@ -11,7 +11,8 @@ Event_Void WorldEvents_NewMap[EventHandler_Size];
Int32 WorldEvents_NewMapCount = 0;
/* Raises NewMap event. */
-void WorldEvents_RaiseNewMap();
+#define WorldEvents_RaiseNewMap()\
+EventHandler_Raise_Void(WorldEvents_NewMap, WorldEvents_NewMapCount);
/* Raised when a portion of the world is read and decompressed, or generated.
@@ -20,23 +21,26 @@ Event_Float32 WorldEvents_MapLoading[EventHandler_Size];
Int32 WorldEvents_MapLoadingCount = 0;
/* Raises MapLoading event. */
-void WorldEvents_RaiseMapLoading(Real32 progress);
+#define WorldEvents_RaiseMapLoading(progress)\
+EventHandler_Raise_Float32(WorldEvents_MapLoading, WorldEvents_MapLoadingCount, progress);
/* Raised when new world has finished loading and the player can now interact with it. */
-Event_Void WorldEvents_NewMapLoaded[EventHandler_Size];
-Int32 WorldEvents_NewMapLoadedCount = 0;
+Event_Void WorldEvents_MapLoaded[EventHandler_Size];
+Int32 WorldEvents_MapLoadedCount = 0;
/* Raises NewMapLoaded event. */
-void WorldEvents_RaiseNewMapLoaded();
+#define WorldEvents_RaiseMapLoaded()\
+EventHandler_Raise_Void(WorldEvents_MapLoaded, WorldEvents_MapLoadedCount);
/* Raised when an environment variable of the world is changed by the user, CPE, or WoM config. */
-Event_Int32 WorldEvents_EnvVariableChanged[EventHandler_Size];
-Int32 WorldEvents_EnvVariableChangedCount = 0;
+Event_Int32 WorldEvents_EnvVarChanged[EventHandler_Size];
+Int32 WorldEvents_EnvVarChangedCount = 0;
/* Raises EnvVariableChanged event. */
-void WorldEvents_RaiseEnvVariableChanged(Int32 envVar);
+#define WorldEvents_RaiseEnvVariableChanged(envVar)\
+EventHandler_Raise_Int32(WorldEvents_EnvVarChanged, WorldEvents_EnvVarChangedCount, envVar);
/* Environment variable identifiers*/