Exemplo n.º 1
0
 public static void IsTrue(bool b, FixedString128Bytes s)
 {
     if (!b)
     {
         Debug.Log(FixedString.Format("<color=red>##### ASSERT =>  {0}</color>", s));
         throw new AssertException();
     }
 }
Exemplo n.º 2
0
        private void writeString(FixedString value, bool prepend)
        {
            byte[] data = _encoder.GetBytes(value);

            Write(data.Length, prepend);
            if (prepend)
            {
                _data.InsertRange(0, data);
            }
            else
            {
                _data.AddRange(data);
            }
        }
 public void transform(XmlNode node)
 {
     if (Validator.Validate(node))
     {
         string fixed_s = FixedString.Trim();
         if (fixed_s != string.Empty)
         {
             node.InnerText = FixedString;
         }
         else
         {
             makeNodeEmpty(node);
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// READ keyword
        /// Read a series of fixed strings from the device into the specified array.
        /// </summary>
        /// <param name="readManager">A ReadManager instance to use</param>
        /// <param name="iostat">A reference variable that will be set to the I/O status</param>
        /// <param name="arraySize">The size of the array</param>
        /// <param name="strArray">A fixed string array to read into</param>
        /// <returns>A zero value if the operation succeeds, or -1 if the operation fails</returns>
        public static int READ(ReadManager readManager, ref int iostat, int arraySize, FixedString[] strArray)
        {
            if (readManager == null) {
                throw new ArgumentNullException("readManager");
            }
            if (strArray == null) {
                throw new ArgumentNullException("strArray");
            }

            int totalCharsRead = 0;
            for (int index = 0; index < arraySize; ++index) {
                int charsRead = READ(readManager, ref iostat, ref strArray[index]);
                if (charsRead <= 0) {
                    return charsRead;
                }
                totalCharsRead += charsRead;
            }
            return totalCharsRead;
        }
Exemplo n.º 5
0
        /// <summary>
        /// INQUIRE keyword.
        /// </summary>
        /// <param name="iodevice">A device number</param>
        /// <param name="filename">A filename</param>
        /// <param name="iostat">A reference variable that will be set to the I/O status</param>
        /// <param name="exists">A reference variable that will be set to true if
        /// the file exists</param>
        /// <param name="opened">A reference variable that will be set to true if
        /// the file is opened</param>
        /// <param name="number">A reference variable that will be set to the device
        /// number of the file</param>
        /// <param name="named">A reference variable that will be set to true if
        /// the device is named</param>
        /// <param name="name">A reference variable that will be set to the name
        /// of the file</param>
        /// <param name="access">A reference variable that will be set to SEQUENTIAL if
        /// the file was opened for sequential access or DIRECT otherwise</param>
        /// <param name="sequential">A reference variable that will be set to YES</param>
        /// <param name="direct">A reference variable that will be set to YES</param>
        /// <param name="form">A reference variable that will be set to FORMATTED if
        /// the file was opened for formatted output or UNFORMATTED otherwise</param>
        /// <param name="formatted">A reference variable that will be set to YES</param>
        /// <param name="unformatted">A reference variable that will be set to YES</param>
        /// <param name="recl">A reference variable that will be set to the record length</param>
        /// <param name="nextrec">A reference variable that will be set to the next direct
        /// access record number</param>
        /// <param name="blank">A reference variable that will be set to NULL or ZERO</param>
        /// <returns>A zero value if the operation succeeds, or -1 if the operation fails</returns>
        public static int INQUIRE(int iodevice, string filename, ref int iostat, ref bool exists, ref bool opened, ref int number,
            ref bool named, ref FixedString name, ref FixedString access, ref FixedString sequential,
            ref FixedString direct, ref FixedString form, ref FixedString formatted, ref FixedString unformatted,
            ref int recl, ref int nextrec, ref FixedString blank)
        {
            bool isFileStatement = (filename != null);
            IOFile ioobject;
            iostat = 0;

            if (isFileStatement) {
                string fixedFilename = filename.Trim();
                exists = File.Exists(fixedFilename);
                named = true;
                name = fixedFilename;
                ioobject = IOFile.Get(fixedFilename);
                opened = (ioobject != null);
                if (opened) {
                    number = ioobject.Unit;
                }
            } else {
                exists = true;
                number = iodevice;
                ioobject = IOFile.Get(iodevice);
                opened = (ioobject != null);
                if (opened) {
                    named = !string.IsNullOrEmpty(ioobject.Path);
                    name = named ? ioobject.Path : string.Empty;
                }
            }
            if (ioobject != null) {
                access = ioobject.IsSequential ? "SEQUENTIAL" : "DIRECT";
                form = ioobject.IsFormatted ? "FORMATTED" : "UNFORMATTED";
                blank = ioobject.Blank == '0' ? "ZERO" : "NULL";
                sequential = "YES";
                direct = "YES";
                formatted = "YES";
                unformatted = "YES";
                if (!ioobject.IsSequential) {
                    recl = ioobject.RecordLength;
                    nextrec = ioobject.RecordIndex;
                }
            }
            return 0;
        }
Exemplo n.º 6
0
 /// <summary>
 /// WRITE keyword
 /// Writes a fixed string value to the device.
 /// </summary>
 /// <param name="writeManager">A WriteManager instance to use</param>
 /// <param name="iostat">A reference variable that will be set to the I/O status</param>
 /// <param name="fixedstrVar">A fixed string value to write</param>
 /// <returns>A zero value if the operation succeeds, or -1 if the operation fails</returns>
 public static int WRITE(WriteManager writeManager, ref int iostat, FixedString fixedstrVar)
 {
     if (writeManager == null) {
         throw new ArgumentNullException("writeManager");
     }
     int charsWritten = writeManager.WriteString(fixedstrVar.ToString());
     if (charsWritten == -1) {
         iostat = IOError.WriteError;
     }
     return charsWritten;
 }
Exemplo n.º 7
0
 /// <summary>
 /// WRITE keyword
 /// Writes an array of fixed string values to the device.
 /// </summary>
 /// <param name="writeManager">A WriteManager instance to use</param>
 /// <param name="iostat">A reference variable that will be set to the I/O status</param>
 /// <param name="fixedstrArray">An array of fixed string values to write</param>
 /// <returns>A zero value if the operation succeeds, or -1 if the operation fails</returns>
 public static int WRITE(WriteManager writeManager, ref int iostat, FixedString [] fixedstrArray)
 {
     if (writeManager == null) {
         throw new ArgumentNullException("writeManager");
     }
     int totalCharsWritten = 0;
     foreach (FixedString fixedstrVar in fixedstrArray) {
         int charsWritten = writeManager.WriteString(fixedstrVar.ToString());
         if (charsWritten == -1) {
             iostat = IOError.WriteError;
             return -1;
         }
         totalCharsWritten += charsWritten;
     }
     return totalCharsWritten;
 }
Exemplo n.º 8
0
        // Read a string, formatted from the file.
        int ReadStringFormatted(ref FixedString fixedstrVar)
        {
            int fieldWidth = 0;
            int charsRead = 0;
            int strSize = fixedstrVar.Length;

            // Handle a repeat count first
            if (_valueRepeatCount > 0) {
                if (_hasValueRepeat) {
                    fixedstrVar = _valueRepeat.ToString();
                }
                --_valueRepeatCount;
                return _valueCharCount;
            }

            // For input formats, only the field width is used and it
            // determines the fixed number of characters to read.
            FormatRecord record = Record();
            if (record != null) {
                fieldWidth = record.FieldWidth;
            }
            if (fieldWidth > 0) {
                string realString = ReadChars(fieldWidth);
                int index = Math.Max(0, realString.Length - strSize);
                int length = Math.Min(strSize, realString.Length);

                fixedstrVar.Set(realString.Substring(index));
                charsRead = length;
            } else {
                StringBuilder str = new StringBuilder();
                char ch = ReadNonSpaceChar();
                if (ch == '\'' && record == null) {
                    ch = ReadChar();
                    while (ch != EOF && ch != EOL) {
                        if (ch == '\'') {
                            ch = ReadChar();
                            if (ch != '\'') {
                                break;
                            }
                        }
                        str.Append(ch);
                        ++charsRead;
                        ch = ReadChar();
                    }
                    SkipSeparators(ch);
                } else {
                    while (charsRead < strSize && ch != EOL && ch != EOF) {
                        str.Append(ch);
                        ch = ReadChar();
                        ++charsRead;
                    }
                    BackChar();
                }
                fixedstrVar.Set(str.ToString());
            }
            return charsRead;
        }
Exemplo n.º 9
0
        protected unsafe override void OnUpdate()
        {
            var input            = World.GetExistingSystem <InputSystem>();
            var renderer         = World.GetExistingSystem <RendererBGFXSystem>();
            var rendererInstance = renderer.InstancePointer();

            bool anyShift = input.GetKey(KeyCode.LeftShift) || input.GetKey(KeyCode.RightShift);
            bool anyCtrl  = input.GetKey(KeyCode.LeftControl) || input.GetKey(KeyCode.RightControl);
            bool anyAlt   = input.GetKey(KeyCode.LeftAlt) || input.GetKey(KeyCode.RightAlt);

            if (!m_configAlwaysRun && !anyShift)
            {
                return;
            }

            // debug bgfx stuff
            if (input.GetKey(KeyCode.F2) || (input.GetKey(KeyCode.Alpha2) && anyAlt))
            {
                rendererInstance->SetFlagThisFrame(bgfx.DebugFlags.Stats);
            }

            if (input.GetKeyDown(KeyCode.F3) || (input.GetKeyDown(KeyCode.Alpha3) && anyAlt))
            {
                var di = GetSingleton <DisplayInfo>();
                if (di.colorSpace == ColorSpace.Gamma)
                {
                    di.colorSpace = ColorSpace.Linear;
                }
                else
                {
                    di.colorSpace = ColorSpace.Gamma;
                }
                SetSingleton(di);
                renderer.DestroyAllTextures();
                renderer.ReloadAllImages();
                Debug.LogFormatAlways("Color space is now {0}.", di.colorSpace == ColorSpace.Gamma ? "Gamma (no srgb sampling)" : "Linear");
            }

            if (input.GetKeyDown(KeyCode.F4) || (input.GetKeyDown(KeyCode.Alpha4) && anyAlt))
            {
                var di = GetSingleton <DisplayInfo>();
                di.disableVSync = !di.disableVSync;
                SetSingleton(di);
                Debug.LogFormatAlways("VSync is now {0}.", di.disableVSync ? "disabled" : "enabled");
            }

            if (input.GetKeyDown(KeyCode.F5) || (input.GetKeyDown(KeyCode.Alpha5) && anyAlt))
            {
                var s = GetSingleton <RenderGraphState>();
                Debug.LogFormatAlways("Render buffer size was: {0}*{1}.", s.RenderBufferCurrentWidth, s.RenderBufferCurrentHeight);
                RenderGraphConfig cfg = GetNextConfig();
                SetSingleton(cfg);
                Debug.LogFormatAlways("Target config is now {0}*{1} {2}.", cfg.RenderBufferHeight, cfg.RenderBufferWidth, cfg.Mode == RenderGraphMode.DirectToFrontBuffer?"direct":"buffer");
            }

            rendererInstance->m_outputDebugSelect = new float4(0, 0, 0, 0);
            if (input.GetKey(KeyCode.Alpha1))
            {
                rendererInstance->m_outputDebugSelect = new float4(1, 0, 0, 0);
            }
            if (input.GetKey(KeyCode.Alpha2))
            {
                rendererInstance->m_outputDebugSelect = new float4(0, 1, 0, 0);
            }
            if (input.GetKey(KeyCode.Alpha3))
            {
                rendererInstance->m_outputDebugSelect = new float4(0, 0, 1, 0);
            }
            if (input.GetKey(KeyCode.Alpha4))
            {
                rendererInstance->m_outputDebugSelect = new float4(0, 0, 0, 1);
            }
            if (input.GetKeyDown(KeyCode.Z))
            {
                renderer.RequestScreenShot(FixedString.Format("screenshot{0}.tga", m_nshots++).ToString());
            }
            if (input.GetKeyDown(KeyCode.Escape))
            {
                Debug.LogFormatAlways("Reloading all textures.");
                // free all textures - this releases the bgfx textures and invalidates all cached bgfx state that might contain texture handles
                // note that this does not free system textures like single pixel white, default spotlight etc.
                renderer.DestroyAllTextures();
                // now force a reload on all image2d's from files
                renderer.ReloadAllImages();
                // once images are loaded, but don't have a texture, the texture will be uploaded and the cpu memory freed
            }
            if (renderer.HasScreenShot())
            {
                // TODO: save out 32bpp pixel data:
                Debug.LogFormat("Write screen shot to disk: {0}, {1}*{2}",
                                renderer.m_screenShotPath, renderer.m_screenShotWidth, renderer.m_screenShotHeight);
                renderer.ResetScreenShot();
            }

            // camera related stuff
            var ecam = FindCamera();

            if (ecam == Entity.Null)
            {
                return;
            }

            // sync scene camera with game camera position
            if (input.GetKeyDown(KeyCode.F))
            {
                SyncSceneViewToCamera(ref ecam);
            }

            ControlCamera(ecam);

            Entities.WithoutBurst().WithAll <Light>().ForEach(
                (Entity eLight, ref LightFromCameraByKey lk, ref Translation tPos, ref Rotation tRot) =>
            {
                if (input.GetKeyDown(lk.key))
                {
                    tPos = EntityManager.GetComponentData <Translation>(ecam);
                    tRot = EntityManager.GetComponentData <Rotation>(ecam);
                    Debug.LogFormat("Set light {0} to {1} {2}", eLight, tPos.Value, tRot.Value.value);
                }
            }).Run();
        }
Exemplo n.º 10
0
 public void Write(FixedString value, bool prepend = false)
 {
     writeString(value, prepend);
 }
Exemplo n.º 11
0
 public void FixedStringFormat()
 {
     Assert.AreEqual("1 0", FixedString.Format("{0} {1}", 1, 0));
     Assert.AreEqual("0.1 1.2", FixedString.Format("{0} {1}", 0.1f, 1.2f));
     Assert.AreEqual("error 500 in line 350: bubbly", FixedString.Format("error {0} in line {1}: {2}", 500, 350, "bubbly"));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Returns length of the character argument.
 /// </summary>
 /// <param name="s">Character argument</param>
 /// <returns>The length of string s</returns>
 public static int LEN(ref FixedString s)
 {
     if (s == null) {
         throw new ArgumentNullException("s");
     }
     return s.Length;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Searches first string and returns position of second string within it, otherwise zero..
 /// </summary>
 /// <param name="s1">First string</param>
 /// <param name="s2">Second string</param>
 /// <returns>The 1 based offset of string s2 within s1</returns>
 public static int INDEX(ref FixedString s1, ref FixedString s2)
 {
     if (s1 == null) {
         throw new ArgumentNullException("s1");
     }
     if (s2 == null) {
         throw new ArgumentNullException("s2");
     }
     return s1.IndexOf(s2) + 1;
 }
Exemplo n.º 14
0
 /// <summary>
 /// Searches first string and returns position of second string within it, otherwise zero..
 /// </summary>
 /// <param name="s1">First string</param>
 /// <param name="s2">Second string</param>
 /// <returns>The 1 based offset of string s2 within s1</returns>
 public static int INDEX(ref string s1, ref FixedString s2)
 {
     if (s1 == null) {
         throw new ArgumentNullException("s1");
     }
     if (s2 == null) {
         throw new ArgumentNullException("s2");
     }
     return s1.IndexOf(s2.ToString(), System.StringComparison.Ordinal) + 1;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Returns position of first character of the string in the local character code table.
 /// </summary>
 /// <param name="ch">Character</param>
 /// <returns>The ASCII value of the character ch</returns>
 public static int ICHAR(FixedString ch)
 {
     if (ch == null) {
         throw new ArgumentNullException("ch");
     }
     return (int)ch[0];
 }
Exemplo n.º 16
0
 /// <summary>
 /// Lexical comparison using ASCII character code: returns true if arg1 is less
 /// than arg2.
 /// </summary>
 /// <param name="s1">First string</param>
 /// <param name="s2">Second string</param>
 /// <returns>True if string s1 is lexically less than s2, false otherwise</returns>
 public static bool LLT(FixedString s1, FixedString s2)
 {
     if (s1 == null) {
         throw new ArgumentNullException("s1");
     }
     if (s2 == null) {
         throw new ArgumentNullException("s2");
     }
     return s1.Compare(s2) < 0;
 }
Exemplo n.º 17
0
 /// <summary>
 /// READ keyword
 /// Read a string from the device into the specified identifier.
 /// </summary>
 /// <param name="readManager">A ReadManager instance to use</param>
 /// <param name="iostat">A reference variable that will be set to the I/O status</param>
 /// <param name="fixedstrVar">The fixed string identifier to read into</param>
 /// <returns>A zero value if the operation succeeds, or -1 if the operation fails</returns>
 public static int READ(ReadManager readManager, ref int iostat, ref FixedString fixedstrVar)
 {
     if (readManager == null) {
         throw new ArgumentNullException("readManager");
     }
     if (fixedstrVar == null) {
         throw new ArgumentNullException("fixedstrVar");
     }
     int charsRead = readManager.ReadString(ref fixedstrVar);
     if (charsRead == -1) {
         iostat = IOError.ReadError;
     }
     return charsRead;
 }
Exemplo n.º 18
0
 /// <summary>
 /// READ keyword
 /// Read a string from the device into a substring of the specified fixed string.
 /// </summary>
 /// <param name="readManager">A ReadManager instance to use</param>
 /// <param name="iostat">A reference variable that will be set to the I/O status</param>
 /// <param name="start">The 1-based start index of the target string</param>
 /// <param name="end">The 1-based end index of the target string</param>
 /// <param name="fixedstrVar">The fixed string identifier to read into</param>
 /// <returns>A zero value if the operation succeeds, or -1 if the operation fails</returns>
 public static int READ(ReadManager readManager, ref int iostat, int start, int end, ref FixedString fixedstrVar)
 {
     if (readManager == null) {
         throw new ArgumentNullException("readManager");
     }
     if (fixedstrVar == null) {
         throw new ArgumentNullException("fixedstrVar");
     }
     if (end == -1) {
         end = fixedstrVar.Length;
     }
     FixedString fixedString = new FixedString((end - start) + 1);
     int charsRead = readManager.ReadString(ref fixedString);
     if (charsRead == -1) {
         iostat = IOError.ReadError;
     } else {
         fixedstrVar.Set(fixedString, start - 1, end - 1);
     }
     return charsRead;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JComLib.WriteManager"/> class using
 /// a specified format string.
 /// </summary>
 /// <param name="formatStringArray">Format string</param>
 public WriteManager(FixedString[] formatStringArray)
 {
     StringBuilder str = new StringBuilder();
     foreach (FixedString formatString in formatStringArray) {
         str.Append(formatString);
     }
     _format = new FormatManager(str.ToString());
 }
Exemplo n.º 20
0
        /// <summary>
        /// Converts a given xml attribute to the corresponding C# valuetype.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="value">The value.</param>
        /// <returns>The property.</returns>
        public static object XmlToValue(string type, string value)
        {
            object propertyValue = null;

            switch (type)
            {
            case "LSString":
                propertyValue = new LSString(value);
                break;

            case "FixedString":
                propertyValue = new FixedString(value);
                break;

            case "TranslatedString":
                propertyValue = new TranslatedString(value);
                break;

            case "int8":
                propertyValue = sbyte.Parse(value, CultureInfo.InvariantCulture);
                break;

            case "int16":
                propertyValue = short.Parse(value, CultureInfo.InvariantCulture);
                break;

            case "int":
            case "int32":
                propertyValue = int.Parse(value, CultureInfo.InvariantCulture);
                break;

            case "uint8":
                propertyValue = byte.Parse(value, CultureInfo.InvariantCulture);
                break;

            case "uint16":
                propertyValue = ushort.Parse(value, CultureInfo.InvariantCulture);
                break;

            case "uint32":
                propertyValue = uint.Parse(value, CultureInfo.InvariantCulture);
                break;

            case "uint64":
                propertyValue = ulong.Parse(value, CultureInfo.InvariantCulture);
                break;

            case "bool":
                propertyValue = bool.Parse(value);
                break;

            case "guid":
                propertyValue = new Guid(value);
                break;

            case "float":
                propertyValue = float.Parse(value, CultureInfo.InvariantCulture);
                break;

            case "fvec2":
                var fvec2 = value.Split(' ').Select(v => float.Parse(v, CultureInfo.InvariantCulture)).ToArray();
                propertyValue = new Tuple <float, float>(fvec2[0], fvec2[1]);
                break;

            case "fvec3":
                var fvec3 = value.Split(' ').Select(v => float.Parse(v, CultureInfo.InvariantCulture)).ToArray();
                propertyValue = new Tuple <float, float, float>(fvec3[0], fvec3[1], fvec3[2]);
                break;

            case "fvec4":
                var fvec4 = value.Split(' ').Select(v => float.Parse(v, CultureInfo.InvariantCulture)).ToArray();
                propertyValue = new Tuple <float, float, float, float>(fvec4[0], fvec4[1], fvec4[2], fvec4[3]);
                break;

            default:
                Services.GeneralHelper.WriteToConsole($"GameObject attribute type [{type}] not covered.\n");
                break;
            }
            return(propertyValue);
        }
Exemplo n.º 21
0
 // Read a string unformatted from the file.
 int ReadStringUnformatted(ref FixedString stringValue)
 {
     return _file.ReadString(ref stringValue);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Writes the string representation of a specified 64-bit signed integer to the buffer.
 /// </summary>
 /// <param name="value">The value to write.</param>
 public void Write(long value)
 {
     Write(FixedString.Format("{0}", value));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Writes the string representation of a specified 32-bit floating-point number to the buffer. This method will allocate.
 /// </summary>
 /// <param name="value">The value to write.</param>
 public void Write(float value)
 {
     Write(FixedString.Format("{0}", value));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Read a string from an unformatted data file. The first part of the
        /// string in the file is the length as an integer. The string follows
        /// on from the length.
        /// </summary>
        /// <param name="strValue">A reference to the string to be set</param>
        /// <returns>The number of bytes read</returns>
        public int ReadString(ref FixedString strValue)
        {
            if (_isDisposed) {
                throw new ObjectDisposedException(GetType().Name);
            }
            int intSize = sizeof(int);
            byte [] intBuffer = new byte[intSize];
            if (ReadBytes(intBuffer, intSize) != intSize) {
                return 0;
            }
            int stringLength = BitConverter.ToInt32(intBuffer, 0);

            byte [] data = new byte[stringLength];
            int bytesRead = ReadBytes(data, stringLength);
            strValue = Encoding.ASCII.GetString(data, 0, bytesRead);
            return bytesRead + sizeof(int);
        }
Exemplo n.º 25
0
 /// <summary>
 /// Reads a string from the input file. The string is read either as
 /// a formatted or unformatted value depending on how the file was opened.
 /// </summary>
 /// <param name="fixedString">A reference to the string to be set</param>
 /// <returns>The count of characters read. 0 means EOF, and -1 means an error</returns>
 public int ReadString(ref FixedString fixedString)
 {
     if (_isDisposed) {
         throw new ObjectDisposedException(GetType().Name);
     }
     int returnValue;
     try {
         if (IsFormatted()) {
             returnValue = ReadStringFormatted(ref fixedString);
         } else {
             returnValue = ReadStringUnformatted(ref fixedString);
         }
     } catch (IOException) {
         returnValue = -1;
     }
     return TestAndThrowError(returnValue);
 }