lumino 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
 - data/Tools/EngineResources/NotoColorEmoji.ttf +0 -0
 - data/Tools/EngineResources/README.md +4 -0
 - data/Tools/ProjectTemplates/cpp-cmake/CMakeLists.txt +14 -0
 - data/Tools/ProjectTemplates/cpp-cmake/assets/LineWave.fx +57 -0
 - data/Tools/ProjectTemplates/cpp-cmake/assets/icon256.png +0 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Editor/CMakeLists.txt +20 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Editor/Common.h +4 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Editor/EditorMain.cpp +10 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Editor/EditorMain.h +16 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Editor/PCH.cpp +1 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Editor/PCH.h +9 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Game/CMakeLists.txt +16 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Game/PCH.cpp +1 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Game/PCH.h +8 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Runtime/CMakeLists.txt +15 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Runtime/Main.Windows.cpp +29 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Runtime/PCH.cpp +1 -0
 - data/Tools/ProjectTemplates/cpp-cmake/projects/Runtime/PCH.h +9 -0
 - data/Tools/ProjectTemplates/cpp-cmake/src/App.cpp +18 -0
 - data/Tools/ProjectTemplates/cpp-cmake/src/App.h +12 -0
 - data/Tools/ProjectTemplates/cpp-default/LuminoApp.sln +25 -0
 - data/Tools/ProjectTemplates/cpp-default/assets/LineWave.fx +57 -0
 - data/Tools/ProjectTemplates/cpp-default/assets/icon256.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/assets/picture1.jpg +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/CMakeLists.txt +64 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/build.gradle +43 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/proguard-rules.pro +21 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/AndroidManifest.xml +24 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/cpp/PCH.cpp +1 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/cpp/PCH.h +4 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/cpp/native-lib.cpp +114 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +34 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/drawable/ic_launcher_background.xml +170 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/layout/activity_main.xml +19 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +5 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +5 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/values/colors.xml +6 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/values/strings.xml +3 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/app/src/main/res/values/styles.xml +11 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/build.gradle +27 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/gradle.properties +13 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/gradle/wrapper/gradle-wrapper.jar +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/gradle/wrapper/gradle-wrapper.properties +6 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/gradlew +172 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/gradlew.bat +84 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Android/settings.gradle +1 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Web/CMakeLists.txt +27 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Web/PCH.cpp +1 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Web/PCH.h +5 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Web/pre.js +13 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/Launch.cpp +30 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/LuminoApp.ico +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/LuminoApp.rc +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/LuminoApp.vcxproj +117 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/LuminoApp.vcxproj.filters +41 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/PCH.cpp +1 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/PCH.h +6 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/Resource.h +30 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/Resource.rc +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/app.ico +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/small.ico +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.Windows/targetver.h +6 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS.xcodeproj/project.pbxproj +450 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/AppDelegate.h +11 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/AppDelegate.mm +70 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Assets.xcassets/AppIcon.appiconset/Contents.json +221 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Assets.xcassets/ColorMap.textureset/Contents.json +17 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Assets.xcassets/ColorMap.textureset/Universal.mipmapset/ColorMap.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Assets.xcassets/ColorMap.textureset/Universal.mipmapset/Contents.json +12 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Assets.xcassets/Contents.json +6 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Base.lproj/LaunchScreen.storyboard +25 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Base.lproj/Main.storyboard +28 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/GameViewController.h +6 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/GameViewController.mm +26 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Info.plist +50 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Prefix.pch +7 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Renderer.h +9 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/Renderer.mm +52 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/RootGLKView.h +13 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/RootGLKView.mm +10 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.iOS/LuminoApp.iOS/main.mm +9 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS.xcodeproj/project.pbxproj +454 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/Assets.xcassets/AppIcon.appiconset/Contents.json +58 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/Assets.xcassets/ColorMap.textureset/Contents.json +17 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/Assets.xcassets/ColorMap.textureset/Universal.mipmapset/ColorMap.png +0 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/Assets.xcassets/ColorMap.textureset/Universal.mipmapset/Contents.json +12 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/Assets.xcassets/Contents.json +6 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/Info.plist +32 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/LuminoApp_macOS.entitlements +10 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/Prefix.pch +8 -0
 - data/Tools/ProjectTemplates/cpp-default/projects/LuminoApp.macOS/LuminoApp.macOS/main.mm +22 -0
 - data/Tools/ProjectTemplates/cpp-default/src/App.cpp +16 -0
 - data/Tools/ProjectTemplates/ruby-default/assets/icon256.png +0 -0
 - data/Tools/ProjectTemplates/ruby-default/assets/picture1.jpg +0 -0
 - data/Tools/ProjectTemplates/ruby-default/main.rb +12 -0
 - data/Tools/lumino-rb.exe +0 -0
 - data/Tools/vswhere.exe +0 -0
 - data/bin/console +14 -0
 - data/bin/setup +8 -0
 - data/exe/lumino-rb +11 -0
 - data/ext/FlatC.generated.h +2239 -0
 - data/ext/FlatCommon.h +176 -0
 - data/ext/Lumino.RubyExt.generated.cpp +8833 -0
 - data/ext/LuminoEngine.dll +0 -0
 - data/ext/LuminoRubyRuntimeManager.cpp +439 -0
 - data/ext/LuminoRubyRuntimeManager.h +92 -0
 - data/ext/extconf.rb +9 -0
 - data/lib/lumino.rb +41 -0
 - data/lib/lumino/cli.rb +10 -0
 - data/lib/lumino/version.rb +3 -0
 - data/test/test_engine.rb +93 -0
 - data/test/test_struct.rb +44 -0
 - metadata +214 -0
 
| 
         Binary file 
     | 
| 
         @@ -0,0 +1,439 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #if 1
         
     | 
| 
      
 2 
     | 
    
         
            +
            #include "LuminoRubyRuntimeManager.h"
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            extern "C" LN_FLAT_API LnResult LnEngine_Finalize();
         
     | 
| 
      
 5 
     | 
    
         
            +
            extern "C" LN_FLAT_API void LnRuntime_RunAppInternal(LnHandle app);
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            //==============================================================================
         
     | 
| 
      
 8 
     | 
    
         
            +
            // 
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            static VALUE Wrap_LnRuntime_RunAppInternal(VALUE self, VALUE app)
         
     | 
| 
      
 11 
     | 
    
         
            +
            {
         
     | 
| 
      
 12 
     | 
    
         
            +
                LnHandle handle = LuminoRubyRuntimeManager::instance->getHandle(app);
         
     | 
| 
      
 13 
     | 
    
         
            +
                LnRuntime_RunAppInternal(handle);
         
     | 
| 
      
 14 
     | 
    
         
            +
                return Qnil;
         
     | 
| 
      
 15 
     | 
    
         
            +
            }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            VALUE Wrap_LnRuntime_RegisterType(VALUE self, VALUE type)
         
     | 
| 
      
 18 
     | 
    
         
            +
            {
         
     | 
| 
      
 19 
     | 
    
         
            +
                std::string className;
         
     | 
| 
      
 20 
     | 
    
         
            +
                {
         
     | 
| 
      
 21 
     | 
    
         
            +
                    VALUE v = rb_funcall(type, rb_intern("name"), 0, 0);
         
     | 
| 
      
 22 
     | 
    
         
            +
                    className = StringValuePtr(v);
         
     | 
| 
      
 23 
     | 
    
         
            +
                }
         
     | 
| 
      
 24 
     | 
    
         
            +
                
         
     | 
| 
      
 25 
     | 
    
         
            +
                std::string superclassName;
         
     | 
| 
      
 26 
     | 
    
         
            +
                {
         
     | 
| 
      
 27 
     | 
    
         
            +
                    VALUE v1  = rb_funcall(type, rb_intern("superclass"), 0, 0);
         
     | 
| 
      
 28 
     | 
    
         
            +
                    superclassName = RubyUtils::makeTypeInfoName(v1);
         
     | 
| 
      
 29 
     | 
    
         
            +
                }
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                LNRB_LOG_D("Usesr type registering. (class: %s, superclass: %s)", className.c_str(), superclassName.c_str());
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                int typeInfoId;
         
     | 
| 
      
 34 
     | 
    
         
            +
                LnTypeInfo_AcquireA(className.c_str(), &typeInfoId);
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                int baseTypeInfoId;
         
     | 
| 
      
 37 
     | 
    
         
            +
                LnTypeInfo_AcquireA(superclassName.c_str(), &baseTypeInfoId);
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                LnTypeInfo_SetBaseClass(typeInfoId, baseTypeInfoId);
         
     | 
| 
      
 40 
     | 
    
         
            +
                LnTypeInfo_SetCreateInstanceCallback(typeInfoId, &LuminoRubyRuntimeManager::handleCreateInstanceCallback);
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                // ユーザー定義型として、あとでインスタンス生成時に型情報を関連付けるときに高速に検索できるように覚えておく
         
     | 
| 
      
 43 
     | 
    
         
            +
                LuminoRubyRuntimeManager::instance->m_userDefinedClassTypeIdMap[className] = typeInfoId;
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                int managedTypeInfoId = LuminoRubyRuntimeManager::instance->registerTypeInfo(type, nullptr);
         
     | 
| 
      
 46 
     | 
    
         
            +
                LnTypeInfo_SetManagedTypeInfoId(typeInfoId, managedTypeInfoId);
         
     | 
| 
      
 47 
     | 
    
         
            +
                
         
     | 
| 
      
 48 
     | 
    
         
            +
                LNRB_LOG_D("Usesr type registerd. (typeInfoId: %d, baseTypeInfoId: %d, managedTypeInfoId: %d)", typeInfoId, baseTypeInfoId, managedTypeInfoId);
         
     | 
| 
      
 49 
     | 
    
         
            +
                return Qnil;
         
     | 
| 
      
 50 
     | 
    
         
            +
            }
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            static VALUE Wrap_LnRuntime_inherited(VALUE self, VALUE type)
         
     | 
| 
      
 53 
     | 
    
         
            +
            {
         
     | 
| 
      
 54 
     | 
    
         
            +
                VALUE v  = rb_funcall(type, rb_intern("name"), 0, 0);
         
     | 
| 
      
 55 
     | 
    
         
            +
                std::string name2 = StringValuePtr(v);
         
     | 
| 
      
 56 
     | 
    
         
            +
                if (name2.find("Lumino::") == 0) return Qnil;   // TODO: Engine::init 前は EngineContext が null なので使えない。ので逃げる
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                auto name = RubyUtils::makeTypeInfoName(type);
         
     | 
| 
      
 59 
     | 
    
         
            +
                LNRB_LOG_D("Usesr type registering from 'self.inherited.' (%s)", name.c_str());
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                int typeInfoId = 0;
         
     | 
| 
      
 62 
     | 
    
         
            +
                LnTypeInfo_FindA(name.c_str(), &typeInfoId);
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                if (typeInfoId == 0) {
         
     | 
| 
      
 65 
     | 
    
         
            +
                    Wrap_LnRuntime_RegisterType(self, type);
         
     | 
| 
      
 66 
     | 
    
         
            +
                }
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                LNRB_LOG_D("Usesr type registerd from 'self.inherited.' (%d)", typeInfoId);
         
     | 
| 
      
 69 
     | 
    
         
            +
                return Qnil;
         
     | 
| 
      
 70 
     | 
    
         
            +
            }
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            //==============================================================================
         
     | 
| 
      
 73 
     | 
    
         
            +
            // LuminoRubyRuntimeManager
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            LuminoRubyRuntimeManager* LuminoRubyRuntimeManager::instance = nullptr;
         
     | 
| 
      
 76 
     | 
    
         
            +
            LnLogLevel LuminoRubyRuntimeManager::s_logLevel = LN_LOG_LEVEL_INFO;
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
            LuminoRubyRuntimeManager* LuminoRubyRuntimeManager::getInstance(VALUE managerInstance)
         
     | 
| 
      
 79 
     | 
    
         
            +
            {
         
     | 
| 
      
 80 
     | 
    
         
            +
                LuminoRubyRuntimeManager* instance;
         
     | 
| 
      
 81 
     | 
    
         
            +
                Data_Get_Struct(managerInstance, LuminoRubyRuntimeManager, instance);
         
     | 
| 
      
 82 
     | 
    
         
            +
                return instance;
         
     | 
| 
      
 83 
     | 
    
         
            +
            }
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::init()
         
     | 
| 
      
 86 
     | 
    
         
            +
            {
         
     | 
| 
      
 87 
     | 
    
         
            +
                instance = this;
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                // Initialize runtime.
         
     | 
| 
      
 90 
     | 
    
         
            +
                {
         
     | 
| 
      
 91 
     | 
    
         
            +
                    VALUE LUMINO_LOG_LEVEL = rb_eval_string_protect("$LUMINO_LOG_LEVEL", NULL);
         
     | 
| 
      
 92 
     | 
    
         
            +
                    if (LUMINO_LOG_LEVEL != Qnil) {
         
     | 
| 
      
 93 
     | 
    
         
            +
                        s_logLevel = (LnLogLevel)FIX2INT(LUMINO_LOG_LEVEL);
         
     | 
| 
      
 94 
     | 
    
         
            +
                        LnLog_SetLevel(s_logLevel);
         
     | 
| 
      
 95 
     | 
    
         
            +
                    }
         
     | 
| 
      
 96 
     | 
    
         
            +
                    
         
     | 
| 
      
 97 
     | 
    
         
            +
                    VALUE LUMINO_ENGINE_RESOURCES_DIR = rb_eval_string_protect("$LUMINO_ENGINE_RESOURCES_DIR", NULL);
         
     | 
| 
      
 98 
     | 
    
         
            +
                    if (LUMINO_ENGINE_RESOURCES_DIR != Qnil) {
         
     | 
| 
      
 99 
     | 
    
         
            +
                        const char* path = StringValuePtr(LUMINO_ENGINE_RESOURCES_DIR);
         
     | 
| 
      
 100 
     | 
    
         
            +
                        printf("path: %s\n", path);
         
     | 
| 
      
 101 
     | 
    
         
            +
                        LnInternalEngineSettings_SetEngineResourcesPathA(path);
         
     | 
| 
      
 102 
     | 
    
         
            +
                    }
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                    LnRuntimeSettings settings;
         
     | 
| 
      
 105 
     | 
    
         
            +
                    settings.runtimeFinalizedCallback = handleRuntimeFinalized;
         
     | 
| 
      
 106 
     | 
    
         
            +
                    settings.referenceCountTrackerCallback = handleReferenceChangedStatic;
         
     | 
| 
      
 107 
     | 
    
         
            +
                    settings.runtimeGetTypeInfoIdCallback = nullptr;
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                    LnRuntime_Initialize(&settings);
         
     | 
| 
      
 110 
     | 
    
         
            +
                }
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                // Define core functions.
         
     | 
| 
      
 113 
     | 
    
         
            +
                {
         
     | 
| 
      
 114 
     | 
    
         
            +
                    m_luminoModule = rb_define_module("Lumino");
         
     | 
| 
      
 115 
     | 
    
         
            +
                    
         
     | 
| 
      
 116 
     | 
    
         
            +
                    int state = 0;
         
     | 
| 
      
 117 
     | 
    
         
            +
                    rb_eval_string_protect(
         
     | 
| 
      
 118 
     | 
    
         
            +
                        "module Lumino\n"
         
     | 
| 
      
 119 
     | 
    
         
            +
                        "  class EventSignal\n"
         
     | 
| 
      
 120 
     | 
    
         
            +
                        "    def initialize\n"
         
     | 
| 
      
 121 
     | 
    
         
            +
                        "      @handlers = []\n"
         
     | 
| 
      
 122 
     | 
    
         
            +
                        "    end\n"
         
     | 
| 
      
 123 
     | 
    
         
            +
                        "    def add(handler=nil, &block)\n"
         
     | 
| 
      
 124 
     | 
    
         
            +
                        "      if handler\n"
         
     | 
| 
      
 125 
     | 
    
         
            +
                        "        @handlers.push(handler)\n"
         
     | 
| 
      
 126 
     | 
    
         
            +
                        "      end\n"
         
     | 
| 
      
 127 
     | 
    
         
            +
                        "      if block\n"
         
     | 
| 
      
 128 
     | 
    
         
            +
                        "        @handlers.push(block)\n"
         
     | 
| 
      
 129 
     | 
    
         
            +
                        "      end\n"
         
     | 
| 
      
 130 
     | 
    
         
            +
                        "    end\n"
         
     | 
| 
      
 131 
     | 
    
         
            +
                        "    def raise(*args)\n"
         
     | 
| 
      
 132 
     | 
    
         
            +
                        "      @handlers.each do |h|\n"
         
     | 
| 
      
 133 
     | 
    
         
            +
                        "        h.call(*args)\n"
         
     | 
| 
      
 134 
     | 
    
         
            +
                        "      end\n"
         
     | 
| 
      
 135 
     | 
    
         
            +
                        "    end\n"
         
     | 
| 
      
 136 
     | 
    
         
            +
                        "  end\n"
         
     | 
| 
      
 137 
     | 
    
         
            +
                        "end\n"
         
     | 
| 
      
 138 
     | 
    
         
            +
                        ,
         
     | 
| 
      
 139 
     | 
    
         
            +
                        &state);
         
     | 
| 
      
 140 
     | 
    
         
            +
                    m_eventSignalClass = rb_eval_string("Lumino::EventSignal");
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
                    m_objectClass = rb_define_class_under(m_luminoModule, "Object", rb_cObject);
         
     | 
| 
      
 143 
     | 
    
         
            +
                    rb_define_singleton_method(m_objectClass, "inherited", reinterpret_cast<VALUE(__cdecl *)(...)>(Wrap_LnRuntime_inherited), 1);
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                    VALUE class_Application = rb_define_class_under(m_luminoModule, "Application", m_objectClass);
         
     | 
| 
      
 146 
     | 
    
         
            +
                    rb_define_singleton_method(class_Application, "run_app_internal", reinterpret_cast<VALUE(__cdecl *)(...)>(Wrap_LnRuntime_RunAppInternal), 1);
         
     | 
| 
      
 147 
     | 
    
         
            +
                    
         
     | 
| 
      
 148 
     | 
    
         
            +
                    rb_define_module_function(m_luminoModule, "register_type", reinterpret_cast<VALUE(__cdecl *)(...)>(Wrap_LnRuntime_RegisterType), 1);
         
     | 
| 
      
 149 
     | 
    
         
            +
                }
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                m_typeInfoList.push_back({});   // [0] is dummy
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
                for (int i = 0; i < InitialListSize; i++) {
         
     | 
| 
      
 154 
     | 
    
         
            +
                    m_objectList.push_back({ Qnil, Qnil });
         
     | 
| 
      
 155 
     | 
    
         
            +
                    m_objectListIndexStack.push(i);
         
     | 
| 
      
 156 
     | 
    
         
            +
                }
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                m_runtimeAliving = true;
         
     | 
| 
      
 159 
     | 
    
         
            +
            }
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
            VALUE LuminoRubyRuntimeManager::wrapObjectForGetting(LnHandle handle, bool retain)
         
     | 
| 
      
 162 
     | 
    
         
            +
            {
         
     | 
| 
      
 163 
     | 
    
         
            +
                if (handle == LN_NULL_HANDLE) return Qnil;
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
                int objectIndex = (int)LnRuntime_GetManagedObjectId(handle);
         
     | 
| 
      
 166 
     | 
    
         
            +
                int typeinfoIndex = (int)LnRuntime_GetManagedTypeInfoId(handle);
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
                if (objectIndex <= 0) {
         
     | 
| 
      
 169 
     | 
    
         
            +
                    LNRB_LOG_D("New Ruby object from WrapObjectForGetting (typeinfoIndex:%d)", typeinfoIndex);
         
     | 
| 
      
 170 
     | 
    
         
            +
                    VALUE obj = m_typeInfoList[typeinfoIndex].factory(m_typeInfoList[typeinfoIndex].klass, handle);
         
     | 
| 
      
 171 
     | 
    
         
            +
                    if (retain) {
         
     | 
| 
      
 172 
     | 
    
         
            +
                        LnObject_Retain(handle);
         
     | 
| 
      
 173 
     | 
    
         
            +
                    }
         
     | 
| 
      
 174 
     | 
    
         
            +
                    registerWrapperObject(obj, true);
         
     | 
| 
      
 175 
     | 
    
         
            +
                    return obj;
         
     | 
| 
      
 176 
     | 
    
         
            +
                }
         
     | 
| 
      
 177 
     | 
    
         
            +
                else {
         
     | 
| 
      
 178 
     | 
    
         
            +
                    return m_objectList[objectIndex].weakRef;
         
     | 
| 
      
 179 
     | 
    
         
            +
                }
         
     | 
| 
      
 180 
     | 
    
         
            +
            }
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
            LnHandle LuminoRubyRuntimeManager::getHandle(VALUE value) const
         
     | 
| 
      
 183 
     | 
    
         
            +
            {
         
     | 
| 
      
 184 
     | 
    
         
            +
                if (value == Qnil) {
         
     | 
| 
      
 185 
     | 
    
         
            +
                    return LN_NULL_HANDLE;
         
     | 
| 
      
 186 
     | 
    
         
            +
                }
         
     | 
| 
      
 187 
     | 
    
         
            +
                Wrap_RubyObject* obj;
         
     | 
| 
      
 188 
     | 
    
         
            +
                Data_Get_Struct(value, Wrap_RubyObject, obj);
         
     | 
| 
      
 189 
     | 
    
         
            +
                return obj->handle;
         
     | 
| 
      
 190 
     | 
    
         
            +
            }
         
     | 
| 
      
 191 
     | 
    
         
            +
             
     | 
| 
      
 192 
     | 
    
         
            +
            int LuminoRubyRuntimeManager::registerTypeInfo(VALUE klass, ObjectFactoryFunc factory)
         
     | 
| 
      
 193 
     | 
    
         
            +
            {
         
     | 
| 
      
 194 
     | 
    
         
            +
                TypeInfo t;
         
     | 
| 
      
 195 
     | 
    
         
            +
                t.klass = klass;
         
     | 
| 
      
 196 
     | 
    
         
            +
                t.factory = factory;
         
     | 
| 
      
 197 
     | 
    
         
            +
                m_typeInfoList.push_back(t);
         
     | 
| 
      
 198 
     | 
    
         
            +
                int id =  m_typeInfoList.size() - 1;
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
                if (s_logLevel == LN_LOG_LEVEL_DEBUG) {
         
     | 
| 
      
 201 
     | 
    
         
            +
                    LNRB_LOG_D("Type registerd. (id: %d, displayName: %s)", id, RubyUtils::getClassNameFromClass(klass).c_str());
         
     | 
| 
      
 202 
     | 
    
         
            +
                }
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
                return id;
         
     | 
| 
      
 205 
     | 
    
         
            +
            }
         
     | 
| 
      
 206 
     | 
    
         
            +
             
     | 
| 
      
 207 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::registerWrapperObject(VALUE obj, bool forNativeGetting)
         
     | 
| 
      
 208 
     | 
    
         
            +
            {
         
     | 
| 
      
 209 
     | 
    
         
            +
                LnHandle handle = getHandle(obj);
         
     | 
| 
      
 210 
     | 
    
         
            +
             
     | 
| 
      
 211 
     | 
    
         
            +
                int64_t id = LnRuntime_GetManagedObjectId(handle);
         
     | 
| 
      
 212 
     | 
    
         
            +
                if (id > 0) {
         
     | 
| 
      
 213 
     | 
    
         
            +
                    // 登録済み
         
     | 
| 
      
 214 
     | 
    
         
            +
                    LNRB_LOG_D("registerWrapperObject: [Registerd] ManagedObjectId: %d\n", id);
         
     | 
| 
      
 215 
     | 
    
         
            +
                    return;
         
     | 
| 
      
 216 
     | 
    
         
            +
                }
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                // grow
         
     | 
| 
      
 219 
     | 
    
         
            +
                if (m_objectListIndexStack.size() == 0)
         
     | 
| 
      
 220 
     | 
    
         
            +
                {
         
     | 
| 
      
 221 
     | 
    
         
            +
                    int growCount = m_objectList.size();
         
     | 
| 
      
 222 
     | 
    
         
            +
                    for (int i = 0; i < growCount; i++)
         
     | 
| 
      
 223 
     | 
    
         
            +
                    {
         
     | 
| 
      
 224 
     | 
    
         
            +
                        m_objectList.push_back({ Qnil, Qnil });
         
     | 
| 
      
 225 
     | 
    
         
            +
                        m_objectListIndexStack.push(growCount + i);
         
     | 
| 
      
 226 
     | 
    
         
            +
                    }
         
     | 
| 
      
 227 
     | 
    
         
            +
                }
         
     | 
| 
      
 228 
     | 
    
         
            +
             
     | 
| 
      
 229 
     | 
    
         
            +
                int index = m_objectListIndexStack.top();
         
     | 
| 
      
 230 
     | 
    
         
            +
                m_objectListIndexStack.pop();
         
     | 
| 
      
 231 
     | 
    
         
            +
                m_objectList[index].weakRef = obj;
         
     | 
| 
      
 232 
     | 
    
         
            +
                if (forNativeGetting) {
         
     | 
| 
      
 233 
     | 
    
         
            +
                    m_objectList[index].strongRef = obj;
         
     | 
| 
      
 234 
     | 
    
         
            +
                }
         
     | 
| 
      
 235 
     | 
    
         
            +
                
         
     | 
| 
      
 236 
     | 
    
         
            +
                LnRuntime_SetManagedObjectId(handle, index);
         
     | 
| 
      
 237 
     | 
    
         
            +
                LNRB_LOG_D("registerWrapperObject (handle:%u, ManagedObjectId:%d)\n", handle, index);
         
     | 
| 
      
 238 
     | 
    
         
            +
             
     | 
| 
      
 239 
     | 
    
         
            +
                // ユーザー定義型の型情報をオブジェクトにセットする
         
     | 
| 
      
 240 
     | 
    
         
            +
                {
         
     | 
| 
      
 241 
     | 
    
         
            +
                    VALUE klass = CLASS_OF(obj);
         
     | 
| 
      
 242 
     | 
    
         
            +
                    VALUE v = rb_funcall(klass, rb_intern("name"), 0, 0);
         
     | 
| 
      
 243 
     | 
    
         
            +
                    std::string name = StringValuePtr(v);
         
     | 
| 
      
 244 
     | 
    
         
            +
             
     | 
| 
      
 245 
     | 
    
         
            +
                    // ユーザー定義型に限定する (Engine 内部型は登録する必要なし)
         
     | 
| 
      
 246 
     | 
    
         
            +
                    auto itr = m_userDefinedClassTypeIdMap.find(name);
         
     | 
| 
      
 247 
     | 
    
         
            +
                    if (itr != m_userDefinedClassTypeIdMap.end()) {
         
     | 
| 
      
 248 
     | 
    
         
            +
                        LnObject_SetTypeInfoId(handle, itr->second);
         
     | 
| 
      
 249 
     | 
    
         
            +
                        LNRB_LOG_D("LnObject_SetTypeInfoId (handle:%u, itr->second:%d)\n", handle, itr->second);
         
     | 
| 
      
 250 
     | 
    
         
            +
                    }
         
     | 
| 
      
 251 
     | 
    
         
            +
                }
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
      
 253 
     | 
    
         
            +
            }
         
     | 
| 
      
 254 
     | 
    
         
            +
             
     | 
| 
      
 255 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::unregisterWrapperObject(LnHandle handle)
         
     | 
| 
      
 256 
     | 
    
         
            +
            {
         
     | 
| 
      
 257 
     | 
    
         
            +
                LNRB_LOG_D("LuminoRubyRuntimeManager::unregisterWrapperObject: LnHandle=%u\n", handle);
         
     | 
| 
      
 258 
     | 
    
         
            +
                if (m_runtimeAliving) {
         
     | 
| 
      
 259 
     | 
    
         
            +
                    LnObject_Release(handle);
         
     | 
| 
      
 260 
     | 
    
         
            +
                    int index = (int)LnRuntime_GetManagedObjectId(handle);
         
     | 
| 
      
 261 
     | 
    
         
            +
                    m_objectList[index].weakRef = Qnil;
         
     | 
| 
      
 262 
     | 
    
         
            +
                    m_objectList[index].strongRef = Qnil;
         
     | 
| 
      
 263 
     | 
    
         
            +
                    m_objectListIndexStack.push(index);
         
     | 
| 
      
 264 
     | 
    
         
            +
                }
         
     | 
| 
      
 265 
     | 
    
         
            +
            }
         
     | 
| 
      
 266 
     | 
    
         
            +
             
     | 
| 
      
 267 
     | 
    
         
            +
            static VALUE g_LuminoRubyRuntimeManagerClass;
         
     | 
| 
      
 268 
     | 
    
         
            +
            static VALUE g_LuminoRubyRuntimeManager;
         
     | 
| 
      
 269 
     | 
    
         
            +
             
     | 
| 
      
 270 
     | 
    
         
            +
            static void LuminoRubyRuntimeManager_delete(LuminoRubyRuntimeManager* obj)
         
     | 
| 
      
 271 
     | 
    
         
            +
            {
         
     | 
| 
      
 272 
     | 
    
         
            +
                if (obj) {
         
     | 
| 
      
 273 
     | 
    
         
            +
                    delete obj;
         
     | 
| 
      
 274 
     | 
    
         
            +
                    LuminoRubyRuntimeManager::instance = nullptr;
         
     | 
| 
      
 275 
     | 
    
         
            +
                }
         
     | 
| 
      
 276 
     | 
    
         
            +
            }
         
     | 
| 
      
 277 
     | 
    
         
            +
             
     | 
| 
      
 278 
     | 
    
         
            +
            static VALUE LuminoRubyRuntimeManager_allocate(VALUE klass)
         
     | 
| 
      
 279 
     | 
    
         
            +
            {
         
     | 
| 
      
 280 
     | 
    
         
            +
                VALUE obj;
         
     | 
| 
      
 281 
     | 
    
         
            +
                LuminoRubyRuntimeManager* internalObj = new LuminoRubyRuntimeManager();
         
     | 
| 
      
 282 
     | 
    
         
            +
                if (!internalObj) rb_raise(rb_eRuntimeError, "Faild alloc - LuminoRubyRuntimeManager_allocate");
         
     | 
| 
      
 283 
     | 
    
         
            +
                internalObj->init();
         
     | 
| 
      
 284 
     | 
    
         
            +
                obj = Data_Wrap_Struct(klass, LuminoRubyRuntimeManager::gc_mark, LuminoRubyRuntimeManager_delete, internalObj);
         
     | 
| 
      
 285 
     | 
    
         
            +
                return obj;
         
     | 
| 
      
 286 
     | 
    
         
            +
            }
         
     | 
| 
      
 287 
     | 
    
         
            +
             
     | 
| 
      
 288 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::gc_mark(LuminoRubyRuntimeManager* obj)
         
     | 
| 
      
 289 
     | 
    
         
            +
            {
         
     | 
| 
      
 290 
     | 
    
         
            +
                LNRB_LOG_D("LuminoRubyRuntimeManager::gc_mark\n");
         
     | 
| 
      
 291 
     | 
    
         
            +
                rb_gc_mark(obj->m_luminoModule);
         
     | 
| 
      
 292 
     | 
    
         
            +
                rb_gc_mark(obj->m_eventSignalClass);
         
     | 
| 
      
 293 
     | 
    
         
            +
                for (auto& item : instance->m_objectList) {
         
     | 
| 
      
 294 
     | 
    
         
            +
                    rb_gc_mark(item.strongRef);
         
     | 
| 
      
 295 
     | 
    
         
            +
                }
         
     | 
| 
      
 296 
     | 
    
         
            +
            }
         
     | 
| 
      
 297 
     | 
    
         
            +
             
     | 
| 
      
 298 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::handleReferenceChangedStatic(LnHandle handle, int method, int count)
         
     | 
| 
      
 299 
     | 
    
         
            +
            {
         
     | 
| 
      
 300 
     | 
    
         
            +
                instance->handleReferenceChanged(handle, method, count);
         
     | 
| 
      
 301 
     | 
    
         
            +
            }
         
     | 
| 
      
 302 
     | 
    
         
            +
             
     | 
| 
      
 303 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::handleReferenceChanged(LnHandle handle, int method, int count)
         
     | 
| 
      
 304 
     | 
    
         
            +
            {
         
     | 
| 
      
 305 
     | 
    
         
            +
                int objectIndex = (int)LnRuntime_GetManagedObjectId(handle);
         
     | 
| 
      
 306 
     | 
    
         
            +
             
     | 
| 
      
 307 
     | 
    
         
            +
                if (method == LNI_REFERENCE_RETAINED) {
         
     | 
| 
      
 308 
     | 
    
         
            +
                    if (count >= 2) {
         
     | 
| 
      
 309 
     | 
    
         
            +
                        m_objectList[objectIndex].strongRef = m_objectList[objectIndex].weakRef;
         
     | 
| 
      
 310 
     | 
    
         
            +
                    }
         
     | 
| 
      
 311 
     | 
    
         
            +
                }
         
     | 
| 
      
 312 
     | 
    
         
            +
                else if (method == LNI_REFERENCE_RELEASED) {
         
     | 
| 
      
 313 
     | 
    
         
            +
                    if (count <= 1) {
         
     | 
| 
      
 314 
     | 
    
         
            +
                        m_objectList[objectIndex].strongRef = Qnil;
         
     | 
| 
      
 315 
     | 
    
         
            +
                    }
         
     | 
| 
      
 316 
     | 
    
         
            +
                }
         
     | 
| 
      
 317 
     | 
    
         
            +
            }
         
     | 
| 
      
 318 
     | 
    
         
            +
             
     | 
| 
      
 319 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::handleRuntimeFinalized()
         
     | 
| 
      
 320 
     | 
    
         
            +
            {
         
     | 
| 
      
 321 
     | 
    
         
            +
                if (instance) {
         
     | 
| 
      
 322 
     | 
    
         
            +
                    instance->m_runtimeAliving = false;
         
     | 
| 
      
 323 
     | 
    
         
            +
                }
         
     | 
| 
      
 324 
     | 
    
         
            +
                LNRB_LOG_D("Runtime finalized.");
         
     | 
| 
      
 325 
     | 
    
         
            +
            }
         
     | 
| 
      
 326 
     | 
    
         
            +
             
     | 
| 
      
 327 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::handleCreateInstanceCallback(int typeInfoId, LnHandle* outHandle)
         
     | 
| 
      
 328 
     | 
    
         
            +
            {
         
     | 
| 
      
 329 
     | 
    
         
            +
                LNRB_LOG_D("start: handleCreateInstanceCallback");
         
     | 
| 
      
 330 
     | 
    
         
            +
                auto* manager = LuminoRubyRuntimeManager::instance;
         
     | 
| 
      
 331 
     | 
    
         
            +
             
     | 
| 
      
 332 
     | 
    
         
            +
                int managedTypeInfoId = -1;
         
     | 
| 
      
 333 
     | 
    
         
            +
                LnTypeInfo_GetManagedTypeInfoId(typeInfoId, &managedTypeInfoId);
         
     | 
| 
      
 334 
     | 
    
         
            +
             
     | 
| 
      
 335 
     | 
    
         
            +
                
         
     | 
| 
      
 336 
     | 
    
         
            +
                printf("managedTypeInfoId: %d\n", managedTypeInfoId);
         
     | 
| 
      
 337 
     | 
    
         
            +
             
     | 
| 
      
 338 
     | 
    
         
            +
                const auto& typeInfo = manager->m_typeInfoList[managedTypeInfoId];
         
     | 
| 
      
 339 
     | 
    
         
            +
                printf("typeInfo.klass: %llu\n", typeInfo.klass);
         
     | 
| 
      
 340 
     | 
    
         
            +
                VALUE obj = rb_funcall(typeInfo.klass, rb_intern("new"), 0, 0);
         
     | 
| 
      
 341 
     | 
    
         
            +
             
     | 
| 
      
 342 
     | 
    
         
            +
                printf("obj: %llu\n", obj);
         
     | 
| 
      
 343 
     | 
    
         
            +
                manager->registerWrapperObject(obj, false);
         
     | 
| 
      
 344 
     | 
    
         
            +
             
     | 
| 
      
 345 
     | 
    
         
            +
             
     | 
| 
      
 346 
     | 
    
         
            +
                *outHandle = manager->getHandle(obj);
         
     | 
| 
      
 347 
     | 
    
         
            +
                printf("outHandle: %d\n", *outHandle);
         
     | 
| 
      
 348 
     | 
    
         
            +
                printf("e handleCreateInstanceCallback\n");
         
     | 
| 
      
 349 
     | 
    
         
            +
             
     | 
| 
      
 350 
     | 
    
         
            +
                
         
     | 
| 
      
 351 
     | 
    
         
            +
                printf("!!!! new Object. Handle:%d (%s)\n", *outHandle, RubyUtils::makeTypeInfoName(CLASS_OF(obj)).c_str());
         
     | 
| 
      
 352 
     | 
    
         
            +
             
     | 
| 
      
 353 
     | 
    
         
            +
                LNRB_LOG_D("end: handleCreateInstanceCallback");
         
     | 
| 
      
 354 
     | 
    
         
            +
            }
         
     | 
| 
      
 355 
     | 
    
         
            +
             
     | 
| 
      
 356 
     | 
    
         
            +
            void LuminoRubyRuntimeManager::dumpInfo() const
         
     | 
| 
      
 357 
     | 
    
         
            +
            {
         
     | 
| 
      
 358 
     | 
    
         
            +
                LnRuntime_DumpInfo();
         
     | 
| 
      
 359 
     | 
    
         
            +
                
         
     | 
| 
      
 360 
     | 
    
         
            +
                std::cout << std::endl;
         
     | 
| 
      
 361 
     | 
    
         
            +
                std::cout << "Ruby alive objects" << std::endl;
         
     | 
| 
      
 362 
     | 
    
         
            +
                std::cout << "----------" << std::endl;
         
     | 
| 
      
 363 
     | 
    
         
            +
             
     | 
| 
      
 364 
     | 
    
         
            +
                for (size_t i = 0; i < m_objectList.size(); i++) {
         
     | 
| 
      
 365 
     | 
    
         
            +
                    const auto& item = m_objectList[i];
         
     | 
| 
      
 366 
     | 
    
         
            +
                    
         
     | 
| 
      
 367 
     | 
    
         
            +
                    if (item.weakRef != Qnil || item.strongRef != Qnil) {
         
     | 
| 
      
 368 
     | 
    
         
            +
                        std::cout << "mid: " << i;
         
     | 
| 
      
 369 
     | 
    
         
            +
             
     | 
| 
      
 370 
     | 
    
         
            +
                        VALUE obj = Qnil;
         
     | 
| 
      
 371 
     | 
    
         
            +
                        if (item.weakRef != Qnil) {
         
     | 
| 
      
 372 
     | 
    
         
            +
                            std::cout << "(weak) ";
         
     | 
| 
      
 373 
     | 
    
         
            +
                            obj = item.weakRef;
         
     | 
| 
      
 374 
     | 
    
         
            +
                        }
         
     | 
| 
      
 375 
     | 
    
         
            +
                        if (item.strongRef != Qnil) {
         
     | 
| 
      
 376 
     | 
    
         
            +
                            std::cout << "(strong) ";
         
     | 
| 
      
 377 
     | 
    
         
            +
                            obj = item.strongRef;
         
     | 
| 
      
 378 
     | 
    
         
            +
                        }
         
     | 
| 
      
 379 
     | 
    
         
            +
             
     | 
| 
      
 380 
     | 
    
         
            +
                        std::cout << "VALUE: " << obj;
         
     | 
| 
      
 381 
     | 
    
         
            +
                        std::cout << "(" << RubyUtils::getClassNameFromObject(obj) << ")" << std::endl;
         
     | 
| 
      
 382 
     | 
    
         
            +
                        std::cout << "  nid(Handle): " << getHandle(obj) << std::endl;
         
     | 
| 
      
 383 
     | 
    
         
            +
                        std::cout << "  TypeInfoName: " << RubyUtils::makeTypeInfoName(CLASS_OF(obj)) << std::endl;
         
     | 
| 
      
 384 
     | 
    
         
            +
                    }
         
     | 
| 
      
 385 
     | 
    
         
            +
                }
         
     | 
| 
      
 386 
     | 
    
         
            +
             
     | 
| 
      
 387 
     | 
    
         
            +
                std::cout << "----------" << std::endl;
         
     | 
| 
      
 388 
     | 
    
         
            +
                std::cout << std::endl;
         
     | 
| 
      
 389 
     | 
    
         
            +
            }
         
     | 
| 
      
 390 
     | 
    
         
            +
             
     | 
| 
      
 391 
     | 
    
         
            +
            extern "C" void InitLuminoRubyRuntimeManager()
         
     | 
| 
      
 392 
     | 
    
         
            +
            {
         
     | 
| 
      
 393 
     | 
    
         
            +
                VALUE manager = rb_eval_string_protect("defined? $lumino_ruby_runtime_manager", NULL);
         
     | 
| 
      
 394 
     | 
    
         
            +
                if (manager == Qnil) {
         
     | 
| 
      
 395 
     | 
    
         
            +
                    // Create new LuminoRubyRuntimeManager.
         
     | 
| 
      
 396 
     | 
    
         
            +
                    g_LuminoRubyRuntimeManagerClass = rb_define_class("LuminoRubyRuntimeManager", rb_cObject);
         
     | 
| 
      
 397 
     | 
    
         
            +
                    g_LuminoRubyRuntimeManager = LuminoRubyRuntimeManager_allocate(g_LuminoRubyRuntimeManagerClass);
         
     | 
| 
      
 398 
     | 
    
         
            +
                    rb_define_readonly_variable("$lumino_ruby_runtime_manager", &g_LuminoRubyRuntimeManager);
         
     | 
| 
      
 399 
     | 
    
         
            +
                }
         
     | 
| 
      
 400 
     | 
    
         
            +
                else {
         
     | 
| 
      
 401 
     | 
    
         
            +
                    // Use defined LuminoRubyRuntimeManager.
         
     | 
| 
      
 402 
     | 
    
         
            +
                    LuminoRubyRuntimeManager::instance = LuminoRubyRuntimeManager::getInstance(manager);
         
     | 
| 
      
 403 
     | 
    
         
            +
                }
         
     | 
| 
      
 404 
     | 
    
         
            +
            }
         
     | 
| 
      
 405 
     | 
    
         
            +
             
     | 
| 
      
 406 
     | 
    
         
            +
            #endif
         
     | 
| 
      
 407 
     | 
    
         
            +
             
     | 
| 
      
 408 
     | 
    
         
            +
             
     | 
| 
      
 409 
     | 
    
         
            +
             
     | 
| 
      
 410 
     | 
    
         
            +
            //==============================================================================
         
     | 
| 
      
 411 
     | 
    
         
            +
            // RubyUtils
         
     | 
| 
      
 412 
     | 
    
         
            +
             
     | 
| 
      
 413 
     | 
    
         
            +
            std::string RubyUtils::getClassNameFromClass(VALUE klass)
         
     | 
| 
      
 414 
     | 
    
         
            +
            {
         
     | 
| 
      
 415 
     | 
    
         
            +
                VALUE v = rb_funcall(klass, rb_intern("name"), 0, 0);
         
     | 
| 
      
 416 
     | 
    
         
            +
                return std::string(StringValuePtr(v));
         
     | 
| 
      
 417 
     | 
    
         
            +
            }
         
     | 
| 
      
 418 
     | 
    
         
            +
             
     | 
| 
      
 419 
     | 
    
         
            +
            std::string RubyUtils::getClassNameFromObject(VALUE obj)
         
     | 
| 
      
 420 
     | 
    
         
            +
            {
         
     | 
| 
      
 421 
     | 
    
         
            +
                VALUE klass = CLASS_OF(obj);
         
     | 
| 
      
 422 
     | 
    
         
            +
                return getClassNameFromClass(klass);
         
     | 
| 
      
 423 
     | 
    
         
            +
            }
         
     | 
| 
      
 424 
     | 
    
         
            +
             
     | 
| 
      
 425 
     | 
    
         
            +
            std::string RubyUtils::makeTypeInfoName(VALUE klass)
         
     | 
| 
      
 426 
     | 
    
         
            +
            {
         
     | 
| 
      
 427 
     | 
    
         
            +
                VALUE v = rb_funcall(klass, rb_intern("name"), 0, 0);
         
     | 
| 
      
 428 
     | 
    
         
            +
                //printf("superclassName: %s\n", StringValuePtr(v2));
         
     | 
| 
      
 429 
     | 
    
         
            +
                std::string name = StringValuePtr(v);
         
     | 
| 
      
 430 
     | 
    
         
            +
             
     | 
| 
      
 431 
     | 
    
         
            +
                // TODO: C++ 側が、LN_OBJECT_IMPLEMENT(Sprite) とか描いただけじゃ FullName で登録されない。
         
     | 
| 
      
 432 
     | 
    
         
            +
                // 対策方法が見つかるまでとりあえず頭消しておく。
         
     | 
| 
      
 433 
     | 
    
         
            +
                if (name.find("Lumino::") == 0) {
         
     | 
| 
      
 434 
     | 
    
         
            +
                    name = name.substr(8);
         
     | 
| 
      
 435 
     | 
    
         
            +
                }
         
     | 
| 
      
 436 
     | 
    
         
            +
             
     | 
| 
      
 437 
     | 
    
         
            +
                return name;
         
     | 
| 
      
 438 
     | 
    
         
            +
            }
         
     | 
| 
      
 439 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,92 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #pragma once
         
     | 
| 
      
 2 
     | 
    
         
            +
            #include <ruby.h>
         
     | 
| 
      
 3 
     | 
    
         
            +
            #include <iostream>
         
     | 
| 
      
 4 
     | 
    
         
            +
            #include <string>
         
     | 
| 
      
 5 
     | 
    
         
            +
            #include <vector>
         
     | 
| 
      
 6 
     | 
    
         
            +
            #include <stack>
         
     | 
| 
      
 7 
     | 
    
         
            +
            #include <unordered_map>
         
     | 
| 
      
 8 
     | 
    
         
            +
            #include "FlatCommon.h"
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            #define LNRB_LOG_D(...) LnLog_PrintA(LN_LOG_LEVEL_DEBUG, "RubyRuntime", __VA_ARGS__)
         
     | 
| 
      
 11 
     | 
    
         
            +
            #define LNRB_LOG_I(...) LnLog_WriteA(LN_LOG_LEVEL_INFO, "RubyRuntime", __VA_ARGS__)
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            typedef VALUE(*ObjectFactoryFunc)(VALUE klass, LnHandle handle);
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            struct TypeInfo
         
     | 
| 
      
 16 
     | 
    
         
            +
            {
         
     | 
| 
      
 17 
     | 
    
         
            +
                VALUE               klass;
         
     | 
| 
      
 18 
     | 
    
         
            +
                ObjectFactoryFunc   factory;
         
     | 
| 
      
 19 
     | 
    
         
            +
            };
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            struct Wrap_RubyObject
         
     | 
| 
      
 22 
     | 
    
         
            +
            {
         
     | 
| 
      
 23 
     | 
    
         
            +
                LnHandle handle;
         
     | 
| 
      
 24 
     | 
    
         
            +
                Wrap_RubyObject() : handle(0) {}
         
     | 
| 
      
 25 
     | 
    
         
            +
            };
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            // 複数の RubyBinding(.so) をまたいで唯一のインスタンス。
         
     | 
| 
      
 28 
     | 
    
         
            +
            // Lumino.RubyExt.generated.cpp とは別の so にするのがイメージしやすいが、
         
     | 
| 
      
 29 
     | 
    
         
            +
            // そうすると require が面倒になるのでひとつの so にまとめている。
         
     | 
| 
      
 30 
     | 
    
         
            +
            class LuminoRubyRuntimeManager
         
     | 
| 
      
 31 
     | 
    
         
            +
            {
         
     | 
| 
      
 32 
     | 
    
         
            +
            public:
         
     | 
| 
      
 33 
     | 
    
         
            +
                static const int InitialListSize = 512;
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                static LuminoRubyRuntimeManager* instance;
         
     | 
| 
      
 36 
     | 
    
         
            +
                static LnLogLevel s_logLevel;
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                void init();
         
     | 
| 
      
 39 
     | 
    
         
            +
                VALUE luminoModule() const { return m_luminoModule; }
         
     | 
| 
      
 40 
     | 
    
         
            +
                VALUE eventSignalClass() const { return m_eventSignalClass; }
         
     | 
| 
      
 41 
     | 
    
         
            +
                VALUE wrapObjectForGetting(LnHandle handle, bool retain = true);
         
     | 
| 
      
 42 
     | 
    
         
            +
                LnHandle getHandle(VALUE value) const;
         
     | 
| 
      
 43 
     | 
    
         
            +
                int registerTypeInfo(VALUE klass, ObjectFactoryFunc factory);
         
     | 
| 
      
 44 
     | 
    
         
            +
                void registerWrapperObject(VALUE obj, bool forNativeGetting);
         
     | 
| 
      
 45 
     | 
    
         
            +
                void unregisterWrapperObject(LnHandle handle);
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                // for generator interface
         
     | 
| 
      
 48 
     | 
    
         
            +
                static LuminoRubyRuntimeManager* getInstance(VALUE managerInstance);
         
     | 
| 
      
 49 
     | 
    
         
            +
                static void gc_mark(LuminoRubyRuntimeManager* obj);
         
     | 
| 
      
 50 
     | 
    
         
            +
                static void handleReferenceChangedStatic(LnHandle handle, int method, int count);
         
     | 
| 
      
 51 
     | 
    
         
            +
                void handleReferenceChanged(LnHandle handle, int method, int count);
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                static void handleRuntimeFinalized();
         
     | 
| 
      
 54 
     | 
    
         
            +
                static void handleCreateInstanceCallback(int typeInfoId, LnHandle* outHandle);
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                void dumpInfo() const;
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                // TODO: internal
         
     | 
| 
      
 59 
     | 
    
         
            +
                std::unordered_map<std::string, int> m_userDefinedClassTypeIdMap;
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            public: // TODO:
         
     | 
| 
      
 62 
     | 
    
         
            +
                struct ObjectReferenceItem
         
     | 
| 
      
 63 
     | 
    
         
            +
                {
         
     | 
| 
      
 64 
     | 
    
         
            +
                    VALUE weakRef;
         
     | 
| 
      
 65 
     | 
    
         
            +
                    VALUE strongRef;
         
     | 
| 
      
 66 
     | 
    
         
            +
                };
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                VALUE m_luminoModule;
         
     | 
| 
      
 69 
     | 
    
         
            +
                VALUE m_eventSignalClass;
         
     | 
| 
      
 70 
     | 
    
         
            +
                VALUE m_objectClass;
         
     | 
| 
      
 71 
     | 
    
         
            +
                std::vector<TypeInfo> m_typeInfoList;
         
     | 
| 
      
 72 
     | 
    
         
            +
                std::vector<ObjectReferenceItem> m_objectList;
         
     | 
| 
      
 73 
     | 
    
         
            +
                std::stack<int> m_objectListIndexStack;
         
     | 
| 
      
 74 
     | 
    
         
            +
                bool m_runtimeAliving;
         
     | 
| 
      
 75 
     | 
    
         
            +
            };
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            class RubyUtils
         
     | 
| 
      
 78 
     | 
    
         
            +
            {
         
     | 
| 
      
 79 
     | 
    
         
            +
            public:
         
     | 
| 
      
 80 
     | 
    
         
            +
                static std::string getClassNameFromClass(VALUE klass);
         
     | 
| 
      
 81 
     | 
    
         
            +
                static std::string getClassNameFromObject(VALUE klass);
         
     | 
| 
      
 82 
     | 
    
         
            +
                static std::string makeTypeInfoName(VALUE klass);
         
     | 
| 
      
 83 
     | 
    
         
            +
            };
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            inline VALUE LNRB_HANDLE_WRAP_TO_VALUE(LnHandle handle) { return LuminoRubyRuntimeManager::instance->wrapObjectForGetting(handle); }
         
     | 
| 
      
 86 
     | 
    
         
            +
            inline VALUE LNRB_HANDLE_WRAP_TO_VALUE(LnHandle handle, VALUE& accessorCache) { return LuminoRubyRuntimeManager::instance->wrapObjectForGetting(handle); }
         
     | 
| 
      
 87 
     | 
    
         
            +
            inline VALUE LNRB_HANDLE_WRAP_TO_VALUE(LnHandle handle, std::vector<VALUE>& accessorCache, int index) { return LuminoRubyRuntimeManager::instance->wrapObjectForGetting(handle); }
         
     | 
| 
      
 88 
     | 
    
         
            +
            inline void LNRB_SAFE_UNREGISTER_WRAPPER_OBJECT(LnHandle handle) { if ( LuminoRubyRuntimeManager::instance) LuminoRubyRuntimeManager::instance->unregisterWrapperObject(handle); }
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
            inline VALUE LNRB_HANDLE_WRAP_TO_VALUE_NO_RETAIN(LnHandle handle) { return LuminoRubyRuntimeManager::instance->wrapObjectForGetting(handle, false); }
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
             
     |