zomgistania

Main page | About | Articles | Previous Posts | Archives

Sunday, May 07, 2006

More engineering

I've been working on a tile map editor today.

I bound my engine into a Panel object residing inside another form... a bit hacky at the moment, as the engine itself is bound into another form. When the editor starts, you get a "ghost form" into the background which is the engine's own form :)

The map editor itself is looking quite good. It loads textures from a file, saves maps into a XML format... changing tile textures is done with clicking the tile with the mouse... I like it! I'm quite surprised I even managed to get it working that well!


I had a huge problem with getting the mouse click detection working... the tile positions would just get offset so much that you'd have to click in a totally different location than the tile itself.

I found out that by setting device.Transform.World = Matrix.Identity after rendering a scene fixes it. It was that simple, and I tried all kinds of weird stuff... bleh.

I also had a small problem with changin the cursors coordinates from the screen coords to the applications coordinates... but after a bit of looking, there was a function on the Control class which does it for me. PointToClient(Point p)



And continuing on my earlier attempts of optimizing the rendering process...

Every tile in a tilemap has a vertexbuffer, containing the vertices for it. Someone suggested that I should use a static vertexbuffer... then every tile would use the same buffer, therefore saving resources.
Okay, so I do that...

FPS with a non-static vertexbuffer = ~260
FPS with a static vertexbuffer = ~360

Nice I'd say.


There's the problem of different sized tiles though... If I were to have different sized tiles (they're all of the same size at the moment), the static buffer wouldn't work...

So I added a static Size-struct, containing the size of the tile in the vertexbuffer. Every tile also has their very own size struct, which is then compared to the static one to see if the vertices in the static buffer are correct.
If the size differs, the Plane calls it's own Reset() method which initializes the static buffer with the correct vertices.



Onwards, to where no man has gone before!

0 Comments:

Post a Comment

<< Home