Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            FixedString512 temp = default;

            ToFixedString(ref temp);
            return(temp.ToString());
        }
Ejemplo n.º 2
0
        public unsafe bool WritePackedFixedString512Delta(FixedString512 str, FixedString512 baseline, NetworkCompressionModel model)
        {
            ushort length = *((ushort *)&str);
            byte * data   = ((byte *)&str) + 2;

            return(WritePackedFixedStringDelta(data, length, ((byte *)&baseline) + 2, *((ushort *)&baseline), model));
        }
Ejemplo n.º 3
0
        public unsafe bool WriteFixedString512(FixedString512 str)
        {
            int   length = (int)*((ushort *)&str) + 2;
            byte *data   = ((byte *)&str);

            return(WriteBytes(data, length));
        }
 public static void Append(this StringBuilder builder, FixedString512 fixedString)
 {
     foreach (var c in fixedString)
     {
         builder.Append((char)c.value);
     }
 }
        public static int GetSectionIndexFromPath(string path)
        {
            var dot      = new FixedString32(".");
            var localStr = new FixedString512(path);

            // Find the extension '.'
            var index = localStr.LastIndexOf(dot);

            if (index < 0) // no '.' characters so return default '0'
            {
                return(0);
            }

            // Found the extension dot, so null it and search for a section number '.' delimiter
            localStr[index] = 0;
            index           = localStr.LastIndexOf(dot, index);
            if (index < 0)
            {
                return(0);
            }

            index++;
            int parsedInt = 0;

            localStr.Parse(ref index, ref parsedInt);

            return(parsedInt);
        }
Ejemplo n.º 6
0
        public unsafe FixedString512 ReadPackedFixedString512Delta(FixedString512 baseline, NetworkCompressionModel model)
        {
            FixedString512 str;
            byte *         data = ((byte *)&str) + 2;

            *(ushort *)&str = ReadPackedFixedStringDelta(data, str.Capacity, ((byte *)&baseline) + 2, *((ushort *)&baseline), model);
            return(str);
        }
Ejemplo n.º 7
0
        public static void IsTrue(bool condition, FixedString512 message)
        {
            if (condition)
            {
                return;
            }

            throw new InvalidOperationException(message.ToString());
        }
Ejemplo n.º 8
0
        public void Log(LogLevel level, FixedString512 str)
        {
            if ((int)level > (int)m_Level)
            {
                return;
            }
            var msg = new LogMessage {
                level = level, msg = str
            };

            m_PendingLog.Enqueue(msg);
        }
Ejemplo n.º 9
0
        protected override void OnCreate()
        {
            base.OnCreate();

            World.GetOrCreateSystem <SnapshotManager>().RegisterSystem(this);
            m_NativeName = ToString();

            SetSystemGroup();

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            SafetyHandle = AtomicSafetyHandle.Create();
#endif

            GetDelegates(out m_SerializeDelegate, out m_DeserializeDelegate);
        }
Ejemplo n.º 10
0
        public void ReadWriteFixedString512()
        {
            var dataStream = new DataStreamWriter(300 * 4, Allocator.Temp);

            var src = new FixedString512("This is a string");

            dataStream.WriteFixedString512(src);

            //Assert.AreEqual(src.LengthInBytes+2, dataStream.Length);

            var reader = new DataStreamReader(dataStream.AsNativeArray());
            var dst    = reader.ReadFixedString512();

            Assert.AreEqual(src, dst);
        }
Ejemplo n.º 11
0
        protected override void OnUpdate()
        {
            if (!HasSingleton <CoopMission>())
            {
                return;
            }

            var singleton = GetSingletonEntity <CoopMission>();

            if (EntityManager.TryGetComponentData(singleton, out ExecutingMissionData executing))
            {
                if (!dentBank.TryGetOutput(executing.Target, out var output))
                {
                    dentBank.CallAndStoreLater(executing.Target);
                }
                else
                {
                    var data = EntityManager.GetSharedComponentData <MissionDetailsComponent>(output);
                    var str  = new FixedString512();
                    unsafe
                    {
                        const int resPathTypePlusProtocolLength = 5;
                        fixed(char *ptr = data.Path.FullString)
                        {
                            str.Append((byte *)ptr + resPathTypePlusProtocolLength, sizeof(char) * (ushort)(data.Path.FullString.Length - resPathTypePlusProtocolLength));
                        }
                    }

                    var switchMap = !HasSingleton <ExecutingMapData>();
                    if (!switchMap && !GetSingleton <ExecutingMapData>().Key.Equals(str))
                    {
                        switchMap = true;
                    }

                    if (switchMap)
                    {
                        EntityManager.AddComponentData(EntityManager.CreateEntity(), new RequestMapLoad {
                            Key = str
                        });
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                EntityManager.SetEnabled(popupEntity, !EntityManager.GetEnabled(popupEntity));
            }
        }
        public override string ToString()
        {
#if NET_DOTS
            if (TypeIndex == 0)
            {
                return("None");
            }

            var            info = TypeManager.GetTypeInfo(TypeIndex);
            FixedString512 ns   = default;
            ns.Append(info.Debug.TypeName);

            if (IsBuffer)
            {
                ns.Append(" [B]");
            }
            if (AccessModeType == AccessMode.Exclude)
            {
                ns.Append(" [S]");
            }
            if (AccessModeType == AccessMode.ReadOnly)
            {
                ns.Append(" [RO]");
            }

            return(ns.ToString());
#else
            var name = GetManagedType().Name;
            if (IsBuffer)
            {
                return($"{name} [B]");
            }
            if (AccessModeType == AccessMode.Exclude)
            {
                return($"{name} [S]");
            }
            if (AccessModeType == AccessMode.ReadOnly)
            {
                return($"{name} [RO]");
            }
            if (TypeIndex == 0)
            {
                return("None");
            }
            return(name);
#endif
        }
Ejemplo n.º 13
0
        public unsafe void LoadSoundClipFromDisk(EntityManager mgr, Entity e, string filePath)
        {
            DynamicBuffer <AudioClipCompressed> audioClipCompressed = mgr.GetBuffer <AudioClipCompressed>(e);

            if (audioClipCompressed.Length > 0)
            {
                return;
            }

#if UNITY_ANDROID
            var op = IOService.RequestAsyncRead(filePath);
            while (op.GetStatus() <= AsyncOp.Status.InProgress)
            {
                ;
            }

            op.GetData(out byte *data, out int sizeInBytes);
            audioClipCompressed.ResizeUninitialized(sizeInBytes);
            byte *audioClipCompressedBytes = (byte *)audioClipCompressed.GetUnsafePtr();
            for (int i = 0; i < sizeInBytes; i++)
            {
                audioClipCompressedBytes[i] = data[i];
            }

            op.Dispose();
#else
            FixedString512          filePathFixedString = new FixedString512(filePath);
            Baselib_ErrorState      errorState          = new Baselib_ErrorState();
            Baselib_FileIO_SyncFile fileHandle          = Baselib_FileIO_SyncOpen(filePathFixedString.GetUnsafePtr(), Baselib_FileIO_OpenFlags.Read, &errorState);
            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return;
            }

            UInt64 fileSize = Baselib_FileIO_SyncGetFileSize(fileHandle, &errorState);
            if (fileSize > Int32.MaxValue)
            {
                Baselib_FileIO_SyncClose(fileHandle, &errorState);
                return;
            }

            audioClipCompressed.ResizeUninitialized((int)fileSize);
            UInt64 bytesRead = Baselib_FileIO_SyncRead(fileHandle, 0, (IntPtr)audioClipCompressed.GetUnsafePtr(), (ulong)audioClipCompressed.Length, &errorState);
            Baselib_FileIO_SyncClose(fileHandle, &errorState);
#endif
        }
Ejemplo n.º 14
0
        public static unsafe FixedString4096 FormatGeneric(string format, object[] args)
        {
            FixedString128 *fargs   = stackalloc FixedString128[8];
            FixedString512  fformat = format;

            if (args != null)
            {
                for (int i = 0; i < args.Length; ++i)
                {
                    fargs[i] = MessageObjectToString(args[i]);
                }
            }

            FixedString4096 result = default;

            result.AppendFormat(fformat, fargs[0], fargs[1], fargs[2], fargs[3], fargs[4], fargs[5], fargs[6], fargs[7]);
            return(result);
        }
Ejemplo n.º 15
0
        public void ReadWritePackedFixedString512Delta()
        {
            var dataStream       = new DataStreamWriter(300 * 4, Allocator.Temp);
            var compressionModel = new NetworkCompressionModel(Allocator.Temp);

            var src      = new FixedString512("This is a string");
            var baseline = new FixedString512("This is another string");

            dataStream.WritePackedFixedString512Delta(src, baseline, compressionModel);
            dataStream.Flush();

            //Assert.LessOrEqual(dataStream.Length, src.LengthInBytes+2);

            var reader = new DataStreamReader(dataStream.AsNativeArray());
            var dst    = reader.ReadPackedFixedString512Delta(baseline, compressionModel);

            Assert.AreEqual(src, dst);
        }
Ejemplo n.º 16
0
            public void Execute()
            {
                Debug.Log("Plain log");
                Debug.LogWarning("Warning log");
                Debug.LogError("Error log");
                Debug.Log($"AAA{1}, {2}, {3}");
                Debug.Log(3 / 2 > 1 ? $"AAA{1}" : $"{2}, {3}");
                Debug.Log(string.Format("AAA{0}, {1}, {2}", 1, 2, 3));
                FixedString128 fixedString128 = "This is an integer value {12} used with FixedString128";
                FixedString512 fixedString512 = string.Format("{0}", 1);

                Debug.Log(fixedString128);
                fixedString512 = "asdasd";
                fixedString512 = "as{2}d{3}asd";
                int            var1     = 2;
                FixedString128 variable = "string";

                string.Format("{0} asdasd", variable);
            }
Ejemplo n.º 17
0
 public static void Text(FixedString512 text, float4x4 transform, Color color) => Unmanaged.Instance.Data.Font.Value.Draw(text, transform, color);
Ejemplo n.º 18
0
        public unsafe bool Contains(string value)
        {
            FixedString512 temp = value;

            return(Contains(ref temp));
        }
Ejemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        public unsafe void SetString(string value)
        {
            FixedString512 temp = value;

            SetFixedString(ref temp);
        }
Ejemplo n.º 20
0
        public static BindingInfo GetBindingInfo(EntityManager entityManager, Entity entity, FixedString512 propertyPath)
        {
            var path = propertyPath.ToString();

            if (string.IsNullOrEmpty(path))
            {
                Debug.LogWarning("Could not find a proper mapping with an empty path.");
                return(BindingInfo.UnsuccessfulBinding);
            }

            var container = new EntityContainer(entityManager, entity);
            var operation = new GetBindingInfoOperation(path);

            PropertyContainer.Visit(ref container, operation);

            return(operation.GetResult());
        }
Ejemplo n.º 21
0
 public unsafe void Draw(FixedString512 text, Matrix4x4 transform, Color color) => Draw(text.GetUnsafePtr(), text.Length, transform, color);