public static Image <Rgba32> GenerateParallax(TomlTable config, Size size, ISawmill sawmill, List <Image <Rgba32> > debugLayerDump)
        {
            sawmill.Debug("Generating parallax!");
            var generator = new ParallaxGenerator();

            generator._loadConfig(config);

            sawmill.Debug("Timing start!");
            var sw = new Stopwatch();

            sw.Start();
            var image = new Image <Rgba32>(Configuration.Default, size.Width, size.Height, new Rgba32(0, 0, 0, 255));
            var count = 0;

            foreach (var layer in generator.Layers)
            {
                layer.Apply(image);
                debugLayerDump?.Add(image.Clone());
                sawmill.Debug("Layer {0} done!", count++);
            }

            sw.Stop();
            sawmill.Debug("Total time: {0}", sw.Elapsed.TotalSeconds);

            return(image);
        }
        public static Image <Rgba32> GenerateParallax(TomlTable config, Size size, ISawmill sawmill)
        {
            sawmill.Debug("Generating parallax!");
            var generator = new ParallaxGenerator();

            generator._loadConfig(config);

            var image = new Image <Rgba32>(Configuration.Default, size.Width, size.Height, Rgba32.Black);
            var count = 0;

            foreach (var layer in generator.Layers)
            {
                layer.Apply(image);
                sawmill.Debug("Layer {0} done!", count++);
            }

            return(image);
        }
Exemplo n.º 3
0
            public void Trace(string message, params object[] args)
            {
                if (Level > LogLevel.Trace)
                {
                    return;
                }

                _sawmill.Debug(message, args);
            }
Exemplo n.º 4
0
            public void Trace(string message, params object[] args)
            {
                if (message == "Setting the connection state to {0}" && args.Length > 0 && (string)args[0] == "CONNECTED")
                {
                    _successfullyConnected = true;
                }
                if (Level > LogLevel.Trace)
                {
                    return;
                }

                _sawmill.Debug(message, args);
            }
        /// <summary>
        /// Starts the handshake from the server end of the given channel,
        /// sending a <see cref="MsgMapStrServerHandshake"/>.
        /// </summary>
        /// <param name="channel">The network channel to perform the handshake over.</param>
        /// <remarks>
        /// Locks the string mapping if this is the first time the server is
        /// performing the handshake.
        /// </remarks>
        /// <seealso cref="MsgMapStrClientHandshake"/>
        /// <seealso cref="MsgMapStrStrings"/>
        public async Task Handshake(INetChannel channel)
        {
            DebugTools.Assert(_net.IsServer);
            DebugTools.Assert(_dict.Locked);

            _incompleteHandshakes.Add(channel);

            var message = _net.CreateNetMessage <MsgMapStrServerHandshake>();

            message.Hash = _stringMapHash;
            _net.ServerSendMessage(message, channel);

            while (_incompleteHandshakes.Contains(channel))
            {
                await Task.Delay(1);
            }

            LogSzr.Debug($"Completed handshake with {channel.RemoteEndPoint.Address}.");
        }
Exemplo n.º 6
0
        private void InitOpenGL()
        {
            var vendor   = GL.GetString(StringName.Vendor);
            var renderer = GL.GetString(StringName.Renderer);
            var version  = GL.GetString(StringName.Version);
            var major    = GL.GetInteger(GetPName.MajorVersion);
            var minor    = GL.GetInteger(GetPName.MinorVersion);

            _sawmillOgl.Debug("OpenGL Vendor: {0}", vendor);
            _sawmillOgl.Debug("OpenGL Renderer: {0}", renderer);
            _sawmillOgl.Debug("OpenGL Version: {0}", version);

            var overrideVersion = ParseGLOverrideVersion();

            if (overrideVersion != null)
            {
                (major, minor) = overrideVersion.Value;
                _sawmillOgl.Debug("OVERRIDING detected GL version to: {0}.{1}", major, minor);
            }

            DetectOpenGLFeatures(major, minor);
            SetupDebugCallback();

            LoadVendorSettings(vendor, renderer, version);

            var glVersion = new OpenGLVersion((byte)major, (byte)minor, _isGLES, _isCore);

            DebugInfo = new ClydeDebugInfo(glVersion, renderer, vendor, version, overrideVersion != null);

            GL.Enable(EnableCap.Blend);
            if (_hasGLSrgb)
            {
                GL.Enable(EnableCap.FramebufferSrgb);
                CheckGlError();
            }
            if (_hasGLPrimitiveRestart)
            {
                GL.Enable(EnableCap.PrimitiveRestart);
                CheckGlError();
                GL.PrimitiveRestartIndex(PrimitiveRestartIndex);
                CheckGlError();
            }
            if (!HasGLAnyVertexArrayObjects)
            {
                _sawmillOgl.Warning("NO VERTEX ARRAY OBJECTS! Things will probably go terribly, terribly wrong (no fallback path yet)");
            }

            ResetBlendFunc();

            CheckGlError();

            // Primitive Restart's presence or lack thereof changes the amount of required memory.
            InitRenderingBatchBuffers();

            _sawmillOgl.Debug("Loading stock textures...");

            LoadStockTextures();

            _sawmillOgl.Debug("Loading stock shaders...");

            LoadStockShaders();

            _sawmillOgl.Debug("Creating various GL objects...");

            CreateMiscGLObjects();

            _sawmillOgl.Debug("Setting up RenderHandle...");

            _renderHandle = new RenderHandle(this);

            _sawmillOgl.Debug("Setting viewport and rendering splash...");

            GL.Viewport(0, 0, ScreenSize.X, ScreenSize.Y);
            CheckGlError();

            // Quickly do a render with _drawingSplash = true so the screen isn't blank.
            Render();
        }
Exemplo n.º 7
0
 internal static void PrintRuntimeInfo(ISawmill sawmill)
 {
     sawmill.Debug($"Runtime: {RuntimeInformation.FrameworkDescription} {RuntimeInformation.RuntimeIdentifier}");
     sawmill.Debug($"OS: {RuntimeInformation.OSDescription} {RuntimeInformation.OSArchitecture}");
 }
        private void PreloadTextures(ISawmill sawmill)
        {
            sawmill.Debug("Preloading textures...");
            var sw      = Stopwatch.StartNew();
            var resList = GetTypeDict <TextureResource>();

            var texList = ContentFindFiles("/Textures/")
                          // Skip PNG files inside RSIs.
                          .Where(p => p.Extension == "png" && !p.ToString().Contains(".rsi/") && !resList.ContainsKey(p))
                          .Select(p => new TextureResource.LoadStepData {
                Path = p
            })
                          .ToArray();

            Parallel.ForEach(texList, data =>
            {
                try
                {
                    TextureResource.LoadPreTexture(this, data);
                }
                catch (Exception e)
                {
                    // Mark failed loads as bad and skip them in the next few stages.
                    // Avoids any silly array resizing or similar.
                    sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}");
                    data.Bad = true;
                }
            });

            foreach (var data in texList)
            {
                if (data.Bad)
                {
                    continue;
                }

                try
                {
                    TextureResource.LoadTexture(_clyde, data);
                }
                catch (Exception e)
                {
                    sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}");
                    data.Bad = true;
                }
            }

            var errors = 0;

            foreach (var data in texList)
            {
                if (data.Bad)
                {
                    errors += 1;
                    continue;
                }

                try
                {
                    var texResource = new TextureResource();
                    texResource.LoadFinish(this, data);
                    resList[data.Path] = texResource;
                }
                catch (Exception e)
                {
                    sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}");
                    data.Bad = true;
                    errors  += 1;
                }
            }

            sawmill.Debug(
                "Preloaded {CountLoaded} textures ({CountErrored} errored) in {LoadTime}",
                texList.Length,
                errors,
                sw.Elapsed);
        }
        private void PreloadRsis(ISawmill sawmill)
        {
            var sw      = Stopwatch.StartNew();
            var resList = GetTypeDict <RSIResource>();

            var rsiList = ContentFindFiles("/Textures/")
                          .Where(p => p.ToString().EndsWith(".rsi/meta.json"))
                          .Select(c => c.Directory)
                          .Where(p => !resList.ContainsKey(p))
                          .Select(p => new RSIResource.LoadStepData {
                Path = p
            })
                          .ToArray();

            Parallel.ForEach(rsiList, data =>
            {
                try
                {
                    RSIResource.LoadPreTexture(this, data);
                }
                catch (Exception e)
                {
                    // Mark failed loads as bad and skip them in the next few stages.
                    // Avoids any silly array resizing or similar.
                    sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}");
                    data.Bad = true;
                }
            });

            foreach (var data in rsiList)
            {
                if (data.Bad)
                {
                    continue;
                }

                try
                {
                    RSIResource.LoadTexture(_clyde, data);
                }
                catch (Exception e)
                {
                    sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}");
                    data.Bad = true;
                }
            }

            Parallel.ForEach(rsiList, data =>
            {
                if (data.Bad)
                {
                    return;
                }

                try
                {
                    RSIResource.LoadPostTexture(data);
                }
                catch (Exception e)
                {
                    data.Bad = true;
                    sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}");
                }
            });

            var errors = 0;

            foreach (var data in rsiList)
            {
                if (data.Bad)
                {
                    errors += 1;
                    continue;
                }

                try
                {
                    var rsiRes = new RSIResource();
                    rsiRes.LoadFinish(this, data);
                    resList[data.Path] = rsiRes;
                }
                catch (Exception e)
                {
                    sawmill.Error($"Exception while loading RSI {data.Path}:\n{e}");
                    data.Bad = true;
                    errors  += 1;
                }
            }

            sawmill.Debug(
                "Preloaded {CountLoaded} RSIs ({CountErrored} errored) in {LoadTime}",
                rsiList.Length,
                errors,
                sw.Elapsed);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Docks 2 ports together and assumes it is valid.
        /// </summary>
        public void Dock(DockingComponent dockA, DockingComponent dockB)
        {
            _sawmill.Debug($"Docking between {dockA.Owner} and {dockB.Owner}");

            // https://gamedev.stackexchange.com/questions/98772/b2distancejoint-with-frequency-equal-to-0-vs-b2weldjoint

            // We could also potentially use a prismatic joint? Depending if we want clamps that can extend or whatever
            var dockAXform = EntityManager.GetComponent <TransformComponent>(dockA.Owner);
            var dockBXform = EntityManager.GetComponent <TransformComponent>(dockB.Owner);

            DebugTools.Assert(dockAXform.GridUid != null);
            DebugTools.Assert(dockBXform.GridUid != null);
            var gridA = dockAXform.GridUid !.Value;
            var gridB = dockBXform.GridUid !.Value;

            SharedJointSystem.LinearStiffness(
                2f,
                0.7f,
                EntityManager.GetComponent <PhysicsComponent>(gridA).Mass,
                EntityManager.GetComponent <PhysicsComponent>(gridB).Mass,
                out var stiffness,
                out var damping);

            // These need playing around with
            // Could also potentially have collideconnected false and stiffness 0 but it was a bit more suss???

            var joint = _jointSystem.GetOrCreateWeldJoint(gridA, gridB, DockingJoint + dockA.Owner);

            var gridAXform = EntityManager.GetComponent <TransformComponent>(gridA);
            var gridBXform = EntityManager.GetComponent <TransformComponent>(gridB);

            var anchorA = dockAXform.LocalPosition + dockAXform.LocalRotation.ToWorldVec() / 2f;
            var anchorB = dockBXform.LocalPosition + dockBXform.LocalRotation.ToWorldVec() / 2f;

            joint.LocalAnchorA     = anchorA;
            joint.LocalAnchorB     = anchorB;
            joint.ReferenceAngle   = (float)(gridBXform.WorldRotation - gridAXform.WorldRotation);
            joint.CollideConnected = true;
            joint.Stiffness        = stiffness;
            joint.Damping          = damping;

            dockA.DockedWith = dockB.Owner;
            dockB.DockedWith = dockA.Owner;
            dockA.DockJoint  = joint;
            dockB.DockJoint  = joint;

            if (TryComp(dockA.Owner, out DoorComponent? doorA))
            {
                doorA.ChangeAirtight = false;
                _doorSystem.StartOpening(doorA.Owner, doorA);
            }

            if (TryComp(dockB.Owner, out DoorComponent? doorB))
            {
                doorB.ChangeAirtight = false;
                _doorSystem.StartOpening(doorB.Owner, doorB);
            }

            var msg = new DockEvent
            {
                DockA    = dockA,
                DockB    = dockB,
                GridAUid = gridA,
                GridBUid = gridB,
            };

            EntityManager.EventBus.RaiseLocalEvent(dockA.Owner, msg, false);
            EntityManager.EventBus.RaiseLocalEvent(dockB.Owner, msg, false);
            EntityManager.EventBus.RaiseEvent(EventSource.Local, msg);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Allows the NPC to actively be updated.
 /// </summary>
 public void WakeNPC(NPCComponent component)
 {
     _sawmill.Debug($"Waking {ToPrettyString(component.Owner)}");
     EnsureComp <ActiveNPCComponent>(component.Owner);
 }
        /// <summary>
        /// Starts the handshake from the server end of the given channel,
        /// sending a <see cref="MsgRobustMappedStringsSerializerServerHandshake"/>.
        /// </summary>
        /// <param name="channel">The network channel to perform the handshake over.</param>
        /// <remarks>
        /// Locks the string mapping if this is the first time the server is
        /// performing the handshake.
        /// </remarks>
        /// <seealso cref="MsgRobustMappedStringsSerializerClientHandshake"/>
        /// <seealso cref="MsgRobustMappedStringsSerializerStrings"/>
        public async Task Handshake(INetChannel channel)
        {
            var net = channel.NetPeer;

            if (net.IsClient)
            {
                return;
            }

            if (!LockMappedStrings)
            {
                LockMappedStrings = true;
                LogSzr.Debug($"Locked in at {_mappedStrings.Count} mapped strings.");
            }

            _incompleteHandshakes.Add(channel);

            var message = net.CreateNetMessage <MsgRobustMappedStringsSerializerServerHandshake>();

            message.Hash = MappedStringsHash;
            net.ServerSendMessage(message, channel);

            while (_incompleteHandshakes.Contains(channel))
            {
                await Task.Delay(1);
            }

            LogSzr.Debug($"Completed handshake with {channel.RemoteEndPoint.Address}.");
        }