Engine Interface
This commit is contained in:
@ -17,36 +17,87 @@
|
||||
#include <Engine.hpp>
|
||||
#include <IAEngine/Engine.hpp>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <IAEngine/EngineInterface.hpp>
|
||||
|
||||
GameFunctionTable g_gameFunctions{};
|
||||
|
||||
//SDL_SetAppMetadata("SDL Hello World Example", "1.0", "com.example.sdl-hello-world");
|
||||
namespace ia::iae
|
||||
{
|
||||
String GetStringVersion(IN UINT64 version)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
VOID __Internal_Engine::Initialize()
|
||||
{
|
||||
IAE_LOG_INFO("Booting IAEngine for ", g_gameFunctions.GetName());
|
||||
|
||||
SDL_SetAppMetadata(g_gameFunctions.GetName(), GetStringVersion(g_gameFunctions.GetVersion()).c_str(),
|
||||
g_gameFunctions.GetPackageName());
|
||||
|
||||
g_gameFunctions.OnInitialize();
|
||||
}
|
||||
|
||||
VOID __Internal_Engine::Terminate()
|
||||
{
|
||||
g_gameFunctions.OnTerminate();
|
||||
|
||||
IAE_LOG_INFO("Shutting down IAEngine");
|
||||
}
|
||||
|
||||
VOID __Internal_Engine::Iterate()
|
||||
{
|
||||
}
|
||||
|
||||
VOID __Internal_Engine::ProcessEvent(IN SDL_Event *event)
|
||||
{
|
||||
switch (event->type)
|
||||
{
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace ia::iae
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#include <IAEngine/EngineInterface.hpp>
|
||||
|
||||
BOOL ValidateGameFunctionTable(IN GameFunctionTable gameFunctionTable)
|
||||
{
|
||||
if(!gameFunctionTable.OnInitialize) return false;
|
||||
if(!gameFunctionTable.OnTerminate) return false;
|
||||
if(!gameFunctionTable.OnDebugDraw) return false;
|
||||
if(!gameFunctionTable.OnFixedUpdate) return false;
|
||||
if(!gameFunctionTable.OnUpdate) return false;
|
||||
if(!gameFunctionTable.OnResize) return false;
|
||||
if(!gameFunctionTable.GetName) return false;
|
||||
if(!gameFunctionTable.GetVersion) return false;
|
||||
if(!gameFunctionTable.GetPackageName) return false;
|
||||
if(!gameFunctionTable.GetDeveloperName) return false;
|
||||
if(!gameFunctionTable.GetPublisherName) return false;
|
||||
if (!gameFunctionTable.OnInitialize)
|
||||
return false;
|
||||
if (!gameFunctionTable.OnTerminate)
|
||||
return false;
|
||||
if (!gameFunctionTable.OnDebugDraw)
|
||||
return false;
|
||||
if (!gameFunctionTable.OnFixedUpdate)
|
||||
return false;
|
||||
if (!gameFunctionTable.OnUpdate)
|
||||
return false;
|
||||
if (!gameFunctionTable.OnResize)
|
||||
return false;
|
||||
if (!gameFunctionTable.GetName)
|
||||
return false;
|
||||
if (!gameFunctionTable.GetVersion)
|
||||
return false;
|
||||
if (!gameFunctionTable.GetPackageName)
|
||||
return false;
|
||||
if (!gameFunctionTable.GetDeveloperName)
|
||||
return false;
|
||||
if (!gameFunctionTable.GetPublisherName)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
C_DECL(IAE_DLL_API ia::BOOL IAEngine_OnInitialize(IN GameFunctionTable gameFunctionTable))
|
||||
{
|
||||
if(!ValidateGameFunctionTable(gameFunctionTable))
|
||||
if (!ValidateGameFunctionTable(gameFunctionTable))
|
||||
{
|
||||
IAE_LOG_ERROR("Invalid game function table was passed to the engine. Exiting..");
|
||||
return false;
|
||||
@ -54,21 +105,23 @@ C_DECL(IAE_DLL_API ia::BOOL IAEngine_OnInitialize(IN GameFunctionTable gameFunct
|
||||
|
||||
g_gameFunctions = gameFunctionTable;
|
||||
|
||||
IAE_LOG_INFO("Booting IAEngine for ", gameFunctionTable.GetName());
|
||||
__Internal_Engine::Initialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
C_DECL(IAE_DLL_API ia::VOID IAEngine_OnTerminate())
|
||||
{
|
||||
IAE_LOG_INFO("Shutting down IAEngine");
|
||||
__Internal_Engine::Terminate();
|
||||
}
|
||||
|
||||
C_DECL(IAE_DLL_API ia::BOOL IAEngine_OnIterate())
|
||||
{
|
||||
__Internal_Engine::Iterate();
|
||||
return true;
|
||||
}
|
||||
|
||||
C_DECL(IAE_DLL_API ia::VOID IAEngine_OnEvent(IN PVOID event))
|
||||
{
|
||||
__Internal_Engine::ProcessEvent((SDL_Event *) event);
|
||||
}
|
||||
0
Engine/Src/Imp/CPP/Random.cpp
Normal file
0
Engine/Src/Imp/CPP/Random.cpp
Normal file
0
Engine/Src/Imp/CPP/Time.cpp
Normal file
0
Engine/Src/Imp/CPP/Time.cpp
Normal file
@ -18,7 +18,16 @@
|
||||
|
||||
#include <IAEngine/Base.hpp>
|
||||
|
||||
#include <SDL3/SDL_events.h>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
class __Internal_Engine
|
||||
{
|
||||
public:
|
||||
STATIC VOID Initialize();
|
||||
STATIC VOID Terminate();
|
||||
STATIC VOID Iterate();
|
||||
STATIC VOID ProcessEvent(IN SDL_Event* event);
|
||||
};
|
||||
}
|
||||
0
Engine/Src/Imp/HPP/Random.hpp
Normal file
0
Engine/Src/Imp/HPP/Random.hpp
Normal file
0
Engine/Src/Imp/HPP/Time.hpp
Normal file
0
Engine/Src/Imp/HPP/Time.hpp
Normal file
@ -40,4 +40,18 @@ namespace ia::iae
|
||||
{
|
||||
using Handle = INT64;
|
||||
STATIC CONSTEXPR Handle INVALID_HANDLE = -1;
|
||||
|
||||
using Vec2 = glm::vec2;
|
||||
using Vec3 = glm::vec3;
|
||||
using Vec4 = glm::vec4;
|
||||
|
||||
struct Color
|
||||
{
|
||||
UINT8 R{0xFF};
|
||||
UINT8 G{0xFF};
|
||||
UINT8 B{0xFF};
|
||||
UINT8 A{0xFF};
|
||||
|
||||
|
||||
};
|
||||
} // namespace ia::iae
|
||||
@ -20,5 +20,136 @@
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
using InputKey = UINT8;
|
||||
|
||||
struct TimePeriod
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct INode
|
||||
{
|
||||
String Name{};
|
||||
};
|
||||
|
||||
struct IComponent
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct ICameraComponent: public IComponent
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct ImageView
|
||||
{
|
||||
Handle Image{};
|
||||
Vec4 Scissor{};
|
||||
};
|
||||
|
||||
struct SoundView
|
||||
{
|
||||
Handle Sound{};
|
||||
INT32 LoopTimes{};
|
||||
TimePeriod LoopDelay{};
|
||||
};
|
||||
|
||||
struct GeometryVertex
|
||||
{
|
||||
Vec2 Position{};
|
||||
Vec2 TexCoord{};
|
||||
Vec4 Color{};
|
||||
};
|
||||
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
// Event Functions
|
||||
STATIC Handle CreateEvent(IN CONST String& name);
|
||||
STATIC VOID DestroyEvent(IN Handle event);
|
||||
STATIC Handle GetEventByName(IN CONST String& name);
|
||||
STATIC VOID AddEventListener(IN Handle event, IN std::function<VOID()> callback);
|
||||
STATIC VOID AddEventListener(IN CONST String& eventName, IN std::function<VOID()> callback);
|
||||
STATIC VOID BroadcastEvent(IN Handle event);
|
||||
STATIC VOID BroadcastEvent(IN CONST String& eventName);
|
||||
|
||||
// Physics Functions
|
||||
STATIC Handle CreatePhysicsBody();
|
||||
STATIC VOID DestroyPhysicsBody(IN Handle body);
|
||||
|
||||
// Renderer Functions
|
||||
STATIC Handle CreateGeometry(IN CONST Vector<GeometryVertex>& vertices, IN CONST Vector<INT32>& indices);
|
||||
STATIC VOID DestroyGeometry(IN Handle geometry);
|
||||
STATIC VOID DrawGeometry(IN Handle handle);
|
||||
STATIC VOID ResizeDisplay(IN INT32 newWidth, IN INT32 newHeight);
|
||||
|
||||
// Renderer State Functions
|
||||
STATIC VOID SetRenderState_Scissor(IN Vec4 rect);
|
||||
STATIC VOID SetRenderState_FlippedH(IN BOOL value);
|
||||
STATIC VOID SetRenderState_FlippedV(IN BOOL value);
|
||||
STATIC VOID SetRenderState_TextureOffset(IN Vec2 off);
|
||||
STATIC VOID SetRenderState_ColorOverlay(IN Color color);
|
||||
STATIC VOID SetRenderState_CameraRelative(IN BOOL value);
|
||||
STATIC VOID SetRenderState_ScissorEnabled(IN BOOL value);
|
||||
STATIC VOID SetRenderState_Texture(IN Handle image);
|
||||
STATIC VOID SetRenderState_Transform(IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation, IN UINT8 layer, IN INT16 sortIndex);
|
||||
|
||||
// Debug Draw Functions
|
||||
STATIC VOID DebugDraw_SetColor(IN Color color);
|
||||
STATIC VOID DebugDraw_StrokeWidth(IN FLOAT32 width);
|
||||
STATIC VOID DebugDraw_Line(IN Vec2 from, IN Vec2 to);
|
||||
STATIC VOID DebugDraw_FillRect(IN Vec2 position, IN Vec2 size);
|
||||
STATIC VOID DebugDraw_StrokeRect(IN Vec2 position, IN Vec2 size);
|
||||
|
||||
// Resource Functions
|
||||
STATIC Handle CreateImage();
|
||||
STATIC Handle CreateSound();
|
||||
STATIC VOID DestroyImage(IN Handle image);
|
||||
STATIC VOID DestroySound(IN Handle sound);
|
||||
STATIC Vec2 GetImageExtent(IN Handle image);
|
||||
STATIC VOID RescaleImage(IN Handle image, IN INT32 newWidth, IN INT32 newHeight);
|
||||
STATIC Handle CombineImages(IN CONST Vector<Handle>& images, IN INT32 unitWidth, IN INT32 unitHeight, IN INT32 unitCountX, IN INT32 unitCountY);
|
||||
|
||||
// Game Functions
|
||||
STATIC VOID SetTimeScale(IN FLOAT32 scale);
|
||||
STATIC VOID SetActiveCamera(IN ICameraComponent* cameraComponent);
|
||||
|
||||
// Scene Functions
|
||||
STATIC Handle CreateScene();
|
||||
STATIC VOID DestroyScene(IN Handle handle);
|
||||
STATIC VOID ChangeActiveScene(IN Handle scene);
|
||||
STATIC VOID AddNodeToActiveScene(IN RefPtr<INode> node);
|
||||
STATIC INode* GetNodeFromActiveScene(IN CONST String& name);
|
||||
STATIC VOID RemoveNodeFromActiveScene(IN CONST String& name);
|
||||
STATIC VOID AddNodeToScene(IN Handle scene, IN RefPtr<INode> node);
|
||||
STATIC VOID RemoveNodeFromScene(IN Handle scene, IN CONST String& name);
|
||||
|
||||
// Input Functions
|
||||
STATIC Vec2 GetInputAxis();
|
||||
STATIC VOID SwitchInputModeToText();
|
||||
STATIC VOID SwitchInputModeToAction();
|
||||
STATIC Vec2 GetInputPointerPosition();
|
||||
STATIC BOOL IsInputKeyDown(IN InputKey key);
|
||||
STATIC BOOL WasInputKeyPressed(IN InputKey key);
|
||||
STATIC BOOL WasInputKeyReleased(IN InputKey key);
|
||||
STATIC BOOL IsInputActionDown(IN Handle action);
|
||||
STATIC BOOL WasInputActionPressed(IN Handle action);
|
||||
STATIC BOOL WasInputActionReleased(IN Handle action);
|
||||
STATIC BOOL IsInputActionDown(IN PCCHAR action);
|
||||
STATIC BOOL WasInputActionPressed(IN PCCHAR action);
|
||||
STATIC BOOL WasInputActionReleased(IN PCCHAR action);
|
||||
STATIC Handle BindInputAction(IN CONST String& name, IN InputKey key);
|
||||
STATIC VOID BindInputAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey);
|
||||
|
||||
// Random Functions
|
||||
STATIC FLOAT32 GetRandomFloat();
|
||||
STATIC INT32 GetRandomInRange(IN INT32 min, IN INT32 max);
|
||||
|
||||
// Time Functions
|
||||
STATIC INT64 GetTickCount();
|
||||
STATIC INT64 GetUnixSecond();
|
||||
STATIC INT64 GetUnixMillisecond();
|
||||
STATIC FLOAT32 GetFrameDeltaTime();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user