From 73e4e67595c5ca248e8c2493d93cba08d8c938d9 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Sat, 28 Sep 2019 19:13:51 -0300 Subject: [PATCH] JIMITA DO THE SOC --- src/dehacked.c | 127 ++++++++++++++++++++++++++++++++++++++--- src/hardware/hw_main.c | 2 +- src/r_defs.h | 13 +++++ src/r_things.c | 15 +++-- src/r_things.h | 4 +- 5 files changed, 146 insertions(+), 15 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 9f74883e7..3f7f6850e 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -738,11 +738,12 @@ static void readlight(MYFILE *f, INT32 num) Z_Free(s); } +#endif // HWRENDER -static void readspritelight(MYFILE *f, INT32 num) +static void readspriteframe(MYFILE *f, INT32 num, INT32 frame) { char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); - char *word; + char *word, *word2; char *tmp; INT32 value; @@ -753,20 +754,122 @@ static void readspritelight(MYFILE *f, INT32 num) if (s[0] == '\n') break; + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + tmp = strchr(s, '#'); if (tmp) *tmp = '\0'; if (s == tmp) continue; // Skip comment lines, but don't break. - value = searchvalue(s); + // Set / reset word + word = s; - word = strtok(s, " "); - if (word) - strupr(word); + // Get the part before the " = " + tmp = strchr(s, '='); + if (tmp) + { + *(tmp-1) = '\0'; + // Now get the part after + word2 = tmp += 2; + } else + { + // Get the part before the " " + tmp = strchr(s, ' '); + if (tmp) + { + *tmp = '\0'; + // Now get the part after + tmp++; + word2 = tmp; + } + else + break; + } + strupr(word); + value = atoi(word2); // used for numerical settings + + if (frame >= 64) + { + deh_warning("Sprite %d: invalid frame %d", num, frame); + break; + } + +#ifdef ROTSPRITE + if (fastcmp(word, "XPIVOT")) + spriteinfo[num].pivot[frame].x = value; + else if (fastcmp(word, "YPIVOT")) + spriteinfo[num].pivot[frame].y = value; + else +#endif + if (fastcmp(word, "END")) + break; + else + deh_warning("Sprite %d frame %d: unknown word '%s'", num, frame, word); + } + } while (!myfeof(f)); // finish when the line is empty + + Z_Free(s); +} + +static void readspriteinfo(MYFILE *f, INT32 num) +{ + char *s = Z_Malloc(MAXLINELEN, PU_STATIC, NULL); + char *word, *word2; + char *tmp; + INT32 value; + + do + { + if (myfgets(s, MAXLINELEN, f)) + { + if (s[0] == '\n') break; + // First remove trailing newline, if there is one + tmp = strchr(s, '\n'); + if (tmp) + *tmp = '\0'; + + tmp = strchr(s, '#'); + if (tmp) + *tmp = '\0'; + if (s == tmp) + continue; // Skip comment lines, but don't break. + + // Set / reset word + word = s; + + // Get the part before the " = " + tmp = strchr(s, '='); + if (tmp) + { + *(tmp-1) = '\0'; + // Now get the part after + word2 = tmp += 2; + } + else + { + // Get the part before the " " + tmp = strchr(s, ' '); + if (tmp) + { + *tmp = '\0'; + // Now get the part after + tmp++; + word2 = tmp; + } + else + break; + } + strupr(word); + value = atoi(word2); // used for numerical settings + +#ifdef HWRENDER if (fastcmp(word, "LIGHTTYPE")) { INT32 oldvar; @@ -775,13 +878,19 @@ static void readspritelight(MYFILE *f, INT32 num) t_lspr[num] = &lspr[value]; } else +#endif + if (fastcmp(word, "FRAME")) + { + readspriteframe(f, num, R_Char2Frame(word2[0])); + spriteinfo[num].available = true; + } + else deh_warning("Sprite %d: unknown word '%s'", num, word); } } while (!myfeof(f)); // finish when the line is empty Z_Free(s); } -#endif // HWRENDER static void readsprite2(MYFILE *f, INT32 num) { @@ -3898,19 +4007,19 @@ static void DEH_LoadDehackedFile(MYFILE *f, boolean mainfile) ignorelines(f); } } +#endif else if (fastcmp(word, "SPRITE")) { if (i == 0 && word2[0] != '0') // If word2 isn't a number i = get_sprite(word2); // find a sprite by name if (i < NUMSPRITES && i > 0) - readspritelight(f, i); + readspriteinfo(f, i); else { deh_warning("Sprite number %d out of range (0 - %d)", i, NUMSPRITES-1); ignorelines(f); } } -#endif else if (fastcmp(word, "LEVEL")) { // Support using the actual map name, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f35a3a225..aff802352 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5658,7 +5658,7 @@ static void HWR_ProjectSprite(mobj_t *thing) if (rollangle > 0) { if (!sprframe->rotsprite.cached[rot]) - R_CacheRotSprite(sprframe, rot, flip); + R_CacheRotSprite(thing->sprite, thing->frame, sprframe, rot, flip); rollangle /= ROTANGDIFF; rotsprite = sprframe->rotsprite.patch[rot][rollangle]; if (rotsprite != NULL) diff --git a/src/r_defs.h b/src/r_defs.h index a04b3128f..aa789a0ea 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -737,8 +737,21 @@ typedef struct aatree_t *hardware_patch[8]; #endif } rotsprite_t; + +typedef struct +{ + INT32 x, y; +} spriteframepivot_t; #endif +typedef struct +{ +#ifdef ROTSPRITE + spriteframepivot_t pivot[64]; +#endif + boolean available; +} spriteinfo_t; + typedef enum { SRF_SINGLE = 0, // 0-angle for all rotations diff --git a/src/r_things.c b/src/r_things.c index bb97242bc..fe2a20b12 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -72,6 +72,8 @@ static lighttable_t **spritelights; INT16 negonearray[MAXVIDWIDTH]; INT16 screenheightarray[MAXVIDWIDTH]; +spriteinfo_t spriteinfo[NUMSPRITES]; + #ifdef ROTSPRITE static fixed_t cosang2rad[ROTANGLES]; static fixed_t sinang2rad[ROTANGLES]; @@ -217,7 +219,7 @@ static void R_InstallSpriteLump(UINT16 wad, // graphics patch } #ifdef ROTSPRITE -void R_CacheRotSprite(spriteframe_t *sprframe, INT32 rot, UINT8 flip) +void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteframe_t *sprframe, INT32 rot, UINT8 flip) { UINT32 i; INT32 angle; @@ -251,8 +253,13 @@ void R_CacheRotSprite(spriteframe_t *sprframe, INT32 rot, UINT8 flip) height = patch->height; // rotation pivot - px = SPRITE_XCENTER; //22; - py = SPRITE_YCENTER; //47; + px = SPRITE_XCENTER; + py = SPRITE_YCENTER; + if (spriteinfo[sprnum].available) + { + px = spriteinfo[sprnum].pivot[frame].x; + py = spriteinfo[sprnum].pivot[frame].y; + } if (flip) px = width - px; @@ -1458,7 +1465,7 @@ static void R_ProjectSprite(mobj_t *thing) if (rollangle > 0) { if (!sprframe->rotsprite.cached[rot]) - R_CacheRotSprite(sprframe, rot, flip); + R_CacheRotSprite(thing->sprite, thing->frame, sprframe, rot, flip); rollangle /= ROTANGDIFF; rotsprite = sprframe->rotsprite.patch[rot][rollangle]; if (rotsprite != NULL) diff --git a/src/r_things.h b/src/r_things.h index 6ed4a7067..aa1c92607 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -53,7 +53,7 @@ void R_DrawFlippedMaskedColumn(column_t *column, INT32 texheight); void R_AddSpriteDefs(UINT16 wadnum); #ifdef ROTSPRITE -void R_CacheRotSprite(spriteframe_t *sprframe, INT32 rot, UINT8 flip); +void R_CacheRotSprite(spritenum_t sprnum, UINT8 frame, spriteframe_t *sprframe, INT32 rot, UINT8 flip); #endif //SoM: 6/5/2000: Light sprites correctly! @@ -210,6 +210,8 @@ typedef struct vissprite_s INT32 dispoffset; // copy of info->dispoffset, affects ordering but not drawing } vissprite_t; +extern spriteinfo_t spriteinfo[NUMSPRITES]; + // A drawnode is something that points to a 3D floor, 3D side, or masked // middle texture. This is used for sorting with sprites. typedef struct drawnode_s