Exemplo n.º 1
0
        public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            s.StreamAttribute("name", ref mName);
            s.StreamStringOpt("yawattachment", ref mYawAttachment, toLower: false);
            s.StreamStringOpt("pitchattachment", ref mPitchAttachment, toLower: false);
            s.StreamAttributeOpt("autocenter", ref mAutoCenter, Predicates.IsFalse);
            s.StreamAttributeOpt("singleboneik", ref mSingleBoneIK, Predicates.IsTrue);
            s.StreamAttributeOpt("combined", ref mCombined, Predicates.IsTrue);
            s.StreamAttributeOpt("hardpitchlimits", ref mHardPitchLimits, Predicates.IsTrue);
            s.StreamAttributeOpt("relativeToUnit", ref mRelativeToUnit, Predicates.IsTrue);
            s.StreamAttributeOpt("useYawAndPitchAsTolerance", ref mUseYawAndPitchAsTolerance, Predicates.IsTrue);
            s.StreamAttributeOpt("infiniteRateWhenHasTarget", ref mInfiniteRateWhenHasTarget, Predicates.IsTrue);
            s.StreamAttributeOpt("yawrate", ref mYawRotationRate, x => x != cPiOver12InDegrees);
            s.StreamAttributeOpt("pitchrate", ref mPitchRotationRate, x => x != cPiOver12InDegrees);

            #region YawLeftMaxAngle and YawRightMaxAngle
            if (s.IsReading)
            {
                float yawMaxAngle = PhxUtil.kInvalidSingleNaN;
                if (s.ReadAttributeOpt("yawMaxAngle", ref yawMaxAngle) ||
                    // #HACK f*****g deal with original HW game data that was hand edited, but only when reading
                    s.ReadAttributeOpt("yawmaxangle", ref yawMaxAngle))
                {
                    mYawLeftMaxAngle  = -yawMaxAngle;
                    mYawRightMaxAngle = yawMaxAngle;
                }

                s.StreamAttributeOpt("YawLeftMaxAngle", ref mYawLeftMaxAngle, x => x != cDefaultYawLeftMaxAngle);
                s.StreamAttributeOpt("YawRightMaxAngle", ref mYawRightMaxAngle, x => x != cDefaultYawRightMaxAngle);
            }
            else if (s.IsWriting)
            {
                if (mYawLeftMaxAngle == cDefaultYawLeftMaxAngle &&
                    mYawRightMaxAngle == cDefaultYawRightMaxAngle)
                {
                    // don't stream anything
                }
                else if (System.Math.Abs(mYawLeftMaxAngle) == mYawRightMaxAngle)
                {
                    s.WriteAttribute("yawMaxAngle", mYawRightMaxAngle);
                }
                else
                {
                    s.StreamAttributeOpt("YawLeftMaxAngle", ref mYawLeftMaxAngle, x => x != cDefaultYawLeftMaxAngle);
                    s.StreamAttributeOpt("YawRightMaxAngle", ref mYawRightMaxAngle, x => x != cDefaultYawRightMaxAngle);
                }
            }
            #endregion

            s.StreamAttributeOpt("pitchMaxAngle", ref mPitchMaxAngle, x => x != cDefaultPitchMaxAngle);
            s.StreamAttributeOpt("pitchMinAngle", ref mPitchMinAngle, x => x != cDefaultPitchMinAngle);

            s.StreamStringOpt("StartYawSound", ref mStartYawSound, toLower: false);
            s.StreamStringOpt("StopYawSound", ref mStopYawSound, toLower: false);
            s.StreamStringOpt("StartPitchSound", ref mStartPitchSound, toLower: false);
            s.StreamStringOpt("StopPitchSound", ref mStopPitchSound, toLower: false);
        }
Exemplo n.º 2
0
        void Read <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            string[] names = kInfo.kValuesEnum.GetEnumNames();

            foreach (var element in s.ElementsByName(kEntryElementName))
            {
                using (s.EnterCursorBookmark(element))
                {
                    string name = null;
                    s.ReadAttribute(kEntryAttrKeyName, ref name);

                    int name_index = Array.IndexOf(names, name);
                    if (name_index < 0)
                    {
                        s.ThrowReadException(new System.IO.InvalidDataException("Invalid name value: " + name));
                    }

                    mArray[name_index] = 0.0f;
                    if (s.ReadAttributeOpt(kEntryAttrValueName, ref mArray[name_index]))                     // #HACK_BLAM: IgnoreWritePredicates hack! didn't used to be Opt
                    {
                        mValidFlags |= 1U << name_index;
                    }
                }
            }
        }
Exemplo n.º 3
0
        internal static void SerializeValueForEmbed <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s,
                                                                    ref int valueId)
            where TDoc : class
            where TCursor : class
        {
            bool is_global = false;
            MegaloScriptValueBase value = null;

            if (s.IsReading)
            {
                if (s.ReadAttributeOpt(kIsGlobalAttributeName, ref is_global) && is_global)
                {
                    s.ReadCursor(ref valueId);
                }
                else
                {
                    bool streamed_sans_ids = model.TagElementStreamSerializeFlags.EmbedObjectsWriteSansIds();
                    var  value_type        = ReadType(s, model.Database);

                    if (streamed_sans_ids)
                    {
                        valueId = TypeExtensions.kNone;                                         // set to NONE to automatically add
                    }
                    else
                    {
                        SerializeId(s, ref valueId);
                    }

                    value = model.Recreate(value_type, valueId);

                    if (streamed_sans_ids)                     // since the stream didn't have the id, we need to explicit set it via value
                    {
                        valueId = value.Id;
                    }
                }
            }
            else
            {
                value = model.Values[valueId];
                if (is_global = value.IsGlobal)
                {
                    s.WriteAttribute(kIsGlobalAttributeName, true);
                    s.WriteCursor(valueId);
                }
            }

            if (!is_global)             // stream non-global values essentially like locals
            {
                Contract.Assume(value != null);
                value.Serialize(model, s);
            }
        }
Exemplo n.º 4
0
        protected virtual int SerializeImpl <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            int type = s.IsReading ? TypeExtensions.kNone : ProtoData.DBID;

            model.SerializeOperationId(s, ref type, ObjectType);

            if (type != 0)
            {
                if (s.IsWriting && (model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.TryToPort) != 0)
                {
                    ProtoData.WriteForTryToPort(s, model.Database);
                }

                if (s.IsWriting && (model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.WriteConditionTypeNames) != 0)
                {
                    s.WriteAttribute("name", ProtoData.Name);
                }

                #region UnionGroup
                if (model.TagElementStreamSerializeFlags.EmbedObjectsWriteSansIds())
                {
                    if (s.IsWriting)
                    {
                        WriteUnionGroupForSansIds(model, s);
                    }
                    else if (!s.ReadAttributeOpt(kAttributeNameUnionGroup, ref mUnionGroup))
                    {
                        mUnionGroup = kUseNewUnionGroupId;
                    }
                }
                else
                {
                    s.StreamAttribute(kAttributeNameUnionGroup, ref mUnionGroup);
                }
                #endregion

                s.StreamAttributeOpt("invert", ref mInverted, Predicates.IsTrue);

                // #REVIEW_BLAM: ThrowReadException?
                if (!UnionGroupIdIsValid(model, s.IsReading))
                {
                    throw new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo,
                                                                           "Condition #{0} has an invalid union group id #{1}",
                                                                           Id, UnionGroup));
                }
            }
            return(type);
        }
Exemplo n.º 5
0
		public static BinaryDataTreeVariantTypeDesc GuessFromStream<TDoc, TCursor>(IO.TagElementStream<TDoc, TCursor, string> s, out int arrayLength)
			where TDoc : class
			where TCursor : class
		{
			arrayLength = 0;

			string typeName = null;
			if (!s.ReadAttributeOpt("dataType", ref typeName))
				return Null;

			var guessedType = GuessTypeFromSerializedString(typeName);

			int alignment = -1;
			s.ReadAttributeOpt("alignment", ref alignment);

			if (s.ReadAttributeOpt("arraySize", ref arrayLength) && arrayLength > 1)
			{
				if (guessedType.Type == EType.Float)
					guessedType = SingleVector;
			}

			return guessedType;
		}
        private void ReadResourceFlags <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            bool flag = false;

            if (s.ReadAttributeOpt("IsContiguous", ref flag))
            {
                IsContiguous = flag;
            }
            if (s.ReadAttributeOpt("IsWriteCombined", ref flag))
            {
                IsWriteCombined = flag;
            }
            if (s.ReadAttributeOpt("IsDeflateStream", ref flag))
            {
                IsDeflateStream = flag;
            }
            if (s.ReadAttributeOpt("IsResourceTag", ref flag))
            {
                IsResourceTag = flag;
            }
        }
Exemplo n.º 7
0
        void ReadEngineLanguageTable <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            const string kElementNameEntry       = "E";
            const string kAttributeNameGameIndex = "id";
            const string kAttributeNameLangIndex = "lang";
            const string kAttributeNameOptional  = "optional";

            // number of languages for this build of the engine
            int lang_count = 0;

            foreach (var e in s.ElementsByName(kElementNameEntry))
            {
                using (s.EnterCursorBookmark(e))
                {
                    int  game_index  = TypeExtensions.kNone;
                    int  lang_index  = TypeExtensions.kNone;
                    bool is_optional = false;

                    s.ReadAttribute(kAttributeNameGameIndex, ref game_index, NumeralBase.Decimal);
                    LanguageRegistry.SerializeLanguageId(s, kAttributeNameLangIndex, ref lang_index);
                    s.ReadAttributeOpt(kAttributeNameOptional, ref is_optional);

                    if (IsInvalidGameIndexFromStream(game_index) || lang_index.IsNone())
                    {
                        s.ThrowReadException(new System.IO.InvalidDataException("Invalid table entry data"));
                    }

                    mEngineLanguageTable[lang_index] = new GameLanguageHandle(mBuildHandle, lang_index, game_index);
                    if (is_optional)
                    {
                        mOptionalEngineLanguageFlags[lang_index] = true;
                        mOptionalGameLanguageFlags[game_index]   = true;
                    }

                    lang_count++;
                }
            }

            if (lang_count == 0)
            {
                s.ThrowReadException(new System.IO.InvalidDataException("Table has no entries"));
            }

            if (!InitializeGameLanguageTableFromEngineTable(lang_count))
            {
                s.ThrowReadException(new System.IO.InvalidDataException("Invalid game index data"));
            }
        }