Removing named namespace from code base.

This commit is contained in:
2026-08-22 21:39:21 -04:00
parent 678795b793
commit 4180622d6a
158 changed files with 12260 additions and 12648 deletions
+25 -25
View File
@@ -1,4 +1,4 @@
#include <Controller/DebugCameraController.h> #include <Controller/DebugCameraController.h>
#include <Controller/ControllerUtils.h> #include <Controller/ControllerUtils.h>
#include <Core/Common/CoreUtils.h> #include <Core/Common/CoreUtils.h>
@@ -24,10 +24,10 @@ void ActivateDebugController()
{ {
Assert(gIsDebugCameraActive == false); Assert(gIsDebugCameraActive == false);
Juliet::Camera* currentCam = Juliet::GetCurrentCamera(); Camera* currentCam = GetCurrentCamera();
gPreviousCameraIndex = currentCam->Index; gPreviousCameraIndex = currentCam->Index;
Juliet::SetCurrentCamera(kDebugCamera); SetCurrentCamera(kDebugCamera);
gIsDebugCameraActive = true; gIsDebugCameraActive = true;
gFirstUpdate = true; gFirstUpdate = true;
@@ -41,7 +41,7 @@ void DeactivateDebugController()
gIsDebugCameraActive = false; gIsDebugCameraActive = false;
Juliet::SetCurrentCamera(gPreviousCameraIndex); SetCurrentCamera(gPreviousCameraIndex);
} }
bool IsDebugControllerActive() bool IsDebugControllerActive()
@@ -51,26 +51,26 @@ bool IsDebugControllerActive()
void UpdateDebugController(float dt) void UpdateDebugController(float dt)
{ {
Juliet::Camera* currentCam = Juliet::GetCurrentCamera(); Camera* currentCam = GetCurrentCamera();
if (gFirstUpdate) if (gFirstUpdate)
{ {
Juliet::Vector3 dir = Juliet::Vector3{ 0.0f, 0.0f, 0.0f } - currentCam->Position; Vector3 dir = Vector3{ 0.0f, 0.0f, 0.0f } - currentCam->Position;
dir = Juliet::Normalize(dir); dir = Normalize(dir);
gPitch = asinf(dir.z); gPitch = asinf(dir.z);
gYaw = atan2f(dir.y, dir.x); gYaw = atan2f(dir.y, dir.x);
gFirstUpdate = false; gFirstUpdate = false;
Juliet::Vector3 forward; Vector3 forward;
forward.x = cosf(gPitch) * cosf(gYaw); forward.x = cosf(gPitch) * cosf(gYaw);
forward.y = cosf(gPitch) * sinf(gYaw); forward.y = cosf(gPitch) * sinf(gYaw);
forward.z = sinf(gPitch); forward.z = sinf(gPitch);
Juliet::Vector3 right = Juliet::Normalize(Juliet::Cross(Juliet::Vector3{ 0.0f, 0.0f, 1.0f }, forward)); Vector3 right = Normalize(Cross(Vector3{ 0.0f, 0.0f, 1.0f }, forward));
currentCam->Target = currentCam->Position + forward; currentCam->Target = currentCam->Position + forward;
currentCam->Up = Juliet::Cross(forward, right); currentCam->Up = Cross(forward, right);
} }
bool isRightMouseButtonDown = Juliet::IsMouseButtonDown(Juliet::MouseButton::Right); bool isRightMouseButtonDown = IsMouseButtonDown(MouseButton::Right);
if (isRightMouseButtonDown && !gWasRightMouseButtonDown) if (isRightMouseButtonDown && !gWasRightMouseButtonDown)
{ {
gIsFpsModeActive = !gIsFpsModeActive; gIsFpsModeActive = !gIsFpsModeActive;
@@ -82,7 +82,7 @@ void UpdateDebugController(float dt)
return; return;
} }
Juliet::MousePosition mouseDelta = Juliet::GetMouseDelta(); MousePosition mouseDelta = GetMouseDelta();
float sensitivity = 0.005f; float sensitivity = 0.005f;
gYaw += mouseDelta.X * sensitivity; gYaw += mouseDelta.X * sensitivity;
@@ -91,52 +91,52 @@ void UpdateDebugController(float dt)
gPitch = std::min(gPitch, 1.5f); gPitch = std::min(gPitch, 1.5f);
gPitch = std::max(gPitch, -1.5f); gPitch = std::max(gPitch, -1.5f);
if (Juliet::IsKeyDown(Juliet::ScanCode::Q)) if (IsKeyDown(ScanCode::Q))
{ {
gYaw -= 2.0f * dt; gYaw -= 2.0f * dt;
} }
if (Juliet::IsKeyDown(Juliet::ScanCode::E)) if (IsKeyDown(ScanCode::E))
{ {
gYaw += 2.0f * dt; gYaw += 2.0f * dt;
} }
Juliet::Vector3 forward; Vector3 forward;
forward.x = cosf(gPitch) * cosf(gYaw); forward.x = cosf(gPitch) * cosf(gYaw);
forward.y = cosf(gPitch) * sinf(gYaw); forward.y = cosf(gPitch) * sinf(gYaw);
forward.z = sinf(gPitch); forward.z = sinf(gPitch);
Juliet::Vector3 right = Juliet::Normalize(Juliet::Cross(Juliet::Vector3{ 0.0f, 0.0f, 1.0f }, forward)); Vector3 right = Normalize(Cross(Vector3{ 0.0f, 0.0f, 1.0f }, forward));
Juliet::Vector3 defaultUp = Juliet::Cross(forward, right); Vector3 defaultUp = Cross(forward, right);
static const float kMovementPerFrame = 10.f; // 10m/s static const float kMovementPerFrame = 10.f; // 10m/s
float speedPerFrame = kMovementPerFrame; float speedPerFrame = kMovementPerFrame;
if (Juliet::IsKeyDown(Juliet::ScanCode::LeftShift)) if (IsKeyDown(ScanCode::LeftShift))
{ {
speedPerFrame *= 10.f; // 100m/s speedPerFrame *= 10.f; // 100m/s
} }
if (Juliet::IsKeyDown(Juliet::ScanCode::W)) if (IsKeyDown(ScanCode::W))
{ {
currentCam->Position = currentCam->Position + forward * (speedPerFrame * dt); currentCam->Position = currentCam->Position + forward * (speedPerFrame * dt);
} }
if (Juliet::IsKeyDown(Juliet::ScanCode::S)) if (IsKeyDown(ScanCode::S))
{ {
currentCam->Position = currentCam->Position - forward * (speedPerFrame * dt); currentCam->Position = currentCam->Position - forward * (speedPerFrame * dt);
} }
if (Juliet::IsKeyDown(Juliet::ScanCode::D)) if (IsKeyDown(ScanCode::D))
{ {
currentCam->Position = currentCam->Position + right * (speedPerFrame * dt); currentCam->Position = currentCam->Position + right * (speedPerFrame * dt);
} }
if (Juliet::IsKeyDown(Juliet::ScanCode::A)) if (IsKeyDown(ScanCode::A))
{ {
currentCam->Position = currentCam->Position - right * (speedPerFrame * dt); currentCam->Position = currentCam->Position - right * (speedPerFrame * dt);
} }
if (Juliet::IsKeyDown(Juliet::ScanCode::Space)) if (IsKeyDown(ScanCode::Space))
{ {
currentCam->Position = currentCam->Position + defaultUp * (speedPerFrame * dt); currentCam->Position = currentCam->Position + defaultUp * (speedPerFrame * dt);
} }
if (Juliet::IsKeyDown(Juliet::ScanCode::LeftControl)) if (IsKeyDown(ScanCode::LeftControl))
{ {
currentCam->Position = currentCam->Position - defaultUp * (speedPerFrame * dt); currentCam->Position = currentCam->Position - defaultUp * (speedPerFrame * dt);
} }
@@ -148,7 +148,7 @@ void UpdateDebugController(float dt)
#if JULIET_DEBUG #if JULIET_DEBUG
void RenderImGuiDebugController(float dt) void RenderImGuiDebugController(float dt)
{ {
Juliet::Camera* currentCam = Juliet::GetCurrentCamera(); Camera* currentCam = GetCurrentCamera();
ImGui::Text("Delta time: %f", dt); ImGui::Text("Delta time: %f", dt);
+2 -3
View File
@@ -1,13 +1,12 @@
#include <Debug/DebugTopBar.h> #include <Debug/DebugTopBar.h>
#include <game.h> #include <game.h>
#include <imgui.h> #include <imgui.h>
namespace namespace
{ {
Juliet::String GetGameModeName(GameMode gameMode) String GetGameModeName(GameMode gameMode)
{ {
using namespace Juliet;
switch (gameMode) switch (gameMode)
{ {
case GameMode::Editor: return WrapString("Editor"); case GameMode::Editor: return WrapString("Editor");
+7 -7
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/CoreUtils.h> #include <Core/Common/CoreUtils.h>
#include <Core/Memory/Allocator.h> #include <Core/Memory/Allocator.h>
@@ -8,19 +8,19 @@
#define DECLARE_ENTITY() \ #define DECLARE_ENTITY() \
Entity* Base; \ Entity* Base; \
static const Juliet::Class* Kind; static const Class* Kind;
// Will register the class globally at launch // Will register the class globally at launch
#define DEFINE_ENTITY(entity) \ #define DEFINE_ENTITY(entity) \
constexpr Juliet::Class entityKind##entity(#entity, sizeof(#entity) / sizeof(char)); \ constexpr Class entityKind##entity(#entity, sizeof(#entity) / sizeof(char)); \
const Juliet::Class* entity::Kind = &entityKind##entity; const Class* entity::Kind = &entityKind##entity;
using DerivedType = void*; using DerivedType = void*;
struct Entity final struct Entity final
{ {
EntityID ID; EntityID ID;
const Juliet::Class* Kind; const Class* Kind;
DerivedType Derived; DerivedType Derived;
float X, Y; float X, Y;
index_t MeshInstance = indexMax; index_t MeshInstance = indexMax;
@@ -28,7 +28,7 @@ struct Entity final
template <typename EntityType> template <typename EntityType>
concept EntityConcept = requires(EntityType entity) { concept EntityConcept = requires(EntityType entity) {
requires std::same_as<decltype(entity.Kind), const Juliet::Class*>; requires std::same_as<decltype(entity.Kind), const Class*>;
requires std::same_as<decltype(entity.Base), Entity*>; requires std::same_as<decltype(entity.Base), Entity*>;
}; };
@@ -44,7 +44,7 @@ template <typename EntityType>
EntityType* MakeEntity(EntityManager& manager, float x, float y) EntityType* MakeEntity(EntityManager& manager, float x, float y)
{ {
auto* arena = manager.Arena; auto* arena = manager.Arena;
EntityType* result = Juliet::ArenaPushStruct<EntityType>(arena); EntityType* result = ArenaPushStruct<EntityType>(arena);
Entity base; Entity base;
base.X = x; base.X = x;
base.Y = y; base.Y = y;
+6 -6
View File
@@ -1,18 +1,18 @@
#include <Entity/EntityManager.h> #include <Entity/EntityManager.h>
#include <Entity/Entity.h> #include <Entity/Entity.h>
#include <Graphics/MeshRenderer.h> #include <Graphics/MeshRenderer.h>
EntityID EntityManager::ID = 0; EntityID EntityManager::ID = 0;
void InitEntityManager(Juliet::NonNullPtr<World> world) void InitEntityManager(NonNullPtr<World> world)
{ {
EntityManager* newManager = Juliet::ArenaPushStruct<EntityManager>(world->WorldArena); EntityManager* newManager = ArenaPushStruct<EntityManager>(world->WorldArena);
world->EntityManager = newManager; world->EntityManager = newManager;
newManager->Entities.Create(world->WorldArena JULIET_DEBUG_PARAM("Entities")); newManager->Entities.Create(world->WorldArena JULIET_DEBUG_PARAM("Entities"));
newManager->Arena = Juliet::ArenaAllocate({ .Name = "Entity Arena" }); newManager->Arena = ArenaAllocate({ .Name = "Entity Arena" });
} }
void ShutdownEntityManager() void ShutdownEntityManager()
@@ -22,7 +22,7 @@ void ShutdownEntityManager()
EntityManager& GetEntityManager() EntityManager& GetEntityManager()
{ {
Juliet::NonNullPtr entityManager = GetGameState()->World->EntityManager; NonNullPtr entityManager = GetGameState()->World->EntityManager;
return *entityManager; return *entityManager;
} }
@@ -37,7 +37,7 @@ void UpdateEntityManager(EntityManager& manager)
{ {
if (ent.MeshInstance != indexMax) if (ent.MeshInstance != indexMax)
{ {
Juliet::SetMeshInstanceTransform(ent.MeshInstance, Juliet::MatrixTranslation(ent.X, ent.Y, 0.0f)); SetMeshInstanceTransform(ent.MeshInstance, MatrixTranslation(ent.X, ent.Y, 0.0f));
} }
} }
} }
+4 -4
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Container/Vector.h> #include <Core/Container/Vector.h>
@@ -11,13 +11,13 @@ struct EntityManager
{ {
static EntityID ID; static EntityID ID;
Juliet::Arena* Arena; Arena* Arena;
// TODO: Should be a pool // TODO: Should be a pool
Juliet::VectorArena<Entity, 1024> Entities; VectorArena<Entity, 1024> Entities;
}; };
void InitEntityManager(Juliet::NonNullPtr<World> world); void InitEntityManager(NonNullPtr<World> world);
void ShutdownEntityManager(); void ShutdownEntityManager();
EntityManager& GetEntityManager(); EntityManager& GetEntityManager();
void RegisterEntity(EntityManager& manager, Entity* entity); void RegisterEntity(EntityManager& manager, Entity* entity);
+2 -4
View File
@@ -1,4 +1,4 @@
#include <game.h> #include <game.h>
#include <Controller/DebugCameraController.h> #include <Controller/DebugCameraController.h>
#include <Core/HAL/Filesystem/Filesystem.h> #include <Core/HAL/Filesystem/Filesystem.h>
@@ -31,14 +31,12 @@ extern "C" JULIET_API void __cdecl GameShutdown()
{ {
printf("Shutting down game...\n"); printf("Shutting down game...\n");
using namespace Juliet;
ShutdownEntityManager(); ShutdownEntityManager();
} }
extern "C" JULIET_API void __cdecl GameUpdate(Juliet::GameData* params, [[maybe_unused]] float deltaTime) extern "C" JULIET_API void __cdecl GameUpdate(GameData* params, [[maybe_unused]] float deltaTime)
{ {
using namespace Juliet;
gGameState = params->GameState; gGameState = params->GameState;
if (!gGameState) if (!gGameState)
+3 -3
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Memory/MemoryArena.h> #include <Core/Memory/MemoryArena.h>
@@ -6,7 +6,7 @@ struct EntityManager;
struct World struct World
{ {
Juliet::Arena* WorldArena; Arena* WorldArena;
EntityManager* EntityManager; EntityManager* EntityManager;
}; };
@@ -19,7 +19,7 @@ enum class GameMode
struct GameState struct GameState
{ {
Juliet::Arena* TotalArena; Arena* TotalArena;
World* World; World* World;
@@ -1,13 +1,10 @@
#pragma once #pragma once
#include <Core/Application/IApplication.h> #include <Core/Application/IApplication.h>
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet enum class JulietInit_Flags : uint8;
{
enum class JulietInit_Flags : uint8;
struct Arena; struct Arena;
extern JULIET_API void StartApplication(IApplication& app, JulietInit_Flags flags); extern JULIET_API void StartApplication(IApplication& app, JulietInit_Flags flags);
} // namespace Juliet
+11 -14
View File
@@ -1,19 +1,17 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
namespace Juliet struct Camera;
{ struct RenderPass;
struct Camera; struct CommandList;
struct RenderPass; struct Texture;
struct CommandList; struct ColorTargetInfo;
struct Texture; struct DepthStencilTargetInfo;
struct ColorTargetInfo; struct Arena;
struct DepthStencilTargetInfo;
struct Arena;
class IApplication class IApplication
{ {
public: public:
virtual ~IApplication() = default; virtual ~IApplication() = default;
virtual void Init(NonNullPtr<Arena> arena) = 0; virtual void Init(NonNullPtr<Arena> arena) = 0;
@@ -28,5 +26,4 @@ namespace Juliet
// Render Lifecycle (Engine-Managed Render Loop) // Render Lifecycle (Engine-Managed Render Loop)
virtual ColorTargetInfo GetColorTargetInfo(Texture* swapchainTexture) = 0; virtual ColorTargetInfo GetColorTargetInfo(Texture* swapchainTexture) = 0;
virtual DepthStencilTargetInfo* GetDepthTargetInfo() = 0; virtual DepthStencilTargetInfo* GetDepthTargetInfo() = 0;
}; };
} // namespace Juliet
+9 -12
View File
@@ -1,11 +1,9 @@
#pragma once #pragma once
// From https://web.mit.edu/freebsd/head/sys/libkern/crc32.c // From https://web.mit.edu/freebsd/head/sys/libkern/crc32.c
namespace Juliet namespace details
{ {
namespace details
{
constexpr uint32_t crc32_tab[] = { constexpr uint32_t crc32_tab[] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832,
0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
@@ -37,10 +35,10 @@ namespace Juliet
0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
}; };
} }
consteval uint32 crc32(const char* str, size_t length) consteval uint32 crc32(const char* str, size_t length)
{ {
const char* p = str; const char* p = str;
uint32_t crc = ~0U; uint32_t crc = ~0U;
while (length--) while (length--)
@@ -48,11 +46,10 @@ namespace Juliet
crc = details::crc32_tab[(crc ^ static_cast<uint8>(*p++)) & 0xFF] ^ (crc >> 8); crc = details::crc32_tab[(crc ^ static_cast<uint8>(*p++)) & 0xFF] ^ (crc >> 8);
} }
return crc ^ ~0U; return crc ^ ~0U;
} }
consteval uint32 operator""_crc32(const char* str, size_t length) consteval uint32 operator""_crc32(const char* str, size_t length)
{ {
return crc32(str, length); return crc32(str, length);
} }
} // namespace Juliet
+76 -79
View File
@@ -1,18 +1,16 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet
{
#define global static #define global static
// 1. Stringify helpers // 1. Stringify helpers
#define JULIET_STR(x) #x #define JULIET_STR(x) #x
#define JULIET_TOSTRING(x) JULIET_STR(x) #define JULIET_TOSTRING(x) JULIET_STR(x)
// 2. Define the pragma operator based on compiler // 2. Define the pragma operator based on compiler
#if defined(__clang__) || defined(__GNUC__) #if defined(__clang__) || defined(__GNUC__)
#define JULIET_PRAGMA(x) _Pragma(#x) #define JULIET_PRAGMA(x) _Pragma(#x)
#define JULIET_SUPPRESS_MSVC(id) #define JULIET_SUPPRESS_MSVC(id)
@@ -27,7 +25,7 @@ namespace Juliet
#define JULIET_SUPPRESS_CLANG(str) #define JULIET_SUPPRESS_CLANG(str)
#endif #endif
// 3. The Agnostic "Push/Pop" // 3. The Agnostic "Push/Pop"
#if defined(__clang__) #if defined(__clang__)
#define JULIET_WARNING_PUSH JULIET_PRAGMA(clang diagnostic push) #define JULIET_WARNING_PUSH JULIET_PRAGMA(clang diagnostic push)
#define JULIET_WARNING_POP JULIET_PRAGMA(clang diagnostic pop) #define JULIET_WARNING_POP JULIET_PRAGMA(clang diagnostic pop)
@@ -40,10 +38,10 @@ namespace Juliet
#endif #endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
// MSVC specific intrinsic // MSVC specific intrinsic
#define JULIET_PLATFORM_BREAK() (__nop(), __debugbreak()) #define JULIET_PLATFORM_BREAK() (__nop(), __debugbreak())
#elif defined(__clang__) || defined(__GNUC__) #elif defined(__clang__) || defined(__GNUC__)
// Clang/GCC specific intrinsic // Clang/GCC specific intrinsic
#define JULIET_PLATFORM_BREAK() __builtin_trap() #define JULIET_PLATFORM_BREAK() __builtin_trap()
#else #else
#include <signal.h> #include <signal.h>
@@ -52,40 +50,40 @@ namespace Juliet
#if JULIET_DEBUG #if JULIET_DEBUG
#define JULIET_ASSERT_INTERNAL(expression, message) \ #define JULIET_ASSERT_INTERNAL(expression, message) \
JULIET_WARNING_PUSH \ JULIET_WARNING_PUSH \
JULIET_SUPPRESS_CLANG("-Wextra-semi-stmt") \ JULIET_SUPPRESS_CLANG("-Wextra-semi-stmt") \
JULIET_SUPPRESS_MSVC(4127) \ JULIET_SUPPRESS_MSVC(4127) \
JULIET_SUPPRESS_MSVC(4548) \ JULIET_SUPPRESS_MSVC(4548) \
{ \ { \
if (!(expression)) [[unlikely]] \ if (!(expression)) [[unlikely]] \
{ \ { \
Juliet::JulietAssert(#expression, message); \ JulietAssert(#expression, message); \
} \ } \
} \ } \
JULIET_WARNING_POP \ JULIET_WARNING_POP \
static_assert(true, "") static_assert(true, "")
#define AssertHR(hr_expression, message) \ #define AssertHR(hr_expression, message) \
do \ do \
{ \ { \
long hr_val = (hr_expression); \ long hr_val = (hr_expression); \
if (hr_val < 0) \ if (hr_val < 0) \
{ \ { \
Juliet::JulietAssert(#hr_expression, message, std::source_location::current(), hr_val); \ JulietAssert(#hr_expression, message, std::source_location::current(), hr_val); \
} \ } \
} \ } \
while (0) while (0)
#define GET_ASSERT_MACRO(_1, _2, NAME, ...) NAME #define GET_ASSERT_MACRO(_1, _2, NAME, ...) NAME
#define Assert(...) GET_ASSERT_MACRO(__VA_ARGS__, JULIET_ASSERT_INTERNAL, JULIET_ASSERT_NO_MSG)(__VA_ARGS__) #define Assert(...) GET_ASSERT_MACRO(__VA_ARGS__, JULIET_ASSERT_INTERNAL, JULIET_ASSERT_NO_MSG)(__VA_ARGS__)
#define JULIET_ASSERT_NO_MSG(expression) JULIET_ASSERT_INTERNAL(expression, "No additional information provided.") #define JULIET_ASSERT_NO_MSG(expression) JULIET_ASSERT_INTERNAL(expression, "No additional information provided.")
#define Unimplemented() \ #define Unimplemented() \
do \ do \
{ \ { \
Juliet::JulietAssert("UNIMPLEMENTED", "This code path is not yet functional."); \ JulietAssert("UNIMPLEMENTED", "This code path is not yet functional."); \
} \ } \
while (0) while (0)
#else #else
#define Assert(...) ((void)0) #define Assert(...) ((void)0)
@@ -93,26 +91,26 @@ namespace Juliet
#define Unimplemented() ((void)0) #define Unimplemented() ((void)0)
#endif #endif
JULIET_API extern void JulietAssert(const char* expression, const char* message, JULIET_API extern void JulietAssert(const char* expression, const char* message,
std::source_location location = std::source_location::current(), long handleResult = 0); std::source_location location = std::source_location::current(), long handleResult = 0);
#define ZeroStruct(structInstance) ZeroSize(sizeof(structInstance), &(structInstance)) #define ZeroStruct(structInstance) ZeroSize(sizeof(structInstance), &(structInstance))
#define ZeroArray(array) ZeroSize(sizeof((array)), (array)) #define ZeroArray(array) ZeroSize(sizeof((array)), (array))
#define ZeroDynArray(Count, Pointer) ZeroSize((Count) * sizeof((Pointer)[0]), Pointer) #define ZeroDynArray(Count, Pointer) ZeroSize((Count) * sizeof((Pointer)[0]), Pointer)
inline void ZeroSize(size_t size, void* ptr) inline void ZeroSize(size_t size, void* ptr)
{ {
auto Byte = (uint8*)ptr; auto Byte = (uint8*)ptr;
while (size--) while (size--)
{ {
*Byte++ = 0; *Byte++ = 0;
} }
} }
#define Restrict __restrict #define Restrict __restrict
template <class Function> template <class Function>
class DeferredFunction class DeferredFunction
{ {
public: public:
explicit DeferredFunction(const Function& otherFct) noexcept explicit DeferredFunction(const Function& otherFct) noexcept
: Callback(otherFct) : Callback(otherFct)
@@ -132,46 +130,46 @@ namespace Juliet
private: private:
Function Callback; Function Callback;
}; };
template <class Function> template <class Function>
auto Defer(Function&& fct) noexcept auto Defer(Function&& fct) noexcept
{ {
return DeferredFunction<std::decay_t<Function>>{ std::forward<Function>(fct) }; return DeferredFunction<std::decay_t<Function>>{ std::forward<Function>(fct) };
} }
inline bool IsValid(ByteBuffer buffer) inline bool IsValid(ByteBuffer buffer)
{ {
return buffer.Size > 0 && buffer.Data; return buffer.Size > 0 && buffer.Data;
} }
extern JULIET_API void Free(ByteBuffer& buffer); extern JULIET_API void Free(ByteBuffer& buffer);
template <std::integral T> template <std::integral T>
[[nodiscard]] constexpr T AlignPow2(T x, T alignment) [[nodiscard]] constexpr T AlignPow2(T x, T alignment)
{ {
// Safety Check: // Safety Check:
Assert(std::has_single_bit(static_cast<size_t>(alignment))); Assert(std::has_single_bit(static_cast<size_t>(alignment)));
return (x + alignment - 1) & ~(alignment - 1); return (x + alignment - 1) & ~(alignment - 1);
} }
template <typename T> template <typename T>
inline void Swap(T* Restrict a, T* Restrict b) inline void Swap(T* Restrict a, T* Restrict b)
{ {
T temp = std::move(*a); T temp = std::move(*a);
*a = std::move(*b); *a = std::move(*b);
*b = std::move(temp); *b = std::move(temp);
} }
// Move to another file dedicated to those // Move to another file dedicated to those
#if defined(__clang__) #if defined(__clang__)
#define COMPILER_CLANG 1 #define COMPILER_CLANG 1
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define COMPILER_MSVC 1 #define COMPILER_MSVC 1
#endif #endif
// Undef anything not defined // Undef anything not defined
#if !defined(COMPILER_CLANG) #if !defined(COMPILER_CLANG)
#define COMPILER_CLANG 0 #define COMPILER_CLANG 0
#endif #endif
@@ -189,9 +187,9 @@ namespace Juliet
#error AlignOf not defined for this compiler. #error AlignOf not defined for this compiler.
#endif #endif
template <typename T> template <typename T>
[[nodiscard]] constexpr const char* GetTypeName() [[nodiscard]] constexpr const char* GetTypeName()
{ {
#if COMPILER_CLANG #if COMPILER_CLANG
return __PRETTY_FUNCTION__; return __PRETTY_FUNCTION__;
#elif COMPILER_MSVC #elif COMPILER_MSVC
@@ -201,31 +199,30 @@ namespace Juliet
#else #else
return "UnknownType"; return "UnknownType";
#endif #endif
} }
inline uint16 safe_cast_uint16(uint32 value) inline uint16 safe_cast_uint16(uint32 value)
{ {
Assert(value <= uint16Max); Assert(value <= uint16Max);
uint16 result = (uint16)value; uint16 result = (uint16)value;
return result; return result;
} }
const uint32 bitmask1 = 0b0000'0001; const uint32 bitmask1 = 0b0000'0001;
const uint32 bitmask2 = 0b0000'0011; const uint32 bitmask2 = 0b0000'0011;
const uint32 bitmask3 = 0b0000'0111; const uint32 bitmask3 = 0b0000'0111;
const uint32 bitmask4 = 0b0000'1111; const uint32 bitmask4 = 0b0000'1111;
const uint32 bitmask5 = 0b0001'1111; const uint32 bitmask5 = 0b0001'1111;
const uint32 bitmask6 = 0b0011'1111; const uint32 bitmask6 = 0b0011'1111;
const uint32 bitmask7 = 0b0111'1111; const uint32 bitmask7 = 0b0111'1111;
const uint32 bitmask8 = 0b1111'1111; const uint32 bitmask8 = 0b1111'1111;
const uint32 bitmask9 = 0x0000'01ff; const uint32 bitmask9 = 0x0000'01ff;
const uint32 bitmask10 = 0x0000'03ff; const uint32 bitmask10 = 0x0000'03ff;
const uint32 bitmask11 = 0x0000'07ff; const uint32 bitmask11 = 0x0000'07ff;
const uint32 bitmask12 = 0x0000'0fff; const uint32 bitmask12 = 0x0000'0fff;
const uint32 bitmask13 = 0x0000'1fff; const uint32 bitmask13 = 0x0000'1fff;
const uint32 bitmask14 = 0x0000'3fff; const uint32 bitmask14 = 0x0000'3fff;
const uint32 bitmask15 = 0x0000'7fff; const uint32 bitmask15 = 0x0000'7fff;
const uint32 bitmask16 = 0x0000'ffff; const uint32 bitmask16 = 0x0000'ffff;
// ... // ...
const uint32 bitmask32 = 0xffff'ffff; const uint32 bitmask32 = 0xffff'ffff;
} // namespace Juliet
+55 -58
View File
@@ -1,89 +1,86 @@
#pragma once #pragma once
namespace Juliet template <typename T>
concept IsEnum = std::is_enum_v<T>;
template <IsEnum E>
constexpr E operator~(E lhs) noexcept
{ {
template <typename T>
concept IsEnum = std::is_enum_v<T>;
template <IsEnum E>
constexpr E operator~(E lhs) noexcept
{
return static_cast<E>(~static_cast<std::underlying_type_t<E>>(lhs)); return static_cast<E>(~static_cast<std::underlying_type_t<E>>(lhs));
} }
template <IsEnum E> template <IsEnum E>
constexpr E operator|(E lhs, E rhs) noexcept constexpr E operator|(E lhs, E rhs) noexcept
{ {
return static_cast<E>(static_cast<std::underlying_type_t<E>>(lhs) | static_cast<std::underlying_type_t<E>>(rhs)); return static_cast<E>(static_cast<std::underlying_type_t<E>>(lhs) | static_cast<std::underlying_type_t<E>>(rhs));
} }
template <IsEnum E> template <IsEnum E>
constexpr E& operator|=(E& lhs, E rhs) noexcept constexpr E& operator|=(E& lhs, E rhs) noexcept
{ {
return lhs = (lhs | rhs); return lhs = (lhs | rhs);
} }
template <IsEnum E> template <IsEnum E>
constexpr E operator&(E lhs, E rhs) noexcept constexpr E operator&(E lhs, E rhs) noexcept
{ {
return static_cast<E>(static_cast<std::underlying_type_t<E>>(lhs) & static_cast<std::underlying_type_t<E>>(rhs)); return static_cast<E>(static_cast<std::underlying_type_t<E>>(lhs) & static_cast<std::underlying_type_t<E>>(rhs));
} }
template <IsEnum E> template <IsEnum E>
constexpr E& operator&=(E& lhs, E rhs) noexcept constexpr E& operator&=(E& lhs, E rhs) noexcept
{ {
return lhs = (lhs & rhs); return lhs = (lhs & rhs);
} }
template <IsEnum E> template <IsEnum E>
constexpr E operator^(E lhs, E rhs) noexcept constexpr E operator^(E lhs, E rhs) noexcept
{ {
return static_cast<E>(static_cast<std::underlying_type_t<E>>(lhs) ^ static_cast<std::underlying_type_t<E>>(rhs)); return static_cast<E>(static_cast<std::underlying_type_t<E>>(lhs) ^ static_cast<std::underlying_type_t<E>>(rhs));
} }
template <IsEnum E> template <IsEnum E>
constexpr E& operator^=(E& lhs, E rhs) noexcept constexpr E& operator^=(E& lhs, E rhs) noexcept
{ {
return lhs = (lhs ^ rhs); return lhs = (lhs ^ rhs);
} }
template <IsEnum E> template <IsEnum E>
constexpr std::underlying_type_t<E> operator-(E lhs, E rhs) noexcept constexpr std::underlying_type_t<E> operator-(E lhs, E rhs) noexcept
{ {
using T = std::underlying_type_t<E>; using T = std::underlying_type_t<E>;
return static_cast<T>(static_cast<T>(lhs) - static_cast<T>(rhs)); return static_cast<T>(static_cast<T>(lhs) - static_cast<T>(rhs));
} }
template <IsEnum E> template <IsEnum E>
constexpr std::underlying_type_t<E> operator+(E lhs, E rhs) noexcept constexpr std::underlying_type_t<E> operator+(E lhs, E rhs) noexcept
{ {
using T = std::underlying_type_t<E>; using T = std::underlying_type_t<E>;
return static_cast<T>(static_cast<T>(lhs) + static_cast<T>(rhs)); return static_cast<T>(static_cast<T>(lhs) + static_cast<T>(rhs));
} }
template <IsEnum E> template <IsEnum E>
constexpr E operator-(E lhs, std::underlying_type_t<E> rhs) noexcept constexpr E operator-(E lhs, std::underlying_type_t<E> rhs) noexcept
{ {
using T = std::underlying_type_t<E>; using T = std::underlying_type_t<E>;
return static_cast<E>(static_cast<T>(static_cast<T>(lhs) - rhs)); return static_cast<E>(static_cast<T>(static_cast<T>(lhs) - rhs));
} }
template <IsEnum E> template <IsEnum E>
constexpr E operator+(E lhs, std::underlying_type_t<E> rhs) noexcept constexpr E operator+(E lhs, std::underlying_type_t<E> rhs) noexcept
{ {
using T = std::underlying_type_t<E>; using T = std::underlying_type_t<E>;
return static_cast<E>(static_cast<T>(static_cast<T>(lhs) + rhs)); return static_cast<E>(static_cast<T>(static_cast<T>(lhs) + rhs));
} }
template <IsEnum E> template <IsEnum E>
constexpr std::underlying_type_t<E> ToUnderlying(E enm) noexcept constexpr std::underlying_type_t<E> ToUnderlying(E enm) noexcept
{ {
return static_cast<std::underlying_type_t<E>>(enm); return static_cast<std::underlying_type_t<E>>(enm);
} }
template <IsEnum E> template <IsEnum E>
constexpr E ToEnum(std::underlying_type_t<E> value) noexcept constexpr E ToEnum(std::underlying_type_t<E> value) noexcept
{ {
return static_cast<E>(value); return static_cast<E>(value);
} }
} // namespace Juliet
+12 -15
View File
@@ -1,18 +1,16 @@
#pragma once #pragma once
#include <Core/Common/CoreUtils.h> #include <Core/Common/CoreUtils.h>
namespace Juliet template <typename Type, typename OtherType>
concept NonNullPtr_Convertible = std::is_convertible_v<OtherType*, Type*>;
template <typename Type, typename OtherType>
concept NonNullPtr_SameType = std::is_same_v<OtherType*, Type*>;
template <typename Type>
class NonNullPtr
{ {
template <typename Type, typename OtherType>
concept NonNullPtr_Convertible = std::is_convertible_v<OtherType*, Type*>;
template <typename Type, typename OtherType>
concept NonNullPtr_SameType = std::is_same_v<OtherType*, Type*>;
template <typename Type>
class NonNullPtr
{
public: public:
constexpr NonNullPtr(Type* ptr) constexpr NonNullPtr(Type* ptr)
: InternalPtr(ptr) : InternalPtr(ptr)
@@ -106,8 +104,7 @@ namespace Juliet
private: private:
Type* InternalPtr; Type* InternalPtr;
}; };
template <typename T> template <typename T>
NonNullPtr(T*) -> NonNullPtr<T>; NonNullPtr(T*) -> NonNullPtr<T>;
} // namespace Juliet
+71 -74
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
#include <Core/Math/MathUtils.h> #include <Core/Math/MathUtils.h>
@@ -14,20 +14,18 @@
#undef RESTORE_GLOBAL #undef RESTORE_GLOBAL
#endif #endif
namespace Juliet struct Arena;
{
struct Arena;
#define ConstString(str) { const_cast<char*>((str)), sizeof(str) - 1 } #define ConstString(str) { const_cast<char*>((str)), sizeof(str) - 1 }
#define CStr(str) ((str).Str) #define CStr(str) ((str).Str)
#define InplaceString(name, size) \ #define InplaceString(name, size) \
char name##_[size]; \ char name##_[size]; \
MemSet(name##_, 0, sizeof(uint32)); \ MemSet(name##_, 0, sizeof(uint32)); \
String name = { name##_, 0 } String name = { name##_, 0 }
// Everything is Little Endian // Everything is Little Endian
enum class StringEncoding : uint8 enum class StringEncoding : uint8
{ {
Unknown = 0, Unknown = 0,
ASCII, ASCII,
LATIN1, LATIN1,
@@ -36,43 +34,43 @@ namespace Juliet
UTF32, UTF32,
UCS2, UCS2,
UCS4, UCS4,
}; };
// Represents a UTF-8 String. // Represents a UTF-8 String.
// Not null terminated. // Not null terminated.
struct String8 struct String8
{ {
char* Str; char* Str;
size_t Size; size_t Size;
}; };
using String = String8; using String = String8;
struct String16 struct String16
{ {
uint16* Str; uint16* Str;
size_t Size; size_t Size;
}; };
struct StringBuffer : String struct StringBuffer : String
{ {
size_t Capacity; size_t Capacity;
}; };
struct UnicodeDecode struct UnicodeDecode
{ {
uint32 Increment; uint32 Increment;
uint32 Codepoint; uint32 Codepoint;
}; };
constexpr uint32 kInvalidUTF8 = 0xFFFD; constexpr uint32 kInvalidUTF8 = 0xFFFD;
inline size_t StringLength(String str) inline size_t StringLength(String str)
{ {
return str.Size; return str.Size;
} }
inline size_t StringLength(const char* str) inline size_t StringLength(const char* str)
{ {
size_t length = 0; size_t length = 0;
if (str) if (str)
{ {
@@ -84,23 +82,23 @@ namespace Juliet
} }
return length; return length;
} }
inline bool IsValid(String str) inline bool IsValid(String str)
{ {
return str.Size > 0 && str.Str != nullptr && *str.Str; return str.Size > 0 && str.Str != nullptr && *str.Str;
} }
inline String WrapString(const char* str) inline String WrapString(const char* str)
{ {
String result = {}; String result = {};
result.Str = const_cast<char*>(str); result.Str = const_cast<char*>(str);
result.Size = str ? strlen(str) : 0; result.Size = str ? strlen(str) : 0;
return result; return result;
} }
inline String FindChar(String str, char c) inline String FindChar(String str, char c)
{ {
String result = str; String result = str;
while (result.Size) while (result.Size)
{ {
@@ -115,19 +113,19 @@ namespace Juliet
} }
} }
return {}; return {};
} }
inline bool ContainsChar(String str, char c) inline bool ContainsChar(String str, char c)
{ {
return IsValid(FindChar(str, c)); return IsValid(FindChar(str, c));
} }
// Return: // Return:
// - < 0 if str1 < str2 // - < 0 if str1 < str2
// - = 0 : Both strings are equals // - = 0 : Both strings are equals
// - > 0 if str1 > str2 // - > 0 if str1 > str2
inline int32 StringCompare(String str1, String str2) inline int32 StringCompare(String str1, String str2)
{ {
size_t len1 = StringLength(str1); size_t len1 = StringLength(str1);
size_t len2 = StringLength(str2); size_t len2 = StringLength(str2);
size_t minLen = Min(len1, len2); size_t minLen = Min(len1, len2);
@@ -145,39 +143,38 @@ namespace Juliet
return 0; return 0;
} }
return result; return result;
} }
JULIET_API uint32 StepUTF8(String& inStr); JULIET_API uint32 StepUTF8(String& inStr);
JULIET_API String FindString(String strLeft, String strRight); JULIET_API String FindString(String strLeft, String strRight);
// Case insensitive compare. Supports ASCII only // Case insensitive compare. Supports ASCII only
// TODO: Support UNICODE // TODO: Support UNICODE
extern JULIET_API int8 StringCompareCaseInsensitive(String str1, String str2); extern JULIET_API int8 StringCompareCaseInsensitive(String str1, String str2);
// Do not allocate anything, you must allocate your out buffer yourself // Do not allocate anything, you must allocate your out buffer yourself
// TODO: Version taking arena that can allocate // TODO: Version taking arena that can allocate
// Do not take String type because we dont know the string encoding we are going from/to // Do not take String type because we dont know the string encoding we are going from/to
// src and dst will be casted based on the encoding. // src and dst will be casted based on the encoding.
// size will correspond to the number of characters // size will correspond to the number of characters
// Will convert \0 character if present. // Will convert \0 character if present.
extern JULIET_API bool ConvertString(StringEncoding from, StringEncoding to, String src, StringBuffer& dst, bool nullTerminate); extern JULIET_API bool ConvertString(StringEncoding from, StringEncoding to, String src, StringBuffer& dst, bool nullTerminate);
extern JULIET_API bool ConvertString(String from, String to, String src, StringBuffer& dst, bool nullTerminate); extern JULIET_API bool ConvertString(String from, String to, String src, StringBuffer& dst, bool nullTerminate);
JULIET_API String StringCopy(NonNullPtr<Arena> arena, String str); JULIET_API String StringCopy(NonNullPtr<Arena> arena, String str);
JULIET_API String16 str16_from_8(NonNullPtr<Arena> arena, String8 str); JULIET_API String16 str16_from_8(NonNullPtr<Arena> arena, String8 str);
template <typename... Args> template <typename... Args>
String Format(NonNullPtr<Arena> arena, const char* formatStr, Args&&... args) String Format(NonNullPtr<Arena> arena, const char* formatStr, Args&&... args)
{ {
std::string result = std::vformat(formatStr, std::make_format_args(args...)); std::string result = std::vformat(formatStr, std::make_format_args(args...));
return StringCopy(arena, WrapString(result.c_str())); return StringCopy(arena, WrapString(result.c_str()));
} }
#define juliet_snprintf snprintf #define juliet_snprintf snprintf
} // namespace Juliet
#ifdef UNIT_TEST #ifdef UNIT_TEST
namespace Juliet::UnitTest namespace UnitTest
{ {
inline void TestFindChar() inline void TestFindChar()
{ {
@@ -192,5 +189,5 @@ namespace Juliet::UnitTest
Assert(FindChar(s2, 'f').Str - s2.Str == 5); Assert(FindChar(s2, 'f').Str - s2.Str == 5);
Assert(FindChar(s3, '1').Str - s3.Str == 0); Assert(FindChar(s3, '1').Str - s3.Str == 0);
} }
} // namespace Juliet::UnitTest } // namespace UnitTest
#endif #endif
+6 -9
View File
@@ -1,13 +1,11 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
#include <Core/Memory/MemoryArena.h> #include <Core/Memory/MemoryArena.h>
namespace Juliet template <typename Type, size_t ReserveSize = 16>
struct VectorArena
{ {
template <typename Type, size_t ReserveSize = 16>
struct VectorArena
{
void Create(NonNullPtr<Arena> arena JULIET_DEBUG_PARAM(const char* name = nullptr)) void Create(NonNullPtr<Arena> arena JULIET_DEBUG_PARAM(const char* name = nullptr))
{ {
Assert(!Arena); Assert(!Arena);
@@ -206,9 +204,8 @@ namespace Juliet
size_t Count = 0; size_t Count = 0;
size_t Capacity = 0; size_t Capacity = 0;
JULIET_DEBUG_ONLY(const char* Name = "VectorArena";) JULIET_DEBUG_ONLY(const char* Name = "VectorArena";)
}; };
static_assert(std::is_standard_layout_v<VectorArena<int>>, static_assert(std::is_standard_layout_v<VectorArena<int>>,
"VectorArena must have a standard layout to remain POD-like."); "VectorArena must have a standard layout to remain POD-like.");
static_assert(std::is_trivially_copyable_v<VectorArena<int>>, static_assert(std::is_trivially_copyable_v<VectorArena<int>>,
"VectorArena must be trivially copyable (no custom destructors/assignment)."); "VectorArena must be trivially copyable (no custom destructors/assignment).");
} // namespace Juliet
+9 -12
View File
@@ -1,21 +1,18 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
#include <Core/Common/String.h> #include <Core/Common/String.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet struct Window;
{
struct Window;
using WindowID = uint8; using WindowID = uint8;
extern JULIET_API Window* CreatePlatformWindow(const char* title, uint16 width, uint16 height, int flags = 0 /* unused */); extern JULIET_API Window* CreatePlatformWindow(const char* title, uint16 width, uint16 height, int flags = 0 /* unused */);
extern JULIET_API void DestroyPlatformWindow(NonNullPtr<Window> window); extern JULIET_API void DestroyPlatformWindow(NonNullPtr<Window> window);
extern JULIET_API void ShowWindow(NonNullPtr<Window> window); extern JULIET_API void ShowWindow(NonNullPtr<Window> window);
extern JULIET_API void HideWindow(NonNullPtr<Window> window); extern JULIET_API void HideWindow(NonNullPtr<Window> window);
extern JULIET_API WindowID GetWindowID(NonNullPtr<Window> window); extern JULIET_API WindowID GetWindowID(NonNullPtr<Window> window);
extern JULIET_API void SetWindowTitle(NonNullPtr<Window> window, String title); extern JULIET_API void SetWindowTitle(NonNullPtr<Window> window, String title);
} // namespace Juliet
@@ -1,12 +1,9 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
namespace Juliet struct DynamicLibrary;
{
struct DynamicLibrary;
extern JULIET_API DynamicLibrary* LoadDynamicLibrary(const char* filename); extern JULIET_API DynamicLibrary* LoadDynamicLibrary(const char* filename);
extern JULIET_API FunctionPtr LoadFunction(NonNullPtr<DynamicLibrary> lib, const char* functionName); extern JULIET_API FunctionPtr LoadFunction(NonNullPtr<DynamicLibrary> lib, const char* functionName);
extern JULIET_API void UnloadDynamicLibrary(NonNullPtr<DynamicLibrary> lib); extern JULIET_API void UnloadDynamicLibrary(NonNullPtr<DynamicLibrary> lib);
} // namespace Juliet
+40 -43
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/HAL/Display/Display.h> #include <Core/HAL/Display/Display.h>
#include <Core/HAL/Keyboard/Keyboard.h> #include <Core/HAL/Keyboard/Keyboard.h>
@@ -9,10 +9,8 @@
// Handles all events from systems handling the Hardware // Handles all events from systems handling the Hardware
// Very inspired by SDL3 // Very inspired by SDL3
namespace Juliet enum class EventType : uint32
{ {
enum class EventType : uint32
{
None = 0, None = 0,
First = None, First = None,
@@ -44,28 +42,28 @@ namespace Juliet
Mouse_End = Mouse_ButtonReleased, Mouse_End = Mouse_ButtonReleased,
Last // Get value from the previous one Last // Get value from the previous one
}; };
struct WindowEvent struct WindowEvent
{ {
WindowID AssociatedWindowID; WindowID AssociatedWindowID;
uint32 DataPadding[2]; // TODO : define how much data param we need uint32 DataPadding[2]; // TODO : define how much data param we need
}; };
struct KeyboardEvent struct KeyboardEvent
{ {
KeyboardID AssociatedKeyboardID; KeyboardID AssociatedKeyboardID;
WindowID WindowID; WindowID WindowID;
Key Key; Key Key;
KeyState KeyState; KeyState KeyState;
KeyMod KeyModeState; KeyMod KeyModeState;
}; };
// ===================================================== // =====================================================
// Mouse Events // Mouse Events
// ===================================================== // =====================================================
struct MouseMovementEvent struct MouseMovementEvent
{ {
MouseID AssociatedMouseID; MouseID AssociatedMouseID;
WindowID WindowID; WindowID WindowID;
float X; float X;
@@ -73,51 +71,50 @@ namespace Juliet
float X_Displacement; float X_Displacement;
float Y_Displacement; float Y_Displacement;
MouseButton ButtonState; MouseButton ButtonState;
}; };
struct MouseButtonEvent struct MouseButtonEvent
{ {
MouseID AssociatedMouseID; MouseID AssociatedMouseID;
WindowID WindowID; WindowID WindowID;
float X; float X;
float Y; float Y;
MouseButton ButtonState; MouseButton ButtonState;
bool IsPressed : 1; bool IsPressed : 1;
}; };
// Tagged union representing ALL possible system events + a bit of data for custom event if needed // Tagged union representing ALL possible system events + a bit of data for custom event if needed
union AllSystemEventUnion union AllSystemEventUnion
{ {
WindowEvent Window; WindowEvent Window;
KeyboardEvent Keyboard; KeyboardEvent Keyboard;
MouseMovementEvent MouseMovement; MouseMovementEvent MouseMovement;
MouseButtonEvent MouseButton; MouseButtonEvent MouseButton;
uint8 Padding[128]; // Make sure that the union is fixed in size and big enough on all platforms. uint8 Padding[128]; // Make sure that the union is fixed in size and big enough on all platforms.
}; };
// Make sure we do not bust the union size // Make sure we do not bust the union size
static_assert(sizeof(AllSystemEventUnion) == sizeof(((AllSystemEventUnion*)nullptr)->Padding)); static_assert(sizeof(AllSystemEventUnion) == sizeof(((AllSystemEventUnion*)nullptr)->Padding));
struct SystemEvent struct SystemEvent
{ {
EventType Type; EventType Type;
uint64 Timestamp; uint64 Timestamp;
AllSystemEventUnion Data; AllSystemEventUnion Data;
}; };
// Poll for any event, return false if no event is available. // Poll for any event, return false if no event is available.
// Equivalent to WaitEvent(event, 0); // Equivalent to WaitEvent(event, 0);
// Will not block // Will not block
extern JULIET_API bool GetEvent(SystemEvent& event); extern JULIET_API bool GetEvent(SystemEvent& event);
// TODO : use chrono to tag the timeout correctly with nanosec // TODO : use chrono to tag the timeout correctly with nanosec
// timeout == -1 means wait for any event before pursuing // timeout == -1 means wait for any event before pursuing
// timeout == 0 means checking once for the frame and getting out // timeout == 0 means checking once for the frame and getting out
// timeout > 0 means wait until time is out // timeout > 0 means wait until time is out
extern JULIET_API bool WaitEvent(SystemEvent& event, int32 timeoutInNS = -1); extern JULIET_API bool WaitEvent(SystemEvent& event, int32 timeoutInNS = -1);
// Add an event onto the event queue. // Add an event onto the event queue.
// TODO : support array of events // TODO : support array of events
extern JULIET_API bool AddEvent(SystemEvent& event); extern JULIET_API bool AddEvent(SystemEvent& event);
extern void Events_NewFrame(float deltaTime); extern void Events_NewFrame(float deltaTime);
} // namespace Juliet
+11 -14
View File
@@ -1,20 +1,17 @@
#pragma once #pragma once
#include <Core/Common/String.h> #include <Core/Common/String.h>
namespace Juliet // Returns the path to the application directory
{ [[nodiscard]] extern JULIET_API String GetBasePath();
// Returns the path to the application directory
[[nodiscard]] extern JULIET_API String GetBasePath();
// Returns the resolved base path to the compiled shaders directory. // Returns the resolved base path to the compiled shaders directory.
// In dev, this resolves to ../../Assets/compiled/ relative to the exe. // In dev, this resolves to ../../Assets/compiled/ relative to the exe.
// In shipping, this resolves to Assets/Shaders/ next to the exe. // In shipping, this resolves to Assets/Shaders/ next to the exe.
[[nodiscard]] extern JULIET_API String GetAssetBasePath(); [[nodiscard]] extern JULIET_API String GetAssetBasePath();
// Builds a full path to an asset file given its filename (e.g. "Triangle.vert.dxil"). // Builds a full path to an asset file given its filename (e.g. "Triangle.vert.dxil").
// The caller owns the returned buffer and must free it. // The caller owns the returned buffer and must free it.
[[nodiscard]] extern JULIET_API String GetAssetPath(NonNullPtr<Arena> arena, String filename); [[nodiscard]] extern JULIET_API String GetAssetPath(NonNullPtr<Arena> arena, String filename);
[[nodiscard]] extern JULIET_API bool IsAbsolutePath(String path); [[nodiscard]] extern JULIET_API bool IsAbsolutePath(String path);
} // namespace Juliet
+29 -32
View File
@@ -1,40 +1,38 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
#include <Core/Common/String.h> #include <Core/Common/String.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet // Opaque type
struct IOStream;
struct IOStreamDataPayload
{ {
// Opaque type };
struct IOStream;
struct IOStreamDataPayload enum class IOStreamStatus : uint8
{ {
};
enum class IOStreamStatus : uint8
{
Ready, Ready,
Error, Error,
EndOfFile, EndOfFile,
NotReady, NotReady,
ReadOnly, ReadOnly,
WriteOnly WriteOnly
}; };
enum class IOStreamSeekPivot : uint8 enum class IOStreamSeekPivot : uint8
{ {
Begin, Begin,
Current, Current,
End, End,
Count Count
}; };
// IOStream can be opened on a file or memory, or anything else. // IOStream can be opened on a file or memory, or anything else.
// Use the interface to make it transparent to the user. // Use the interface to make it transparent to the user.
struct IOStreamInterface struct IOStreamInterface
{ {
uint32 Version; uint32 Version;
int64 (*Size)(NonNullPtr<IOStreamDataPayload> data); int64 (*Size)(NonNullPtr<IOStreamDataPayload> data);
@@ -45,25 +43,24 @@ namespace Juliet
bool (*Flush)(NonNullPtr<IOStreamDataPayload> data, NonNullPtr<IOStreamStatus> status); bool (*Flush)(NonNullPtr<IOStreamDataPayload> data, NonNullPtr<IOStreamStatus> status);
bool (*Close)(NonNullPtr<IOStreamDataPayload> data); bool (*Close)(NonNullPtr<IOStreamDataPayload> data);
}; };
extern JULIET_API IOStream* IOFromFile(NonNullPtr<Arena> arena, String filename, String mode); extern JULIET_API IOStream* IOFromFile(NonNullPtr<Arena> arena, String filename, String mode);
// Let you use an interface to open any io. Is used internally by IOFromFile // Let you use an interface to open any io. Is used internally by IOFromFile
extern JULIET_API IOStream* IOFromInterface(NonNullPtr<Arena> arena, NonNullPtr<const IOStreamInterface> streamInterface, extern JULIET_API IOStream* IOFromInterface(NonNullPtr<Arena> arena, NonNullPtr<const IOStreamInterface> streamInterface,
NonNullPtr<IOStreamDataPayload> payload); NonNullPtr<IOStreamDataPayload> payload);
// Write formatted string into the stream. // Write formatted string into the stream.
extern JULIET_API size_t IOPrintf(NonNullPtr<IOStream> stream, _Printf_format_string_ const char* format, ...); extern JULIET_API size_t IOPrintf(NonNullPtr<IOStream> stream, _Printf_format_string_ const char* format, ...);
extern JULIET_API size_t IOWrite(NonNullPtr<IOStream> stream, ByteBuffer inBuffer); extern JULIET_API size_t IOWrite(NonNullPtr<IOStream> stream, ByteBuffer inBuffer);
extern JULIET_API size_t IORead(NonNullPtr<IOStream> stream, void* ptr, size_t size); extern JULIET_API size_t IORead(NonNullPtr<IOStream> stream, void* ptr, size_t size);
extern JULIET_API int64 IOSeek(NonNullPtr<IOStream> stream, int64 offset, IOStreamSeekPivot pivot); extern JULIET_API int64 IOSeek(NonNullPtr<IOStream> stream, int64 offset, IOStreamSeekPivot pivot);
extern JULIET_API int64 IOSize(NonNullPtr<IOStream> stream); extern JULIET_API int64 IOSize(NonNullPtr<IOStream> stream);
extern JULIET_API ByteBuffer LoadFile(NonNullPtr<Arena> arena, String filename); extern JULIET_API ByteBuffer LoadFile(NonNullPtr<Arena> arena, String filename);
extern JULIET_API ByteBuffer LoadFile(NonNullPtr<Arena> arena, NonNullPtr<IOStream> stream, bool closeStreamWhenDone); extern JULIET_API ByteBuffer LoadFile(NonNullPtr<Arena> arena, NonNullPtr<IOStream> stream, bool closeStreamWhenDone);
extern JULIET_API bool IOClose(NonNullPtr<IOStream> stream); extern JULIET_API bool IOClose(NonNullPtr<IOStream> stream);
} // namespace Juliet
+13 -16
View File
@@ -1,18 +1,16 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
namespace Juliet // Represents a Virtual Key corresponding to the Physical key, but localized using the keyboard layout
// ScanCode reprensent US ASCII Keyboard
// WASD Scan codes are ZQSD in KeyCode for French keyboard
// We use the ASCII value of the generated character as value, when possible.
// Keys that do not produce a character are converted to an abritrary value high enough to not conflict
// Reference: https://www.asciitable.com/
// Reference: https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa299374(v=vs.60)
enum class KeyCode : uint32
{ {
// Represents a Virtual Key corresponding to the Physical key, but localized using the keyboard layout
// ScanCode reprensent US ASCII Keyboard
// WASD Scan codes are ZQSD in KeyCode for French keyboard
// We use the ASCII value of the generated character as value, when possible.
// Keys that do not produce a character are converted to an abritrary value high enough to not conflict
// Reference: https://www.asciitable.com/
// Reference: https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-6.0/aa299374(v=vs.60)
enum class KeyCode : uint32
{
Unknown = 0x0, // 0 Unknown = 0x0, // 0
Unsupported = 0x0, // 0 Unsupported = 0x0, // 0
Return = 0X0Du, // '\r' Return = 0X0Du, // '\r'
@@ -169,10 +167,10 @@ namespace Juliet
Media_Eject = 0x4000010Eu, Media_Eject = 0x4000010Eu,
Media_PlayPause = 0x4000010Fu, Media_PlayPause = 0x4000010Fu,
Media_Select = 0x40000110u, Media_Select = 0x40000110u,
}; };
enum class KeyMod : uint16 enum class KeyMod : uint16
{ {
None = 0b0, None = 0b0,
LeftShift = 0b0000'0000'0001u, LeftShift = 0b0000'0000'0001u,
RightShift = 0b0000'0000'0010u, RightShift = 0b0000'0000'0010u,
@@ -189,5 +187,4 @@ namespace Juliet
Shift = LeftShift | RightShift, Shift = LeftShift | RightShift,
Alt = LeftAlt | RightAlt, Alt = LeftAlt | RightAlt,
OSCommand = LeftOSCommand | RightOSCommand, OSCommand = LeftOSCommand | RightOSCommand,
}; };
} // namespace Juliet
+15 -18
View File
@@ -1,35 +1,32 @@
#pragma once #pragma once
#include <Core/HAL/Keyboard/KeyCode.h> #include <Core/HAL/Keyboard/KeyCode.h>
#include <Core/HAL/Keyboard/ScanCode.h> #include <Core/HAL/Keyboard/ScanCode.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet using KeyboardID = uint8;
{
using KeyboardID = uint8;
enum class KeyPosition : bool enum class KeyPosition : bool
{ {
Up = false, Up = false,
Down = true Down = true
}; };
struct KeyState struct KeyState
{ {
KeyPosition Position; KeyPosition Position;
float Time; float Time;
}; };
struct Key struct Key
{ {
ScanCode ScanCode; ScanCode ScanCode;
KeyCode KeyCode; KeyCode KeyCode;
uint16 Raw; uint16 Raw;
}; };
extern JULIET_API bool IsKeyDown(ScanCode scanCode); extern JULIET_API bool IsKeyDown(ScanCode scanCode);
extern JULIET_API bool IsKeyPressed(ScanCode scanCode); extern JULIET_API bool IsKeyPressed(ScanCode scanCode);
extern JULIET_API KeyMod GetKeyModState(); extern JULIET_API KeyMod GetKeyModState();
extern JULIET_API KeyCode GetKeyCodeFromScanCode(ScanCode scanCode, KeyMod keyModState); extern JULIET_API KeyCode GetKeyCodeFromScanCode(ScanCode scanCode, KeyMod keyModState);
} // namespace Juliet
+9 -12
View File
@@ -1,15 +1,13 @@
#pragma once #pragma once
namespace Juliet // Follow the HID Usage page for USB
// https://usb.org/sites/default/files/hut1_5.pdf
// 0 to 256 Is dedicated to Keyboard Usage Page (0x07)
// 257 to 286 Is dedicated to Consumer Usage Page (0xC)
// 287 to 511 Is not implemented. Could be used for Mobile or Consoles
// ScanCode reprensent Physical Keys and Buttons
enum class ScanCode : uint16
{ {
// Follow the HID Usage page for USB
// https://usb.org/sites/default/files/hut1_5.pdf
// 0 to 256 Is dedicated to Keyboard Usage Page (0x07)
// 257 to 286 Is dedicated to Consumer Usage Page (0xC)
// 287 to 511 Is not implemented. Could be used for Mobile or Consoles
// ScanCode reprensent Physical Keys and Buttons
enum class ScanCode : uint16
{
Unknown = 0, Unknown = 0,
Unsupported = 0, Unsupported = 0,
@@ -182,5 +180,4 @@ namespace Juliet
Reserved = 287, Reserved = 287,
Count = 512 Count = 512
}; };
} // namespace Juliet
+13 -16
View File
@@ -1,28 +1,25 @@
#pragma once #pragma once
namespace Juliet using MouseID = uint8;
enum class MouseButton : uint8
{ {
using MouseID = uint8;
enum class MouseButton : uint8
{
None = 0, None = 0,
Left = 1 << 0, Left = 1 << 0,
Right = 1 << 1, Right = 1 << 1,
Middle = 1 << 2, Middle = 1 << 2,
Button1 = 1 << 3, Button1 = 1 << 3,
Button2 = 1 << 4, Button2 = 1 << 4,
}; };
// TODO : Replace by Vector2f // TODO : Replace by Vector2f
struct MousePosition struct MousePosition
{ {
float X; float X;
float Y; float Y;
}; };
JULIET_API extern bool IsMouseButtonDown(MouseButton button); JULIET_API extern bool IsMouseButtonDown(MouseButton button);
JULIET_API extern MousePosition GetMousePosition(); JULIET_API extern MousePosition GetMousePosition();
JULIET_API extern MousePosition GetMouseDelta(); JULIET_API extern MousePosition GetMouseDelta();
JULIET_API extern MouseButton GetMouseButtonState(); JULIET_API extern MouseButton GetMouseButtonState();
} // namespace Juliet
+11 -14
View File
@@ -1,12 +1,10 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet namespace Memory
{ {
namespace Memory
{
Byte* OS_Reserve(size_t size); Byte* OS_Reserve(size_t size);
bool OS_Commit(Byte* ptr, size_t size); bool OS_Commit(Byte* ptr, size_t size);
void OS_Release(Byte* ptr, size_t size); void OS_Release(Byte* ptr, size_t size);
@@ -29,21 +27,20 @@ namespace Juliet
OS_Release(reinterpret_cast<Byte*>(ptr), size); OS_Release(reinterpret_cast<Byte*>(ptr), size);
} }
} // namespace Memory } // namespace Memory
namespace Time namespace Time
{ {
uint64 Timestamp(); uint64 Timestamp();
void ComputeDeltaTime(); void ComputeDeltaTime();
float GetDeltaTime(); float GetDeltaTime();
uint64 GetFrameNumber(); uint64 GetFrameNumber();
} // namespace Time } // namespace Time
namespace Debug namespace Debug
{ {
JULIET_API bool IsDebuggerPresent(); JULIET_API bool IsDebuggerPresent();
} // namespace Debug } // namespace Debug
using EntryPointFunc = int (*)(int, wchar_t**); using EntryPointFunc = int (*)(int, wchar_t**);
JULIET_API int Bootstrap(EntryPointFunc entryPointFunc, int argc, wchar_t** argv); JULIET_API int Bootstrap(EntryPointFunc entryPointFunc, int argc, wchar_t** argv);
} // namespace Juliet
+12 -15
View File
@@ -1,14 +1,12 @@
#pragma once #pragma once
#include <Core/Common/String.h> #include <Core/Common/String.h>
namespace Juliet // Fwd Declare
{ struct DynamicLibrary;
// Fwd Declare
struct DynamicLibrary;
struct HotReloadCode struct HotReloadCode
{ {
String DLLFullPath; String DLLFullPath;
String LockFullPath; String LockFullPath;
String TransientDLLName; String TransientDLLName;
@@ -24,15 +22,14 @@ namespace Juliet
uint32 UniqueID; uint32 UniqueID;
bool IsValid : 1; bool IsValid : 1;
}; };
extern JULIET_API void InitHotReloadCode(NonNullPtr<Arena> arena, HotReloadCode& code, String dllName, extern JULIET_API void InitHotReloadCode(NonNullPtr<Arena> arena, HotReloadCode& code, String dllName,
String transientDllName, String lockFilename); String transientDllName, String lockFilename);
extern JULIET_API void ShutdownHotReloadCode(HotReloadCode& code); extern JULIET_API void ShutdownHotReloadCode(HotReloadCode& code);
extern JULIET_API void LoadCode(HotReloadCode& code); extern JULIET_API void LoadCode(HotReloadCode& code);
extern JULIET_API void UnloadCode(HotReloadCode& code); extern JULIET_API void UnloadCode(HotReloadCode& code);
extern JULIET_API void ReloadCode(HotReloadCode& code); extern JULIET_API void ReloadCode(HotReloadCode& code);
extern JULIET_API bool ShouldReloadCode(const HotReloadCode& code); extern JULIET_API bool ShouldReloadCode(const HotReloadCode& code);
} // namespace Juliet
+6 -9
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
@@ -7,13 +7,11 @@
struct ImGuiContext; struct ImGuiContext;
namespace Juliet struct Window;
{ struct GraphicsDevice;
struct Window;
struct GraphicsDevice;
namespace ImGuiService namespace ImGuiService
{ {
JULIET_API void Initialize(NonNullPtr<Window> window); JULIET_API void Initialize(NonNullPtr<Window> window);
JULIET_API void Shutdown(); JULIET_API void Shutdown();
@@ -25,7 +23,6 @@ namespace Juliet
// Run internal unit tests // Run internal unit tests
JULIET_API void RunTests(); JULIET_API void RunTests();
} // namespace ImGuiService } // namespace ImGuiService
} // namespace Juliet
#endif // JULIET_ENABLE_IMGUI #endif // JULIET_ENABLE_IMGUI
+2 -2
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
#include <Core/HAL/Display/Window.h> #include <Core/HAL/Display/Window.h>
@@ -6,7 +6,7 @@
#include <Juliet.h> #include <Juliet.h>
namespace Juliet::UnitTest namespace UnitTest
{ {
void TestImGui(); void TestImGui();
} }
+9 -12
View File
@@ -1,26 +1,23 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
namespace Juliet enum class JulietInit_Flags : uint8
{ {
enum class JulietInit_Flags : uint8
{
None = 0, None = 0,
Display = 1 << 0, Display = 1 << 0,
Audio = 1 << 1, Audio = 1 << 1,
Count = Audio, Count = Audio,
All = 0xFb All = 0xFb
}; };
struct Arena; struct Arena;
struct GameData struct GameData
{ {
struct GameState* GameState; struct GameState* GameState;
Arena* ScratchArena; Arena* ScratchArena;
}; };
void JulietInit(JulietInit_Flags flags); void JulietInit(JulietInit_Flags flags);
void JulietShutdown(); void JulietShutdown();
} // namespace Juliet
+13 -16
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
@@ -9,21 +9,18 @@
// TODO Juliet Containers + Allocators... // TODO Juliet Containers + Allocators...
// TODO: Juliet chrono, because it prevents me from doing #define global static // TODO: Juliet chrono, because it prevents me from doing #define global static
namespace Juliet enum class LogLevel : uint8;
{ enum class LogCategory : uint8;
enum class LogLevel : uint8;
enum class LogCategory : uint8;
extern void JULIET_API InitializeLogManager(); extern void JULIET_API InitializeLogManager();
extern void JULIET_API ShutdownLogManager(); extern void JULIET_API ShutdownLogManager();
extern void JULIET_API LogScopeBegin(); extern void JULIET_API LogScopeBegin();
// TODO everything that happened in there to export them to file or something // TODO everything that happened in there to export them to file or something
extern void JULIET_API LogScopeEnd(); extern void JULIET_API LogScopeEnd();
extern void JULIET_API Log(LogLevel level, LogCategory category, const char* fmt, ...); extern void JULIET_API Log(LogLevel level, LogCategory category, const char* fmt, ...);
extern void JULIET_API LogDebug(LogCategory category, const char* fmt, ...); extern void JULIET_API LogDebug(LogCategory category, const char* fmt, ...);
extern void JULIET_API LogMessage(LogCategory category, const char* fmt, ...); extern void JULIET_API LogMessage(LogCategory category, const char* fmt, ...);
extern void JULIET_API LogWarning(LogCategory category, const char* fmt, ...); extern void JULIET_API LogWarning(LogCategory category, const char* fmt, ...);
extern void JULIET_API LogError(LogCategory category, const char* fmt, ...); extern void JULIET_API LogError(LogCategory category, const char* fmt, ...);
} // namespace Juliet
+6 -9
View File
@@ -1,22 +1,19 @@
#pragma once #pragma once
namespace Juliet enum class LogLevel : uint8
{ {
enum class LogLevel : uint8
{
Debug = 0, Debug = 0,
Message = 1, Message = 1,
Warning = 2, Warning = 2,
Error = 3, Error = 3,
}; };
enum class LogCategory : uint8 enum class LogCategory : uint8
{ {
Core = 0, Core = 0,
Graphics = 1, Graphics = 1,
Networking = 2, Networking = 2,
Engine = 3, Engine = 3,
Tool = 4, Tool = 4,
Game = 5, Game = 5,
}; };
} // namespace Juliet
+4 -4
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/HAL/OS/OS.h> #include <Core/HAL/OS/OS.h>
@@ -12,12 +12,12 @@ extern int JulietMain(int, wchar_t**);
#if UNICODE #if UNICODE
int wmain(int argc, wchar_t** argv) int wmain(int argc, wchar_t** argv)
{ {
return Juliet::Bootstrap(JulietMain, argc, argv); return Bootstrap(JulietMain, argc, argv);
} }
#else #else
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
return Juliet::Bootstrap(JulietMain, argc, argv); return Bootstrap(JulietMain, argc, argv);
} }
#endif #endif
@@ -38,7 +38,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
(void)szCmdLine; (void)szCmdLine;
(void)sw; (void)sw;
return Juliet::Bootstrap(JulietMain, __argc, __wargv); return Bootstrap(JulietMain, __argc, __wargv);
} }
} }
#else #else
+25 -28
View File
@@ -1,44 +1,42 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet extern JULIET_API float RoundF(float value);
inline int32 LRoundF(float value)
{ {
extern JULIET_API float RoundF(float value);
inline int32 LRoundF(float value)
{
return static_cast<int32>(RoundF(value)); return static_cast<int32>(RoundF(value));
} }
template <typename Type> template <typename Type>
constexpr Type Min(Type lhs, Type rhs) constexpr Type Min(Type lhs, Type rhs)
{ {
return rhs < lhs ? rhs : lhs; return rhs < lhs ? rhs : lhs;
} }
template <typename Type> template <typename Type>
constexpr Type Max(Type lhs, Type rhs) constexpr Type Max(Type lhs, Type rhs)
{ {
return lhs < rhs ? rhs : lhs; return lhs < rhs ? rhs : lhs;
} }
template <typename Type> template <typename Type>
constexpr Type ClampTop(Type value, Type X) constexpr Type ClampTop(Type value, Type X)
{ {
return Min(value, X); return Min(value, X);
} }
template <typename Type> template <typename Type>
constexpr Type ClampBottom(Type value, Type X) constexpr Type ClampBottom(Type value, Type X)
{ {
return Max(value, X); return Max(value, X);
} }
template <typename Type> template <typename Type>
constexpr Type Clamp(Type val, Type min, Type max) constexpr Type Clamp(Type val, Type min, Type max)
{ {
if (val < min) if (val < min)
{ {
return min; return min;
@@ -48,5 +46,4 @@ namespace Juliet
return max; return max;
} }
return val; return val;
} }
} // namespace Juliet
+39 -42
View File
@@ -1,27 +1,25 @@
#pragma once #pragma once
#include <Core/Math/Vector.h> #include <Core/Math/Vector.h>
#include <math.h> #include <math.h>
namespace Juliet struct Matrix
{ {
struct Matrix
{
float m[4][4]; float m[4][4];
}; };
[[nodiscard]] inline Matrix MatrixIdentity() [[nodiscard]] inline Matrix MatrixIdentity()
{ {
Matrix result = {}; Matrix result = {};
result.m[0][0] = 1.0f; result.m[0][0] = 1.0f;
result.m[1][1] = 1.0f; result.m[1][1] = 1.0f;
result.m[2][2] = 1.0f; result.m[2][2] = 1.0f;
result.m[3][3] = 1.0f; result.m[3][3] = 1.0f;
return result; return result;
} }
[[nodiscard]] inline Matrix operator*(const Matrix& lhs, const Matrix& rhs) [[nodiscard]] inline Matrix operator*(const Matrix& lhs, const Matrix& rhs)
{ {
Matrix result = {}; Matrix result = {};
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
{ {
@@ -34,28 +32,28 @@ namespace Juliet
} }
} }
return result; return result;
} }
[[nodiscard]] inline Matrix MatrixTranslation(float x, float y, float z) [[nodiscard]] inline Matrix MatrixTranslation(float x, float y, float z)
{ {
Matrix result = MatrixIdentity(); Matrix result = MatrixIdentity();
result.m[0][3] = x; result.m[0][3] = x;
result.m[1][3] = y; result.m[1][3] = y;
result.m[2][3] = z; result.m[2][3] = z;
return result; return result;
} }
[[nodiscard]] inline Matrix MatrixScale(float x, float y, float z) [[nodiscard]] inline Matrix MatrixScale(float x, float y, float z)
{ {
Matrix result = MatrixIdentity(); Matrix result = MatrixIdentity();
result.m[0][0] = x; result.m[0][0] = x;
result.m[1][1] = y; result.m[1][1] = y;
result.m[2][2] = z; result.m[2][2] = z;
return result; return result;
} }
[[nodiscard]] inline Matrix MatrixRotationX(float radians) [[nodiscard]] inline Matrix MatrixRotationX(float radians)
{ {
float c = cosf(radians); float c = cosf(radians);
float s = sinf(radians); float s = sinf(radians);
Matrix result = MatrixIdentity(); Matrix result = MatrixIdentity();
@@ -64,10 +62,10 @@ namespace Juliet
result.m[2][1] = s; result.m[2][1] = s;
result.m[2][2] = c; result.m[2][2] = c;
return result; return result;
} }
[[nodiscard]] inline Matrix MatrixRotationY(float radians) [[nodiscard]] inline Matrix MatrixRotationY(float radians)
{ {
float c = cosf(radians); float c = cosf(radians);
float s = sinf(radians); float s = sinf(radians);
Matrix result = MatrixIdentity(); Matrix result = MatrixIdentity();
@@ -76,10 +74,10 @@ namespace Juliet
result.m[2][0] = -s; result.m[2][0] = -s;
result.m[2][2] = c; result.m[2][2] = c;
return result; return result;
} }
[[nodiscard]] inline Matrix MatrixRotationZ(float radians) [[nodiscard]] inline Matrix MatrixRotationZ(float radians)
{ {
float c = cosf(radians); float c = cosf(radians);
float s = sinf(radians); float s = sinf(radians);
Matrix result = MatrixIdentity(); Matrix result = MatrixIdentity();
@@ -88,22 +86,22 @@ namespace Juliet
result.m[1][0] = s; result.m[1][0] = s;
result.m[1][1] = c; result.m[1][1] = c;
return result; return result;
} }
inline void MatrixTranslate(Matrix& m, const Vector3& v) inline void MatrixTranslate(Matrix& m, const Vector3& v)
{ {
m.m[0][3] += v.x; m.m[0][3] += v.x;
m.m[1][3] += v.y; m.m[1][3] += v.y;
m.m[2][3] += v.z; m.m[2][3] += v.z;
} }
[[nodiscard]] inline Matrix MatrixRotation(float x, float y, float z) [[nodiscard]] inline Matrix MatrixRotation(float x, float y, float z)
{ {
return MatrixRotationX(x) * MatrixRotationY(y) * MatrixRotationZ(z); return MatrixRotationX(x) * MatrixRotationY(y) * MatrixRotationZ(z);
} }
inline Matrix LookAt(const Vector3& eye, const Vector3& target, const Vector3& up) inline Matrix LookAt(const Vector3& eye, const Vector3& target, const Vector3& up)
{ {
// Left-Handed convention // Left-Handed convention
Vector3 zaxis = Normalize(target - eye); // Forward is +z Vector3 zaxis = Normalize(target - eye); // Forward is +z
Vector3 xaxis = Normalize(Cross(up, zaxis)); Vector3 xaxis = Normalize(Cross(up, zaxis));
@@ -132,10 +130,10 @@ namespace Juliet
result.m[3][3] = 1.0f; result.m[3][3] = 1.0f;
return result; return result;
} }
inline Matrix PerspectiveFov(float fovY, float aspectRatio, float nearZ, float farZ) inline Matrix PerspectiveFov(float fovY, float aspectRatio, float nearZ, float farZ)
{ {
// Left-Handed Perspective // Left-Handed Perspective
float yScale = 1.0f / tanf(fovY * 0.5f); float yScale = 1.0f / tanf(fovY * 0.5f);
float xScale = yScale / aspectRatio; float xScale = yScale / aspectRatio;
@@ -148,10 +146,10 @@ namespace Juliet
result.m[3][2] = 1.0f; result.m[3][2] = 1.0f;
result.m[3][3] = 0.0f; result.m[3][3] = 0.0f;
return result; return result;
} }
[[nodiscard]] inline Matrix MatrixInverse(const Matrix& m) [[nodiscard]] inline Matrix MatrixInverse(const Matrix& m)
{ {
Matrix out = {}; Matrix out = {};
float m00 = m.m[0][0], m01 = m.m[0][1], m02 = m.m[0][2], m03 = m.m[0][3]; float m00 = m.m[0][0], m01 = m.m[0][1], m02 = m.m[0][2], m03 = m.m[0][3];
@@ -190,5 +188,4 @@ namespace Juliet
} }
return out; return out;
} }
} // namespace Juliet
+3 -6
View File
@@ -1,12 +1,9 @@
#pragma once #pragma once
namespace Juliet struct Rectangle
{ {
struct Rectangle
{
int32 X; int32 X;
int32 Y; int32 Y;
int32 Width; int32 Width;
int32 Height; int32 Height;
}; };
} // namespace Juliet
+13 -16
View File
@@ -1,39 +1,36 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Juliet.h> #include <Juliet.h>
#include <math.h> #include <math.h>
namespace Juliet struct Vector3
{ {
struct Vector3
{
float x, y, z; float x, y, z;
Vector3 operator+(const Vector3& rhs) const { return { x + rhs.x, y + rhs.y, z + rhs.z }; } Vector3 operator+(const Vector3& rhs) const { return { x + rhs.x, y + rhs.y, z + rhs.z }; }
Vector3 operator-(const Vector3& rhs) const { return { x - rhs.x, y - rhs.y, z - rhs.z }; } Vector3 operator-(const Vector3& rhs) const { return { x - rhs.x, y - rhs.y, z - rhs.z }; }
Vector3 operator*(float s) const { return { x * s, y * s, z * s }; } Vector3 operator*(float s) const { return { x * s, y * s, z * s }; }
}; };
struct Vector4 struct Vector4
{ {
float x, y, z, w; float x, y, z, w;
}; };
inline Vector3 Normalize(const Vector3& v) inline Vector3 Normalize(const Vector3& v)
{ {
float len = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); float len = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
if (len > 0.0001f) if (len > 0.0001f)
{ {
return { v.x / len, v.y / len, v.z / len }; return { v.x / len, v.y / len, v.z / len };
} }
return v; return v;
} }
inline Vector3 Cross(const Vector3& a, const Vector3& b) inline Vector3 Cross(const Vector3& a, const Vector3& b)
{ {
return { a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x }; return { a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x };
} }
inline float Dot(const Vector3& a, const Vector3& b) { return a.x * b.x + a.y * b.y + a.z * b.z; } inline float Dot(const Vector3& a, const Vector3& b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
} // namespace Juliet
+16 -19
View File
@@ -1,31 +1,28 @@
#pragma once #pragma once
#include <Juliet.h> #include <Juliet.h>
#include <Core/Common/CoreUtils.h> #include <Core/Common/CoreUtils.h>
namespace Juliet // Uninitialized allocation
{ JULIET_API void* Malloc(size_t elem_size);
// Uninitialized allocation // Initialized to 0 allocation
JULIET_API void* Malloc(size_t elem_size); JULIET_API void* Calloc(size_t nb_elem, size_t elem_size);
// Initialized to 0 allocation JULIET_API void* Realloc(void* memory, size_t newSize);
JULIET_API void* Calloc(size_t nb_elem, size_t elem_size);
JULIET_API void* Realloc(void* memory, size_t newSize);
// Free // Free
template <typename Type> template <typename Type>
void Free(Type* memory) void Free(Type* memory)
{ {
Assert(memory); Assert(memory);
::free(memory); ::free(memory);
} }
// Free and Set the ptr to nullptr // Free and Set the ptr to nullptr
template <typename Type> template <typename Type>
void SafeFree(Type*& memory) void SafeFree(Type*& memory)
{ {
if (memory) if (memory)
{ {
::free(memory); ::free(memory);
memory = nullptr; memory = nullptr;
} }
} }
} // namespace Juliet
+38 -41
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Common/CoreUtils.h> #include <Core/Common/CoreUtils.h>
@@ -10,19 +10,17 @@
#include <Core/Memory/MemoryArenaDebug.h> #include <Core/Memory/MemoryArenaDebug.h>
#endif #endif
namespace Juliet constexpr global uint64 g_Arena_Default_Reserve_Size = Megabytes(64);
{ constexpr global uint64 g_Arena_Default_Commit_Size = Kilobytes(64);
constexpr global uint64 g_Arena_Default_Reserve_Size = Megabytes(64); constexpr global uint64 k_ArenaHeaderSize = 128;
constexpr global uint64 g_Arena_Default_Commit_Size = Kilobytes(64);
constexpr global uint64 k_ArenaHeaderSize = 128;
#if JULIET_DEBUG #if JULIET_DEBUG
struct ArenaDebugInfo; struct ArenaDebugInfo;
JULIET_API String FormatDebugTagV(const char* formatStr, std::format_args args); JULIET_API String FormatDebugTagV(const char* formatStr, std::format_args args);
#endif #endif
struct Arena struct Arena
{ {
Arena* Previous; Arena* Previous;
Arena* Current; Arena* Current;
@@ -45,17 +43,17 @@ namespace Juliet
JULIET_DEBUG_ONLY(Arena* GlobalPrev;) JULIET_DEBUG_ONLY(Arena* GlobalPrev;)
JULIET_DEBUG_ONLY(ArenaDebugInfo* FirstDebugInfo;) JULIET_DEBUG_ONLY(ArenaDebugInfo* FirstDebugInfo;)
const char* Name; const char* Name;
}; };
static_assert(sizeof(Arena) <= k_ArenaHeaderSize); static_assert(sizeof(Arena) <= k_ArenaHeaderSize);
struct TempArena struct TempArena
{ {
Arena* Arena; Arena* Arena;
index_t Position; index_t Position;
}; };
struct ArenaParams struct ArenaParams
{ {
uint64 ReserveSize = g_Arena_Default_Reserve_Size; uint64 ReserveSize = g_Arena_Default_Reserve_Size;
uint64 CommitSize = g_Arena_Default_Commit_Size; uint64 CommitSize = g_Arena_Default_Commit_Size;
@@ -63,27 +61,27 @@ namespace Juliet
// When false, will assert if a new block is reserved. // When false, will assert if a new block is reserved.
JULIET_DEBUG_ONLY(bool CanReserveMore : 1 = true;) JULIET_DEBUG_ONLY(bool CanReserveMore : 1 = true;)
}; };
[[nodiscard]] JULIET_API Arena* ArenaAllocate(const ArenaParams& params, [[nodiscard]] JULIET_API Arena* ArenaAllocate(const ArenaParams& params,
const std::source_location& loc = std::source_location::current()); const std::source_location& loc = std::source_location::current());
JULIET_API void ArenaRelease(NonNullPtr<Arena> arena); JULIET_API void ArenaRelease(NonNullPtr<Arena> arena);
// Raw Push, can be used but templated helpers exists below // Raw Push, can be used but templated helpers exists below
[[nodiscard]] JULIET_API void* ArenaPush(NonNullPtr<Arena> arena, size_t size, size_t align, [[nodiscard]] JULIET_API void* ArenaPush(NonNullPtr<Arena> arena, size_t size, size_t align,
bool shouldBeZeroed JULIET_DEBUG_PARAM(const char* tag)); bool shouldBeZeroed JULIET_DEBUG_PARAM(const char* tag));
JULIET_API void ArenaPopTo(NonNullPtr<Arena> arena, size_t position); JULIET_API void ArenaPopTo(NonNullPtr<Arena> arena, size_t position);
JULIET_API void ArenaPop(NonNullPtr<Arena> arena, size_t amount); JULIET_API void ArenaPop(NonNullPtr<Arena> arena, size_t amount);
JULIET_API void ArenaClear(NonNullPtr<Arena> arena); JULIET_API void ArenaClear(NonNullPtr<Arena> arena);
[[nodiscard]] JULIET_API size_t ArenaPos(NonNullPtr<Arena> arena); [[nodiscard]] JULIET_API size_t ArenaPos(NonNullPtr<Arena> arena);
#if JULIET_DEBUG #if JULIET_DEBUG
template <typename FirstDebugArg, typename... DebugArgs> template <typename FirstDebugArg, typename... DebugArgs>
#endif #endif
[[nodiscard]] inline void* ArenaPushSize(NonNullPtr<Arena> arena, size_t size, size_t align, [[nodiscard]] inline void* ArenaPushSize(NonNullPtr<Arena> arena, size_t size, size_t align,
bool shouldBeZeroed JULIET_DEBUG_PARAM(FirstDebugArg&& firstDebugArg, bool shouldBeZeroed JULIET_DEBUG_PARAM(FirstDebugArg&& firstDebugArg,
DebugArgs&&... debugArgs)) DebugArgs&&... debugArgs))
{ {
return ArenaPush(arena, size, align, return ArenaPush(arena, size, align,
shouldBeZeroed JULIET_DEBUG_PARAM( shouldBeZeroed JULIET_DEBUG_PARAM(
[&]() -> const char* [&]() -> const char*
@@ -92,11 +90,11 @@ namespace Juliet
std::forward<DebugArgs>(debugArgs)...) std::forward<DebugArgs>(debugArgs)...)
.Str; .Str;
}())); }()));
} }
template <typename Type JULIET_DEBUG_ONLY(, typename... DebugArgs)> template <typename Type JULIET_DEBUG_ONLY(, typename... DebugArgs)>
[[nodiscard]] Type* ArenaPushStruct(NonNullPtr<Arena> arena JULIET_DEBUG_PARAM(DebugArgs&&... debugArgs)) [[nodiscard]] Type* ArenaPushStruct(NonNullPtr<Arena> arena JULIET_DEBUG_PARAM(DebugArgs&&... debugArgs))
{ {
return static_cast<Type*>( return static_cast<Type*>(
ArenaPush(arena, sizeof(Type) * 1, AlignOf(Type), ArenaPush(arena, sizeof(Type) * 1, AlignOf(Type),
true JULIET_DEBUG_PARAM( true JULIET_DEBUG_PARAM(
@@ -108,11 +106,11 @@ namespace Juliet
} }
return GetTypeName<Type>(); return GetTypeName<Type>();
}()))); }())));
} }
template <typename Type, bool shouldZero = true JULIET_DEBUG_ONLY(, typename... DebugArgs)> template <typename Type, bool shouldZero = true JULIET_DEBUG_ONLY(, typename... DebugArgs)>
[[nodiscard]] Type* ArenaPushArray(NonNullPtr<Arena> arena, size_t count JULIET_DEBUG_PARAM(DebugArgs&&... debugArgs)) [[nodiscard]] Type* ArenaPushArray(NonNullPtr<Arena> arena, size_t count JULIET_DEBUG_PARAM(DebugArgs&&... debugArgs))
{ {
return static_cast<Type*>( return static_cast<Type*>(
ArenaPush(arena, sizeof(Type) * count, Max(8ull, AlignOf(Type)), ArenaPush(arena, sizeof(Type) * count, Max(8ull, AlignOf(Type)),
shouldZero JULIET_DEBUG_PARAM( shouldZero JULIET_DEBUG_PARAM(
@@ -124,8 +122,7 @@ namespace Juliet
} }
return GetTypeName<Type>(); return GetTypeName<Type>();
}()))); }())));
} }
TempArena ArenaTempBegin(NonNullPtr<Arena> arena); TempArena ArenaTempBegin(NonNullPtr<Arena> arena);
void ArenaTempEnd(TempArena temp); void ArenaTempEnd(TempArena temp);
} // namespace Juliet
+25 -28
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
@@ -7,46 +7,43 @@
#if JULIET_DEBUG #if JULIET_DEBUG
namespace Juliet struct Arena;
{ struct MemoryBlock;
struct Arena;
struct MemoryBlock;
// Arena (Struct) // Arena (Struct)
struct ArenaDebugInfo struct ArenaDebugInfo
{ {
const char* Tag; const char* Tag;
size_t Offset; size_t Offset;
size_t Size; size_t Size;
ArenaDebugInfo* Next; ArenaDebugInfo* Next;
}; };
// MemoryArena (Pool-based) // MemoryArena (Pool-based)
struct ArenaAllocation struct ArenaAllocation
{ {
size_t Offset; size_t Offset;
size_t Size; size_t Size;
String Tag; String Tag;
ArenaAllocation* Next; ArenaAllocation* Next;
}; };
// Arena (Struct) // Arena (Struct)
void DebugRegisterArena(NonNullPtr<Arena> arena); void DebugRegisterArena(NonNullPtr<Arena> arena);
void DebugUnregisterArena(NonNullPtr<Arena> arena); void DebugUnregisterArena(NonNullPtr<Arena> arena);
void DebugArenaSetDebugName(NonNullPtr<Arena> arena, const char* name); void DebugArenaSetDebugName(NonNullPtr<Arena> arena, const char* name);
bool IsDebugInfoArena(const Arena* arena); // To prevent recursion bool IsDebugInfoArena(const Arena* arena); // To prevent recursion
void DebugArenaFreeBlock(Arena* block); // To clear all debug infos in a block void DebugArenaFreeBlock(Arena* block); // To clear all debug infos in a block
void DebugArenaRemoveAllocation(Arena* block, size_t oldOffset); void DebugArenaRemoveAllocation(Arena* block, size_t oldOffset);
void DebugArenaPopTo(Arena* block, size_t newPosition); void DebugArenaPopTo(Arena* block, size_t newPosition);
void DebugArenaAddDebugInfo(Arena* block, size_t size, size_t offset, const char* tag); void DebugArenaAddDebugInfo(Arena* block, size_t size, size_t offset, const char* tag);
// MemoryArena (Pool-based) // MemoryArena (Pool-based)
void DebugFreeArenaAllocations(MemoryBlock* blk); void DebugFreeArenaAllocations(MemoryBlock* blk);
void DebugArenaAddAllocation(MemoryBlock* blk, size_t size, size_t offset, String tag); void DebugArenaAddAllocation(MemoryBlock* blk, size_t size, size_t offset, String tag);
void DebugArenaRemoveLastAllocation(MemoryBlock* blk); void DebugArenaRemoveLastAllocation(MemoryBlock* blk);
JULIET_API Arena* GetDebugInfoArena(); JULIET_API Arena* GetDebugInfoArena();
} // namespace Juliet
#endif #endif
+25 -28
View File
@@ -1,13 +1,11 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#define ArraySize(array) (sizeof(array) / sizeof(array[0])) #define ArraySize(array) (sizeof(array) / sizeof(array[0]))
namespace Juliet inline int32 MemCompare(const void* leftValue, const void* rightValue, size_t size)
{ {
inline int32 MemCompare(const void* leftValue, const void* rightValue, size_t size)
{
auto left = static_cast<const unsigned char*>(leftValue); auto left = static_cast<const unsigned char*>(leftValue);
auto right = static_cast<const unsigned char*>(rightValue); auto right = static_cast<const unsigned char*>(rightValue);
while (size && *left == *right) while (size && *left == *right)
@@ -17,30 +15,30 @@ namespace Juliet
--size; --size;
} }
return size ? *left - *right : 0; return size ? *left - *right : 0;
} }
// Single linked list // Single linked list
void SingleLinkedListPushNext(auto*& stackTop, auto* node) void SingleLinkedListPushNext(auto*& stackTop, auto* node)
{ {
node->Next = stackTop; node->Next = stackTop;
stackTop = node; stackTop = node;
} }
void SingleLinkedListPushPrevious(auto*& stackTop, auto* node) void SingleLinkedListPushPrevious(auto*& stackTop, auto* node)
{ {
node->Previous = stackTop; node->Previous = stackTop;
stackTop = node; stackTop = node;
} }
void SingleLinkedListPopNext(auto*& stackTop) void SingleLinkedListPopNext(auto*& stackTop)
{ {
stackTop = stackTop->Next; stackTop = stackTop->Next;
} }
// Double linked list // Double linked list
template <typename QueueType, typename QueueTypeNode> template <typename QueueType, typename QueueTypeNode>
void Enqueue(QueueType& queue, QueueTypeNode* node) void Enqueue(QueueType& queue, QueueTypeNode* node)
{ {
if (queue.First == nullptr) if (queue.First == nullptr)
{ {
queue.First = queue.Last = node; queue.First = queue.Last = node;
@@ -53,26 +51,25 @@ namespace Juliet
} }
queue.Nodecount += 1; queue.Nodecount += 1;
} }
template <typename QueueType> template <typename QueueType>
struct QueueNode struct QueueNode
{ {
QueueType* Next; QueueType* Next;
}; };
#define DECLARE_QUEUE(type) \ #define DECLARE_QUEUE(type) \
struct type##Queue \ struct type##Queue \
{ \ { \
type* First; \ type* First; \
type* Last; \ type* Last; \
size_t Nodecount; \ size_t Nodecount; \
size_t Size; \ size_t Size; \
}; };
// TODO: homemade versions // TODO: homemade versions
#define MemSet memset #define MemSet memset
#define MemCopy memcpy #define MemCopy memcpy
#define MemoryZero(dst, size) MemSet(dst, 0, size) #define MemoryZero(dst, size) MemSet(dst, 0, size)
} // namespace Juliet
+5 -8
View File
@@ -1,11 +1,8 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
namespace Juliet // TODO : Do something better.
{ constexpr uint32 kLocalhost = (127 << 3) | (0 << 2) | (0 << 1) | 1;
// TODO : Do something better. constexpr uint32 kAnyIp = 0;
constexpr uint32 kLocalhost = (127 << 3) | (0 << 2) | (0 << 1) | 1; constexpr uint32 kBroadcastIp = (255 << 3) | (255 << 2) | (255 << 1) | 255;
constexpr uint32 kAnyIp = 0;
constexpr uint32 kBroadcastIp = (255 << 3) | (255 << 2) | (255 << 1) | 255;
} // namespace Juliet
@@ -1,12 +1,10 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Container/Vector.h> #include <Core/Container/Vector.h>
namespace Juliet class NetworkPacket
{ {
class NetworkPacket
{
public: public:
NetworkPacket(); NetworkPacket();
NetworkPacket(Arena& arena); NetworkPacket(Arena& arena);
@@ -32,5 +30,4 @@ namespace Juliet
private: private:
VectorArena<Byte, 4096> Data; VectorArena<Byte, 4096> Data;
size_t PartialSendIndex = 0; size_t PartialSendIndex = 0;
}; };
} // namespace Juliet
+3 -6
View File
@@ -1,11 +1,9 @@
#pragma once #pragma once
#include <Core/Networking/SocketHandle.h> #include <Core/Networking/SocketHandle.h>
namespace Juliet class Socket
{ {
class Socket
{
public: public:
virtual ~Socket(); virtual ~Socket();
@@ -52,5 +50,4 @@ namespace Juliet
private: private:
SocketHandle Handle; SocketHandle Handle;
Protocol ProtocolType; Protocol ProtocolType;
}; };
} // namespace Juliet
@@ -1,14 +1,11 @@
#pragma once #pragma once
#if JULIET_WIN32 #if JULIET_WIN32
#include <basetsd.h> #include <basetsd.h>
#endif #endif
namespace Juliet
{
#if JULIET_WIN32 #if JULIET_WIN32
using SocketHandle = UINT_PTR; using SocketHandle = UINT_PTR;
#else #else
using SocketHandle = int; using SocketHandle = int;
#endif #endif
} // namespace Juliet
+3 -6
View File
@@ -1,13 +1,11 @@
#pragma once #pragma once
#include <Core/Networking/IPAddress.h> #include <Core/Networking/IPAddress.h>
#include <Core/Networking/Socket.h> #include <Core/Networking/Socket.h>
#include <Core/Networking/TcpSocket.h> #include <Core/Networking/TcpSocket.h>
namespace Juliet class TcpListener : public Socket
{ {
class TcpListener : public Socket
{
public: public:
TcpListener(); TcpListener();
@@ -17,5 +15,4 @@ namespace Juliet
Status Listen(uint16 port, uint32 address = kAnyIp); Status Listen(uint16 port, uint32 address = kAnyIp);
Status Accept(TcpSocket& socket); Status Accept(TcpSocket& socket);
void Close(); void Close();
}; };
} // namespace Juliet
+5 -8
View File
@@ -1,13 +1,11 @@
#pragma once #pragma once
#include <Core/Networking/Socket.h> #include <Core/Networking/Socket.h>
namespace Juliet class NetworkPacket;
{
class NetworkPacket;
class TcpSocket : public Socket class TcpSocket : public Socket
{ {
public: public:
TcpSocket(); TcpSocket();
@@ -20,5 +18,4 @@ namespace Juliet
private: private:
friend class TcpListener; friend class TcpListener;
}; };
} // namespace Juliet
+1 -1
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <algorithm> #include <algorithm>
#include <bit> #include <bit>
+3 -6
View File
@@ -1,7 +1,4 @@
#pragma once #pragma once
namespace Juliet using Mutex = std::mutex;
{ using LockGuard = std::lock_guard<Mutex>;
using Mutex = std::mutex;
using LockGuard = std::lock_guard<Mutex>;
} // namespace Juliet
+8 -11
View File
@@ -1,19 +1,16 @@
#pragma once #pragma once
#include <Core/Common/String.h> #include <Core/Common/String.h>
namespace Juliet uint32 thread_id();
void set_thread_name(String name);
// TODO : Proper wait
inline void wait_ms(int milliseconds)
{ {
uint32 thread_id();
void set_thread_name(String name);
// TODO : Proper wait
inline void wait_ms(int milliseconds)
{
clock_t start_time = clock(); clock_t start_time = clock();
while (clock() < start_time + milliseconds) while (clock() < start_time + milliseconds)
{ {
} }
} }
} // namespace Juliet
+10 -13
View File
@@ -1,24 +1,21 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Memory/MemoryArena.h> #include <Core/Memory/MemoryArena.h>
namespace Juliet struct thread_context
{ {
struct thread_context
{
Arena* ScratchArenas[2]; Arena* ScratchArenas[2];
char ThreadName[64]; char ThreadName[64];
uint8 ThreadNameSize; uint8 ThreadNameSize;
}; };
thread_context* thread_context_alloc(); thread_context* thread_context_alloc();
void thread_context_release(NonNullPtr<thread_context> ctx); void thread_context_release(NonNullPtr<thread_context> ctx);
void thread_context_select(NonNullPtr<thread_context> ctx); void thread_context_select(NonNullPtr<thread_context> ctx);
thread_context* thread_context_current(); thread_context* thread_context_current();
Arena* thread_context_get_scratch(Arena** conflicts, size_t count); Arena* thread_context_get_scratch(Arena** conflicts, size_t count);
TempArena scratch_begin(Arena** conflicts, size_t count); TempArena scratch_begin(Arena** conflicts, size_t count);
void scratch_end(TempArena scratch); void scratch_end(TempArena scratch);
} // namespace Juliet
+2 -5
View File
@@ -1,9 +1,6 @@
#pragma once #pragma once
#include <Core/Common/String.h> #include <Core/Common/String.h>
#include <Graphics/MeshRenderer.h> #include <Graphics/MeshRenderer.h>
namespace Juliet JULIET_API extern MeshAssetID LoadMesh(String filename);
{
JULIET_API extern MeshAssetID LoadMesh(String filename);
}
+7 -10
View File
@@ -1,12 +1,10 @@
#pragma once #pragma once
#include <Core/Common/CRC32.h> #include <Core/Common/CRC32.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet struct Class
{ {
struct Class
{
uint32 CRC; uint32 CRC;
#if JULIET_DEBUG #if JULIET_DEBUG
// TODO: string struct may be // TODO: string struct may be
@@ -23,11 +21,10 @@ namespace Juliet
Name_Length = name_length; Name_Length = name_length;
#endif #endif
} }
}; };
template <typename type> template <typename type>
bool IsA(Class& cls) bool IsA(Class& cls)
{ {
return cls.CRC == type::StaticClass->CRC; return cls.CRC == type::StaticClass->CRC;
} }
} // namespace Juliet
+3 -3
View File
@@ -1,12 +1,12 @@
#pragma once #pragma once
#include <Juliet.h> #include <Juliet.h>
#if JULIET_DEBUG #if JULIET_DEBUG
namespace Juliet::Debug namespace Debug
{ {
JULIET_API void DebugDrawMemoryArena(); JULIET_API void DebugDrawMemoryArena();
} // namespace Juliet::Debug } // namespace Debug
#endif #endif
+11 -14
View File
@@ -1,25 +1,22 @@
#pragma once #pragma once
#include <Core/Application/IApplication.h> #include <Core/Application/IApplication.h>
namespace Juliet enum class JulietInit_Flags : uint8;
{
enum class JulietInit_Flags : uint8;
struct Engine struct Engine
{ {
IApplication* Application = nullptr; IApplication* Application = nullptr;
Arena* PlatformArena = nullptr; Arena* PlatformArena = nullptr;
Arena* AssetArena = nullptr; Arena* AssetArena = nullptr;
}; };
void InitializeEngine(JulietInit_Flags flags); void InitializeEngine(JulietInit_Flags flags);
void ShutdownEngine(); void ShutdownEngine();
void LoadApplication(IApplication& app); void LoadApplication(IApplication& app);
void UnloadApplication(); void UnloadApplication();
void RunEngine(); void RunEngine();
extern Arena* GetPlatformArena(); extern Arena* GetPlatformArena();
} // namespace Juliet
+15 -18
View File
@@ -1,12 +1,10 @@
#pragma once #pragma once
#include <Core/Math/Matrix.h> #include <Core/Math/Matrix.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet struct Camera
{ {
struct Camera
{
index_t Index; index_t Index;
Vector3 Position; Vector3 Position;
Vector3 Target; Vector3 Target;
@@ -15,24 +13,23 @@ namespace Juliet
float AspectRatio; float AspectRatio;
float NearPlane; float NearPlane;
float FarPlane; float FarPlane;
}; };
inline Matrix Camera_GetViewMatrix(const Camera& cam) inline Matrix Camera_GetViewMatrix(const Camera& cam)
{ {
return LookAt(cam.Position, cam.Target, cam.Up); return LookAt(cam.Position, cam.Target, cam.Up);
} }
inline Matrix Camera_GetProjectionMatrix(const Camera& cam) inline Matrix Camera_GetProjectionMatrix(const Camera& cam)
{ {
return PerspectiveFov(cam.FOV, cam.AspectRatio, cam.NearPlane, cam.FarPlane); return PerspectiveFov(cam.FOV, cam.AspectRatio, cam.NearPlane, cam.FarPlane);
} }
inline Matrix Camera_GetViewProjectionMatrix(const Camera& cam) inline Matrix Camera_GetViewProjectionMatrix(const Camera& cam)
{ {
return Camera_GetProjectionMatrix(cam) * Camera_GetViewMatrix(cam); return Camera_GetProjectionMatrix(cam) * Camera_GetViewMatrix(cam);
} }
JULIET_API extern void ReserveCamera(size_t amount); JULIET_API extern void ReserveCamera(size_t amount);
JULIET_API extern Camera* GetCurrentCamera(); JULIET_API extern Camera* GetCurrentCamera();
JULIET_API extern void SetCurrentCamera(index_t index); JULIET_API extern void SetCurrentCamera(index_t index);
} // namespace Juliet
+6 -9
View File
@@ -1,16 +1,13 @@
#pragma once #pragma once
namespace Juliet template <typename Type>
struct ColorType
{ {
template <typename Type>
struct ColorType
{
Type R; Type R;
Type G; Type G;
Type B; Type B;
Type A; Type A;
}; };
using FColor = ColorType<float>; using FColor = ColorType<float>;
using Color = ColorType<uint8>; using Color = ColorType<uint8>;
} // namespace Juliet
+7 -10
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Math/Vector.h> #include <Core/Math/Vector.h>
#include <Graphics/Camera.h> #include <Graphics/Camera.h>
@@ -6,12 +6,9 @@
#include <Graphics/Graphics.h> #include <Graphics/Graphics.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet extern JULIET_API void DebugDisplay_Initialize(NonNullPtr<Arena> arena, GraphicsDevice* device);
{ extern JULIET_API void DebugDisplay_Shutdown(GraphicsDevice* device);
extern JULIET_API void DebugDisplay_Initialize(NonNullPtr<Arena> arena, GraphicsDevice* device); extern JULIET_API void DebugDisplay_DrawLine(const Vector3& start, const Vector3& end, const FColor& color, bool overlay);
extern JULIET_API void DebugDisplay_Shutdown(GraphicsDevice* device); extern JULIET_API void DebugDisplay_DrawSphere(const Vector3& center, float radius, const FColor& color, bool overlay);
extern JULIET_API void DebugDisplay_DrawLine(const Vector3& start, const Vector3& end, const FColor& color, bool overlay); extern JULIET_API void DebugDisplay_Prepare(CommandList* cmdList);
extern JULIET_API void DebugDisplay_DrawSphere(const Vector3& center, float radius, const FColor& color, bool overlay); extern JULIET_API void DebugDisplay_Flush(CommandList* cmdList, RenderPass* renderPass, const Camera& camera);
extern JULIET_API void DebugDisplay_Prepare(CommandList* cmdList);
extern JULIET_API void DebugDisplay_Flush(CommandList* cmdList, RenderPass* renderPass, const Camera& camera);
} // namespace Juliet
+88 -91
View File
@@ -12,166 +12,163 @@
#include <Juliet.h> #include <Juliet.h>
// Graphics Interface // Graphics Interface
namespace Juliet // Opaque types
{ struct CommandList;
// Opaque types struct GraphicsDevice;
struct CommandList; struct Fence;
struct GraphicsDevice;
struct Fence;
// Parameters of an indirect draw command // Parameters of an indirect draw command
struct IndirectDrawCommand struct IndirectDrawCommand
{ {
uint32 VertexCount; // Number of vertices to draw uint32 VertexCount; // Number of vertices to draw
uint32 InstanceCount; // Number of instanced to draw uint32 InstanceCount; // Number of instanced to draw
uint32 FirstVertex; // Index of the first vertex to draw uint32 FirstVertex; // Index of the first vertex to draw
uint32 FirstInstance; // ID of the first instance to draw uint32 FirstInstance; // ID of the first instance to draw
}; };
// Parameters of an INDEXED indirect draw command // Parameters of an INDEXED indirect draw command
struct IndexedIndirectDrawCommand struct IndexedIndirectDrawCommand
{ {
uint32 VertexCount; // Number of vertices to draw uint32 VertexCount; // Number of vertices to draw
uint32 InstanceCount; // Number of instanced to draw uint32 InstanceCount; // Number of instanced to draw
uint32 FirstIndex; // Base Index within the index buffer uint32 FirstIndex; // Base Index within the index buffer
int32 VertexOffset; // Offset the vertex index into the buffer int32 VertexOffset; // Offset the vertex index into the buffer
uint32 FirstInstance; // ID of the first instance to draw uint32 FirstInstance; // ID of the first instance to draw
}; };
// Parameters of an INDEXED Indirect Dispatch Command // Parameters of an INDEXED Indirect Dispatch Command
struct IndirectDispatchCommand struct IndirectDispatchCommand
{ {
uint32 X_WorkGroupCount; // Number of Workgroup to dispatch on dimension X uint32 X_WorkGroupCount; // Number of Workgroup to dispatch on dimension X
uint32 Y_WorkGroupCount; // Number of Workgroup to dispatch on dimension Y uint32 Y_WorkGroupCount; // Number of Workgroup to dispatch on dimension Y
uint32 Z_WorkGroupCount; // Number of Workgroup to dispatch on dimension Z uint32 Z_WorkGroupCount; // Number of Workgroup to dispatch on dimension Z
}; };
enum class QueueType : uint8 enum class QueueType : uint8
{ {
Graphics = 0, Graphics = 0,
Compute, Compute,
Copy, Copy,
Count Count
}; };
enum class IndexFormat : uint8 enum class IndexFormat : uint8
{ {
UInt16, UInt16,
UInt32 UInt32
}; };
enum struct SwapChainComposition : uint8 enum struct SwapChainComposition : uint8
{ {
SDR, SDR,
SDR_LINEAR, SDR_LINEAR,
HDR_EXTENDED_LINEAR, HDR_EXTENDED_LINEAR,
HDR10_ST2084 HDR10_ST2084
}; };
// PresentMode from highest to lowest latency // PresentMode from highest to lowest latency
// Vsync prevents tearing. Enqueue ready images. // Vsync prevents tearing. Enqueue ready images.
// Mailbox prevents tearing. When image is ready, replace any pending image // Mailbox prevents tearing. When image is ready, replace any pending image
// Immediate replace current image as soon as possible. Can cause tearing // Immediate replace current image as soon as possible. Can cause tearing
enum struct PresentMode : uint8 enum struct PresentMode : uint8
{ {
VSync, VSync,
Mailbox, Mailbox,
Immediate Immediate
}; };
struct GraphicsViewPort struct GraphicsViewPort
{ {
float X; float X;
float Y; float Y;
float Width; float Width;
float Height; float Height;
float MinDepth; float MinDepth;
float MaxDepth; float MaxDepth;
}; };
extern JULIET_API GraphicsDevice* CreateGraphicsDevice(GraphicsConfig config); extern JULIET_API GraphicsDevice* CreateGraphicsDevice(GraphicsConfig config);
extern JULIET_API void DestroyGraphicsDevice(NonNullPtr<GraphicsDevice> device); extern JULIET_API void DestroyGraphicsDevice(NonNullPtr<GraphicsDevice> device);
// Attach To Window // Attach To Window
extern JULIET_API bool AttachToWindow(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window); extern JULIET_API bool AttachToWindow(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window);
extern JULIET_API void DetachFromWindow(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window); extern JULIET_API void DetachFromWindow(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window);
// SwapChain // SwapChain
extern JULIET_API bool AcquireSwapChainTexture(NonNullPtr<CommandList> commandList, NonNullPtr<Window> window, extern JULIET_API bool AcquireSwapChainTexture(NonNullPtr<CommandList> commandList, NonNullPtr<Window> window,
Texture** swapChainTexture); Texture** swapChainTexture);
extern JULIET_API bool WaitAndAcquireSwapChainTexture(NonNullPtr<CommandList> commandList, extern JULIET_API bool WaitAndAcquireSwapChainTexture(NonNullPtr<CommandList> commandList,
NonNullPtr<Window> window, Texture** swapChainTexture); NonNullPtr<Window> window, Texture** swapChainTexture);
extern JULIET_API bool WaitForSwapchain(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window); extern JULIET_API bool WaitForSwapchain(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window);
extern JULIET_API TextureFormat GetSwapChainTextureFormat(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window); extern JULIET_API TextureFormat GetSwapChainTextureFormat(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window);
// Textures // Textures
extern JULIET_API Texture* CreateTexture(NonNullPtr<GraphicsDevice> device, const TextureCreateInfo& createInfo); extern JULIET_API Texture* CreateTexture(NonNullPtr<GraphicsDevice> device, const TextureCreateInfo& createInfo);
extern JULIET_API void DestroyTexture(NonNullPtr<GraphicsDevice> device, NonNullPtr<Texture> texture); extern JULIET_API void DestroyTexture(NonNullPtr<GraphicsDevice> device, NonNullPtr<Texture> texture);
// Command List // Command List
extern JULIET_API CommandList* AcquireCommandList(NonNullPtr<GraphicsDevice> device, QueueType queueType = QueueType::Graphics); extern JULIET_API CommandList* AcquireCommandList(NonNullPtr<GraphicsDevice> device, QueueType queueType = QueueType::Graphics);
extern JULIET_API void SubmitCommandLists(NonNullPtr<CommandList> commandList); extern JULIET_API void SubmitCommandLists(NonNullPtr<CommandList> commandList);
// RenderPass // RenderPass
extern JULIET_API RenderPass* BeginRenderPass(NonNullPtr<CommandList> commandList, ColorTargetInfo& colorTargetInfo, extern JULIET_API RenderPass* BeginRenderPass(NonNullPtr<CommandList> commandList, ColorTargetInfo& colorTargetInfo,
DepthStencilTargetInfo* depthStencilTargetInfo = nullptr); DepthStencilTargetInfo* depthStencilTargetInfo = nullptr);
extern JULIET_API RenderPass* BeginRenderPass(NonNullPtr<CommandList> commandList, extern JULIET_API RenderPass* BeginRenderPass(NonNullPtr<CommandList> commandList,
NonNullPtr<const ColorTargetInfo> colorTargetInfos, uint32 colorTargetInfoCount, NonNullPtr<const ColorTargetInfo> colorTargetInfos, uint32 colorTargetInfoCount,
DepthStencilTargetInfo* depthStencilTargetInfo = nullptr); DepthStencilTargetInfo* depthStencilTargetInfo = nullptr);
extern JULIET_API void EndRenderPass(NonNullPtr<RenderPass> renderPass); extern JULIET_API void EndRenderPass(NonNullPtr<RenderPass> renderPass);
extern JULIET_API void SetGraphicsViewPort(NonNullPtr<RenderPass> renderPass, const GraphicsViewPort& viewPort); extern JULIET_API void SetGraphicsViewPort(NonNullPtr<RenderPass> renderPass, const GraphicsViewPort& viewPort);
extern JULIET_API void SetScissorRect(NonNullPtr<RenderPass> renderPass, const Rectangle& rectangle); extern JULIET_API void SetScissorRect(NonNullPtr<RenderPass> renderPass, const struct Rectangle& rectangle);
extern JULIET_API void SetBlendConstants(NonNullPtr<RenderPass> renderPass, FColor blendConstants); extern JULIET_API void SetBlendConstants(NonNullPtr<RenderPass> renderPass, FColor blendConstants);
extern JULIET_API void SetStencilReference(NonNullPtr<RenderPass> renderPass, uint8 reference); extern JULIET_API void SetStencilReference(NonNullPtr<RenderPass> renderPass, uint8 reference);
extern JULIET_API void BindGraphicsPipeline(NonNullPtr<RenderPass> renderPass, NonNullPtr<GraphicsPipeline> graphicsPipeline); extern JULIET_API void BindGraphicsPipeline(NonNullPtr<RenderPass> renderPass, NonNullPtr<GraphicsPipeline> graphicsPipeline);
extern JULIET_API void DrawPrimitives(NonNullPtr<RenderPass> renderPass, uint32 numVertices, uint32 numInstances, extern JULIET_API void DrawPrimitives(NonNullPtr<RenderPass> renderPass, uint32 numVertices, uint32 numInstances,
uint32 firstVertex, uint32 firstInstance); uint32 firstVertex, uint32 firstInstance);
extern JULIET_API void DrawIndexedPrimitives(NonNullPtr<RenderPass> renderPass, uint32 numIndices, uint32 numInstances, extern JULIET_API void DrawIndexedPrimitives(NonNullPtr<RenderPass> renderPass, uint32 numIndices, uint32 numInstances,
uint32 firstIndex, uint32 vertexOffset, uint32 firstInstance); uint32 firstIndex, uint32 vertexOffset, uint32 firstInstance);
extern JULIET_API void SetIndexBuffer(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsBuffer> buffer, extern JULIET_API void SetIndexBuffer(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsBuffer> buffer,
IndexFormat format, size_t indexCount, index_t offset); IndexFormat format, size_t indexCount, index_t offset);
extern JULIET_API void SetPushConstants(NonNullPtr<CommandList> commandList, ShaderStage stage, extern JULIET_API void SetPushConstants(NonNullPtr<CommandList> commandList, ShaderStage stage,
uint32 rootParameterIndex, uint32 numConstants, const void* constants); uint32 rootParameterIndex, uint32 numConstants, const void* constants);
// Fences // Fences
extern JULIET_API bool WaitUntilGPUIsIdle(NonNullPtr<GraphicsDevice> device); extern JULIET_API bool WaitUntilGPUIsIdle(NonNullPtr<GraphicsDevice> device);
// Shaders // Shaders
extern JULIET_API Shader* CreateShader(NonNullPtr<GraphicsDevice> device, String filename, ShaderCreateInfo& shaderCreateInfo); extern JULIET_API Shader* CreateShader(NonNullPtr<GraphicsDevice> device, String filename, ShaderCreateInfo& shaderCreateInfo);
extern JULIET_API void DestroyShader(NonNullPtr<GraphicsDevice> device, NonNullPtr<Shader> shader); extern JULIET_API void DestroyShader(NonNullPtr<GraphicsDevice> device, NonNullPtr<Shader> shader);
// Pipelines // Pipelines
extern JULIET_API GraphicsPipeline* CreateGraphicsPipeline(NonNullPtr<GraphicsDevice> device, extern JULIET_API GraphicsPipeline* CreateGraphicsPipeline(NonNullPtr<GraphicsDevice> device,
const GraphicsPipelineCreateInfo& createInfo); const GraphicsPipelineCreateInfo& createInfo);
extern JULIET_API void DestroyGraphicsPipeline(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsPipeline> graphicsPipeline); extern JULIET_API void DestroyGraphicsPipeline(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsPipeline> graphicsPipeline);
#if ALLOW_SHADER_HOT_RELOAD #if ALLOW_SHADER_HOT_RELOAD
// Allows updating the graphics pipeline shaders. Can update either one or both shaders. // Allows updating the graphics pipeline shaders. Can update either one or both shaders.
extern JULIET_API bool UpdateGraphicsPipelineShaders(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsPipeline> graphicsPipeline, extern JULIET_API bool UpdateGraphicsPipelineShaders(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsPipeline> graphicsPipeline,
Shader* optional_vertexShader, Shader* optional_fragmentShader); Shader* optional_vertexShader, Shader* optional_fragmentShader);
#endif #endif
// Buffers // Buffers
extern JULIET_API GraphicsBuffer* CreateGraphicsBuffer(NonNullPtr<GraphicsDevice> device, const BufferCreateInfo& createInfo); extern JULIET_API GraphicsBuffer* CreateGraphicsBuffer(NonNullPtr<GraphicsDevice> device, const BufferCreateInfo& createInfo);
extern JULIET_API GraphicsTransferBuffer* CreateGraphicsTransferBuffer(NonNullPtr<GraphicsDevice> device, extern JULIET_API GraphicsTransferBuffer* CreateGraphicsTransferBuffer(NonNullPtr<GraphicsDevice> device,
const TransferBufferCreateInfo& createInfo); const TransferBufferCreateInfo& createInfo);
extern JULIET_API void* MapGraphicsBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsBuffer> buffer); extern JULIET_API void* MapGraphicsBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsBuffer> buffer);
extern JULIET_API void UnmapGraphicsBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsBuffer> buffer); extern JULIET_API void UnmapGraphicsBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsBuffer> buffer);
extern JULIET_API void* MapGraphicsTransferBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsTransferBuffer> buffer); extern JULIET_API void* MapGraphicsTransferBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsTransferBuffer> buffer);
extern JULIET_API void UnmapGraphicsTransferBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsTransferBuffer> buffer); extern JULIET_API void UnmapGraphicsTransferBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsTransferBuffer> buffer);
extern JULIET_API void CopyBuffer(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsBuffer> dst, extern JULIET_API void CopyBuffer(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsBuffer> dst,
NonNullPtr<GraphicsTransferBuffer> src, size_t size, size_t dstOffset = 0, NonNullPtr<GraphicsTransferBuffer> src, size_t size, size_t dstOffset = 0,
size_t srcOffset = 0); size_t srcOffset = 0);
extern JULIET_API void CopyBufferToTexture(NonNullPtr<CommandList> commandList, NonNullPtr<Texture> dst, extern JULIET_API void CopyBufferToTexture(NonNullPtr<CommandList> commandList, NonNullPtr<Texture> dst,
NonNullPtr<GraphicsTransferBuffer> src); NonNullPtr<GraphicsTransferBuffer> src);
extern JULIET_API void TransitionBufferToReadable(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsBuffer> buffer); extern JULIET_API void TransitionBufferToReadable(NonNullPtr<CommandList> commandList, NonNullPtr<GraphicsBuffer> buffer);
extern JULIET_API uint32 GetDescriptorIndex(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsBuffer> buffer); extern JULIET_API uint32 GetDescriptorIndex(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsBuffer> buffer);
extern JULIET_API uint32 GetDescriptorIndex(NonNullPtr<GraphicsDevice> device, NonNullPtr<Texture> texture); extern JULIET_API uint32 GetDescriptorIndex(NonNullPtr<GraphicsDevice> device, NonNullPtr<Texture> texture);
extern JULIET_API void DestroyGraphicsBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsBuffer> buffer); extern JULIET_API void DestroyGraphicsBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsBuffer> buffer);
extern JULIET_API void DestroyGraphicsTransferBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsTransferBuffer> buffer); extern JULIET_API void DestroyGraphicsTransferBuffer(NonNullPtr<GraphicsDevice> device, NonNullPtr<GraphicsTransferBuffer> buffer);
} // namespace Juliet
+15 -18
View File
@@ -1,36 +1,33 @@
#pragma once #pragma once
namespace Juliet enum class BufferUsage : uint8
{ {
enum class BufferUsage : uint8
{
None = 0, None = 0,
IndexBuffer = 1 << 0, IndexBuffer = 1 << 0,
ConstantBuffer = 1 << 1, ConstantBuffer = 1 << 1,
StructuredBuffer = 1 << 2, StructuredBuffer = 1 << 2,
}; };
enum class TransferBufferUsage : uint8 enum class TransferBufferUsage : uint8
{ {
Download, Download,
Upload Upload
}; };
struct BufferCreateInfo struct BufferCreateInfo
{ {
size_t Size; size_t Size;
size_t Stride; size_t Stride;
BufferUsage Usage; BufferUsage Usage;
bool IsDynamic; bool IsDynamic;
}; };
struct TransferBufferCreateInfo struct TransferBufferCreateInfo
{ {
size_t Size; size_t Size;
TransferBufferUsage Usage; TransferBufferUsage Usage;
}; };
// Opaque // Opaque
struct GraphicsBuffer; struct GraphicsBuffer;
struct GraphicsTransferBuffer; struct GraphicsTransferBuffer;
} // namespace Juliet
+6 -9
View File
@@ -10,17 +10,14 @@
#define ALLOW_SHADER_HOT_RELOAD 0 #define ALLOW_SHADER_HOT_RELOAD 0
#endif #endif
namespace Juliet enum class GraphicsDriverType : uint8
{ {
enum class DriverType : uint8
{
Any = 0, Any = 0,
DX12 = 1, DX12 = 1,
}; };
struct GraphicsConfig struct GraphicsConfig
{ {
DriverType PreferredDriver = DriverType::DX12; GraphicsDriverType PreferredDriver = GraphicsDriverType::DX12;
bool EnableDebug; bool EnableDebug;
}; };
} // namespace Juliet
+56 -59
View File
@@ -1,46 +1,44 @@
#pragma once #pragma once
#include <Graphics/Shader.h> #include <Graphics/Shader.h>
#include <Graphics/Texture.h> #include <Graphics/Texture.h>
namespace Juliet // Forward Declare
{ struct ColorTargetDescription;
// Forward Declare
struct ColorTargetDescription;
enum class FillMode : uint8 enum class FillMode : uint8
{ {
Solid, Solid,
Wireframe, Wireframe,
Count Count
}; };
enum class CullMode : uint8 enum class CullMode : uint8
{ {
None, None,
Front, Front,
Back, Back,
Count Count
}; };
enum class FrontFace : uint8 enum class FrontFace : uint8
{ {
CounterClockwise, CounterClockwise,
Clockwise, Clockwise,
Count Count
}; };
enum class PrimitiveType : uint8 enum class PrimitiveType : uint8
{ {
TriangleList, TriangleList,
TriangleStrip, TriangleStrip,
LineList, LineList,
LineStrip, LineStrip,
PointList, PointList,
Count Count
}; };
struct RasterizerState struct RasterizerState
{ {
FillMode FillMode; FillMode FillMode;
CullMode CullMode; CullMode CullMode;
FrontFace FrontFace; FrontFace FrontFace;
@@ -50,25 +48,25 @@ namespace Juliet
float DepthBiasSlopeFactor; // Scalar applied to Fragment's slope float DepthBiasSlopeFactor; // Scalar applied to Fragment's slope
bool EnableDepthBias; // Bias fragment depth values bool EnableDepthBias; // Bias fragment depth values
bool EnableDepthClip; // True to clip, false to clamp bool EnableDepthClip; // True to clip, false to clamp
}; };
enum class VertexInputRate : uint8 enum class VertexInputRate : uint8
{ {
Vertex, // Use vertex index Vertex, // Use vertex index
Instance, // Use instance index Instance, // Use instance index
Count Count
}; };
struct VertexBufferDescription struct VertexBufferDescription
{ {
uint32 Slot; // Binding Slot uint32 Slot; // Binding Slot
uint32 PitchInBytes; // Pitch between two elements uint32 PitchInBytes; // Pitch between two elements
VertexInputRate InputRate; VertexInputRate InputRate;
uint32 InstanceStepRate; // Only used when input rate == Instance. Number of instances to draw before advancing in the instance buffer by 1 uint32 InstanceStepRate; // Only used when input rate == Instance. Number of instances to draw before advancing in the instance buffer by 1
}; };
enum class VertexElementFormat : uint8 enum class VertexElementFormat : uint8
{ {
Invalid, Invalid,
/* 32-bit Signed Integers */ /* 32-bit Signed Integers */
@@ -127,34 +125,34 @@ namespace Juliet
// //
Count Count
}; };
struct VertexAttribute struct VertexAttribute
{ {
uint32 Location; // Shader input location index uint32 Location; // Shader input location index
uint32 BufferSlot; // Binding slot of associated vertex buffer uint32 BufferSlot; // Binding slot of associated vertex buffer
VertexElementFormat Format; // Size and type of attribute VertexElementFormat Format; // Size and type of attribute
uint32 Offset; // Offset of this attribute relative to the start of the vertex element uint32 Offset; // Offset of this attribute relative to the start of the vertex element
}; };
struct VertexInputState struct VertexInputState
{ {
const VertexBufferDescription* VertexBufferDescriptions; const VertexBufferDescription* VertexBufferDescriptions;
uint32 NumVertexBufferDescriptions; uint32 NumVertexBufferDescriptions;
const VertexAttribute* VertexAttributes; const VertexAttribute* VertexAttributes;
uint32 NumVertexAttributes; uint32 NumVertexAttributes;
}; };
struct GraphicsPipelineTargetInfo struct GraphicsPipelineTargetInfo
{ {
const ColorTargetDescription* ColorTargetDescriptions; const ColorTargetDescription* ColorTargetDescriptions;
size_t NumColorTargets; size_t NumColorTargets;
TextureFormat DepthStencilFormat; TextureFormat DepthStencilFormat;
bool HasDepthStencilTarget; bool HasDepthStencilTarget;
}; };
enum class CompareOperation : uint8 enum class CompareOperation : uint8
{ {
Invalid, Invalid,
Never, // The comparison always evaluates false. Never, // The comparison always evaluates false.
Less, // The comparison evaluates reference < test. Less, // The comparison evaluates reference < test.
@@ -165,10 +163,10 @@ namespace Juliet
GreaterOrEqual, // The comparison evalutes reference >= test. GreaterOrEqual, // The comparison evalutes reference >= test.
Always, // The comparison always evaluates true. Always, // The comparison always evaluates true.
Count Count
}; };
enum class StencilOperation : uint8 enum class StencilOperation : uint8
{ {
Invalid, Invalid,
Keep, // Keeps the current value. Keep, // Keeps the current value.
Zero, // Sets the value to 0. Zero, // Sets the value to 0.
@@ -179,18 +177,18 @@ namespace Juliet
IncrementAndWrap, // Increments the current value and wraps back to 0. IncrementAndWrap, // Increments the current value and wraps back to 0.
DecrementAndWrap, // Decrements the current value and wraps to the maximum value. DecrementAndWrap, // Decrements the current value and wraps to the maximum value.
Count Count
}; };
struct StencilOperationState struct StencilOperationState
{ {
StencilOperation FailOperation; // The action performed on samples that fail the stencil test. StencilOperation FailOperation; // The action performed on samples that fail the stencil test.
StencilOperation PassOperation; // The action performed on samples that pass the depth and stencil tests. StencilOperation PassOperation; // The action performed on samples that pass the depth and stencil tests.
StencilOperation DepthFailOperation; // The action performed on samples that pass the stencil test and fail the depth test. StencilOperation DepthFailOperation; // The action performed on samples that pass the stencil test and fail the depth test.
StencilOperation CompareOperation; // The comparison operator used in the stencil test. StencilOperation CompareOperation; // The comparison operator used in the stencil test.
}; };
struct DepthStencilState struct DepthStencilState
{ {
CompareOperation CompareOperation; // The comparison operator used for depth testing. CompareOperation CompareOperation; // The comparison operator used for depth testing.
StencilOperationState BackStencilState; // The stencil op state for back-facing triangles. StencilOperationState BackStencilState; // The stencil op state for back-facing triangles.
StencilOperationState FrontStencilState; // The stencil op state for front-facing triangles. StencilOperationState FrontStencilState; // The stencil op state for front-facing triangles.
@@ -199,17 +197,17 @@ namespace Juliet
bool EnableDepthTest : 1; // true enables the depth test. bool EnableDepthTest : 1; // true enables the depth test.
bool EnableDepthWrite : 1; // true enables depth writes. Depth writes are always disabled when enable_depth_test is false. bool EnableDepthWrite : 1; // true enables depth writes. Depth writes are always disabled when enable_depth_test is false.
bool EnableStencilTest : 1; // true enables the stencil test. bool EnableStencilTest : 1; // true enables the stencil test.
}; };
struct MultisampleState struct MultisampleState
{ {
TextureSampleCount SampleCount; TextureSampleCount SampleCount;
uint32 SampleMask; // Which sample should be updated. If Enabled mask == false -> 0xFFFFFFFF uint32 SampleMask; // Which sample should be updated. If Enabled mask == false -> 0xFFFFFFFF
bool EnableMask; bool EnableMask;
}; };
struct GraphicsPipelineCreateInfo struct GraphicsPipelineCreateInfo
{ {
Shader* VertexShader; Shader* VertexShader;
Shader* FragmentShader; Shader* FragmentShader;
PrimitiveType PrimitiveType; PrimitiveType PrimitiveType;
@@ -218,8 +216,7 @@ namespace Juliet
MultisampleState MultisampleState; MultisampleState MultisampleState;
VertexInputState VertexInputState; VertexInputState VertexInputState;
DepthStencilState DepthStencilState; DepthStencilState DepthStencilState;
}; };
// Opaque type // Opaque type
struct GraphicsPipeline; struct GraphicsPipeline;
} // namespace Juliet
+5 -8
View File
@@ -1,12 +1,9 @@
#pragma once #pragma once
#include <Graphics/Graphics.h> #include <Graphics/Graphics.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet extern bool ImGuiRenderer_Initialize(GraphicsDevice* device);
{ extern void ImGuiRenderer_Shutdown(GraphicsDevice* device);
extern bool ImGuiRenderer_Initialize(GraphicsDevice* device); extern void ImGuiRenderer_NewFrame();
extern void ImGuiRenderer_Shutdown(GraphicsDevice* device); extern JULIET_API void ImGuiRenderer_Render(CommandList* cmdList, RenderPass* renderPass);
extern void ImGuiRenderer_NewFrame();
extern JULIET_API void ImGuiRenderer_Render(CommandList* cmdList, RenderPass* renderPass);
} // namespace Juliet
+3 -6
View File
@@ -1,15 +1,12 @@
#pragma once #pragma once
#include <Juliet.h> #include <Juliet.h>
#include <Core/Math/Vector.h> #include <Core/Math/Vector.h>
namespace Juliet struct PointLight
{ {
struct PointLight
{
Vector3 Position; Vector3 Position;
float Radius; float Radius;
Vector3 Color; Vector3 Color;
float Intensity; float Intensity;
}; };
} // namespace Juliet
+16 -19
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
@@ -7,34 +7,31 @@
#include <Core/Math/Vector.h> #include <Core/Math/Vector.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet struct Arena;
struct Vertex;
using MeshAssetID = index_t;
using MaterialAssetID = index_t;
using MeshInstanceID = index_t;
struct MeshAsset
{ {
struct Arena;
struct Vertex;
using MeshAssetID = index_t;
using MaterialAssetID = index_t;
using MeshInstanceID = index_t;
struct MeshAsset
{
String Name; String Name;
size_t VertexCount; size_t VertexCount;
size_t IndexCount; size_t IndexCount;
index_t VertexOffset; index_t VertexOffset;
index_t IndexOffset; index_t IndexOffset;
}; };
struct MaterialAsset struct MaterialAsset
{ {
Vector4 AlbedoColor = {1.0f, 1.0f, 1.0f, 1.0f}; Vector4 AlbedoColor = {1.0f, 1.0f, 1.0f, 1.0f};
}; };
struct MeshInstance struct MeshInstance
{ {
MeshAssetID MeshAsset; MeshAssetID MeshAsset;
MaterialAssetID MaterialAsset; MaterialAssetID MaterialAsset;
Matrix Transform = MatrixIdentity(); Matrix Transform = MatrixIdentity();
}; };
} // namespace Juliet
+38 -41
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Core/Container/Vector.h> #include <Core/Container/Vector.h>
#include <Core/Math/Matrix.h> #include <Core/Math/Matrix.h>
@@ -9,52 +9,49 @@
#include <Graphics/Mesh.h> #include <Graphics/Mesh.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet struct GraphicsTransferBuffer;
{ struct RenderPass;
struct GraphicsTransferBuffer; struct CommandList;
struct RenderPass; struct GraphicsBuffer;
struct CommandList; struct Window;
struct GraphicsBuffer; struct GraphicsPipeline;
struct Window; struct GraphicsDevice;
struct GraphicsPipeline; using LightID = index_t;
struct GraphicsDevice;
using LightID = index_t;
constexpr size_t kGeometryPage = Megabytes(64); constexpr size_t kGeometryPage = Megabytes(64);
constexpr size_t kIndexPage = Megabytes(32); constexpr size_t kIndexPage = Megabytes(32);
constexpr size_t kDefaultMeshNumber = 500; constexpr size_t kDefaultMeshNumber = 500;
constexpr size_t kDefaultVertexCount = 2'000'000; // Fit less than one geometry page constexpr size_t kDefaultVertexCount = 2'000'000; // Fit less than one geometry page
constexpr size_t kDefaultIndexCount = 16'000'000; // Fit less than one index page constexpr size_t kDefaultIndexCount = 16'000'000; // Fit less than one index page
constexpr size_t kDefaultLightCount = 1024; constexpr size_t kDefaultLightCount = 1024;
JULIET_API void InitializeMeshRenderer(NonNullPtr<Arena> assetArena, NonNullPtr<Arena> instanceArena); JULIET_API void InitializeMeshRenderer(NonNullPtr<Arena> assetArena, NonNullPtr<Arena> instanceArena);
[[nodiscard]] JULIET_API bool InitializeMeshRendererGraphics(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window); [[nodiscard]] JULIET_API bool InitializeMeshRendererGraphics(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window);
JULIET_API void ShutdownMeshRendererGraphics(); JULIET_API void ShutdownMeshRendererGraphics();
JULIET_API void ShutdownMeshRenderer(); JULIET_API void ShutdownMeshRenderer();
JULIET_API void LoadMeshesOnGPU(NonNullPtr<CommandList> cmdList); JULIET_API void LoadMeshesOnGPU(NonNullPtr<CommandList> cmdList);
JULIET_API void RenderMeshes(NonNullPtr<CommandList> cmdList, NonNullPtr<RenderPass> pass, const Matrix& viewProjection); JULIET_API void RenderMeshes(NonNullPtr<CommandList> cmdList, NonNullPtr<RenderPass> pass, const Matrix& viewProjection);
// Lights // Lights
[[nodiscard]] JULIET_API LightID AddPointLight(const PointLight& light); [[nodiscard]] JULIET_API LightID AddPointLight(const PointLight& light);
JULIET_API void SetPointLightPosition(LightID id, const Vector3& position); JULIET_API void SetPointLightPosition(LightID id, const Vector3& position);
JULIET_API void SetPointLightColor(LightID id, const Vector3& color); JULIET_API void SetPointLightColor(LightID id, const Vector3& color);
JULIET_API void SetPointLightRadius(LightID id, float radius); JULIET_API void SetPointLightRadius(LightID id, float radius);
JULIET_API void SetPointLightIntensity(LightID id, float intensity); JULIET_API void SetPointLightIntensity(LightID id, float intensity);
JULIET_API void ClearPointLights(); JULIET_API void ClearPointLights();
JULIET_API void SetGlobalLight(const Vector3& direction, const Vector3& color, float ambientIntensity); JULIET_API void SetGlobalLight(const Vector3& direction, const Vector3& color, float ambientIntensity);
// Assets & Instances // Assets & Instances
[[nodiscard]] JULIET_API MeshAssetID GetOrCreateMeshAsset(String name); [[nodiscard]] JULIET_API MeshAssetID GetOrCreateMeshAsset(String name);
[[nodiscard]] JULIET_API MeshInstanceID CreateMeshInstance(MeshAssetID meshAsset, MaterialAssetID materialAsset, const Matrix& transform); [[nodiscard]] JULIET_API MeshInstanceID CreateMeshInstance(MeshAssetID meshAsset, MaterialAssetID materialAsset, const Matrix& transform);
JULIET_API void SetMeshInstanceTransform(MeshInstanceID id, const Matrix& transform); JULIET_API void SetMeshInstanceTransform(MeshInstanceID id, const Matrix& transform);
// Primitives // Primitives
JULIET_API MeshAssetID GetCubePrimitiveMeshAssetID(); JULIET_API MeshAssetID GetCubePrimitiveMeshAssetID();
JULIET_API MeshAssetID GetQuadPrimitiveMeshAssetID(); JULIET_API MeshAssetID GetQuadPrimitiveMeshAssetID();
JULIET_API MeshAssetID GetSpherePrimitiveMeshAssetID(); JULIET_API MeshAssetID GetSpherePrimitiveMeshAssetID();
#if ALLOW_SHADER_HOT_RELOAD #if ALLOW_SHADER_HOT_RELOAD
JULIET_API void ReloadMeshRendererShaders(); JULIET_API void ReloadMeshRendererShaders();
#endif #endif
} // namespace Juliet
+3 -6
View File
@@ -1,13 +1,11 @@
#pragma once #pragma once
#include <Core/Math/Matrix.h> #include <Core/Math/Matrix.h>
#include <Core/Math/Vector.h> #include <Core/Math/Vector.h>
#include <Juliet.h> #include <Juliet.h>
namespace Juliet struct PushData
{ {
struct PushData
{
Matrix ViewProjection; Matrix ViewProjection;
uint32 MeshIndex; uint32 MeshIndex;
uint32 TransformsBufferIndex; uint32 TransformsBufferIndex;
@@ -28,5 +26,4 @@ namespace Juliet
float Translate[2]; float Translate[2];
Vector4 MeshAlbedo; Vector4 MeshAlbedo;
}; };
} // namespace Juliet
+28 -31
View File
@@ -1,27 +1,25 @@
#pragma once #pragma once
#include <Graphics/Colors.h> #include <Graphics/Colors.h>
#include <Graphics/Texture.h> #include <Graphics/Texture.h>
namespace Juliet enum struct LoadOperation : uint8
{ {
enum struct LoadOperation : uint8
{
Load, // Load the texture from memory (preserve) Load, // Load the texture from memory (preserve)
Clear, // Clear the texture Clear, // Clear the texture
Ignore // Ignore the content of the texture (undefined) Ignore // Ignore the content of the texture (undefined)
}; };
enum struct StoreOperation : uint8 enum struct StoreOperation : uint8
{ {
Store, // Store the result of the render pass into memory Store, // Store the result of the render pass into memory
Ignore, // Whatever is generated is ignored (undefined) Ignore, // Whatever is generated is ignored (undefined)
Resolve, // Resolve MipMaps into non mip map texture. Discard MipMap content Resolve, // Resolve MipMaps into non mip map texture. Discard MipMap content
ResolveAndStore // Same but store the MipMap content to memory ResolveAndStore // Same but store the MipMap content to memory
}; };
struct ColorTargetInfo struct ColorTargetInfo
{ {
Texture* TargetTexture; Texture* TargetTexture;
uint32 MipLevel; uint32 MipLevel;
union union
@@ -39,10 +37,10 @@ namespace Juliet
FColor ClearColor; FColor ClearColor;
LoadOperation LoadOperation; LoadOperation LoadOperation;
StoreOperation StoreOperation; StoreOperation StoreOperation;
}; };
struct DepthStencilTargetInfo struct DepthStencilTargetInfo
{ {
Texture* TargetTexture; Texture* TargetTexture;
uint32 MipLevel; uint32 MipLevel;
uint32 LayerIndex; uint32 LayerIndex;
@@ -51,10 +49,10 @@ namespace Juliet
uint8 ClearStencil; uint8 ClearStencil;
LoadOperation LoadOperation; LoadOperation LoadOperation;
StoreOperation StoreOperation; StoreOperation StoreOperation;
}; };
enum class BlendFactor : uint8 enum class BlendFactor : uint8
{ {
Invalid, Invalid,
Zero, Zero,
One, One,
@@ -70,10 +68,10 @@ namespace Juliet
One_MINUS_Constant_Color, One_MINUS_Constant_Color,
Src_Alpha_Saturate, // min(source alpha, 1 - destination alpha) Src_Alpha_Saturate, // min(source alpha, 1 - destination alpha)
Count Count
}; };
enum class BlendOperation : uint8 enum class BlendOperation : uint8
{ {
Invalid, Invalid,
Add, // (source * source_factor) + (destination * destination_factor) Add, // (source * source_factor) + (destination * destination_factor)
Subtract, // (source * source_factor) - (destination * destination_factor) Subtract, // (source * source_factor) - (destination * destination_factor)
@@ -81,18 +79,18 @@ namespace Juliet
Min, // min(source, destination) Min, // min(source, destination)
Max, // max(source, destination) Max, // max(source, destination)
Count Count
}; };
enum class ColorComponentFlags : uint8 enum class ColorComponentFlags : uint8
{ {
R = 1u << 0, R = 1u << 0,
G = 1u << 1, G = 1u << 1,
B = 1u << 2, B = 1u << 2,
A = 1u << 3 A = 1u << 3
}; };
struct ColorTargetBlendState struct ColorTargetBlendState
{ {
BlendFactor SourceColorBlendFactor; // The value to be multiplied by the source RGB value. BlendFactor SourceColorBlendFactor; // The value to be multiplied by the source RGB value.
BlendFactor DestinationColorBlendFactor; // The value to be multiplied by the destination RGB value. BlendFactor DestinationColorBlendFactor; // The value to be multiplied by the destination RGB value.
BlendOperation ColorBlendOperation; // The blend operation for the RGB components. BlendOperation ColorBlendOperation; // The blend operation for the RGB components.
@@ -102,14 +100,13 @@ namespace Juliet
ColorComponentFlags ColorWriteMask; // A bitmask specifying which of the RGBA components are enabled for writing. Writes to all channels if enable_color_write_mask is false. ColorComponentFlags ColorWriteMask; // A bitmask specifying which of the RGBA components are enabled for writing. Writes to all channels if enable_color_write_mask is false.
bool EnableBlend : 1; // Whether blending is enabled for the color target. bool EnableBlend : 1; // Whether blending is enabled for the color target.
bool EnableColorWriteMask : 1; // Whether the color write mask is enabled. bool EnableColorWriteMask : 1; // Whether the color write mask is enabled.
}; };
struct ColorTargetDescription struct ColorTargetDescription
{ {
TextureFormat Format; TextureFormat Format;
ColorTargetBlendState BlendState; ColorTargetBlendState BlendState;
}; };
// Opaque Type // Opaque Type
struct RenderPass; struct RenderPass;
} // namespace Juliet
+9 -12
View File
@@ -1,23 +1,20 @@
#pragma once #pragma once
#include <Core/Common/String.h> #include <Core/Common/String.h>
namespace Juliet // Opaque type
{ struct Shader;
// Opaque type
struct Shader;
enum class ShaderStage : uint8 enum class ShaderStage : uint8
{ {
Vertex, Vertex,
Fragment, Fragment,
Compute Compute
}; };
struct ShaderCreateInfo struct ShaderCreateInfo
{ {
ShaderStage Stage; ShaderStage Stage;
String EntryPoint; String EntryPoint;
}; };
} // namespace Juliet
+13 -16
View File
@@ -1,4 +1,4 @@
#pragma once #pragma once
#include <Juliet.h> #include <Juliet.h>
@@ -6,26 +6,23 @@
#include <Core/Math/Matrix.h> #include <Core/Math/Matrix.h>
#include <Graphics/GraphicsConfig.h> #include <Graphics/GraphicsConfig.h>
namespace Juliet struct RenderPass;
{ struct CommandList;
struct RenderPass; struct Window;
struct CommandList; struct GraphicsPipeline;
struct Window; struct GraphicsDevice;
struct GraphicsPipeline;
struct GraphicsDevice;
struct SkyboxRenderer struct SkyboxRenderer
{ {
GraphicsDevice* Device; GraphicsDevice* Device;
GraphicsPipeline* Pipeline; GraphicsPipeline* Pipeline;
}; };
[[nodiscard]] JULIET_API bool InitializeSkyboxRenderer(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window); [[nodiscard]] JULIET_API bool InitializeSkyboxRenderer(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window);
JULIET_API void ShutdownSkyboxRenderer(); JULIET_API void ShutdownSkyboxRenderer();
JULIET_API void RenderSkybox(NonNullPtr<CommandList> cmdList, NonNullPtr<RenderPass> pass, const Matrix& viewProjection); JULIET_API void RenderSkybox(NonNullPtr<CommandList> cmdList, NonNullPtr<RenderPass> pass, const Matrix& viewProjection);
#if ALLOW_SHADER_HOT_RELOAD #if ALLOW_SHADER_HOT_RELOAD
JULIET_API void ReloadSkyboxShaders(); JULIET_API void ReloadSkyboxShaders();
#endif #endif
} // namespace Juliet
+18 -21
View File
@@ -1,9 +1,7 @@
#pragma once #pragma once
namespace Juliet enum struct TextureFormat : uint8
{ {
enum struct TextureFormat : uint8
{
Invalid, Invalid,
/* Unsigned Normalized Float Color Formats */ /* Unsigned Normalized Float Color Formats */
@@ -127,10 +125,10 @@ namespace Juliet
ASTC_12x12_FLOAT, ASTC_12x12_FLOAT,
Count Count
}; };
enum struct TextureUsageFlag : uint8 enum struct TextureUsageFlag : uint8
{ {
None = 0, None = 0,
Sampler = 1 << 0, // Textures supports sampling Sampler = 1 << 0, // Textures supports sampling
ColorTarget = 1 << 1, // Texture is color render target ColorTarget = 1 << 1, // Texture is color render target
@@ -140,29 +138,29 @@ namespace Juliet
ComputeStorageWrite = 1 << 5, // Support Storage Write at compute stage ComputeStorageWrite = 1 << 5, // Support Storage Write at compute stage
ComputeStorageSimultaneousReadWrite = ComputeStorageSimultaneousReadWrite =
1 << 6, // Supports reads and writes in the same compute shader. Not equivalent to ComputeStorageRead | ComputeStorageWrite 1 << 6, // Supports reads and writes in the same compute shader. Not equivalent to ComputeStorageRead | ComputeStorageWrite
}; };
enum struct TextureType : uint8 enum struct TextureType : uint8
{ {
Texture_2D, Texture_2D,
Texture_2DArray, Texture_2DArray,
Texture_3D, Texture_3D,
Texture_3DArray, Texture_3DArray,
Texture_Cube, Texture_Cube,
Texture_CubeArray, Texture_CubeArray,
}; };
enum struct TextureSampleCount : uint8 enum struct TextureSampleCount : uint8
{ {
One, One,
Two, Two,
Four, Four,
Eight, Eight,
}; };
// Create Information structs // Create Information structs
struct TextureCreateInfo struct TextureCreateInfo
{ {
TextureType Type; TextureType Type;
TextureFormat Format; TextureFormat Format;
TextureUsageFlag Flags; TextureUsageFlag Flags;
@@ -176,8 +174,7 @@ namespace Juliet
uint32 DepthPlane; uint32 DepthPlane;
}; // LayerCount is used in 2d array textures and Depth for 3d textures }; // LayerCount is used in 2d array textures and Depth for 3d textures
uint32 MipLevelCount; uint32 MipLevelCount;
}; };
// Opaque Type // Opaque Type
struct Texture; struct Texture;
} // namespace Juliet
+4 -7
View File
@@ -1,13 +1,10 @@
#pragma once #pragma once
namespace Juliet struct Vertex
{ {
struct Vertex
{
float Position[3]; float Position[3];
float Normal[3]; float Normal[3];
float Color[4]; float Color[4];
}; };
using Index = uint16; using Index = uint16;
} // namespace Juliet
@@ -1,12 +1,10 @@
#include <Core/Application/ApplicationManager.h> #include <Core/Application/ApplicationManager.h>
#include <Core/JulietInit.h> #include <Core/JulietInit.h>
#include <Engine/Engine.h> #include <Engine/Engine.h>
namespace Juliet void StartApplication(IApplication& app, JulietInit_Flags flags)
{ {
void StartApplication(IApplication& app, JulietInit_Flags flags)
{
InitializeEngine(flags); InitializeEngine(flags);
LoadApplication(app); LoadApplication(app);
@@ -16,5 +14,4 @@ namespace Juliet
UnloadApplication(); UnloadApplication();
ShutdownEngine(); ShutdownEngine();
} }
} // namespace Juliet
+6 -9
View File
@@ -1,14 +1,12 @@
#include <Core/Logging/LogManager.h> #include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h> #include <Core/Logging/LogTypes.h>
#include <Core/Memory/Allocator.h> #include <Core/Memory/Allocator.h>
#include <comdef.h> // For _com_error to decode HRESULTs #include <comdef.h> // For _com_error to decode HRESULTs
#include <intrin.h> // For __debugbreak #include <intrin.h> // For __debugbreak
namespace Juliet void JulietAssert(const char* expression, const char* message, std::source_location location, long handleResult)
{ {
void JulietAssert(const char* expression, const char* message, std::source_location location, long handleResult)
{
Log(LogLevel::Error, LogCategory::Core, "--- ASSERTION FAILED ---"); Log(LogLevel::Error, LogCategory::Core, "--- ASSERTION FAILED ---");
Log(LogLevel::Error, LogCategory::Core, "Expression: %s", expression); Log(LogLevel::Error, LogCategory::Core, "Expression: %s", expression);
Log(LogLevel::Error, LogCategory::Core, "Message: %s", message); Log(LogLevel::Error, LogCategory::Core, "Message: %s", message);
@@ -25,14 +23,13 @@ namespace Juliet
Log(LogLevel::Error, LogCategory::Core, "-------------------------"); Log(LogLevel::Error, LogCategory::Core, "-------------------------");
JULIET_PLATFORM_BREAK(); JULIET_PLATFORM_BREAK();
} }
void Free(ByteBuffer& buffer) void Free(ByteBuffer& buffer)
{ {
if (buffer.Data) if (buffer.Data)
{ {
Free(buffer.Data); Free(buffer.Data);
} }
buffer = {}; buffer = {};
} }
} // namespace Juliet
+28 -31
View File
@@ -1,14 +1,12 @@
#include <Core/Common/CoreUtils.h> #include <Core/Common/CoreUtils.h>
#include <Core/Common/String.h> #include <Core/Common/String.h>
#include <Core/Logging/LogManager.h> #include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h> #include <Core/Logging/LogTypes.h>
#include <Core/Memory/MemoryArena.h> #include <Core/Memory/MemoryArena.h>
#include <Core/Memory/Utils.h> #include <Core/Memory/Utils.h>
namespace Juliet namespace
{ {
namespace
{
constexpr int32 kUnknown_UNICODE = 0xFFFD; constexpr int32 kUnknown_UNICODE = 0xFFFD;
struct struct
@@ -58,11 +56,11 @@ namespace Juliet
*to = from; *to = from;
return 1; return 1;
} }
} // namespace } // namespace
// TODO: remove this as we convert to simple unicode decode / encode at the bottom // TODO: remove this as we convert to simple unicode decode / encode at the bottom
uint32 StepUTF8(String& inStr) uint32 StepUTF8(String& inStr)
{ {
// From rfc3629, the UTF-8 spec: // From rfc3629, the UTF-8 spec:
// https://www.ietf.org/rfc/rfc3629.txt // https://www.ietf.org/rfc/rfc3629.txt
// //
@@ -183,10 +181,10 @@ namespace Juliet
isOverlong ? "true" : "false", isInvalid ? "true" : "false", isUTF16Surrogate ? "true" : "false"); isOverlong ? "true" : "false", isInvalid ? "true" : "false", isUTF16Surrogate ? "true" : "false");
inStr.Str += 1; inStr.Str += 1;
return kInvalidUTF8; return kInvalidUTF8;
} }
String FindString(String haystack, String needle) String FindString(String haystack, String needle)
{ {
if (!IsValid(needle)) if (!IsValid(needle))
{ {
return haystack; return haystack;
@@ -214,10 +212,10 @@ namespace Juliet
} }
return {}; return {};
} }
int8 StringCompareCaseInsensitive(String str1, String str2) int8 StringCompareCaseInsensitive(String str1, String str2)
{ {
// TODO: Support UTF8. For now ASCII only. // TODO: Support UTF8. For now ASCII only.
uint32 left = 0; uint32 left = 0;
uint32 right = 0; uint32 right = 0;
@@ -249,10 +247,10 @@ namespace Juliet
} }
} }
return 0; return 0;
} }
bool ConvertString(StringEncoding from, StringEncoding to, String src, StringBuffer& dst, bool nullTerminate) bool ConvertString(StringEncoding from, StringEncoding to, String src, StringBuffer& dst, bool nullTerminate)
{ {
Assert(IsValid(src)); Assert(IsValid(src));
const char* srcStr = src.Str; const char* srcStr = src.Str;
@@ -452,10 +450,10 @@ namespace Juliet
} }
return true; return true;
} }
bool ConvertString(String from, String to, String src, StringBuffer& dst, bool nullTerminate) bool ConvertString(String from, String to, String src, StringBuffer& dst, bool nullTerminate)
{ {
Assert(IsValid(from)); Assert(IsValid(from));
Assert(IsValid(to)); Assert(IsValid(to));
@@ -488,10 +486,10 @@ namespace Juliet
} }
return ConvertString(sourceFormat, destFormat, src, dst, nullTerminate); return ConvertString(sourceFormat, destFormat, src, dst, nullTerminate);
} }
namespace namespace
{ {
uint8 utf8_class[32] = { uint8 utf8_class[32] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 4, 5,
}; };
@@ -589,20 +587,20 @@ namespace Juliet
} }
return increment; return increment;
} }
} // namespace } // namespace
String StringCopy(NonNullPtr<Arena> arena, String str) String StringCopy(NonNullPtr<Arena> arena, String str)
{ {
String result; String result;
result.Size = str.Size; result.Size = str.Size;
result.Str = static_cast<char*>(ArenaPush(arena, str.Size + 1, alignof(char), true JULIET_DEBUG_PARAM("String"))); result.Str = static_cast<char*>(ArenaPush(arena, str.Size + 1, alignof(char), true JULIET_DEBUG_PARAM("String")));
MemCopy(result.Str, str.Str, str.Size); MemCopy(result.Str, str.Str, str.Size);
result.Str[result.Size] = 0; result.Str[result.Size] = 0;
return result; return result;
} }
String16 str16_from_8(NonNullPtr<Arena> arena, String8 in) String16 str16_from_8(NonNullPtr<Arena> arena, String8 in)
{ {
String16 result = {}; String16 result = {};
if (in.Size > 0) if (in.Size > 0)
{ {
@@ -623,6 +621,5 @@ namespace Juliet
result = { str, size }; result = { str, size };
} }
return result; return result;
} }
} // namespace Juliet
+1 -4
View File
@@ -1,5 +1,2 @@
#include <Core/Container/Vector.h> #include <Core/Container/Vector.h>
namespace Juliet
{
}
+37 -40
View File
@@ -1,26 +1,24 @@
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/HAL/Display/Display_cpp.h> #include <Core/HAL/Display/Display_cpp.h>
#include <Core/HAL/Display/DisplayDevice.h> #include <Core/HAL/Display/DisplayDevice.h>
#include <Core/Memory/Allocator.h> #include <Core/Memory/Allocator.h>
#include <Core/Memory/MemoryArena.h> #include <Core/Memory/MemoryArena.h>
namespace Juliet namespace
{ {
namespace
{
DisplayDevice* g_CurrentDisplayDevice = nullptr; DisplayDevice* g_CurrentDisplayDevice = nullptr;
void DestroyPlatformWindow(index_t windowIndex); void DestroyPlatformWindow(index_t windowIndex);
} // namespace } // namespace
namespace Internal::Display namespace Internal::Display
{ {
// TODO : IfDef new factories that are not compatible // TODO : IfDef new factories that are not compatible
constexpr DisplayDeviceFactory* Factories[] = { &Win32DisplayDeviceFactory, nullptr }; constexpr DisplayDeviceFactory* Factories[] = { &Win32DisplayDeviceFactory, nullptr };
} // namespace Internal::Display } // namespace Internal::Display
void InitializeDisplaySystem() void InitializeDisplaySystem()
{ {
Assert(!g_CurrentDisplayDevice); Assert(!g_CurrentDisplayDevice);
Arena* arena = ArenaAllocate({ .Name = "Display System" }); Arena* arena = ArenaAllocate({ .Name = "Display System" });
@@ -51,10 +49,10 @@ namespace Juliet
{ {
ShutdownDisplaySystem(); ShutdownDisplaySystem();
} }
} }
void ShutdownDisplaySystem() void ShutdownDisplaySystem()
{ {
if (!g_CurrentDisplayDevice) if (!g_CurrentDisplayDevice)
{ {
return; return;
@@ -73,10 +71,10 @@ namespace Juliet
ArenaRelease(g_CurrentDisplayDevice->Arena); ArenaRelease(g_CurrentDisplayDevice->Arena);
g_CurrentDisplayDevice = nullptr; g_CurrentDisplayDevice = nullptr;
} }
Window* CreatePlatformWindow(const char* title, uint16 width, uint16 height, int /*flags*/ /* = 0 unused */) Window* CreatePlatformWindow(const char* title, uint16 width, uint16 height, int /*flags*/ /* = 0 unused */)
{ {
Assert(g_CurrentDisplayDevice->CreatePlatformWindow); Assert(g_CurrentDisplayDevice->CreatePlatformWindow);
Window window = {}; Window window = {};
@@ -99,10 +97,10 @@ namespace Juliet
g_CurrentDisplayDevice->ShowWindow(g_CurrentDisplayDevice, pWindow); g_CurrentDisplayDevice->ShowWindow(g_CurrentDisplayDevice, pWindow);
return pWindow; return pWindow;
} }
namespace namespace
{ {
void DestroyPlatformWindow(index_t windowIndex) void DestroyPlatformWindow(index_t windowIndex)
{ {
VectorArena<Window>& windows = g_CurrentDisplayDevice->Windows; VectorArena<Window>& windows = g_CurrentDisplayDevice->Windows;
@@ -117,10 +115,10 @@ namespace Juliet
windows.RemoveAtFast(windowIndex); windows.RemoveAtFast(windowIndex);
} }
} // namespace } // namespace
void DestroyPlatformWindow(NonNullPtr<Window> window) void DestroyPlatformWindow(NonNullPtr<Window> window)
{ {
// Find and destroy // Find and destroy
VectorArena<Window>& windows = g_CurrentDisplayDevice->Windows; VectorArena<Window>& windows = g_CurrentDisplayDevice->Windows;
for (index_t idx = windows.Size(); idx-- > 0;) for (index_t idx = windows.Size(); idx-- > 0;)
@@ -132,31 +130,30 @@ namespace Juliet
break; break;
} }
} }
} }
void ShowWindow(NonNullPtr<Window> window) void ShowWindow(NonNullPtr<Window> window)
{ {
g_CurrentDisplayDevice->ShowWindow(g_CurrentDisplayDevice, window); g_CurrentDisplayDevice->ShowWindow(g_CurrentDisplayDevice, window);
} }
void HideWindow(NonNullPtr<Window> window) void HideWindow(NonNullPtr<Window> window)
{ {
g_CurrentDisplayDevice->HideWindow(g_CurrentDisplayDevice, window); g_CurrentDisplayDevice->HideWindow(g_CurrentDisplayDevice, window);
} }
WindowID GetWindowID(NonNullPtr<Window> window) WindowID GetWindowID(NonNullPtr<Window> window)
{ {
return window->ID; return window->ID;
} }
void SetWindowTitle(NonNullPtr<Window> window, String title) void SetWindowTitle(NonNullPtr<Window> window, String title)
{ {
g_CurrentDisplayDevice->SetWindowTitle(g_CurrentDisplayDevice, window, title); g_CurrentDisplayDevice->SetWindowTitle(g_CurrentDisplayDevice, window, title);
} }
// Display Device Utils. Not exposed in the API // Display Device Utils. Not exposed in the API
DisplayDevice* GetDisplayDevice() DisplayDevice* GetDisplayDevice()
{ {
return g_CurrentDisplayDevice; return g_CurrentDisplayDevice;
} }
} // namespace Juliet
+13 -16
View File
@@ -1,16 +1,14 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
#include <Core/Container/Vector.h> #include <Core/Container/Vector.h>
#include <Core/HAL/Display/Window.h> #include <Core/HAL/Display/Window.h>
namespace Juliet // Driver to the display device.
// Functions ptr will be set by the chosen factory
// Acts as a singleton after Initialize has been called and is freed in Shutdown.
struct DisplayDevice
{ {
// Driver to the display device.
// Functions ptr will be set by the chosen factory
// Acts as a singleton after Initialize has been called and is freed in Shutdown.
struct DisplayDevice
{
Arena* Arena; Arena* Arena;
const char* Name = "Unknown"; const char* Name = "Unknown";
@@ -31,17 +29,16 @@ namespace Juliet
void (*PumpEvents)(NonNullPtr<DisplayDevice> self); void (*PumpEvents)(NonNullPtr<DisplayDevice> self);
VectorArena<Window> Windows; VectorArena<Window> Windows;
}; };
struct DisplayDeviceFactory struct DisplayDeviceFactory
{ {
const char* Name = "Unknown"; const char* Name = "Unknown";
DisplayDevice* (*CreateDevice)(Arena* arena); DisplayDevice* (*CreateDevice)(Arena* arena);
}; };
// TODO : Support more platforms // TODO : Support more platforms
extern DisplayDeviceFactory Win32DisplayDeviceFactory; extern DisplayDeviceFactory Win32DisplayDeviceFactory;
// Utils // Utils
extern DisplayDevice* GetDisplayDevice(); extern DisplayDevice* GetDisplayDevice();
} // namespace Juliet
+3 -6
View File
@@ -1,7 +1,4 @@
#pragma once #pragma once
namespace Juliet void InitializeDisplaySystem();
{ void ShutdownDisplaySystem();
void InitializeDisplaySystem();
void ShutdownDisplaySystem();
} // namespace Juliet
@@ -1,8 +1,8 @@
#include <Core/HAL/Display/DisplayDevice.h> #include <Core/HAL/Display/DisplayDevice.h>
#include <Core/HAL/Display/Win32/Win32DisplayEvent.h> #include <Core/HAL/Display/Win32/Win32DisplayEvent.h>
#include <Core/HAL/Display/Win32/Win32Window.h> #include <Core/HAL/Display/Win32/Win32Window.h>
namespace Juliet::Win32 namespace Win32
{ {
namespace namespace
{ {
@@ -43,10 +43,7 @@ namespace Juliet::Win32
} }
} // namespace } // namespace
} // namespace Juliet::Win32 } // namespace Win32
// Factory cannot be in an anonymous/unknown namespace // Factory cannot be in an anonymous/unknown namespace
namespace Juliet DisplayDeviceFactory Win32DisplayDeviceFactory = { .Name = "Win32", .CreateDevice = Win32::CreateDevice };
{
DisplayDeviceFactory Win32DisplayDeviceFactory = { .Name = "Win32", .CreateDevice = Win32::CreateDevice };
}
@@ -1,4 +1,4 @@
#include <Core/Common/EnumUtils.h> #include <Core/Common/EnumUtils.h>
#include <Core/HAL/Display/DisplayDevice.h> #include <Core/HAL/Display/DisplayDevice.h>
#include <Core/HAL/Display/Win32/Win32DisplayEvent.h> #include <Core/HAL/Display/Win32/Win32DisplayEvent.h>
#include <Core/HAL/Display/Win32/Win32Window.h> #include <Core/HAL/Display/Win32/Win32Window.h>
@@ -20,7 +20,7 @@
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
#endif #endif
namespace Juliet::Win32 namespace Win32
{ {
namespace namespace
{ {
@@ -276,4 +276,4 @@ namespace Juliet::Win32
return CallWindowProcA(DefWindowProcA, handle, message, wParam, lParam); return CallWindowProcA(DefWindowProcA, handle, message, wParam, lParam);
} }
} // namespace Juliet::Win32 } // namespace Win32
@@ -1,15 +1,12 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
#include <Core/HAL/Win32.h> #include <Core/HAL/Win32.h>
namespace Juliet struct DisplayDevice;
{
struct DisplayDevice;
}
namespace Juliet::Win32 namespace Win32
{ {
extern void PumpEvents(NonNullPtr<DisplayDevice> self); extern void PumpEvents(NonNullPtr<DisplayDevice> self);
extern LRESULT CALLBACK Win32MainWindowCallback(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam); extern LRESULT CALLBACK Win32MainWindowCallback(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam);
} // namespace Juliet::Win32 } // namespace Win32
@@ -1,10 +1,10 @@
#include <Core/HAL/Display/Win32/Win32DisplayEvent.h> #include <Core/HAL/Display/Win32/Win32DisplayEvent.h>
#include <Core/HAL/Display/Win32/Win32Window.h> #include <Core/HAL/Display/Win32/Win32Window.h>
#include <Core/HAL/Display/Window.h> #include <Core/HAL/Display/Window.h>
#include <Core/Memory/Allocator.h> #include <Core/Memory/Allocator.h>
#include <Core/Memory/MemoryArena.h> #include <Core/Memory/MemoryArena.h>
namespace Juliet::Win32 namespace Win32
{ {
namespace namespace
{ {
@@ -101,4 +101,4 @@ namespace Juliet::Win32
auto& win32State = static_cast<Window32State&>(*window->State); auto& win32State = static_cast<Window32State&>(*window->State);
SetWindowTextA(win32State.Handle, CStr(title)); SetWindowTextA(win32State.Handle, CStr(title));
} }
} // namespace Juliet::Win32 } // namespace Win32
@@ -1,16 +1,13 @@
#pragma once #pragma once
#include <Core/Common/NonNullPtr.h> #include <Core/Common/NonNullPtr.h>
#include <Core/HAL/Display/Window.h> #include <Core/HAL/Display/Window.h>
#include <Core/HAL/Win32.h> #include <Core/HAL/Win32.h>
namespace Juliet struct DisplayDevice;
{ struct Window;
struct DisplayDevice;
struct Window;
} // namespace Juliet
namespace Juliet::Win32 namespace Win32
{ {
// TODO : Evaluate if its worth the burden of casting to Window32State all the time // TODO : Evaluate if its worth the burden of casting to Window32State all the time
struct Window32State : WindowState struct Window32State : WindowState
@@ -26,4 +23,4 @@ namespace Juliet::Win32
extern void ShowWindow(NonNullPtr<DisplayDevice> self, NonNullPtr<Window> window); extern void ShowWindow(NonNullPtr<DisplayDevice> self, NonNullPtr<Window> window);
extern void HideWindow(NonNullPtr<DisplayDevice> self, NonNullPtr<Window> window); extern void HideWindow(NonNullPtr<DisplayDevice> self, NonNullPtr<Window> window);
extern void SetWindowTitle(NonNullPtr<DisplayDevice> self, NonNullPtr<Window> window, String title); extern void SetWindowTitle(NonNullPtr<DisplayDevice> self, NonNullPtr<Window> window, String title);
} // namespace Juliet::Win32 } // namespace Win32
+7 -10
View File
@@ -1,18 +1,16 @@
#pragma once #pragma once
#include <Core/Common/String.h> #include <Core/Common/String.h>
#include <Core/HAL/Display/Display.h> #include <Core/HAL/Display/Display.h>
namespace Juliet struct Window;
struct WindowState
{ {
struct Window;
struct WindowState
{
Window* Window; Window* Window;
}; };
struct Window struct Window
{ {
WindowID ID; WindowID ID;
WindowState* State; WindowState* State;
Arena* Arena; Arena* Arena;
@@ -20,5 +18,4 @@ namespace Juliet
int32 Width; int32 Width;
int32 Height; int32 Height;
String Title; String Title;
}; };
} // namespace Juliet
@@ -1,12 +1,10 @@
#include <Core/HAL/DynLib/DynamicLibrary.h> #include <Core/HAL/DynLib/DynamicLibrary.h>
#include <Core/HAL/Win32.h> #include <Core/HAL/Win32.h>
#include <Core/Logging/LogManager.h> #include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h> #include <Core/Logging/LogTypes.h>
namespace Juliet DynamicLibrary* LoadDynamicLibrary(const char* filename)
{ {
DynamicLibrary* LoadDynamicLibrary(const char* filename)
{
if (!filename) if (!filename)
{ {
Log(LogLevel::Error, LogCategory::Core, "Library filename is invalid (empty)"); Log(LogLevel::Error, LogCategory::Core, "Library filename is invalid (empty)");
@@ -22,10 +20,10 @@ namespace Juliet
return nullptr; return nullptr;
} }
return reinterpret_cast<DynamicLibrary*>(handle); return reinterpret_cast<DynamicLibrary*>(handle);
} }
FunctionPtr LoadFunction(NonNullPtr<DynamicLibrary> lib, const char* functionName) FunctionPtr LoadFunction(NonNullPtr<DynamicLibrary> lib, const char* functionName)
{ {
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4191) // Disable "unsafe conversion from FARPROC" #pragma warning(disable: 4191) // Disable "unsafe conversion from FARPROC"
auto function = reinterpret_cast<FunctionPtr>(GetProcAddress(reinterpret_cast<HMODULE>(lib.Get()), functionName)); auto function = reinterpret_cast<FunctionPtr>(GetProcAddress(reinterpret_cast<HMODULE>(lib.Get()), functionName));
@@ -35,10 +33,9 @@ namespace Juliet
} }
return function; return function;
#pragma warning(pop) #pragma warning(pop)
} }
void UnloadDynamicLibrary(NonNullPtr<DynamicLibrary> lib) void UnloadDynamicLibrary(NonNullPtr<DynamicLibrary> lib)
{ {
FreeLibrary(reinterpret_cast<HMODULE>(lib.Get())); FreeLibrary(reinterpret_cast<HMODULE>(lib.Get()));
} }
} // namespace Juliet
+28 -31
View File
@@ -1,14 +1,12 @@
#include <Core/Common/EnumUtils.h> #include <Core/Common/EnumUtils.h>
#include <Core/HAL/Event/Keyboard_Private.h> #include <Core/HAL/Event/Keyboard_Private.h>
#include <Core/HAL/Event/KeyboardMapping.h> #include <Core/HAL/Event/KeyboardMapping.h>
#include <Core/HAL/Event/SystemEvent.h> #include <Core/HAL/Event/SystemEvent.h>
namespace Juliet constexpr KeyboardID kGlobalKeyboardID = 0;
{
constexpr KeyboardID kGlobalKeyboardID = 0;
namespace namespace
{ {
struct KeyboardState struct KeyboardState
{ {
KeyState KeyState[ToUnderlying(ScanCode::Count)]; KeyState KeyState[ToUnderlying(ScanCode::Count)];
@@ -106,15 +104,15 @@ namespace Juliet
return evtPosted; return evtPosted;
} }
} // namespace } // namespace
bool SendKeyboardKey(uint64 timestamp, KeyboardID ID, Key key, KeyPosition keyPosition) bool SendKeyboardKey(uint64 timestamp, KeyboardID ID, Key key, KeyPosition keyPosition)
{ {
return SendKeyboardKey_Internal(timestamp, ID, key, keyPosition); return SendKeyboardKey_Internal(timestamp, ID, key, keyPosition);
} }
void UpdateKeyboardstate(float deltaTime) void UpdateKeyboardstate(float deltaTime)
{ {
for (KeyState& state : KeyboardState.KeyState) for (KeyState& state : KeyboardState.KeyState)
{ {
if (state.Position == KeyPosition::Down) if (state.Position == KeyPosition::Down)
@@ -133,33 +131,32 @@ namespace Juliet
state.Time = -1.0f; state.Time = -1.0f;
} }
} }
} }
bool IsKeyDown(ScanCode scanCode) bool IsKeyDown(ScanCode scanCode)
{ {
return KeyboardState.KeyState[ToUnderlying(scanCode)].Position == KeyPosition::Down; return KeyboardState.KeyState[ToUnderlying(scanCode)].Position == KeyPosition::Down;
} }
bool IsKeyPressed(ScanCode scanCode) bool IsKeyPressed(ScanCode scanCode)
{ {
auto& keyState = KeyboardState.KeyState[ToUnderlying(scanCode)]; auto& keyState = KeyboardState.KeyState[ToUnderlying(scanCode)];
return keyState.Position == KeyPosition::Down && keyState.Time == 0.0f; return keyState.Position == KeyPosition::Down && keyState.Time == 0.0f;
} }
KeyMod GetKeyModState() KeyMod GetKeyModState()
{ {
auto& keyboardState = KeyboardState; auto& keyboardState = KeyboardState;
return keyboardState.KeyModState; return keyboardState.KeyModState;
} }
KeyCode GetKeyCodeFromScanCode(ScanCode scanCode, KeyMod keyModState) KeyCode GetKeyCodeFromScanCode(ScanCode scanCode, KeyMod keyModState)
{ {
return GetKeyCodeFromDefaultMapping(scanCode, keyModState); return GetKeyCodeFromDefaultMapping(scanCode, keyModState);
} }
static_assert(sizeof(KeyPosition) == sizeof(bool)); static_assert(sizeof(KeyPosition) == sizeof(bool));
static_assert(ToUnderlying(KeyPosition::Down) == true); static_assert(ToUnderlying(KeyPosition::Down) == true);
static_assert(ToUnderlying(KeyPosition::Up) == false); static_assert(ToUnderlying(KeyPosition::Up) == false);
static_assert(sizeof(ScanCode) == sizeof(uint16)); static_assert(sizeof(ScanCode) == sizeof(uint16));
static_assert(ToUnderlying(ScanCode::Count) == 512); static_assert(ToUnderlying(ScanCode::Count) == 512);
} // namespace Juliet
@@ -1,13 +1,11 @@
#include <Core/Common/CoreUtils.h> #include <Core/Common/CoreUtils.h>
#include <Core/Common/EnumUtils.h> #include <Core/Common/EnumUtils.h>
#include <Core/HAL/Event/KeyboardMapping.h> #include <Core/HAL/Event/KeyboardMapping.h>
#include <Core/HAL/Keyboard/KeyCode.h> #include <Core/HAL/Keyboard/KeyCode.h>
#include <Core/HAL/Keyboard/ScanCode.h> #include <Core/HAL/Keyboard/ScanCode.h>
namespace Juliet namespace
{ {
namespace
{
// clang-format off // clang-format off
KeyCode UnshiftedDefaultSymbols[] = { KeyCode UnshiftedDefaultSymbols[] = {
KeyCode::Num1, KeyCode::Num1,
@@ -154,10 +152,10 @@ namespace Juliet
default: return KeyCode::Unknown; default: return KeyCode::Unknown;
} }
} }
} // namespace } // namespace
KeyCode GetKeyCodeFromDefaultMapping(ScanCode scanCode, KeyMod keyModState) KeyCode GetKeyCodeFromDefaultMapping(ScanCode scanCode, KeyMod keyModState)
{ {
if (scanCode <= ScanCode::Unknown || scanCode > ScanCode::Count) if (scanCode <= ScanCode::Unknown || scanCode > ScanCode::Count)
{ {
Assert(false , "Unsupported KeyCode (out of bounds)"); Assert(false , "Unsupported KeyCode (out of bounds)");
@@ -200,5 +198,4 @@ namespace Juliet
// Handle everything else (characters that do not convert to ASCII code) // Handle everything else (characters that do not convert to ASCII code)
return GetNonPrintableKeys(scanCode); return GetNonPrintableKeys(scanCode);
} }
} // namespace Juliet
+3 -6
View File
@@ -1,10 +1,7 @@
#pragma once #pragma once
#include <Core/HAL/Keyboard/KeyCode.h> #include <Core/HAL/Keyboard/KeyCode.h>
#include <Core/HAL/Keyboard/ScanCode.h> #include <Core/HAL/Keyboard/ScanCode.h>
namespace Juliet // Transforms ScanCode into KeyCode using the default US ASCII Mapping
{ extern KeyCode GetKeyCodeFromDefaultMapping(ScanCode scanCode, KeyMod keyModState);
// Transforms ScanCode into KeyCode using the default US ASCII Mapping
extern KeyCode GetKeyCodeFromDefaultMapping(ScanCode scanCode, KeyMod keyModState);
} // namespace Juliet
+4 -7
View File
@@ -1,12 +1,9 @@
#pragma once #pragma once
#include <Core/HAL/Keyboard/Keyboard.h> #include <Core/HAL/Keyboard/Keyboard.h>
#include <Core/HAL/Keyboard/KeyCode.h> #include <Core/HAL/Keyboard/KeyCode.h>
namespace Juliet extern bool SendKeyboardKey(uint64 timestamp, KeyboardID ID, Key key, KeyPosition keyPosition);
{ extern void UpdateKeyboardstate(float deltaTime);
extern bool SendKeyboardKey(uint64 timestamp, KeyboardID ID, Key key, KeyPosition keyPosition);
extern void UpdateKeyboardstate(float deltaTime);
extern const KeyboardID kGlobalKeyboardID; extern const KeyboardID kGlobalKeyboardID;
} // namespace Juliet
+28 -31
View File
@@ -1,13 +1,11 @@
#include <Core/Common/EnumUtils.h> #include <Core/Common/EnumUtils.h>
#include <Core/HAL/Display/Window.h> #include <Core/HAL/Display/Window.h>
#include <Core/HAL/Event/Mouse_Private.h> #include <Core/HAL/Event/Mouse_Private.h>
#include <Core/HAL/Event/SystemEvent.h> #include <Core/HAL/Event/SystemEvent.h>
#include <Core/HAL/Mouse/Mouse.h> #include <Core/HAL/Mouse/Mouse.h>
namespace Juliet namespace
{ {
namespace
{
Mouse MouseState; Mouse MouseState;
void ConstraintMousePositionToWindow(Mouse& mouseState, Window* window, float& x, float& y) void ConstraintMousePositionToWindow(Mouse& mouseState, Window* window, float& x, float& y)
@@ -71,24 +69,24 @@ namespace Juliet
AddEvent(evt); AddEvent(evt);
} }
} // namespace } // namespace
constexpr MouseID kGlobalMouseID = 0; constexpr MouseID kGlobalMouseID = 0;
Mouse& GetMouseState() Mouse& GetMouseState()
{ {
return MouseState; return MouseState;
} }
void SendMouseMotion(uint64 timestamp, NonNullPtr<Window> window, MouseID ID, float x, float y) void SendMouseMotion(uint64 timestamp, NonNullPtr<Window> window, MouseID ID, float x, float y)
{ {
// TODO : Update Mouse focus and send Mouse Enter / Mouse Leave event // TODO : Update Mouse focus and send Mouse Enter / Mouse Leave event
SendMouseMotion_Internal(timestamp, window, ID, x, y); SendMouseMotion_Internal(timestamp, window, ID, x, y);
} }
void SendMouseButton(uint64 timestamp, NonNullPtr<Window> window, MouseID mouseID, MouseButton button, bool pressed) void SendMouseButton(uint64 timestamp, NonNullPtr<Window> window, MouseID mouseID, MouseButton button, bool pressed)
{ {
Mouse& mouseState = GetMouseState(); Mouse& mouseState = GetMouseState();
MouseButton flags = mouseState.ButtonState; MouseButton flags = mouseState.ButtonState;
@@ -122,37 +120,36 @@ namespace Juliet
evt.Data.MouseButton.Y = mouseState.Y; evt.Data.MouseButton.Y = mouseState.Y;
evt.Data.MouseButton.IsPressed = pressed; evt.Data.MouseButton.IsPressed = pressed;
AddEvent(evt); AddEvent(evt);
} }
bool IsMouseButtonDown(MouseButton button) bool IsMouseButtonDown(MouseButton button)
{ {
auto& mouseState = GetMouseState(); auto& mouseState = GetMouseState();
return (mouseState.ButtonState & button) != MouseButton::None; return (mouseState.ButtonState & button) != MouseButton::None;
} }
MousePosition GetMousePosition() MousePosition GetMousePosition()
{ {
auto& mouseState = GetMouseState(); auto& mouseState = GetMouseState();
return { .X = mouseState.X, .Y = mouseState.Y }; return { .X = mouseState.X, .Y = mouseState.Y };
} }
MousePosition GetMouseDelta() MousePosition GetMouseDelta()
{ {
auto& mouseState = GetMouseState(); auto& mouseState = GetMouseState();
return { .X = mouseState.DeltaX, .Y = mouseState.DeltaY }; return { .X = mouseState.DeltaX, .Y = mouseState.DeltaY };
} }
MouseButton GetMouseButtonState() MouseButton GetMouseButtonState()
{ {
const auto& mouseState = GetMouseState(); const auto& mouseState = GetMouseState();
return mouseState.ButtonState; return mouseState.ButtonState;
} }
void UpdateMouseState() void UpdateMouseState()
{ {
auto& mouseState = GetMouseState(); auto& mouseState = GetMouseState();
mouseState.DeltaX = 0.0f; mouseState.DeltaX = 0.0f;
mouseState.DeltaY = 0.0f; mouseState.DeltaY = 0.0f;
} }
} // namespace Juliet
+10 -13
View File
@@ -1,13 +1,11 @@
#pragma once #pragma once
#include <Core/HAL/Mouse/Mouse.h> #include <Core/HAL/Mouse/Mouse.h>
namespace Juliet struct Window;
{
struct Window;
struct Mouse struct Mouse
{ {
float X; float X;
float Y; float Y;
@@ -20,13 +18,12 @@ namespace Juliet
MouseButton ButtonState; MouseButton ButtonState;
bool HasPosition : 1; bool HasPosition : 1;
}; };
Mouse& GetMouseState(); Mouse& GetMouseState();
extern void UpdateMouseState(); extern void UpdateMouseState();
extern void SendMouseMotion(uint64 timestamp, NonNullPtr<Window> window, MouseID ID, float x, float y); extern void SendMouseMotion(uint64 timestamp, NonNullPtr<Window> window, MouseID ID, float x, float y);
extern void SendMouseButton(uint64 timestamp, NonNullPtr<Window> window, MouseID mouseID, MouseButton button, bool pressed); extern void SendMouseButton(uint64 timestamp, NonNullPtr<Window> window, MouseID mouseID, MouseButton button, bool pressed);
extern const MouseID kGlobalMouseID; extern const MouseID kGlobalMouseID;
} // namespace Juliet
+15 -18
View File
@@ -1,4 +1,4 @@
#include <Core/HAL/Display/DisplayDevice.h> #include <Core/HAL/Display/DisplayDevice.h>
#include <Core/HAL/Event/SystemEvent.h> #include <Core/HAL/Event/SystemEvent.h>
#include <Core/HAL/Event/Keyboard_Private.h> #include <Core/HAL/Event/Keyboard_Private.h>
@@ -9,10 +9,8 @@
#pragma pop_macro("global") #pragma pop_macro("global")
namespace Juliet namespace
{ {
namespace
{
// TODO : make my own queue / using vector // TODO : make my own queue / using vector
std::queue<SystemEvent> eventQueue; std::queue<SystemEvent> eventQueue;
@@ -34,15 +32,15 @@ namespace Juliet
return true; return true;
} }
} // namespace } // namespace
bool GetEvent(SystemEvent& event) bool GetEvent(SystemEvent& event)
{ {
return WaitEvent(event, 0); return WaitEvent(event, 0);
} }
bool WaitEvent(SystemEvent& event, int32 timeoutInNS /* = -1 */) bool WaitEvent(SystemEvent& event, int32 timeoutInNS /* = -1 */)
{ {
using namespace std::chrono; using namespace std::chrono;
// Handle the "Infinite Wait" and "Timed Wait" logic // Handle the "Infinite Wait" and "Timed Wait" logic
@@ -79,22 +77,21 @@ namespace Juliet
} }
return false; return false;
} }
bool AddEvent(SystemEvent& event) bool AddEvent(SystemEvent& event)
{ {
if (event.Timestamp == 0) if (event.Timestamp == 0)
{ {
event.Timestamp = 1; // TODO : Clock::Now(); event.Timestamp = 1; // TODO : Clock::Now();
} }
return AddEvent_Internal(event); return AddEvent_Internal(event);
} }
void Events_NewFrame(float deltaTime) void Events_NewFrame(float deltaTime)
{ {
UpdateKeyboardstate(deltaTime); UpdateKeyboardstate(deltaTime);
UpdateMouseState(); UpdateMouseState();
} }
} // namespace Juliet
+3 -3
View File
@@ -1,8 +1,8 @@
#pragma once #pragma once
#include <Core/HAL/Keyboard/ScanCode.h> #include <Core/HAL/Keyboard/ScanCode.h>
namespace Juliet::Win32 namespace Win32
{ {
// Conversion table from Win32 scan code to HID Usage Page (see Keyboard.h) // Conversion table from Win32 scan code to HID Usage Page (see Keyboard.h)
// https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#extended-key-flag // https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input#extended-key-flag
@@ -267,4 +267,4 @@ namespace Juliet::Win32
}; };
// clang-format on // clang-format on
} // namespace Juliet::Win32 } // namespace Win32
+3 -6
View File
@@ -1,11 +1,9 @@
#include <Core/HAL/Display/Window.h> #include <Core/HAL/Display/Window.h>
#include <Core/HAL/Event/SystemEvent.h> #include <Core/HAL/Event/SystemEvent.h>
#include <Core/HAL/Event/WindowEvent.h> #include <Core/HAL/Event/WindowEvent.h>
namespace Juliet bool SendWindowEvent(Window* window, EventType type)
{ {
bool SendWindowEvent(Window* window, EventType type)
{
Assert(window); Assert(window);
SystemEvent evt; SystemEvent evt;
@@ -16,6 +14,5 @@ namespace Juliet
bool evtPosted = AddEvent(evt); bool evtPosted = AddEvent(evt);
return evtPosted; return evtPosted;
} }
} // namespace Juliet
+4 -7
View File
@@ -1,9 +1,6 @@
#pragma once #pragma once
namespace Juliet struct Window;
{ enum class EventType : uint32;
struct Window;
enum class EventType : uint32;
extern bool SendWindowEvent(Window* window, EventType type); extern bool SendWindowEvent(Window* window, EventType type);
} // namespace Juliet
+21 -24
View File
@@ -1,4 +1,4 @@
#include <Core/Common/CoreTypes.h> #include <Core/Common/CoreTypes.h>
#include <Core/Common/CoreUtils.h> #include <Core/Common/CoreUtils.h>
#include <Core/Common/String.h> #include <Core/Common/String.h>
#include <Core/HAL/Filesystem/Filesystem.h> #include <Core/HAL/Filesystem/Filesystem.h>
@@ -9,10 +9,8 @@
#include <Core/Logging/LogTypes.h> #include <Core/Logging/LogTypes.h>
#include <Core/Memory/Allocator.h> #include <Core/Memory/Allocator.h>
namespace Juliet namespace
{ {
namespace
{
String CachedBasePath = {}; String CachedBasePath = {};
String CachedAssetBasePath = {}; String CachedAssetBasePath = {};
@@ -22,22 +20,22 @@ namespace Juliet
DWORD attributes = GetFileAttributesA(path); DWORD attributes = GetFileAttributesA(path);
return (attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY); return (attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY);
} }
} // namespace } // namespace
String GetBasePath() String GetBasePath()
{ {
Assert(IsValid(CachedBasePath)); Assert(IsValid(CachedBasePath));
return CachedBasePath; return CachedBasePath;
} }
String GetAssetBasePath() String GetAssetBasePath()
{ {
Assert(IsValid(CachedAssetBasePath)); Assert(IsValid(CachedAssetBasePath));
return CachedAssetBasePath; return CachedAssetBasePath;
} }
[[nodiscard]] String GetAssetPath(NonNullPtr<Arena> arena, String filename) [[nodiscard]] String GetAssetPath(NonNullPtr<Arena> arena, String filename)
{ {
Assert(IsValid(CachedAssetBasePath)); Assert(IsValid(CachedAssetBasePath));
Assert(IsValid(filename)); Assert(IsValid(filename));
@@ -47,19 +45,19 @@ namespace Juliet
juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename)); juliet_snprintf(buffer, totalSize, "%s%s", CStr(CachedAssetBasePath), CStr(filename));
return { buffer, totalSize - 1 }; return { buffer, totalSize - 1 };
} }
bool IsAbsolutePath(String path) bool IsAbsolutePath(String path)
{ {
if (!IsValid(path)) if (!IsValid(path))
{ {
return false; return false;
} }
return Platform::IsAbsolutePath(path); return Platform::IsAbsolutePath(path);
} }
void InitFilesystem(NonNullPtr<Arena> arena) void InitFilesystem(NonNullPtr<Arena> arena)
{ {
CachedBasePath = Platform::GetBasePath(arena); CachedBasePath = Platform::GetBasePath(arena);
String basePath = GetBasePath(); String basePath = GetBasePath();
@@ -89,13 +87,12 @@ namespace Juliet
} }
Log(LogLevel::Error, LogCategory::Core, "Filesystem: Could not find Assets/compiled/ directory!"); Log(LogLevel::Error, LogCategory::Core, "Filesystem: Could not find Assets/compiled/ directory!");
} }
void ShutdownFilesystem() void ShutdownFilesystem()
{ {
CachedBasePath.Size = 0; CachedBasePath.Size = 0;
CachedBasePath.Str = nullptr; CachedBasePath.Str = nullptr;
CachedAssetBasePath.Size = 0; CachedAssetBasePath.Size = 0;
CachedAssetBasePath.Str = nullptr; CachedAssetBasePath.Str = nullptr;
} }
} // namespace Juliet
@@ -1,7 +1,7 @@
#pragma once #pragma once
namespace Juliet::Platform namespace Platform
{ {
extern String GetBasePath(NonNullPtr<Arena> arena); extern String GetBasePath(NonNullPtr<Arena> arena);
extern bool IsAbsolutePath(String path); extern bool IsAbsolutePath(String path);
} // namespace Juliet::Platform } // namespace Platform
@@ -1,7 +1,4 @@
#pragma once #pragma once
namespace Juliet extern void InitFilesystem(NonNullPtr<Arena> arena);
{ extern void ShutdownFilesystem();
extern void InitFilesystem(NonNullPtr<Arena> arena);
extern void ShutdownFilesystem();
} // namespace Juliet
@@ -1,11 +1,11 @@
#include <Core/Common/String.h> #include <Core/Common/String.h>
#include <Core/HAL/Filesystem/Filesystem_Platform.h> #include <Core/HAL/Filesystem/Filesystem_Platform.h>
#include <Core/HAL/Win32.h> #include <Core/HAL/Win32.h>
#include <Core/Logging/LogManager.h> #include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h> #include <Core/Logging/LogTypes.h>
#include <Core/Memory/Allocator.h> #include <Core/Memory/Allocator.h>
namespace Juliet::Platform namespace Platform
{ {
String GetBasePath(NonNullPtr<Arena> arena) String GetBasePath(NonNullPtr<Arena> arena)
{ {
@@ -91,4 +91,4 @@ namespace Juliet::Platform
return false; return false;
} }
} // namespace Juliet::Platform } // namespace Platform

Some files were not shown because too many files have changed in this diff Show More