Pixel-by-pixel destructible terrain?[Yup, why not]

Get help using Construct 2

Post » Mon Dec 23, 2013 1:18 am

Hey guys!
Just curious if someone's tried to do it without using 3rd party pug-ins..
Here's what I've tried to do:
Example capx
Bresenham's algorithm inside a while loop & decreasing radius. Yikes
Well, it works, but waay too buggy and dirty, as expected:)
Try setting global Radius to 32 and radius decrement(at the end of first "while" loop)
to something like 0.05 and you'll see that it's way too CPU-abusive..
Yeah, I know it's far from optimal:(
I would really appreciate if someone point me in a right direction on how to optimise this algorithm
Or, even better, show me a better filled-circle drawing method :P
Not that I need it badly for my projects, just curious

//upd I guess I have an idea how to modify Bres's algorithm, but I'm too weak at programming so it may take a while

Thanks in advance!
George. JJList2013-12-23 05:31:40
B
18
S
5
G
1
Posts: 74
Reputation: 2,672

Post » Mon Dec 23, 2013 1:51 am

Yay, think I'm getting closer :D Example 2
Now it's clean, but still seems a bit slow :( Any ideas how to make it run smoother?:P

//Upd. Not sure if it is any faster, but Example 3
Allright, I'm running out of ideas

//Upd. Looks simple, but still slow : Example 4 and Example 5JJList2013-12-23 03:38:23
B
18
S
5
G
1
Posts: 74
Reputation: 2,672

Post » Mon Dec 23, 2013 3:51 am

I'm impressed that the tilemap renders so fast with 1x1 tiles. This has potential, and I do enjoy optimizing.

I took your forth capx and added a text object to store the average time it takes the function to clear a circle.
https://www.dropbox.com/s/mwjxctu4vhx7w ... .capx?dl=0

So now I have something to compare against. For an initial test I went for circle clearing with as few events as possible. The algorithm I used is just the graph of a circle. Bresenham's algorithm probably will be faster but I haven't fiddled with your events with the same stuff I did with mine.
https://www.dropbox.com/s/t8mizv3e6hugt ... .capx?dl=0
Compared to the two "simple.capx" is about 3 times faster. Here are some things I did and my reasoning. Note that I wasn't profiling as I went along so I'm unsure of the boost each gave, if any.
* I changed the function so x,y and radius are passed as parameters. This to eliminate the need to re-pick the bullet in the function. Actually this probably was a negligible change. It was more of a style preference.
* I used "erase tile range" instead of "erase tile". This likely was the biggest boost since it eliminated a loop level since we can just erase spans of tiles at a time.
* I didn't use the "Tilemap.PositionToTile" functions since with 1x1 tiles pixel position is the same as tile position. A little flexibility is lost doing this since the tilemap object has to be at position 0,0.

That's about it. Next I'll have tinker with your events to see avoiding a sqrt() with some more events perform better.
Last edited by R0J0hound on Wed Mar 22, 2017 6:01 pm, edited 1 time in total.
B
94
S
33
G
113
Posts: 5,354
Reputation: 73,269

Post » Mon Dec 23, 2013 5:25 am

Now that's what I call an optimisation!
Thank you so much @R0J0hound ! I understand the changes you've made, and I totally agree. I've learned alot from them, thanks again

Hehe, I guess that's a nice way to generate new ideas: first, a curious newbie (Me) shows a potential of something to an experienced person(Master R0J0).
Than this skilled person finds the best way to make it work and releases a nice new solution, usable for all other community people:P

R0J0hound, I admire your skills:) Would be nice to see if avoiding sqrt() can make it run even faster! (Tho I think it's already usable as it is :P )

P.S. Would be nice if someone could test it on mobile platforms, btw ;)JJList2013-12-23 05:30:06
B
18
S
5
G
1
Posts: 74
Reputation: 2,672

Post » Mon Dec 23, 2013 6:27 am

@JJList : I don't have time to see the work you've done, but I really like the idea of pixel by pixel destructible terrain, I think it opens really a lot of possibilities, Worms armageddon for instance uses this kind of logic I think (except that you could import a picture in Worms armageddon to define the level also, but I don't think it'll be possible to do without serious work in C2, it was also limited in size and color), maybe some algorythms to generate from a mathematical graphic equation? I am thinking too much sometimes.

Anyway, good concept you got thereAphrodite2013-12-23 06:29:20
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Mon Dec 23, 2013 10:08 am

@R0J0hound dat math! Simple yet elegant. This is actually working extremely fast and solid! Sometime I notice bullets going missing when I fire in salvo's but I couldn't test this further. This is so awesome!

EDIT: I think it's possible to add "diffX and diffY" variables if you don't want to place tilemap at "0,0". Just set them manually at startup and include in your math, but I'm just unsure how to.Windwalker2013-12-23 10:11:46
B
18
S
4
G
1
Posts: 332
Reputation: 3,149

Post » Mon Dec 23, 2013 12:25 pm

Wow!

I didn't think per pixel stuff was doable, but that may be even faster than Construct Classic could have done.

Great job, or should I say tanks guys?
Image ImageImage
B
170
S
50
G
179
Posts: 8,378
Reputation: 113,425

Post » Mon Dec 23, 2013 2:29 pm

Ditto wow, the old artillery games didn't erase that fast.

Firing rapidly I got my processor usage to spike at 23%, (averaged 9%) but could never get the framerate to drop from 60.
B
239
S
62
G
33
Posts: 903
Reputation: 40,562

Post » Mon Dec 23, 2013 3:40 pm

@JJList

Tested on Ipad 3, and there is a slowdown on fps for the function, more like a choke really.

It goes from 45, down to 40, accumulative for multiple shots, so that's not advisable.
Image ImageImage
B
170
S
50
G
179
Posts: 8,378
Reputation: 113,425

Post » Tue Dec 24, 2013 2:31 pm

@newt wow, 40-45 fps? And that's while rendering a ton of 1x1 pix tiles.. Ain't that impressive? :D
Sure it still has those little "chokes" when erasing tiles, even on desktop:(
Note sure if we can avoid it.. but I think it's not that bad and it fits worms-like games pretty good:)

Another problem I see is to "draw" the tiles. Kinda hard to fill our layout with 1pix tiles manually:(
Any thoughts on how to solve this one?
One way, i guess is to use tilemap as a collision mask, leave it empty,
build our level scenery with regular sprites/tiledBGR and than generate our tilemap on those sprites.
Here's an example. Mask generation
Works fine for rectangles.. Not sure how to do it for other shapes:(
Ideas?:)
B
18
S
5
G
1
Posts: 74
Reputation: 2,672

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests