summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5c36c02)
raw | patch | inline | side by side (parent: 5c36c02)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 7 May 2021 06:22:07 +0000 (09:22 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 7 May 2021 06:22:07 +0000 (09:22 +0300) |
diff --git a/src/common/wadres.c b/src/common/wadres.c
index 356f591f2267be52967cfed126d433fefa21623b..43251c8d9d00507d5a251e24e422400bbd2c034a 100644 (file)
--- a/src/common/wadres.c
+++ b/src/common/wadres.c
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];
ok = 0;
}
}
+ s_start = WADRES_find("S_START");
+ s_end = WADRES_find("S_END");
return ok;
}
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 49f0f9dcbb469b09d1fb11e7f1dd51cec18e369d..c1be63a8e13dc61095bcf8fc84815454f764202f 100644 (file)
--- a/src/common/wadres.h
+++ b/src/common/wadres.h
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 69a362c18a5b4d78db069d2ca097e986478c282d..52680425dc0a236726b74ffee540ee29d017d214 100644 (file)
--- a/src/kos32/files.c
+++ b/src/kos32/files.c
}
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 b46856d21fcc8eb63d3697dba10bf37b8d8a58ec..472fa5b1587c0cdc0be37e270aa112dce2a54a31 100644 (file)
--- a/src/sdl/files.c
+++ b/src/sdl/files.c
}
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 5fb8b317c48f25df91b6317ad305d3bacb369083..736e651e5becd669aefd15ee3429133fea8dbc93 100644 (file)
--- a/src/sdl2/files.c
+++ b/src/sdl2/files.c
}
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) {