From 65ebb1748961902c7e67319e52e3c78261c62b52 Mon Sep 17 00:00:00 2001 From: Justin Marshall Date: Mon, 3 Aug 2020 08:36:06 -0700 Subject: [PATCH] TS/RA2 SHP shadow support. --- code/redalert/bdata.cpp | 1 + code/redalert/building.cpp | 24 ++++++++++++++++++++++++ code/redalert/externs.h | 1 + code/redalert/globals.cpp | 1 + code/redalert/newblit.cpp | 4 ++-- code/redalert/shape.cpp | 9 +++++++++ code/redalert/type.h | 1 + code/redalert/winstub.cpp | 8 +++++++- rules.ini | 3 ++- 9 files changed, 48 insertions(+), 4 deletions(-) diff --git a/code/redalert/bdata.cpp b/code/redalert/bdata.cpp index 1da4f3d..45703f7 100644 --- a/code/redalert/bdata.cpp +++ b/code/redalert/bdata.cpp @@ -4084,6 +4084,7 @@ bool BuildingTypeClass::Read_INI(CCINIClass & ini) ActiveAnimAnimShape = MFCD::Retrieve(ConstructAnimName); } + IdleHasShadowFrames = ini.Get_Int(Name(), "IdleHasShadowFrames", 0); IdleAnimNonDamagedStart = ini.Get_Int(Name(), "IdleAnimNonDamagedStart", -1); IdleAnimNonDamagedFrames = ini.Get_Int(Name(), "IdleAnimNonDamagedFrames", -1); IdleAnimDamagedStart = ini.Get_Int(Name(), "IdleAnimDamagedStart", -1); diff --git a/code/redalert/building.cpp b/code/redalert/building.cpp index 6bb4c89..61f5598 100644 --- a/code/redalert/building.cpp +++ b/code/redalert/building.cpp @@ -528,6 +528,30 @@ void BuildingClass::Draw_It(int x, int y, WindowNumberType window) const CCGlobalOveridePalette = NULL; // jmarshall end + +// jmarshall - shadows are going to need to be done differently, but for now this will work. + if (Get_Build_TS_Shape(shapefile)) + { + CCGlobalShadowRender = true; + { + int shadowFrameOffset = Get_Build_Frame_Count(shapefile) / 2; + Techno_Draw_Object(shapefile, shadowFrameOffset + Shape_Number(), x, y, window); + } + if (Class->IdleHasShadowFrames && Class->IdleAnimShape != NULL) { + int shapeNum = animFrameNum; + int maxframes = Get_Build_Frame_Count(Class->IdleAnimShape); + if (Class->IdleAnimNonDamagedFrames != -1) { + maxframes = Class->IdleAnimNonDamagedFrames; + } + + shapeNum = shapeNum % maxframes; + int shadowFrameOffset = Get_Build_Frame_Count(Class->IdleAnimShape) / 2; + Techno_Draw_Object(Class->IdleAnimShape, shadowFrameOffset + shapeNum, x, y, window); + } + CCGlobalShadowRender = false; + } +// jmarshall end + IsTheaterShape = false; /* diff --git a/code/redalert/externs.h b/code/redalert/externs.h index 9d56160..8271d0a 100644 --- a/code/redalert/externs.h +++ b/code/redalert/externs.h @@ -322,6 +322,7 @@ extern int ScenarioInit; extern HouseClass * PlayerPtr; extern PaletteClass CCPalette; extern void* CCGlobalOveridePalette; +extern bool CCGlobalShadowRender; extern int CCPaletteHouseColor; extern HSVClass HSVColors[8]; extern PaletteClass BlackPalette; diff --git a/code/redalert/globals.cpp b/code/redalert/globals.cpp index de208a7..4648741 100644 --- a/code/redalert/globals.cpp +++ b/code/redalert/globals.cpp @@ -551,6 +551,7 @@ HouseClass * PlayerPtr; */ PaletteClass CCPalette; void* CCGlobalOveridePalette = NULL; +bool CCGlobalShadowRender = false; int CCPaletteHouseColor = 0; PaletteClass GamePalette; //PaletteClass InGamePalette; diff --git a/code/redalert/newblit.cpp b/code/redalert/newblit.cpp index 9bf94ba..be8c622 100644 --- a/code/redalert/newblit.cpp +++ b/code/redalert/newblit.cpp @@ -36,8 +36,8 @@ static void GL_EnableBlendCallback(const ImDrawList* parent_list, const ImDrawCm glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR); } else { - glBlendEquation(GL_MULT); - glBlendFunc(GL_DST_COLOR, GL_ZERO); + //glBlendEquation(GL_MULT); + glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); } } diff --git a/code/redalert/shape.cpp b/code/redalert/shape.cpp index c9997f1..bc16ae2 100644 --- a/code/redalert/shape.cpp +++ b/code/redalert/shape.cpp @@ -427,6 +427,11 @@ long Buffer_Frame_To_Page(int shapeNum, int x, int y, int width, int height, str // // return 0; //} + + if(CCGlobalShadowRender) { + GL_EnableBlend(GL_BLEND_MULT); + } + xstart = xstart + WindowList[Window][WINDOWX];// + LogicPage->Get_XPos(); ystart = ystart + WindowList[Window][WINDOWY];// + LogicPage->Get_YPos(); //GL_SetClipRect(WindowList[Window][WINDOWX], WindowList[Window][WINDOWY], WindowList[Window][WINDOWWIDTH], WindowList[Window][WINDOWWIDTH]); @@ -435,6 +440,10 @@ long Buffer_Frame_To_Page(int shapeNum, int x, int y, int width, int height, str else GL_RenderImage(shape_image, xstart, ystart, width, height, 0); + if (CCGlobalShadowRender) { + GL_EnableBlend(GL_BLEND_NONE); + } + // Here we just use the function that will blit the entire frame // using the appropriate effects. //if (blit_height > 0 && blit_width > 0) { diff --git a/code/redalert/type.h b/code/redalert/type.h index cc4e31c..482bdd4 100644 --- a/code/redalert/type.h +++ b/code/redalert/type.h @@ -821,6 +821,7 @@ class BuildingTypeClass : public TechnoTypeClass { const void* CustomTheatrePalette[3]; const void* IdleAnimShape; const void* ActiveAnimAnimShape; + int IdleHasShadowFrames; int IdleAnimNonDamagedStart; int IdleAnimNonDamagedFrames; int IdleAnimDamagedStart; diff --git a/code/redalert/winstub.cpp b/code/redalert/winstub.cpp index 94661e9..cb8bcfa 100644 --- a/code/redalert/winstub.cpp +++ b/code/redalert/winstub.cpp @@ -510,7 +510,13 @@ Image_t* Image_CreateImageFrom8Bit(const char* name, int Width, int Height, unsi unsigned char b = 0; unsigned char a = 0; - if (CCGlobalOveridePalette && remap) { + if (CCGlobalShadowRender && c != 0) { + r = 120; + g = 120; + b = 120; + a = 120; + } + else if (CCGlobalOveridePalette && remap) { r = ccpalete[(c * 3) + 0] << 2; g = ccpalete[(c * 3) + 1] << 2; b = ccpalete[(c * 3) + 2] << 2; diff --git a/rules.ini b/rules.ini index 318dea8..243ec77 100644 --- a/rules.ini +++ b/rules.ini @@ -1431,7 +1431,7 @@ ActiveAnimNonDamagedFrames=41 ActiveAnimDamagedStart=0 ActiveAnimDamagedFrames=41 -; Tesla coil +; Pirsm Tower [GGPRIS] Primary=TeslaZap Strength=400 @@ -1454,6 +1454,7 @@ IdleAnimNonDamagedStart=0 IdleAnimNonDamagedFrames=8 IdleAnimDamagedStart=9 IdleAnimDamagedFrames=8 +IdleHasShadowFrames=1 ActiveAnimNonDamagedStart=0 ActiveAnimNonDamagedFrames=9 ActiveAnimDamagedStart=10