コード例 #1
0
        Vector3 Eval(float t)
        {
            var val = CatmullRom(Points[0], Points[1], Points[2], Points[3], t);

            FLLog.Debug("GotoSpline", $"heading to point t={t} - {val}");
            return(val);
        }
コード例 #2
0
        public AudioManager(IUIThread uithread)
        {
            UIThread      = uithread;
            audioThreadId = Thread.CurrentThread.ManagedThreadId;
            initTask      = Task.Run(() =>
            {
                Platform.RegisterDllMap(typeof(AudioManager).Assembly);
                Music = new MusicPlayer(this);
                //Init context
                dev = Alc.alcOpenDevice(null);
                ctx = Alc.alcCreateContext(dev, IntPtr.Zero);
                Alc.alcMakeContextCurrent(ctx);
                for (int i = 0; i < MAX_SOURCES; i++)
                {
                    freeSources.Enqueue(Al.GenSource());
                }

                for (int i = 0; i < MAX_STREAM_BUFFERS; i++)
                {
                    Buffers.Enqueue(Al.GenBuffer());
                }

                Instances = new InstanceInfo[MAX_INSTANCES];
                for (int i = 0; i < MAX_INSTANCES; i++)
                {
                    Instances[i].Source = uint.MaxValue;
                    freeInstances.Enqueue((uint)i);
                }

                uint musicSource;
                for (int i = 0; i < 2; i++)
                {
                    while (!freeSources.TryDequeue(out musicSource))
                    {
                    }

                    streamingSources.Enqueue(musicSource);
                }

                FLLog.Debug("Audio", "Audio initialised");
                Al.alListenerf(Al.AL_GAIN, ALUtils.ClampVolume(ALUtils.LinearToAlGain(_masterVolume)));
                Ready = true;
            });
        }
コード例 #3
0
 public static void Log(string text)
 {
     FLLog.Debug("Shader", text);
 }
コード例 #4
0
        void Optimize()
        {
            needsOptimize = false;
            List <int>             meshes      = new List <int>();
            bool                   didOptimise = false;
            List <MaterialIndices> mats        = new List <MaterialIndices>();

            for (int i = StartMesh; i < endMesh; i++)
            {
                var c = counts.Where((x) => x.Material == Mesh.Meshes[i].MaterialCrc).First();
                if (c.Count == 1 || Mesh.Meshes[i].Material == null || Mesh.Meshes[i].Material.Render.IsTransparent)
                {
                    meshes.Add(i);
                }
                else
                {
                    didOptimise = true;
                    var m = mats.Where((x) => x.Crc == Mesh.Meshes[i].MaterialCrc).FirstOrDefault();
                    if (m == null)
                    {
                        m = new MaterialIndices()
                        {
                            Crc = Mesh.Meshes[i].MaterialCrc
                        };
                        mats.Add(m);
                    }
                    for (int j = Mesh.Meshes[i].TriangleStart; j < (Mesh.Meshes[i].TriangleStart + Mesh.Meshes[i].NumRefVertices); j++)
                    {
                        m.Indices.Add(Mesh.Indices[j] + StartVertex + Mesh.Meshes[i].StartVertex);
                    }
                }
            }

            if (didOptimise)
            {
                List <OptimizedDrawcall> dcs     = new List <OptimizedDrawcall>();
                List <ushort>            indices = new List <ushort>();
                foreach (var m in mats)
                {
                    var dc = new OptimizedDrawcall();
                    dc.MaterialCrc    = m.Crc;
                    dc.PrimitiveCount = m.Indices.Count / 3;
                    dc.StartIndex     = indices.Count + Mesh.IndexHandle.CountIndex;
                    var min = m.Indices.Min();
                    for (int i = 0; i < m.Indices.Count; i++)
                    {
                        indices.Add((ushort)(m.Indices[i] - min));
                    }
                    dc.VertexOffset = min + Mesh.VertexOffset;
                    dc.vMeshLibrary = vMeshLibrary;
                    dcs.Add(dc);
                }
                if (Mesh.IndexHandle.CountIndex + indices.Count >= Mesh.IndexHandle.TotalIndex)
                {
                    FLLog.Warning("Vms", "Failed to optimise: Not enough space in element buffer");
                    return;
                }
                var arr = indices.ToArray();
                mesh.IndexHandle.Elements.SetData(arr, arr.Length, Mesh.IndexHandle.CountIndex);
                mesh.IndexHandle.CountIndex += arr.Length;
                FLLog.Debug("Optimiser", "Reduced from " + MeshCount + " drawcalls to " + (meshes.Count + dcs.Count));
                optimized            = new OptimizedDraw();
                optimized.NormalDraw = meshes.ToArray();
                optimized.Optimized  = dcs.ToArray();
            }
        }
コード例 #5
0
        void UpdateThread()
        {
            //Init context
            IntPtr dev = Alc.alcOpenDevice(null);
            IntPtr ctx = Alc.alcCreateContext(dev, IntPtr.Zero);

            Alc.alcMakeContextCurrent(ctx);
            for (int i = 0; i < MAX_SOURCES; i++)
            {
                freeSources.Enqueue(Al.GenSource());
            }
            for (int i = 0; i < MAX_BUFFERS; i++)
            {
                Buffers.Enqueue(Al.GenBuffer());
            }
            uint musicSource;

            for (int i = 0; i < 2; i++)
            {
                while (!freeSources.TryDequeue(out musicSource))
                {
                }
                streamingSources.Enqueue(musicSource);
            }
            FLLog.Debug("Audio", "Audio initialised");
            Ready = true;
            while (running)
            {
                //insert into items to update
                while (toAdd.Count > 0)
                {
                    SoundEffectInstance item;
                    if (toAdd.TryDequeue(out item))
                    {
                        sfxInstances.Add(item);
                    }
                }
                Action toRun;
                if (Actions.TryDequeue(out toRun))
                {
                    toRun();
                }
                //update SFX
                for (int i = sfxInstances.Count - 1; i >= 0; i--)
                {
                    int state;
                    Al.alGetSourcei(sfxInstances[i].ID, Al.AL_SOURCE_STATE, out state);
                    if (state != Al.AL_PLAYING)
                    {
                        if (sfxInstances[i].Dispose != null)
                        {
                            sfxInstances[i].Dispose.Dispose();
                        }
                        freeSources.Enqueue(sfxInstances[i].ID);
                        sfxInstances.RemoveAt(i);
                        i--;
                    }
                }
                //update Streaming
                foreach (var item in activeStreamers)
                {
                    item.Update();
                }
                foreach (var item in toRemove)
                {
                    activeStreamers.Remove(item);
                    if (item.Stopped != null)
                    {
                        item.OnStopped();
                    }
                }
                Thread.Sleep(5);
            }
            //Delete context
            Alc.alcMakeContextCurrent(IntPtr.Zero);
            Alc.alcDestroyContext(ctx);
            Alc.alcCloseDevice(ctx);
        }
コード例 #6
0
ファイル: Material.cs プロジェクト: Giperion/Librelancer
        public static Material FromNode(IntermediateNode node, ILibFile textureLibrary)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (textureLibrary == null)
            {
                throw new ArgumentNullException("textureLibrary");
            }

            LeafNode typeNode = node["Type"] as LeafNode;

            if (typeNode == null)
            {
                throw new Exception("Invalid or missing type node in " + node.Name);
            }


            string type = typeNode.StringData;

            type = MaterialMap.Instance.Get(type) ?? type;
            type = MaterialMap.Instance.Get(node.Name.ToLowerInvariant()) ?? type;

            if (type == "HighGlassMaterial" ||
                type == "HUDAnimMaterial" ||
                type == "HUDIconMaterial" ||
                type == "PlanetWaterMaterial")
            {
                type = "DcDtOcOt";                 //HACK: Should do env mapping
            }
            if (type == "ExclusionZoneMaterial")
            {
                type = "DcDt";                 //HACK: This is handled in NebulaRenderer, not in Material.cs
            }
            var mat = new Material(node, textureLibrary, type);

            if (basicMaterials.Contains(type))
            {
                mat.isBasic = true;
            }
            else
            {
                switch (type)
                {
                case "Nebula":
                case "NebulaTwo":
                case "AtmosphereMaterial":
                case "DetailMapMaterial":
                case "DetailMap2Dm1Msk2PassMaterial":
                case "IllumDetailMapMaterial":
                case "Masked2DetailMapMaterial":
                case "NomadMaterialNoBendy":
                case "NomadMaterial":
                    break;

                default:
                    throw new Exception("Invalid material type: " + type);
                }
            }
            FLLog.Debug("Material", "Created " + type);
            return(mat);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Regenhardt/Librelancer
        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);
        }
コード例 #8
0
        void UpdateThread()
        {
            audioThreadId = Thread.CurrentThread.ManagedThreadId;
            //Init context
            IntPtr dev = Alc.alcOpenDevice(null);
            IntPtr ctx = Alc.alcCreateContext(dev, IntPtr.Zero);

            Alc.alcMakeContextCurrent(ctx);
            Al.CheckErrors();
            for (int i = 0; i < MAX_SOURCES; i++)
            {
                freeSources.Enqueue(Al.GenSource());
            }
            for (int i = 0; i < MAX_STREAM_BUFFERS; i++)
            {
                Buffers.Enqueue(Al.GenBuffer());
            }
            Instances = new InstanceInfo[MAX_INSTANCES];
            for (int i = 0; i < MAX_INSTANCES; i++)
            {
                Instances[i].Source = uint.MaxValue;
                freeInstances.Enqueue((uint)i);
            }
            uint musicSource;

            for (int i = 0; i < 2; i++)
            {
                while (!freeSources.TryDequeue(out musicSource))
                {
                }
                streamingSources.Enqueue(musicSource);
            }
            FLLog.Debug("Audio", "Audio initialised");
            Ready = true;
            Al.alListenerf(Al.AL_GAIN, ALUtils.ClampVolume(ALUtils.LinearToAlGain(_masterVolume)));
            while (running)
            {
                //Run actions
                Action toRun;
                while (actions.TryDequeue(out toRun))
                {
                    toRun();
                }
                //update SFX
                for (int i = sfxInstances.Count - 1; i >= 0; i--)
                {
                    var src      = Instances[sfxInstances[i]].Source;
                    var instance = Instances[sfxInstances[i]].Instance;
                    int state;
                    Al.alGetSourcei(src, Al.AL_SOURCE_STATE, out state);
                    Al.CheckErrors();
                    if (state == Al.AL_STOPPED)
                    {
                        Al.alSourcei(src, Al.AL_BUFFER, 0);
                        freeSources.Enqueue(src);
                        Instances[sfxInstances[i]].Source = uint.MaxValue;
                        instance?.Stopped();
                        sfxInstances.RemoveAt(i);
                        i--;
                    }
                }
                //update Streaming
                foreach (var item in activeStreamers)
                {
                    item.Update();
                }

                foreach (var item in toRemove)
                {
                    activeStreamers.Remove(item);
                    item.OnStopped();
                }
                toRemove.Clear();
                Thread.Sleep((sfxInstances.Count > 0 || activeStreamers.Count > 0) ? 1 : 5);
            }
            //Delete context
            Alc.alcMakeContextCurrent(IntPtr.Zero);
            Alc.alcDestroyContext(ctx);
            Alc.alcCloseDevice(dev);
        }