internal InterfaceHandler()
        {
            Translation = new Com.Latipium.Core.Tuple <float, float, float>();
            Rotation    = new Com.Latipium.Core.Tuple <float, float>();
            LatipiumModule graphics = ModuleFactory.FindModule("Com.Latipium.Modules.Graphics");

            if (graphics != null)
            {
                graphics.AddEvent("MouseMoved", (Action <int, int, int, int>)HandleMouse);
                Action <Action <int, int>, long> AddKeyboardBinding = graphics.GetProcedure <Action <int, int>, long>("AddKeyboardBinding");
                if (AddKeyboardBinding != null)
                {
                    AddKeyboardBinding(HandleKeyboard, 0);
                }
                graphics.InvokeProcedure("HideCursor");
            }
            int x;
            int y;

            CenterScreen(out x, out y);
            Cursor.Position = new Point(x, y);
        }
Exemple #2
0
        /// <summary>
        /// Launches Latipium once inside the sandbox.
        /// </summary>
        /// <param name="startMod">The module to call Start() on inside the sandbox.</param>
        /// <param name="customIO">The path to the custom I/O module, or <c>null</c> to use the default I/O module.</param>
        /// <param name="logConfig">The path to the configuration file for the logger</param>
        public void Launch(string startMod, string customIO, string logConfig)
        {
            new FileIOPermission(PermissionState.Unrestricted).Assert();
            XmlConfigurator.Configure(new FileInfo(logConfig));
            ILog Log = LogManager.GetLogger(typeof(StartObject));

            Log.Info("Sandbox started!");
            customIO = Path.GetFullPath(customIO);
            Assembly asm = Assembly.LoadFile(customIO);

            CodeAccessPermission.RevertAssert();
            AssemblyLoader.Init(asm);
            LatipiumModule mod = ModuleFactory.FindModule(startMod);

            if (mod == null)
            {
                Log.Error("Unable to find startup module.");
            }
            else
            {
                mod.InvokeProcedure("Start");
            }
        }
Exemple #3
0
        public void Start()
        {
            LatipiumModule network = ModuleFactory.FindModule("Com.Latipium.Modules.Network");
            LatipiumModule physics = ModuleFactory.FindModule("Com.Latipium.Modules.Physics");
            // LatipiumModule player = ModuleFactory.FindModule("Com.Latipium.Modules.Player");
            LatipiumModule worldGen = ModuleFactory.FindModule("Com.Latipium.Modules.World.Generator");
            LatipiumModule worldSer = ModuleFactory.FindModule("Com.Latipium.Modules.World.Serialization");

            if (network == null)
            {
                Log.Error("Unable to find network module");
            }
            else
            {
                LatipiumObject world = null;
                if (worldSer != null)
                {
                    world = worldSer.InvokeFunction <LatipiumObject>("Load");
                }
                if (world == null && worldGen != null)
                {
                    world = worldGen.InvokeFunction <LatipiumObject>("Generate");
                }
                Thread physicsThread = null;
                Thread parent        = null;
                if (physics != null)
                {
                    physicsThread = new Thread(() => {
                        physics.InvokeProcedure("Initialize");
                        if (world != null)
                        {
                            physics.InvokeProcedure <LatipiumObject>("LoadWorld", world);
                        }
                        try {
                            physics.InvokeProcedure("Loop");
                        } catch (ThreadInterruptedException) {
                        } finally {
                            physics.InvokeProcedure("Destroy");
                            if (parent != null)
                            {
                                parent.Interrupt();
                            }
                        }
                    });
                    physicsThread.Start();
                }
                network.InvokeProcedure("InitializeServer");
                if (world != null)
                {
                    network.InvokeProcedure <LatipiumObject>("LoadWorld", world);
                }
                try {
                    network.InvokeProcedure("Loop");
                } finally {
                    network.InvokeProcedure("Destroy");
                    if (physicsThread != null)
                    {
                        physicsThread.Interrupt();
                        try {
                            Thread.Sleep(int.MaxValue);
                        } catch (ThreadInterruptedException) {
                        }
                    }
                    if (world != null && worldSer != null)
                    {
                        worldSer.InvokeProcedure <LatipiumObject>("Save", world);
                    }
                }
            }
        }
        public void Start()
        {
            LatipiumModule auth     = ModuleFactory.FindModule("Com.Latipium.Modules.Authentication");
            LatipiumModule graphics = ModuleFactory.FindModule("Com.Latipium.Modules.Graphics");
            LatipiumModule physics  = ModuleFactory.FindModule("Com.Latipium.Modules.Physics");
            LatipiumModule player   = ModuleFactory.FindModule("Com.Latipium.Modules.Player");
            LatipiumModule worldGen = ModuleFactory.FindModule("Com.Latipium.Modules.World.Generator");
            LatipiumModule worldSer = ModuleFactory.FindModule("Com.Latipium.Modules.World.Serialization");

            if (graphics == null)
            {
                Log.Error("Unable to find graphics module");
            }
            else
            {
                string         name  = null;
                LatipiumObject world = null;
                if (worldGen != null || worldSer != null)
                {
                    if (auth == null)
                    {
                        name = "Player";
                    }
                    else
                    {
                        name = auth.InvokeFunction <string>("GetUsername");
                    }
                    if (worldSer != null)
                    {
                        world = worldSer.InvokeFunction <LatipiumObject>("Load");
                    }
                    if (world == null && worldGen != null)
                    {
                        world = worldGen.InvokeFunction <LatipiumObject>("Generate");
                    }
                }
                LatipiumObject p = null;
                if (world != null)
                {
                    p = world.InvokeFunction <string, LatipiumObject>("GetPlayer", name);
                    if (player != null && p != null)
                    {
                        player.InvokeProcedure <LatipiumObject>("HandleFor", p);
                    }
                }
                Thread physicsThread = null;
                Thread parent        = null;
                if (physics != null)
                {
                    physicsThread = new Thread(() => {
                        physics.InvokeProcedure("Initialize");
                        if (world != null)
                        {
                            physics.InvokeProcedure <LatipiumObject>("LoadWorld", world);
                        }
                        try {
                            physics.InvokeProcedure("Loop");
                        } catch (ThreadInterruptedException) {
                        } finally {
                            physics.InvokeProcedure("Destroy");
                            if (parent != null)
                            {
                                parent.Interrupt();
                            }
                        }
                    });
                    physicsThread.Start();
                }
                graphics.InvokeProcedure("Initialize");
                if (world != null)
                {
                    graphics.InvokeProcedure <LatipiumObject>("LoadWorld", world);
                    if (p != null)
                    {
                        graphics.InvokeProcedure <LatipiumObject>("SetPlayer", p);
                    }
                }
                try {
                    graphics.InvokeProcedure("Loop");
                } finally {
                    graphics.InvokeProcedure("Destroy");
                    if (physicsThread != null)
                    {
                        parent = Thread.CurrentThread;
                        physicsThread.Interrupt();
                        try {
                            Thread.Sleep(int.MaxValue);
                        } catch (ThreadInterruptedException) {
                        }
                    }
                    if (world != null && worldSer != null)
                    {
                        worldSer.InvokeProcedure <LatipiumObject>("Save", world);
                    }
                }
            }
        }
        public void Start()
        {
            LatipiumModule auth     = ModuleFactory.FindModule("Com.Latipium.Modules.Authentication");
            LatipiumModule graphics = ModuleFactory.FindModule("Com.Latipium.Modules.Graphics");
            LatipiumModule network  = ModuleFactory.FindModule("Com.Latipium.Modules.Network");
            LatipiumModule player   = ModuleFactory.FindModule("Com.Latipium.Modules.Player");
            LatipiumModule world    = ModuleFactory.FindModule("Com.Latipium.Modules.World");

            if (graphics == null)
            {
                Log.Error("Unable to find graphics module");
            }
            else
            {
                string         name = null;
                LatipiumObject w    = null;
                if (world != null)
                {
                    if (auth == null)
                    {
                        name = "Player";
                    }
                    else
                    {
                        name = auth.InvokeFunction <string>("GetUsername");
                    }
                    w = world.InvokeFunction <LatipiumObject>("CreateWorld");
                }
                Thread networkThread = null;
                if (network != null)
                {
                    Thread parent = Thread.CurrentThread;
                    networkThread = new Thread(() => {
                        network.InvokeProcedure("InitializeClient");
                        if (world != null)
                        {
                            network.InvokeProcedure <LatipiumObject>("LoadWorld", w);
                        }
                        parent.Interrupt();
                        try {
                            network.InvokeProcedure("Loop");
                        } catch (ThreadInterruptedException) {
                        } finally {
                            network.InvokeProcedure("Destroy");
                        }
                    });
                    networkThread.Start();
                    try {
                        // Will be interrupted when the network loads
                        Thread.Sleep(int.MaxValue);
                    } catch (ThreadInterruptedException) {
                    }
                }
                LatipiumObject p = null;
                if (w != null)
                {
                    p = w.InvokeFunction <string, LatipiumObject>("GetPlayer", name);
                    if (player != null && p != null)
                    {
                        player.InvokeProcedure <LatipiumObject>("HandleFor", p);
                    }
                }
                graphics.InvokeProcedure("Initialize");
                if (world != null)
                {
                    graphics.InvokeProcedure <LatipiumObject>("LoadWorld", w);
                    if (p != null)
                    {
                        graphics.InvokeProcedure <LatipiumObject>("SetPlayer", p);
                    }
                }
                try {
                    graphics.InvokeProcedure("Loop");
                } finally {
                    graphics.InvokeProcedure("Destroy");
                    if (networkThread != null)
                    {
                        networkThread.Interrupt();
                    }
                }
            }
        }