zomgistania

Main page | About | Articles | Previous Posts | Archives

Wednesday, May 17, 2006

A static engine

Earlier today.. or actually yesterday.. I was working on my game project again. It's going to be a small strategy game, kind of like Advance Wars. So anyways, I'm in the phase where I'm figuring out things like units and structures... how they will be done etc.

I have a base class for game objects, aptly named "GameObject". For now, there's also a GameObjectType enum, which can be two different things: either "Unit" or "Structure". I have my unit code in quite good order at the moment. The game loads unit data from an XML file, which defines the unit's name, texture, movement, weaponry and armor. The data is then saved into a container class, from where you can get a certain unit's details with the unit's name, eg. "Tank" or "Infantry" or whatever.. the class returns a struct, which has a method for generating a Unit-object from the data. The Unit object is an actual renderable class, which contains all the logic and related. I've used some units in my tests, and they can be moved around the map, when you select one, you'll get a highlight of the area where it can move to and so on.

Now, I was making a similar class for structures... Structures in my game would be something like... factories, where you could build tanks, airbases for building jets and helis and so on..
So obviously, a structure must be able to create a whole new unit into the world.. if it wants to, not every structure will do that. While implementing that, I ran into several problems. Firstly, the object manager, which is used to handle the units in the game.. eg. when the game is in "select unit" state, mouse clicks trigger a check in the object manager which then checks if you clicked on a unit or not and returns the unit in question if you did and so on... the problem with this was that the structures needed a reference to this.. well, no problem.. I'll just pass it to the structure-class constructor and save it. Okay, that's solved.

Next.
The actual game engine's device for rendering stuff. It would need that too! Guh.. I got tired of having to pass stuff not really even related to the object, so I thought that I'll try to see if I can modify the engine so that it's accessible from everywhere in the code...

so I made it a static class

I had tried to do this earlier in another project which I scrapped later due to loss of intrest and time... and failed miserably. The engine would always get stuck into the main loop, never even rendering anything. I had no idea what was the problem back then.

Now that I had succesfully already got my engine drawing into a windows forms control, a Panel to be specific, I thought that maybe I could get it working this time. Well, I did.

I tried the static engine with my map editor first, because it was simply easier to change than the game itself. As I have posted earlier on, the "old" engine is built inside a form... and the game is built inside that very same form too and so on... It was a bit hasty I guess, but now I have the engine as a separate class. (guess what it's called... that's right, "Engine")

There's just one problem with the editor now.. the other controls aren't drawn properly. They are drawn, but they kind of disappear and aren't visible at all times and other stuff like that. I think it's probably the render loop I'm using (http://blogs.msdn.com/rickhos/archive/2005/03/30/403952.aspx) since it's so crazily optimized for rendering with DirectX.

If someone knows about fixing that, let me know.



Another fun thing I stumbled upon: SizeF.Equals(something) is stupondously more expensive to call than comparing the Width and Height properties... I had NO idea. Thank you CLR Profiler for .NET Framework 2.0.

That's about it. For now. Back to hacking the engine and optimizing things. And I want to be able to sleep normally again goddamnit.

0 Comments:

Post a Comment

<< Home