Fix up include headers, try to reduce dependencies

Ensure that all headers are self-sufficient instead of relying on included
headers to include headers for execution.
This commit is contained in:
2016-07-16 23:27:52 +10:00
parent 6da8eff9b1
commit a426461dad
17 changed files with 176 additions and 159 deletions
+1 -69
View File
@@ -1,80 +1,12 @@
#ifndef DENGINE_ASSET_MANAGER_H
#define DENGINE_ASSET_MANAGER_H
#include "Dengine/Assets.h"
#include "Dengine/Shader.h"
#include "Dengine/Texture.h"
#define MAX_TEXTURE_SIZE 1024
enum TexList
{
texlist_empty,
texlist_hero,
texlist_terrain,
texlist_font,
texlist_count,
};
enum ShaderList
{
shaderlist_sprite,
shaderlist_count,
};
enum TerrainCoords
{
terraincoords_ground,
terraincoords_count,
};
enum HeroCoords
{
herocoords_idle,
herocoords_walkA,
herocoords_walkB,
herocoords_head,
herocoords_waveA,
herocoords_waveB,
herocoords_count,
};
typedef struct TexAtlas
{
// TODO(doyle): String hash based lookup
v4 texRect[128];
} TexAtlas;
// TODO(doyle): We only use the offset and advance metric at the moment, remove?
typedef struct FontMetrics
{
i32 ascent;
i32 descent;
i32 lineGap;
} FontMetrics;
typedef struct CharMetrics
{
i32 advance;
i32 leftSideBearing;
// TODO(doyle): Utilise kerning
i32 *kerning;
v2i offset;
v2i trueSize;
} CharMetrics;
typedef struct Font
{
TexAtlas *atlas;
Texture *tex;
FontMetrics metrics;
CharMetrics *charMetrics;
v2i codepointRange;
v2i maxSize;
} Font;
// TODO(doyle): Switch to hash based lookup
typedef struct AssetManager
{
+75
View File
@@ -0,0 +1,75 @@
#ifndef DENGINE_ASSETS_H
#define DENGINE_ASSETS_H
#include "Dengine/Math.h"
#include "Dengine/Texture.h"
enum TexList
{
texlist_empty,
texlist_hero,
texlist_terrain,
texlist_font,
texlist_count,
};
enum ShaderList
{
shaderlist_sprite,
shaderlist_count,
};
enum TerrainCoords
{
terraincoords_ground,
terraincoords_count,
};
enum HeroCoords
{
herocoords_idle,
herocoords_walkA,
herocoords_walkB,
herocoords_head,
herocoords_waveA,
herocoords_waveB,
herocoords_count,
};
typedef struct TexAtlas
{
// TODO(doyle): String hash based lookup
v4 texRect[128];
} TexAtlas;
// TODO(doyle): We only use the offset and advance metric at the moment, remove?
typedef struct FontMetrics
{
i32 ascent;
i32 descent;
i32 lineGap;
} FontMetrics;
typedef struct CharMetrics
{
i32 advance;
i32 leftSideBearing;
// TODO(doyle): Utilise kerning
i32 *kerning;
v2i offset;
v2i trueSize;
} CharMetrics;
typedef struct Font
{
TexAtlas *atlas;
Texture *tex;
FontMetrics metrics;
CharMetrics *charMetrics;
v2i codepointRange;
v2i maxSize;
} Font;
#endif
+3
View File
@@ -1,6 +1,9 @@
#ifndef DENGINE_DEBUG_H
#define DENGINE_DEBUG_H
#include "Dengine/Assets.h"
#include "Dengine/Common.h"
#include "Dengine/Math.h"
#include "Dengine/Renderer.h"
#define INVALID_CODE_PATH TRUE
+2 -1
View File
@@ -1,8 +1,9 @@
#ifndef DENGINE_ENTITY_H
#define DENGINE_ENTITY_H
#include "Dengine/Texture.h"
#include "Dengine/Common.h"
#include "Dengine/Math.h"
#include "Dengine/Texture.h"
enum Direction
{
+7 -38
View File
@@ -1,56 +1,25 @@
#ifndef DENGINE_PLATFORM_H
#define DENGINE_PLATFORM_H
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "Dengine/Common.h"
#include "Dengine/Debug.h"
// TODO(doyle): Create own custom memory allocator
#define PLATFORM_MEM_ALLOC(num, type) \
CAST(type *) platform_memoryAlloc(num * sizeof(type))
#define PLATFORM_MEM_FREE(ptr, bytes) \
platform_memoryFree(CAST(void *) ptr, bytes)
typedef struct
typedef struct PlatformFileRead
{
void *buffer;
i32 size;
} PlatformFileRead;
// TODO(doyle): Create own custom memory allocator
#define PLATFORM_MEM_FREE(ptr, bytes) platform_memoryFree(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
inline void platform_memoryFree(void *data, i32 numBytes)
{
if (data) free(data);
#ifdef DENGINE_DEBUG
GLOBAL_debugState.totalMemoryAllocated -= numBytes;
#endif
}
inline void *platform_memoryAlloc(i32 numBytes)
{
void *result = calloc(1, numBytes);
#ifdef DENGINE_DEBUG
if (result)
GLOBAL_debugState.totalMemoryAllocated += numBytes;
#endif
return result;
}
inline void platform_closeFileRead(PlatformFileRead *file)
{
PLATFORM_MEM_FREE(file->buffer, file->size);
}
void platform_memoryFree(void *data, i32 numBytes);
#define PLATFORM_MEM_ALLOC(num, type) CAST(type *) platform_memoryAlloc(num * sizeof(type))
void *platform_memoryAlloc(i32 numBytes);
void platform_closeFileRead(PlatformFileRead *file);
i32 platform_readFileToBuffer(const char *const filePath,
PlatformFileRead *file);
+6 -24
View File
@@ -1,14 +1,17 @@
#ifndef DENGINE_RENDERER_H
#define DENGINE_RENDERER_H
#include "Dengine/Entity.h"
#include "Dengine/AssetManager.h"
#include "Dengine/Common.h"
#include "Dengine/Entity.h"
#include "Dengine/Math.h"
#include "Dengine/Shader.h"
typedef struct Renderer
{
Shader *shader;
GLuint vao;
GLuint vbo;
u32 vao;
u32 vbo;
i32 numVertexesInVbo;
v2 vertexNdcFactor;
v2 size;
@@ -20,11 +23,6 @@ typedef struct RenderTex
v4 texRect;
} RenderTex;
typedef struct RenderQuad
{
v4 vertex[4];
} RenderQuad;
// TODO(doyle): Clean up lines
// Renderer::~Renderer() { glDeleteVertexArrays(1, &this->quadVAO); }
void renderer_rect(Renderer *const renderer, v4 cameraBounds, v2 pos, v2 size,
@@ -55,20 +53,4 @@ inline void renderer_staticString(Renderer *const renderer, Font *const font,
void renderer_entity(Renderer *renderer, v4 cameraBounds, Entity *entity,
f32 dt, f32 rotate, v4 color);
INTERNAL inline void renderer_flipTexCoord(v4 *texCoords, b32 flipX, b32 flipY)
{
if (flipX)
{
v4 tmp = *texCoords;
texCoords->x = tmp.z;
texCoords->z = tmp.x;
}
if (flipY)
{
v4 tmp = *texCoords;
texCoords->y = tmp.w;
texCoords->w = tmp.y;
}
}
#endif
+1 -1
View File
@@ -1,8 +1,8 @@
#ifndef DENGINE_SHADER_H
#define DENGINE_SHADER_H
#include "Dengine/OpenGL.h"
#include "Dengine/Math.h"
#include "Dengine/OpenGL.h"
typedef struct Shader
{
+1 -1
View File
@@ -1,8 +1,8 @@
#ifndef DENGINE_TEXTURE_H
#define DENGINE_TEXTURE_H
#include "Dengine/OpenGL.h"
#include "Dengine/Common.h"
#include "Dengine/OpenGL.h"
#define TARGET_TEXTURE_SIZE 1024
#define TARGET_BYTES_PER_PIXEL 4
+3 -8
View File
@@ -1,19 +1,16 @@
#ifndef WORLDTRAVELLER_GAME_H
#define WORLDTRAVELLER_GAME_H
#include "Dengine/AssetManager.h"
#include "Dengine/Common.h"
#include "Dengine/Entity.h"
#include "Dengine/Math.h"
#include "Dengine/Renderer.h"
#define NUM_KEYS 1024
#define METERS_TO_PIXEL 64
enum State
{
state_active,
state_menu,
state_win,
};
enum State;
typedef struct World
{
@@ -27,7 +24,6 @@ typedef struct World
i32 heroIndex;
i32 freeEntityIndex;
} World;
typedef struct GameState
@@ -44,7 +40,6 @@ typedef struct GameState
AssetManager assetManager;
} GameState;
void worldTraveller_gameInit(GameState *state, v2i windowSize);
void worldTraveller_gameUpdateAndRender(GameState *state, const f32 dt);
#endif