상속: MonoBehaviour
예제 #1
0
        public static void Initialize()
        {
            ContainerModule.Initialize();
            CoreModule.Initialize();
            MathModule.Initialize();
            EngineModule.Initialize();
            InputModule.Initialize();
            IOModule.Initialize();
            ResourceModule.Initialize();
            AudioModule.Initialize();
            GraphicsModule.Initialize();
            SceneModule.Initialize();
            Atomic2DModule.Initialize();
            Atomic3DModule.Initialize();
            NavigationModule.Initialize();
            NetworkModule.Initialize();
            PhysicsModule.Initialize();
            EnvironmentModule.Initialize();
            UIModule.Initialize();

            AtomicPlayer.PlayerModule.Initialize();

            AtomicInterop.Initialize();

            atomicsharp_initialize();

            initSubsystems();
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        static void StartPython()
        {
            try
            {
                pythonMutex_.WaitOne();

                pythonEngine_ = new PythonEngine();

                string   dll = new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName + "\\WwwProxy.dll";
                Assembly wwwProxyAssembly = Assembly.LoadFile(dll);
                pythonEngine_.LoadAssembly(wwwProxyAssembly);

                wwwPyFilterMod_ = pythonEngine_.CreateModule("wwwpyfilter", true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
                Console.WriteLine();
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                pythonMutex_.ReleaseMutex();
            }
        }
예제 #3
0
        static void RunPythonScript(string filePath)
        {
            string file = Path.GetFileName(filePath);

            EngineModule module = s_pythonEngine.CreateModule("<" + file + ">", false);

            try
            {
                string wrapCode =
                    @"import sys
try:
	execfile(r"""     + filePath + @""")
except Exception:
	etype, value, tb = sys.exc_info()
	
	print ""%s: %s"" % (etype.__name__, value)
	
	while tb is not None:
		f = tb.tb_frame
		lineno = tb.tb_lineno
		co = f.f_code
		filename = co.co_filename
		name = co.co_name
		print '  File ""%s"", line %d, in %s' % (filename,lineno,name)
		tb = tb.tb_next
";
                s_pythonEngine.Execute(wrapCode, module);
            }
            catch (Exception e)
            {
                ChiConsole.WriteError("Error running script " + file, e, file);
            }
        }
예제 #4
0
        public static bool RunModule(string path, string file, string module, bool publish, Dictionary <string, object> globals)
        {
            string scriptFile = ResolvePath(path) + file;

            if (!scriptFile.EndsWith(".py"))
            {
                return(false);
            }

            try
            {
                log.InfoFormat("Running module file '{0}' in module '{1}'", scriptFile, module);
                EngineModule mod = interpreter.CreateModule(module, globals, publish);
                // save the module so we can use it later
                modules[module] = mod;
                interpreter.ExecuteFile(scriptFile, mod);

                log.InfoFormat("Ran script file '{0}' in module '{1}'", scriptFile, module);
                return(true);
            }
            catch (Exception ex)
            {
                LogUtil.ExceptionLog.WarnFormat("Exception when running script file '{0}' in module '{1}'", scriptFile, module);
                LogUtil.ExceptionLog.WarnFormat("Python Stack Trace: {0}", interpreter.FormatException(ex));
                LogUtil.ExceptionLog.WarnFormat("Full Stack Trace: {0}", ex.ToString());
                return(false);
            }
        }
예제 #5
0
        public static void Initialize()
        {
            // Atomic Modules
            CoreModule.Initialize();
            MathModule.Initialize();
            EngineModule.Initialize();
            InputModule.Initialize();
            IOModule.Initialize();
            ResourceModule.Initialize();
            AudioModule.Initialize();
            GraphicsModule.Initialize();
            SceneModule.Initialize();
            Atomic2DModule.Initialize();
            NavigationModule.Initialize();
            NetworkModule.Initialize();
            PhysicsModule.Initialize();
            EnvironmentModule.Initialize();
            UIModule.Initialize();

#if ATOMIC_DESKTOP
            IPCModule.Initialize();
#endif

            AtomicAppModule.Initialize();
            ScriptModule.Initialize();

            AtomicNETScriptModule.Initialize();
            AtomicNETNativeModule.Initialize();

            PlayerModule.Initialize();

            coreDelegates = new CoreDelegates();
            coreDelegates.eventDispatch  = NativeCore.EventDispatch;
            coreDelegates.updateDispatch = NativeCore.UpdateDispatch;

            IntPtr coreptr = csi_Atomic_NETCore_Initialize(ref coreDelegates);

            NETCore core = (coreptr == IntPtr.Zero ? null : NativeCore.WrapNative <NETCore>(coreptr));

            if (core != null)
            {
                AtomicNET.RegisterSubsystem("NETCore", core);
            }

            context = core.Context;

            NativeCore.Initialize();
            CSComponentCore.Initialize();

#if ATOMIC_DESKTOP
            string[] arguments = Environment.GetCommandLineArgs();
            foreach (string arg in arguments)
            {
                AppBase.AddArgument(arg);
            }
#endif
        }
예제 #6
0
        public static void SetVariable(string moduleName, string name, object val)
        {
            //if (interpreter.Sys.modules.ContainsKey(moduleName))
            {
                EngineModule module = modules[moduleName];

                module.Globals[name] = val;
            }
        }
        public void RotateTo_DoesNotOvershoot(RotationSpeed speed)
        {
            var rotorPair = new MockFacingRotorPair {
                CurrentAngleDegrees = 20
            };

            var module = new EngineModule("Test", rotorPair, new RotorLimits(0, 130), new IMyThrust[0]);

            // 10% frame jitter.
            const float jitter = RotationSpeed.TimeStepSeconds * 0.1f;
            var         random = new Random();

            var operation       = module.RotateTo(90, speed);
            var rotorVelocities = new List <float>();

            // First iteration performs setup, so the clock doesn't need to tick until the next.
            while (operation.MoveNext())
            {
                rotorVelocities.Add(rotorPair.TargetVelocityDegreesPerSecond);
                // Accuracy ranges:
                if (rotorVelocities.Count < speed.TimeTargetSeconds * 6)
                {
                    // No target within deadline.
                }
                else if (rotorVelocities.Count < speed.TimeTargetSeconds * 12)
                {
                    // After deadline, expect to be within 5 degrees.
                    Assert.That(rotorPair.CurrentAngleDegrees, Is.EqualTo(90).Within(5f));
                }
                else
                {
                    // After double deadline, expect to be within 0.1 degrees.
                    Assert.That(rotorPair.CurrentAngleDegrees, Is.EqualTo(90).Within(0.1f));
                }
                if (!operation.Current)
                {
                    break;                      // Completed.
                }
                var step = TimeSpan.FromSeconds(MathHelper.Lerp(-jitter, jitter, random.NextDouble()) + RotationSpeed.TimeStepSeconds);
                rotorPair.Step(step);
                Clock.AddTime(step);
            }

            TestContext.WriteLine("Iterations: {0} ({1} sec)", rotorVelocities.Count, rotorVelocities.Count / 6);
            Assert.That(rotorPair.CurrentAngleDegrees, Is.EqualTo(90).Within(0.1f));
            Assert.That(rotorVelocities, Has.None.Negative);
            Assert.That(rotorVelocities, Has.Count.LessThanOrEqualTo(60));
        }
예제 #8
0
        public static void Initialize()
        {
            // Atomic Modules
            CoreModule.Initialize();
            MathModule.Initialize();
            EngineModule.Initialize();
            InputModule.Initialize();
            IOModule.Initialize();
            ResourceModule.Initialize();
            AudioModule.Initialize();
            GraphicsModule.Initialize();
            SceneModule.Initialize();
            Atomic2DModule.Initialize();
            Atomic3DModule.Initialize();
            NavigationModule.Initialize();
            NetworkModule.Initialize();
            PhysicsModule.Initialize();
            EnvironmentModule.Initialize();
            UIModule.Initialize();
            IPCModule.Initialize();
            AtomicAppModule.Initialize();
            ScriptModule.Initialize();

            AtomicNETScriptModule.Initialize();
            AtomicNETNativeModule.Initialize();

            PlayerModule.Initialize();

            coreDelegates = new CoreDelegates();
            coreDelegates.eventDispatch  = NativeCore.EventDispatch;
            coreDelegates.updateDispatch = NativeCore.UpdateDispatch;

            IntPtr coreptr = csb_Atomic_NETCore_Initialize(ref coreDelegates);

            NETCore core = (coreptr == IntPtr.Zero ? null : NativeCore.WrapNative <NETCore>(coreptr));

            if (core != null)
            {
                AtomicNET.RegisterSubsystem("NETCore", core);
            }

            context = core.Context;

            NativeCore.Initialize();
            CSComponentCore.Initialize();
        }
        /// <summary>
        /// Creates a random mobile object at the given location.
        /// </summary>
        private void Create(
			Segment segment, MersenneRandom random, float x, float y)
        {
            // Figure out the type
            Mobile m = new HousingBubble();
            int pick = random.Next(10);

            if (pick == 0)
                m = new ContainmentModule();
            else if (pick < 5)
                m = new EngineModule();

            // Create a housing bubble
            PointF p = segment.ChildJunctionPoint;
            m.Point = new PointF(p.X + x, p.Y + y);
            m.Radius = random.NextSingle(5, 20);

            // Add it
            segment.ParentJunction.Mobiles.Add(m);
        }
예제 #10
0
        public override Sentence run(Sentence result)
        {
            EngineModule module = Python.python.default_module;

            module.Globals["grammar"] = library;
            if (result != null)
            {
                module.Globals["word"] = result;
                //module.Globals["result"] = result.result;
            }

            foreach (string key in Global.plugins.Keys)
            {
                Plugin plugin = Global.plugins[key];
                module.Globals[key.ToLower()] = plugin;
            }

            //Feedback.print(text);
            Python.python.Run(code);
            return(null);
        }
예제 #11
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        static void StopPython()
        {
            try
            {
                pythonMutex_.WaitOne();

                wwwPyFilterMod_ = null;

                pythonEngine_.Shutdown();
                pythonEngine_ = null;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
                Console.WriteLine();
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                pythonMutex_.ReleaseMutex();
            }
        }
예제 #12
0
        /// <summary>
        ///   Run the script file in the given module.  If module is null,
        ///   run the script in the default context (__main__).
        /// </summary>
        /// <param name="scriptFile">the name of the script file</param>
        /// <param name="module">the name of the module where the script will
        ///                      be run, or null to run in __main__</param>
        /// <returns>true if the script was run successfully</returns>
        private static bool RunFileHelper(string scriptFile, string module, bool publish)
        {
            if (!scriptFile.EndsWith(".py"))
            {
                return(false);
            }

            try {
                if (module == null || module == "")
                {
                    log.InfoFormat("Executing script file '{0}'", scriptFile);
                    interpreter.ExecuteFile(scriptFile);
                }
                else
                {
                    log.InfoFormat("Running script file '{0}' in module '{1}'", scriptFile, module);
                    EngineModule mod = interpreter.CreateModule(module, publish);
                    // save the module so we can use it later
                    modules[module] = mod;
                    interpreter.ExecuteFile(scriptFile, mod);
                }
                log.InfoFormat("Ran script file '{0}' in module '{1}'", scriptFile, module);
                return(true);
            } catch (IronPython.Runtime.Exceptions.PythonSyntaxErrorException ex) {
                LogUtil.ExceptionLog.ErrorFormat("Failed to run script file '{0}' in module '{1}'", scriptFile, module);
                LogUtil.ExceptionLog.ErrorFormat("PythonSyntaxErrorException at {0}:{1}: {2}", ex.FileName, ex.Line, ex.Message);
                // log.Warn(ex.ToString());
                return(false);
            } catch (Exception ex) {
                // interpreter.DumpException(ex);
                LogUtil.ExceptionLog.ErrorFormat("Exception when running script file '{0}' in module '{1}'", scriptFile, module);
                LogUtil.ExceptionLog.ErrorFormat("Python Stack Trace: {0}", interpreter.FormatException(ex));
                LogUtil.ExceptionLog.ErrorFormat("Full Stack Trace: {0}", ex.ToString());
                return(false);
                // } finally {
                // interpreter.DumpDebugInfo();
            }
        }
예제 #13
0
 static public void Initialize()
 {
     ContainerModule.Initialize();
     CoreModule.Initialize();
     MathModule.Initialize();
     EngineModule.Initialize();
     InputModule.Initialize();
     IOModule.Initialize();
     ResourceModule.Initialize();
     AudioModule.Initialize();
     GraphicsModule.Initialize();
     SceneModule.Initialize();
     Atomic2DModule.Initialize();
     Atomic3DModule.Initialize();
     NavigationModule.Initialize();
     NetworkModule.Initialize();
     PhysicsModule.Initialize();
     EnvironmentModule.Initialize();
     UIModule.Initialize();
     NETCoreModule.Initialize();
     NETScriptModule.Initialize();
     AtomicPlayer.PlayerModule.Initialize();
 }
예제 #14
0
        private PuffinPython()
        {
            if (srcDir == null || srcDir.Length == 0)
            {
                srcDir = @"c:\bbd\python\source";
            }
            if (runDir == null || runDir.Length == 0)
            {
                runDir = @"c:\bbd\python\runtime";
            }
            engine = new PythonEngine();
            sbout  = new MemoryStream();
            sberr  = new MemoryStream();
            loaded = new StringBuilder();
            EngineModule agent = engine.CreateModule("agentModule", true);

            puffinAgent = new PuffinAgent();
            agent.Globals.Add("agent", puffinAgent);
            engine.SetStandardOutput(sbout);
            engine.SetStandardError(sberr);
            engine.AddToPath(runDir);
            WritePy("INTRINSICS", Code());
            WriteDB();
        }
예제 #15
0
    // Use this for initialization
    void Start()
    {
        //Camera camera = Camera.main;
        //camera.orthographicSize = 640 / Screen.width * Screen.height / 2;
        if (shipName == "")
        {
            shipName = ShipDefinitions.generateName();
        }
        GameObject parent = GameObject.Find("GameLogic").GetComponent <PrefabHost>().getEmptyObject();

        this.health = GameObject.Find("GameLogic").GetComponent <PrefabHost>().getHealthObject();
        this.ammo   = GameObject.Find("GameLogic").GetComponent <PrefabHost>().getAmmoObject();
        this.text   = GameObject.Find("GameLogic").GetComponent <PrefabHost>().getLabelObject();
        health.transform.SetParent(parent.transform);
        ammo.transform.SetParent(parent.transform);
        text.transform.SetParent(parent.transform);
        transform.SetParent(parent.transform);
        text.GetComponent <ShipLabel>().setText(shipName);
        health.GetComponent <HealthBar>().setTarget(gameObject);
        ammo.GetComponent <AmmoBar>().setTarget(gameObject);
        text.GetComponent <ShipLabel>().setTarget(gameObject);
        if (inventory == null)
        {
            inventory = new List <ItemAbstract>();
        }
        GameObject engineObj;

        if (engType == ShipDefinitions.EngineType.Engine1)
        {
            engineObj = GameObject.Find("GameLogic").GetComponent <PrefabHost>()
                        .getEngineLvl1Object();
        }
        else
        {
            engineObj = GameObject.Find("GameLogic").GetComponent <PrefabHost>()
                        .getEngineLvl2Object();
        }
        engineObj.transform.parent     = gameObject.transform;
        engineObj.transform.position   = gameObject.transform.position;
        engineObj.transform.localScale = new Vector3(1.5f, 1.5f, 0);

        engine = engineObj.GetComponent <EngineModule>();
        switch (weapType)
        {
        case ShipDefinitions.WeaponType.Crown:
            weapon = gameObject.AddComponent <CrownMod>();
            break;

        case ShipDefinitions.WeaponType.Laser:
            weapon = gameObject.AddComponent <PewPewLaserMod>();
            break;

        case ShipDefinitions.WeaponType.Missile:
            weapon = gameObject.AddComponent <MissileMod>();
            break;

        case ShipDefinitions.WeaponType.Flame:
            weapon = gameObject.AddComponent <FlameMod>();
            break;

        default:
            weapon = gameObject.AddComponent <DummyFiringMod>();
            break;
        }

        foreach (ItemAbstract item in inventory)
        {
            if (WeaponItem.isWeaponType(item.getType()))
            {
                weapon.applyBuff(item);
            }
            else if (EngineItem.isEngineType(item.getType()))
            {
                engine.applyBuff(item);
            }
        }

        ShipDefinitions.Faction faction = ShipDefinitions.stringToFaction(gameObject.tag);
        if (faction == ShipDefinitions.Faction.Enemy)
        {
            if (shipType == ShipDefinitions.ShipType.Ruby)
            {
                SpriteRenderer spr = gameObject.GetComponent <SpriteRenderer>();
                if (spr == null)
                {
                    spr = gameObject.AddComponent <SpriteRenderer>();
                }
                spr.sprite = GameObject.Find("GameLogic").GetComponent <PrefabHost>().
                             shipRubyPirateSprite;
                gameObject.AddComponent <Animator>().runtimeAnimatorController
                    = GameObject.Find("GameLogic").GetComponent <PrefabHost>().
                      shipRubyPirateAnimator;
            }
            else
            {
                SpriteRenderer spr = gameObject.GetComponent <SpriteRenderer>();
                if (spr == null)
                {
                    spr = gameObject.AddComponent <SpriteRenderer>();
                }
                spr.sprite = GameObject.Find("GameLogic").GetComponent <PrefabHost>().
                             shipPeacockPirateSprite;
                gameObject.AddComponent <Animator>().runtimeAnimatorController
                    = GameObject.Find("GameLogic").GetComponent <PrefabHost>().
                      shipPeacockPirateAnimator;
            }
        }
        else
        {
            if (shipType == ShipDefinitions.ShipType.Ruby)
            {
                SpriteRenderer spr = gameObject.GetComponent <SpriteRenderer>();
                if (spr == null)
                {
                    spr = gameObject.AddComponent <SpriteRenderer>();
                }
                spr.sprite = GameObject.Find("GameLogic").GetComponent <PrefabHost>().
                             shipRubySprite;
                gameObject.AddComponent <Animator>().runtimeAnimatorController
                    = GameObject.Find("GameLogic").GetComponent <PrefabHost>().
                      shipRubyAnimator;
            }
            else
            {
                SpriteRenderer spr = gameObject.GetComponent <SpriteRenderer>();
                if (spr == null)
                {
                    spr = gameObject.AddComponent <SpriteRenderer>();
                }
                spr.sprite = GameObject.Find("GameLogic").GetComponent <PrefabHost>().
                             shipPeacockSprite;
                gameObject.AddComponent <Animator>().runtimeAnimatorController
                    = GameObject.Find("GameLogic").GetComponent <PrefabHost>().
                      shipPeacockAnimator;
            }
        }

        gameObject.AddComponent <BoxCollider2D>();
        gameObject.GetComponent <BoxCollider2D>().isTrigger = true;

        //string id = shipName.Substring(shipName.Length - 4);
        parent.name     = "Parent-" + shipName;
        gameObject.name = "Ship-" + shipName;
        health.name     = "Health-" + shipName;
        ammo.name       = "Ammo-" + shipName;
        text.name       = "Text-" + shipName;
        initialized     = true;
    }
예제 #16
0
 /// <summary>
 /// Пакеты для сервера
 /// </summary>
 public static void SetSendPacket(byte value) => EngineModule.Write((IntPtr)Offsets.OSendPacket, value);