/// <summary>
        /// Loads the object.
        /// </summary>
        public override void Load()
        {
            LatipiumModule          worldObjects = ModuleFactory.FindModule("Com.Latipium.Modules.World.Objects");
            Action <LatipiumObject> load         = worldObjects.GetProcedure <LatipiumObject>("LoadObject");

            load(new CubeObject());
        }
示例#2
0
        private static LatipiumModule GetModule(string type)
        {
            LatipiumModule mod      = null;
            int            priority = int.MinValue;

            foreach (LatipiumModule impl in ModuleLoader.GetModules())
            {
                for (int i = 0; i < impl.Provides
                     .Length; ++i)
                {
                    if (impl.Provides[i] == type)
                    {
                        if (impl.Priorities[i] > priority)
                        {
                            mod      = impl;
                            priority = impl.Priorities[i];
                        }
                        break;
                    }
                }
            }
            if (mod != null)
            {
                mod.Load(type);
            }
            return(mod);
        }
示例#3
0
 /// <summary>
 /// Loads the player module.
 /// </summary>
 public override void Load()
 {
     if (PlayerModule.Loaded)
     {
         LatipiumModule          worldObjects = ModuleFactory.FindModule("Com.Latipium.Modules.World.Objects");
         Action <LatipiumObject> load         = worldObjects.GetProcedure <LatipiumObject>("LoadObject");
         load(Instance = new PlayerObject());
     }
 }
示例#4
0
        /// <summary>
        /// Initializes the loader and loads all assemblies.
        /// </summary>
        /// <param name="io">The assembly containing the io module</param>
        public static void Init(Assembly io)
        {
            List <Assembly> assemblies = new List <Assembly>();

            // Register the IO assembly first so we can use it
            ModuleLoader.RegisterAssembly(io);
            assemblies.Add(io);
            Assemblies[io.GetName().Name] = io;
            LatipiumModule mod = ModuleFactory.FindModule("Com.Latipium.Modules.IO");

            if (mod != null)
            {
                Func <string, FileMode, FileAccess, Stream> Open = mod.GetFunction <string, FileMode, FileAccess, Stream>("Open");
                if (Open != null)
                {
                    // Pull the list of mods from the IO assembly
                    foreach (string file in mod.InvokeFunction <IEnumerable <string> >("GetModules"))
                    {
                        try {
                            Stream stream = Open(file, FileMode.Open, FileAccess.Read);
                            if (stream == null)
                            {
                                Log.ErrorFormat("IO module was unable to open file {0}", file);
                            }
                            else
                            {
                                byte[] buffer = new byte[stream.Length];
                                stream.Read(buffer, 0, buffer.Length);
                                stream.Close();
                                stream.Dispose();
                                Assembly asm = Assembly.Load(buffer);
                                assemblies.Add(asm);
                                Assemblies[asm.GetName().Name] = asm;
                            }
                        } catch (Exception ex) {
                            Log.Error(ex);
                        }
                    }
                }
            }
            AppDomain.CurrentDomain.AssemblyResolve += ResolveDependency;
            foreach (Assembly asm in assemblies)
            {
                ModuleLoader.RegisterAssembly(asm);
            }
            LoaderLoader.LoadLoaderModules();
            foreach (Assembly asm in assemblies)
            {
                LoaderLoader.LoadAssembly(asm);
            }
        }
示例#5
0
        /// <summary>
        /// Loads the module.
        /// </summary>
        /// <param name="name">The name of the module.</param>
        public override void Load(string name)
        {
            Renderer = new GameRenderer();
            Renderer.Add(new ColorArrayRenderer());
            Renderer.Add(new VertexArrayRenderer());
            Keyboard         = new KeyboardHandler();
            Mouse            = new MouseHandler(this);
            CursorVisibility = true;
            LatipiumModule objectModule = ModuleFactory.FindModule("Com.Latipium.Modules.World.Objects");

            if (objectModule != null)
            {
                objectModule.AddEvent("ObjectLoaded", (Action <LatipiumObject>)LoadObject);
            }
        }
 /// <summary>
 /// Loads the module.
 /// </summary>
 /// <param name="name">The module name.</param>
 public override void Load(string name)
 {
     WorldModule = ModuleFactory.FindModule("Com.Latipium.Modules.World");
     if (WorldModule != null)
     {
         CreateWorld  = WorldModule.GetFunction <LatipiumObject>("CreateWorld");
         CreateRealm  = WorldModule.GetFunction <string, LatipiumObject>("CreateRealm");
         CreateObject = WorldModule.GetFunction <LatipiumObject, LatipiumObject>("CreateObject");
     }
     ObjectModule = ModuleFactory.FindModule("Com.Latipium.Modules.World.Objects");
     if (ObjectModule != null)
     {
         GetObject = ObjectModule.GetFunction <string, LatipiumObject>("Get");
     }
 }
示例#7
0
 internal WorldImpl(WorldModule world)
 {
     Realms       = new List <LatipiumObject>();
     Players      = new Dictionary <string, LatipiumObject>();
     WorldModule  = world;
     PlayerModule = ModuleFactory.FindModule("Com.Latipium.Modules.Player");
     if (PlayerModule == null)
     {
         GetPlayer = null;
     }
     else
     {
         GetPlayer = PlayerModule.GetFunction <LatipiumObject>("GetPlayer");
     }
     WorldLock = new object();
 }
        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);
        }
示例#9
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");
            }
        }
示例#10
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);
                    }
                }
            }
        }
示例#12
0
        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();
                    }
                }
            }
        }