MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Animations_ReadDescription

Function Animations_ReadDescription

src/Animations.c:196–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194#define ANIM_MIN_ARGS 7
195
196static void Animations_ReadDescription(struct Stream* stream, const cc_string* path) {
197 cc_string line; char lineBuffer[STRING_SIZE * 2];
198 cc_string parts[ANIM_MIN_ARGS];
199 int count;
200 struct AnimationData data = { 0 };
201 cc_uint8 tileX, tileY;
202
203 cc_uint8 buffer[2048];
204 struct Stream buffered;
205 cc_result res;
206
207 String_InitArray(line, lineBuffer);
208 /* ReadLine reads single byte at a time */
209 Stream_ReadonlyBuffered(&buffered, stream, buffer, sizeof(buffer));
210
211 for (;;) {
212 res = Stream_ReadLine(&buffered, &line);
213 if (res == ERR_END_OF_STREAM) break;
214 if (res) { Logger_SysWarn2(res, "reading from", path); break; }
215
216 if (!line.length || line.buffer[0] == '#') continue;
217 count = String_UNSAFE_Split(&line, ' ', parts, ANIM_MIN_ARGS);
218 if (count < ANIM_MIN_ARGS) {
219 Chat_Add1("&cNot enough arguments for anim: %s", &line); continue;
220 }
221
222 if (!Convert_ParseUInt8(&parts[0], &tileX) || tileX >= ATLAS2D_TILES_PER_ROW) {
223 Chat_Add1("&cInvalid anim tile X coord: %s", &parts[0]); continue;
224 }
225 if (!Convert_ParseUInt8(&parts[1], &tileY) || tileY >= ATLAS2D_MAX_ROWS_COUNT) {
226 Chat_Add1("&cInvalid anim tile Y coord: %s", &parts[1]); continue;
227 }
228 if (!Convert_ParseUInt16(&parts[2], &data.frameX)) {
229 Chat_Add1("&cInvalid anim frame X coord: %s", &parts[2]); continue;
230 }
231 if (!Convert_ParseUInt16(&parts[3], &data.frameY)) {
232 Chat_Add1("&cInvalid anim frame Y coord: %s", &parts[3]); continue;
233 }
234 if (!Convert_ParseUInt16(&parts[4], &data.frameSize) || !data.frameSize) {
235 Chat_Add1("&cInvalid anim frame size: %s", &parts[4]); continue;
236 }
237 if (!Convert_ParseUInt16(&parts[5], &data.statesCount)) {
238 Chat_Add1("&cInvalid anim states count: %s", &parts[5]); continue;
239 }
240 if (!Convert_ParseUInt16(&parts[6], &data.frameDelay)) {
241 Chat_Add1("&cInvalid anim frame delay: %s", &parts[6]); continue;
242 }
243
244 if (anims_count == Array_Elems(anims_list)) {
245 Chat_AddRaw("&cCannot show over 512 animations"); return;
246 }
247
248 data.texLoc = tileX + (tileY * ATLAS2D_TILES_PER_ROW);
249 anims_list[anims_count++] = data;
250 }
251}
252
253static void Animations_Update(int texLoc, struct Bitmap* bmp, int stride) {

Callers

nothing calls this directly

Calls 8

Stream_ReadonlyBufferedFunction · 0.85
Stream_ReadLineFunction · 0.85
Logger_SysWarn2Function · 0.85
String_UNSAFE_SplitFunction · 0.85
Chat_Add1Function · 0.85
Convert_ParseUInt8Function · 0.85
Convert_ParseUInt16Function · 0.85
Chat_AddRawFunction · 0.85

Tested by

no test coverage detected