changeset 638:e16808365d42

core: s/mlk_texture_new/mlk_texture_init/g
author David Demelier <markand@malikania.fr>
date Mon, 11 Sep 2023 20:44:16 +0200
parents 19707e3ad048
children 19d19f644b5e
files examples/example-action/dialog.c examples/example-action/example-action.c libmlk-core/mlk/core/sprite.c libmlk-core/mlk/core/texture.c libmlk-core/mlk/core/texture.h libmlk-rpg/mlk/rpg/map.c libmlk-rpg/mlk/rpg/message.c
diffstat 7 files changed, 14 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/examples/example-action/dialog.c	Mon Sep 11 20:15:31 2023 +0200
+++ b/examples/example-action/dialog.c	Mon Sep 11 20:44:16 2023 +0200
@@ -58,8 +58,8 @@
 {
 	struct dialog *dlg = act->data;
 
-	if ((dlg->msg.flags & MLK_MESSAGE_FLAGS_QUESTION) && dlg->response)
-		dlg->response(dlg, dlg->msg.index);
+	if (dlg->msg.selectable && dlg->response)
+		dlg->response(dlg, dlg->msg.selected);
 }
 
 struct mlk_action *
--- a/examples/example-action/example-action.c	Mon Sep 11 20:15:31 2023 +0200
+++ b/examples/example-action/example-action.c	Mon Sep 11 20:44:16 2023 +0200
@@ -99,7 +99,7 @@
 	{
 		.response = script_left_response,
 		.msg = {
-			.flags = MLK_MESSAGE_FLAGS_QUESTION,
+			.selectable = 0x3,
 			.linesz = 2,
 			.lines = (const char *[]) {
 				"Of course I am",
@@ -147,7 +147,7 @@
 	{
 		.response = script_right_response,
 		.msg = {
-			.flags = MLK_MESSAGE_FLAGS_QUESTION,
+			.selectable = 0x3,
 			.linesz = 2,
 			.lines = (const char *[]) {
 				"Because I think there was some gold",
--- a/libmlk-core/mlk/core/sprite.c	Mon Sep 11 20:15:31 2023 +0200
+++ b/libmlk-core/mlk/core/sprite.c	Mon Sep 11 20:44:16 2023 +0200
@@ -25,7 +25,6 @@
 mlk_sprite_init(struct mlk_sprite *sprite)
 {
 	assert(sprite);
-	assert(mlk_texture_ok(sprite->texture));
 
 	sprite->nrows = sprite->texture->h / sprite->cellh;
 	sprite->ncols = sprite->texture->w / sprite->cellw;
@@ -34,7 +33,7 @@
 int
 mlk_sprite_ok(const struct mlk_sprite *sprite)
 {
-	return sprite && sprite->cellw && sprite->cellh && mlk_texture_ok(sprite->texture);
+	return sprite && sprite->cellw && sprite->cellh && sprite->texture;
 }
 
 int
--- a/libmlk-core/mlk/core/texture.c	Mon Sep 11 20:15:31 2023 +0200
+++ b/libmlk-core/mlk/core/texture.c	Mon Sep 11 20:44:16 2023 +0200
@@ -28,7 +28,7 @@
 #include "window_p.h"
 
 int
-mlk_texture_new(struct mlk_texture *tex, unsigned int w, unsigned int h)
+mlk_texture_init(struct mlk_texture *tex, unsigned int w, unsigned int h)
 {
 	assert(tex);
 	assert(w);
@@ -49,12 +49,6 @@
 }
 
 int
-mlk_texture_ok(const struct mlk_texture *tex)
-{
-	return tex && tex->handle && tex->w && tex->h;
-}
-
-int
 mlk_texture_set_blend_mode(struct mlk_texture *tex, enum mlk_texture_blend blend)
 {
 	assert(tex);
@@ -76,7 +70,7 @@
 int
 mlk_texture_set_alpha_mod(struct mlk_texture *tex, unsigned int alpha)
 {
-	assert(mlk_texture_ok(tex));
+	assert(tex);
 	assert(alpha <= 255);
 
 	if (SDL_SetTextureAlphaMod(tex->handle, alpha) < 0)
@@ -88,7 +82,7 @@
 int
 mlk_texture_set_color_mod(struct mlk_texture *tex, unsigned long color)
 {
-	assert(mlk_texture_ok(tex));
+	assert(tex);
 
 	if (SDL_SetTextureColorMod(tex->handle, MLK_COLOR_R(color), MLK_COLOR_G(color), MLK_COLOR_B(color)) < 0)
 		return mlk_errf("%s", SDL_GetError());
--- a/libmlk-core/mlk/core/texture.h	Mon Sep 11 20:15:31 2023 +0200
+++ b/libmlk-core/mlk/core/texture.h	Mon Sep 11 20:44:16 2023 +0200
@@ -109,16 +109,7 @@
  * \return 0 on success or an error code on failure
  */
 int
-mlk_texture_new(struct mlk_texture *texture, unsigned int w, unsigned int h);
-
-/**
- * Tells if the texture structure is usable.
- *
- * \param texture the texture to check
- * \return non-zero if the texture structure is usable
- */
-int
-mlk_texture_ok(const struct mlk_texture *texture);
+mlk_texture_init(struct mlk_texture *texture, unsigned int w, unsigned int h);
 
 /**
  * Change color/alpha blending mode.
--- a/libmlk-rpg/mlk/rpg/map.c	Mon Sep 11 20:15:31 2023 +0200
+++ b/libmlk-rpg/mlk/rpg/map.c	Mon Sep 11 20:44:16 2023 +0200
@@ -503,7 +503,7 @@
 	mlk_tileset_draw(map->tileset, sr, sc, mx, my);
 
 	/* Draw collision box if colbox is non NULL. */
-	if ((tc = find_collision_by_id(map, id)) && mlk_texture_ok(colbox))
+	if ((tc = find_collision_by_id(map, id)) && colbox)
 		mlk_texture_scale(colbox, 0, 0, 5, 5, mx + tc->x, my + tc->y, tc->w, tc->h, 0);
 
 	if (map->flags & MLK_MAP_FLAGS_SHOW_GRID) {
@@ -539,7 +539,7 @@
 		return;
 
 	/* Show collision box if requested. */
-	if (map->flags & MLK_MAP_FLAGS_SHOW_COLLIDE && mlk_texture_new(&colbox, 16, 16) == 0) {
+	if (map->flags & MLK_MAP_FLAGS_SHOW_COLLIDE && mlk_texture_init(&colbox, 16, 16) == 0) {
 		mlk_texture_set_blend_mode(&colbox, MLK_TEXTURE_BLEND_BLEND);
 		mlk_texture_set_alpha_mod(&colbox, 100);
 		MLK_PAINTER_BEGIN(&colbox);
@@ -566,7 +566,7 @@
 {
 	struct mlk_texture box = {};
 
-	if (map->flags & MLK_MAP_FLAGS_SHOW_COLLIDE && mlk_texture_new(&box, 64, 64) == 0) {
+	if (map->flags & MLK_MAP_FLAGS_SHOW_COLLIDE && mlk_texture_init(&box, 64, 64) == 0) {
 		/* Draw collide box around player if requested. */
 		mlk_texture_set_alpha_mod(&box, 100);
 		mlk_texture_set_blend_mode(&box, MLK_TEXTURE_BLEND_BLEND);
--- a/libmlk-rpg/mlk/rpg/message.c	Mon Sep 11 20:15:31 2023 +0200
+++ b/libmlk-rpg/mlk/rpg/message.c	Mon Sep 11 20:44:16 2023 +0200
@@ -216,7 +216,7 @@
 	(void)self;
 
 	struct mlk_texture tex;
-	int x, y, err;
+	int x, y;
 	unsigned int w, h;
 
 	if (msg->w == 0 || msg->h == 0) {
@@ -224,7 +224,7 @@
 		return;
 	}
 
-	if ((err = mlk_texture_new(&tex, msg->w, msg->h)) < 0)
+	if (mlk_texture_init(&tex, msg->w, msg->h) < 0)
 		mlk_panic();
 
 	MLK_PAINTER_BEGIN(&tex);