Example #1
0
    public void Draw(IRenderContext context, IRenderer renderer)
    {
        //get all the visible blocks
        if (p_UpdateVisibleBlocks)
        {
            lock (p_Mutex) {
                p_VisibleBlocks       = getVisibleBlocks(context);
                p_UpdateVisibleBlocks = false;
            }
        }

        List <VisibleBlock> visible = VisibleBlocks;

        if (visible.Count == 0)
        {
            return;
        }

        //grab the LOS matrix so we can quickly deturmine if a block is
        //within LOS.
        bool *los = (bool *)0;
        Fog   fog = p_Game.CurrentPlayer.Fog;

        fog.Lock();
        if (p_Game.EnableLOS)
        {
            los = fog.GetLOSMatrix();
        }

        //fire the event for the beginning of a frame render
        if (BeginRenderFrame != null)
        {
            BeginRenderFrame(
                this,
                context,
                renderer);
        }

        Camera camera    = p_Game.Camera;
        int    blockSize = camera.BlockSize;

        #region initial render pass
        Point cursorPos = p_Game.PointToClient(Cursor.Position);
        foreach (VisibleBlock block in visible)
        {
            drawBlock(
                context,
                renderer,
                block,
                los);
        }
        #endregion

        #region secondary pass

        /*
         *  for anything that requires us to render over other blocks.
         */
        foreach (VisibleBlock block in visible)
        {
            /*draw coastline*/
            if ((*block.Block).TypeID != Globals.TERRAIN_WATER)
            {
                drawCoastBlock(
                    context,
                    renderer,
                    block);
            }

            /*fire block render*/
            if (BlockRender != null)
            {
                BlockRender(
                    this,
                    context,
                    renderer,
                    block);
            }
        }
        #endregion

        //fire event after frame finished
        if (EndRenderFrame != null)
        {
            EndRenderFrame(
                this,
                context,
                renderer);
        }

        fog.Unlock();
    }