示例#1
0
        private TypedFlags <eBindGameAction> LookupCharacterData(
            RequestCache requestCache)
        {
            TypedFlags <eBindGameAction> actionFlags = new TypedFlags <eBindGameAction>();

            actionFlags.Clear();

            // Get the current state of the character before moving them to another game
            m_character_state = CharacterQueries.GetFullCharacterState(requestCache.DatabaseContext, m_character_id);

            // Get the previous game this character was a part of, if any
            m_previous_game_id = m_character_state.game_id;

            // Only bother doing anything if the character isn't already bound to this game
            if (m_previous_game_id != m_game_id)
            {
                if (m_previous_game_id != -1)
                {
                    actionFlags.Set(eBindGameAction.leaveGame, true);
                }

                actionFlags.Set(eBindGameAction.joinGame, true);
            }

            return(actionFlags);
        }
示例#2
0
        private void ParseEntities(XmlNode entityXml)
        {
            foreach (XmlNode energyTankNode in entityXml.SelectNodes("EnergyTank"))
            {
                m_energyTanks.Add(new EnergyTankTemplate(energyTankNode));
            }

            foreach (XmlNode treasureNode in entityXml.SelectNodes("Treasure"))
            {
                m_treasures.Add(new TreasureTemplate(treasureNode));
            }

            foreach (XmlNode trapNode in entityXml.SelectNodes("Trap"))
            {
                m_traps.Add(new TrapTemplate(trapNode));
            }

            foreach (XmlNode mobSpawnerNode in entityXml.SelectNodes("MobSpawner"))
            {
                m_mobSpawners.Add(new MobSpawnerTemplate(mobSpawnerNode));
            }

            m_portalRoomSideBitmask.Clear();
            foreach (XmlNode portalNode in entityXml.SelectNodes("Portal"))
            {
                PortalTemplate portalTemplate = new PortalTemplate(portalNode);

                m_portals.Add(portalTemplate);
                if (portalTemplate.PortalRoomSide != MathConstants.eSignedDirection.none)
                {
                    m_portalRoomSideBitmask.Set(portalTemplate.PortalRoomSide, true);
                }
            }
        }
        private TypedFlags<eBindGameAction> LookupCharacterData(
            RequestCache requestCache)
        {
            TypedFlags<eBindGameAction> actionFlags = new TypedFlags<eBindGameAction>();

            actionFlags.Clear();

            // Get the current state of the character before moving them to another game
            m_character_state = CharacterQueries.GetFullCharacterState(requestCache.DatabaseContext, m_character_id);

            // Get the previous game this character was a part of, if any
            m_previous_game_id = m_character_state.game_id;

            // Only bother doing anything if the character isn't already bound to this game
            if (m_previous_game_id != m_game_id)
            {
                if (m_previous_game_id != -1)
                {
                    actionFlags.Set(eBindGameAction.leaveGame, true);
                }

                actionFlags.Set(eBindGameAction.joinGame, true);
            }

            return actionFlags;
        }
示例#4
0
        public bool RunTest()
        {
            bool success = true;

            {
                TypedFlags <TestEnum> flags = new TypedFlags <TestEnum>();

                Debug.Assert(flags.IsEmpty());
                success &= flags.IsEmpty();

                for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex)
                {
                    Debug.Assert(!flags.Test(bitIndex));
                    success &= !flags.Test(bitIndex);

                    flags.Set(bitIndex, true);
                    Debug.Assert(flags.Test(bitIndex));
                    success &= flags.Test(bitIndex);

                    flags.Set(bitIndex, false);
                    Debug.Assert(!flags.Test(bitIndex));
                    success &= !flags.Test(bitIndex);
                }
            }


            {
                TypedFlags <TestEnum> flagsA = new TypedFlags <TestEnum>();
                TypedFlags <TestEnum> flagsB = new TypedFlags <TestEnum>();

                flagsB.Set(TestEnum._flag10, true);

                TypedFlags <TestEnum> flagsC = new TypedFlags <TestEnum>(flagsB);

                Debug.Assert(flagsA != flagsB);
                success &= flagsA != flagsB;

                Debug.Assert(flagsB == flagsC);
                success &= flagsB == flagsC;
            }

            {
                TypedFlags <TestEnum> flags = new TypedFlags <TestEnum>(
                    TypedFlags <TestEnum> .FLAG(TestEnum._flag4) |
                    TypedFlags <TestEnum> .FLAG(TestEnum._flag9));


                for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex)
                {
                    if (bitIndex == TestEnum._flag4 || bitIndex == TestEnum._flag9)
                    {
                        Debug.Assert(flags.Test(bitIndex));
                        success &= flags.Test(bitIndex);
                    }
                    else
                    {
                        Debug.Assert(!flags.Test(bitIndex));
                        success &= !flags.Test(bitIndex);
                    }
                }
            }

            return(success);
        }
示例#5
0
 public void RoomFlagPortalOnSide(MathConstants.eSignedDirection side, bool flag)
 {
     portalRoomSideBitmask.Set(side, flag);
 }
示例#6
0
        private void JoinAdjacentDisjointRoomSets(
            Dictionary <int, List <RoomIndex> > connectivityIdToRoomIndexMap)
        {
            // Look for any null room that neighboring at least two disjoint sets of rooms
            for (RoomIndexIterator iterator = new RoomIndexIterator(m_roomGrid, RoomIndexIterator.eIterationType.nullRooms);
                 iterator.Valid;
                 iterator.Next())
            {
                RoomIndex   nullRoomIndex      = iterator.Current;
                RoomIndex[] neighboringIndices = new RoomIndex[4] {
                    nullRoomIndex.Offset(1, 0, 0),
                    nullRoomIndex.Offset(-1, 0, 0),
                    nullRoomIndex.Offset(0, 1, 0),
                    nullRoomIndex.Offset(0, -1, 0)
                };
                MathConstants.eSignedDirection[] neighborSideFlags = new MathConstants.eSignedDirection[4] {
                    MathConstants.eSignedDirection.positive_x,
                    MathConstants.eSignedDirection.negative_x,
                    MathConstants.eSignedDirection.positive_y,
                    MathConstants.eSignedDirection.negative_y
                };

                bool createNewRoom = false;
                TypedFlags <MathConstants.eSignedDirection> nullRoomNeighborFlags = new TypedFlags <MathConstants.eSignedDirection>();
                int lastConnectivityId = -1;

                for (int side_index = 0; side_index < 4; ++side_index)
                {
                    MathConstants.eSignedDirection neighborSide = neighborSideFlags[side_index];
                    RoomIndex neighborRoomIndex = neighboringIndices[side_index];

                    // See if an adjacent room exists on this side
                    RoomLayout neighborRoom = TryGetRoomByIndex(neighborRoomIndex);

                    if (neighborRoom != null)
                    {
                        // Record that a neighboring room was found in this side
                        nullRoomNeighborFlags.Set(neighborSide, true);

                        // See if the neighboring room is actually disjoint from a previous neighbor
                        // we have found on another side (different connectivity_id)
                        int roomConnectivityId = neighborRoom.connectivity_id;

                        if (lastConnectivityId != -1 &&
                            roomConnectivityId != lastConnectivityId)
                        {
                            List <RoomIndex> roomSet     = connectivityIdToRoomIndexMap[roomConnectivityId];
                            List <RoomIndex> lastRoomSet = connectivityIdToRoomIndexMap[lastConnectivityId];

                            // Make the connectivity ids match for rooms in both sets
                            roomSet.ForEach(rIndex => GetRoomByIndex(rIndex).connectivity_id = lastConnectivityId);

                            // Merge the rooms in the set into the previous set
                            lastRoomSet.AddRange(roomSet);

                            // Remove the set
                            connectivityIdToRoomIndexMap.Remove(roomConnectivityId);

                            // Since we have merged two adjacent sets we now need a new room
                            // to bridge the disjoin sets
                            createNewRoom = true;
                        }

                        // Keep track of the last valid connectivity we found for the next iteration
                        lastConnectivityId = neighborRoom.connectivity_id;
                    }
                }

                if (createNewRoom)
                {
                    // Create a new room at the null room index location
                    RoomLayout newRoom = new RoomLayout(GetRoomKeyForRoomIndex(nullRoomIndex));

                    // Record which neighbors the null room has
                    newRoom.portalRoomSideBitmask = nullRoomNeighborFlags;

                    // All neighbors should have the same connectivity id now
                    // so just get the connectivity id from the last valid neighbor
                    newRoom.connectivity_id = lastConnectivityId;

                    // Finally store the new room in the room grid
                    m_roomGrid[nullRoomIndex.X, nullRoomIndex.Y, nullRoomIndex.Z] = newRoom;

                    // Add the new room to the connectivity set it's helping to bridge
                    {
                        List <RoomIndex> lastRoomSet = connectivityIdToRoomIndexMap[lastConnectivityId];

                        lastRoomSet.Add(new RoomIndex(nullRoomIndex));
                    }

                    // Tell all neighboring rooms about the new room adjacent to it
                    for (int side_index = 0; side_index < 4; ++side_index)
                    {
                        MathConstants.eSignedDirection neighborSide = neighborSideFlags[side_index];
                        RoomIndex neighborRoomIndex = neighboringIndices[side_index];

                        // See if an adjacent room exists on this side
                        if (newRoom.portalRoomSideBitmask.Test(neighborSide))
                        {
                            RoomLayout neighborRoom = GetRoomByIndex(neighborRoomIndex);
                            MathConstants.eSignedDirection opposingNeighborSide = RoomKey.GetOpposingRoomSide(neighborSide);

                            neighborRoom.RoomFlagPortalOnSide(opposingNeighborSide, true);
                        }
                    }
                }
            }
        }
        public bool RunTest()
        {
            bool success = true;

            {
                TypedFlags<TestEnum> flags = new TypedFlags<TestEnum>();

                Debug.Assert(flags.IsEmpty());
                success &= flags.IsEmpty();

                for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex)
                {
                    Debug.Assert(!flags.Test(bitIndex));
                    success &= !flags.Test(bitIndex);

                    flags.Set(bitIndex, true);
                    Debug.Assert(flags.Test(bitIndex));
                    success &= flags.Test(bitIndex);

                    flags.Set(bitIndex, false);
                    Debug.Assert(!flags.Test(bitIndex));
                    success &= !flags.Test(bitIndex);
                }
            }

            {
                TypedFlags<TestEnum> flagsA = new TypedFlags<TestEnum>();
                TypedFlags<TestEnum> flagsB = new TypedFlags<TestEnum>();

                flagsB.Set(TestEnum._flag10, true);

                TypedFlags<TestEnum> flagsC = new TypedFlags<TestEnum>(flagsB);

                Debug.Assert(flagsA != flagsB);
                success &= flagsA != flagsB;

                Debug.Assert(flagsB == flagsC);
                success &= flagsB == flagsC;
            }

            {
                TypedFlags<TestEnum> flags = new TypedFlags<TestEnum>(
                    TypedFlags<TestEnum>.FLAG(TestEnum._flag4) |
                    TypedFlags<TestEnum>.FLAG(TestEnum._flag9));

                for (TestEnum bitIndex = TestEnum._flag0; bitIndex <= TestEnum._flag31; ++bitIndex)
                {
                    if (bitIndex == TestEnum._flag4 || bitIndex == TestEnum._flag9)
                    {
                        Debug.Assert(flags.Test(bitIndex));
                        success &= flags.Test(bitIndex);
                    }
                    else
                    {
                        Debug.Assert(!flags.Test(bitIndex));
                        success &= !flags.Test(bitIndex);
                    }
                }
            }

            return success;
        }