Merge the game to dengine, reduce header coupling

Until engine architecture can clearly be separated from the game, i.e.
notion of entity storage belonging to game and concept of entity belonging
to engine, worlds/scenes belonging to game or engine- the project will
only refer to Dengine.
This commit is contained in:
Doyle Thai 2016-07-28 15:19:23 +10:00
parent 8a3886a60e
commit 85becdfd6c
17 changed files with 179 additions and 183 deletions

View File

@ -154,7 +154,7 @@
<ClInclude Include="src\include\Dengine\Renderer.h" />
<ClInclude Include="src\include\Dengine\Shader.h" />
<ClInclude Include="src\include\Dengine\Texture.h" />
<ClInclude Include="src\include\WorldTraveller\WorldTraveller.h" />
<ClInclude Include="src\include\Dengine\WorldTraveller.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -33,9 +33,6 @@
<ClCompile Include="src\Platform.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\dengine.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\AssetManager.c">
<Filter>Source Files</Filter>
</ClCompile>
@ -51,6 +48,9 @@
<ClCompile Include="src\Entity.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\dengine.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="data\shaders\default.vert.glsl" />
@ -80,9 +80,6 @@
<ClInclude Include="src\include\Dengine\Renderer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\include\WorldTraveller\WorldTraveller.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\include\Dengine\Entity.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -104,5 +101,8 @@
<ClInclude Include="src\include\Dengine\Audio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\include\Dengine\WorldTraveller.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -21,6 +21,8 @@
#include "Dengine/OpenGL.h"
#include "Dengine/Platform.h"
// TODO(doyle): Switch to hash based lookup
// TODO(doyle): Use pointers, so we can forward declare all assets?
AudioVorbis *asset_getVorbis(AssetManager *assetManager,
const enum AudioList type)
{

View File

@ -1,8 +1,81 @@
#include "Dengine/Debug.h"
#include "Dengine/Platform.h"
#include "Dengine/AssetManager.h"
#include "Dengine/Entity.h"
#include "Dengine/MemoryArena.h"
#include "Dengine/Platform.h"
#include "Dengine/Renderer.h"
#include "Dengine/WorldTraveller.h"
DebugState GLOBAL_debug;
typedef struct DebugState
{
Font font;
i32 *callCount;
f32 stringLineGap;
/* Debug strings rendered in top left corner */
char debugStrings[64][128];
i32 numDebugStrings;
f32 stringUpdateTimer;
f32 stringUpdateRate;
v2 initialStringP;
v2 currStringP;
/* Debug gui console log */
char console[20][128];
i32 consoleIndex;
v2 initialConsoleP;
} DebugState;
GLOBAL_VAR DebugState GLOBAL_debug;
inline char *debug_entitystate_string(i32 val)
{
char *string;
switch(val)
{
case entitystate_idle:
string = "EntityState_Idle";
break;
case entitystate_battle:
string = "EntityState_Battle";
break;
case entitystate_attack:
string = "EntityState_Attack";
break;
case entitystate_dead:
string = "EntityState_Dead";
break;
case entitystate_count:
string = "EntityState_Count (Error!)";
break;
case entitystate_invalid:
string = "EntityState_Invalid (Error!)";
break;
default:
string = "EntityState Unknown (NOT DEFINED)";
}
return string;
}
inline char *debug_entityattack_string(i32 val)
{
char *string;
switch(val)
{
case entityattack_tackle:
string = "EntityAttack_Tackle";
break;
case entityattack_count:
string = "EntityAttack_Count (Error!)";
break;
case entityattack_invalid:
string = "EntityAttack_Invalid";
break;
default:
string = "EntityAttack Unknown (NOT DEFINED)";
}
return string;
}
void debug_init(MemoryArena *arena, v2 windowSize, Font font)
{
@ -30,6 +103,19 @@ void debug_init(MemoryArena *arena, v2 windowSize, Font font)
GLOBAL_debug.initialConsoleP = V2(consoleXPos, consoleYPos);
}
void debug_callCountIncrement(i32 id)
{
ASSERT(id < debugcallcount_num);
GLOBAL_debug.callCount[id]++;
}
void debug_clearCallCounter()
{
for (i32 i = 0; i < debugcallcount_num; i++)
GLOBAL_debug.callCount[i] = 0;
}
void debug_consoleLog(char *string, char *file, int lineNum)
{

View File

@ -1,11 +1,7 @@
#include "Dengine/AssetManager.h"
#include "Dengine/MemoryArena.h"
#include "Dengine/Platform.h"
#include "Dengine/Debug.h"
#include "Dengine/Entity.h"
#include "WorldTraveller/WorldTraveller.h"
#include "Dengine/Debug.h"
#include "Dengine/Platform.h"
#include "Dengine/WorldTraveller.h"
void entity_setActiveAnim(Entity *entity, enum AnimList animId)
{
@ -25,7 +21,8 @@ void entity_setActiveAnim(Entity *entity, enum AnimList animId)
void entity_updateAnim(Entity *entity, f32 dt)
{
if (!entity->tex) return;
if (!entity->tex)
return;
// TODO(doyle): Recheck why we have this twice
EntityAnim_ *entityAnim = &entity->anim[entity->currAnimId];
@ -87,12 +84,11 @@ void entity_addGenericMob(MemoryArena *arena, AssetManager *assetManager,
entity_addAnim(assetManager, mob, animlist_hero_battlePose);
entity_addAnim(assetManager, mob, animlist_hero_tackle);
mob->currAnimId = animlist_hero_idle;
}
Entity *entity_add(MemoryArena *arena, World *world, v2 pos, v2 size,
enum EntityType type, enum Direction direction,
Texture *tex, b32 collides)
enum EntityType type, enum Direction direction, Texture *tex,
b32 collides)
{
#ifdef DENGINE_DEBUG

View File

@ -3,7 +3,7 @@
#include <stdlib.h>
#include "Dengine/Platform.h"
#include "Dengine/Debug.h"
#include "Dengine/MemoryArena.h"
void platform_memoryFree(MemoryArena *arena, void *data, i32 numBytes)
{

View File

@ -1,7 +1,10 @@
#include "Dengine/Renderer.h"
#include "Dengine/Debug.h"
#include "Dengine/Entity.h"
#include "Dengine/OpenGL.h"
#include "Dengine/Platform.h"
#include "Dengine/Shader.h"
#include "Dengine/Texture.h"
#define RENDER_BOUNDING_BOX FALSE

View File

@ -1,5 +1,4 @@
#include "WorldTraveller/WorldTraveller.h"
#include "Dengine/WorldTraveller.h"
#include "Dengine/Audio.h"
#include "Dengine/Debug.h"
#include "Dengine/Entity.h"

View File

@ -1,16 +1,9 @@
#if 1
#include "Dengine/AssetManager.h"
#include "Dengine/Audio.h"
#include "Dengine/Common.h"
#include "Dengine/Debug.h"
#include "Dengine/Math.h"
#include "Dengine/OpenGL.h"
#include "Dengine/Platform.h"
#include "WorldTraveller/WorldTraveller.h"
// TODO(doyle): Temporary
struct AudioRenderer;
#include "Dengine/WorldTraveller.h"
void key_callback(GLFWwindow *window, int key, int scancode, int action, int mode)
{
@ -176,7 +169,3 @@ int main()
glfwTerminate();
return 0;
}
#else
#include <Tutorial.cpp>
#endif

View File

@ -8,10 +8,6 @@
/* Forward declaration */
typedef struct MemoryArena MemoryArena;
#define MAX_TEXTURE_SIZE 1024
// TODO(doyle): Switch to hash based lookup
// TODO(doyle): Use pointers, so we can forward declare all assets?
typedef struct AssetManager
{
Texture textures[32];
@ -22,7 +18,7 @@ typedef struct AssetManager
Font font;
} AssetManager;
GLOBAL_VAR AssetManager assetManager;
#define MAX_TEXTURE_SIZE 1024
AudioVorbis *asset_getVorbis(AssetManager *assetManager,
const enum AudioList type);
@ -48,8 +44,7 @@ const i32 asset_loadTTFont(AssetManager *assetManager, MemoryArena *arena,
inline i32 asset_getVFontSpacing(FontMetrics metrics)
{
i32 result =
metrics.ascent - metrics.descent + metrics.lineGap;
i32 result = metrics.ascent - metrics.descent + metrics.lineGap;
return result;
}

View File

@ -4,8 +4,11 @@
#define STB_VORBIS_HEADER_ONLY
#include <STB/stb_vorbis.c>
#include "Dengine/Common.h"
#include "Dengine/Math.h"
#include "Dengine/Texture.h"
/* Forward Declaration */
typedef struct Texture Texture;
enum TexList
{

View File

@ -21,9 +21,10 @@ typedef struct AudioManager
} AudioManager;
#define AUDIO_REPEAT_INFINITE -10
#define AUDIO_SOURCE_UNASSIGNED -1
struct AudioRenderer
typedef struct AudioRenderer
{
i32 sourceIndex;
ALuint bufferId[4];
@ -31,9 +32,8 @@ struct AudioRenderer
AudioVorbis *audio;
ALuint format;
i32 numPlays;
};
} AudioRenderer;
typedef struct AudioRenderer AudioRenderer;
const i32 audio_init(AudioManager *audioManager);
const i32 audio_streamPlayVorbis(AudioManager *audioManager,

View File

@ -4,10 +4,10 @@
#include "Dengine/Assets.h"
#include "Dengine/Common.h"
#include "Dengine/Math.h"
#include "Dengine/Renderer.h"
#include "Dengine/Entity.h"
#include "WorldTraveller/WorldTraveller.h"
/* Forward Declaration */
typedef struct GameState GameState;
typedef struct MemoryArena MemoryArena;
#define INVALID_CODE_PATH 0
enum DebugCallCount
@ -16,92 +16,10 @@ enum DebugCallCount
debugcallcount_num,
};
typedef struct DebugState
{
Font font;
i32 *callCount;
f32 stringLineGap;
/* Debug strings rendered in top left corner */
char debugStrings[64][128];
i32 numDebugStrings;
f32 stringUpdateTimer;
f32 stringUpdateRate;
v2 initialStringP;
v2 currStringP;
/* Debug gui console log */
char console[20][128];
i32 consoleIndex;
v2 initialConsoleP;
} DebugState;
extern DebugState GLOBAL_debug;
inline void debug_callCountIncrement(i32 id)
{
ASSERT(id < debugcallcount_num);
GLOBAL_debug.callCount[id]++;
}
inline void debug_clearCallCounter()
{
for (i32 i = 0; i < debugcallcount_num; i++)
GLOBAL_debug.callCount[i] = 0;
}
inline char *debug_entitystate_string(i32 val)
{
char *string;
switch(val)
{
case entitystate_idle:
string = "EntityState_Idle";
break;
case entitystate_battle:
string = "EntityState_Battle";
break;
case entitystate_attack:
string = "EntityState_Attack";
break;
case entitystate_dead:
string = "EntityState_Dead";
break;
case entitystate_count:
string = "EntityState_Count (Error!)";
break;
case entitystate_invalid:
string = "EntityState_Invalid (Error!)";
break;
default:
string = "EntityState Unknown (NOT DEFINED)";
}
return string;
}
inline char *debug_entityattack_string(i32 val)
{
char *string;
switch(val)
{
case entityattack_tackle:
string = "EntityAttack_Tackle";
break;
case entityattack_count:
string = "EntityAttack_Count (Error!)";
break;
case entityattack_invalid:
string = "EntityAttack_Invalid";
break;
default:
string = "EntityAttack Unknown (NOT DEFINED)";
}
return string;
}
void debug_init(MemoryArena *arena, v2 windowSize, Font font);
void debug_callCountIncrement(enum DebugCallCount id);
void debug_clearCallCounter();
#define DEBUG_LOG(string) debug_consoleLog(string, __FILE__, __LINE__);
void debug_consoleLog(char *string, char *file, int lineNum);

View File

@ -6,6 +6,7 @@
typedef struct AssetManager AssetManager;
typedef struct AudioRenderer AudioRenderer;
typedef struct MemoryArena MemoryArena;
typedef struct Texture Texture;
typedef struct Animation Animation;
typedef struct World World;
@ -101,8 +102,8 @@ typedef struct Entity
void entity_setActiveAnim(Entity *entity, enum AnimList animId);
void entity_updateAnim(Entity *entity, f32 dt);
void entity_addAnim(AssetManager *assetManager, Entity *entity, i32 animId);
void entity_addGenericMob(MemoryArena *arena, AssetManager *assetManager, World *world,
v2 pos);
void entity_addGenericMob(MemoryArena *arena, AssetManager *assetManager,
World *world, v2 pos);
Entity *entity_add(MemoryArena *arena, World *world, v2 pos, v2 size,
enum EntityType type, enum Direction direction, Texture *tex,
b32 collides);

View File

@ -1,12 +1,15 @@
#ifndef DENGINE_RENDERER_H
#define DENGINE_RENDERER_H
#include "Dengine/AssetManager.h"
#include "Dengine/Common.h"
#include "Dengine/Entity.h"
#include "Dengine/Math.h"
#include "Dengine/Shader.h"
#include "Dengine/MemoryArena.h"
/* Forward Declaration */
typedef struct Shader Shader;
typedef struct Entity Entity;
typedef struct MemoryArena MemoryArena;
typedef struct Texture Texture;
typedef struct Font Font;
typedef struct Renderer
{

View File

@ -7,6 +7,7 @@
#define TARGET_TEXTURE_SIZE 1024
#define TARGET_BYTES_PER_PIXEL 4
// TODO(doyle): Look into merging into assets.h file ..
typedef struct Texture
{
// Holds the ID of the texture object, used for all texture operations to