So I just got finished implementing components to replace my inheritance based entity system. Getting used to factories and pooling has been a bit of a battle, but I feel as though I’m ready to start actual game production. My engine has fake lighting, which adds another draw call, and it slows things down a bit. Typically you can get away with 1000-1500 triangles in a Papervision3D scene without worrying about the CPU melting, but I’ve limited my game scenes to around 500 triangles, which is 250 quads or 40-ish cubes.
Luckily culling can smooth out those numbers a bit and I can get away with more. The entire engine will have a hard focus on culling triangles from the viewport, and culling objects in general. By removing physics bodies and making models invisible at a distance, I can have many objects in a level. It’s all about effective culling and sparse distribution of objects. Also, I can focus on designing good looking levels with many static objects, as they aren’t as resource intensive as dynamic moving objects.
Speaking of CPU usage and lighting, here’s an image I just took showing 100 GameObjects with several components attached. The draw function is called twice, once with a normal blendmode, and again with the multiply blendmode (lighting). Surprisingly the CPU usage isn’t too high, but then again, I’m on a 2.4GHz quadcore. I want my game to be playable on a netbook, even if it does drain the battery a bit. I haven’t decided if I want to go to 30FPS. It would cut my CPU usage down in half, but I feel like 30FPS is choppy! Ā š
Anyway, now that I have fairly quick rendering, and a component based architecture, I feel that it’s time for me to get some interactive-ness back into my game. This is probably the 6th iteration of my engine. I have rebuilt it so many times that it isn’t the same thing anymore. It’s something smarter…faster…awesome..er!
EDIT: As you can see from the image above, I’ve stolen my naming conventions from FlashPunk. Before I had a much crazier folder/class structure.
I felt as though this set up was the best, but then I saw the simplicity in FlashPunk.
maybe i’m wrong about this, but is it worth learning papervision or away3d when molehill is coming out?
Papervision won’t be updated to use molehill because it’s pretty much an abandoned project, but Away3D already has a molehill build you can play around with.
Molehill is just a very low level API, and you still need a library like Away3D, Alternativa, or something of your own to do things like importing meshes, set up textures/UVs, and all that other fun stuff.
So I just got finished implementing components to replace my inheritance based entity system. Getting used to factories and pooling has been a bit of a battle, but I feel as though Iām ready to start actual game production.
im interested, but it seems i cant find the perfect reference of what you are saying.. inheritance system vs the factories and pooling. is there an article that explains about the factory system?
You might take a look at PushButtonEngine or another components library. Essentially you rid yourself of inheritance (except in situations where it is obvious to use it), and use components to build your game objects. The components are written to be ‘plug and play’, as if you’re hooking up new USB devices, or ‘code chunks’.
There are several different ways you can do components. Some people like to get rid of the GameObject class entirely, and use a component manager with an ID set up. That was is the quickest, with a lower amount of function calls to update components.
Personally I prefer having a GameObject class, as a component container. I think many implementations would do it this way. To break it down further, you’ll have a GameObject class, which simply holds a list of components, a BaseComponent, which you can extend into the new components, and a TickedComponent – or UpdateableComponent, or a BehaviourComponent, whatever you wish to call it, that is updated either each frame, or on a timer/regular basis.
So maybe you’d have a SpriteComponent, and a RigidBodyComponent, and a FlyingBombBehaviourComponent to create a physics enabled bomb that flys around using user input. But I’m rambling, here’s some links to the FGL discussions where I got into components.
EDIT: Oh, and the best video I’ve ever seen describing components!
Components in 5 minutes or less
Component based Entities with Properties
http://www.flashgamelicense.com/view_thread.php?search=1&offset=0&thread_id=20587
Organizing Classes and Objects in a Game
http://www.flashgamelicense.com/view_thread.php?search=1&offset=0&thread_id=26962
Good luck, and remember not to get too stuck on design patterns. You can end up dumping a lot of time into them, and the players don’t care how the game was coded… Oh, and make sure your game could actually use components! In many cases, inheritance is fine.
wow, thank you very much for the reply, you even hook up a video of it..
perhaps since my background is art and not programming, i still have a hard time in understanding the component implementation, from the video. I’m now going to read the stuff in the fgl thread. THank you again š