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

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