From 0be09f54bde1ab1ad084c4359d018d7e28341381 Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Mon, 25 Jan 2016 15:44:11 -0600 Subject: [PATCH 1/8] Particles can now scale up to 65535. --- src/p_acs.cpp | 8 ++++---- src/p_effect.cpp | 2 +- src/p_effect.h | 4 ++-- src/thingdef/thingdef_codeptr.cpp | 5 ++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/p_acs.cpp b/src/p_acs.cpp index ff968d62f2..3aab261f46 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -6009,10 +6009,10 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) int startalpha = argCount > 13 ? args[13] : 0xFF; // Byte trans int fadestep = argCount > 14 ? args[14] : -1; - startalpha = clamp(startalpha, 0, 0xFF); // Clamp to byte - lifetime = clamp(lifetime, 0, 0xFF); // Clamp to byte - fadestep = clamp(fadestep, -1, 0xFF); // Clamp to byte inc. -1 (indicating automatic) - size = clamp(size, 0, 127); // Clamp to byte + startalpha = clamp(startalpha, 0, 255); // Clamp to byte + lifetime = clamp(lifetime, 0, 255); // Clamp to byte + fadestep = clamp(fadestep, -1, 255); // Clamp to byte inc. -1 (indicating automatic) + size = clamp(size, 0, 65535); // Clamp to word if (lifetime != 0) P_SpawnParticle(x, y, z, xvel, yvel, zvel, color, fullbright, startalpha, lifetime, size, fadestep, accelx, accely, accelz); diff --git a/src/p_effect.cpp b/src/p_effect.cpp index 3ccfb67d2c..84ed4c16fe 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -284,7 +284,7 @@ void P_ThinkParticles () } } -void P_SpawnParticle(fixed_t x, fixed_t y, fixed_t z, fixed_t velx, fixed_t vely, fixed_t velz, PalEntry color, bool fullbright, BYTE startalpha, BYTE lifetime, BYTE size, int fadestep, fixed_t accelx, fixed_t accely, fixed_t accelz) +void P_SpawnParticle(fixed_t x, fixed_t y, fixed_t z, fixed_t velx, fixed_t vely, fixed_t velz, PalEntry color, bool fullbright, BYTE startalpha, BYTE lifetime, WORD size, int fadestep, fixed_t accelx, fixed_t accely, fixed_t accelz) { particle_t *particle = NewParticle(); diff --git a/src/p_effect.h b/src/p_effect.h index aac9a63dc5..d92c77e237 100644 --- a/src/p_effect.h +++ b/src/p_effect.h @@ -59,7 +59,7 @@ struct particle_t fixed_t accx,accy,accz; BYTE ttl; BYTE trans; - BYTE size:7; + WORD size; BYTE bright:1; BYTE fade; int color; @@ -83,7 +83,7 @@ particle_t *JitterParticle (int ttl); particle_t *JitterParticle (int ttl, float drift); void P_ThinkParticles (void); -void P_SpawnParticle(fixed_t x, fixed_t y, fixed_t z, fixed_t velx, fixed_t vely, fixed_t velz, PalEntry color, bool fullbright, BYTE startalpha, BYTE lifetime, BYTE size, int fadestep, fixed_t accelx, fixed_t accely, fixed_t accelz); +void P_SpawnParticle(fixed_t x, fixed_t y, fixed_t z, fixed_t velx, fixed_t vely, fixed_t velz, PalEntry color, bool fullbright, BYTE startalpha, BYTE lifetime, WORD size, int fadestep, fixed_t accelx, fixed_t accely, fixed_t accelz); void P_InitEffects (void); void P_RunEffects (void); diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index ac1afcf495..6926c1fac9 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -2644,7 +2644,6 @@ enum SPFflag DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SpawnParticle) { - //(color color1, int flags = 0, int lifetime = 35, int size = 1, float angle = 0, float xoff = 0, float yoff = 0, float zoff = 0, float velx = 0, float vely = 0, float velz = 0, float accelx = 0, float accely = 0, float accelz = 0, float startalphaf = 1, float fadestepf = -1); ACTION_PARAM_START(15); ACTION_PARAM_COLOR(color, 0); ACTION_PARAM_INT(flags, 1); @@ -2665,8 +2664,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_SpawnParticle) BYTE startalpha = (BYTE)Scale(clamp(startalphaf, 0, FRACUNIT), 255, FRACUNIT); int fadestep = fadestepf < 0? -1 : Scale(clamp(fadestepf, 0, FRACUNIT), 255, FRACUNIT); - lifetime = clamp(lifetime, 0, 0xFF); // Clamp to byte - size = clamp(size, 0, 0xFF); // Clamp to byte + lifetime = clamp(lifetime, 0, 255); // Clamp to byte + size = clamp(size, 0, 65535); // Clamp to word if (lifetime != 0) { From 774c1365326dc93f3787cb9001a383660253df12 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 25 Jan 2016 18:55:05 -0600 Subject: [PATCH 2/8] Fixed: Player.FallingScreamSpeed used minz as the maxz as well --- src/thingdef/thingdef_properties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 183cf27091..fd0636a707 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -2455,7 +2455,7 @@ DEFINE_CLASS_PROPERTY_PREFIX(player, GruntSpeed, F, PlayerPawn) DEFINE_CLASS_PROPERTY_PREFIX(player, FallingScreamSpeed, FF, PlayerPawn) { PROP_FIXED_PARM(minz, 0); - PROP_FIXED_PARM(maxz, 0); + PROP_FIXED_PARM(maxz, 1); defaults->FallingScreamMinSpeed = minz; defaults->FallingScreamMaxSpeed = maxz; } From 61d033328bed5ea2adda9409eaa1b6c22c0d5184 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 25 Jan 2016 20:18:33 -0600 Subject: [PATCH 3/8] Don't show "exited the level" messages after the level has exited --- src/p_spec.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/p_spec.cpp b/src/p_spec.cpp index 0dcf5124a5..b49dd43afb 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -36,6 +36,7 @@ #include "templates.h" #include "doomdef.h" #include "doomstat.h" +#include "d_event.h" #include "gstrings.h" #include "i_system.h" @@ -174,7 +175,7 @@ bool CheckIfExitIsGood (AActor *self, level_info_t *info) { return false; } - if (deathmatch) + if (deathmatch && gameaction != ga_completed) { Printf ("%s exited the level.\n", self->player->userinfo.GetName()); } From 0fc40cff0a44055d968f2569073a12e036691d2a Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 25 Jan 2016 21:23:53 -0600 Subject: [PATCH 4/8] Fix some rare PNG tRNS chunk cases - For grayscale images drawn with the paletted renderer, the value here was treated as always full range [0,65535]. The max value is actually determined by the bit depth. - For RGB images drawn with the paletted renderer, the tRNS chunk was ignored. - For grayscale images drawn with the RGB renderer, having a tRNS chunk present resulted in undefined behavior. - For RGB images drawn with the RGB renderer, the tRNS chunk was ignored. --- src/textures/bitmap.cpp | 27 +++++++++------- src/textures/bitmap.h | 33 ++++++++++++------- src/textures/pngtexture.cpp | 64 ++++++++++++++++++++++++++++++------- 3 files changed, 90 insertions(+), 34 deletions(-) diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index 94b8ce774e..6c25306538 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -46,7 +46,8 @@ // //=========================================================================== template -void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *inf) +void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *inf, + BYTE tr, BYTE tg, BYTE tb) { int i; int fac; @@ -59,7 +60,7 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in case BLEND_NONE: for(i=0;i>4; @@ -99,7 +100,7 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in FSpecialColormap *cm = &SpecialColormaps[inf->blend - BLEND_SPECIALCOLORMAP1]; for(i=0;i(TSrc::Gray(pin),0,255); @@ -120,7 +121,7 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in fac=inf->blend-BLEND_DESATURATE1+1; for(i=0;iblendcolor[0])>>FRACBITS; @@ -163,7 +164,7 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in for(i=0;iblendcolor[3] + inf->blendcolor[0]) >> FRACBITS; @@ -183,11 +184,12 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in } } -typedef void (*CopyFunc)(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *inf); +typedef void (*CopyFunc)(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *inf, BYTE r, BYTE g, BYTE b); #define COPY_FUNCS(op) \ { \ iCopyColors, \ + iCopyColors, \ iCopyColors, \ iCopyColors, \ iCopyColors, \ @@ -197,7 +199,7 @@ typedef void (*CopyFunc)(BYTE *pout, const BYTE *pin, int count, int step, FCopy iCopyColors, \ iCopyColors \ } -static const CopyFunc copyfuncs[][9]={ +static const CopyFunc copyfuncs[][10]={ COPY_FUNCS(bCopy), COPY_FUNCS(bBlend), COPY_FUNCS(bAdd), @@ -370,7 +372,8 @@ bool FClipRect::Intersect(int ix, int iy, int iw, int ih) // //=========================================================================== void FBitmap::CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth, - int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf) + int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf, + int r, int g, int b) { if (ClipCopyPixelRect(&ClipRect, originx, originy, patch, srcwidth, srcheight, step_x, step_y, rotate)) { @@ -378,7 +381,7 @@ void FBitmap::CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int int op = inf==NULL? OP_COPY : inf->op; for (int y=0;yblend) { - iCopyColors((BYTE*)penew, (const BYTE*)palette, 256, 4, inf); + iCopyColors((BYTE*)penew, (const BYTE*)palette, 256, 4, inf, 0, 0, 0); palette = penew; } diff --git a/src/textures/bitmap.h b/src/textures/bitmap.h index ef57f562db..b8494efaf0 100644 --- a/src/textures/bitmap.h +++ b/src/textures/bitmap.h @@ -157,7 +157,8 @@ public: virtual void CopyPixelDataRGB(int originx, int originy, const BYTE *patch, int srcwidth, - int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf = NULL); + int srcheight, int step_x, int step_y, int rotate, int ct, FCopyInfo *inf = NULL, + /* for PNG tRNS */ int r=0, int g=0, int b=0); virtual void CopyPixelData(int originx, int originy, const BYTE * patch, int srcwidth, int srcheight, int step_x, int step_y, int rotate, PalEntry * palette, FCopyInfo *inf = NULL); @@ -179,7 +180,16 @@ struct cRGB static __forceinline unsigned char R(const unsigned char * p) { return p[0]; } static __forceinline unsigned char G(const unsigned char * p) { return p[1]; } static __forceinline unsigned char B(const unsigned char * p) { return p[2]; } - static __forceinline unsigned char A(const unsigned char * p) { return 255; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return 255; } + static __forceinline int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; } +}; + +struct cRGBT +{ + static __forceinline unsigned char R(const unsigned char * p) { return p[0]; } + static __forceinline unsigned char G(const unsigned char * p) { return p[1]; } + static __forceinline unsigned char B(const unsigned char * p) { return p[2]; } + static __forceinline unsigned char A(const unsigned char * p, BYTE r, BYTE g, BYTE b) { return p[0] != r || p[1] != g || p[2] != b; } static __forceinline int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; } }; @@ -195,7 +205,7 @@ struct cRGBA static __forceinline unsigned char R(const unsigned char * p) { return p[0]; } static __forceinline unsigned char G(const unsigned char * p) { return p[1]; } static __forceinline unsigned char B(const unsigned char * p) { return p[2]; } - static __forceinline unsigned char A(const unsigned char * p) { return p[3]; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return p[3]; } static __forceinline int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; } }; @@ -204,7 +214,7 @@ struct cIA static __forceinline unsigned char R(const unsigned char * p) { return p[0]; } static __forceinline unsigned char G(const unsigned char * p) { return p[0]; } static __forceinline unsigned char B(const unsigned char * p) { return p[0]; } - static __forceinline unsigned char A(const unsigned char * p) { return p[1]; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return p[1]; } static __forceinline int Gray(const unsigned char * p) { return p[0]; } }; @@ -213,7 +223,7 @@ struct cCMYK static __forceinline unsigned char R(const unsigned char * p) { return p[3] - (((256-p[0])*p[3]) >> 8); } static __forceinline unsigned char G(const unsigned char * p) { return p[3] - (((256-p[1])*p[3]) >> 8); } static __forceinline unsigned char B(const unsigned char * p) { return p[3] - (((256-p[2])*p[3]) >> 8); } - static __forceinline unsigned char A(const unsigned char * p) { return 255; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return 255; } static __forceinline int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } }; @@ -222,7 +232,7 @@ struct cBGR static __forceinline unsigned char R(const unsigned char * p) { return p[2]; } static __forceinline unsigned char G(const unsigned char * p) { return p[1]; } static __forceinline unsigned char B(const unsigned char * p) { return p[0]; } - static __forceinline unsigned char A(const unsigned char * p) { return 255; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return 255; } static __forceinline int Gray(const unsigned char * p) { return (p[2]*77 + p[1]*143 + p[0]*36)>>8; } }; @@ -238,7 +248,7 @@ struct cBGRA static __forceinline unsigned char R(const unsigned char * p) { return p[2]; } static __forceinline unsigned char G(const unsigned char * p) { return p[1]; } static __forceinline unsigned char B(const unsigned char * p) { return p[0]; } - static __forceinline unsigned char A(const unsigned char * p) { return p[3]; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return p[3]; } static __forceinline int Gray(const unsigned char * p) { return (p[2]*77 + p[1]*143 + p[0]*36)>>8; } }; @@ -254,7 +264,7 @@ struct cARGB static __forceinline unsigned char R(const unsigned char * p) { return p[1]; } static __forceinline unsigned char G(const unsigned char * p) { return p[2]; } static __forceinline unsigned char B(const unsigned char * p) { return p[3]; } - static __forceinline unsigned char A(const unsigned char * p) { return p[0]; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return p[0]; } static __forceinline int Gray(const unsigned char * p) { return (p[1]*77 + p[2]*143 + p[3]*36)>>8; } }; @@ -263,7 +273,7 @@ struct cI16 static __forceinline unsigned char R(const unsigned char * p) { return p[1]; } static __forceinline unsigned char G(const unsigned char * p) { return p[1]; } static __forceinline unsigned char B(const unsigned char * p) { return p[1]; } - static __forceinline unsigned char A(const unsigned char * p) { return 255; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return 255; } static __forceinline int Gray(const unsigned char * p) { return p[1]; } }; @@ -272,7 +282,7 @@ struct cRGB555 static __forceinline unsigned char R(const unsigned char * p) { return (((*(WORD*)p)&0x1f)<<3); } static __forceinline unsigned char G(const unsigned char * p) { return (((*(WORD*)p)&0x3e0)>>2); } static __forceinline unsigned char B(const unsigned char * p) { return (((*(WORD*)p)&0x7c00)>>7); } - static __forceinline unsigned char A(const unsigned char * p) { return 255; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return 255; } static __forceinline int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } }; @@ -281,13 +291,14 @@ struct cPalEntry static __forceinline unsigned char R(const unsigned char * p) { return ((PalEntry*)p)->r; } static __forceinline unsigned char G(const unsigned char * p) { return ((PalEntry*)p)->g; } static __forceinline unsigned char B(const unsigned char * p) { return ((PalEntry*)p)->b; } - static __forceinline unsigned char A(const unsigned char * p) { return ((PalEntry*)p)->a; } + static __forceinline unsigned char A(const unsigned char * p, BYTE x, BYTE y, BYTE z) { return ((PalEntry*)p)->a; } static __forceinline int Gray(const unsigned char * p) { return (R(p)*77 + G(p)*143 + B(p)*36)>>8; } }; enum ColorType { CF_RGB, + CF_RGBT, CF_RGBA, CF_IA, CF_CMYK, diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 165e730a1c..7a7e4960d7 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -70,6 +70,8 @@ protected: BYTE BitDepth; BYTE ColorType; BYTE Interlace; + bool HaveTrans; + WORD NonPaletteTrans[3]; BYTE *PaletteMap; int PaletteSize; @@ -195,7 +197,7 @@ FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, BYTE depth, BYTE colortype, BYTE interlace) : FTexture(NULL, lumpnum), SourceFile(filename), Pixels(0), Spans(0), - BitDepth(depth), ColorType(colortype), Interlace(interlace), + BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false), PaletteMap(0), PaletteSize(0), StartOfIDAT(0) { union @@ -204,7 +206,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename BYTE pngpal[256][3]; } p; BYTE trans[256]; - bool havetRNS = false; DWORD len, id; int i; @@ -273,7 +274,11 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename case MAKE_ID('t','R','N','S'): lump.Read (trans, len); - havetRNS = true; + HaveTrans = true; + // Save for colortype 2 + NonPaletteTrans[0] = BigShort(((WORD *)trans)[0]); + NonPaletteTrans[1] = BigShort(((WORD *)trans)[1]); + NonPaletteTrans[2] = BigShort(((WORD *)trans)[2]); break; case MAKE_ID('a','l','P','h'): @@ -297,13 +302,13 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename case 0: // Grayscale if (!bAlphaTexture) { - if (colortype == 0 && havetRNS && trans[0] != 0) + if (colortype == 0 && HaveTrans && NonPaletteTrans[0] != 0 && NonPaletteTrans[0] < 256) { bMasked = true; PaletteSize = 256; PaletteMap = new BYTE[256]; memcpy (PaletteMap, GrayMap, 256); - PaletteMap[trans[0]] = 0; + PaletteMap[NonPaletteTrans[0]] = 0; } else { @@ -328,6 +333,10 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename case 6: // RGB + Alpha bMasked = true; break; + + case 2: // RGB + bMasked = HaveTrans; + break; } } @@ -521,7 +530,23 @@ void FPNGTexture::MakeTexture () { for (y = Height; y > 0; --y) { - *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; + if (!HaveTrans) + { + *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; + } + else + { + if (in[0] == NonPaletteTrans[0] && + in[1] == NonPaletteTrans[1] && + in[2] == NonPaletteTrans[2]) + { + *out++ = 0; + } + else + { + *out++ = RGB32k.RGB[in[0]>>3][in[1]>>3][in[2]>>3]; + } + } in += pitch; } in -= backstep; @@ -625,11 +650,14 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo break; case MAKE_ID('t','R','N','S'): - for(DWORD i = 0; i < len; i++) + if (ColorType == 3) { - (*lump) >> pe[i].a; - if (pe[i].a != 0 && pe[i].a != 255) - transpal = true; + for(DWORD i = 0; i < len; i++) + { + (*lump) >> pe[i].a; + if (pe[i].a != 0 && pe[i].a != 255) + transpal = true; + } } break; } @@ -639,6 +667,12 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo lump->Read(&id, 4); } + if (ColorType == 0 && HaveTrans && NonPaletteTrans[0] < 256) + { + pe[NonPaletteTrans[0]].a = 0; + transpal = true; + } + BYTE * Pixels = new BYTE[pixwidth * Height]; lump->Seek (StartOfIDAT, SEEK_SET); @@ -655,7 +689,15 @@ int FPNGTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCo break; case 2: - bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGB, inf); + if (!HaveTrans) + { + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGB, inf); + } + else + { + bmp->CopyPixelDataRGB(x, y, Pixels, Width, Height, 3, pixwidth, rotate, CF_RGBT, inf, + NonPaletteTrans[0], NonPaletteTrans[1], NonPaletteTrans[2]); + } break; case 4: From 450b6de384aae0d71d2bcfba6c967e57b37faed0 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 25 Jan 2016 21:31:21 -0600 Subject: [PATCH 5/8] cRGBT::A should return 255, not 1. Whoops. --- src/textures/bitmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textures/bitmap.h b/src/textures/bitmap.h index b8494efaf0..15a0ffc294 100644 --- a/src/textures/bitmap.h +++ b/src/textures/bitmap.h @@ -189,7 +189,7 @@ struct cRGBT static __forceinline unsigned char R(const unsigned char * p) { return p[0]; } static __forceinline unsigned char G(const unsigned char * p) { return p[1]; } static __forceinline unsigned char B(const unsigned char * p) { return p[2]; } - static __forceinline unsigned char A(const unsigned char * p, BYTE r, BYTE g, BYTE b) { return p[0] != r || p[1] != g || p[2] != b; } + static __forceinline unsigned char A(const unsigned char * p, BYTE r, BYTE g, BYTE b) { return (p[0] != r || p[1] != g || p[2] != b) ? 255 : 0; } static __forceinline int Gray(const unsigned char * p) { return (p[0]*77 + p[1]*143 + p[2]*36)>>8; } }; From 9f8dee45c49aca39323e41ebf98434114aa39236 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Mon, 25 Jan 2016 21:44:08 -0600 Subject: [PATCH 6/8] Fixed: 0 was accidentally not allowed as transparent for grayscale - I don't know what I was thinking when I wrote that. --- src/textures/pngtexture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 7a7e4960d7..5a3ae960a1 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -302,7 +302,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename case 0: // Grayscale if (!bAlphaTexture) { - if (colortype == 0 && HaveTrans && NonPaletteTrans[0] != 0 && NonPaletteTrans[0] < 256) + if (colortype == 0 && HaveTrans && NonPaletteTrans[0] < 256) { bMasked = true; PaletteSize = 256; From 623276f5a643fecd4f3a387dbbd8037dbc49a1d5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 26 Jan 2016 09:43:47 +0100 Subject: [PATCH 7/8] - fixed: All access to weapon info in DECORATE functions should be restricted to when they get called from an actual weapon, not from a CustomInventory item. Issues this fixes: * all original Doom attack functions unconditionally altered the flash state. * A_FireOldBFG, A_RailAttack and A_Blast never checked for a valid ReadyWeapon. * CustomInventory items could deplete an unrelated weapon's ammo. --- src/g_doom/a_doomweaps.cpp | 39 +++++++++++++++++-------------- src/g_hexen/a_blastradius.cpp | 4 ++-- src/thingdef/thingdef.h | 2 +- src/thingdef/thingdef_codeptr.cpp | 6 ++--- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/g_doom/a_doomweaps.cpp b/src/g_doom/a_doomweaps.cpp index 4021ad2061..283cf83233 100644 --- a/src/g_doom/a_doomweaps.cpp +++ b/src/g_doom/a_doomweaps.cpp @@ -36,7 +36,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Punch) if (self->player != NULL) { AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL && !(weapon->WeaponFlags & WIF_DEHAMMO)) + if (weapon != NULL && !(weapon->WeaponFlags & WIF_DEHAMMO) && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire)) return; @@ -73,7 +73,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FirePistol) if (self->player != NULL) { AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 1)) return; @@ -148,7 +148,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Saw) slope = P_AimLineAttack (self, angle, Range, &linetarget) + (pr_saw.Random2() * (Spread_Z / 255)); AWeapon *weapon = self->player->ReadyWeapon; - if ((weapon != NULL) && !(Flags & SF_NOUSEAMMO) && !(!linetarget && (Flags & SF_NOUSEAMMOMISS)) && !(weapon->WeaponFlags & WIF_DEHAMMO)) + if ((weapon != NULL) && !(Flags & SF_NOUSEAMMO) && !(!linetarget && (Flags & SF_NOUSEAMMOMISS)) && !(weapon->WeaponFlags & WIF_DEHAMMO) && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire)) return; @@ -250,7 +250,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireShotgun) S_Sound (self, CHAN_WEAPON, "weapons/shotgf", 1, ATTN_NORM); AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 1)) return; @@ -281,7 +281,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireShotgun2) S_Sound (self, CHAN_WEAPON, "weapons/sshotf", 1, ATTN_NORM); AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 2)) return; @@ -390,7 +390,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireCGun) } AWeapon *weapon = player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 1)) return; @@ -431,7 +431,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireMissile) return; } AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 1)) return; @@ -454,7 +454,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_FireSTGrenade) return; } AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire)) return; @@ -479,7 +479,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FirePlasma) return; } AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 1)) return; @@ -497,7 +497,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FirePlasma) // // [RH] A_FireRailgun // -static void FireRailgun(AActor *self, int offset_xy) +static void FireRailgun(AActor *self, int offset_xy, bool fromweapon) { int damage; player_t *player; @@ -508,7 +508,7 @@ static void FireRailgun(AActor *self, int offset_xy) } AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && fromweapon) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 1)) return; @@ -528,17 +528,17 @@ static void FireRailgun(AActor *self, int offset_xy) DEFINE_ACTION_FUNCTION(AActor, A_FireRailgun) { - FireRailgun(self, 0); + FireRailgun(self, 0, ACTION_CALL_FROM_WEAPON()); } DEFINE_ACTION_FUNCTION(AActor, A_FireRailgunRight) { - FireRailgun(self, 10); + FireRailgun(self, 10, ACTION_CALL_FROM_WEAPON()); } DEFINE_ACTION_FUNCTION(AActor, A_FireRailgunLeft) { - FireRailgun(self, -10); + FireRailgun(self, -10, ACTION_CALL_FROM_WEAPON()); } DEFINE_ACTION_FUNCTION(AActor, A_RailWait) @@ -560,7 +560,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireBFG) } AWeapon *weapon = self->player->ReadyWeapon; - if (weapon != NULL) + if (weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, deh.BFGCells)) return; @@ -671,6 +671,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireOldBFG) AActor * mo = NULL; player_t *player; + bool doesautoaim = false; if (NULL == (player = self->player)) { @@ -678,18 +679,20 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireOldBFG) } AWeapon *weapon = self->player->ReadyWeapon; + if (ACTION_CALL_FROM_WEAPON()) weapon = NULL; if (weapon != NULL) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 1)) return; + + doesautoaim = !(weapon->WeaponFlags & WIF_NOAUTOAIM); + weapon->WeaponFlags |= WIF_NOAUTOAIM; // No autoaiming that gun } self->player->extralight = 2; // Save values temporarily angle_t SavedPlayerAngle = self->angle; fixed_t SavedPlayerPitch = self->pitch; - bool doesautoaim = !(self->player->ReadyWeapon->WeaponFlags & WIF_NOAUTOAIM); - self->player->ReadyWeapon->WeaponFlags |= WIF_NOAUTOAIM; // No autoaiming that gun for (int i = 0; i < 2; i++) // Spawn two plasma balls in sequence { self->angle += ((pr_oldbfg()&127) - 64) * (ANG90/768); @@ -699,5 +702,5 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireOldBFG) self->angle = SavedPlayerAngle; self->pitch = SavedPlayerPitch; } - if (doesautoaim) self->player->ReadyWeapon->WeaponFlags &= ~WIF_NOAUTOAIM; // Restore autoaim setting + if (doesautoaim && weapon != NULL) weapon->WeaponFlags &= ~WIF_NOAUTOAIM; // Restore autoaim setting } diff --git a/src/g_hexen/a_blastradius.cpp b/src/g_hexen/a_blastradius.cpp index c7d962e124..bbd87c87d1 100644 --- a/src/g_hexen/a_blastradius.cpp +++ b/src/g_hexen/a_blastradius.cpp @@ -109,10 +109,10 @@ DEFINE_ACTION_FUNCTION_PARAMS (AActor, A_Blast) TThinkerIterator iterator; fixed_t dist; - if (self->player && (blastflags & BF_USEAMMO)) + if (self->player && (blastflags & BF_USEAMMO) && ACTION_CALL_FROM_WEAPON()) { AWeapon * weapon = self->player->ReadyWeapon; - if (!weapon->DepleteAmmo(weapon->bAltFire)) + if (weapon != NULL && !weapon->DepleteAmmo(weapon->bAltFire)) return; } diff --git a/src/thingdef/thingdef.h b/src/thingdef/thingdef.h index 5225b787a9..e60c746cde 100644 --- a/src/thingdef/thingdef.h +++ b/src/thingdef/thingdef.h @@ -382,7 +382,7 @@ struct StateCallData void AF_##name (AActor *self, AActor *stateowner, FState *, int, StateCallData *); \ static AFuncDesc info_##cls##_##name = { #name, AF_##name }; \ MSVC_ASEG AFuncDesc *infoptr_##cls##_##name GCC_ASEG = &info_##cls##_##name; \ - void AF_##name (AActor *self, AActor *stateowner, FState *, int, StateCallData *statecall) + void AF_##name (AActor *self, AActor *stateowner, FState *CallingState, int, StateCallData *statecall) #define DEFINE_ACTION_FUNCTION_PARAMS(cls, name) \ void AFP_##name (AActor *self, AActor *stateowner, FState *CallingState, int ParameterIndex, StateCallData *statecall); \ diff --git a/src/thingdef/thingdef_codeptr.cpp b/src/thingdef/thingdef_codeptr.cpp index 6926c1fac9..8ca30621b6 100644 --- a/src/thingdef/thingdef_codeptr.cpp +++ b/src/thingdef/thingdef_codeptr.cpp @@ -1261,7 +1261,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_FireBullets) int bslope = 0; int laflags = (flags & FBF_NORANDOMPUFFZ)? LAF_NORANDOMPUFFZ : 0; - if ((flags & FBF_USEAMMO) && weapon) + if ((flags & FBF_USEAMMO) && weapon && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo(weapon->bAltFire, true)) return; // out of ammo @@ -1450,7 +1450,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_CustomPunch) pitch = P_AimLineAttack (self, angle, range, &linetarget); // only use ammo when actually hitting something! - if ((flags & CPF_USEAMMO) && linetarget && weapon) + if ((flags & CPF_USEAMMO) && linetarget && weapon && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo(weapon->bAltFire, true)) return; // out of ammo @@ -1548,7 +1548,7 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_RailAttack) AWeapon *weapon = self->player->ReadyWeapon; // only use ammo when actually hitting something! - if (useammo) + if (useammo && weapon != NULL && ACTION_CALL_FROM_WEAPON()) { if (!weapon->DepleteAmmo(weapon->bAltFire, true)) return; // out of ammo From 4f0cfa29b466383de953be41adc7029e8baf6e01 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 26 Jan 2016 10:50:31 +0100 Subject: [PATCH 8/8] - missed a '!'. --- src/g_doom/a_doomweaps.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_doom/a_doomweaps.cpp b/src/g_doom/a_doomweaps.cpp index 283cf83233..1ff05a0f4f 100644 --- a/src/g_doom/a_doomweaps.cpp +++ b/src/g_doom/a_doomweaps.cpp @@ -679,7 +679,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireOldBFG) } AWeapon *weapon = self->player->ReadyWeapon; - if (ACTION_CALL_FROM_WEAPON()) weapon = NULL; + if (!ACTION_CALL_FROM_WEAPON()) weapon = NULL; if (weapon != NULL) { if (!weapon->DepleteAmmo (weapon->bAltFire, true, 1))