forthevin
|
|
Posted on: October 06, 2012, 10:32:31 am |
|
|
Joined: Jun 2012
Posts: 167
|
Currently, the structure for sprites does not contain information for which kind of shape is wanted for a given sprite, such as bounding box, precise, ellipse, diamond or polygon mesh.
I propose a simple system, where a single integer field, for example "collisionshape", is used as an enum, and where each value indicates a given desired shape, for example:
0: bounding box
1: precise
2: ellipse
3: diamond
4: polygon mesh
Different collision systems can interpret the wanted shape differently. The BBox collision system can for example always use bounding boxes independent of the wanted shape, and a polygon collision system could model bounding boxes, ellipses and diamonds as polygons internally and ignore the precise shape. I think this is fine, because a collision system cannot handle a shape it does not support anyway, and it is very easy to change between collision systems. Basically, game developers should pick shapes that fit the collision system they use for a given game.
|
|
|
Logged
|
|
|
|
Josh @ Dreamland
|
|
Reply #1 Posted on: October 06, 2012, 12:04:16 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
In principle, I'm fine with that. My concern is keeping the IDs straight. As such, I think it best to define the above as enum constants in collisions_mandatory.h. enum collision_type { ct_bbox, ct_precise, ct_circle, ct_ellipse, ct_diamond, ct_polygon }
This way, if a collision system offers some other, more obscure shape, it can be added without confusing other systems. We'll also need to define [snip=CPP]void *get_collision_mask(sprite* spr, collision_type ct)[/snip] to fetch a collision mask from the system, and [snip=CPP]void *free_collision_mask(void* mask)[/snip] to set the colldata values in spritestruct.h.
|
|
« Last Edit: October 06, 2012, 12:11:09 pm by Josh @ Dreamland »
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Josh @ Dreamland
|
|
Reply #3 Posted on: October 07, 2012, 07:40:18 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Since it returns void*, [snip]get_collision_mask[/snip] would only be for one subimage (the actual array is void**).
The other function, [snip]free_collision_mask[/snip], would only be for use on game termination for the purposes of cleaning up. It should actually return void, not void*. It would just cast the (void*) to the appropriate collision-system-specific structure and delete it. For example,
void free_collision_mask(void* mask) { delete (polygon_mesh*)mask; }
Note that it might not necessarily be a single class type, but the point is that the collision_data is a black box that only the selected collision system need understand. So it must handle allocation and freeing in addition to the actual checking.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
forthevin
|
|
Reply #4 Posted on: October 09, 2012, 02:08:57 pm |
|
|
Joined: Jun 2012
Posts: 167
|
I think I understand the functions now. [snip]void *get_collision_mask(sprite* spr, collision_type ct)[/snip] seems like it lacks a way to pass the collision system the input data for a subimage, since the sprite struct does not contain image data.
That brings up another issue, namely what to do if the collision type requires different input data than image data. For the majority of the collision types, image data works, but for collision types like polygon, the input data should ought to be vertex data rather than image data.
The current input data for [snip]collisionsystem_sprite_data_create[/snip] is of the form [snip]char*[/snip]. That works for image data, and I believe it could also work for vertex data as well as other formats. For instance, for image data, [snip]char*[/snip] can be interpreted as it is currently, namely as an array of pixel-values, where each quadruple of bytes constitutes an RGBA-value, and where the size of the array can be calculated from the sprite's width and height. For vertex data, the first four bytes could indicate the number of vertices and therefore also the size of the array, and each following 2*4 bytes could indicate a vertex with (x, y) coordinates, each coordinate 32-bit.
The functions would then look like this:
void *get_collision_mask(sprite* spr, collision_type ct, char* input_data) void free_collision_mask(void* mask)
|
|
|
Logged
|
|
|
|
IsmAvatar
|
|
Reply #5 Posted on: October 11, 2012, 03:43:10 pm |
|
|
LateralGM Developer
Location: Pennsylvania/USA Joined: Apr 2008
Posts: 877
|
the sprite struct does not contain image data. Depends which sprite struct we're talking about. backend/resources/sprite.h:36: SubImage *subImages; backend/sub/SubImage.h:17: Image image; backend/util/Image.h:16: char *data; //zlib compressed RGBA
|
|
|
Logged
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #7 Posted on: October 12, 2012, 06:01:36 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
Quite right. We'll need to pass that as a second parameter, then; your correction is accepted. Though I might switch the last two parameters because I'm anal-retentive and I like the types to be of descending size.
The system needs refactored, anyway, I believe; we currently do not query the collision system for any kind of sprite data (which I believe is okay for now because, as I recall, the bbox_ values only change when the sprite_index changes, not the image_index).
Moreover, the sprite editor doesn't support editing anything on a per-subimage basis, meaning polygon masks created by the user cannot currently be animated. And to top it all off, the mask system is very poorly integrated. So, some more planning is required at this phase.
That said, anything else you want to add to that function, speak now.
I might also point out that ENIGMA has had pixel-perfect collisions in the past, so it's not that difficult; I just don't want another clusterfuck.
|
|
« Last Edit: October 12, 2012, 06:04:21 pm by Josh @ Dreamland »
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
|
Josh @ Dreamland
|
|
Reply #10 Posted on: October 20, 2012, 04:58:36 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
I'll happily pull the patch so long as it doesn't break any existing functions.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
forthevin
|
|
Reply #11 Posted on: October 21, 2012, 01:30:23 pm |
|
|
Joined: Jun 2012
Posts: 167
|
I have just finished the patch, and it can be seen here: https://github.com/forthevin/enigma-dev/commit/de35331e431188f6ddb6767229cad064c87dc5e9. It has also been added to the existing pull request. In regards to the interface change and the commit, I decided to change the interface from using [snip]char*[/snip] to using [snip]unsigned char*[/snip], since that turned out to fit better with the existing systems. Apart from that, there was no other changes to the new interface.
|
|
|
Logged
|
|
|
|
polygone
|
|
Reply #12 Posted on: November 07, 2012, 12:30:49 am |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
forthevin: to note; the move_* functions etc should use the object parameter when checking collision_inst_inst not all. Also in the for loops you should increment by DMIN instead of 1.
ps are you ever possibly planning on using the enigma irc channel? It would be nice to know your future plans etc with regards to what you're going to be working on in enigma. Great to see someone actually doing precise collisions again though.
|
|
« Last Edit: November 07, 2012, 07:23:08 am by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
|
|