From 1cbba8dc35e42f4a8220832d247114b8bfba9ec7 Mon Sep 17 00:00:00 2001 From: Karutoh Date: Sat, 27 Jul 2024 10:18:00 -0700 Subject: [PATCH] First commit. --- .gitignore | 13 +++++++ CMakeLists.txt | 83 ++++++++++++++++++++++++++++++++++++++++++ MainLvl.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ MainLvl.h | 29 +++++++++++++++ Sprite.cpp | 5 +++ Sprite.h | 9 +++++ main.cpp | 51 ++++++++++++++++++++++++++ 7 files changed, 287 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 MainLvl.cpp create mode 100644 MainLvl.h create mode 100644 Sprite.cpp create mode 100644 Sprite.h create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebe792b --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.obj +*.cpp.obj +*.lib +*.exe +*.a +*.ninja_deps +*.ninja_log +*.ninja +*.cmake +*.log +/.idea/ +/cmake-build-release/ +/cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..44afd3b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,83 @@ +cmake_minimum_required(VERSION 3.18.4) +project(SpriteGen C CXX) + +if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") + set(IS_OS_WINDOWS TRUE) + set(USER_HOME_DIRECTORY $ENV{USERPROFILE}) + string(REPLACE "\\" "/" USER_HOME_DIRECTORY "${USER_HOME_DIRECTORY}") + message("Building for the Windows operating system.") +elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") + set(IS_OS_LINUX TRUE) + set(USER_HOME_DIRECTORY $ENV{HOME}) + add_compile_options(-Wno-stringop-overflow) + message("Building for the Linux operating system.") +elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin") + set(IS_OS_MAC TRUE) + set(USER_HOME_DIRECTORY $ENV{HOME}) + message("Building for the Mac operating system.") +endif () + +if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") + message("Building for AMD64 architecture.") + set(IS_ARCH_AMD64 TRUE) +elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ARM64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64") + message("Building for ARM64 architecture.") + set(IS_ARCH_ARM64 TRUE) +endif () + +message("Home Dir: ${USER_HOME_DIRECTORY}") + +set(CMAKE_CXX_STANDARD 20) + +add_executable(SpriteGen + main.cpp + MainLvl.h MainLvl.cpp + Sprite.cpp + Sprite.h +) + +find_package(Vulkan REQUIRED) +if (Vulkan_FOUND) + message(STATUS "Vulkan was found.") +else () + message(STATUS "Vulkan was not found.") +endif () + +find_package(ZLIB REQUIRED) +if (ZLIB_FOUND) + message(STATUS "ZLIB was found.") +else () + message(STATUS "ZLIB was not found.") +endif () + +find_package(OpenSSL REQUIRED) +if (OpenSSL_FOUND) + message(STATUS "OpenSSL was found.") +else () + message(STATUS "OpenSSL was not found.") +endif () + +if (IS_OS_WINDOWS) + add_compile_definitions(VK_USE_PLATFORM_WIN32_KHR) + + target_include_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/EHS/include") + target_include_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/EHE/include") + target_include_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/EHC/include") + target_include_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/LWE/include") + + target_link_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/EHS/lib") + target_link_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/EHE/lib") + target_link_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/EHC/lib") + target_link_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/LWE/lib") + + target_link_libraries(SpriteGen PRIVATE ws2_32 avrt) +elseif (IS_OS_LINUX) + add_compile_definitions(VK_USE_PLATFORM_WAYLAND_KHR EHS_WS_WAYLAND) + + target_link_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/.local/lib") + target_include_directories(SpriteGen PRIVATE "${USER_HOME_DIRECTORY}/.local/include") + + target_link_libraries(SpriteGen PRIVATE wayland-client xcb xcb-cursor xcb-xfixes xcb-xinput asound) +endif() + +target_link_libraries(SpriteGen PRIVATE Vulkan::Headers Vulkan::Vulkan OpenSSL::SSL OpenSSL::Crypto ZLIB::ZLIB LWE EHC EHE EHS_STC) \ No newline at end of file diff --git a/MainLvl.cpp b/MainLvl.cpp new file mode 100644 index 0000000..9a09aff --- /dev/null +++ b/MainLvl.cpp @@ -0,0 +1,97 @@ +#include "MainLvl.h" + +#include +#include +#include +#include +#include + +MainLvl::~MainLvl() +{ +} + +MainLvl::MainLvl() + : Level("Main") +{ +} + +MainLvl::MainLvl(MainLvl &&lvl) noexcept + : Level((Level &&) lvl) +{ +} + +MainLvl::MainLvl(const MainLvl &lvl) + : Level(lvl) +{ +} + +MainLvl &MainLvl::operator=(MainLvl &&lvl) noexcept +{ + if (this == &lvl) + return *this; + + Level::operator=((Level &&) lvl); + + return *this; +} + +MainLvl &MainLvl::operator=(const MainLvl &lvl) +{ + if (this == &lvl) + return *this; + + Level::operator=(lvl); + + return *this; +} + +void MainLvl::SetupResources(lwe::GpuInterface *inf) +{ + Level::SetupResources(inf); + + //Your resource setup code here. +} + +void MainLvl::Setup(lwe::GpuInterface *inf) +{ + Level::Setup(inf); + + //Your setup code here. + + lwe::GuiSystem *guiSys = new lwe::GuiSystem(); + AddSystem(guiSys); + + //Add Resources + lwe::GpuFontAtlas *arial_24 = new lwe::GpuFontAtlas("resources/fonts/Arial_24.ehf", inf); + guiSys->AddResource(arial_24); + + //Add Gui + lwe::LabelGui *dirLabel = new lwe::LabelGui("DirLabel", "Arial_24", "Directory:"); + guiSys->AddGui(dirLabel); + + lwe::TextFieldGui *dirField = new lwe::TextFieldGui("DirField", "Test"); + dirField->SetPosition({arial_24->CalculateWidth(dirLabel->GetText()), 0.0f, 0.0f}); + dirField->SetScale({200.0f, (float)arial_24->GetGlyphScale() + 10.0f}); + guiSys->AddGui(dirField); +} + +void MainLvl::PostInitialize(lwe::GpuCmdBuffer *cmdBuffer) +{ + Level::PostInitialize(cmdBuffer); + + //Your post-initialize code here. +} + +void MainLvl::OnUpdate(lwe::RenderWindow *win, ehs::Input *input, const float delta) +{ + Level::OnUpdate(win, input, delta); + + //Your on-update code here. +} + +void MainLvl::PreRender(lwe::GpuCmdBuffer *cmdBuffer) +{ + Level::PreRender(cmdBuffer); + + //Your pre-render code here. +} \ No newline at end of file diff --git a/MainLvl.h b/MainLvl.h new file mode 100644 index 0000000..7dcf0c6 --- /dev/null +++ b/MainLvl.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +class MainLvl : public lwe::Level +{ +public: + ~MainLvl() override; + + MainLvl(); + + MainLvl(MainLvl &&lvl) noexcept; + + MainLvl(const MainLvl &lvl); + + MainLvl &operator=(MainLvl &&lvl) noexcept; + + MainLvl &operator=(const MainLvl &lvl); + + void SetupResources(lwe::GpuInterface *inf) override; + + void Setup(lwe::GpuInterface *inf) override; + + void PostInitialize(lwe::GpuCmdBuffer *cmdBuffer) override; + + void OnUpdate(lwe::RenderWindow *win, ehs::Input *input, float delta) override; + + void PreRender(lwe::GpuCmdBuffer *cmdBuffer) override; +}; \ No newline at end of file diff --git a/Sprite.cpp b/Sprite.cpp new file mode 100644 index 0000000..a58f7ee --- /dev/null +++ b/Sprite.cpp @@ -0,0 +1,5 @@ +#include "Sprite.h" + +namespace ehs +{ +} \ No newline at end of file diff --git a/Sprite.h b/Sprite.h new file mode 100644 index 0000000..6844dc1 --- /dev/null +++ b/Sprite.h @@ -0,0 +1,9 @@ +#pragma once + +namespace ehs +{ + class Sprite + { + + }; +} \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..47f5f5e --- /dev/null +++ b/main.cpp @@ -0,0 +1,51 @@ +#include +#include + +#include +#include + +#include "MainLvl.h" + +int main() +{ + ehs::Initialize("SpriteGen", "Release", {1, 0, 0}); + + ehs::Log::EnableImmediateMode(true); + + lwe::RenderWindow::AddExtensions(); + lwe::GpuInstance::Initialize(true); + + lwe::GpuDevice device = std::move(lwe::GpuDevice::GetBest()); + lwe::GpuQueueFamily* family = device.GetQueueFamily(lwe::QueueType::GRAPHICS); + + lwe::GpuInterface inf(&device); + lwe::RenderWindow::AddExtensions(&inf); + + lwe::GpuQueue primary(family, &inf, 1.0f); + + inf.Initialize(); + + lwe::RenderWindow win(&inf, &primary); + win.Create_8(ehs::GetAppName_8(), {0, 0}, {1024, 768}); + win.Show(); + + lwe::GameLoop gl(&win, 0, 0); + gl.EnableTimeLock(true); + gl.SetMaxTPS(60); + + gl.AddLevel(new MainLvl()); + + gl.Initialize(); + gl.Start(); + gl.UnInitialize(); + + win.Close(); + + inf.Release(); + + lwe::GpuInstance::Release(); + + ehs::Uninitialize(); + + return 0; +}