mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 01:21:57 -05:00
Port IGameComponent and ScheduledTask to C
This commit is contained in:
parent
3811bb623b
commit
159dfbded6
10 changed files with 141 additions and 14 deletions
|
@ -4,7 +4,7 @@
|
|||
#include "Block.h"
|
||||
#include "TerrainAtlas2D.h"
|
||||
|
||||
void Block_Reset(Game* game) {
|
||||
void Block_Reset() {
|
||||
Block_Init();
|
||||
Block_RecalculateSpriteBB();
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ UInt8 Block_CanStretch[Block_Count];
|
|||
|
||||
|
||||
/* Recalculates the initial properties and culling states for all blocks. */
|
||||
void Block_Reset(Game* game);
|
||||
void Block_Reset();
|
||||
|
||||
/* Calculates the initial properties and culling states for all blocks. */
|
||||
void Block_Init();
|
||||
|
|
|
@ -180,6 +180,7 @@
|
|||
<ClInclude Include="ErrorHandler.h" />
|
||||
<ClInclude Include="FrustumCulling.h" />
|
||||
<ClInclude Include="Stream.h" />
|
||||
<ClInclude Include="GameStructs.h" />
|
||||
<ClInclude Include="TerrainAtlas1D.h" />
|
||||
<ClInclude Include="TerrainAtlas2D.h" />
|
||||
<ClInclude Include="WorldEvents.h" />
|
||||
|
@ -216,6 +217,7 @@
|
|||
<ClCompile Include="EventHandler.c" />
|
||||
<ClCompile Include="ExtMath.c" />
|
||||
<ClCompile Include="FrustumCulling.c" />
|
||||
<ClCompile Include="GameStructs.c" />
|
||||
<ClCompile Include="PackedCol.c" />
|
||||
<ClCompile Include="Funcs.c" />
|
||||
<ClCompile Include="GraphicsCommon.c" />
|
||||
|
|
|
@ -100,6 +100,12 @@
|
|||
<Filter Include="Header Files\IO">
|
||||
<UniqueIdentifier>{82a3fbdf-5459-4e08-bff9-04dd23aa4342}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Game">
|
||||
<UniqueIdentifier>{570b92b8-b3df-40cb-a42a-da14c81c877a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Game">
|
||||
<UniqueIdentifier>{62c942cf-1d93-4e9c-8635-61fa1ec2bbdc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="NotchyGenerator.h">
|
||||
|
@ -135,9 +141,6 @@
|
|||
<ClInclude Include="Matrix.h">
|
||||
<Filter>Header Files\Math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Game.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Bitmap.h">
|
||||
<Filter>Header Files\2D\Utils</Filter>
|
||||
</ClInclude>
|
||||
|
@ -210,6 +213,12 @@
|
|||
<ClInclude Include="Stream.h">
|
||||
<Filter>Header Files\IO</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Game.h">
|
||||
<Filter>Header Files\Game</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GameStructs.h">
|
||||
<Filter>Header Files\Game</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="NotchyGenerator.c">
|
||||
|
@ -299,5 +308,8 @@
|
|||
<ClCompile Include="Stream.c">
|
||||
<Filter>Source Files\IO</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GameStructs.c">
|
||||
<Filter>Source Files\Game</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,8 +1,19 @@
|
|||
#ifndef CS_GAME_H
|
||||
#define CS_GAME_H
|
||||
#include "Typedefs.h"
|
||||
/* Represents the game.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
typedef struct Game {
|
||||
Int32 xxxx;
|
||||
} Game;
|
||||
/* Called when projection matrix is updated. */
|
||||
void Game_UpdateProjection();
|
||||
|
||||
/* Updates the block at the given coordinates. */
|
||||
void Game_UpdateBlock(Int32 x, Int32 y, Int32 z, BlockID block);
|
||||
|
||||
/* Performs thread sleeping to limit the FPS. */
|
||||
static void Game_LimitFPS();
|
||||
|
||||
/* Frees all resources held by the game. */
|
||||
void Game_Free();
|
||||
#endif
|
52
src/Client/GameStructs.c
Normal file
52
src/Client/GameStructs.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
#ifndef CS_GAMESTRUCTS_H
|
||||
#define CS_GAMESTRUCTS_H
|
||||
#include "Typedefs.h"
|
||||
/* Represents Game related structures.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
/* Callback function that takes no args. */
|
||||
typedef void (*Void_Callback)(void);
|
||||
|
||||
/* Represents a game component. */
|
||||
typedef struct IGameComponent {
|
||||
|
||||
/* Called when the game is being loaded. */
|
||||
Void_Callback Init;
|
||||
|
||||
/* Called when the texture pack has been loaded and all components have been initalised. */
|
||||
Void_Callback Ready;
|
||||
|
||||
/* Called to reset the component's state when the user is reconnecting to a server */
|
||||
Void_Callback Reset;
|
||||
|
||||
/* Called to update the component's state when the user begins loading a new map. */
|
||||
Void_Callback OnNewMap;
|
||||
|
||||
/* Called to update the component's state when the user has finished loading a new map. */
|
||||
Void_Callback OnNewMapLoaded;
|
||||
} IGameComponent;
|
||||
|
||||
/* Makes an empty game component with all its function pointers initalised to null. */
|
||||
IGameComponent IGameComponent_MakeEmpty() {
|
||||
IGameComponent comp;
|
||||
comp.Init = NULL;
|
||||
comp.Ready = NULL;
|
||||
comp.Reset = NULL;
|
||||
comp.OnNewMap = NULL;
|
||||
comp.OnNewMapLoaded = NULL;
|
||||
}
|
||||
|
||||
/* Represents a task that runs on the main thread every certain interval. */
|
||||
typedef struct ScheduledTask {
|
||||
|
||||
/* How much time has elapsed since callback was last invoked. */
|
||||
Real64 Accumulator;
|
||||
|
||||
/* How long (in seconds) between invocations of the callback. */
|
||||
Real64 Interval;
|
||||
|
||||
/* Callback function that is periodically invoked. */
|
||||
void (*Callback)(struct ScheduledTask* task);
|
||||
} ScheduledTask;
|
||||
#endif
|
49
src/Client/GameStructs.h
Normal file
49
src/Client/GameStructs.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef CS_GAMESTRUCTS_H
|
||||
#define CS_GAMESTRUCTS_H
|
||||
#include "Typedefs.h"
|
||||
/* Represents Game related structures.
|
||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
*/
|
||||
|
||||
/* Callback function that takes no args. */
|
||||
typedef void (*Void_Callback)(void);
|
||||
|
||||
/* Represents a game component. */
|
||||
typedef struct IGameComponent {
|
||||
|
||||
/* Called when the game is being loaded. */
|
||||
Void_Callback Init;
|
||||
|
||||
/* Called when the texture pack has been loaded and all components have been initalised. */
|
||||
Void_Callback Ready;
|
||||
|
||||
/* Called to reset the component's state when the user is reconnecting to a server */
|
||||
Void_Callback Reset;
|
||||
|
||||
/* Called to update the component's state when the user begins loading a new map. */
|
||||
Void_Callback OnNewMap;
|
||||
|
||||
/* Called to update the component's state when the user has finished loading a new map. */
|
||||
Void_Callback OnNewMapLoaded;
|
||||
} IGameComponent;
|
||||
|
||||
/* Makes an empty game component with all its function pointers initalised to null. */
|
||||
IGameComponent IGameComponent_MakeEmpty();
|
||||
|
||||
|
||||
/* Callback invoked for a scheduled task. */
|
||||
typedef void (*ScheduledTask_Callback)(ScheduledTask* task);
|
||||
|
||||
/* Represents a task that runs on the main thread every certain interval. */
|
||||
typedef struct ScheduledTask {
|
||||
|
||||
/* How much time has elapsed since callback was last invoked. */
|
||||
Real64 Accumulator;
|
||||
|
||||
/* How long (in seconds) between invocations of the callback. */
|
||||
Real64 Interval;
|
||||
|
||||
/* Callback function that is periodically invoked. */
|
||||
ScheduledTask_Callback Callback;
|
||||
} ScheduledTask;
|
||||
#endif
|
|
@ -197,20 +197,20 @@ void Gfx_TakeScreenshot(String output, Int32 width, Int32 height);
|
|||
|
||||
/* Adds a warning to game's chat if this graphics API has problems with the current user's GPU.
|
||||
Returns boolean of whether legacy rendering mode is needed. */
|
||||
bool Gfx_WarnIfNecessary(Game* game);
|
||||
bool Gfx_WarnIfNecessary();
|
||||
|
||||
/* Informs the graphic api to update its state in preparation for a new frame. */
|
||||
void Gfx_BeginFrame(Game* game);
|
||||
void Gfx_BeginFrame();
|
||||
|
||||
/* Informs the graphic api to update its state in preparation for the end of a frame,
|
||||
and to prepare that frame for display on the monitor. */
|
||||
void Gfx_EndFrame(Game* game);
|
||||
void Gfx_EndFrame();
|
||||
|
||||
/* Sets whether the graphics api should tie frame rendering to the refresh rate of the monitor. */
|
||||
void Gfx_SetVSync(Game* game, bool value);
|
||||
void Gfx_SetVSync(bool value);
|
||||
|
||||
/* Raised when the dimensions of the game's window have changed. */
|
||||
void Gfx_OnWindowResize(Game* game);
|
||||
void Gfx_OnWindowResize();
|
||||
|
||||
|
||||
/* Makes an array of strings of information about the graphics API. */
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "String.h"
|
||||
#include "WorldEnv.h"
|
||||
#include "Platform.h"
|
||||
#include "WorldEvents.h"
|
||||
|
||||
void World_Reset() {
|
||||
World_Width = 0; World_Height = 0; World_Length = 0;
|
||||
|
|
|
@ -17,7 +17,7 @@ EventHandler_Raise_Void(WorldEvents_NewMap, WorldEvents_NewMapCount);
|
|||
|
||||
/* Raised when a portion of the world is read and decompressed, or generated.
|
||||
The floating point argument is progress (from 0 to 1). */
|
||||
Event_Float32 WorldEvents_MapLoading[EventHandler_Size];
|
||||
Event_Float32 WorldEvents_MapLoading;
|
||||
Int32 WorldEvents_MapLoadingCount;
|
||||
|
||||
/* Raises MapLoading event. */
|
||||
|
|
Loading…
Reference in a new issue