/// Gets the index data for this tile based on current settings
 public IndexData GetIndexData( long stitchFlags, long RenderLevel, Renderable[] neighbors)
 {
     Debug.Assert (levelIndex[ (int)RenderLevel ] != null);
     IEnumerator ii = ((Axiom.Collections.Map)(levelIndex[ (int)RenderLevel ])).Find( (long)stitchFlags );
     if ( ii == null)
     {
         // Create
         IndexData indexData = GenerateTriListIndexes((long)stitchFlags, RenderLevel, neighbors);
         ((Axiom.Collections.Map)(levelIndex[ (int)RenderLevel ])).Insert((long) stitchFlags, indexData );
         return indexData;
     }
     else
     {
         ii.MoveNext();
         return (IndexData)ii.Current;
     }
 }
        protected void addBatch(long num)
        {
            numRenderables += num;
            //    mRenderables.reserve (mNumRenderables);
            //    mRenderables.resize (mNumRenderables);

            for (long i = 0; i < num; i++ )
            {
                Renderable rend = new Renderable();
                renderables.Add( rend );
                queue.Push( rend );
            }
        }
        /// Internal method for generating triangle list terrain indexes
        public IndexData GenerateTriListIndexes( long stitchFlags, long RenderLevel, Renderable[] neighbors)
        {
            long step = (1L << (int)RenderLevel);
            long north = ((stitchFlags & (long)Stitch_Direction.North) != 0 ? step : 0);
            long south = ((stitchFlags & (long)Stitch_Direction.South) != 0 ? step : 0);
            long east =  ((stitchFlags & (long)Stitch_Direction.East)  != 0 ? step : 0);
            long west =  ((stitchFlags & (long)Stitch_Direction.West)  != 0 ? step : 0);

            long new_length = ( tileSize * tileSize * 6 ) / step;

            IndexData indexData = new IndexData();
            indexData.indexBuffer =
            HardwareBufferManager.Instance.CreateIndexBuffer(IndexType.Size16, (int)new_length, BufferUsage.StaticWriteOnly);

            cache.Add( indexData );

            /** Returns the index into the height array for the given coordinates. */
            IntPtr ipIdx = indexData.indexBuffer.Lock(0,indexData.indexBuffer.Size,BufferLocking.Discard);
            numIndexes = 0;

            long pos = 0;
            long step_offset = step * tileSize;
            long height_count = north * tileSize;
            unsafe
            {
                ushort* pIdx = (ushort *)ipIdx.ToPointer();
                for (long j = north; j < tileSize - 1 - south; j += step )
                {
                    for (long i = west; i <  tileSize - 1 - east; i += step )
                    {
                        //triangles

                        pIdx[pos++] = (ushort) (i        + height_count);                 numIndexes++;
                        pIdx[pos++] = (ushort) (i        + height_count + step_offset);   numIndexes++;
                        pIdx[pos++] = (ushort) (i + step + height_count);                 numIndexes++;

                        pIdx[pos++] = (ushort) (i        + height_count + step_offset);   numIndexes++;
                        pIdx[pos++] = (ushort) (i + step + height_count + step_offset);   numIndexes++;
                        pIdx[pos++] = (ushort) (i + step + height_count);                 numIndexes++;

                    }
                    height_count += step_offset;
                }

            }

            // North stitching
            if ( north != 0 )
            {
                numIndexes += StitchEdge(Neighbor.North, RenderLevel, neighbors[(int)Neighbor.North].RenderLevel,
                    west > 0 , east > 0 , ipIdx,ref pos);
            }
            // East stitching
            if ( east != 0 )
            {
                numIndexes += StitchEdge(Neighbor.East, RenderLevel, neighbors[(int)Neighbor.East].RenderLevel,
                    north > 0, south > 0, ipIdx,ref pos);
            }
            // South stitching
            if ( south != 0 )
            {
                numIndexes += StitchEdge(Neighbor.South, RenderLevel, neighbors[(int)Neighbor.South].RenderLevel,
                    east > 0 , west > 0, ipIdx,ref pos);
            }
            // West stitching
            if ( west != 0 )
            {
                numIndexes += StitchEdge(Neighbor.West, RenderLevel, neighbors[(int)Neighbor.West].RenderLevel,
                    south > 0 , north > 0, ipIdx,ref pos);
            }

            indexData.indexBuffer.Unlock();
            indexData.indexCount = (int)numIndexes;
            indexData.indexStart = 0;

            return indexData;
        }
 /** Make a renderable free.
 */
 public void FreeRenderable( Renderable rend )
 {
     queue.Push( rend );
 }
 /** Set this renderable to be loaded
 */
 public void QueueRenderableLoading( Renderable rend, Tile.Tile tile )
 {
     renderablesLoadQueue.Push( rend );
     tilesLoadQueue.Push( tile );
 }
        public Tile()
        {
            info = new TileInfo();
            tileSceneNode = null;
            renderable = null;
            init = false;
            loaded = false;

            bounds = new AxisAlignedBox();
            boundsExt = new AxisAlignedBox();
            //worldBounds = new AxisAlignedBox();
            neighbors = new Tile[4];
        }
        public void Release()
        {
            if (init)
            {
                init = false;

                if ( loaded && renderable != null )
                {
                    renderable.Release();
                    renderable = null;
                    loaded = false;
                }
                if (neighbors[(int)Neighbor.North] != null)
                    neighbors[(int)Neighbor.North].SetNeighbor(Neighbor.South, null);
                if (neighbors[(int)Neighbor.South] != null)
                    neighbors[(int)Neighbor.South].SetNeighbor(Neighbor.North, null);
                if (neighbors[(int)Neighbor.East] != null)
                    neighbors[(int)Neighbor.East].SetNeighbor(Neighbor.West, null);
                if (neighbors[(int)Neighbor.West] != null)
                    neighbors[(int)Neighbor.West].SetNeighbor(Neighbor.East, null);
                for ( long i = 0; i < 4; i++ )
                {
                    neighbors[ i ] = null;
                }

                if ( tileSceneNode != null )
                {
                    //mTileNode->getParent()->removeChild( mTileNode->getName() );
                    //delete mTileNode;
                    //assert (mTileSceneNode->getParent());

                    // jsw - we need to call both of these to delete the scene node.  The first
                    //  one removes it from the SceneManager's list of all nodes, and the 2nd one
                    //  removes it from the tree of scene nodes.
                    tileSceneNode.Creator.DestroySceneNode(tileSceneNode.Name);
                    tileSceneNode.Parent.RemoveChild( tileSceneNode );
                    tileSceneNode = null;
                }

                TileManager.Instance.FreeTile( this );
            }
        }
        public void Notify( Vector3 pos, PagingLandscape.Camera Cam)
        {
            if ((( pos - tileSceneNode.DerivedPosition).LengthSquared <=
                            Options.Instance.Renderable_Factor))
            {

                if ( loaded == false
                    //&& Cam.getVisibility (mBoundsExt))
            //					&& Cam.GetVisibility (tileSceneNode.WorldAABB ))
                    && Cam.GetVisibility (this.worldAABB ))
                    {
                        // Request a renderable
                        renderable = RenderableManager.Instance.GetRenderable();
                        if ( renderable != null )
                        {
                            //TODO: We may remove the PosX and PosZ since it is not necessary
                            renderable.Init( info );
                            // Set the material
                            renderable.Material = Texture.TextureManager.Instance.GetMaterial( info.PageX, info.PageZ ) ;

                            if ( tileSceneNode != null)
                            {
                                tileSceneNode.Clear();
                            }
                            //Queue it for loading
                            RenderableManager.Instance.QueueRenderableLoading( renderable, this );
                            loaded = true;

                            PageManager.Instance.GetPage(info.PageX,info.PageZ).LinkTileNeighbors();
                        }
                    }

            }
            else
            {
                if ( renderable != null )
                {
                    loaded = false;
                    if ( tileSceneNode != null && renderable.IsLoaded )
                    {
                        tileSceneNode.DetachObject( renderable );
                    }
                    renderable.Release();
                    renderable = null;
                }
            }
        }
 /** Sets the appropriate neighbor for this TerrainRenderable.  Neighbors are necessary
 to know when to bridge between LODs.
 */
 public void SetNeighbor( Neighbor n, Renderable t )
 {
     neighbors[(int) n ] = t;
 }
Exemple #10
0
 /** Sets the appropriate neighbor for this TerrainRenderable.  Neighbors are necessary
  * to know when to bridge between LODs.
  */
 public void SetNeighbor(Neighbor n, Renderable t)
 {
     neighbors[(int)n] = t;
 }