2024-01-26 09:01:01 -08:00
|
|
|
#include <ehs/Str.h>
|
|
|
|
#include <ehs/Log.h>
|
2024-07-05 13:17:24 -07:00
|
|
|
#include <ehs/GC.h>
|
2024-01-26 09:01:01 -08:00
|
|
|
#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-07-27 10:14:28 -07:00
|
|
|
int main()
|
2023-11-14 00:32:05 -08:00
|
|
|
{
|
2024-07-27 10:14:28 -07:00
|
|
|
ehs::Initialize("TechDemo", "Release", {1, 0, 0});
|
2023-11-14 00:32:05 -08:00
|
|
|
|
2024-07-05 13:17:24 -07:00
|
|
|
ehs::Log::EnableImmediateMode(true);
|
|
|
|
|
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-07-05 13:17:24 -07:00
|
|
|
EHS_LOG(ehs::LogType::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-07-24 00:51:03 -07:00
|
|
|
lwe::RenderWindow::AddExtensions();
|
2024-07-05 13:17:24 -07:00
|
|
|
lwe::GpuInstance::Initialize(true);
|
2023-11-14 00:32:05 -08:00
|
|
|
|
|
|
|
lwe::GpuDevice device = std::move(lwe::GpuDevice::GetBest());
|
|
|
|
lwe::GpuQueueFamily* family = device.GetQueueFamily(lwe::QueueType::GRAPHICS);
|
|
|
|
|
|
|
|
lwe::GpuInterface inf(&device);
|
2024-07-24 00:51:03 -07:00
|
|
|
lwe::RenderWindow::AddExtensions(&inf);
|
2023-11-14 00:32:05 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
2024-07-27 10:14:28 -07:00
|
|
|
ehs::Uninitialize();
|
|
|
|
|
2023-11-14 00:32:05 -08:00
|
|
|
return 0;
|
|
|
|
}
|