Exemple #1
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"));
            }
        }
Exemple #2
0
        void InitializeEngineLanguageTableWithBuildHandle()
        {
            mEngineLanguageTable = new GameLanguageHandle[LanguageRegistry.NumberOfLanguages];

            for (int langIndex = 0; langIndex < mEngineLanguageTable.Length; langIndex++)
            {
                mEngineLanguageTable[langIndex] =
                    new GameLanguageHandle(mBuildHandle, langIndex, TypeExtensions.kNone);
            }

            Contract.Assert(LanguageRegistry.NumberOfLanguages <= Bits.kInt32BitCount,
                            nameof(mOptionalEngineLanguageFlags) + " and " + nameof(mOptionalGameLanguageFlags) +
                            " are too small to actually be a language bitvector");
        }
Exemple #3
0
 static bool IsInvalidGameIndexFromStream(int index)
 {
     return(index < 0 || !GameLanguageHandle.IsValidGameIndex(index));
 }