Sign in to follow this  
RealmRPGer

Tile Editor: What to use as the "map"? (Bitmap, openGL)

Recommended Posts

I started to make a level editor for a college game project last year, and I used openGL for it, which worked out relatively well, except for the fact that it doesn't really merge well with windows forms applications. So, this time around I decided to try using a bitmap. But I found out they're a LOT slower to use than just rendering an openGL scene, especially when you have a large level. So what do you people prefer? btw, I moved to C# for this new level editor (as opposed to managed c++).

Share this post


Link to post
Share on other sites
GDI bitmaps are perfectly fast enough for 2D level editors. I'm currently working on an editor that uses hi-res scans as a background to allow me to create the level data. These tiles are 1200x800 true colour images and it requires dynamic creation of HBITMAPs (there's limited GDI memory!) and it runs fine.

Skizz

Share this post


Link to post
Share on other sites
Well...The levels are potentially a LOT larger than that (10+ times larger), and are filled with 16x16 tiles. This means that I have to copy and paste hundreds of thousands of 16x16 tiles in a single loop. Of course, that large of a bitmap will cause a slowdown just by existing, so the solution is to create a single bitmap the size of the screen. But this still means somewhere around 3000 copies every time you scroll the map... Which with my current implementation takes about a second to do. I could possibly speed it up if I tried locking the bitmap and such...Though maybe I couldn't.

Share this post


Link to post
Share on other sites
The trick is not to draw all the tiles every time. Create a back buffer slightly larger than the view window and draw the tiles into that. Use dirty rectangles to update only those bits that change. On a WM_PAINT (or c# equivalent) just copy back buffer to front buffer. Use a virtual window onto the backbuffer so that when the image moves, move the virtual window and fill in the tiles being brought into view. This virtual window wraps vertically and horizontally so you'll need up to four blits from the back buffer to the screen. If you make the size of the backbuffer larger than the front buffer, you can amortise the cost of drawing the tiles over several "frames", possibly in a background thread.

Skizz

Share this post


Link to post
Share on other sites
Quote:
Original post by RealmRPGer
Well...The levels are potentially a LOT larger than that (10+ times larger), and are filled with 16x16 tiles. This means that I have to copy and paste hundreds of thousands of 16x16 tiles in a single loop. Of course, that large of a bitmap will cause a slowdown just by existing, so the solution is to create a single bitmap the size of the screen. But this still means somewhere around 3000 copies every time you scroll the map... Which with my current implementation takes about a second to do. I could possibly speed it up if I tried locking the bitmap and such...Though maybe I couldn't.


you should only draw visible tiles, and have only screen-size bitmap.
drawing 3000 16x16 images shouldnt take a second. The word "copy" is suspicious, are you coping the tile data into a new structure every time? just new-copy-delete 3000 times will take too long, you must not new-delete every frame and preferbly not copy the data around. The tile data should be in one place and only drawn to screen (or backbuffer) every frame.

how are you drawing your tiles? you should have one big bitmap which will hold all the tiles and then DrawTile will draw only the part of the image that is the tile (with GDI draw image).

Share this post


Link to post
Share on other sites
Post your copy loop. The part where you are actually copying the tiles to bitmaps. It shouldnt take a second to draw.

That said, if you are using pixel level GDI stuff, its horrifically slow.

Share this post


Link to post
Share on other sites

byte q = (byte)j;

int y = (int)(q * 16) / chipset.Width;
int x = (int)(q % (chipset.Width / 16));

g.DrawImage(chipset, new Rectangle(row * 16, col * 16, 16, 16),
new Rectangle(x * 16, y * 16, 16, 16), GraphicsUnit.Pixel);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this