Mercurial > molko
diff libmlk-rpg/mlk/rpg/tileset-loader.c @ 593:f9e85d0aca74
rpg: introduce private loader_file to help allocating map/tileset
The structure is just an allocator and owner for various data shared among the
map and the tileset such as sprites, textures, animations...
While here, simplify use of mlk_(map|tileset)_loader_file so they don't have a
public structure anymore but insert themselves into the loader->data.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 21 Mar 2023 14:08:15 +0100 |
parents | cba66f7d8a53 |
children | bb67f935a93f |
line wrap: on
line diff
--- a/libmlk-rpg/mlk/rpg/tileset-loader.c Mon Mar 20 21:59:02 2023 +0100 +++ b/libmlk-rpg/mlk/rpg/tileset-loader.c Tue Mar 21 14:08:15 2023 +0100 @@ -106,7 +106,7 @@ size_t collisionsz = 0; while (fscanf(fp, "%u|%d|%d|%u|%u\n", &id, &x, &y, &w, &h) == 5) { - if (!(array = loader->expand_collisions(loader, collisions, collisionsz + 1))) + if (!(array = loader->expand_collisions(loader, tileset, collisions, collisionsz + 1))) return -1; collisions = array; @@ -158,13 +158,13 @@ * 4. Link the animation to the tileset animation. */ while (fscanf(fp, fmt, &id, filename, &delay) == 3) { - if (!(texture = loader->init_texture(loader, filename))) + if (!(texture = loader->new_texture(loader, tileset, filename))) return -1; - if (!(sprite = loader->init_sprite(loader))) + if (!(sprite = loader->new_sprite(loader, tileset))) return -1; - if (!(animation = loader->init_animation(loader))) + if (!(animation = loader->new_animation(loader, tileset))) return -1; - if (!(array = loader->expand_animations(loader, tileanimations, tileanimationsz + 1))) + if (!(array = loader->expand_animations(loader, tileset, tileanimations, tileanimationsz + 1))) return -1; /* Bind the texture to the new sprite. */ @@ -211,9 +211,9 @@ return mlk_errf("missing tile dimensions before image"); if (!(p = strchr(line, '|'))) return mlk_errf("could not parse image"); - if (!(texture = loader->init_texture(loader, p + 1))) + if (!(texture = loader->new_texture(loader, tileset, p + 1))) return -1; - if (!(sprite = loader->init_sprite(loader))) + if (!(sprite = loader->new_sprite(loader, tileset))) return -1; /* Initialize the sprite with the texture. */