remove optional by pointer texture_region parameters
This commit is contained in:
parent
991196f7c8
commit
b67bc92857
@ -179,7 +179,7 @@ static void draw_terrain(SceneIngame *scn) {
|
||||
draw_billboard("/assets/grasses/10.png",
|
||||
(Vec3){ (float)x, d0 + 0.15f, (float)y },
|
||||
(Vec2){0.3f, 0.3f},
|
||||
NULL,
|
||||
(Rect){0},
|
||||
(Color){255, 255, 255, 255}, true);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
/* TODO: combine flip_x and flip_y into a flip_mask with enum */
|
||||
TWN_API void draw_sprite(char const *texture,
|
||||
Rect rect,
|
||||
Rect const *texture_region, /* optional, default: NULL */
|
||||
Rect texture_region, /* optional, default: all 0 */
|
||||
Color color, /* optional, default: all 255 */
|
||||
float rotation, /* optional, default: 0 */
|
||||
bool flip_x, /* optional, default: false */
|
||||
@ -76,8 +76,8 @@ TWN_API void draw_quad(char const *texture,
|
||||
TWN_API void draw_billboard(char const *texture,
|
||||
Vec3 position,
|
||||
Vec2 size,
|
||||
Rect const *texture_region, /* optional, default: NULL */
|
||||
Color color, /* optional, default: all 255 */
|
||||
Rect texture_region, /* optional, default: NULL */
|
||||
Color color, /* optional, default: all 0 */
|
||||
bool cylindrical); /* optional, default: false */
|
||||
|
||||
TWN_API void draw_camera_2d(Vec2 position, /* optional, default: (0, 0) */
|
||||
|
@ -59,7 +59,7 @@
|
||||
"params": [
|
||||
{ "name": "texture", "type": "char *" },
|
||||
{ "name": "rect", "type": "Rect" },
|
||||
{ "name": "texture_region", "type": "Rect *", "default": {} },
|
||||
{ "name": "texture_region", "type": "Rect", "default": { "x": 0, "y": 0, "w": 0, "h": 0 } },
|
||||
{ "name": "color", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } },
|
||||
{ "name": "rotation", "type": "float", "default": 0.0 },
|
||||
{ "name": "flip_x", "type": "bool", "default": false },
|
||||
@ -180,7 +180,7 @@
|
||||
{ "name": "texture", "type": "char *" },
|
||||
{ "name": "position", "type": "Vec3" },
|
||||
{ "name": "size", "type": "Vec2" },
|
||||
{ "name": "texture_region", "type": "Rect *", "default": {} },
|
||||
{ "name": "texture_region", "type": "Rect", "default": { "x": 0, "y": 0, "w": 0, "h": 0 } },
|
||||
{ "name": "color", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } },
|
||||
{ "name": "cylindrical", "type": "bool", "default": false }
|
||||
]
|
||||
|
@ -12,7 +12,7 @@
|
||||
void draw_billboard(char const *texture,
|
||||
Vec3 position,
|
||||
Vec2 size,
|
||||
Rect const *texture_region,
|
||||
Rect texture_region,
|
||||
Color color,
|
||||
bool cylindrical)
|
||||
{
|
||||
@ -26,16 +26,19 @@ void draw_billboard(char const *texture,
|
||||
batch_p = &ctx.billboard_batches[hmlenu(ctx.billboard_batches) - 1]; /* TODO: can last index be used? */
|
||||
}
|
||||
|
||||
bool const texture_region_valid = fabsf(texture_region.w - texture_region.h) > 0.00001f
|
||||
&& fabsf(0.0f - texture_region.w) > 0.00001f;
|
||||
|
||||
struct SpaceBillboard billboard = {
|
||||
.color = color,
|
||||
.cylindrical = cylindrical,
|
||||
.position = position,
|
||||
.size = size,
|
||||
.texture_region_opt_set = texture_region != NULL,
|
||||
.texture_region_opt_set = texture_region_valid,
|
||||
};
|
||||
|
||||
if (texture_region)
|
||||
billboard.texture_region_opt = *texture_region;
|
||||
if (texture_region_valid)
|
||||
billboard.texture_region_opt = texture_region;
|
||||
|
||||
struct SpaceBillboard *billboards = (struct SpaceBillboard *)(void *)batch_p->value.primitives;
|
||||
|
||||
|
@ -19,13 +19,18 @@
|
||||
*/
|
||||
void draw_sprite(char const *path,
|
||||
Rect rect,
|
||||
Rect const *texture_region, /* optional, default: NULL */
|
||||
Rect texture_region, /* optional, default: 0 */
|
||||
Color color, /* optional, default: all 255 */
|
||||
float rotation, /* optional, default: 0 */
|
||||
bool flip_x, /* optional, default: false */
|
||||
bool flip_y, /* optional, default: false */
|
||||
bool stretch)
|
||||
{
|
||||
/* if .w and .h are zeroed then assume whole region */
|
||||
/* TODO: don't check here, just move to redner code ? */
|
||||
bool const texture_region_valid = fabsf(texture_region.w - texture_region.h) > 0.00001f
|
||||
&& fabsf(0.0f - texture_region.w) > 0.00001f;
|
||||
|
||||
SpritePrimitive sprite = {
|
||||
.rect = rect,
|
||||
.color = color,
|
||||
@ -34,11 +39,11 @@ void draw_sprite(char const *path,
|
||||
.flip_x = flip_x,
|
||||
.flip_y = flip_y,
|
||||
.repeat = !stretch,
|
||||
.texture_region_opt_set = texture_region != NULL,
|
||||
.texture_region_opt_set = texture_region_valid,
|
||||
};
|
||||
|
||||
if (texture_region)
|
||||
sprite.texture_region_opt = *texture_region;
|
||||
if (texture_region_valid)
|
||||
sprite.texture_region_opt = texture_region;
|
||||
|
||||
Primitive2D primitive = {
|
||||
.type = PRIMITIVE_2D_SPRITE,
|
||||
@ -54,7 +59,7 @@ void draw_sprite_args(const DrawSpriteArgs args) {
|
||||
bool const flip_x = m_or(args, flip_x, false);
|
||||
bool const flip_y = m_or(args, flip_y, false);
|
||||
bool const stretch = m_or(args, stretch, false);
|
||||
Rect const *texture_region = m_is_set(args, texture_region) ? &args.texture_region_opt : NULL;
|
||||
Rect const texture_region = m_or(args, texture_region, ((Rect){0}));
|
||||
|
||||
draw_sprite(args.texture, args.rect, texture_region, color, rotation, flip_x, flip_y, stretch);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user