MCPcopy Create free account
hub / github.com/defold/defold / engine_main

Function engine_main

engine/engine/src/engine_main.cpp:106–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106int engine_main(int argc, char *argv[])
107{
108 dmThread::SetThreadName(dmThread::GetCurrentThread(), "looper_main");
109
110 pthread_attr_t attr;
111 size_t stacksize;
112
113 pthread_getattr_np(pthread_self(), &attr);
114 pthread_attr_getstacksize(&attr, &stacksize);
115
116 struct android_app* app = dmAndroid::GetAndroidApp();
117 assert(app);
118
119 app->onAppCmd = glfwAndroidHandleCommand;
120 app->onInputEvent = glfwAndroidHandleInput;
121
122 // Wait for window to become ready (APP_CMD_INIT_WINDOW in handleCommand)
123 if (!WaitForWindow())
124 {
125 // When phone lock/unlock app may receive APP_CMD_DESTROY without APP_CMD_INIT_WINDOW
126 // in this case app should exit immediately
127 return 0;
128 }
129
130 glfwInit();
131
132 EngineMainThreadArgs args;
133 args.m_Argc = argc;
134 args.m_Argv = argv;
135 args.m_Finished = 0;
136 dmThread::Thread t = dmThread::New(EngineMainThread, stacksize, &args, "engine_main");
137 while (!args.m_Finished)
138 {
139 glfwAndroidPollEvents();
140 dmTime::Sleep(0);
141 if (app->destroyRequested) {
142 // App requested exit. It doesn't wait when thread work finished because app is in background already.
143 // App will never end up here from within the app itself, only using OS functions.
144 return 0;
145 }
146 }
147 dmThread::Join(t);
148
149 glfwTerminate();
150 return args.m_ExitCode;
151}
152
153#else
154

Callers 1

mainFunction · 0.85

Calls 12

glfwAndroidPollEventsFunction · 0.85
glfwTerminateFunction · 0.85
EngineMainFunction · 0.85
WaitForWindowFunction · 0.70
NewFunction · 0.70
SetThreadNameFunction · 0.50
GetCurrentThreadFunction · 0.50
GetAndroidAppFunction · 0.50
assertFunction · 0.50
glfwInitFunction · 0.50
SleepFunction · 0.50
JoinFunction · 0.50

Tested by

no test coverage detected