示例#1
0
        private IEnumerable <GeoModel> createBlock(GeoBlock block)
        {
            float ox, oy, oz;

            if (block.getType() == GEO.GEO_BLOCK_TYPE_FLAT)
            {
                GeoCell cell = block.nGetCell(0, 0, 0);
                //
                float xx = GEO.getWorldX(cell.getGeoX());
                float yy = GEO.getWorldY(cell.getGeoY());
                float zz = GEO.getHeight(cell.getHeight());
                yield return(appendModel(xx, zz, yy, true));
            }
            else if (block.getType() == GEO.GEO_BLOCK_TYPE_COMPLEX)
            {
                GeoModel  m;
                GeoCell   cell;
                GeoCell[] cells = block.getCells();
                int       c     = cells.Length;
                for (int i = 0; i < c; i++)
                {
                    cell = cells[i];
                    ox   = GEO.getWorldX(cell.getGeoX());
                    oz   = GEO.getWorldY(cell.getGeoY());
                    oy   = GEO.getHeight(cell.getHeight());
                    m    = appendModel(ox, oy, oz, false);
                    updateMask(m, cell);
                    yield return(m);
                }
            }
            else if (block.getType() == GEO.GEO_BLOCK_TYPE_MULTILAYER)
            {
                int c = block.getMaxLayerCount();
                //
                GeoModel m;
                int      x, y;
                int      min_x = block.getGeoX();
                int      max_x = block.getMaxGeoX();
                int      min_y = block.getGeoY();
                int      max_y = block.getMaxGeoY();
                for (y = min_y; y <= max_y; y++)
                {
                    for (x = min_x; x <= max_x; x++)
                    {
                        GeoCell[] cells = block.nGetLayers(x, y);
                        foreach (GeoCell cell in cells)
                        {
                            ox = GEO.getWorldX(cell.getGeoX());
                            oz = GEO.getWorldY(cell.getGeoY());
                            oy = GEO.getHeight(cell.getHeight());
                            m  = appendModel(ox, oy, oz, false);
                            updateMask(m, cell);
                            yield return(m);
                        }
                    }
                }
            }
        }
        //=============================

        public static GeoBlockMultiLayer convertFrom(GeoBlock block)
        {
            if (block is GeoBlockFlat)
            {
                return(new GeoBlockMultiLayer((GeoBlockFlat)block));
            }
            if (block is GeoBlockComplex)
            {
                return(new GeoBlockMultiLayer((GeoBlockComplex)block));
            }
            return(new GeoBlockMultiLayer((GeoBlockMultiLayer)block));
        }
示例#3
0
        public Color getColor(GeoBlock block, bool insideSelectionBox)
        {
            switch (block.getType())
            {
            case Engine.GEO_BLOCK_TYPE_FLAT: return(_colorFlat);

            case Engine.GEO_BLOCK_TYPE_COMPLEX:
                return(block.getBlockX() % 2 != block.getBlockY() % 2 ? _colorComplex2 : _colorComplex1);

            default:
                if (insideSelectionBox)
                {
                    return(block.getBlockX() % 2 != block.getBlockY() % 2 ? _colorMutliLayer2Special : _colorMutliLayer1Special);
                }
                else
                {
                    return(block.getBlockX() % 2 != block.getBlockY() % 2 ? _colorMutliLayer2 : _colorMutliLayer1);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Initializes <see cref="Geodata"/> engine.
        /// </summary>
        /// <returns>True, if <see cref="Geodata"/> engine was initialized successfully, otherwise false.</returns>
        internal static unsafe bool Initialize()
        {
            //return true;

            try
            {
                FileInfo[] filesInfoArray = L2FileReader.GetFiles
                    (
                        Path.Combine
                            (
                                AppDomain.CurrentDomain.BaseDirectory,
                                Settings.Default.GeodataFilesPath
                            ),
                        m_GeoFileMask,
                        SearchOption.TopDirectoryOnly
                    );

                FileInfo currentFile;

                int counter, reader, i, j, k, m;
                short[] heightsComplex = new short[0x40], heightsMultilayered = new short[0x900];
                byte[] heightsMap = new byte[0x40];
                ushort[] offsetsMap = new ushort[0x40];
                GeoBlock[] nextMap;
            #if GEO_FIX_DATA
                bool flat;
            #endif
                for ( i = 0; i < filesInfoArray.Length; i++ )
                {
                    currentFile = filesInfoArray[i];

                    Logger.Write(false, "Loading {0} ", currentFile.Name);

                    counter = reader = 0;
                    nextMap = new GeoBlock[ushort.MaxValue];

                    fixed ( byte* buffer = L2FileReader.Read(currentFile.FullName, ( int )currentFile.Length) )
                    {
                        while ( counter < ushort.MaxValue )
                        {
                            switch ( *( buffer + reader++ ) )
                            {
                                case 0x00:
                                    {
                                        nextMap[counter] = new GeoBlock(null, null, *( short* )( buffer + reader ));
                                        reader += sizeof(short);
                                        break;
                                    }
                                case 0x01:
                                    {
            #if GEO_FIX_DATA
                                        flat = true;
            #endif
                                        fixed ( short* heights = heightsComplex )
                                        {
                                            for ( j = 0; j < 0x40; reader += sizeof(short), j++ )
                                            {
                                                *( heights + j ) = ( short )( *( short* )( buffer + reader ) >> 1 );

            #if GEO_FIX_DATA
                                                if ( j > 0 && *( heights + j ) != *( heights + j - 1 ) )
                                                    flat = false; // validating that not all heights are same
            #endif
                                            }
                                        }
            #if GEO_FIX_DATA
                                        if ( flat )
                                            nextMap[counter] = new GeoBlock(null, null, heightsComplex[0]);
                                        else
            #endif
                                        nextMap[counter] = new GeoBlock(null, null, heightsComplex);

                                        break;
                                    }
                                case 0x02:
                                    {
                                        fixed ( ushort* offsets = offsetsMap )
                                        fixed ( byte* map = heightsMap )
                                        fixed ( short* heights = heightsMultilayered )
                                        {
                                            for ( j = 0, m = 0; j < 0x40; j++ )
                                            {
                                                *( map + j ) = *( byte* )( buffer + reader++ );

                                                for ( k = 0; k < *( map + j ); k++, m++ )
                                                {
                                                    *( heights + m ) = ( short )( *( short* )( buffer + reader ) >> 1 );
                                                    reader += sizeof(short);
                                                }

                                                *( offsets + j ) = ( ushort )( k + *( offsets + j - 0x01 ) );
                                            }

            #if GEO_FIX_DATA
                                            if ( offsetsMap[0x3f] == 0x40 ) // only 64 heights, so block is complex or flat
                                            {
                                                flat = true;

                                                for ( j = 1; j < 0x40; j++ )
                                                {
                                                    if ( offsetsMap[j] != offsetsMap[j - 1] )
                                                    {
                                                        flat = false; // validating that not all heights are same
                                                        break;
                                                    }
                                                }

                                                if ( flat )
                                                    nextMap[counter] = new GeoBlock(null, null, heights[0]);
                                                else
                                                    nextMap[counter] = new GeoBlock(null, null, L2Buffer.SpecialCopy(heights, 0x40));
                                            }
                                            else
            #endif
                                            nextMap[counter] = new GeoBlock(heightsMap, offsetsMap, L2Buffer.SpecialCopy(heights, offsetsMap[0x3f]));
                                        }

                                        break;
                                    }
                                default:
                                    throw new InvalidOperationException(String.Format("Failed to read geodata file '{0}'", currentFile.FullName));
                            }

                            counter++;

                            if ( counter % ( ushort.MaxValue / 20 ) == 0 )
                                Logger.Write(true, ".");
                        }
                    }

                    geodata.Add(ParseMapOffsets(currentFile), nextMap);
                    Logger.EndWrite(" complete.");
                }

                geodata.TrimExcess();

                filesInfoArray = null;
                currentFile = null;
                heightsComplex = null;
                heightsMultilayered = null;
                heightsMap = null;
                offsetsMap = null;
                nextMap = null;

                GC.WaitForPendingFinalizers();
                GC.Collect();

                return true;
            }
            catch ( Exception e )
            {
                Logger.WriteLine(Source.Geodata, "Failed to load data files.");
                Logger.Exception(e);
            }

            return false;
        }
示例#5
0
 public static GeoBlockFlat convertFrom(GeoBlock block)
 {
     return(new GeoBlockFlat(block));
 }
示例#6
0
 private GeoBlockFlat(GeoBlock block) : base(block.getGeoX(), block.getGeoY())
 {
     _cells = new GeoCell[] { new GeoCellFlat(this, block.getMinHeight()) };
 }
示例#7
0
 public GeoCellCM(GeoBlock block, short heightAndNSWE, int cellX, int cellY) : base(block)
 {
     _cellX         = (byte)cellX;
     _cellY         = (byte)cellY;
     _heightAndNSWE = heightAndNSWE;
 }
 public void setKey(GeoBlock key)
 {
     _key = key;
 }