Jump to content


Photo

Terrain Engine V2.1


  • Please log in to reply
6 replies to this topic

#1 xDanielx

xDanielx

    GMC Member

  • GMC Member
  • 1001 posts
  • Version:Unknown

Posted 13 January 2009 - 01:35 AM

>> Download v2.1 <<
Or v1 (less efficient, but easier to use) (see below for .gm6)

This is a raster-based terrain engine which supports both construction and destruction in real time. In the example, the left mouse button is used to destroy a region of terrain while the right mouse button is used to add to it.

Internally, the engine works as follows. The terrain object (obj_terrain) maintains a surface as well as a sprite to represent the terrain. To add to the terrain, an instance draws onto the surface and informs the terrain object that an update is required for the sprite. To subtract from the terrain, an instance draws onto the surface using bm_subtract and likewise informs the terrain object that an update is required. Any drawing functions can be used for these purposes, so arbitrary shapes and/or images can be used for construction and destruction.

When the terrain is being modified every step, the computational cost is substantial but very stable. No matter how extensive the modifications, the most costly operation, (sprite_create_from_surface) is called no more than once. The cost of this function depends on the size of the terrain, but it typically takes around 30 ms, giving an FPS of about 30. But remember, this is only when modifications are being made every step; if they are made periodically, the FPS will drop only for an instant and quickly climb back up.

UPDATE: The latest version splits up the terrain into small pieces, making it much more efficient. Unless you have construction/destruction going on in many different parts of the map at the same time, the computational cost is pretty negligible.

A nice feature of the engine is that it is inherently compatible with most platform engines (or other motion engines). From the perspective of other objects, obj_terrain is just a solid object with a sprite; you don't need to perform any special collision checking to interact with it.

Edited by xDanielx, 15 January 2009 - 12:03 AM.

  • 0

#2 garrlker

garrlker

    GMC Member

  • GMC Member
  • 343 posts

Posted 13 January 2009 - 02:11 AM

Oh gmk. Hold on I'l post review when I convert. And I'l post converted engine.
EDIT:Ok I like it but for some reason when it started the character went right through the surface. It might be the way how I converted it. Anyway its good incase I need a surface example. 8/10 10/10 if you get the falling through glitch fixed :(
and the GM6
Posted Image

Edited by garrlker, 13 January 2009 - 02:24 AM.

  • 0

#3 xDanielx

xDanielx

    GMC Member

  • GMC Member
  • 1001 posts
  • Version:Unknown

Posted 13 January 2009 - 03:57 AM

Thanks for converting it for me. As for the player falling through, just make obj_terrain solid and it should stop.

I put together a more efficient version which splits the terrain up into pieces so that the sprites generated during runtime are much smaller. The efficiency boost is very substantial -- it can run at several hundred FPS with constant construction/destruction -- but it's also harder to customize as the techniques used are more complex. I'll definitely keep the old one up for anyone who wants a small, simple terrain and isn't too concerned with efficiency.
  • 0

#4 coolist

coolist

    The Coolist

  • New Member
  • 913 posts

Posted 14 January 2009 - 09:19 PM

Smart way of doing that! I guess you could make it a little easyer by working with objects instead of sprites to delete the derain but it is still very nice!
  • 0

#5 xDanielx

xDanielx

    GMC Member

  • GMC Member
  • 1001 posts
  • Version:Unknown

Posted 15 January 2009 - 01:40 AM

Glad you like it. I agree that it could be easier to use... I'm planning on adding some scripts like ter_subtract_sprite and ter_subtract_circle to simplify the processes.

Slight update -- I added some code to keep track of the bottom-left pixel when possible, so you won't see a grid pattern of 1px*1px holes any more.
  • 0

#6 Keano

Keano

    GMC Member

  • GMC Member
  • 18 posts
  • Version:GM:Studio

Posted 18 April 2012 - 07:49 PM

This Example sucks im sorry but please fix the whole GMK
  • 0

#7 Bytewin

Bytewin

    GMC Member

  • New Member
  • 92 posts
  • Version:GM8

Posted 18 April 2012 - 10:14 PM

This Example sucks im sorry but please fix the whole GMK


Everyone says it is amazing, and you say it sucks...
Now give me a reason why we would listen to you...
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users