MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / main_module_exec

Method main_module_exec

samples/application/game/src/game_module.cpp:518–1013  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

516
517SKR_EXTERN_C int luaopen_clonefunc(lua_State* L);
518int SGameModule::main_module_exec(int argc, char8_t** argv)
519{
520 SkrZoneScopedN("GameExecution");
521 // auto moduleManager = skr_get_module_manager();
522 SKR_LOG_INFO(u8"game executed as main module!");
523
524 if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
525 return -1;
526
527 auto render_device = skr_get_default_render_device();
528 auto cgpu_device = render_device->get_cgpu_device();
529 auto gfx_queue = render_device->get_gfx_queue();
530 auto window_desc = make_zeroed<SWindowDescroptor>();
531 window_desc.flags = SKR_WINDOW_CENTERED | SKR_WINDOW_RESIZABLE; // | SKR_WINDOW_BOARDLESS;
532 window_desc.height = BACK_BUFFER_HEIGHT;
533 window_desc.width = BACK_BUFFER_WIDTH;
534 main_window = skr_create_window(
535 skr::format(u8"Game [{}]", gCGPUBackendNames[cgpu_device->adapter->instance->backend]).u8_str(),
536 &window_desc);
537 // Initialize renderer
538 swapchain = skr_render_device_register_window(render_device, main_window);
539 present_fence = cgpu_create_fence(cgpu_device);
540
541 namespace render_graph = skr::render_graph;
542 auto renderGraph = render_graph::RenderGraph::create(
543 [=](skr::render_graph::RenderGraphBuilder& builder) {
544 builder.with_device(cgpu_device)
545 .with_gfx_queue(gfx_queue)
546 .enable_memory_aliasing();
547 });
548 game_initialize_render_effects(game_renderer, renderGraph, resource_vfs);
549 create_test_scene(game_renderer);
550 create_imgui_resources(resource_vfs, render_device, renderGraph);
551 // Lua
552 auto L = skr_lua_newstate(resource_vfs);
553 skr_lua_bind_imgui(L);
554 skr_lua_open_game_runtime(L);
555 lua_newtable(L);
556 lua_pushvalue(L, -1);
557 lua_setglobal(L, "game");
558 auto GetStorage = +[](lua_State* L) -> int {
559 lua_pushlightuserdata(L, g_game_module->game_world);
560 return 1;
561 };
562 lua_pushcfunction(L, GetStorage, "GetStorage");
563 lua_setfield(L, -2, "GetStorage");
564 lua_pop(L, 1);
565 if (skr_lua_loadfile(L, "main") != 0)
566 {
567 if (lua_pcall(L, 0, 0, 0) != LUA_OK)
568 {
569 SKR_LOG_ERROR(u8"lua_pcall error: {}", lua_tostring(L, -1));
570 lua_pop(L, 1);
571 }
572 }
573
574 lua_getglobal(L, "GameMain");
575 if (lua_pcall(L, 0, 0, 0) != LUA_OK)

Callers

nothing calls this directly

Calls 15

skr_create_windowFunction · 0.85
cgpu_create_fenceFunction · 0.85
skr_lua_newstateFunction · 0.85
skr_lua_bind_imguiFunction · 0.85
lua_setglobalFunction · 0.85
lua_pushlightuserdataFunction · 0.85
skr_lua_loadfileFunction · 0.85
lua_pcallFunction · 0.85
lua_getglobalFunction · 0.85

Tested by

no test coverage detected