internal void OptimizeStorage()
 {
     if (EnabledCount == 0)
     {
         mBits = null;
     }
 }
        internal IProtoEnum InitializeFromEnum(Phx.BDatabaseBase db)
        {
            IProtoEnum penum = null;

            if (Params.kGetProtoEnum != null)
            {
                penum = Params.kGetProtoEnum();
            }
            else if (db != null)
            {
                penum = Params.kGetProtoEnumFromDB(db);
            }

            if (penum != null)
            {
                if (mBits == null)
                {
                    mBits = new Collections.BitSet(penum.MemberCount);
                }
                else
                {
                    mBits.Clear();

                    if (mBits.Length != penum.MemberCount)
                    {
                        mBits.Length = penum.MemberCount;
                    }
                }

                InitializeDefaultValues(penum);
            }

            return(penum);
        }
        static void InitializePrototypes()
        {
            // #TODO_BLAM: if we use a 'null' engine entry, add it here, before the prototypes are read
            using (var s = OpenRegistryTagElementStream())
            {
                SerializePrototypes(s);
                SerializeTargets(s);
            }

            KSoft.Debug.ValueCheck.IsLessThanEqualTo("EngineRegistry: Too many registered engines",
                                                     BlamEngine.kMaxCount, Engines.Count);
            KSoft.Debug.ValueCheck.IsLessThanEqualTo("EngineRegistry: Too many registered target platforms",
                                                     EngineTargetPlatform.kMaxCount, TargetPlatforms.Count);
            KSoft.Debug.ValueCheck.IsLessThanEqualTo("EngineRegistry: Too many registered resource models",
                                                     kMaxResourceModels, ResourceModels.Count);

            KSoft.Debug.ValueCheck.IsDistinct("EngineRegistry: Duplicate engines registered",
                                              "name", Engines.Select(e => e.Name));
            KSoft.Debug.ValueCheck.IsDistinct("EngineRegistry: Duplicate target platforms registered",
                                              "name", TargetPlatforms.Select(e => e.Name));
            KSoft.Debug.ValueCheck.IsDistinct("EngineRegistry: Duplicate resource models registered",
                                              "name", ResourceModels);

            gEngines.TrimExcess();
            gTargetPlatforms.TrimExcess();
            gResourceModels.TrimExcess();

            BlamEngine.InitializeEngineBuildHandles();
            kNullValidTargetPlatforms = new Collections.BitSet(TargetPlatforms.Count);
            InitializeTargetPlatformIndicies();
        }
        protected MegaloScriptModel(Variants.GameEngineVariant variantManager, Variants.GameEngineMegaloVariant variant)
        {
            Database      = variantManager.MegaloProtoSystem.GetMegaloDatabaseAsync(variantManager.GameBuild).Result;
            MegaloVariant = variant;

            var db = Database;

            UnionGroups           = new Collections.ActiveList <MegaloScriptUnionGroup>(db.Limits.UnionGroupsDesc);
            Values                = new Collections.ActiveList <MegaloScriptValueBase>(db.Limits.ScriptValuesDesc);
            VirtualTriggers       = new Collections.ActiveList <MegaloScriptVirtualTrigger>(db.Limits.VirtualTriggersDesc);
            TriggerExecutionOrder = new ObservableCollection <int>();

            Conditions     = new Collections.ActiveList <MegaloScriptCondition>(db.Limits.ConditionsDesc);
            Actions        = new Collections.ActiveList <MegaloScriptAction>(db.Limits.ActionsDesc);
            Triggers       = new Collections.ActiveList <MegaloScriptTrigger>(db.Limits.TriggersDesc);
            GameStatistics = new ObservableCollection <MegaloScriptGameStatistic>();
            #region Variable Sets
            GlobalVariables = new MegaloScriptModelVariableSet(Database, MegaloScriptVariableSet.Globals);
            PlayerVariables = new MegaloScriptModelVariableSet(Database, MegaloScriptVariableSet.Player);
            ObjectVariables = new MegaloScriptModelVariableSet(Database, MegaloScriptVariableSet.Object);
            TeamVariables   = new MegaloScriptModelVariableSet(Database, MegaloScriptVariableSet.Team);
            #endregion
            HudWidgets = new ObservableCollection <MegaloScriptHudWidget>();
            #region Trigger entry points
            InitializationTriggerIndex           = LocalInitializationTriggerIndex =
                HostMigrationTriggerIndex        = DoubleHostMigrationTriggerIndex =
                    ObjectDeathEventTriggerIndex =
                        LocalTriggerIndex        = PregameTriggerIndex =
                            IncidentTriggerIndex =
                                TypeExtensions.kNone;
            #endregion
            ObjectTypeReferences = new Collections.BitSet(db.Limits.MultiplayerObjectTypes.MaxCount);
            ObjectFilters        = new ObservableCollection <MegaloScriptObjectFilter>();
            CandySpawnerFilters  = new ObservableCollection <MegaloScriptGameObjectFilter>();
        }
Exemple #5
0
        static int SerializeUserOptionToggle <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                             Collections.BitSet bitset, int bitIndex, GameEngineMegaloVariant variant)
            where TDoc : class
            where TCursor : class
        {
            if (!variant.TagElementStreamSerializeFlags.UseUserOptionNames())
            {
                s.StreamCursor(ref bitIndex);
            }
            else if (s.IsReading)
            {
                string option_name = null;
                s.ReadCursor(ref option_name);
                bitIndex = variant.EngineDefinition.FromIndexName(
                    Megalo.Proto.MegaloScriptValueIndexTarget.Option, option_name);
            }
            else if (s.IsWriting)
            {
                string option_name = variant.EngineDefinition.ToIndexName(
                    Megalo.Proto.MegaloScriptValueIndexTarget.Option, bitIndex);
                s.WriteCursor(option_name);
            }

            return(bitIndex);
        }
Exemple #6
0
        protected GameEngineMegaloVariant(GameEngineVariant variantManager,
                                          LocaleStringTableInfo stringTableInfo,
                                          LocaleStringTableInfo nameStringInfo, LocaleStringTableInfo descriptionStringInfo,
                                          LocaleStringTableInfo categoryStringInfo)
        {
            var build_handle = variantManager.GameBuild;

            EngineDefinition = Megalo.Model.MegaloScriptModel.Create(variantManager, this);

            PlayerTraits           = new List <MegaloVariantPlayerTraitsBase>(MegaloDatabase.Limits.PlayerTraits.MaxCount);
            UserDefinedOptions     = new List <MegaloVariantUserDefinedOption>(MegaloDatabase.Limits.UserDefinedOptions.MaxCount);
            StringTable            = new LocaleStringTable(stringTableInfo, build_handle);
            BaseNameStringIndex    = TypeExtensions.kNone;
            NameString             = new LocaleStringTable(nameStringInfo, build_handle);
            DescriptionString      = new LocaleStringTable(descriptionStringInfo, build_handle);
            CategoryString         = new LocaleStringTable(categoryStringInfo, build_handle);
            EngineIconIndex        = EngineCategory = TypeExtensions.kNone;
            MapPermissions         = new MegaloVariantMapPermissions();
            PlayerRatingParameters = new MegaloVariantPlayerRatingParameters();

            DisabledEngineOptions = new Collections.BitSet(MegaloDatabase.Limits.GameEngineOptions.MaxCount, fixedLength: true);
            HiddenEngineOptions   = new Collections.BitSet(MegaloDatabase.Limits.GameEngineOptions.MaxCount, fixedLength: true);
            DisabledUserOptions   = new Collections.BitSet(MegaloDatabase.Limits.UserDefinedOptions.MaxCount, fixedLength: true);
            HiddenUserOptions     = new Collections.BitSet(MegaloDatabase.Limits.UserDefinedOptions.MaxCount, fixedLength: true);
        }
Exemple #7
0
        static int SerializeEngineOptionToggle <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                               Collections.BitSet bitset, int bitIndex, GameEngineMegaloVariant variant)
            where TDoc : class
            where TCursor : class
        {
            s.StreamCursor(ref bitIndex);

            return(bitIndex);
        }
Exemple #8
0
        internal static void SerializeBitSet <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                             ref Collections.BitSet bitset, string setElementName, string bitElementName = "Platform")
            where TDoc : class
            where TCursor : class
        {
            using (var bm = s.EnterCursorBookmarkOpt(setElementName, bitset, Predicates.HasBits)) if (bm.IsNotNull)
                {
                    if (s.IsReading)
                    {
                        bitset = new Collections.BitSet(EngineRegistry.TargetPlatforms.Count);
                    }

                    bitset.Serialize(s, bitElementName, (object)null, SerializeBitIndex);
                }
        }
        static int SerializeObjectTypeReference <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                                Collections.BitSet bitset, int bitIndex, MegaloScriptModel model)
            where TDoc : class
            where TCursor : class
        {
            if (s.IsReading)
            {
                string object_name = null;
                s.ReadCursor(ref object_name);
                bitIndex = model.FromIndexName(Proto.MegaloScriptValueIndexTarget.ObjectType, object_name);
            }
            else if (s.IsWriting)
            {
                string object_name = model.ToIndexName(Proto.MegaloScriptValueIndexTarget.ObjectType, bitIndex);
                s.WriteCursor(object_name);
            }

            return(bitIndex);
        }
Exemple #10
0
        static int SerializeBitIndex <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                     Collections.BitSet bitset, int bitIndex, object _null)
            where TDoc : class
            where TCursor : class
        {
            if (s.IsReading)
            {
                string platform_name = null;
                s.ReadCursor(ref platform_name);
                bitIndex = TargetPlatformIdResolver(null, platform_name);
            }
            else if (s.IsWriting)
            {
                string platform_name = TargetPlatformNameResolver(null, bitIndex);
                s.WriteCursor(platform_name);
            }

            return(bitIndex);
        }
        private void AssignItems(Collections.BitSet newBits)
        {
            if (newBits == null)
            {
                foreach (var bit_model in BitItems)
                {
                    if (bit_model.IsSet)
                    {
                        bit_model.IsSet = false;
                    }
                }
            }
            else
            {
                foreach (var bit_model in BitItems)
                {
                    if (!bit_model.IsValid)
                    {
                        continue;
                    }

                    int bit_index = bit_model.BitIndex;

                    if (bit_index >= newBits.Length)
                    {
                        throw new ArgumentOutOfRangeException(string.Format(Util.InvariantCultureInfo,
                                                                            "newBits length is {0} which is less than the number of bits needed to represent one or more items. #{1} can't be updated ({2})",
                                                                            newBits.Length, bit_index, bit_model.DisplayName));
                    }

                    bool old_bit = bit_model.IsSet;
                    bool new_bit = newBits[bit_index];
                    if (old_bit != new_bit)
                    {
                        bit_model.IsSet = new_bit;
                    }
                }
            }
        }