premake finally working, todo add sdl support to linux build

This commit is contained in:
2024-06-23 20:42:33 +02:00
commit 9bf5e7d44b
196 changed files with 135721 additions and 0 deletions

126
SakuraVNE/SakuraVNE.vcxproj Normal file
View File

@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D55F2F81-41CA-E3F7-8A08-959DF6B1C14C}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>SakuraVNE</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>..\bin\Debug-windows-x86_64\SakuraVNE\</OutDir>
<IntDir>..\bin-int\Debug-windows-x86_64\SakuraVNE\</IntDir>
<TargetName>SakuraVNE</TargetName>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\bin\Release-windows-x86_64\SakuraVNE\</OutDir>
<IntDir>..\bin-int\Release-windows-x86_64\SakuraVNE\</IntDir>
<TargetName>SakuraVNE</TargetName>
<TargetExt>.exe</TargetExt>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>PLATFORM_WINDOWS;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>src;..\libs\spdlog\include;..\libs\imgui;..\libs\imgui\misc;..\libs\imgui\backends;..\libs\sdl\windows\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>ImGui.lib;SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\libs\imgui\bin\Debug-windows-x86_64\ImGui;..\libs\sdl\windows\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
<Command>IF EXIST ..\libs\sdl\windows\lib\x64\SDL2.dll\ (xcopy /Q /E /Y /I ..\libs\sdl\windows\lib\x64\SDL2.dll ..\bin\Debug-windows-x86_64\SakuraVNE &gt; nul) ELSE (xcopy /Q /Y /I ..\libs\sdl\windows\lib\x64\SDL2.dll ..\bin\Debug-windows-x86_64\SakuraVNE &gt; nul)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>PLATFORM_WINDOWS;RELEASE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>src;..\libs\spdlog\include;..\libs\imgui;..\libs\imgui\misc;..\libs\imgui\backends;..\libs\sdl\windows\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DebugInformationFormat>None</DebugInformationFormat>
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<MinimalRebuild>false</MinimalRebuild>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<LanguageStandard>stdcpp20</LanguageStandard>
<ExternalWarningLevel>Level3</ExternalWarningLevel>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>ImGui.lib;SDL2.lib;SDL2main.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>..\libs\imgui\bin\Release-windows-x86_64\ImGui;..\libs\sdl\windows\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
<Command>IF EXIST ..\libs\sdl\windows\lib\x64\SDL2.dll\ (xcopy /Q /E /Y /I ..\libs\sdl\windows\lib\x64\SDL2.dll ..\bin\Release-windows-x86_64\SakuraVNE &gt; nul) ELSE (xcopy /Q /Y /I ..\libs\sdl\windows\lib\x64\SDL2.dll ..\bin\Release-windows-x86_64\SakuraVNE &gt; nul)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\Application.h" />
<ClInclude Include="src\Event.h" />
<ClInclude Include="src\Log.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Application.cpp" />
<ClCompile Include="src\Event.cpp" />
<ClCompile Include="src\Log.cpp" />
<ClCompile Include="src\main.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\libs\imgui\ImGui.vcxproj">
<Project>{C0FF640D-2C14-8DBE-F595-301E616989EF}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

12
SakuraVNE/imgui.ini Normal file
View File

@@ -0,0 +1,12 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
[Window][Dear ImGui Demo]
Pos=650,20
Size=550,680
[Window][Hello World!]
Pos=60,60
Size=311,157

View File

@@ -0,0 +1,169 @@
#include "Application.h"
#include "Log.h"
#include "Event.h"
#include "imgui.h"
#include "imgui_impl_sdl2.h"
#include "imgui_impl_sdlrenderer2.h"
#if !SDL_VERSION_ATLEAST(2,0,17)
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
#endif
WindowData Application::m_WindowData;
bool Application::m_isRunning = false;
Application::Application(){}
Application::~Application()
{
Shutdown();
}
bool Application::Init()
{
SetRunningState(true);
SakuraVNE::Log::Init();
LOG_INFO("Initialized logger library");
LOG_INFO("window width: {0}, height: {1}", GetWindowData().width, GetWindowData().height);
// Init sdl
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER /*| SDL_INIT_GAMECONTROLLER*/) < 0)
{
LOG_ERROR("SDL could not be initialized! {0}", SDL_GetError());
Shutdown();
return false;
}
#ifdef SDL_HINT_IME_SHOW_UI
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
#endif
//TODO: add the resizable flag and update the window size with the event system
SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI /*| SDL_WINDOW_RESIZABLE*/);
m_Window = SDL_CreateWindow(GetWindowData().title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, GetWindowData().width, GetWindowData().height, windowFlags);
if (!m_Window)
{
LOG_ERROR("SDL window could not be created! {0}", SDL_GetError());
Shutdown();
return false;
}
else
{
LOG_INFO("SDl window created");
}
m_Renderer = SDL_CreateRenderer(m_Window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
if(!m_Renderer){
LOG_ERROR("Renderer could not be created! {0}", SDL_GetError());
}else{
LOG_INFO("SDL renderer created");
SDL_RendererInfo info;
SDL_GetRendererInfo(m_Renderer, &info);
}
m_Surface = SDL_GetWindowSurface(m_Window);
if (!m_Surface)
{
LOG_ERROR("SDL surface could not be created! {0}", SDL_GetError());
Shutdown();
return false;
}
else
{
LOG_INFO("SDl surface created");
}
//Imgui init
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void) io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
ImGui::StyleColorsDark();
ImGui_ImplSDL2_InitForSDLRenderer(m_Window, m_Renderer);
ImGui_ImplSDLRenderer2_Init(m_Renderer);
return true;
}
void Application::Run()
{
bool demoWindowShow = true;
bool showOtherWindow = false;
ImVec4 clearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
ImGuiIO& io = ImGui::GetIO();
while (Application::GetRunningState())
{
SakuraVNE::ProcessEvents();
ImGui_ImplSDLRenderer2_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
if(demoWindowShow){
ImGui::ShowDemoWindow(&demoWindowShow);
}
//imgui demo window stuff or frame stuff
static float f = 0.0f;
static int counter = 0;
ImGui::Begin("Hello World!"); //creates window and add later stuff to it
ImGui::Text("text stuff");
ImGui::Checkbox("Demo checkbox", &showOtherWindow);
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
ImGui::ColorEdit3("clear color edit", (float*)&clearColor);
if(ImGui::Button("Button")) counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("Application avg %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End();
//Rendering
ImGui::Render();
SDL_RenderSetScale(m_Renderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
SDL_SetRenderDrawColor(m_Renderer, (Uint8)(clearColor.x * 255), (Uint8)(clearColor.y * 255), (Uint8)(clearColor.z * 255), (Uint8)(clearColor.w * 255));
SDL_RenderClear(m_Renderer);
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), m_Renderer);
SDL_RenderPresent(m_Renderer);
}
}
void Application::Shutdown()
{
LOG_WARN("Shutting down the application!");
ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_DestroyRenderer(m_Renderer);
SDL_FreeSurface(m_Surface);
// Destroy window
SDL_DestroyWindow(m_Window);
// Quit SDL subsystems
SDL_Quit();
}

View File

@@ -0,0 +1,34 @@
#pragma once
#include "SDL.h"
struct WindowData{
int width = 800;
int height = 600;
const char* title = "Sakura Visual Novel Engine";
};
class Application
{
public:
Application();
~Application();
bool Init();
void Run();
void Shutdown();
static inline WindowData& GetWindowData(){ return m_WindowData; }
//static inline SDL_Window* GetWindow() { return m_Window; }
static bool& GetRunningState() { return m_isRunning; }
static void SetRunningState(bool isRunning) { m_isRunning = isRunning; }
private:
SDL_Window* m_Window;
SDL_Renderer* m_Renderer;
SDL_Surface* m_Surface;
static WindowData m_WindowData;
static bool m_isRunning;
};

23
SakuraVNE/src/Event.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "SDL.h"
#include "Application.h"
#include "Event.h"
#include "Log.h"
void SakuraVNE::ProcessEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
Application::SetRunningState(false);
LOG_INFO("Running state: {0}", Application::GetRunningState());
}
/*if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(Application::GetWindow()))
{
Application::SetRunningState(false);
} */
}
}

3
SakuraVNE/src/Event.h Normal file
View File

@@ -0,0 +1,3 @@
namespace SakuraVNE{
void ProcessEvents();
}

16
SakuraVNE/src/Log.cpp Normal file
View File

@@ -0,0 +1,16 @@
#include "Log.h"
#include "spdlog/sinks/stdout_color_sinks.h"
namespace SakuraVNE{
std::shared_ptr<spdlog::logger> Log::m_Logger;
void Log::Init(){
spdlog::set_pattern("%^[%T] %n: %v%$");
m_Logger = spdlog::stdout_color_mt("Sakura");
m_Logger->set_level(spdlog::level::trace);
}
}

23
SakuraVNE/src/Log.h Normal file
View File

@@ -0,0 +1,23 @@
#pragma once
#include "spdlog/spdlog.h"
#include "spdlog/fmt/ostr.h"
#include <memory>
namespace SakuraVNE
{
class Log
{
public:
static void Init();
inline static std::shared_ptr<spdlog::logger>& GetLogger() {return m_Logger;}
private:
static std::shared_ptr<spdlog::logger> m_Logger;
};
}
#define LOG_INFO(...) ::SakuraVNE::Log::GetLogger()->info(__VA_ARGS__)
#define LOG_WARN(...) ::SakuraVNE::Log::GetLogger()->warn(__VA_ARGS__)
#define LOG_ERROR(...) ::SakuraVNE::Log::GetLogger()->error(__VA_ARGS__)

16
SakuraVNE/src/main.cpp Normal file
View File

@@ -0,0 +1,16 @@
#define SDL_MAIN_HANDLED
#include "Application.h"
#include "Log.h"
int main(int argc, char* argv[]){
SDL_SetMainReady();
Application app;
bool success = app.Init();
if(success)
app.Run();
return 0;
}