TechDemo/main.cpp

136 lines
3.4 KiB
C++
Raw Normal View History

2024-01-26 09:01:01 -08:00
#include <ehs/Str.h>
#include <ehs/Log.h>
#include <ehs/GarbageCollector.h>
#include <ehs/Array.h>
#include <ehs/io/File.h>
#include <ehs/io/Console.h>
#include <ehs/system/Thread.h>
#include <ehs/json/Json.h>
#include <ehs/io/img/PNG.h>
#include <lwe/RenderWindow.h>
#include <lwe/gpu/GpuDevice.h>
#include <lwe/gpu/GpuInterface.h>
#include <lwe/GameLoop.h>
2023-11-14 00:32:05 -08:00
#include <vulkan/vulkan.h>
#include "Levels/MainMenu.h"
#include "Levels/TestLevel.h"
2024-01-26 09:01:01 -08:00
ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer)
2023-11-14 00:32:05 -08:00
{
*appName = "TechDemo";
*appVerId = "Release";
*appVer = {1, 0, 0};
2024-01-26 09:01:01 -08:00
ehs::File configFile("Config.json", ehs::Mode::READ_WRITE, ehs::Disposition::OPEN_PERSISTENT);
2023-11-14 00:32:05 -08:00
if (!configFile.Size())
{
2024-01-26 09:01:01 -08:00
ehs::JsonObj root;
2023-11-14 00:32:05 -08:00
2024-01-26 09:01:01 -08:00
ehs::JsonObj server;
2023-11-14 00:32:05 -08:00
server.AddVar({"identifier", ""});
server.AddVar({"address", ""});
server.AddVar({"port", 7840});
server.AddVar({"maxPlayers", 0});
root.AddVar({"server", server});
2024-01-26 09:01:01 -08:00
ehs::JsonObj client;
2023-11-14 00:32:05 -08:00
client.AddVar({"username", ""});
client.AddVar({"connectAddress", ""});
client.AddVar({"connectPort", 7840});
root.AddVar({"client", client});
2024-01-26 09:01:01 -08:00
ehs::JsonObj server_client;
2023-11-14 00:32:05 -08:00
server_client.AddVar({"timeout", 5});
server_client.AddVar({"resendRate", 0.5f});
root.AddVar({"server_client", server_client});
2024-01-26 09:01:01 -08:00
ehs::JsonObj engine;
2023-11-14 00:32:05 -08:00
engine.AddVar({"threadCount", 0});
engine.AddVar({"timeLocked", true});
engine.AddVar({"maxTPS", 60});
root.AddVar({"engine", engine});
2024-01-26 09:01:01 -08:00
ehs::Json config(root);
2023-11-14 00:32:05 -08:00
configFile.WriteStr_8(config.ToStr(false));
configFile.Release();
return 0;
}
2024-01-26 09:01:01 -08:00
ehs::Json config(configFile.ReadStr_8(configFile.Size()), 0);
2023-11-14 00:32:05 -08:00
configFile.Release();
2024-01-26 09:01:01 -08:00
ehs::Vector<ehs::Str_8> args = ehs::Console::GetArgs_8();
if (args.Size() > 1 && ehs::Str_8::Cmp(args[1], "-server"))
2023-11-14 00:32:05 -08:00
{
2024-01-26 09:01:01 -08:00
ehs::Console::Attach();
2023-11-14 00:32:05 -08:00
2024-01-26 09:01:01 -08:00
ehs::Console::SetTitle_8("TechDemo");
2023-11-14 00:32:05 -08:00
2024-01-26 09:01:01 -08:00
EHS_LOG("Info", 0, "Initializing server, standby.");
2023-11-14 00:32:05 -08:00
2024-01-26 09:01:01 -08:00
lwe::GameLoop gl((ehs::UInt_8)*(ehs::JsonNum*)config.RetrieveValue("engine.threadCount"), 0);
gl.EnableTimeLock(*(ehs::JsonBool*)config.RetrieveValue("engine.timeLocked"));
gl.SetMaxTPS((ehs::UInt_32)*(ehs::JsonNum*)config.RetrieveValue("engine.maxTPS"));
2023-11-14 00:32:05 -08:00
2024-01-26 09:01:01 -08:00
gl.AddLevel(new MainMenu("MainMenu"));
2023-11-14 00:32:05 -08:00
gl.Initialize();
gl.Start();
gl.UnInitialize();
}
else
{
2024-01-26 09:01:01 -08:00
ehs::Console::Attach();
2023-11-14 00:32:05 -08:00
2024-01-26 09:01:01 -08:00
#if defined(EHS_OS_WINDOWS)
2023-11-14 00:32:05 -08:00
lwe::GpuInstance::AddExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
2024-01-26 09:01:01 -08:00
#elif defined(EHS_OS_LINUX)
2023-11-14 00:32:05 -08:00
lwe::GpuInstance::AddExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
#endif
lwe::GpuInstance::AddExtension(VK_KHR_SURFACE_EXTENSION_NAME);
lwe::GpuInstance::Initialize(false);
lwe::GpuDevice device = std::move(lwe::GpuDevice::GetBest());
lwe::GpuQueueFamily* family = device.GetQueueFamily(lwe::QueueType::GRAPHICS);
lwe::GpuInterface inf(&device);
inf.AddExtensions(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
lwe::GpuQueue primary(family, &inf, 1.0f);
inf.Initialize();
lwe::RenderWindow win(&inf, &primary);
2024-01-26 09:01:01 -08:00
win.Create_8(ehs::GetAppName_8(), {0, 0}, {1024, 768});
2023-11-14 00:32:05 -08:00
win.Show();
2024-01-26 09:01:01 -08:00
lwe::GameLoop gl(&win, (ehs::UInt_8)*(ehs::JsonNum*)config.RetrieveValue("engine.threadCount"), 0);
gl.EnableTimeLock(*(ehs::JsonBool*)config.RetrieveValue("engine.timeLocked"));
gl.SetMaxTPS((ehs::UInt_32)*(ehs::JsonNum*)config.RetrieveValue("engine.maxTPS"));
2023-11-14 00:32:05 -08:00
2024-01-26 09:01:01 -08:00
gl.AddLevel(new TestLevel("Test"));
2023-11-14 00:32:05 -08:00
gl.Initialize();
gl.Start();
gl.UnInitialize();
win.Close();
inf.Release();
lwe::GpuInstance::Release();
}
2024-01-26 09:01:01 -08:00
ehs::Console::Free();
2023-11-14 00:32:05 -08:00
return 0;
}