Stardew Engine
Loading...
Searching...
No Matches
Game2DLayer.h
Go to the documentation of this file.
1#ifndef H_GAME2DLAYER
2#define H_GAME2DLAYER
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include "IntTypes.h"
9#include "DynArray.h"
10#include "HandleDefs.h"
11#include <cglm/cglm.h>
12#include "InputContext.h"
13#include "FreeLookCameraMode.h"
14#include "Entity2DCollection.h"
15#include "TimerPool.h"
16
17#define MAX_GAME_LAYER_ASSET_FILE_PATH_LEN 128
18
20
22
23struct GameLayer2DData;
24struct BinarySerializer;
25
26typedef void (*PreFirstInitFn)(struct GameLayer2DData* pGameLayerData);
27typedef void (*PreLoadLevelFn)(struct GameLayer2DData* pGameLayerData);
28
33typedef void (*LevelDataPacketExtenderFn)(struct GameLayer2DData* pGameLayerData, struct BinarySerializer* pBS);
34
41typedef void (*LevelDataRequestHandlerExtenderFn)(struct GameLayer2DData* pGameLayerData, struct BinarySerializer* pBS);
42
43typedef void (*LevelDataHandlerExtenderFn)(struct GameLayer2DData* pGameLayerData, struct BinarySerializer* pBS);
44
45
47struct DrawContext;
48typedef struct DrawContext DrawContext;
49
50// the real type of this should be hSprite ie u32 but i want to save memory so u16 it is - that
51// should be enough for anyone - just store the tiles in the first 16 bits worth of indexes
52
53
55{
57 vec2 scale;
58 float rotation;
60};
61
62struct TilemapRenderData;
63struct TilemapLayerRenderData;
64
70
84
85struct TileMap
86{
87 VECTOR(struct TileMapLayer) layers;
89 struct TilemapRenderData* pRenderData;
90};
91
240
242{
243
244 const char* atlasFilePath;
245
246 const char* levelFilePath;
247
248};
249
250void TilemapLayer_GetTLBR(vec2 tl, vec2 br, struct TileMapLayer* pTMLayer);
251
252void Game2DLayer_Get(struct GameFrameworkLayer* pLayer, struct Game2DLayerOptions* pOptions, DrawContext* pDC);
253
254void Game2DLayer_SaveLevelFile(struct GameLayer2DData* pData, const char* outputFilePath);
255
256void GameLayer2D_OnPush(struct GameFrameworkLayer* pLayer, DrawContext* drawContext, InputContext* inputContext);
257
258void Game2DLayer_OnPop(struct GameFrameworkLayer* pLayer, DrawContext* drawContext, InputContext* inputContext);
259
263void G2D_SaveLevelDataInternal(struct GameLayer2DData* pData, struct BinarySerializer* pBS);
264
265#ifdef __cplusplus
266}
267#endif
268
269#endif // !H_GAME2DLAYER
u32 VertIndexT
Definition DrawContext.h:52
vec2 vec2 struct Entity2DCollection struct GameFrameworkLayer * pLayer
Definition EntityQuadTree.h:38
void(* LevelDataRequestHandlerExtenderFn)(struct GameLayer2DData *pGameLayerData, struct BinarySerializer *pBS)
Definition Game2DLayer.h:41
void(* PreLoadLevelFn)(struct GameLayer2DData *pGameLayerData)
Definition Game2DLayer.h:27
ObjectLayer2DDrawOrder
Definition Game2DLayer.h:66
@ DrawOrder_TopDown
Definition Game2DLayer.h:67
@ DrawOrder_Index
Definition Game2DLayer.h:68
void Game2DLayer_Get(struct GameFrameworkLayer *pLayer, struct Game2DLayerOptions *pOptions, DrawContext *pDC)
Definition Game2DLayer.c:753
void Game2DLayer_SaveLevelFile(struct GameLayer2DData *pData, const char *outputFilePath)
Definition Game2DLayer.c:793
void G2D_SaveLevelDataInternal(struct GameLayer2DData *pData, struct BinarySerializer *pBS)
Definition Game2DLayer.c:243
void Game2DLayer_OnPop(struct GameFrameworkLayer *pLayer, DrawContext *drawContext, InputContext *inputContext)
Definition Game2DLayer.c:736
void(* LevelDataPacketExtenderFn)(struct GameLayer2DData *pGameLayerData, struct BinarySerializer *pBS)
Extend the writing of the level data packet that servers send to clients.
Definition Game2DLayer.h:33
#define MAX_GAME_LAYER_ASSET_FILE_PATH_LEN
Definition Game2DLayer.h:17
void TilemapLayer_GetTLBR(vec2 tl, vec2 br, struct TileMapLayer *pTMLayer)
Definition Game2DLayer.c:31
void(* PreFirstInitFn)(struct GameLayer2DData *pGameLayerData)
Definition Game2DLayer.h:26
void(* LevelDataHandlerExtenderFn)(struct GameLayer2DData *pGameLayerData, struct BinarySerializer *pBS)
Definition Game2DLayer.h:43
void GameLayer2D_OnPush(struct GameFrameworkLayer *pLayer, DrawContext *drawContext, InputContext *inputContext)
Definition Game2DLayer.c:692
HGeneric HTimer
Definition HandleDefs.h:36
HGeneric HEntity2DQuadtreeNode
Definition HandleDefs.h:44
HGeneric HPhysicsWorld
Definition HandleDefs.h:40
HGeneric H2DWorldspaceVertexBuffer
Definition HandleDefs.h:26
HGeneric hAtlas
Definition HandleDefs.h:14
u16 TileIndex
Definition IntTypes.h:18
uint32_t u32
Definition IntTypes.h:12
Definition BinarySerializer.h:17
Definition DrawContext.h:59
Definition Entity2DCollection.h:30
Definition FreeLookCameraMode.h:9
Definition Game2DLayer.h:242
const char * atlasFilePath
Definition Game2DLayer.h:244
const char * levelFilePath
Definition Game2DLayer.h:246
Definition GameFrameworkEvent.c:14
Definition GameFramework.h:42
Definition Game2DLayer.h:93
VECTOR(VertIndexT) pWorldspaceIndices
int windowH
Window height.
Definition Game2DLayer.h:170
HTimer hNetworkStateUpdateTimer
handler for timer that calls G2D_Enqueue_Worldstate_Packet
Definition Game2DLayer.h:238
struct Transform2D camera
the one and only camera
Definition Game2DLayer.h:117
struct FreeLookCameraModeControls freeLookCtrls
controls for free look mode
Definition Game2DLayer.h:128
bool bSkipDraw
Definition Game2DLayer.h:206
bool bLoaded
mostly pointless
Definition Game2DLayer.h:107
char atlasFilePath[MAX_GAME_LAYER_ASSET_FILE_PATH_LEN]
Path of loaded atlas file.
Definition Game2DLayer.h:140
bool bCurrentLocationIsDirty
Current location has changed in such a way that it needs to be saved, when a new area is moved to or ...
Definition Game2DLayer.h:211
void * pUserData
Game specific data.
Definition Game2DLayer.h:185
int windowW
Window width.
Definition Game2DLayer.h:165
PreLoadLevelFn preLoadLevelFn
Definition Game2DLayer.h:193
int cameraClampedToTilemapLayer
Which layer, if any, is the camera clamped to. If it is not clamped (the default) then this should be...
Definition Game2DLayer.h:123
VECTOR(struct Worldspace2DVert) pWorldspaceVertices
buffers of vertices and indices populated each frame
PreFirstInitFn preFirstInitCallback
a callback called when the layer is pushed, and the level and all entities are loaded,...
Definition Game2DLayer.h:191
bool bFreeLookMode
When in this mode the game is paused and you have a different set of controls to freely move the came...
Definition Game2DLayer.h:114
H2DWorldspaceVertexBuffer vertexBuffer
Definition Game2DLayer.h:135
LevelDataHandlerExtenderFn levelDataHandlerExtender
AS THE CLIENT : Read extra game specific data the server has written to the initial level data packet...
Definition Game2DLayer.h:232
struct TileMap tilemap
tilemap comprised of a list of tilemap layers
Definition Game2DLayer.h:104
bool bDebugLayerAttatched
flag for whether the debug overlay is pushed on top of the game
Definition Game2DLayer.h:150
struct GameFrameworkLayer * pLayer
for convenience, a reference back to the layer
Definition Game2DLayer.h:95
DrawContext * pDrawContext
HACK : todo: sort out the availabilty of these draw and input contexts todo: use global getter for dr...
Definition Game2DLayer.h:200
LevelDataPacketExtenderFn levelDataPacketExtender
AS THE SERVER : Write extra game specific data to the level data packet the server sends initially to...
Definition Game2DLayer.h:217
char debugMsg[256]
A message to display on the screen when the debug overlay is on top of the game2dlayer.
Definition Game2DLayer.h:155
struct GameFrameworkEventListener * pDebugListener
Listens for the debug overlay game framework layer being pushed.
Definition Game2DLayer.h:160
HPhysicsWorld hPhysicsWorld
Physics world handle.
Definition Game2DLayer.h:175
struct SDTimerPool timerPool
Use this to register timers that will be called after a given time, optionally on repeat.
Definition Game2DLayer.h:235
LevelDataRequestHandlerExtenderFn levelDataRequestHandlerExtender
AS THE SERVER : Read extra game specific data from the level data request packet the client sends to ...
Definition Game2DLayer.h:226
hAtlas hAtlas
handle to atlas containing sprite data
Definition Game2DLayer.h:101
HEntity2DQuadtreeNode hEntitiesQuadTree
The top node of a quad tree that holds references to static sprites for culling.
Definition Game2DLayer.h:98
char tilemapFilePath[MAX_GAME_LAYER_ASSET_FILE_PATH_LEN]
path of loaded level file
Definition Game2DLayer.h:145
struct Entity2DCollection entities
Entities collection.
Definition Game2DLayer.h:180
Definition InputContext.h:137
Definition InputContext.h:59
Definition TimerPool.h:35
Definition Game2DLayer.h:72
bool bIsObjectLayer
Definition Game2DLayer.h:79
enum ObjectLayer2DDrawOrder drawOrder
Definition Game2DLayer.h:80
TileIndex * Tiles
Definition Game2DLayer.h:81
u32 type
Definition Game2DLayer.h:82
int tileHeightPx
Definition Game2DLayer.h:76
struct Transform2D transform
Definition Game2DLayer.h:74
int heightTiles
Definition Game2DLayer.h:78
struct TilemapLayerRenderData * pRenderData
Definition Game2DLayer.h:73
int widthTiles
Definition Game2DLayer.h:77
int tileWidthPx
Definition Game2DLayer.h:75
Definition Game2DLayer.h:86
char * dataFilePath
Definition Game2DLayer.h:88
VECTOR(struct TileMapLayer) layers
struct TilemapRenderData * pRenderData
Definition Game2DLayer.h:89
Definition Game2DLayer.h:55
vec2 position
Definition Game2DLayer.h:56
vec2 scale
Definition Game2DLayer.h:57
bool bMirrored
Definition Game2DLayer.h:59
float rotation
Definition Game2DLayer.h:58
Definition DrawContext.h:13