Hello, we need to optimize launching of several games written in cocos2d-x on an linux embedded system. Currently we use separate games launched from an also cocos2d-x based menu. It runs in a shell loop and based on the return code of menu application the right game is launched then. This works fine, but has some delays and screen goes black between the games, which we do not like.
We have two ideas how to deal with it. First one is building everything into big single binary. Which We do not like much as it would get very poorly maintanable for the future. Second one is building all the games as shared libraries (.so files) and dynamic loading of scenes from them… which sounds a bit better.
For building the game as shared library we needed to change a lot of CMakeLists files inside cocos as you cannot build shared library from static library and almost everything is built as static in cocos by default.
Just a thought, could you change the XCode or VS Project to compiled as a shared lib? on OS X I can change from static library to framework…I am not sure about VS though.
I moved a bit forward. A test with two empty HelloWorld projects works for me now. But I was still not able to do it with our a bit more complex games and game menu.
What I did (we use cocos2d-x v3.2) was something like find ./cocos2d/ -name CMakeLists.txt -print0 | xargs -0 sed -i 's/STATIC/SHARED/g' for Cocos’ CMakeLists. Then for every precompiled library I had to obtain their shared (.so) versions, in my game’s CMakeLists change add_executable(${APP_NAME} ${GAME_SRC}) to add_library(${APP_NAME} SHARED ${GAME_SRC}). And few simillar things. I was then able to load scene from libMyGame.so into MyMenu app and replace the scenes.
Now I keep getting several segfaults like
Program received signal SIGSEGV, Segmentation fault.
cocos2d::Scheduler::schedule(void (cocos2d::Ref::*)(float), cocos2d::Ref*, float, unsigned int, float, bool) () at /var/lib/jenkins/jobs/shared_menu/workspace/cocos2d/cocos/base/CCScheduler.cpp:989
989 HASH_FIND_PTR(_hashForTimers, &target, element);
(gdb) bt
#0 cocos2d::Scheduler::schedule(void (cocos2d::Ref::*)(float), cocos2d::Ref*, float, unsigned int, float, bool) () at /var/lib/jenkins/jobs/shared_menu/workspace/cocos2d/cocos/base/CCScheduler.cpp:989
#1 0x00007fffe1080258 in Game::startPreload() () at /var/lib/jenkins/jobs/shared_game_A/workspace/Classes/src/Core/Game.cpp:229
#2 0x00007ffff70f3461 in cocos2d::Scheduler::update(float) () at /usr/include/c++/4.9/functional:2439
#3 0x00007ffff70e0c84 in cocos2d::Director::drawScene() () at /var/lib/jenkins/jobs/shared_menu/workspace/cocos2d/cocos/base/CCDirector.cpp:272
#4 0x00007ffff70e0cc1 in cocos2d::DisplayLinkDirector::mainLoop() () at /var/lib/jenkins/jobs/shared_menu/workspace/cocos2d/cocos/base/CCDirector.cpp:1269
#5 0x0000000000428f04 in AppDelegate::run() () at /var/lib/jenkins/jobs/shared_menu/workspace/Classes/AppDelegate.cpp:121
#6 0x0000000000427f6a in main () at /var/lib/jenkins/jobs/shared_menu/workspace/proj.linux/main.cpp:13
Maybe separate namespaces for game and menu could help a bit, we’re going to try…
Regarding the cocos gen-libs it is not present in v3.2 and seems it does something different, than what could be useful for us.