Skip to content

Commit

Permalink
C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
nepp95 committed Jan 4, 2025
1 parent 9190c8c commit 28831ee
Show file tree
Hide file tree
Showing 52 changed files with 390 additions and 299 deletions.
4 changes: 2 additions & 2 deletions EppoEditor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24)

project(EppoEditor VERSION 1.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Sources
Expand All @@ -27,4 +27,4 @@ target_link_libraries(${PROJECT_NAME} PRIVATE
${BULLET_COLLISION_LIBRARY} ${BULLET_DYNAMICS_LIBRARY} ${BULLET_MATH_LIBRARY} ${BULLET_SOFTBODY_LIBRARY}
${mono_LIBRARIES}
${Vulkan_LIBRARY} shaderc_combined spirv-cross-core spirv-cross-glsl
)
)
27 changes: 15 additions & 12 deletions EppoEditor/Source/EditorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,21 @@ namespace Eppo
static const std::string PROPERTY_PANEL = "PropertyPanel";
static const std::string SCENE_HIERARCHY_PANEL = "SceneHierarchyPanel";

static bool s_NewProjectPopup = false;
static bool s_PreferencesPopup = false;
namespace
{
bool s_NewProjectPopup = false;
bool s_PreferencesPopup = false;

void ReplaceToken(std::string& input, const char* token, const std::string& value)
{
size_t pos = 0;
while ((pos = input.find(token, pos)) != std::string::npos)
{
input.replace(pos, strlen(token), value);
pos += strlen(token);
}
}
}

EditorLayer::EditorLayer()
: Layer("EditorLayer"), m_PanelManager(PanelManager::Get())
Expand Down Expand Up @@ -337,16 +350,6 @@ namespace Eppo
m_ActiveScene = nullptr;
}

static void ReplaceToken(std::string& input, const char* token, const std::string& value)
{
size_t pos = 0;
while ((pos = input.find(token, pos)) != std::string::npos)
{
input.replace(pos, strlen(token), value);
pos += strlen(token);
}
}

void EditorLayer::NewProject(const std::string& name)
{
// Create project directory
Expand Down
2 changes: 1 addition & 1 deletion EppoEditor/Source/Panel/ContentBrowserPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Eppo

ImGui::BeginGroup();

constexpr char* items[] = { "Meshes", "Scenes", "Scripts", "Textures" };
const char* items[] = { "Meshes", "Scenes", "Scripts", "Textures" };
static int currentItem = 0;
if (ImGui::BeginListBox("##Assets", ImVec2(100.0f, -FLT_MIN)))
{
Expand Down
4 changes: 2 additions & 2 deletions EppoEditor/Source/Panel/PanelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ namespace Eppo
return it->second.Panel; // TODO: Might not work? dynamic cast to derived class
}

bool HasPanel(const std::string& name)
bool HasPanel(const std::string& name) const
{
return m_PanelData.find(name) != m_PanelData.end();
return m_PanelData.contains(name);
}

static PanelManager& Get();
Expand Down
2 changes: 1 addition & 1 deletion EppoEditor/Source/ThumbnailCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Eppo

Ref<Image> ThumbnailCache::GetOrCreateThumbnail(const AssetType type)
{
if (m_AssetTypeThumbnails.find(type) == m_AssetTypeThumbnails.end())
if (!m_AssetTypeThumbnails.contains(type))
return m_AssetTypeThumbnails.at(AssetType::None);

return m_AssetTypeThumbnails.at(type);
Expand Down
2 changes: 1 addition & 1 deletion EppoEditor/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project "EppoEditor"
kind "ConsoleApp"
language "C++"
cppdialect "C++17"
cppdialect "C++20"
staticruntime "Off"

targetdir ("%{wks.location}/Bin/" .. OutputDir .. "/%{prj.name}")
Expand Down
2 changes: 1 addition & 1 deletion EppoEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.24)

project(EppoEng VERSION 1.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Sources
Expand Down
8 changes: 6 additions & 2 deletions EppoEngine/Source/Asset/AssetImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ namespace Eppo
EPPO_PROFILE_FUNCTION("AssetImporter::ImportScene");

Ref<Scene> scene = CreateRef<Scene>();
SceneSerializer serializer(scene);
serializer.Deserialize(Project::GetAssetFilepath(metadata.Filepath));

if (const SceneSerializer serializer(scene);
!serializer.Deserialize(Project::GetAssetFilepath(metadata.Filepath)))
{
EPPO_ERROR("Failed to import scene '{}'", metadata.Filepath);
}

return scene;
}
Expand Down
7 changes: 0 additions & 7 deletions EppoEngine/Source/Asset/AssetManager.cpp

This file was deleted.

38 changes: 19 additions & 19 deletions EppoEngine/Source/Asset/AssetManagerEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

namespace Eppo
{
static std::map<std::filesystem::path, AssetType> s_AssetExtensionMap =
namespace
{
{ ".epscene", AssetType::Scene },
{ ".glb", AssetType::Mesh },
{ ".gltf", AssetType::Mesh },
{ ".jpeg", AssetType::Texture },
{ ".jpg", AssetType::Texture },
{ ".png", AssetType::Texture },
};

namespace Utils
{
static AssetType GetAssetTypeFromFileExtension(const std::filesystem::path& extension)
std::map<std::filesystem::path, AssetType> s_AssetExtensionMap =
{
{ ".epscene", AssetType::Scene },
{ ".glb", AssetType::Mesh },
{ ".gltf", AssetType::Mesh },
{ ".jpeg", AssetType::Texture },
{ ".jpg", AssetType::Texture },
{ ".png", AssetType::Texture },
};

AssetType GetAssetTypeFromFileExtension(const std::filesystem::path& extension)
{
if (s_AssetExtensionMap.find(extension) == s_AssetExtensionMap.end())
{
Expand All @@ -31,7 +31,7 @@ namespace Eppo
return s_AssetExtensionMap.at(extension);
}

static std::filesystem::path CopyAssetToAssetsDirectory(const std::filesystem::path& filepath)
std::filesystem::path CopyAssetToAssetsDirectory(const std::filesystem::path& filepath)
{
const AssetType type = GetAssetTypeFromFileExtension(filepath.extension());
std::filesystem::path destPath;
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace Eppo
if (IsAssetLoaded(handle))
return false;

const AssetType type = Utils::GetAssetTypeFromFileExtension(filepath.extension());
const AssetType type = GetAssetTypeFromFileExtension(filepath.extension());
EPPO_ASSERT(type != AssetType::None)

AssetMetadata metadata;
Expand Down Expand Up @@ -151,12 +151,12 @@ namespace Eppo
std::filesystem::path baseCanonical = std::filesystem::canonical(Project::GetAssetsDirectory());
std::filesystem::path targetCanonical = std::filesystem::canonical(Project::GetAssetFilepath(filepath));

const AssetType type = Utils::GetAssetTypeFromFileExtension(filepath.extension());
const AssetType type = GetAssetTypeFromFileExtension(filepath.extension());
EPPO_ASSERT(type != AssetType::None)

std::filesystem::path newPath;
if (std::mismatch(baseCanonical.begin(), baseCanonical.end(), targetCanonical.begin()).first != baseCanonical.end())
newPath = Utils::CopyAssetToAssetsDirectory(targetCanonical);
newPath = CopyAssetToAssetsDirectory(targetCanonical);

AssetMetadata metadata;
metadata.Filepath = Project::GetAssetRelativeFilepath(newPath.empty() ? filepath : newPath);
Expand All @@ -175,16 +175,16 @@ namespace Eppo
return asset;
}

const AssetMetadata& AssetManagerEditor::GetMetadata(AssetHandle handle) const
const AssetMetadata& AssetManagerEditor::GetMetadata(const AssetHandle handle) const
{
auto it = m_AssetData.find(handle);
const auto it = m_AssetData.find(handle);
if (it == m_AssetData.end())
return s_NullMetadata;

return it->second;
}

const std::filesystem::path& AssetManagerEditor::GetFilepath(AssetHandle handle) const
const std::filesystem::path& AssetManagerEditor::GetFilepath(const AssetHandle handle) const
{
return GetMetadata(handle).Filepath;
}
Expand Down
2 changes: 1 addition & 1 deletion EppoEngine/Source/Core/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace Eppo
m_Buffer.SetData(value, offset);
}

void SetData(void* data, uint32_t size)
void SetData(void* data, const uint32_t size)
{
m_Buffer.SetData(data, size);
}
Expand Down
8 changes: 3 additions & 5 deletions EppoEngine/Source/Core/Entrypoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

#include "Core/Application.h"

using namespace Eppo;

int main(int argc, char** argv)
{
Log::Init();
Eppo::Log::Init();

const ApplicationCommandLineArgs args(argc, argv);
const Eppo::ApplicationCommandLineArgs args(argc, argv);

Application* app = CreateApplication(args);
Eppo::Application* app = CreateApplication(args);
app->Run();

delete app;
Expand Down
10 changes: 5 additions & 5 deletions EppoEngine/Source/Core/Filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace Eppo
return {};

Buffer buffer(static_cast<uint32_t>(fileSize));
stream.read(buffer.As<char>(), fileSize);
stream.read(buffer.As<char>(), static_cast<int32_t>(fileSize));
stream.close();

return buffer;
Expand All @@ -120,7 +120,7 @@ namespace Eppo
{
text.resize(size);
stream.seekg(0, std::ios::beg);
stream.read(text.data(), text.size());
stream.read(text.data(), static_cast<int32_t>(text.size()));
}

return text;
Expand Down Expand Up @@ -149,10 +149,10 @@ namespace Eppo
std::ofstream stream(filepath, std::ios::binary);
EPPO_ASSERT(stream)

stream.write((char*)buffer.data(), buffer.size() * sizeof(uint32_t));
stream.write((char*)buffer.data(), static_cast<int32_t>(buffer.size()) * sizeof(uint32_t));
}

void Filesystem::WriteText(const std::filesystem::path& filepath, const std::string& text, bool overwrite)
void Filesystem::WriteText(const std::filesystem::path& filepath, const std::string& text, const bool overwrite)
{
EPPO_PROFILE_FUNCTION("Filesystem::WriteText");

Expand All @@ -167,6 +167,6 @@ namespace Eppo

EPPO_ASSERT(stream)

stream.write(text.c_str(), text.size());
stream.write(text.c_str(), static_cast<int32_t>(text.size()));
}
}
6 changes: 3 additions & 3 deletions EppoEngine/Source/Core/Hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Eppo
{
namespace Utils
namespace
{
static void byteswap64(uint64_t value, void* ptr)
void byteswap64(uint64_t value, void* ptr)
{
value =
((value & 0xFF00000000000000u) >> 56u) |
Expand Down Expand Up @@ -50,7 +50,7 @@ namespace Eppo
}

// Reverse byte order
Utils::byteswap64(hash, &hash);
byteswap64(hash, &hash);

return hash;
}
Expand Down
9 changes: 6 additions & 3 deletions EppoEngine/Source/Core/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

namespace Eppo
{
static void GLFWErrorCallback(int error, const char* description)
namespace
{
EPPO_ERROR("GLFW Error: ({}) {}", error, description);
void GLFWErrorCallback(int error, const char* description)
{
EPPO_ERROR("GLFW Error: ({}) {}", error, description);
}
}

Window::Window(WindowSpecification specification)
Expand Down Expand Up @@ -148,7 +151,7 @@ namespace Eppo
glfwTerminate();
}

void Window::ProcessEvents() const
void Window::ProcessEvents()
{
glfwPollEvents();
}
Expand Down
2 changes: 1 addition & 1 deletion EppoEngine/Source/Core/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Eppo
void Init();
void Shutdown() const;

void ProcessEvents() const;
static void ProcessEvents();
void SetEventCallback(const EventCallbackFn& callback) { m_Callback = callback; }

void SetWindowTitle(const std::string& name) const;
Expand Down
4 changes: 2 additions & 2 deletions EppoEngine/Source/Event/ApplicationEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace Eppo
EVENT_CLASS_TYPE(WindowResize);
EVENT_CLASS_CATEGORY(EventCategoryApplication);

uint32_t GetWidth() const { return m_Width; }
uint32_t GetHeight() const { return m_Height; }
[[nodiscard]] uint32_t GetWidth() const { return m_Width; }
[[nodiscard]] uint32_t GetHeight() const { return m_Height; }

private:
uint32_t m_Width, m_Height;
Expand Down
2 changes: 1 addition & 1 deletion EppoEngine/Source/Event/KeyEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Eppo
public:
[[nodiscard]] KeyCode GetKeyCode() const { return m_KeyCode; }

EVENT_CLASS_CATEGORY(EventCategoryInput | EventCategoryKeyboard);
EVENT_CLASS_CATEGORY(EventCategoryInput | EventCategoryKeyboard)

protected:
explicit KeyEvent(const KeyCode keyCode)
Expand Down
5 changes: 4 additions & 1 deletion EppoEngine/Source/ImGui/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ namespace Eppo::UI
VkDescriptorSet DescriptorSet;
};

static std::unordered_map<void*, ImageInfo> s_ImageCache;
namespace
{
std::unordered_map<void*, ImageInfo> s_ImageCache;
}

void ClearResources()
{
Expand Down
Loading

0 comments on commit 28831ee

Please sign in to comment.