Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes "predator" drawing effect. #998

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 64 additions & 21 deletions common/keybuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// distributed with this program. You should have received a copy of the
// GNU General Public License along with permitted additional restrictions
// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
#include "debugstring.h"
#include "graphicsviewport.h"
#include "keyframe.h"
#include "shape.h"
Expand All @@ -29,7 +30,10 @@ extern bool OriginalUseBigShapeBuffer;
// with the value PredTable[PredFrame] pixels away if PartialCount
// is greater than or equal to 256. After every pixel, it is increased by
// PartialPred and reset to % 256 after reaching 256 or greater.
static const short PredTable[8] = {1, 3, 2, 5, 2, 3, 4, 1};
static const short PredNegTable[8] = {-1, -3, -2, -5, -2, -3, -4, -1};
static short PredNegOffTable[8] = {0, 0, 0, 0, 0, 0, 0, 0};
static const short PredPosTable[8] = {1, 3, 2, 5, 2, 3, 4, 1};
static const short* PredTable = PredPosTable;
static unsigned PredFrame;
static unsigned PartialCount;
static unsigned PartialPred;
Expand Down Expand Up @@ -172,14 +176,17 @@ void BF_Fading(int width,
{
while (height--) {
for (int i = width; i > 0; --i) {
unsigned char sbyte = *src;
unsigned char sbyte = *src++;

for (int i = 0; i < count; ++i) {
sbyte = fade_tab[sbyte];
}

*dst++ = sbyte;
}

src += src_pitch;
dst += dst_pitch;
}
}

Expand Down Expand Up @@ -298,22 +305,19 @@ void BF_Predator(int width,
for (int i = width; i > 0; --i) {
PartialCount += PartialPred;

// if ( PartialCount & 0xFF00 ) {
// PartialCount &= 0xFFFF00FF;
if (PartialCount >= 256) {
PartialCount %= 256;

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
*dst = dst[PredTable[PredFrame]];
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

++dst;
}

src += src_pitch + width;
dst += dst_pitch;
}
}
Expand All @@ -340,9 +344,11 @@ void BF_Predator_Trans(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

*dst = sbyte;
Expand Down Expand Up @@ -377,9 +383,11 @@ void BF_Predator_Ghost(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

unsigned char fbyte = ghost_lookup[sbyte];
Expand Down Expand Up @@ -418,9 +426,11 @@ void BF_Predator_Ghost_Trans(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

unsigned char fbyte = ghost_lookup[sbyte];
Expand Down Expand Up @@ -461,9 +471,11 @@ void BF_Predator_Fading(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

for (int i = 0; i < count; ++i) {
Expand Down Expand Up @@ -497,9 +509,11 @@ void BF_Predator_Fading_Trans(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

for (int i = 0; i < count; ++i) {
Expand Down Expand Up @@ -539,9 +553,11 @@ void BF_Predator_Ghost_Fading(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

unsigned char fbyte = ghost_lookup[sbyte];
Expand Down Expand Up @@ -585,9 +601,11 @@ void BF_Predator_Ghost_Fading_Trans(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

unsigned char fbyte = ghost_lookup[sbyte];
Expand Down Expand Up @@ -858,7 +876,7 @@ void Single_Line_Predator(int width,
*dst = dst[PredTable[PredFrame]];
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

++dst;
Expand All @@ -883,9 +901,11 @@ void Single_Line_Predator_Trans(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

*dst = sbyte;
Expand All @@ -912,9 +932,11 @@ void Single_Line_Predator_Ghost(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

unsigned char fbyte = ghost_lookup[sbyte];
Expand Down Expand Up @@ -945,9 +967,11 @@ void Single_Line_Predator_Ghost_Trans(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

unsigned char fbyte = ghost_lookup[sbyte];
Expand Down Expand Up @@ -980,9 +1004,11 @@ void Single_Line_Predator_Fading(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

for (int i = 0; i < count; ++i) {
Expand Down Expand Up @@ -1011,9 +1037,11 @@ void Single_Line_Predator_Fading_Trans(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

for (int i = 0; i < count; ++i) {
Expand Down Expand Up @@ -1045,9 +1073,11 @@ void Single_Line_Predator_Ghost_Fading(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

unsigned char fbyte = ghost_lookup[sbyte];
Expand Down Expand Up @@ -1083,9 +1113,11 @@ void Single_Line_Predator_Ghost_Fading_Trans(int width,

if (&dst[PredTable[PredFrame]] < PredatorLimit) {
sbyte = dst[PredTable[PredFrame]];
} else {
sbyte = *dst;
}

PredFrame = (PredFrame + 2) % 8;
PredFrame = (PredFrame + 1) % 8;
}

unsigned char fbyte = ghost_lookup[sbyte];
Expand Down Expand Up @@ -1302,6 +1334,17 @@ void Buffer_Frame_To_Page(int x,
int current_frame = va_arg(ap, unsigned);
blit_style |= 8;

if (current_frame < 0) {

for (int i = 0; i < 8; ++i) {
PredNegOffTable[i] =
PredNegTable[i] + viewport.Get_XAdd() + viewport.Get_Width() + viewport.Get_Pitch();
}
PredTable = PredNegOffTable;
} else {
PredTable = PredPosTable;
}

PredFrame = ((unsigned)current_frame) % 8;
PartialCount = 0;
PartialPred = 256;
Expand Down
2 changes: 1 addition & 1 deletion redalert/conquer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3139,7 +3139,7 @@ void CC_Draw_Shape(void const* shapefile,

predoffset = Frame;

if (x > WindowList[window][WINDOWWIDTH]) {
if (x > WindowList[window][WINDOWWIDTH] >> 1) {
predoffset = -predoffset;
}

Expand Down
2 changes: 1 addition & 1 deletion tiberiandawn/conquer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@ void CC_Draw_Shape(void const* shapefile,

predoffset = Frame;

if (x > WindowList[window][WINDOWWIDTH]) {
if (x > WindowList[window][WINDOWWIDTH] >> 1) {
predoffset = -predoffset;
}

Expand Down
Loading