Search Results

Monday, March 11, 2013

SolarLune-Game - Google Code Game Development Module Page

Hey. So, I thought it would be a good idea to make a central Google Code page for my BGE Python modules. That way, it's easy to make sure that you have the most up-to-date scripts and functions.  You can use an SVN tool like TortoiseSVN to download the latest versions and keep up to date. It's pretty slick, I think.




-Flatten-



The current newest addition is the Flatten module. The Flatten module allows you to copy the meshes of several objects over to a single one. This is done because the BGE draws a single batch much faster than it draws several. As you can observe in the picture below, 729 objects renders much, much faster when you Flatten everything together, as opposed to the right, where every object is individually drawn. Now, the test isn't completely correct, as the destination object (where the source objects are flattened to) should be destroyed if you choose not to flatten things, but it's just a quick-and-dirty example.

Now, there are some downsides to this - the flattened objects are all part of a single mesh, so they all have to share materials, and they're all "stuck together" . However, the advantage is still pretty good, I think. I made this for a little voxel / Minecraft-like test awhile back, and I revisited it just recently to add some functionality.

Now, you can both flatten, as well as remove flattened polygons.

You can also now progressively flatten objects into a single mesh through repeated Flatten() function calls. This is particularly useful as you can spawn an object, alter its vertex info (UV, position, vertex colors) and then flatten it into the destination mesh, and repeat, almost like stamping. Come to think of it, you probably could use the same mesh multiple times.




Usually, spawned objects share meshes internally, so altering vertex info would change every mesh of every similar object in the game scene. However, the flattening process can grab the vertex data before you move on to altering the next object, so the edited mesh data is still valid. You can see the result in the picture above.

Unflattening isn't that intuitive, but it is not too hard to use. Currently, it works something like this:

  • You make the destination mesh with enough faces to cover all of the source objects you plan to spawn.

  • You flatten the source objects into the destination object.

  • When you flatten the sources, the Flatten function returns a list of lists, consisting of vertex indices. Each vertex index list corresponds to the object in the same position in the source lists (at least, it SHOULD, hah).

  • You later call the Unflatten() function and pass in the destination object and the vertex list to unflatten (remove) them.

It would probably be nicer to pass in the object name for the vertices, rather than a list. If people find this useful, maybe I'll add that later.

An example for the Flatten module is available on the Google Code page.



- BGInput -



I made an input module that allows you to set up key bindings easily. For example, rather than checking logic.keyboard.events and logic.joystick for input, you can set up a new binding name, and then poll for that name. Here's a quick example.




device = CInputDevice()
  
device.Add('jump', KEYPRESSED, events.ZKEY, 'keyboard') # Add a keybinding named "jump", reacting to a key being pressed (not held down), that correlates to the Z Key, and add it to the keyboard group (unnecessary last step)
  
device.Poll('keyboard') # Run Poll() only ONCE per CInputDevice per game frame.
  
print (device.bindings['jump'])



 It's also on the GC page, though there's no example for it. The link to the GC page is at the top of this post, by the way.

Anyway, thanks a lot for reading, and have fun!

No comments:

Post a Comment