public override bool Init() { FLLog.Info("Video", "Opening mpv backend"); if (!Mpv.LoadLibrary(mpvo)) { return(false); } try { //mpv will not run unless lc_numeric is "C" IntPtr locale; if ((locale = setlocale(LC_NUMERIC, "C")) == IntPtr.Zero) { throw new Exception("setlocale(LC_NUMERIC, \"C\") failed"); } mpvhandle = Mpv.mpv_create(); if (mpvhandle == IntPtr.Zero) { throw new Exception("mpv_create failed"); } CheckError(Mpv.mpv_initialize(mpvhandle)); mpvgl = Mpv.mpv_get_sub_api(mpvhandle, Mpv.mpv_sub_api.MPV_SUB_API_OPENGL_CB); CheckError(Mpv.mpv_opengl_cb_init_gl(mpvgl, IntPtr.Zero, GetProcAddress, IntPtr.Zero)); CheckError(Mpv.mpv_set_option_string(mpvhandle, "vo", "opengl-cb")); update = ctx => game.QueueUIThread(() => doDraw = true); Mpv.mpv_opengl_cb_set_update_callback(mpvgl, update, IntPtr.Zero); } catch (Exception ex) { FLLog.Info("mpv", "Failed to initialize: " + ex.Message); return(false); } return(true); }
public override void Dispose() { FLLog.Info("Video", "Closing Windows Media Foundation backend"); if (session != null) { session.ClearTopologies(); session.Stop(); session.Close(); session.Dispose(); } if (topology != null) { topology.Dispose(); } if (videoSampler != null) { videoSampler.Dispose(); } if (clock != null) { clock.Dispose(); } if (_texture != null) { _texture.Dispose(); } if (cb != null) { cb.Dispose(); } }
unsafe void RenderImage(string output) { try { TextureImport.LoadLibraries(); } catch (Exception ex) { FLLog.Error("Render", "Could not load FreeImage"); FLLog.Info("Exception Info", ex.Message + "\n" + ex.StackTrace); return; } imageViewport.Background = renderBackground ? background : Color4.TransparentBlack; imageViewport.Begin(imageWidth, imageHeight); DrawGL(imageWidth, imageHeight); imageViewport.End(false); byte[] data = new byte[imageWidth * imageHeight * 4]; imageViewport.RenderTarget.GetData(data); using (var sfc = new TeximpNet.Surface(imageWidth, imageHeight, true)) { byte *sfcData = (byte *)sfc.DataPtr; for (int i = 0; i < data.Length; i++) { sfcData[i] = data[i]; } sfc.SaveToFile(TeximpNet.ImageFormat.PNG, output); } }
public override bool Init() { FLLog.Info("Video", "Opening Windows Media Foundation backend"); try { if (dot == null) { dot = new Texture2D(1, 1); dot.SetData(new uint[] { 0x000000FF }); } if (!_started) { MediaManager.Startup(); _started = true; } MediaFactory.CreateTopology(out topology); MediaFactory.CreateMediaSession(null, out session); return(true); } catch (Exception ex) { FLLog.Info("Video", "Media Foundation: " + ex.Message); return(false); } }
void SetActiveScene() { if (_activeScene != null && _activeScene.ID.Equals(ActiveScene, StringComparison.OrdinalIgnoreCase)) { if (scriptingEnabled && !lastScriptingEnabled) { lastScriptingEnabled = true; _activeScene.EnableScripting(scriptingContext, modalData); } return; } if (string.IsNullOrWhiteSpace(ActiveScene)) { _activeScene = null; return; } var sw = Stopwatch.StartNew(); _activeScene = Scenes.FirstOrDefault(x => x.ID.Equals(ActiveScene, StringComparison.OrdinalIgnoreCase)); _activeScene?.Reset(); if (scriptingEnabled) { _activeScene?.EnableScripting(scriptingContext, modalData); lastScriptingEnabled = true; } sw.Stop(); FLLog.Info("lua", $"init took {sw.Elapsed.TotalMilliseconds}ms"); }
public override void Dispose() { disposed = true; if (mpvhandle != IntPtr.Zero) { FLLog.Info("Video", "Closing mpv backend"); Mpv.mpv_opengl_cb_uninit_gl(mpvgl); Mpv.mpv_terminate_destroy(mpvhandle); framebuffer.Dispose(); Playing = false; } }
public static void Init(string fldir) { FreelancerDirectory = fldir.TrimEnd('\\', '/'); CaseSensitive = Platform.IsDirCaseSensitive(fldir); if (CaseSensitive) { FLLog.Info("VFS", "Case-Sensitive: Path translation enabled (will impact performance)"); } else { FLLog.Info("VFS", "Not Case-Sensitive: Path translation disabled"); } }
public static void InitXML() { if (initing) { return; } initing = true; new Thread(() => { _xml = new XmlSerializer(typeof(CL.COLLADA)); FLLog.Info("Collada", "Xml support loaded"); inited = true; }).Start(); }
static LuaContext() { UserData.DefaultAccessMode = InteropAccessMode.Hardwired; Lua.LuaContext_Hardwire.Initialize(); UserData.RegisterType <HorizontalAlignment>(); UserData.RegisterType <VerticalAlignment>(); UserData.RegisterType <AnchorKind>(); script = new Script(CoreModules.Preset_HardSandbox); script.Options.DebugPrint = s => FLLog.Info("Lua", s); script.Globals["HorizontalAlignment"] = UserData.CreateStatic <HorizontalAlignment>(); script.Globals["VerticalAlignment"] = UserData.CreateStatic <VerticalAlignment>(); script.Globals["AnchorKind"] = UserData.CreateStatic <AnchorKind>(); baseCode = Compile(script, null, DEFAULT_LUA, "LuaContext.LuaCode"); }
public override void Invoke(MissionRuntime runtime, MissionScript script) { FLLog.Info("Act_CallThorn", Thorn); runtime.Player.WorldAction(() => { int mainObject = 0; if (MainObject != null) { var gameObj = runtime.Player.World.GameWorld.GetObject(MainObject); mainObject = gameObj?.NetID ?? 0; } FLLog.Info("Server", $"Calling Thorn {Thorn} with mainObject `{mainObject}`"); runtime.Player.CallThorn(Thorn, mainObject); }); }
public static void Init(string fldir) { FreelancerDirectory = Path.GetFullPath(fldir).TrimEnd('\\', '/'); CaseSensitive = Platform.IsDirCaseSensitive(fldir); if (CaseSensitive) { //Provide a fast lookup for files in the directory. Don't follow symlinks FLLog.Info("VFS", "Case-Sensitive: Path translation enabled (will impact performance)"); fileDict = new Dictionary <string, string[]>(StringComparer.CurrentCultureIgnoreCase); WalkDir(FreelancerDirectory); } else { FLLog.Info("VFS", "Not Case-Sensitive: Path translation disabled"); } }
public SharedLib(params string[] libraries) { var errbuilder = new StringBuilder(); errbuilder.AppendLine("Failed loading library:"); IntPtr ptr; foreach (string lib in libraries) { if (Load(lib, errbuilder, out ptr)) { FLLog.Info("dlopen", "opened " + lib); handle = ptr; return; } } throw new Exception(errbuilder.ToString()); }
void LoadData(string path) { if (world != null) { world.Renderer.Dispose(); world.Dispose(); world = null; } Thread GameDataLoaderThread = new Thread(() => { GameData = new GameDataManager(path, Resources); GameData.LoadData(); FLLog.Info("Game", "Finished loading game data"); EnsureUIThread(OnLoadComplete); }); GameDataLoaderThread.Name = "GamedataLoader"; GameDataLoaderThread.Start(); }
void LoadData(string path) { loaded = false; if (cutscene != null) { cutscene.Dispose(); cutscene = null; } Thread GameDataLoaderThread = new Thread(() => { GameData = new GameDataManager(path, Resources); GameData.LoadData(); FLLog.Info("Game", "Finished loading game data"); EnsureUIThread(OnLoadComplete); }); GameDataLoaderThread.Name = "GamedataLoader"; GameDataLoaderThread.Start(); }
public override void Dispose() { FLLog.Info("Video", "Closing Windows Media Foundation backend"); if (session != null) { session.Stop(); session.ClearTopologies(); //Sample grabber thread works asynchronously (as task), so we need give him a time, to understand, that session is closed //minimal time to wait: 33 ms (1000 ms / 30 fps), but I decide to use a little more System.Threading.Thread.Sleep(100); session.Close(); session.Dispose(); session = null; } if (topology != null) { topology.Dispose(); topology = null; } if (videoSampler != null) { videoSampler.Dispose(); videoSampler = null; } if (clock != null) { clock.Dispose(); clock = null; } if (_texture != null) { _texture.Dispose(); _texture = null; } if (cb != null) { cb.Dispose(); cb = null; } }
public LuaContext(UiContext context) { uiContext = context; script = new Script(CoreModules.Preset_HardSandbox | CoreModules.Metatables); script.Options.DebugPrint = s => FLLog.Info("Lua", s); script.Globals["HorizontalAlignment"] = UserData.CreateStatic <HorizontalAlignment>(); script.Globals["VerticalAlignment"] = UserData.CreateStatic <VerticalAlignment>(); script.Globals["AnchorKind"] = UserData.CreateStatic <AnchorKind>(); script.Options.ScriptLoader = new UiScriptLoader(context); var globalTable = script.Globals; foreach (var g in script.Globals.Keys) { globalTable[g] = script.Globals[g]; } var typeTable = new Table(script); globalTable["ClrTypes"] = typeTable; typeTable["System_Collections_Generic_List___LibreLancer_Interface_XmlStyle___"] = typeof(List <XmlStyle>); typeTable["System_Collections_Generic_List___LibreLancer_Interface_DisplayElement___"] = typeof(List <DisplayElement>); typeTable["System_Collections_Generic_List___LibreLancer_Interface_UiWidget___"] = typeof(List <UiWidget>); typeTable["System_Collections_Generic_List___LibreLancer_Interface_ListItem___"] = typeof(List <ListItem>); typeTable["System_Collections_Generic_List___LibreLancer_Interface_TableColumn___"] = typeof(List <TableColumn>); foreach (var type in typeof(LuaContext).Assembly.GetTypes()) { if (type.GetCustomAttributes(false).OfType <MoonSharpUserDataAttribute>().Any()) { typeTable[type.FullName.Replace(".", "_")] = type; } } globalTable["Game"] = context.GameApi; //Functions globalTable["Funcs"] = new ContextFunctions(this); script.DoString(DEFAULT_LUA, null, "LuaContext.LuaCode"); }
static void LogString(string s) { FLLog.Info("Lua", s); }
public static int Main(string[] args) { if (args.Length > 0 && args[0] == "--makeconfig") { MakeConfig(); return(0); } if (!File.Exists("librelancerserver.config.json")) { Console.Error.WriteLine("Can't find librelancerserver.config.json"); return(2); } var config = JSON.Deserialize <Config>(File.ReadAllText("librelancerserver.config.json")); config.DatabasePath = Path.GetFullPath(config.DatabasePath); var srv = new GameServer(config.FreelancerPath); var ctxFactory = new SqlDesignTimeFactory(config); if (!File.Exists(config.DatabasePath)) { FLLog.Info("Server", $"Creating database file {config.DatabasePath}"); using (var ctx = ctxFactory.CreateDbContext(new string[0])) { ctx.Database.Migrate(); } } using (var ctx = ctxFactory.CreateDbContext(new string[0])) { //Force create model early if (ctx.Database.GetPendingMigrations().Any()) { FLLog.Info("Server", "Migrating database"); ctx.Database.Migrate(); } FLLog.Debug("model", ctx.Model.ToString()); } srv.DbContextFactory = ctxFactory; srv.ServerName = config.ServerName; srv.ServerDescription = config.ServerDescription; srv.Start(); bool running = true; while (running) { var cmd = Console.ReadLine(); switch (cmd.Trim().ToLowerInvariant()) { case "stop": case "quit": case "exit": running = false; break; } } srv.Stop(); return(0); }
static EditorConfiguration() { SetConfigPath(); FLLog.Info("Config", "Path: " + configPath); }