Ejemplo n.º 1
0
        public void EnsureMapFullyLoaded()
        {
            int chunksize = api.World.BlockAccessor.ChunkSize;

            nowVisible.Clear();
            nowHidden.Clear();

            Cuboidi chunkviewBounds = CurrentBlockViewBounds.ToCuboidi();

            chunkviewBounds.Div(chunksize);

            BlockPos cur = new BlockPos().Set(chunkviewBounds.X1, 0, chunkviewBounds.Z1);

            bool beforeBoundsEmpty = chunkViewBoundsBefore.SizeX == 0 && chunkViewBoundsBefore.SizeZ == 0;

            while (cur.X <= chunkviewBounds.X2)
            {
                cur.Z = chunkviewBounds.Z1;

                while (cur.Z <= chunkviewBounds.Z2)
                {
                    if (beforeBoundsEmpty || !chunkViewBoundsBefore.ContainsOrTouches(cur))
                    {
                        nowVisible.Add(new Vec2i(cur.X, cur.Z));
                    }
                    cur.Z++;
                }

                cur.X++;
            }


            cur.Set(chunkViewBoundsBefore.X1, 0, chunkViewBoundsBefore.Z1);

            while (cur.X <= chunkViewBoundsBefore.X2)
            {
                cur.Z = chunkViewBoundsBefore.Z1;

                while (cur.Z <= chunkViewBoundsBefore.Z2)
                {
                    if (!chunkviewBounds.ContainsOrTouches(cur))
                    {
                        nowHidden.Add(new Vec2i(cur.X, cur.Z));
                    }

                    cur.Z++;
                }

                cur.X++;
            }


            chunkViewBoundsBefore = chunkviewBounds.Clone();

            if (nowHidden.Count > 0 || nowVisible.Count > 0)
            {
                viewChanged(nowVisible, nowHidden);
            }
        }
Ejemplo n.º 2
0
        public bool Contains(BlockPos pos)
        {
            if (!Location.ContainsOrTouches(pos))
            {
                return(false);
            }

            int sizez = Location.Z2 - Location.Z1 + 1;
            int sizex = Location.X2 - Location.X1 + 1;

            int dx = pos.X - Location.X1;
            int dy = pos.Y - Location.Y1;
            int dz = pos.Z - Location.Z1;

            int index = (dy * sizez + dz) * sizex + dx;

            return((PosInRoom[index / 8] & (1 << (index % 8))) > 0);
        }
Ejemplo n.º 3
0
        public void EnsureMapFullyLoaded()
        {
            int chunksize = api.World.BlockAccessor.ChunkSize;

            nowVisible.Clear();
            nowHidden.Clear();

            Cuboidi worldBounds = CurrentViewBounds.ToCuboidi();

            worldBounds.Div(chunksize);
            //worldBounds.GrowBy(1);

            BlockPos cur = new BlockPos().Set(worldBounds.X1, 0, worldBounds.Z1);

            //     StringBuilder debug = new StringBuilder();

            while (cur.X <= worldBounds.X2)
            {
                cur.Z = worldBounds.Z1;

                while (cur.Z <= worldBounds.Z2)
                {
                    if (!worldBoundsBefore.ContainsOrTouches(cur))
                    {
                        nowVisible.Add(new Vec2i(cur.X, cur.Z));
                        //       debug.Append(string.Format("{0}/{1}, ", cur.X, cur.Z));
                    }

                    cur.Z++;
                }

                cur.X++;
            }

            //        if (nowVisible.Count > 0) Console.WriteLine("{0} chunks now visible: {1}", nowVisible.Count, debug.ToString());


            cur.Set(worldBoundsBefore.X1, 0, worldBoundsBefore.Z1);

            while (cur.X <= worldBoundsBefore.X2)
            {
                cur.Z = worldBoundsBefore.Z1;

                while (cur.Z <= worldBoundsBefore.Z2)
                {
                    if (!worldBounds.ContainsOrTouches(cur))
                    {
                        nowHidden.Add(new Vec2i(cur.X, cur.Z));
                    }

                    cur.Z++;
                }

                cur.X++;
            }


            worldBoundsBefore = worldBounds.Clone();

            viewChanged(nowVisible, nowHidden);
        }