SpiderPig Posted June 8 Share Posted June 8 I'm not sure how to go about creating a loading screen where I can load all the assets in the background. Does Ultra support this out of the box or do I have to code some thread magic myself? I need to be able to update a progress bar and / or a spinning 3D object in the corner of the screen without any pauses. Quote Link to comment Share on other sites More sharing options...
Yue Posted June 8 Share Posted June 8 A background thread loads the elements and the main thread would show the loading bar or animation. 1 Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted June 8 Author Share Posted June 8 I'm not sure if we can call such things like : LoadModel() & LoadTexture() on a separate thread though. I think it might break something in the engine. But I'm unsure... Quote Link to comment Share on other sites More sharing options...
Yue Posted June 9 Share Posted June 9 I have thought that if you can, as long as you don't run a render of the world. Possibly it will go into the main loop after doing the load. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted June 9 Author Share Posted June 9 Yeah maybe it can. But I want to render the loading screen as well, so everything needs to be thread safe. Quote Link to comment Share on other sites More sharing options...
Yue Posted June 9 Share Posted June 9 Synchronization between the two threads in mutex programming. Quote Link to comment Share on other sites More sharing options...
Josh Posted June 9 Share Posted June 9 If you have called World::Render once, then the rendering thread will just keep rendering as the map is loading on the main thread. You can use a custom shader to display a spinning object, or wait for texture animation to be added, and you can make a circular object with a scrolling texture. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
SpiderPig Posted June 10 Author Share Posted June 10 I see, thanks. Could the application go non responsive though? Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted June 10 Share Posted June 10 Tried to replicate how i made loading screen in my game but for some reason loading screen shows with big delay in this example #include "UltraEngine.h" #include "ComponentSystem.h" using namespace UltraEngine; shared_ptr<World> gameWorld; shared_ptr<World> world; shared_ptr<Interface> ui; shared_ptr<Camera> uiCamera; shared_ptr<Map> gameScene; shared_ptr<Window> window; shared_ptr<Framebuffer> framebuffer; shared_ptr<World> loadingWorld; shared_ptr<Interface> loadingUi; shared_ptr<Camera> loadingCamera; shared_ptr<Widget> loadingLabel; shared_ptr<Widget> menuPanel; bool isMainMenuOn = true; bool newGameButtonCallback(const Event& ev, shared_ptr<Object> extra) { ui = nullptr; world = nullptr; loadingWorld->Render(framebuffer); WString mapName = "Maps/start.ultra"; gameScene = LoadMap(gameWorld, mapName); isMainMenuOn = false; return true; } bool exitButtonCallback(const Event& ev, shared_ptr<Object> extra) { exit(0); return true; } void loadingInit() { loadingWorld = CreateWorld(); //Loading UI auto font = LoadFont("Fonts/arial.ttf"); loadingUi = CreateInterface(loadingWorld, font, framebuffer->GetSize()); loadingUi->SetScale(1); loadingUi->SetRenderLayers(2); loadingUi->LoadColorScheme("Resources/configs/Style.json"); //Label LOADING... int centerX = float(framebuffer->GetSize().x) * 0.5f; int centerY = float(framebuffer->GetSize().y) * 0.5f; float labelHeight = float(framebuffer->GetSize().y) * 0.2f; loadingLabel = CreateLabel("LOADING", float(framebuffer->GetSize().x) * 0.05f, centerY - labelHeight * 0.5f, float(framebuffer->GetSize().x) * 0.95f, labelHeight, loadingUi->root, LABEL_CENTER | LABEL_MIDDLE); loadingLabel->SetFontScale(20); //Create ui camera loadingCamera = CreateCamera(loadingWorld, PROJECTION_ORTHOGRAPHIC); loadingCamera->SetPosition(centerX, centerY, 0); loadingCamera->SetRenderLayers(2); loadingCamera->SetClearMode(CLEAR_DEPTH); loadingCamera->SetLighting(false); } int main(int argc, const char* argv[]) { RegisterComponents(); //Load FreeImage plugin (optional) auto fiplugin = LoadPlugin("Plugins/FITextureLoader"); //Get the displays auto displays = GetDisplays(); //Create a window window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a framebuffer framebuffer = CreateFramebuffer(window); //Create a world world = CreateWorld(); //Load a font auto font = LoadFont("Fonts/arial.ttf"); //Create user interface ui = CreateInterface(world, font, framebuffer->GetSize()); ui->SetRenderLayers(2); ui->root->SetColor(0.2f, 0.2f, 0.2f, 1.0f); ui->LoadColorScheme("Resources/configs/Style.json"); //Create ui camera auto uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC); uiCamera->SetPosition(float(framebuffer->GetSize().x) * 0.5f, float(framebuffer->GetSize().y) * 0.5f, 0); uiCamera->SetRenderLayers(2); uiCamera->SetClearMode(CLEAR_DEPTH); auto newGameButton = CreateButton("New game", 200, 125, 200, 50, ui->root); ListenEvent(EVENT_WIDGETACTION, newGameButton, newGameButtonCallback); auto exitButton = CreateButton("Exit", 200, 200, 200, 50, ui->root); ListenEvent(EVENT_WIDGETACTION, exitButton, exitButtonCallback); gameWorld = CreateWorld(); gameWorld->RecordStats(); loadingInit(); shared_ptr<World> currentWorld = world; shared_ptr<Interface> currentUI = ui; while (window->Closed() == false) { if (!isMainMenuOn) currentWorld = gameWorld; while (PeekEvent()) { const Event ev = WaitEvent(); switch (ev.id) { case EVENT_WINDOWCLOSE: if (ev.source == window) { exit(0); break; } break; default: currentUI->ProcessEvent(ev); break; } } currentWorld->Update(); currentWorld->Render(framebuffer); } return 0; } 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted June 10 Share Posted June 10 1 hour ago, SpiderPig said: I see, thanks. Could the application go non responsive though? The window event system is on the main thread, so it would stop processing events while the map is loading. However, the screen buffer would continue to refresh as the rendering thread runs. 1 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.