Mercurial > molko
comparison 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 |
comparison
equal
deleted
inserted
replaced
592:1560ef13146c | 593:f9e85d0aca74 |
---|---|
104 unsigned int id, w, h; | 104 unsigned int id, w, h; |
105 int x, y; | 105 int x, y; |
106 size_t collisionsz = 0; | 106 size_t collisionsz = 0; |
107 | 107 |
108 while (fscanf(fp, "%u|%d|%d|%u|%u\n", &id, &x, &y, &w, &h) == 5) { | 108 while (fscanf(fp, "%u|%d|%d|%u|%u\n", &id, &x, &y, &w, &h) == 5) { |
109 if (!(array = loader->expand_collisions(loader, collisions, collisionsz + 1))) | 109 if (!(array = loader->expand_collisions(loader, tileset, collisions, collisionsz + 1))) |
110 return -1; | 110 return -1; |
111 | 111 |
112 collisions = array; | 112 collisions = array; |
113 collision = &collisions[collisionsz++]; | 113 collision = &collisions[collisionsz++]; |
114 collision->id = id; | 114 collision->id = id; |
156 * 2. The sprite object that will use the above texture. | 156 * 2. The sprite object that will use the above texture. |
157 * 3. The animation object. | 157 * 3. The animation object. |
158 * 4. Link the animation to the tileset animation. | 158 * 4. Link the animation to the tileset animation. |
159 */ | 159 */ |
160 while (fscanf(fp, fmt, &id, filename, &delay) == 3) { | 160 while (fscanf(fp, fmt, &id, filename, &delay) == 3) { |
161 if (!(texture = loader->init_texture(loader, filename))) | 161 if (!(texture = loader->new_texture(loader, tileset, filename))) |
162 return -1; | 162 return -1; |
163 if (!(sprite = loader->init_sprite(loader))) | 163 if (!(sprite = loader->new_sprite(loader, tileset))) |
164 return -1; | 164 return -1; |
165 if (!(animation = loader->init_animation(loader))) | 165 if (!(animation = loader->new_animation(loader, tileset))) |
166 return -1; | 166 return -1; |
167 if (!(array = loader->expand_animations(loader, tileanimations, tileanimationsz + 1))) | 167 if (!(array = loader->expand_animations(loader, tileset, tileanimations, tileanimationsz + 1))) |
168 return -1; | 168 return -1; |
169 | 169 |
170 /* Bind the texture to the new sprite. */ | 170 /* Bind the texture to the new sprite. */ |
171 sprite->texture = texture; | 171 sprite->texture = texture; |
172 sprite->cellw = loader->tilewidth; | 172 sprite->cellw = loader->tilewidth; |
209 | 209 |
210 if (loader->tilewidth == 0 || loader->tileheight == 0) | 210 if (loader->tilewidth == 0 || loader->tileheight == 0) |
211 return mlk_errf("missing tile dimensions before image"); | 211 return mlk_errf("missing tile dimensions before image"); |
212 if (!(p = strchr(line, '|'))) | 212 if (!(p = strchr(line, '|'))) |
213 return mlk_errf("could not parse image"); | 213 return mlk_errf("could not parse image"); |
214 if (!(texture = loader->init_texture(loader, p + 1))) | 214 if (!(texture = loader->new_texture(loader, tileset, p + 1))) |
215 return -1; | 215 return -1; |
216 if (!(sprite = loader->init_sprite(loader))) | 216 if (!(sprite = loader->new_sprite(loader, tileset))) |
217 return -1; | 217 return -1; |
218 | 218 |
219 /* Initialize the sprite with the texture. */ | 219 /* Initialize the sprite with the texture. */ |
220 sprite->texture = texture; | 220 sprite->texture = texture; |
221 sprite->cellw = loader->tilewidth; | 221 sprite->cellw = loader->tilewidth; |