From: DeaDDooMER Date: Fri, 7 May 2021 06:22:07 +0000 (+0300) Subject: files: move getsprid to wadres X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=f3b05d5b038cb8fe4d720d8d43bf89bf94759251;p=flatwaifu.git files: move getsprid to wadres --- diff --git a/src/common/wadres.c b/src/common/wadres.c index 356f591..43251c8 100644 --- a/src/common/wadres.c +++ b/src/common/wadres.c @@ -25,6 +25,8 @@ static Stream *wads[MAX_WADS]; static Entry resources[MAX_RESOURCES]; static Block *blocks[MAX_RESOURCES]; +static int s_start, s_end; + static int check_header (Stream *r) { assert(r != NULL); char ident[4]; @@ -85,6 +87,8 @@ int WADRES_rehash (void) { ok = 0; } } + s_start = WADRES_find("S_START"); + s_end = WADRES_find("S_END"); return ok; } @@ -100,6 +104,26 @@ int WADRES_maxids (void) { return n_resources; } +int WADRES_findsprite (const char n[4], int s, int d, char *dir) { + s += 'A'; + d += '0'; + for (int i = s_start + 1; i < s_end; i++) { + char a, b; + char *wn = resources[i].name; + if (cp866_strncasecmp(wn, n, 4) == 0 && (wn[4] == s || wn[6] == s)) { + a = wn[4] == s ? wn[5] : 0; + b = wn[6] == s ? wn[7] : 0; + if (a == '0' || b == '0' || a == d || b == d) { + if (dir != NULL) { + *dir = (a != '0' && b == '0') || (a != d && b == d); + } + return i; + } + } + } + return -1; +} + Stream *WADRES_getbasereader (int id) { assert(id >= 0 && id < n_resources); return wads[resources[id].f]; diff --git a/src/common/wadres.h b/src/common/wadres.h index 49f0f9d..c1be63a 100644 --- a/src/common/wadres.h +++ b/src/common/wadres.h @@ -12,6 +12,24 @@ int WADRES_rehash (void); int WADRES_find (const char name[8]); int WADRES_maxids (void); +// Get sprite resource id. +// Sprite name has following format: +// (nnnn)('A'+s)('0'+d)[('A'+s)('0'+d)] +// Letter means animation frame +// A for first, B for second... +// Number means direction +// 0 = front +// 1 = left +// 2 = right +// Optional part means that this file can be used for differnt frame/direction. +// Note that if found FRONT direction for this frame than it UNCONDITIONALLY used. +// Note that search performed between markers S_START and S_END in order as paced in wad. +// int n[4] -- sprite name +// int s -- sprite frame +// int d -- sprite direction +// char *dir -- out flag "alternative used" +int WADRES_findsprite (const char n[4], int s, int d, char *dir); + Stream *WADRES_getbasereader (int id); long WADRES_getoffset (int id); long WADRES_getsize (int id); diff --git a/src/kos32/files.c b/src/kos32/files.c index 69a362c..5268042 100644 --- a/src/kos32/files.c +++ b/src/kos32/files.c @@ -86,25 +86,11 @@ void F_getresname (char n[8], int r) { } int F_getsprid (const char n[4], int s, int d, char *dir) { - s += 'A'; - d += '0'; - for (int i = s_start + 1; i < s_end; i++) { - char wn[8]; - byte a, b; - WADRES_getname(i, wn); - if (cp866_strncasecmp(wn, n, 4) == 0 && (wn[4] == s || wn[6] == s)) { - a = wn[4] == s ? wn[5] : 0; - b = wn[6] == s ? wn[7] : 0; - if (a == '0' || b == '0' || a == d || b == d) { - if (dir != NULL) { - *dir = (a != '0' && b == '0') || (a != d && b == d); - } - return i; - } - } + int i = WADRES_findsprite(n, s, d, dir); + if (i == -1) { + ERR_fatal("F_getsprid: image %.4s%c%c not found", n, s, d); } - ERR_fatal("F_getsprid: image %.4s%c%c not found", n, s, d); - return -1; + return i; } int F_getreslen (int r) { diff --git a/src/sdl/files.c b/src/sdl/files.c index b46856d..472fa5b 100644 --- a/src/sdl/files.c +++ b/src/sdl/files.c @@ -90,25 +90,11 @@ void F_getresname (char n[8], int r) { } int F_getsprid (const char n[4], int s, int d, char *dir) { - s += 'A'; - d += '0'; - for (int i = s_start + 1; i < s_end; i++) { - char wn[8]; - byte a, b; - WADRES_getname(i, wn); - if (cp866_strncasecmp(wn, n, 4) == 0 && (wn[4] == s || wn[6] == s)) { - a = wn[4] == s ? wn[5] : 0; - b = wn[6] == s ? wn[7] : 0; - if (a == '0' || b == '0' || a == d || b == d) { - if (dir != NULL) { - *dir = (a != '0' && b == '0') || (a != d && b == d); - } - return i; - } - } + int i = WADRES_findsprite(n, s, d, dir); + if (i == -1) { + ERR_fatal("F_getsprid: image %.4s%c%c not found", n, s, d); } - ERR_fatal("F_getsprid: image %.4s%c%c not found", n, s, d); - return -1; + return i; } int F_getreslen (int r) { diff --git a/src/sdl2/files.c b/src/sdl2/files.c index 5fb8b31..736e651 100644 --- a/src/sdl2/files.c +++ b/src/sdl2/files.c @@ -90,25 +90,11 @@ void F_getresname (char n[8], int r) { } int F_getsprid (const char n[4], int s, int d, char *dir) { - s += 'A'; - d += '0'; - for (int i = s_start + 1; i < s_end; i++) { - char wn[8]; - byte a, b; - WADRES_getname(i, wn); - if (cp866_strncasecmp(wn, n, 4) == 0 && (wn[4] == s || wn[6] == s)) { - a = wn[4] == s ? wn[5] : 0; - b = wn[6] == s ? wn[7] : 0; - if (a == '0' || b == '0' || a == d || b == d) { - if (dir != NULL) { - *dir = (a != '0' && b == '0') || (a != d && b == d); - } - return i; - } - } + int i = WADRES_findsprite(n, s, d, dir); + if (i == -1) { + ERR_fatal("F_getsprid: image %.4s%c%c not found", n, s, d); } - ERR_fatal("F_getsprid: image %.4s%c%c not found", n, s, d); - return -1; + return i; } int F_getreslen (int r) {