Completely redesign the C event handling.

This commit is contained in:
UnknownShadow200 2017-08-15 13:17:51 +10:00
parent 89e5b4e770
commit 91d33a9136
21 changed files with 358 additions and 459 deletions

View file

@ -8,6 +8,7 @@
#include "PackedCol.h"
#include "Camera.h"
#include "LocalPlayer.h"
#include "Events.h"
GfxResourceID axisLines_vb = -1;
#define axisLines_numVertices 12
@ -54,12 +55,12 @@ void AxisLinesRenderer_Render(Real64 delta) {
void AxisLinesRenderer_Init(void) {
EventHandler_RegisterVoid(Gfx_ContextLost, AxisLinesRenderer_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextLost, AxisLinesRenderer_ContextLost);
}
void AxisLinesRenderer_Free(void) {
AxisLinesRenderer_ContextLost();
EventHandler_UnregisterVoid(Gfx_ContextLost, AxisLinesRenderer_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextLost, AxisLinesRenderer_ContextLost);
}
void AxisLinesRenderer_ContextLost(void) {

View file

@ -76,20 +76,20 @@ void BordersRenderer_RenderEdges(Real64 delta) {
void BordersRenderer_Init(void) {
EventHandler_RegisterInt32(WorldEvents_EnvVarChanged, BordersRenderer_EnvVariableChanged);
EventHandler_RegisterVoid(GfxEvents_ViewDistanceChanged, BordersRenderer_ResetSidesAndEdges);
EventHandler_RegisterVoid(TextureEvents_AtlasChanged, BordersRenderer_ResetTextures);
EventHandler_RegisterVoid(Gfx_ContextLost, BordersRenderer_ContextLost);
EventHandler_RegisterVoid(Gfx_ContextRecreated, BordersRenderer_ContextRecreated);
Event_RegisterInt32(&WorldEvents_EnvVarChanged, BordersRenderer_EnvVariableChanged);
Event_RegisterVoid(&GfxEvents_ViewDistanceChanged, BordersRenderer_ResetSidesAndEdges);
Event_RegisterVoid(&TextureEvents_AtlasChanged, BordersRenderer_ResetTextures);
Event_RegisterVoid(&GfxEvents_ContextLost, BordersRenderer_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, BordersRenderer_ContextRecreated);
}
void BordersRenderer_Free(void) {
BordersRenderer_ContextLost();
EventHandler_UnregisterInt32(WorldEvents_EnvVarChanged, BordersRenderer_EnvVariableChanged);
EventHandler_UnregisterVoid(GfxEvents_ViewDistanceChanged, BordersRenderer_ResetSidesAndEdges);
EventHandler_UnregisterVoid(TextureEvents_AtlasChanged, BordersRenderer_ResetTextures);
EventHandler_UnregisterVoid(Gfx_ContextLost, BordersRenderer_ContextLost);
EventHandler_UnregisterVoid(Gfx_ContextRecreated, BordersRenderer_ContextRecreated);
Event_UnregisterInt32(&WorldEvents_EnvVarChanged, BordersRenderer_EnvVariableChanged);
Event_UnregisterVoid(&GfxEvents_ViewDistanceChanged, BordersRenderer_ResetSidesAndEdges);
Event_UnregisterVoid(&TextureEvents_AtlasChanged, BordersRenderer_ResetTextures);
Event_UnregisterVoid(&GfxEvents_ContextLost, BordersRenderer_ContextLost);
Event_UnregisterVoid(&GfxEvents_ContextRecreated, BordersRenderer_ContextRecreated);
}
void BordersRenderer_Reset(void) {

View file

@ -24,32 +24,32 @@ Int32 cu_atlas1DCount;
Int32 cu_elementsPerBitmap;
void ChunkUpdater_Init(void) {
EventHandler_RegisterVoid(TextureEvents_AtlasChanged, ChunkUpdater_TerrainAtlasChanged);
EventHandler_RegisterVoid(WorldEvents_NewMap, ChunkUpdater_OnNewMap);
EventHandler_RegisterVoid(WorldEvents_MapLoaded, ChunkUpdater_OnNewMapLoaded);
EventHandler_RegisterInt32(WorldEvents_EnvVarChanged, ChunkUpdater_EnvVariableChanged);
Event_RegisterVoid(&TextureEvents_AtlasChanged, ChunkUpdater_TerrainAtlasChanged);
Event_RegisterVoid(&WorldEvents_NewMap, ChunkUpdater_OnNewMap);
Event_RegisterVoid(&WorldEvents_MapLoaded, ChunkUpdater_OnNewMapLoaded);
Event_RegisterInt32(&WorldEvents_EnvVarChanged, ChunkUpdater_EnvVariableChanged);
EventHandler_RegisterVoid(BlockEvents_BlockDefChanged, ChunkUpdater_BlockDefinitionChanged);
EventHandler_RegisterVoid(GfxEvents_ViewDistanceChanged, ChunkUpdater_ViewDistanceChanged);
EventHandler_RegisterVoid(GfxEvents_ProjectionChanged, ChunkUpdater_ProjectionChanged);
EventHandler_RegisterVoid(Gfx_ContextLost, ChunkUpdater_ClearChunkCache);
EventHandler_RegisterVoid(Gfx_ContextRecreated, ChunkUpdater_Refresh);
Event_RegisterVoid(&BlockEvents_BlockDefChanged, ChunkUpdater_BlockDefinitionChanged);
Event_RegisterVoid(&GfxEvents_ViewDistanceChanged, ChunkUpdater_ViewDistanceChanged);
Event_RegisterVoid(&GfxEvents_ProjectionChanged, ChunkUpdater_ProjectionChanged);
Event_RegisterVoid(&GfxEvents_ContextLost, ChunkUpdater_ClearChunkCache);
Event_RegisterVoid(&GfxEvents_ContextRecreated, ChunkUpdater_Refresh);
ChunkUpdater_ChunkPos = Vector3I_Create1(Int32_MaxValue);
ChunkUpdater_ApplyMeshBuilder();
}
void ChunkUpdater_Free(void) {
EventHandler_UnregisterVoid(TextureEvents_AtlasChanged, ChunkUpdater_TerrainAtlasChanged);
EventHandler_UnregisterVoid(WorldEvents_NewMap, ChunkUpdater_OnNewMap);
EventHandler_UnregisterVoid(WorldEvents_MapLoaded, ChunkUpdater_OnNewMapLoaded);
EventHandler_UnregisterInt32(WorldEvents_EnvVarChanged, ChunkUpdater_EnvVariableChanged);
Event_UnregisterVoid(&TextureEvents_AtlasChanged, ChunkUpdater_TerrainAtlasChanged);
Event_UnregisterVoid(&WorldEvents_NewMap, ChunkUpdater_OnNewMap);
Event_UnregisterVoid(&WorldEvents_MapLoaded, ChunkUpdater_OnNewMapLoaded);
Event_UnregisterInt32(&WorldEvents_EnvVarChanged, ChunkUpdater_EnvVariableChanged);
EventHandler_UnregisterVoid(BlockEvents_BlockDefChanged, ChunkUpdater_BlockDefinitionChanged);
EventHandler_UnregisterVoid(GfxEvents_ViewDistanceChanged, ChunkUpdater_ViewDistanceChanged);
EventHandler_UnregisterVoid(GfxEvents_ProjectionChanged, ChunkUpdater_ProjectionChanged);
EventHandler_UnregisterVoid(Gfx_ContextLost, ChunkUpdater_ClearChunkCache);
EventHandler_UnregisterVoid(Gfx_ContextRecreated, ChunkUpdater_Refresh);
Event_UnregisterVoid(&BlockEvents_BlockDefChanged, ChunkUpdater_BlockDefinitionChanged);
Event_UnregisterVoid(&GfxEvents_ViewDistanceChanged, ChunkUpdater_ViewDistanceChanged);
Event_UnregisterVoid(&GfxEvents_ProjectionChanged, ChunkUpdater_ProjectionChanged);
Event_UnregisterVoid(&Gfx_ContextLost, ChunkUpdater_ClearChunkCache);
Event_UnregisterVoid(&Gfx_ContextRecreated, ChunkUpdater_Refresh);
ChunkUpdater_OnNewMap();
}

View file

@ -191,9 +191,10 @@
<ClInclude Include="DisplayDevice.h" />
<ClInclude Include="Drawer.h" />
<ClInclude Include="Entity.h" />
<ClInclude Include="EntityEvents.h" />
<ClInclude Include="EnvRenderer.h" />
<ClInclude Include="ErrorHandler.h" />
<ClInclude Include="Event.h" />
<ClInclude Include="Events.h" />
<ClInclude Include="FlatgrassGenerator.h" />
<ClInclude Include="FrustumCulling.h" />
<ClInclude Include="GameProps.h" />
@ -209,7 +210,6 @@
<ClInclude Include="LocationUpdate.h" />
<ClInclude Include="MapGenerator.h" />
<ClInclude Include="MapRenderer.h" />
<ClInclude Include="MiscEvents.h" />
<ClInclude Include="ModelBuilder.h" />
<ClInclude Include="ModelCache.h" />
<ClInclude Include="NetworkEnums.h" />
@ -231,8 +231,6 @@
<ClInclude Include="TiltComp.h" />
<ClInclude Include="TreeGen.h" />
<ClInclude Include="WeatherRenderer.h" />
<ClInclude Include="WorldEvents.h" />
<ClInclude Include="EventHandler.h" />
<ClInclude Include="PackedCol.h" />
<ClInclude Include="Funcs.h" />
<ClInclude Include="Game.h" />
@ -275,7 +273,7 @@
<ClCompile Include="DisplayDevice.c" />
<ClCompile Include="Drawer.c" />
<ClCompile Include="EnvRenderer.c" />
<ClCompile Include="EventHandler.c" />
<ClCompile Include="Event.c" />
<ClCompile Include="ExtMath.c" />
<ClCompile Include="FlatgrassGenerator.c" />
<ClCompile Include="FrustumCulling.c" />

View file

@ -228,12 +228,6 @@
<ClInclude Include="D3D9Api.h">
<Filter>Header Files\Graphics</Filter>
</ClInclude>
<ClInclude Include="EventHandler.h">
<Filter>Header Files\Events</Filter>
</ClInclude>
<ClInclude Include="WorldEvents.h">
<Filter>Header Files\Events</Filter>
</ClInclude>
<ClInclude Include="Funcs.h">
<Filter>Header Files\Utils</Filter>
</ClInclude>
@ -264,12 +258,6 @@
<ClInclude Include="Intersection.h">
<Filter>Header Files\Math</Filter>
</ClInclude>
<ClInclude Include="EntityEvents.h">
<Filter>Header Files\Events</Filter>
</ClInclude>
<ClInclude Include="MiscEvents.h">
<Filter>Header Files\Events</Filter>
</ClInclude>
<ClInclude Include="Camera.h">
<Filter>Header Files\Utils</Filter>
</ClInclude>
@ -411,6 +399,12 @@
<ClInclude Include="DisplayDevice.h">
<Filter>Header Files\Platform\Window</Filter>
</ClInclude>
<ClInclude Include="Event.h">
<Filter>Header Files\Events</Filter>
</ClInclude>
<ClInclude Include="Events.h">
<Filter>Header Files\Events</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="NotchyGenerator.c">
@ -461,9 +455,6 @@
<ClCompile Include="D3D9Api.c">
<Filter>Source Files\Graphics</Filter>
</ClCompile>
<ClCompile Include="EventHandler.c">
<Filter>Source Files\Events</Filter>
</ClCompile>
<ClCompile Include="VertexStructs.c">
<Filter>Source Files\Math</Filter>
</ClCompile>
@ -626,5 +617,8 @@
<ClCompile Include="DisplayDevice.c">
<Filter>Source Files\Platform\Window</Filter>
</ClCompile>
<ClCompile Include="Event.c">
<Filter>Source Files\Events</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -99,10 +99,10 @@ void EnvRenderer_EnvVariableChanged(EnvVar envVar) {
void EnvRenderer_Init(void) {
EnvRenderer_ResetAllEnv();
EventHandler_RegisterVoid(GfxEvents_ViewDistanceChanged, EnvRenderer_ResetAllEnv);
EventHandler_RegisterVoid(Gfx_ContextLost, EnvRenderer_ContextLost);
EventHandler_RegisterVoid(Gfx_ContextRecreated, EnvRenderer_ContextRecreated);
EventHandler_RegisterInt32(WorldEvents_EnvVarChanged, EnvRenderer_EnvVariableChanged);
Event_RegisterVoid(&GfxEvents_ViewDistanceChanged, EnvRenderer_ResetAllEnv);
Event_RegisterVoid(&GfxEvents_ContextLost, EnvRenderer_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, EnvRenderer_ContextRecreated);
Event_RegisterInt32(&WorldEvents_EnvVarChanged, EnvRenderer_EnvVariableChanged);
Game_SetViewDistance(Game_UserViewDistance, false);
}
@ -123,10 +123,10 @@ void EnvRenderer_ResetAllEnv(void) {
void EnvRenderer_Free(void) {
EnvRenderer_ContextLost();
EventHandler_UnregisterVoid(GfxEvents_ViewDistanceChanged, EnvRenderer_ResetAllEnv);
EventHandler_UnregisterVoid(Gfx_ContextLost, EnvRenderer_ContextLost);
EventHandler_UnregisterVoid(Gfx_ContextRecreated, EnvRenderer_ContextRecreated);
EventHandler_UnregisterInt32(WorldEvents_EnvVarChanged, EnvRenderer_EnvVariableChanged);
Event_UnregisterVoid(&GfxEvents_ViewDistanceChanged, EnvRenderer_ResetAllEnv);
Event_UnregisterVoid(&Gfx_ContextLost, EnvRenderer_ContextLost);
Event_UnregisterVoid(&Gfx_ContextRecreated, EnvRenderer_ContextRecreated);
Event_UnregisterInt32(&WorldEvents_EnvVarChanged, EnvRenderer_EnvVariableChanged);
}
void EnvRenderer_ContextLost(void) {

112
src/Client/Event.c Normal file
View file

@ -0,0 +1,112 @@
#include "Event.h"
#include "ErrorHandler.h"
void Event_RegisterImpl(Event_Void* handlers, Event_Void_Callback handler) {
Int32 i;
for (i = 0; i < handlers->Count; i++) {
if (handlers->Handlers[i] == handler) return;
}
if (handlers->Count == Event_MaxCallbacks) {
ErrorHandler_Fail("Unable to register another event handler");
} else {
handlers->Handlers[handlers->Count] = handler;
handlers->Count++;
}
}
void Event_UnregisterImpl(Event_Void* handlers, Event_Void_Callback handler) {
Int32 i, j;
for (i = 0; i < handlers->Count; i++) {
if (handlers->Handlers[i] != handler) continue;
/* Remove this handler from the list, by shifting all following handlers left */
for (j = i; j < handlers->Count - 1; j++) {
handlers->Handlers[j] = handlers->Handlers[j + 1];
}
handlers->Handlers[handlers->Count - 1] = NULL;
handlers->Count--;
return;
}
ErrorHandler_Fail("Unregistering event handler that was not registered to begin with");
}
void Event_RaiseVoid(Event_Void* handlers) {
Int32 i;
for (i = 0; i < handlers->Count; i++) {
handlers->Handlers[i]();
}
}
void Event_RegisterVoid(Event_Void* handlers, Event_Void_Callback handler) {
Event_RegisterImpl(handlers, handler);
}
void Event_UnregisterVoid(&Event_Void* handlers, Event_Void_Callback handler) {
Event_UnregisterImpl(handlers, handler);
}
void Event_RaiseInt32(Event_Int32* handlers, Int32 arg) {
Int32 i;
for (i = 0; i < handlers->Count; i++) {
handlers->Handlers[i](arg);
}
}
void Event_RegisterInt32(Event_Int32* handlers,Event_Int32_Callback handler) {
Event_RegisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_UnregisterInt32Impl(Event_Int32* handlers, Event_Int32_Callback handler) {
Event_UnregisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_RaiseReal32(Event_Real32* handlers, Real32 arg) {
Int32 i;
for (i = 0; i < handlers->Count; i++) {
handlers->Handlers[i](arg);
}
}
void Event_RegisterReal32(Event_Real32* handlers, Event_Real32_Callback handler) {
Event_RegisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_UnregisterReal32(Event_Real32* handlers, Event_Real32_Callback handler) {
Event_UnregisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_RaiseEntityID(Event_EntityID* handlers, EntityID arg) {
Int32 i;
for (i = 0; i < handlers->Count; i++) {
handlers->Handlers[i](arg);
}
}
void Event_RegisterEntityID(Event_EntityID* handlers, Event_EntityID_Callback handler) {
Event_RegisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_UnregisterEntityID(Event_EntityID* handlers, Event_EntityID_Callback handler) {
Event_UnregisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_RaiseStream(Event_Stream* handlers, Stream* stream) {
Int32 i;
for (i = 0; i < handlers->Count; i++) {
handlers->Handlers[i](stream);
}
}
void Event_RegisterStream(Event_Stream* handlers, Event_Stream_Callback handler) {
Event_RegisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_UnregisterStream(Event_Stream* handlers, Event_Stream_Callback handler) {
Event_UnregisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_RaiseBlock(Event_Block* handlers, Vector3I coords, BlockID oldBlock, BlockID block) {
Int32 i;
for (i = 0; i < handlers->Count; i++) {
handlers->Handlers[i](coords, oldBlock, block);
}
}
void Event_RegisterBlock(Event_Block* handlers, Event_Block_Callback handler) {
Event_RegisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}
void Event_UnregisterBlock(Event_Block* handlers, Event_Block_Callback handler) {
Event_UnregisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
}

85
src/Client/Event.h Normal file
View file

@ -0,0 +1,85 @@
#ifndef CS_EVENT_H
#define CS_EVENT_H
#include "Typedefs.h"
#include "String.h"
#include "Stream.h"
#include "Vectors.h"
/* Helper method for managing events.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
/* Maximum number of event handlers that can be registered. */
#define Event_MaxCallbacks 32
/* Event that takes no arguments. */
typedef void(*Event_Void_Callback)(void);
typedef struct Event_Void_ {
Event_Void_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
} Event_Void;
/* Event that takes single 32 bit signed integer argument. */
typedef void(*Event_Int32_Callback)(Int32 argument);
typedef struct Event_Int32_ {
Event_Int32_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
} Event_Int32;
/* Event handler that takes single floating-point argument. */
typedef void(*Event_Real32_Callback)(Real32 argument);
typedef struct Event_Real32_ {
Event_Real32_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
} Event_Real32;
/* Event handler that takes an entity ID as an argument. */
typedef void(*Event_EntityID_Callback)(EntityID argument);
typedef struct Event_EntityID_ {
Event_EntityID_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
} Event_EntityID;
/* Event handler that takes stream as an argument. */
typedef void(*Event_Stream_Callback)(Stream* stream);
typedef struct Event_Stream_ {
Event_Stream_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
} Event_Stream;
/* Event handler that takes a block change argument. */
typedef void(*Event_Block_Callback)(Vector3I coords, BlockID oldBlock, BlockID block);
typedef struct Event_Block_ {
Event_Block_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
} Event_Block;
/* Adds given event handler to handlers list for the given event. */
static void Event_RegisterImpl(Event_Void* handlers, Event_Void_Callback handler);
/* Removes given event handler from handlers list of the given event. */
static void Event_UnregisterImpl(Event_Void* handlers, Event_Void_Callback handler);
/* Calls handlers for an event that has no arguments.*/
void Event_RaiseVoid(Event_Void* handlers);
void Event_RegisterVoid(Event_Void* handlers, Event_Void_Callback handler);
void Event_UnregisterVoid(Event_Void* handlers, Event_Void_Callback handler);
/* Calls handlers for an event that takes a 32-bit signed interger argument.*/
void Event_RaiseInt32(Event_Int32* handlers, Int32 arg);
void Event_RegisterInt32(Event_Int32* handlers, Event_Int32_Callback handler);
void Event_UnregisterInt32(Event_Int32* handlers, Event_Int32_Callback handler);
/* Calls handlers for an event that takes a 32-bit floating point argument.*/
void Event_RaiseReal32(Event_Real32* handlers, Real32 arg);
void Event_RegisterReal32(Event_Real32* handlers, Event_Real32_Callback handler);
void Event_UnregisterReal32(Event_Real32* handlers, Event_Real32_Callback handler);
/* Calls handlers for an event that takes an entity ID argument.*/
void Event_RaiseEntityID(Event_EntityID* handlers, EntityID arg);
void Event_RegisterEntityID(Event_EntityID* handlers, Event_EntityID_Callback handler);
void Event_UnregisterEntityID(Event_EntityID* handlers, Event_EntityID_Callback handler);
/* Calls handlers for an event that takes a stream as an argument.*/
void Event_RaiseStream(Event_Stream* handlers, Stream* stream);
void Event_RegisterStream(Event_Stream* handlers, Event_Stream_Callback handler);
void Event_UnregisterStream(Event_Stream* handlers, Event_Stream_Callback handler);
/* Calls handlers for an event that takes a block change as an argument.*/
void Event_RaiseBlock(Event_Block* handlers, Vector3I coords, BlockID oldBlock, BlockID block);
void Event_RegisterBlock(Event_Block* handlers, Event_Block_Callback handler);
void Event_UnregisterBlock(Event_Block* handlers, Event_Block_Callback handler);
#endif

View file

@ -1,129 +0,0 @@
#include "EventHandler.h"
#include "ErrorHandler.h"
void EventHandler_RegisterImpl(void** handlers, Int32* count, void* handler) {
Int32 i;
for (i = 0; i < *count; i++) {
if (handlers[i] == handler) return;
}
if (*count == EventHandler_Size) {
ErrorHandler_Fail("Unable to register another event handler");
} else {
handlers[*count] = handler;
(*count)++;
}
}
void EventHandler_UnregisterImpl(void** handlers, Int32* count, void* handler) {
Int32 i, j;
for (i = 0; i < *count; i++) {
if (handlers[i] != handler) continue;
/* Remove this handler from the list, by shifting all following handlers left */
for (j = i; j < *count - 1; j++) {
handlers[j] = handlers[j + 1];
}
handlers[*count - 1] = NULL;
(*count)--;
return;
}
ErrorHandler_Fail("Unregistering event handler that was not registered to begin with");
}
void EventHandler_Raise_Void(Event_Void* handlers, Int32 handlersCount) {
Int32 i;
for (i = 0; i < handlersCount; i++) {
handlers[i]();
}
}
void EventHandler_RegisterVoidImpl(Event_Void* handlers, Int32* count, Event_Void handler) {
EventHandler_RegisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_UnregisterVoidImpl(Event_Void* handlers, Int32* count, Event_Void handler) {
EventHandler_UnregisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_Raise_Int32(Event_Int32* handlers, Int32 handlersCount, Int32 arg) {
Int32 i;
for (i = 0; i < handlersCount; i++) {
handlers[i](arg);
}
}
void EventHandler_RegisterInt32Impl(Event_Int32* handlers, Int32* count, Event_Int32 handler) {
EventHandler_RegisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_UnregisterInt32Impl(Event_Int32* handlers, Int32* count, Event_Int32 handler) {
EventHandler_UnregisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_Raise_Real32(Event_Real32* handlers, Int32 handlersCount, Real32 arg) {
Int32 i;
for (i = 0; i < handlersCount; i++) {
handlers[i](arg);
}
}
void EventHandler_RegisterReal32Impl(Event_Real32* handlers, Int32* count, Event_Real32 handler) {
EventHandler_RegisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_UnregisterReal32Impl(Event_Real32* handlers, Int32* count, Event_Real32 handler) {
EventHandler_UnregisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_Raise_EntityID(Event_EntityID* handlers, Int32 handlersCount, EntityID arg) {
Int32 i;
for (i = 0; i < handlersCount; i++) {
handlers[i](arg);
}
}
void EventHandler_RegisterEntityIDImpl(Event_EntityID* handlers, Int32* count, Event_EntityID handler) {
EventHandler_RegisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_UnregisterEntityIDImpl(Event_EntityID* handlers, Int32* count, Event_EntityID handler) {
EventHandler_UnregisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_Raise_Stream(Event_Stream* handlers, Int32 handlersCount, Stream* stream) {
Int32 i;
for (i = 0; i < handlersCount; i++) {
handlers[i](stream);
}
}
void EventHandler_RegisterStreamImpl(Event_Stream* handlers, Int32* count, Event_Stream handler) {
EventHandler_RegisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_UnregisterStreamImpl(Event_Stream* handlers, Int32* count, Event_Stream handler) {
EventHandler_UnregisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_Raise_Block(Event_Block* handlers, Int32 handlersCount, Vector3I coords, BlockID oldBlock, BlockID block) {
Int32 i;
for (i = 0; i < handlersCount; i++) {
handlers[i](coords, oldBlock, block);
}
}
void EventHandler_RegisterBlockImpl(Event_Block* handlers, Int32* count, Event_Block handler) {
EventHandler_RegisterImpl((void**)handlers, count, (void*)handler);
}
void EventHandler_UnregisterBlockImpl(Event_Block* handlers, Int32* count, Event_Block handler) {
EventHandler_UnregisterImpl((void**)handlers, count, (void*)handler);
}

View file

@ -1,100 +0,0 @@
#ifndef CS_EVENTHANDLER_H
#define CS_EVENTHANDLER_H
#include "Typedefs.h"
#include "String.h"
#include "Stream.h"
#include "Vectors.h"
/* Helper method for managing events.
Copyright 2017 ClassicalSharp | Licensed under BSD-3
*/
/* Event handler that takes no arguments. */
typedef void(*Event_Void)(void);
/* Event handler that takes single 32 bit signed integer argument. */
typedef void(*Event_Int32)(Int32 argument);
/* Event handler that takes single floating-point argument. */
typedef void(*Event_Real32)(Real32 argument);
/* Event handler that takes an entity ID as an argument. */
typedef void(*Event_EntityID)(EntityID argument);
/* Event handler that takes stream as an argument. */
typedef void(*Event_Stream)(Stream* stream);
/* Event handler that takes a block change argument. */
typedef void(*Event_Block)(Vector3I coords, BlockID oldBlock, BlockID block);
/* Maximum number of event handlers that can be registered. */
#define EventHandler_Size 32
/* Adds given event handler to handlers list for the given event. */
static void EventHandler_RegisterImpl(void** handlers, Int32* count, void* handler);
/* Removes given event handler from handlers list of the given event. */
static void EventHandler_UnregisterImpl(void** handlers, Int32* count, void* handler);
/* Calls handlers for an event that has no arguments.*/
void EventHandler_Raise_Void(Event_Void* handlers, Int32 handlersCount);
#define EventHandler_RegisterVoid(eventName, handler) EventHandler_RegisterVoidImpl(eventName, &eventName ## Count, handler)
void EventHandler_RegisterVoidImpl(Event_Void* handlers, Int32* count, Event_Void handler);
#define EventHandler_UnregisterVoid(eventName, handler) EventHandler_UnregisterVoidImpl(eventName, &eventName ## Count, handler)
void EventHandler_UnregisterVoidImpl(Event_Void* handlers, Int32* count, Event_Void handler);
/* Calls handlers for an event that takes a 32-bit signed interger argument.*/
void EventHandler_Raise_Int32(Event_Int32* handlers, Int32 handlersCount, Int32 arg);
#define EventHandler_RegisterInt32(eventName, handler) EventHandler_RegisterInt32Impl(eventName, &eventName ## Count, handler)
void EventHandler_RegisterInt32Impl(Event_Int32* handlers, Int32* count, Event_Int32 handler);
#define EventHandler_UnregisterInt32(eventName, handler) EventHandler_UnregisterInt32Impl(eventName, &eventName ## Count, handler)
void EventHandler_UnregisterInt32Impl(Event_Int32* handlers, Int32* count, Event_Int32 handler);
/* Calls handlers for an event that takes a 32-bit floating point argument.*/
void EventHandler_Raise_Real32(Event_Real32* handlers, Int32 handlersCount, Real32 arg);
#define EventHandler_RegisterReal32(eventName, handler) EventHandler_RegisterFloat32Impl(eventName, &eventName ## Count, handler)
void EventHandler_RegisterReal32Impl(Event_Real32* handlers, Int32* count, Event_Real32 handler);
#define EventHandler_UnregisterReal32(eventName, handler) EventHandler_UnregisterFloat32Impl(eventName, &eventName ## Count, handler)
void EventHandler_UnregisterReal32Impl(Event_Real32* handlers, Int32* count, Event_Real32 handler);
/* Calls handlers for an event that takes an entity ID argument.*/
void EventHandler_Raise_EntityID(Event_EntityID* handlers, Int32 handlersCount, EntityID arg);
#define EventHandler_RegisterEntityID(eventName, handler) EventHandler_RegisterEntityIDImpl(eventName, &eventName ## Count, handler)
void EventHandler_RegisterEntityIDImpl(Event_EntityID* handlers, Int32* count, Event_EntityID handler);
#define EventHandler_UnregisterEntityID(eventName, handler) EventHandler_UnregisterEntityIDImpl(eventName, &eventName ## Count, handler)
void EventHandler_UnregisterEntityIDImpl(Event_EntityID* handlers, Int32* count, Event_EntityID handler);
/* Calls handlers for an event that takes a stream as an argument.*/
void EventHandler_Raise_Stream(Event_Stream* handlers, Int32 handlersCount, Stream* stream);
#define EventHandler_RegisterStream(eventName, handler) EventHandler_RegisterStreamImpl(eventName, &eventName ## Count, handler)
void EventHandler_RegisterStreamImpl(Event_Stream* handlers, Int32* count, Event_Stream handler);
#define EventHandler_UnregisterStream(eventName, handler) EventHandler_UnregisterStreamImpl(eventName, &eventName ## Count, handler)
void EventHandler_UnregisterStreamImpl(Event_Stream* handlers, Int32* count, Event_Stream handler);
/* Calls handlers for an event that takes a block change as an argument.*/
void EventHandler_Raise_Block(Event_Block* handlers, Int32 handlersCount, Vector3I coords, BlockID oldBlock, BlockID block);
#define EventHandler_RegisterBlock(eventName, handler) EventHandler_RegisterBlockImpl(eventName, &eventName ## Count, handler)
void EventHandler_RegisterBlockImpl(Event_Block* handlers, Int32* count, Event_Block handler);
#define EventHandler_UnregisterBlock(eventName, handler) EventHandler_UnregisterBlockImpl(eventName, &eventName ## Count, handler)
void EventHandler_UnregisterBlockImpl(Event_Block* handlers, Int32* count, Event_Block handler);
#endif

View file

@ -1,120 +1,55 @@
#ifndef CS_EVENTS_H
#define CS_EVENTS_H
#include "EventHandler.h"
#include "Event.h"
#include "Typedefs.h"
/* Contains the various events that are raised by the client.
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
*/
/* Raised when an entity is spawned in the current world. */
Event_EntityID EntityEvents_Added[EventHandler_Size];
Int32 EntityEvents_AddedCount;
#define EntityEvents_RaiseAdded(id)\
EventHandler_Raise_EntityID(EntityEvents_Added, EntityEvents_AddedCount, id);
Event_EntityID EntityEvents_Added;
/* Raised when an entity is despawned from the current world. */
Event_EntityID EntityEvents_Removed[EventHandler_Size];
Int32 EntityEvents_RemovedCount;
#define EntityEvents_RaiseRemoved(id)\
EventHandler_Raise_EntityID(EntityEvents_Removed, EntityEvents_RemovedCount, id);
Event_EntityID EntityEvents_Removed;
/* Raised when a tab list entry is created. */
Event_EntityID TabListEvents_Added[EventHandler_Size];
Int32 TabListEvents_AddedCount;
#define TabListEvents_RaiseAdded(id)\
EventHandler_Raise_EntityID(TabListEvents_Added, TabListEvents_AddedCount, id);
Event_EntityID TabListEvents_Added;
/* Raised when a tab list entry is modified. */
Event_EntityID TabListEvents_Changed[EventHandler_Size];
Int32 TabListEvents_ChangedCount;
#define TabListEvents_RaiseChanged(id)\
EventHandler_Raise_EntityID(TabListEvents_Changed, TabListEvents_ChangedCount, id);
Event_EntityID TabListEvents_Changed;
/* Raised when a tab list entry is removed. */
Event_EntityID TabListEvents_Removed[EventHandler_Size];
Int32 TabListEvents_RemovedCount;
#define TabListEvents_RaiseRemoved(id)\
EventHandler_Raise_EntityID(TabListEvents_Removed, TabListEvents_RemovedCount, id);
Event_EntityID TabListEvents_Removed;
/* Raised when the terrain atlas ("terrain.png") is changed. */
Event_Void TextureEvents_AtlasChanged[EventHandler_Size];
Int32 TextureEvents_AtlasChangedCount;
#define TextureEvents_RaiseAtlasChanged()\
EventHandler_Raise_Void(TextureEvents_AtlasChanged, TextureEvents_AtlasChangedCount);
Event_Void TextureEvents_AtlasChanged;
/* Raised when the texture pack is changed. */
Event_Void TextureEvents_PackChanged[EventHandler_Size];
Int32 TextureEvents_PackChangedCount;
#define TextureEvents_RaisePackChanged()\
EventHandler_Raise_Void(TextureEvents_PackChanged, TextureEvents_PackChangedCount);
Event_Void TextureEvents_PackChanged;
/* Raised when a file in a texture pack is changed. (such as "terrain.png", "rain.png") */
Event_Stream TextureEvents_FileChanged[EventHandler_Size];
Int32 TextureEvents_FileChangedCount;
#define TextureEvents_RaiseFileChanged(stream)\
EventHandler_Raise_Stream(TextureEvents_TextureChanged, TextureEvents_FileChangedCount, stream);
Event_Stream TextureEvents_FileChanged;
/* Raised when the user changed their view/fog distance. */
Event_Void GfxEvents_ViewDistanceChanged[EventHandler_Size];
Int32 GfxEvents_ViewDistanceChangedCount;
#define GfxEvents_RaiseViewDistanceChanged()\
EventHandler_Raise_Void(GfxEvents_ViewDistanceChanged, GfxEvents_ViewDistanceCount);
Event_Void GfxEvents_ViewDistanceChanged;
/* Raised when the projection matrix changes. */
Event_Void GfxEvents_ProjectionChanged[EventHandler_Size];
Int32 GfxEvents_ProjectionChangedCount;
#define GfxEvents_RaiseProjectionChanged()\
EventHandler_Raise_Void(GfxEvents_ProjectionChanged, GfxEvents_ProjectionCount);
Event_Void GfxEvents_ProjectionChanged;
/* Event raised when a context is destroyed after having been previously lost. */
Event_Void GfxEvents_ContextLost;
/* Event raised when a context is recreated after having been previously lost. */
Event_Void GfxEvents_ContextRecreated;
/* Raised when the user changes a block. */
Event_Block UserEvents_BlockChanged[EventHandler_Size];
Int32 UserEvents_BlockChangedCount;
#define UserEvents_BlockChangedChanged(coords, oldBlock, block)\
EventHandler_Raise_Block(UserEvents_BlockChanged, UserEvents_BlockChangedCount, coords, oldBlock, block);
Event_Block UserEvents_BlockChanged;
/* Raised when the block permissions(can place or delete a block) for the player changes. */
Event_Void BlockEvents_PermissionsChanged[EventHandler_Size];
Int32 BlockEvents_PermissionsChangedCount;
#define BlockEvents_RaisePermissionsChanged()\
EventHandler_Raise_Void(BlockEvents_PermissionsChanged, BlockEvents_PermissionsChangedCount);
Event_Void BlockEvents_PermissionsChanged;
/* Raised when a block definition is changed. */
Event_Void BlockEvents_BlockDefChanged[EventHandler_Size];
Int32 BlockEvents_BlockDefChangedCount;
#define BlockEvents_RaiseBlockDefChanged()\
EventHandler_Raise_Void(BlockEvents_BlockDefChanged, BlockEvents_BlockDefChangedCount);
Event_Void BlockEvents_BlockDefChanged;
/* Raised when the player joins and begins loading a new world. */
Event_Void WorldEvents_NewMap[EventHandler_Size];
Int32 WorldEvents_NewMapCount;
#define WorldEvents_RaiseNewMap()\
EventHandler_Raise_Void(WorldEvents_NewMap, WorldEvents_NewMapCount);
Event_Void WorldEvents_NewMap;
/* Raised when a portion of the world is read and decompressed, or generated.
The floating point argument is progress (from 0 to 1). */
Event_Real32 WorldEvents_MapLoading[EventHandler_Size];
Int32 WorldEvents_MapLoadingCount;
#define WorldEvents_RaiseMapLoading(progress)\
EventHandler_Raise_Real32(WorldEvents_MapLoading, WorldEvents_MapLoadingCount, progress);
Event_Real32 WorldEvents_MapLoading;
/* Raised when new world has finished loading and the player can now interact with it. */
Event_Void WorldEvents_MapLoaded[EventHandler_Size];
Int32 WorldEvents_MapLoadedCount;
#define WorldEvents_RaiseMapLoaded()\
EventHandler_Raise_Void(WorldEvents_MapLoaded, WorldEvents_MapLoadedCount);
Event_Void WorldEvents_MapLoaded;
/* Raised when an environment variable of the world is changed by the user, CPE, or WoM config. */
Event_Int32 WorldEvents_EnvVarChanged[EventHandler_Size];
Int32 WorldEvents_EnvVarChangedCount;
#define WorldEvents_RaiseEnvVariableChanged(envVar)\
EventHandler_Raise_Int32(WorldEvents_EnvVarChanged, WorldEvents_EnvVarChangedCount, envVar);
Event_Int32 WorldEvents_EnvVarChanged;
/* Environment variable identifiers*/
typedef Int32 EnvVar;
@ -135,4 +70,51 @@ typedef Int32 EnvVar;
#define EnvVar_FogCol 12
#define EnvVar_SunCol 13
#define EnvVar_ShadowCol 14
/*
The Open Toolkit Library License
Copyright (c) 2006 - 2009 the Open Toolkit library.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
/* Raised when the window is moved. */
Event_Void WindowEvents_OnMove;
/* Raised whene the window is resized. */
Event_Void WindowEvents_OnResize;
/* Raised when the window is about to close. */
Event_Void WindowEvents_OnClosing;
/* Raised after the window has closed. */
Event_Void WindowEvents_OnClosed;
/* Raised the visibility of the window changes. */
Event_Void WindowEvents_OnVisibleChanged;
/* Raised when the focus of the window changes. */
Event_Void WindowEvents_OnFocusedChanged;
/* Raised when the WindowState of the window changes. */
Event_Void WindowEvents_OnWindowStateChanged;
/// <summary> Occurs whenever a character is typed. </summary>
event EventHandler<KeyPressEventArgs> KeyPress;
/* Raised whenever the mouse cursor leaves the bounds of the window. */
Event_Void WindowEvents_OnMouseLeave;
/* Raised whenever the mouse cursor enters the bounds of the window. */
Event_Void WindowEvents_OnMouseEnter;
#endif

View file

@ -1,7 +1,6 @@
#ifndef CS_GFXAPI_H
#define CS_GFXAPI_H
#include "Typedefs.h"
#include "EventHandler.h"
#include "Bitmap.h"
#include "PackedCol.h"
#include "String.h"
@ -36,15 +35,6 @@ bool Gfx_LostContext;
/* Maximum number of vertices that can be indexed. */
#define Gfx_MaxVertex 65536
/* Event raised when a context is destroyed after having been previously lost. */
Event_Void Gfx_ContextLost[EventHandler_Size];
Int32 Gfx_ContextLostCount;
/* Event raised when a context is recreated after having been previously lost. */
Event_Void Gfx_ContextRecreated[EventHandler_Size];
Int32 Gfx_ContextRecreatedCount;
/* TODO: IMPLEMENT THIS */
/* /// <summary> Delegate that is invoked when the current context is lost,
/// and is repeatedly invoked until the context can be retrieved. </summary>

View file

@ -3,6 +3,7 @@
#include "GraphicsEnums.h"
#include "Platform.h"
#include "Block.h"
#include "Events.h"
void GfxCommon_Init(void) {
GfxCommon_quadVb = Gfx_CreateDynamicVb(VertexFormat_P3fC4b, 4);
@ -19,7 +20,7 @@ void GfxCommon_LoseContext(STRING_TRANSIENT String* reason) {
Platform_Log(String_FromConstant("Lost graphics context:"));
Platform_Log(*reason);
EventHandler_Raise_Void(Gfx_ContextLost, Gfx_ContextLostCount);
Event_RaiseVoid(&GfxEvents_ContextLost);
GfxCommon_Free();
}
@ -27,7 +28,7 @@ void GfxCommon_RecreateContext(void) {
Gfx_LostContext = false;
Platform_Log(String_FromConstant("Recreating graphics context"));
EventHandler_Raise_Void(Gfx_ContextRecreated, Gfx_ContextRecreatedCount);
Event_RaiseVoid(&GfxEvents_ContextRecreated);
GfxCommon_Init();
}

View file

@ -22,7 +22,7 @@ IGameComponent Lighting_MakeGameComponent(void) {
}
void Lighting_Init(void) {
EventHandler_RegisterInt32(WorldEvents_EnvVarChanged, &Lighting_EnvVariableChanged);
Event_RegisterInt32(&WorldEvents_EnvVarChanged, &Lighting_EnvVariableChanged);
Lighting_SetSun(WorldEnv_DefaultSunCol);
Lighting_SetShadow(WorldEnv_DefaultShadowCol);
}
@ -50,7 +50,7 @@ void Lighting_OnNewMapLoaded(void) {
}
void Lighting_Free(void) {
EventHandler_UnregisterInt32(WorldEvents_EnvVarChanged, &Lighting_EnvVariableChanged);
Event_UnregisterInt32(&WorldEvents_EnvVarChanged, &Lighting_EnvVariableChanged);
Lighting_Reset();
}

View file

@ -13,9 +13,9 @@ void ModelCache_Init(void) {
ModelCache_RegisterDefaultModels();
ModelCache_ContextRecreated();
EventHandler_RegisterStream(TextureEvents_FileChanged, ModelCache_TextureChanged);
EventHandler_RegisterVoid(Gfx_ContextLost, ModelCache_ContextLost);
EventHandler_RegisterVoid(Gfx_ContextRecreated, ModelCache_ContextRecreated);
Event_RegisterStream(&TextureEvents_FileChanged, ModelCache_TextureChanged);
Event_RegisterVoid(&GfxEvents_ContextLost, ModelCache_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, ModelCache_ContextRecreated);
}
void ModelCache_Free(void) {
@ -26,9 +26,9 @@ void ModelCache_Free(void) {
}
ModelCache_ContextLost();
EventHandler_UnregisterStream(TextureEvents_FileChanged, ModelCache_TextureChanged);
EventHandler_UnregisterVoid(Gfx_ContextLost, ModelCache_ContextLost);
EventHandler_UnregisterVoid(Gfx_ContextRecreated, ModelCache_ContextRecreated);
Event_UnregisterStream(&TextureEvents_FileChanged, ModelCache_TextureChanged);
Event_UnregisterVoid(&Gfx_ContextLost, ModelCache_ContextLost);
Event_UnregisterVoid(&Gfx_ContextRecreated, ModelCache_ContextRecreated);
}

View file

@ -30,8 +30,8 @@ void Physics_SetEnabled(bool enabled) {
}
void Physics_Init(void) {
EventHandler_RegisterVoid(WorldEvents_MapLoaded, Physics_OnNewMapLoaded);
EventHandler_RegisterBlock(UserEvents_BlockChanged, Physics_BlockChanged);
Event_RegisterVoid(&WorldEvents_MapLoaded, Physics_OnNewMapLoaded);
Event_RegisterBlock(&UserEvents_BlockChanged, Physics_BlockChanged);
Physics_Enabled = Options_GetBool(OptionsKey_SingleplayerPhysics, true);
TickQueue_Init(&physics_lavaQ);
TickQueue_Init(&physics_waterQ);
@ -74,8 +74,8 @@ void Physics_Init(void) {
}
void Physics_Free(void) {
EventHandler_UnregisterVoid(WorldEvents_MapLoaded, Physics_OnNewMapLoaded);
EventHandler_UnregisterBlock(UserEvents_BlockChanged, Physics_BlockChanged);
Event_UnregisterVoid(&WorldEvents_MapLoaded, Physics_OnNewMapLoaded);
Event_UnregisterBlock(&UserEvents_BlockChanged, Physics_BlockChanged);
}
void Physics_Tick(void) {

View file

@ -23,14 +23,14 @@ IGameComponent PickedPosRenderer_MakeGameComponent(void) {
void PickedPosRenderer_Init(void) {
pickedPos_col = PackedCol_Create4(0, 0, 0, 102);
PickedPosRenderer_ContextRecreated();
EventHandler_RegisterVoid(Gfx_ContextLost, PickedPosRenderer_ContextLost);
EventHandler_RegisterVoid(Gfx_ContextRecreated, PickedPosRenderer_ContextRecreated);
Event_RegisterVoid(&GfxEvents_ContextLost, PickedPosRenderer_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, PickedPosRenderer_ContextRecreated);
}
void PickedPosRenderer_Free(void) {
PickedPosRenderer_ContextLost();
EventHandler_UnregisterVoid(Gfx_ContextLost, PickedPosRenderer_ContextLost);
EventHandler_UnregisterVoid(Gfx_ContextRecreated, PickedPosRenderer_ContextRecreated);
Event_UnregisterVoid(&Gfx_ContextLost, PickedPosRenderer_ContextLost);
Event_UnregisterVoid(&Gfx_ContextRecreated, PickedPosRenderer_ContextRecreated);
}
void PickedPosRenderer_Render(Real64 delta) {

View file

@ -1,7 +1,7 @@
#if 0
#include "SkyboxRenderer.h"
#include "Camera.h"
#include "EventHandler.h"
#include "Events.h"
#include "Game.h"
#include "GameProps.h"
#include "GraphicsAPI.h"
@ -30,11 +30,11 @@ bool SkyboxRenderer_ShouldRender(void) {
}
void SkyboxRenderer_Init(void) {
EventHandler_RegisterStream(TextureEvents_FileChanged, &SkyboxRenderer_FileChanged);
EventHandler_RegisterVoid(TextureEvents_PackChanged, &SkyboxRenderer_TexturePackChanged);
EventHandler_RegisterInt32(WorldEvents_EnvVarChanged, &SkyboxRenderer_EnvVariableChanged);
EventHandler_RegisterVoid(Gfx_ContextLost, &SkyboxRenderer_ContextLost);
EventHandler_RegisterVoid(Gfx_ContextRecreated, &SkyboxRenderer_ContextRecreated);
Event_RegisterStream(&TextureEvents_FileChanged, &SkyboxRenderer_FileChanged);
Event_RegisterVoid(&TextureEvents_PackChanged, &SkyboxRenderer_TexturePackChanged);
Event_RegisterInt32(&WorldEvents_EnvVarChanged, &SkyboxRenderer_EnvVariableChanged);
Event_RegisterVoid(&GfxEvents_ContextLost, &SkyboxRenderer_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, &SkyboxRenderer_ContextRecreated);
}
void SkyboxRenderer_Reset(void) { Gfx_DeleteTexture(&skybox_tex); }
@ -43,11 +43,11 @@ void SkyboxRenderer_Free(void) {
Gfx_DeleteTexture(&skybox_tex);
SkyboxRenderer_ContextLost();
EventHandler_UnregisterStream(TextureEvents_FileChanged, &SkyboxRenderer_FileChanged);
EventHandler_UnregisterVoid(TextureEvents_PackChanged, &SkyboxRenderer_TexturePackChanged);
EventHandler_UnregisterInt32(WorldEvents_EnvVarChanged, &SkyboxRenderer_EnvVariableChanged);
EventHandler_UnregisterVoid(Gfx_ContextLost, &SkyboxRenderer_ContextLost);
EventHandler_UnregisterVoid(Gfx_ContextRecreated, &SkyboxRenderer_ContextRecreated);
Event_UnregisterStream(&TextureEvents_FileChanged, &SkyboxRenderer_FileChanged);
Event_UnregisterVoid(&TextureEvents_PackChanged, &SkyboxRenderer_TexturePackChanged);
Event_UnregisterInt32(&WorldEvents_EnvVarChanged, &SkyboxRenderer_EnvVariableChanged);
Event_UnregisterVoid(&Gfx_ContextLost, &SkyboxRenderer_ContextLost);
Event_UnregisterVoid(&Gfx_ContextRecreated, &SkyboxRenderer_ContextRecreated);
}
void SkyboxRenderer_EnvVariableChanged(EnvVar envVar) {

View file

@ -3,7 +3,7 @@
#include "Block.h"
#include "ExtMath.h"
#include "Funcs.h"
#include "EventHandler.h"
#include "Events.h"
#include "Game.h"
#include "GameProps.h"
#include "GraphicsAPI.h"
@ -39,12 +39,12 @@ IGameComponent WeatherRenderer_MakeGameComponent(void) {
}
void WeatherRenderer_Init(void) {
EventHandler_RegisterStream(TextureEvents_FileChanged, &WeatherRenderer_FileChanged);
Event_RegisterStream(&TextureEvents_FileChanged, &WeatherRenderer_FileChanged);
weather_lastPos = Vector3I_Create1(Int32_MaxValue);
WeatherRenderer_ContextRecreated();
EventHandler_RegisterVoid(Gfx_ContextLost, &WeatherRenderer_ContextLost);
EventHandler_RegisterVoid(Gfx_ContextRecreated, &WeatherRenderer_ContextRecreated);
Event_RegisterVoid(&GfxEvents_ContextLost, &WeatherRenderer_ContextLost);
Event_RegisterVoid(&GfxEvents_ContextRecreated, &WeatherRenderer_ContextRecreated);
}
void WeatherRenderer_Render(Real64 deltaTime) {
@ -162,9 +162,9 @@ void WeatherRenderer_Free(void) {
WeatherRenderer_ContextLost();
WeatherRenderer_Reset();
EventHandler_UnregisterStream(TextureEvents_FileChanged, &WeatherRenderer_FileChanged);
EventHandler_UnregisterVoid(Gfx_ContextLost, &WeatherRenderer_ContextLost);
EventHandler_UnregisterVoid(Gfx_ContextRecreated, &WeatherRenderer_ContextRecreated);
Event_UnregisterStream(&TextureEvents_FileChanged, &WeatherRenderer_FileChanged);
Event_UnregisterVoid(&Gfx_ContextLost, &WeatherRenderer_ContextLost);
Event_UnregisterVoid(&Gfx_ContextRecreated, &WeatherRenderer_ContextRecreated);
}
void WeatherRenderer_InitHeightmap(void) {

View file

@ -110,38 +110,4 @@ void Window_SetDesktopCursorPos(Point2D point);
bool Window_GetCursorVisible(void);
/* Sets whether the cursor is visible in the window. */
void Window_SetCursorVisible(bool visible);
/// <summary> Occurs whenever the window is moved. </summary>
event EventHandler<EventArgs> Move;
/// <summary> Occurs whenever the window is resized. </summary>
event EventHandler<EventArgs> Resize;
/// <summary> Occurs when the window is about to close. </summary>
event EventHandler<CancelEventArgs> Closing;
/// <summary> Occurs after the window has closed. </summary>
event EventHandler<EventArgs> Closed;
/// <summary> Occurs when the window is disposed. </summary>
event EventHandler<EventArgs> Disposed;
/// <summary> Occurs when the <see cref="Visible"/> property of the window changes. </summary>
event EventHandler<EventArgs> VisibleChanged;
/// <summary> Occurs when the <see cref="Focused"/> property of the window changes. </summary>
event EventHandler<EventArgs> FocusedChanged;
/// <summary> Occurs when the <see cref="WindowState"/> property of the window changes. </summary>
event EventHandler<EventArgs> WindowStateChanged;
/// <summary> Occurs whenever a character is typed. </summary>
event EventHandler<KeyPressEventArgs> KeyPress;
/// <summary> Occurs whenever the mouse cursor leaves the window <see cref="Bounds"/>. </summary>
event EventHandler<EventArgs> MouseLeave;
/// <summary> Occurs whenever the mouse cursor enters the window <see cref="Bounds"/>. </summary>
event EventHandler<EventArgs> MouseEnter;
#endif

View file

@ -1,6 +1,5 @@
#if 0
#include "WorldEnv.h"
#include "EventHandler.h"
#include "Events.h"
@ -8,13 +7,13 @@
#define WorldEnv_Set(value, dst, envVar)\
if (value == dst) return;\
dst = value;\
WorldEvents_RaiseEnvVariableChanged(envVar);
Event_RaiseInt32(&WorldEvents_EnvVarChanged, envVar);
/* Sets a colour and potentially raises event. */
#define WorldEnv_SetCol(value, dst, envVar)\
if (PackedCol_Equals(value, dst)) return;\
dst = value;\
WorldEvents_RaiseEnvVariableChanged(envVar);
Event_RaiseInt32(&WorldEvents_EnvVarChanged, envVar);
void WorldEnv_Reset(void) {
@ -117,7 +116,7 @@ void WorldEnv_SetSunCol(PackedCol col) {
WorldEnv_SunCol = col;
PackedCol_GetShaded(WorldEnv_SunCol, &WorldEnv_SunXSide,
&WorldEnv_SunZSide, &WorldEnv_SunYBottom);
WorldEvents_RaiseEnvVariableChanged(EnvVar_SunCol);
Event_RaiseInt32(&WorldEvents_EnvVarChanged, EnvVar_SunCol);
}
void WorldEnv_SetShadowCol(PackedCol col) {
@ -126,6 +125,6 @@ void WorldEnv_SetShadowCol(PackedCol col) {
WorldEnv_ShadowCol = col;
PackedCol_GetShaded(WorldEnv_ShadowCol, &WorldEnv_ShadowXSide,
&WorldEnv_ShadowZSide, &WorldEnv_ShadowYBottom);
WorldEvents_RaiseEnvVariableChanged(EnvVar_ShadowCol);
Event_RaiseInt32(&WorldEvents_EnvVarChanged, EnvVar_ShadowCol);
}
#endif