It's been a while since I've posted here. Guess I really like to abandon online places more often than I'd like, but whatever.
So, if you've read any of my previous posts, you might be aware that, for some graphical parts in my game, Brave Sir Knight, I've used polygons instead of saved images like a PNG, which got many ideas brewing in my head. Now, I'm finally giving them proper shape.
I'll be using Godot again, but this time, all the graphics will be done with Polygon2D nodes, meaning that graphics can be "hidden" as code or text files (actually, it'll be CSV for easier reading). That's not the point, the real bangers are:
* A lot less disk space is needed
* Less RAM usage overall
* Easy to create a variety of shapes that fit
* Lossless zoom in/out
Of course, applying math to god knows how many different points and lines can be taxing on a CPU, so I ran a few tests, creating a bunch of polygons with 70 points, then moving 25 points of each of them per frame. The results, on my i7-7700 were satisfactory: moving roughly 260 points per frame resulted in roughly 10% increased CPU usage, from ~11% to 19%, without any effect on delta (how long the CPU was taking to finish a cycle, which was at ~8.3ms, which translates to ~120FPS). To be sure, I exported the project for web target and made a prototype page on my itch.io - currently accessible only to me - and there, too, CPU usage remained decent without any impact in delta/FPS while the points moved across the screen.
One thing that might not be clear is this point movement, so let me explain: every 2D polygon has a number of points that are connected by lines. By moving a point, every line connecting it to other points immediately updates to show the new result, think of it like having a yarn string over some sticks, if you move only one stick, the overall shape changes. So, by being able to move each single point separately, I can define positions that I would otherwise have to draw by hand and keep as separate image files: instead of having 1 image for front facing and 1 image for 3/4, by moving the points to new positions, the same polygon can act as both directions. This also eliminates load times, as these values will likely be within memory or calculated during runtime. Setting up all the correct positions will be a lot of work, but I expect it to be worth it.
The basic functions I've made can either set the points to certain positions, or move them by a provided delta. What really annoys me in this case is how Godot does not allow direct manipulation of values, instead forcing people to create a duplicate of the polygon, changing that, then applying it back to the original one. It's essentially the following:
So, if you've read any of my previous posts, you might be aware that, for some graphical parts in my game, Brave Sir Knight, I've used polygons instead of saved images like a PNG, which got many ideas brewing in my head. Now, I'm finally giving them proper shape.
I'll be using Godot again, but this time, all the graphics will be done with Polygon2D nodes, meaning that graphics can be "hidden" as code or text files (actually, it'll be CSV for easier reading). That's not the point, the real bangers are:
* A lot less disk space is needed
* Less RAM usage overall
* Easy to create a variety of shapes that fit
* Lossless zoom in/out
Of course, applying math to god knows how many different points and lines can be taxing on a CPU, so I ran a few tests, creating a bunch of polygons with 70 points, then moving 25 points of each of them per frame. The results, on my i7-7700 were satisfactory: moving roughly 260 points per frame resulted in roughly 10% increased CPU usage, from ~11% to 19%, without any effect on delta (how long the CPU was taking to finish a cycle, which was at ~8.3ms, which translates to ~120FPS). To be sure, I exported the project for web target and made a prototype page on my itch.io - currently accessible only to me - and there, too, CPU usage remained decent without any impact in delta/FPS while the points moved across the screen.
One thing that might not be clear is this point movement, so let me explain: every 2D polygon has a number of points that are connected by lines. By moving a point, every line connecting it to other points immediately updates to show the new result, think of it like having a yarn string over some sticks, if you move only one stick, the overall shape changes. So, by being able to move each single point separately, I can define positions that I would otherwise have to draw by hand and keep as separate image files: instead of having 1 image for front facing and 1 image for 3/4, by moving the points to new positions, the same polygon can act as both directions. This also eliminates load times, as these values will likely be within memory or calculated during runtime. Setting up all the correct positions will be a lot of work, but I expect it to be worth it.
The basic functions I've made can either set the points to certain positions, or move them by a provided delta. What really annoys me in this case is how Godot does not allow direct manipulation of values, instead forcing people to create a duplicate of the polygon, changing that, then applying it back to the original one. It's essentially the following:
var dup = original.polygon.duplicate()
dup.set(0, Vector2(10,20))
original.polygon = dup
Very annoying, but they claim that this kind of PackagedArray is more performant than normal Arrays. I guess I'll find out during this development.dup.set(0, Vector2(10,20))
original.polygon = dup