コード例 #1
0
ファイル: MapChunk.cs プロジェクト: uotools/ClassicUO
        public unsafe void Load(int map)
        {
            IndexMap im = GetIndex(map);

            if (im.MapAddress != 0)
            {
                MapBlock block = Marshal.PtrToStructure <MapBlock>((IntPtr)im.MapAddress);
                int      bx    = X * 8;
                int      by    = Y * 8;

                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        int    pos    = y * 8 + x;
                        ushort tileID = (ushort)(block.Cells[pos].TileID & 0x3FFF);
                        sbyte  z      = block.Cells[pos].Z;
                        Tiles[x][y].Graphic  = tileID;
                        Tiles[x][y].Position = new Position((ushort)(bx + x), (ushort)(by + y), z);
                        Tiles[x][y].AverageZ = z;
                        Tiles[x][y].MinZ     = z;
                        Tiles[x][y].AddGameObject(Tiles[x][y]);
                    }
                }

                if (im.StaticAddress != 0)
                {
                    StaticsBlock *sb = (StaticsBlock *)im.StaticAddress;

                    if (sb != null)
                    {
                        int count = (int)im.StaticCount;

                        for (int i = 0; i < count; i++, sb++)
                        {
                            if (sb->Color > 0 && sb->Color != 0xFFFF)
                            {
                                ushort x   = sb->X;
                                ushort y   = sb->Y;
                                int    pos = y * 8 + x;

                                if (pos >= 64)
                                {
                                    continue;
                                }
                                sbyte  z            = sb->Z;
                                Static staticObject = new Static(sb->Color, sb->Hue, pos)
                                {
                                    Position = new Position((ushort)(bx + x), (ushort)(by + y), z)
                                };
                                Tiles[x][y].AddGameObject(staticObject);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public unsafe void LoadStatics(int map)
        {
            IndexMap im = GetIndex(map);

            if (im.MapAddress != 0)
            {
                int bx = X * 8;
                int by = Y * 8;

                if (im.StaticAddress != 0)
                {
                    StaticsBlock *sb = (StaticsBlock *)im.StaticAddress;

                    if (sb != null)
                    {
                        int count = (int)im.StaticCount;

                        for (int i = 0; i < count; i++, sb++)
                        {
                            if (sb->Color != 0 && sb->Color != 0xFFFF)
                            {
                                ushort x   = sb->X;
                                ushort y   = sb->Y;
                                int    pos = y * 8 + x;

                                if (pos >= 64)
                                {
                                    continue;
                                }
                                sbyte z = sb->Z;

                                ushort staticX = (ushort)(bx + x);
                                ushort staticY = (ushort)(by + y);

                                Static staticObject = new Static(sb->Color, sb->Hue, pos)
                                {
                                    Position = new Position(staticX, staticY, z)
                                };

                                if (staticObject.ItemData.IsAnimated)
                                {
                                    World.AddEffect(new AnimatedItemEffect(staticObject, staticObject.Graphic, staticObject.Hue, -1));
                                }
                                else
                                {
                                    staticObject.AddToTile(Tiles[x, y]);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: WorldMapGump.cs プロジェクト: longtianchi/ClassicUO
        private unsafe void Load()
        {
            int size = FileManager.Map.MapsDefaultSize[World.MapIndex, 0] * FileManager.Map.MapsDefaultSize[World.MapIndex, 1];

            ushort[] buffer   = new ushort[size];
            int      maxBlock = size - 1;

            for (int bx = 0; bx < FileManager.Map.MapBlocksSize[World.MapIndex, 0]; bx++)
            {
                int mapX = bx << 3;

                for (int by = 0; by < FileManager.Map.MapBlocksSize[World.MapIndex, 1]; by++)
                {
                    IndexMap indexMap = World.Map.GetIndex(bx, by);

                    if (indexMap.MapAddress == 0)
                    {
                        continue;
                    }

                    int       mapY      = by << 3;
                    MapBlock  info      = new MapBlock();
                    MapCells *infoCells = (MapCells *)&info.Cells;
                    MapBlock *mapBlock  = (MapBlock *)indexMap.MapAddress;
                    MapCells *cells     = (MapCells *)&mapBlock->Cells;
                    int       pos       = 0;

                    for (int y = 0; y < 8; y++)
                    {
                        for (int x = 0; x < 8; x++)
                        {
                            ref MapCells cell     = ref cells[pos];
                            ref MapCells infoCell = ref infoCells[pos];
                            infoCell.TileID = cell.TileID;
                            infoCell.Z      = cell.Z;
                            pos++;
                        }
                    }

                    StaticsBlock *sb = (StaticsBlock *)indexMap.StaticAddress;

                    if (sb != null)
                    {
                        int count = (int)indexMap.StaticCount;

                        for (int c = 0; c < count; c++)
                        {
                            ref readonly StaticsBlock staticBlock = ref sb[c];
コード例 #4
0
ファイル: MapGump.cs プロジェクト: OutsideTheBoxGit/ClassicUO
        private unsafe void Load()
        {
            int size = IO.Resources.Map.MapsDefaultSize[World.MapIndex][0] * IO.Resources.Map.MapsDefaultSize[World.MapIndex][1];

            ushort[] buffer   = new ushort[size];
            int      maxBlock = size - 1;

            for (int bx = 0; bx < IO.Resources.Map.MapBlocksSize[World.MapIndex][0]; bx++)
            {
                int mapX = bx * 8;

                for (int by = 0; by < IO.Resources.Map.MapBlocksSize[World.MapIndex][1]; by++)
                {
                    IndexMap indexMap = World.Map.GetIndex(bx, by);

                    if (indexMap.MapAddress == 0)
                    {
                        continue;
                    }
                    int mapY = by * 8;

                    MapBlock  info      = new MapBlock();
                    MapCells *infoCells = (MapCells *)&info.Cells;

                    MapBlock *mapBlock = (MapBlock *)indexMap.MapAddress;
                    MapCells *cells    = (MapCells *)&mapBlock->Cells;

                    int pos = 0;

                    for (int y = 0; y < 8; y++)
                    {
                        for (int x = 0; x < 8; x++)
                        {
                            ref MapCells cell     = ref cells[pos];
                            ref MapCells infoCell = ref infoCells[pos];
                            infoCell.TileID = cell.TileID;
                            infoCell.Z      = cell.Z;
                            pos++;
                        }
                    }

                    StaticsBlock *sb = (StaticsBlock *)indexMap.StaticAddress;

                    if (sb != null)
                    {
                        int count = (int)indexMap.StaticCount;

                        for (int c = 0; c < count; c++)
                        {
                            StaticsBlock staticBlock = sb[c];

                            if (staticBlock.Color > 0 && staticBlock.Color != 0xFFFF && !View.IsNoDrawable(staticBlock.Color))
                            {
                                pos = staticBlock.Y * 8 + staticBlock.X;
                                ref MapCells cell = ref infoCells[pos];

                                if (cell.Z <= staticBlock.Z)
                                {
                                    cell.TileID = (ushort)(staticBlock.Color + 0x4000);
                                    cell.Z      = staticBlock.Z;
                                }
                            }
                        }
                    }
コード例 #5
0
        public unsafe override ComputedStaticFieldLayout ComputeStaticFieldLayout(DefType defType)
        {
            MetadataType type            = (MetadataType)defType;
            int          numStaticFields = 0;

            foreach (var field in type.GetFields())
            {
                if (!field.IsStatic || field.HasRva || field.IsLiteral)
                {
                    continue;
                }

                numStaticFields++;
            }

            ComputedStaticFieldLayout result;

            result.GcStatics     = new StaticsBlock();
            result.NonGcStatics  = new StaticsBlock();
            result.ThreadStatics = new StaticsBlock();

            if (numStaticFields == 0)
            {
                result.Offsets = null;
                return(result);
            }

            result.Offsets = new FieldAndOffset[numStaticFields];

            PrepareRuntimeSpecificStaticFieldLayout(type.Context, ref result);

            int index = 0;

            foreach (var field in type.GetFields())
            {
                // Nonstatic fields, literal fields, and RVA mapped fields don't participate in layout
                if (!field.IsStatic || field.HasRva || field.IsLiteral)
                {
                    continue;
                }

                StaticsBlock *block =
                    field.IsThreadStatic ? &result.ThreadStatics :
                    field.HasGCStaticBase ? &result.GcStatics :
                    &result.NonGcStatics;

                SizeAndAlignment sizeAndAlignment = ComputeFieldSizeAndAlignment(field.FieldType, type.Context.Target.DefaultPackingSize);

                block->Size           = AlignmentHelper.AlignUp(block->Size, sizeAndAlignment.Alignment);
                result.Offsets[index] = new FieldAndOffset(field, block->Size);
                block->Size           = checked (block->Size + sizeAndAlignment.Size);

                block->LargestAlignment = Math.Max(block->LargestAlignment, sizeAndAlignment.Alignment);

                index++;
            }

            FinalizeRuntimeSpecificStaticFieldLayout(type.Context, ref result);

            return(result);
        }
コード例 #6
0
        public unsafe void Load(int map)
        {
            IndexMap im = GetIndex(map);

            if (im.MapAddress != 0)
            {
                MapBlock *block = (MapBlock *)im.MapAddress;
                MapCells *cells = (MapCells *)&block->Cells;
                int       bx    = X * 8;
                int       by    = Y * 8;

                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        int    pos    = y * 8 + x;
                        ushort tileID = (ushort)(cells[pos].TileID & 0x3FFF);
                        sbyte  z      = cells[pos].Z;

                        Land land = new Land(tileID)
                        {
                            Graphic  = tileID,
                            AverageZ = z,
                            MinZ     = z,
                        };

                        ushort tileX = (ushort)(bx + x);
                        ushort tileY = (ushort)(by + y);

                        land.Calculate(tileX, tileY, z);
                        land.Position = new Position(tileX, tileY, z);

                        land.AddToTile(Tiles[x, y]);
                    }
                }

                if (im.StaticAddress != 0)
                {
                    StaticsBlock *sb = (StaticsBlock *)im.StaticAddress;

                    if (sb != null)
                    {
                        int count = (int)im.StaticCount;

                        for (int i = 0; i < count; i++, sb++)
                        {
                            if (sb->Color != 0 && sb->Color != 0xFFFF)
                            {
                                ushort x   = sb->X;
                                ushort y   = sb->Y;
                                int    pos = y * 8 + x;

                                if (pos >= 64)
                                {
                                    continue;
                                }
                                sbyte z = sb->Z;

                                ushort staticX = (ushort)(bx + x);
                                ushort staticY = (ushort)(by + y);

                                Static staticObject = new Static(sb->Color, sb->Hue, pos)
                                {
                                    Position = new Position(staticX, staticY, z)
                                };

                                if (staticObject.ItemData.IsAnimated)
                                {
                                    World.AddEffect(new AnimatedItemEffect(staticObject, staticObject.Graphic, staticObject.Hue, -1));
                                }
                                else
                                {
                                    staticObject.AddToTile(Tiles[x, y]);
                                }
                            }
                        }
                    }
                }


                //CreateLand();
            }
        }
コード例 #7
0
        public unsafe override ComputedStaticFieldLayout ComputeStaticFieldLayout(DefType defType, StaticLayoutKind layoutKind)
        {
            MetadataType type            = (MetadataType)defType;
            int          numStaticFields = 0;

            foreach (var field in type.GetFields())
            {
                if (!field.IsStatic || field.HasRva || field.IsLiteral)
                {
                    continue;
                }

                numStaticFields++;
            }

            ComputedStaticFieldLayout result;

            result.GcStatics     = new StaticsBlock();
            result.NonGcStatics  = new StaticsBlock();
            result.ThreadStatics = new StaticsBlock();

            if (numStaticFields == 0)
            {
                result.Offsets = Array.Empty <FieldAndOffset>();
                return(result);
            }

            result.Offsets = new FieldAndOffset[numStaticFields];

            PrepareRuntimeSpecificStaticFieldLayout(type.Context, ref result);

            int index = 0;

            foreach (var field in type.GetFields())
            {
                // Nonstatic fields, literal fields, and RVA mapped fields don't participate in layout
                if (!field.IsStatic || field.HasRva || field.IsLiteral)
                {
                    continue;
                }

                TypeDesc fieldType = field.FieldType;
                if (fieldType.IsByRef || (fieldType.IsValueType && ((DefType)fieldType).IsByRefLike))
                {
                    throw new TypeSystemException.TypeLoadException(ExceptionStringID.ClassLoadGeneral, type);
                }

                StaticsBlock *block =
                    field.IsThreadStatic ? &result.ThreadStatics :
                    field.HasGCStaticBase ? &result.GcStatics :
                    &result.NonGcStatics;

                SizeAndAlignment sizeAndAlignment = ComputeFieldSizeAndAlignment(fieldType, type.Context.Target.DefaultPackingSize);

                block->Size           = LayoutInt.AlignUp(block->Size, sizeAndAlignment.Alignment);
                result.Offsets[index] = new FieldAndOffset(field, block->Size);
                block->Size           = block->Size + sizeAndAlignment.Size;

                block->LargestAlignment = LayoutInt.Max(block->LargestAlignment, sizeAndAlignment.Alignment);

                index++;
            }

            FinalizeRuntimeSpecificStaticFieldLayout(type.Context, ref result);

            return(result);
        }
コード例 #8
0
        public unsafe void Load(int map)
        {
            IndexMap im = GetIndex(map);

            if (im.MapAddress != 0)
            {
                MapBlock *block = (MapBlock *)im.MapAddress;
                MapCells *cells = (MapCells *)&block->Cells;
                int       bx    = X * 8;
                int       by    = Y * 8;

                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        int       pos    = y * 8 + x;
                        ushort    tileID = (ushort)(cells[pos].TileID & 0x3FFF);
                        sbyte     z      = cells[pos].Z;
                        LandTiles info   = TileData.LandData[tileID];

                        Land land = new Land(tileID)
                        {
                            Graphic     = tileID,
                            AverageZ    = z,
                            MinZ        = z,
                            IsStretched = info.TexID == 0 && TileData.IsWet(info.Flags),
                        };
                        ushort tileX = (ushort)(bx + x);
                        ushort tileY = (ushort)(by + y);
                        land.Calculate(tileX, tileY, z);
                        land.Position = new Position(tileX, tileY, z);
                    }
                }

                if (im.StaticAddress != 0)
                {
                    StaticsBlock *sb = (StaticsBlock *)im.StaticAddress;

                    if (sb != null)
                    {
                        int count = (int)im.StaticCount;

                        for (int i = 0; i < count; i++, sb++)
                        {
                            if (sb->Color > 0 && sb->Color != 0xFFFF)
                            {
                                ushort x   = sb->X;
                                ushort y   = sb->Y;
                                int    pos = y * 8 + x;

                                if (pos >= 64)
                                {
                                    continue;
                                }
                                sbyte z = sb->Z;

                                Static staticObject = new Static(sb->Color, sb->Hue, pos)
                                {
                                    Position = new Position((ushort)(bx + x), (ushort)(by + y), z)
                                };

                                if (TileData.IsAnimated(staticObject.ItemData.Flags))
                                {
                                    staticObject.Effect = new AnimatedItemEffect(staticObject, staticObject.Graphic, staticObject.Hue, -1);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #9
0
ファイル: MapChunk.cs プロジェクト: broem/ClassicUO
        public unsafe void Load(int map)
        {
            IndexMap im = GetIndex(map);

            if (im.MapAddress != 0)
            {
                MapBlock block = Marshal.PtrToStructure <MapBlock>((IntPtr)im.MapAddress);
                int      bx    = X * 8;
                int      by    = Y * 8;

                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        int       pos    = y * 8 + x;
                        ushort    tileID = (ushort)(block.Cells[pos].TileID & 0x3FFF);
                        sbyte     z      = block.Cells[pos].Z;
                        Tile      tile   = Tiles[x][y];
                        LandTiles info   = TileData.LandData[tileID];
                        tile.Graphic     = tileID;
                        tile.Position    = new Position((ushort)(bx + x), (ushort)(by + y), z);
                        tile.AverageZ    = z;
                        tile.MinZ        = z;
                        tile.IsStretched = info.TexID == 0 && TileData.IsWet((long)info.Flags);
                        tile.AddGameObject(tile);
                        tile.Calculate();
                    }
                }

                if (im.StaticAddress != 0)
                {
                    StaticsBlock *sb = (StaticsBlock *)im.StaticAddress;

                    if (sb != null)
                    {
                        int count = (int)im.StaticCount;

                        for (int i = 0; i < count; i++, sb++)
                        {
                            if (sb->Color > 0 && sb->Color != 0xFFFF)
                            {
                                ushort x   = sb->X;
                                ushort y   = sb->Y;
                                int    pos = y * 8 + x;

                                if (pos >= 64)
                                {
                                    continue;
                                }
                                sbyte z = sb->Z;

                                Static staticObject = new Static(sb->Color, sb->Hue, pos)
                                {
                                    Position = new Position((ushort)(bx + x), (ushort)(by + y), z)
                                };

                                if (TileData.IsAnimated((long)staticObject.ItemData.Flags))
                                {
                                    staticObject.Effect = new AnimatedItemEffect(staticObject, staticObject.Graphic, staticObject.Hue, -1);
                                }
                                //Service.Get<EffectManager>().Add(GraphicEffectType.FixedXYZ, Serial.Invalid, Serial.Invalid, staticObject.Graphic, staticObject.Hue, staticObject.Position, Position.Invalid, 0, -1, false, false, false, GraphicEffectBlendMode.Normal);

                                Tiles[x][y].AddGameObject(staticObject);
                            }
                        }
                    }
                }
            }
        }
コード例 #10
0
        private unsafe void CreateMiniMapTexture(bool force = false)
        {
            if (_gumpTexture == null || _gumpTexture.IsDisposed)
            {
                return;
            }

            ushort lastX = World.Player.X;
            ushort lastY = World.Player.Y;


            if (_x != lastX || _y != lastY)
            {
                _x = lastX;
                _y = lastY;
            }
            else if (!force)
            {
                return;
            }


            int blockOffsetX = Width >> 2;
            int blockOffsetY = Height >> 2;
            int gumpCenterX  = Width >> 1;
            //int gumpCenterY = Height >> 1;

            //0xFF080808 - pixel32
            //0x8421 - pixel16
            int minBlockX = ((lastX - blockOffsetX) >> 3) - 1;
            int minBlockY = ((lastY - blockOffsetY) >> 3) - 1;
            int maxBlockX = ((lastX + blockOffsetX) >> 3) + 1;
            int maxBlockY = ((lastY + blockOffsetY) >> 3) + 1;

            if (minBlockX < 0)
            {
                minBlockX = 0;
            }

            if (minBlockY < 0)
            {
                minBlockY = 0;
            }

            int maxBlockIndex  = World.Map.BlocksCount;
            int mapBlockHeight = MapLoader.Instance.MapBlocksSize[World.MapIndex, 1];
            int index          = _useLargeMap ? 1 : 0;

            _blankGumpsPixels[index].CopyTo(_blankGumpsPixels[index + 2], 0);

            uint[] data = _blankGumpsPixels[index + 2];

            Point *table = stackalloc Point[2];

            table[0].X = 0;
            table[0].Y = 0;
            table[1].X = 0;
            table[1].Y = 1;



            for (int i = minBlockX; i <= maxBlockX; i++)
            {
                int blockIndexOffset = i * mapBlockHeight;

                for (int j = minBlockY; j <= maxBlockY; j++)
                {
                    int blockIndex = blockIndexOffset + j;

                    if (blockIndex >= maxBlockIndex)
                    {
                        break;
                    }

                    ref IndexMap indexMap = ref World.Map.GetIndex(i, j);

                    if (indexMap.MapAddress == 0)
                    {
                        break;
                    }

                    MapBlock *    mp          = (MapBlock *)indexMap.MapAddress;
                    MapCells *    cells       = (MapCells *)&mp->Cells;
                    StaticsBlock *sb          = (StaticsBlock *)indexMap.StaticAddress;
                    uint          staticCount = indexMap.StaticCount;

                    Chunk block      = World.Map.GetChunk(blockIndex);
                    int   realBlockX = i << 3;
                    int   realBlockY = j << 3;

                    for (int x = 0; x < 8; x++)
                    {
                        int px = realBlockX + x - lastX + gumpCenterX;

                        for (int y = 0; y < 8; y++)
                        {
                            ref MapCells cell   = ref cells[(y << 3) + x];
                            int          color  = cell.TileID;
                            bool         isLand = true;
                            int          z      = cell.Z;

                            for (int c = 0; c < staticCount; ++c)
                            {
                                ref StaticsBlock stblock = ref sb[c];

                                if (stblock.X == x && stblock.Y == y &&
                                    stblock.Color > 0 && stblock.Color != 0xFFFF &&
                                    GameObject.CanBeDrawn(stblock.Color))
                                {
                                    if (stblock.Z >= z)
                                    {
                                        color  = stblock.Hue > 0 ? (ushort)(stblock.Hue + 0x4000) : stblock.Color;
                                        isLand = stblock.Hue > 0;

                                        z = stblock.Z;
                                    }
                                }
                            }


                            if (block != null)
                            {
                                GameObject obj = block.Tiles[x, y];

                                while (obj?.TNext != null)
                                {
                                    obj = obj.TNext;
                                }

                                for (; obj != null; obj = obj.TPrevious)
                                {
                                    if (obj is Multi)
                                    {
                                        if (obj.Hue == 0)
                                        {
                                            color  = obj.Graphic;
                                            isLand = false;
                                        }
                                        else
                                        {
                                            color = obj.Hue + 0x4000;
                                        }

                                        break;
                                    }
                                }
                            }

                            if (!isLand)
                            {
                                color += 0x4000;
                            }

                            int tableSize = 2;

                            if (isLand && color > 0x4000)
                            {
                                color = HuesLoader.Instance.GetColor16(16384, (ushort)(color - 0x4000));  //28672 is an arbitrary position in hues.mul, is the 14 position in the range
                            }
                            else
                            {
                                color = HuesLoader.Instance.GetRadarColorData(color);
                            }

                            int py = realBlockY + y - lastY;
                            int gx = px - py;
                            int gy = px + py;

                            CreatePixels
                            (
                                data,
                                0x8000 | color,
                                gx,
                                gy,
                                Width,
                                Height,
                                table,
                                tableSize
                            );
                        }
                    }