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:
parent
6da8eff9b1
commit
a426461dad
@ -138,6 +138,7 @@
|
||||
<None Include="data\shaders\sprite.vert.glsl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\include\Dengine\Assets.h" />
|
||||
<ClInclude Include="src\include\Dengine\Debug.h" />
|
||||
<ClInclude Include="src\include\Dengine\Platform.h" />
|
||||
<ClInclude Include="src\include\Dengine\AssetManager.h" />
|
||||
|
@ -89,5 +89,8 @@
|
||||
<ClInclude Include="src\include\Dengine\Debug.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\include\Dengine\Assets.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,5 +1,5 @@
|
||||
#include "Dengine/Platform.h"
|
||||
#include "Dengine/Debug.h"
|
||||
#include "Dengine/Platform.h"
|
||||
|
||||
DebugState GLOBAL_debugState;
|
||||
|
||||
|
@ -1,7 +1,37 @@
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Dengine/Platform.h"
|
||||
#include "Dengine/Debug.h"
|
||||
|
||||
void platform_memoryFree(void *data, i32 numBytes)
|
||||
{
|
||||
if (data) free(data);
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
GLOBAL_debugState.totalMemoryAllocated -= numBytes;
|
||||
#endif
|
||||
}
|
||||
|
||||
void *platform_memoryAlloc(i32 numBytes)
|
||||
{
|
||||
void *result = calloc(1, numBytes);
|
||||
|
||||
#ifdef DENGINE_DEBUG
|
||||
if (result)
|
||||
GLOBAL_debugState.totalMemoryAllocated += numBytes;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
void platform_closeFileRead(PlatformFileRead *file)
|
||||
{
|
||||
PLATFORM_MEM_FREE(file->buffer, file->size);
|
||||
}
|
||||
|
||||
i32 platform_readFileToBuffer(const char *const filePath,
|
||||
PlatformFileRead *file)
|
||||
PlatformFileRead *file)
|
||||
{
|
||||
HANDLE fileHandle = CreateFile(filePath, GENERIC_READ, FILE_SHARE_READ,
|
||||
NULL, OPEN_ALWAYS, 0, NULL);
|
||||
|
@ -1,10 +1,32 @@
|
||||
#include "Dengine/Platform.h"
|
||||
#include "Dengine/OpenGL.h"
|
||||
#include "Dengine/Renderer.h"
|
||||
#include "Dengine/Debug.h"
|
||||
#include "Dengine/OpenGL.h"
|
||||
#include "Dengine/Platform.h"
|
||||
|
||||
#define RENDER_BOUNDING_BOX FALSE
|
||||
|
||||
typedef struct RenderQuad
|
||||
{
|
||||
v4 vertex[4];
|
||||
} RenderQuad;
|
||||
|
||||
INTERNAL inline void 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;
|
||||
}
|
||||
}
|
||||
|
||||
INTERNAL void updateBufferObject(Renderer *const renderer,
|
||||
RenderQuad *const quads, const i32 numQuads)
|
||||
{
|
||||
@ -174,7 +196,7 @@ void renderer_string(Renderer *const renderer, v4 cameraBounds,
|
||||
|
||||
/* Get texture out */
|
||||
v4 charTexRect = font->atlas->texRect[relativeIndex];
|
||||
renderer_flipTexCoord(&charTexRect, FALSE, TRUE);
|
||||
flipTexCoord(&charTexRect, FALSE, TRUE);
|
||||
RenderTex renderTex = {font->tex, charTexRect};
|
||||
|
||||
RenderQuad charQuad =
|
||||
@ -220,7 +242,7 @@ void renderer_entity(Renderer *renderer, v4 cameraBounds, Entity *entity,
|
||||
if (entity->direction == direction_east)
|
||||
{
|
||||
// NOTE(doyle): Flip the x coordinates to flip the tex
|
||||
renderer_flipTexCoord(&texRect, TRUE, FALSE);
|
||||
flipTexCoord(&texRect, TRUE, FALSE);
|
||||
}
|
||||
RenderTex renderTex = {entity->tex, texRect};
|
||||
RenderQuad entityQuad =
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "Dengine\Texture.h"
|
||||
#include "Dengine/Texture.h"
|
||||
|
||||
enum BytesPerPixel
|
||||
{
|
||||
|
@ -1,11 +1,14 @@
|
||||
#include "Dengine/Platform.h"
|
||||
#include "Dengine/AssetManager.h"
|
||||
#include "Dengine/Debug.h"
|
||||
|
||||
#include "WorldTraveller/WorldTraveller.h"
|
||||
|
||||
// TODO(doyle): This is temporary! Maybe abstract into our platform layer, or
|
||||
// choose to load assets outside of WorldTraveller !
|
||||
#include "Dengine/Debug.h"
|
||||
#include "Dengine/Platform.h"
|
||||
|
||||
enum State
|
||||
{
|
||||
state_active,
|
||||
state_menu,
|
||||
state_win,
|
||||
};
|
||||
|
||||
INTERNAL Entity *addEntity(World *world, v2 pos, v2 size, enum EntityType type,
|
||||
enum Direction direction, Texture *tex, b32 collides)
|
||||
|
@ -1,8 +1,9 @@
|
||||
#if 1
|
||||
#include "Dengine/AssetManager.h"
|
||||
#include "Dengine/Renderer.h"
|
||||
#include "Dengine/Math.h"
|
||||
#include "Dengine/Common.h"
|
||||
#include "Dengine/Debug.h"
|
||||
#include "Dengine/Math.h"
|
||||
#include "Dengine/OpenGL.h"
|
||||
|
||||
#include "WorldTraveller/WorldTraveller.h"
|
||||
|
||||
@ -136,8 +137,8 @@ int main()
|
||||
f32 framesPerSecond = 1.0f / secondsElapsed;
|
||||
|
||||
char textBuffer[256];
|
||||
snprintf(textBuffer, ARRAY_COUNT(textBuffer), "Dengine | %f ms/f | %f fps", msPerFrame,
|
||||
framesPerSecond);
|
||||
snprintf(textBuffer, ARRAY_COUNT(textBuffer),
|
||||
"Dengine | %f ms/f | %f fps", msPerFrame, framesPerSecond);
|
||||
|
||||
glfwSetWindowTitle(window, textBuffer);
|
||||
titleUpdateFrequencyInSeconds = 0.5f;
|
||||
|
@ -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
src/include/Dengine/Assets.h
Normal file
75
src/include/Dengine/Assets.h
Normal 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
|
@ -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
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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,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,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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user