static void LoadGameDll(string BasePath) { BasePath = Path.Combine(BasePath, "Game.dll"); Assembly GameAssembly = Reflect.LoadAssembly(BasePath); Type[] GameImplementations = Reflect.GetAllImplementationsOf(GameAssembly, typeof(LibTechGame)).ToArray(); if (GameImplementations.Length == 0) { GConsole.WriteLine("No game implementations found in " + BasePath); Environment.Exit(0); } else if (GameImplementations.Length > 1) { GConsole.WriteLine("Too many game implementations in " + BasePath); Environment.Exit(0); } AppDomain.CurrentDomain.AssemblyResolve += (S, E) => TryLoadAssembly(E.Name, BasePath); Importers.RegisterAll(GameAssembly); Game = (LibTechGame)Activator.CreateInstance(GameImplementations[0]); Game.Load(); }
public static void RegisterAll(Assembly A) { foreach (var Type in Reflect.GetAllImplementationsOf(A, typeof(Importer))) { Register(Type); } }
static void LoadGameDll(string BasePath) { string GameDllPath = Path.Combine(BasePath, "Game.dll"); Assembly GameAssembly = Assembly.GetExecutingAssembly(); bool LoadImporters = false; if (File.Exists(GameDllPath)) { GameAssembly = Reflect.LoadAssembly(GameDllPath); LoadImporters = true; } Type[] GameImplementations = Reflect.GetAllImplementationsOf(GameAssembly, typeof(LibTechGame)).ToArray(); if (GameImplementations.Length == 0) { GConsole.WriteLine("No game implementations found in " + GameDllPath); Environment.Exit(0); } else if (GameImplementations.Length > 1) { GConsole.WriteLine("Too many game implementations in " + GameDllPath); Environment.Exit(0); } AppDomain.CurrentDomain.AssemblyResolve += (S, E) => TryLoadAssembly(E.Name, GameDllPath); if (LoadImporters) { Importers.RegisterAll(GameAssembly); } Entity.LoadAllTypes(); Engine.Game = (LibTechGame)Activator.CreateInstance(GameImplementations[0]); Engine.Game.Load(); }
static void LoadContent() { string GameDllPath = Path.Combine(CVar.GetString("game"), "Game.dll"); if (!File.Exists(GameDllPath)) { FatalError("File not found: {0}", GameDllPath); } Assembly GameAssembly = Reflect.LoadAssembly(GameDllPath); Importers.RegisterAll(GameAssembly); Type[] GameImplementations = Reflect.GetAllImplementationsOf(GameAssembly, typeof(LibTechGame)).ToArray(); if (GameImplementations.Length == 0) { FatalError("Could not find game implementation in {0}", GameDllPath); } if (GameImplementations.Length > 1) { FatalError("Found too many game implementations in {0}", GameDllPath); } Game = (LibTechGame)Activator.CreateInstance(GameImplementations[0]); Game.Load(); RenderDevice = new RenderDevice(ShaderProgram.GUI, Width, Height); NuklearAPI.Init(RenderDevice); NuklearAPI.SetClipboardCallback((Txt) => { if (string.IsNullOrEmpty(Txt)) { return; } Glfw.SetClipboardString(Window, Txt); }, () => { string Str = Glfw.GetClipboardString(Window); if (Str == null) { Str = ""; } return(Str); }); Glfw.SetCursorPosCallback(Window, (Wnd, X, Y) => { RenderDevice.OnMouseMove((int)X, (int)Y); }); Glfw.SetMouseButtonCallback(Window, (Wnd, Button, State, Mods) => { NuklearEvent.MouseButton NkButton; bool IsDown = State == Glfw.InputState.Press ? true : false; if (!(State == Glfw.InputState.Press || State == Glfw.InputState.Release)) { return; } if (Button == Glfw.MouseButton.ButtonLeft) { NkButton = NuklearEvent.MouseButton.Left; } else if (Button == Glfw.MouseButton.ButtonMiddle) { NkButton = NuklearEvent.MouseButton.Middle; } else if (Button == Glfw.MouseButton.ButtonRight) { NkButton = NuklearEvent.MouseButton.Right; } else { return; } RenderDevice.OnMouseButton(NkButton, (int)MousePos.X, (int)MousePos.Y, IsDown); }); Glfw.SetScrollCallback(Window, (Wnd, X, Y) => { RenderDevice.OnScroll((float)X, (float)Y); }); Glfw.SetCharCallback(Window, (Wnd, Chr) => { RenderDevice.OnText(((char)Chr).ToString()); }); Glfw.SetKeyCallback(Window, (Wnd, KCode, SCode, State, Mods) => { if (KCode == Glfw.KeyCode.F1 && State == Glfw.InputState.Press) { GConsole.Open = true; } NkKeys K = ConvertToNkKey(KCode, Mods); if (K != NkKeys.None) { RenderDevice.OnKey(K, State == Glfw.InputState.Press); if (State == Glfw.InputState.Repeat) { RenderDevice.OnKey(K, true); } } }); Glfw.SetDropCallback(Window, (Wnd, Cnt, Paths) => { DragDropPaths = Paths; }); }