Beispiel #1
0
        // Serialize / deserialize
        internal void ReadWrite(IReadWriteStream s)
        {
            s.rwInt(ref type);
            switch ((UniversalType)type)
            {
            case UniversalType.AngleRadians:
            case UniversalType.AngleDegreesFloat:
            case UniversalType.Float:
            {
                float v = 0.0f;
                try { v = (float)value; } catch (NullReferenceException e) { }
                s.rwFloat(ref v);
                value = v;
                break;
            }

            case UniversalType.AngleDegrees:
            case UniversalType.Color:
            case UniversalType.EnumBits:
            case UniversalType.EnumOption:
            case UniversalType.Integer:
            case UniversalType.LinedefTag:
            case UniversalType.LinedefType:
            case UniversalType.SectorEffect:
            case UniversalType.SectorTag:
            case UniversalType.ThingTag:
            case UniversalType.PortalTag:
            {
                int v = 0;
                try { v = (int)value; } catch (NullReferenceException e) { }
                s.rwInt(ref v);
                value = v;
                break;
            }

            case UniversalType.Boolean:
            {
                bool v = false;
                try { v = (bool)value; } catch (NullReferenceException e) { }
                s.rwBool(ref v);
                value = v;
                break;
            }

            case UniversalType.Flat:
            case UniversalType.String:
            case UniversalType.Texture:
            case UniversalType.EnumStrings:
            {
                string v = (string)value;
                s.rwString(ref v);
                value = v;
                break;
            }

            default:
                General.Fail("Unknown field type to read/write!");
                break;
            }
        }
        // Serialize / deserialize
        internal void ReadWrite(IReadWriteStream s)
        {
            s.rwInt(ref type);
            switch ((UniversalType)type)
            {
            case UniversalType.AngleRadians:
            case UniversalType.AngleDegreesFloat:
            case UniversalType.Float:
            {
                double v = 0.0f;
                //mxd. Seems to work faster this way
                //try { v = (float)value; } catch(NullReferenceException e) { }
                if (value != null)
                {
                    v = (double)value;
                }
                s.rwDouble(ref v);
                value = v;
                break;
            }

            case UniversalType.AngleDegrees:
            case UniversalType.AngleByte:                     //mxd
            case UniversalType.Color:
            case UniversalType.EnumBits:
            case UniversalType.EnumOption:
            case UniversalType.Integer:
            case UniversalType.LinedefTag:
            case UniversalType.LinedefType:
            case UniversalType.SectorEffect:
            case UniversalType.SectorTag:
            case UniversalType.ThingTag:
            case UniversalType.ThingType:
            {
                int v = 0;
                //mxd. Seems to work faster this way
                //try { v = (int)value; } catch(NullReferenceException e) { }
                if (value != null)
                {
                    v = (int)value;
                }
                s.rwInt(ref v);
                value = v;
                break;
            }

            case UniversalType.Boolean:
            {
                bool v = false;
                //mxd. Seems to work faster this way
                //try { v = (bool)value; } catch(NullReferenceException e) { }
                if (value != null)
                {
                    v = (bool)value;
                }
                s.rwBool(ref v);
                value = v;
                break;
            }

            case UniversalType.Flat:
            case UniversalType.String:
            case UniversalType.Texture:
            case UniversalType.EnumStrings:
            case UniversalType.ThingClass:
            {
                string v = (string)value;
                s.rwString(ref v);
                value = v;
                break;
            }

            default:
                General.Fail("Unknown field type to read/write!");
                break;
            }
        }