/// <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); } }
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(); } } } }