Skip to content

Commit 2d39cf1

Browse files
committed
[Shell] new entrypoint
1 parent 17d98e8 commit 2d39cf1

6 files changed

Lines changed: 109 additions & 127 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef APPLICATION_HPP
2+
#define APPLICATION_HPP
3+
4+
#include "openminecraft/log/om_log_common.hpp"
5+
#include <vector>
6+
namespace openminecraftshell
7+
{
8+
class OMApplication
9+
{
10+
public:
11+
OMApplication(std::vector<std::string> args);
12+
~OMApplication();
13+
14+
auto entry() -> int;
15+
16+
private:
17+
std::vector<std::string> args;
18+
openminecraft::log::OMLogger logger;
19+
};
20+
}; // namespace openminecraftshell
21+
22+
#endif

include/openminecraft-shell/renderer/worldrenderer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef OM_RENDERER_LAYER_VK_TESTRENDERER
2-
#define OM_RENDERER_LAYER_VK_TESTRENDERER
1+
#ifndef WORLDRENDERER_HPP
2+
#define WORLDRENDERER_HPP
33
#include "glm/ext/vector_float3.hpp"
44
#include "glm/fwd.hpp"
55
#include "openminecraft-shell/data/block/om_blockstate_resolver.hpp"

include/openminecraft-shell/entrypoint.hpp renamed to include/openminecraft-shell/rendererloop.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
#ifndef OM_BOOT_HPP
2-
#define OM_BOOT_HPP
1+
#ifndef RENDERERLOOP_HPP
2+
#define RENDERERLOOP_HPP
33

44
#include "openminecraft/renderer/om_renderer_window.hpp"
5-
#include <string>
6-
#include <vector>
75

86
using namespace openminecraft;
97

108
namespace openminecraftshell
119
{
12-
// INFO: the boot function for the app
13-
auto boot(std::vector<std::string> args) -> int;
1410
void rendererLoop(renderer::OMBackend);
1511
} // namespace openminecraftshell
1612

src/openminecraft/application.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <SDL3/SDL_error.h>
2+
3+
#include "openminecraft-shell/rendererloop.hpp"
4+
#include "openminecraft/i18n/om_i18n_res.hpp"
5+
#include "openminecraft/log/om_log_common.hpp"
6+
#include "openminecraft/log/om_log_threadname.hpp"
7+
#include "openminecraft/mem/om_mem_allocator.hpp"
8+
#include "openminecraft/renderer/om_renderer_window.hpp"
9+
#include "openminecraft/vm/os/om_hardware.hpp"
10+
#include <SDL3/SDL_init.h>
11+
#include <SDL3/SDL_stdinc.h>
12+
#include <SDL3/SDL_video.h>
13+
#include <boost/stacktrace/stacktrace.hpp>
14+
#include <memory>
15+
#include <string>
16+
17+
#include <SDL3/SDL.h>
18+
#include <boost/stacktrace.hpp>
19+
#include <fmt/format.h>
20+
#include <vector>
21+
22+
#include "openminecraft-shell/application.hpp"
23+
24+
using namespace openminecraft;
25+
26+
namespace openminecraftshell
27+
{
28+
OMApplication::OMApplication(std::vector<std::string> args) : logger("OMApplication", this), args(args)
29+
{
30+
}
31+
OMApplication::~OMApplication() = default;
32+
33+
static void setupI18nEnv()
34+
{
35+
i18n::res::registerModule("openminecraft-boot");
36+
i18n::res::registerModule("openminecraft-renderer");
37+
i18n::res::pushResourceRoot("/bootassets");
38+
i18n::res::load();
39+
}
40+
41+
auto OMApplication::entry() -> int
42+
{
43+
log::multithread::registerCurrentThreadName("engineMain");
44+
auto logger = std::make_shared<log::OMLogger>("boot");
45+
46+
SDL_SetMemoryFunctions(mem::allocator::tracedMallocSDL, mem::allocator::tracedCallocSDL,
47+
mem::allocator::tracedReallocSDL, mem::allocator::tracedFreeSDL);
48+
setupI18nEnv();
49+
if (!SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO))
50+
{
51+
logger->info("SDL Status: {}", SDL_GetError());
52+
}
53+
logger->info(i18n::res::translate("openminecraft.boot.arg"));
54+
for (auto a : args)
55+
{
56+
logger->info(a);
57+
}
58+
59+
// INFO: hardware information
60+
logger->info("hardware / software status");
61+
logger->info("CPU Name: {}", openminecraft::vm::os::fetchCpuName());
62+
logger->info("System: {}, version {}", openminecraft::vm::os::fetchSystemName(),
63+
openminecraft::vm::os::fetchSystemVersion());
64+
logger->info("Total memory: {} bytes", openminecraft::vm::os::fetchMemoryTotal());
65+
66+
renderer::OMBackend bk = renderer::Vulkan;
67+
if (args.size() >= 2)
68+
{
69+
bk = args[1] == "gl" ? renderer::OpenGL : renderer::Vulkan;
70+
}
71+
72+
rendererLoop(bk);
73+
74+
SDL_Quit();
75+
76+
return 0;
77+
}
78+
} // namespace openminecraftshell

src/openminecraft/entrypoint.cpp

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/openminecraft/launcher.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#include "openminecraft-shell/entrypoint.hpp"
1+
#include "openminecraft-shell/application.hpp"
22
#include "openminecraft/log/om_log_common.hpp"
33
#include "openminecraft/log/om_log_threadname.hpp"
44
#include "openminecraft/vfs/om_vfs_base.hpp"
55
#include <csignal>
6+
#include <string>
7+
#include "openminecraft/log/om_log_common.hpp"
68

79
extern "C"
810
{
@@ -40,7 +42,8 @@ auto main(int argc, char **argv) -> int
4042
openminecraft::vfs::fsmountZipArchive(_binary_external_bundle_start,
4143
(uint32_t)(_binary_external_bundle_end - _binary_external_bundle_start),
4244
"/external");
43-
int re = openminecraftshell::boot(a);
45+
openminecraftshell::OMApplication app(a);
46+
int re = app.entry();
4447
logger.info("Kernel exited with code {}", re);
4548

4649
return re;

0 commit comments

Comments
 (0)