Android update and small improvements

-fixed code do cross compiling to android
-fixed build with GCC (workaround)
-added little benchmark
-several small fixes
-updated meson build (demos building, working with GCC, LDC and DMD)
-added some meson options
-added ImGUI bind for OpenGL3
This commit is contained in:
Mergul 2020-06-01 11:24:50 +02:00
parent 86edfa4a57
commit 66860b9042
30 changed files with 1358 additions and 173 deletions

View file

@ -203,12 +203,10 @@ void mainLoop(void* arg)
temp_fps = 0;
}
SDL_Event event;
while (SDL_PollEvent(&event))
{
version(WebAssembly)ImGui_ImplSDL2_ProcessEvent(&event);
else ImGui_ImplSDL2_ProcessEvent(&event);
ImGui_ImplSDL2_ProcessEvent(&event);
if(launcher.event)launcher.event(&event);
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_ESCAPE)) {
quit();
@ -278,7 +276,8 @@ void mainLoop(void* arg)
}
else
{
ImGuiImplOpenGL2NewFrame();
//ImGuiImplOpenGL2NewFrame();
ImGui_ImplOpenGL3_NewFrame();
ImGuiImplSDL2NewFrame(launcher.window);
}
@ -632,7 +631,9 @@ void mainLoop(void* arg)
igRender();
version(WebAssembly)ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());
else ImGuiImplOpenGL2RenderDrawData(igGetDrawData());
else version(Android)ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());
else ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());
//ImGuiImplOpenGL2RenderDrawData(igGetDrawData());
//launcher.renderer.clear();
//launcher.renderer.present();
@ -652,15 +653,48 @@ void quit()
version(WebAssembly)emscripten_cancel_main_loop();
}
int main(int argc, char** argv)
version(Android)
{
export extern (C) int SDL_main(int argc, char** args)
{
return app_main(argc,args);
}
import ldc.attributes;
extern (C) __gshared
{
@section(".tdata")
int _tlsstart = 0;
@section(".tcommon")
int _tlsend = 0;
}
}
else
{
extern (C) int main(int argc, char** argv)
{
return app_main(argc,argv);
}
}
int app_main(int argc, char** argv)
//int main(int argc, char** argv)
{
version(BindSDL_Static){}
else
{
loadSDL();
loadSDLImage();
}
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("SDL could not initialize! SDL_Error: %s", SDL_GetError());
return -1;
}
SDL_version sdl_version;
SDL_GetVersion(&sdl_version);
printf("SDL version: %u.%u.%u\n",cast(uint)sdl_version.major,cast(uint)sdl_version.minor,cast(uint)sdl_version.patch);
@ -692,6 +726,21 @@ int main(int argc, char** argv)
return -3;
}
}
else version(Android)
{
//gladLoadGL();
gladLoadGLES2(x => SDL_GL_GetProcAddress(x));
if(!ImGuiImplSDL2InitForOpenGL(launcher.window,launcher.gl_context))
{
printf("ImGui initialization failed!");
return -2;
}
if(!ImGui_ImplOpenGL3_Init("#version 100"))
{
printf("ImGui OpenGL initialization failed!");
return -3;
}
}
else
{
gladLoadGL();
@ -700,13 +749,14 @@ int main(int argc, char** argv)
printf("ImGui initialization failed!");
return -2;
}
if(!ImGuiImplOpenGL2Init())
//if(!ImGuiImplOpenGL2Init())
if(!ImGui_ImplOpenGL3_Init("#version 120"))
{
printf("ImGui OpenGL initialization failed!");
return -3;
}
}
ImFontConfig* config = ImFontConfig_ImFontConfig();
ImGuiIO* io = igGetIO();
const ushort* font_ranges = ImFontAtlas_GetGlyphRangesDefault(io.Fonts);

View file

@ -1392,7 +1392,7 @@ struct UpgradeCollisionSystem
if(space_invaders.shoot_grid.test(id, data.location[i], cast(ubyte)(0xFF)))
{
Entity* entity = launcher.manager.getEntity(id);
if(entity.hasComponent(CShip.component_id))
if(entity && entity.hasComponent(CShip.component_id))
{
launcher.manager.sendEvent(id, EUpgrade());
launcher.manager.removeEntity(data.entity[i].id);

View file

@ -37,12 +37,17 @@ struct ECSJobUpdater
//pool.unregistExternalThread(thread_data);
if(jobs)Mallocator.dispose(jobs);
version(WebAssembly)pthread_key_delete(tls_key);
else version(Android)pthread_key_delete(tls_key);
}
version(WebAssembly)
{
__gshared pthread_key_t tls_key;
}
else version(Android)
{
__gshared pthread_key_t tls_key;
}
else static uint thread_id = 0;
ThreadPool pool;
@ -105,6 +110,7 @@ struct ECSJobUpdater
void onCreate(uint threads_count)
{
version(WebAssembly)pthread_key_create(&tls_key, null);
else version(Android)pthread_key_create(&tls_key, null);
pool.initialize();
thread_data = pool.registerExternalThread();
@ -116,6 +122,7 @@ struct ECSJobUpdater
uint getThreadID() @nogc nothrow
{
version(WebAssembly)return cast(int)pthread_getspecific(tls_key);
else version(Android)return cast(int)pthread_getspecific(tls_key);
else return thread_id;
}
@ -200,6 +207,11 @@ struct ECSJobUpdater
}
else job.execute();
}
else version(Android)
{
pthread_setspecific(tls_key, cast(void*)th_data.threadId);
job.execute();
}
else
{
updater.thread_id = th_data.threadId;