Mobs battle with hero, engine architect. changes

Mobs battle in real-time with the hero when in range. Start encapsulating
logic into entityStateSwitch() to organise entity properties changing
between different states.

Introduce basic concept of memory management in MemoryArena. Begin passing
around a memory object to track memory usage and eventually delegate
memory allocations through. Remove the old memory tracker in the debug
object and incorporate into engine primarily.

Add a debug console for logging information and events to the screen in
a console-like fashion. Debug is now initialised after the game, this is
so that you can pass the game's memory arena and font file to the debug
services. Debug services now properly initialise debug element positions
from this information and not through the update routine.
This commit is contained in:
2016-07-19 21:19:26 +10:00
parent 5fc58ca643
commit fd94eb5afd
17 changed files with 386 additions and 163 deletions
+8 -5
View File
@@ -2,8 +2,10 @@
#define DENGINE_ASSET_MANAGER_H
#include "Dengine/Assets.h"
#include "Dengine/MemoryArena.h"
#include "Dengine/Shader.h"
#include "Dengine/Texture.h"
#include "Dengine/MemoryArena.h"
#define MAX_TEXTURE_SIZE 1024
@@ -29,12 +31,13 @@ const i32 asset_loadTextureImage(AssetManager *assetManager,
const char *const path,
const enum TexList type);
const i32 asset_loadShaderFiles(AssetManager *assetManager,
const i32 asset_loadShaderFiles(AssetManager *assetManager, MemoryArena *arena,
const char *const vertexPath,
const char *const fragmentPath,
const enum ShaderList type);
const i32 asset_loadTTFont(AssetManager *assetManager, const char *filePath);
const i32 asset_loadTTFont(AssetManager *assetManager, MemoryArena *arena,
const char *filePath);
inline i32 asset_getVFontSpacing(FontMetrics metrics)
{
@@ -43,8 +46,8 @@ inline i32 asset_getVFontSpacing(FontMetrics metrics)
return result;
}
void asset_addAnimation(AssetManager *assetManager, i32 texId,
i32 animId, i32 *atlasIndexes, i32 numFrames,
f32 frameDuration);
void asset_addAnimation(AssetManager *assetManager, MemoryArena *arena,
i32 texId, i32 animId, i32 *atlasIndexes, i32 numFrames,
f32 frameDuration);
#endif
+1
View File
@@ -28,5 +28,6 @@ typedef double f64;
i32 common_strlen(const char *const string);
i32 common_strcmp(const char *a, const char *b);
void common_itoa(i32 value, char *buf, i32 bufSize);
#endif
+14 -9
View File
@@ -9,7 +9,7 @@
#include "WorldTraveller/WorldTraveller.h"
#define INVALID_CODE_PATH TRUE
#define INVALID_CODE_PATH 0
enum DebugCallCount
{
debugcallcount_drawArrays,
@@ -18,19 +18,22 @@ enum DebugCallCount
typedef struct DebugState
{
i32 totalMemoryAllocated;
Font font;
i32 *callCount;
f32 stringLineGap;
/* Debug strings rendered in top left corner */
char debugStrings[256][64];
char debugStrings[64][128];
i32 numDebugStrings;
f32 stringUpdateTimer;
f32 stringUpdateRate;
v2 initialStringP;
v2 currStringP;
v2 initialStringPos;
v2 stringPos;
f32 stringLineGap;
/* Debug gui console log */
char console[20][128];
i32 consoleIndex;
v2 initialConsoleP;
} DebugState;
extern DebugState GLOBAL_debug;
@@ -97,14 +100,16 @@ inline char *debug_entityattack_string(i32 val)
}
void debug_init();
void debug_init(MemoryArena *arena, v2 windowSize, Font font);
#define DEBUG_PUSH_STRING(string) debug_pushString(string, NULL, "char")
#define DEBUG_PUSH_VAR(formatString, data, type) \
debug_pushString(formatString, CAST(void *)&data, type)
void debug_pushString(char *formatString, void *data, char *dataType);
void debug_stringUpdateAndRender(Renderer *renderer, Font *font, f32 dt);
void debug_drawUi(GameState *state, f32 dt);
#define DEBUG_LOG(string) debug_consoleLog(string, __FILE__, __LINE__);
void debug_consoleLog(char *string, char *file, int lineNum);
#endif
+1 -1
View File
@@ -65,7 +65,7 @@ typedef struct EntityAnim_
typedef struct Entity
{
u32 id;
i32 id;
v2 pos; // Position
v2 dPos; // Velocity
+9
View File
@@ -0,0 +1,9 @@
#ifndef DENGINE_MEMORY_ARENA_H
#define DENGINE_MEMORY_ARENA_H
typedef struct MemoryArena
{
i32 bytesAllocated;
} MemoryArena;
#endif
+7 -6
View File
@@ -2,6 +2,7 @@
#define DENGINE_PLATFORM_H
#include "Dengine/Common.h"
#include "Dengine/MemoryArena.h"
typedef struct PlatformFileRead
{
@@ -10,17 +11,17 @@ typedef struct PlatformFileRead
} PlatformFileRead;
// TODO(doyle): Create own custom memory allocator
#define PLATFORM_MEM_FREE(ptr, bytes) platform_memoryFree(CAST(void *) ptr, bytes)
#define PLATFORM_MEM_FREE(arena, ptr, bytes) platform_memoryFree(arena, CAST(void *) ptr, bytes)
// TODO(doyle): numBytes in mem free is temporary until we create custom
// allocator since we haven't put in a system to track memory usage per
// allocation
void platform_memoryFree(void *data, i32 numBytes);
void platform_memoryFree(MemoryArena *arena, void *data, i32 numBytes);
#define PLATFORM_MEM_ALLOC(num, type) CAST(type *) platform_memoryAlloc(num * sizeof(type))
void *platform_memoryAlloc(i32 numBytes);
#define PLATFORM_MEM_ALLOC(arena, num, type) CAST(type *) platform_memoryAlloc(arena, num * sizeof(type))
void *platform_memoryAlloc(MemoryArena *arena, i32 numBytes);
void platform_closeFileRead(PlatformFileRead *file);
i32 platform_readFileToBuffer(const char *const filePath,
void platform_closeFileRead(MemoryArena *arena, PlatformFileRead *file);
i32 platform_readFileToBuffer(MemoryArena *arena, const char *const filePath,
PlatformFileRead *file);
#endif
+9 -9
View File
@@ -6,6 +6,7 @@
#include "Dengine/Entity.h"
#include "Dengine/Math.h"
#include "Dengine/Shader.h"
#include "Dengine/MemoryArena.h"
typedef struct Renderer
{
@@ -36,18 +37,17 @@ inline void renderer_staticRect(Renderer *const renderer, v2 pos, v2 size,
color);
}
void renderer_string(Renderer *const renderer, MemoryArena *arena,
v4 cameraBounds, Font *const font,
const char *const string, v2 pos, f32 rotate, v4 color);
void renderer_string(Renderer *const renderer, v4 cameraBounds,
Font *const font, const char *const string, v2 pos,
f32 rotate, v4 color);
inline void renderer_staticString(Renderer *const renderer, Font *const font,
const char *const string, v2 pos, f32 rotate,
v4 color)
inline void renderer_staticString(Renderer *const renderer, MemoryArena *arena,
Font *const font, const char *const string,
v2 pos, f32 rotate, v4 color)
{
v4 staticCameraBounds = math_getRect(V2(0, 0), renderer->size);
renderer_string(renderer, staticCameraBounds, font, string, pos, rotate,
color);
renderer_string(renderer, arena, staticCameraBounds, font, string, pos,
rotate, color);
}
void renderer_entity(Renderer *renderer, v4 cameraBounds, Entity *entity,
@@ -5,6 +5,7 @@
#include "Dengine/Common.h"
#include "Dengine/Entity.h"
#include "Dengine/Math.h"
#include "Dengine/MemoryArena.h"
#include "Dengine/Renderer.h"
#define NUM_KEYS 1024
@@ -41,6 +42,7 @@ typedef struct GameState
i32 tileSize;
AssetManager assetManager;
MemoryArena arena;
} GameState;
void worldTraveller_gameInit(GameState *state, v2 windowSize);