Exemplo n.º 1
0
        /// <summary>
        /// Used to add the initial session to this Mega Session
        /// </summary>
        public void SetOrigoSession(Session session)
        {
            foreach (Tile tile in session.Tiles)
            {
                tile.GlobalX = tile.LocalX;
                tile.GlobalY = tile.LocalY;

                LayerTile lt = new LayerTile();
                lt.CurrentSession = session.Name;
                lt.GlobalX        = tile.GlobalX;
                lt.GlobalY        = tile.GlobalY;
                lt.LocalX         = tile.LocalX;
                lt.LocalY         = tile.LocalY;
                lt.TileFilePath   = tile.TileFilePath;

                SessionHistoryEntry history_entry = new SessionHistoryEntry();
                history_entry.SessionX = 0;
                history_entry.SessionY = 0;
                history_entry.Session  = session.Name;
                lt.SessionHistory.Add(history_entry);

                //Non serializeable
                lt.SessionRef     = session;
                lt.SessionTileRef = tile;

                m_tiles.Add(lt);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="session"></param>
        public bool Analyze(Session in_session)
        {
            bool was_match    = false;
            int  session_x    = 0;
            int  session_y    = 0;
            int  match_tile_x = 0;
            int  match_tile_y = 0;

            //Make a local copy of the tile list
            m_tile_mutex.WaitOne();
            LayerTile[] our_tiles = new LayerTile[m_tiles.Count];
            int         idx       = 0;

            foreach (LayerTile mst in m_tiles)
            {
                our_tiles[idx++] = mst;
            }
            m_tile_mutex.ReleaseMutex();

            //Match tiles!
            foreach (Tile in_session_tile in in_session.Tiles)
            {
                foreach (LayerTile layer_tile in our_tiles)
                {
                    if (Compare(in_session_tile, layer_tile.SessionTileRef, 90.0))
                    {
                        //We have a match!
                        in_session_tile.GlobalX = layer_tile.GlobalX;
                        in_session_tile.GlobalY = layer_tile.GlobalY;

                        //if this tile is -1, -2
                        //Then our session global x would be (other_x + (1)) or (other_x - (-1))
                        session_x = layer_tile.GlobalX - in_session_tile.LocalX;
                        session_y = layer_tile.GlobalY - in_session_tile.LocalY;

                        match_tile_x = in_session_tile.LocalX;
                        match_tile_y = in_session_tile.LocalY;

                        was_match = true;
                        break;
                    }
                }
                if (was_match)
                {
                    break;
                }
            }

            if (was_match)
            {
                //Also attempt to look at neighbours
                foreach (Tile in_tile in in_session.Tiles)
                {
                    in_tile.GlobalX = session_x + in_tile.LocalX;
                    in_tile.GlobalY = session_y + in_tile.LocalY;

                    //Find that tiles in our tiles repo
                    foreach (LayerTile layer_tile in our_tiles)
                    {
                        if (in_tile.GlobalX == layer_tile.GlobalX &&
                            in_tile.GlobalY == layer_tile.GlobalY)
                        {
                            //Attempt to match this tile to
                            if (!Compare(in_tile, layer_tile.SessionTileRef, 90.0))
                            {
                                return(false);
                            }
                        }
                    }
                }

                m_tile_mutex.WaitOne();
                foreach (Tile tile in in_session.Tiles)
                {
                    tile.GlobalX = session_x + tile.LocalX;
                    tile.GlobalY = session_y + tile.LocalY;

                    //T_T
                    List <LayerTile> to_remove = new List <LayerTile>();
                    foreach (LayerTile layer_tile in m_tiles)
                    {
                        if (layer_tile.GlobalX == tile.GlobalX &&
                            layer_tile.GlobalY == tile.GlobalY)
                        {
                            to_remove.Add(layer_tile);
                        }
                    }
                    foreach (LayerTile remove_tile in to_remove)
                    {
                        m_tiles.Remove(remove_tile);
                    }

                    LayerTile lt = new LayerTile();
                    lt.CurrentSession = in_session.Name;
                    lt.GlobalX        = tile.GlobalX;
                    lt.GlobalY        = tile.GlobalY;
                    lt.LocalX         = tile.LocalX;
                    lt.LocalY         = tile.LocalY;
                    lt.TileFilePath   = tile.TileFilePath;

                    SessionHistoryEntry history_entry = new SessionHistoryEntry();
                    history_entry.SessionX = 0;
                    history_entry.SessionY = 0;
                    lt.SessionHistory.Add(history_entry);

                    //Non serializeable
                    lt.SessionRef     = in_session;
                    lt.SessionTileRef = tile;

                    m_tiles.Add(lt);

                    //Also save the tile!
                    Database.SaveTile(0, lt);
                }

                m_tile_mutex.ReleaseMutex();
            }



            return(was_match);
        }