Jump to content
  • Advertisement
Sign in to follow this  
Stormtrooper

[SlimDX] Tilemap KILLED performance.

This topic is 3683 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was able to get my program to draw an image, but as soon as I get it to render an entire screen full of 32x32 tiles, the performance and responsiveness of the program is horrible.
        /// <summary>
        /// Clears the buffers and begins the scene.
        /// </summary>
        public void BeginScene()
        {
            _device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            _device.BeginScene();
            _sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.DoNotSaveState);
        }


        /// <summary>
        /// Ends the scene then flips the buffers.
        /// </summary>
        public void EndScene()
        {
            _sprite.End();
            _device.EndScene();
            _device.Present();
        }

        public void drawSprite(Texture texture, Rectangle srcRect, Point position, Color4 color)
        {
            // For some weird reason, I have to offset everything by 16 pixels go get 
            // them to appear fully on screen.
            _sprite.Draw(texture, srcRect, new Vector3(srcRect.Width / 2, srcRect.Height / 2, 0), 
                new Vector3(position.X + 16, position.Y + 16, 0), color);
        }

Game loop, called on Application_Idle
        public void GameLoop()
        {
            if (_running)
            {
                _renderer.BeginScene();
                for (int y = 0; y < 600; y++)
                {
                    for (int x = 0; x < 800; x++)
                    {
                        _renderer.drawSprite(_testSprite, new Rectangle(32, 0, 32, 32), new Point(x*32, y*32), Color.White);
                    }
                }
                _renderer.EndScene();
            }
        }

Share this post


Link to post
Share on other sites
Advertisement
I'm not familiar with SlimDX but it appears that you're rendering several 100000 sprites offscreen.

In your loop, by the time y=600 and x=800, Point(x*32, y*32) = (25600,19200).

EDIT: if your screen is 800x600, try

for(y=0; y<600/32; y++) { for(x=0; x<800/32; x++) ...


EDIT2: or, as gimbal suggested (simultaneous posts)

for(y=0; y<600; y += 32) { for(x=0; x<800; x += 32) ...
... Point(x,y); // not Point(x*32,y*32)


[Edited by - Buckeye on July 15, 2008 12:29:58 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!