1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 18:19:43 +01:00

Fix, for in-GAMEMODE sprites, their colors updating too fast

Okay, so the problem here is that Graphics::setcol() is called right
before a sprite is drawn in a render function, but render functions are
done in deltatime, meaning that the color of a sprite keeps being
recalculated every time. This only affects sprites that use fRandom()
(the other thing that can dynamically determine a color is help.glow,
but that's only updated in the fixed-timestep loop), but is especially
noticeable for sprites that flash wildly, like the teleporter, trinket,
and elephant.

To fix this, we need to make the color be recalculated only in the
fixed-timestep loop. However, this means that we MUST store the color of
the sprite SOMEWHERE for the delta-timesteps to render it, otherwise the
color calculation will just be lost or something.

So each entity now has a new attribute, `realcol`, which is the actual
raw color used to render the sprite in render functions. This is not to
be confused with their `colour` attribute, which is more akin to a color
"ID" of sorts, but which isn't an actual color.

At the end of gamelogic(), as well as when an entity is first created,
the `colour` is given to Graphics::setcol() and then `realcol` gets set
to the actual color. Then when it comes time to render the entity,
`realcol` gets used instead.

Gravitron squares are a somewhat tricky case where there's technically
TWO colors for it - one is the actual sprite itself and the other is the
indicator. However, usually the indicator and the square aren't both
onscreen at the same time, so we can simply switch the realcol between
the two as needed.

However, we can't use this system for the sprite colors used on the
title and map screen, so we'll have to do something else for those.
This commit is contained in:
Misa 2020-04-30 17:34:37 -07:00 committed by Ethan Lee
parent 4c2d219e45
commit 3699adec82
6 changed files with 82 additions and 23 deletions

View file

@ -53,6 +53,8 @@ entclass::entclass()
walkingframe = 0; walkingframe = 0;
dir = 0; dir = 0;
actionframe = 0; actionframe = 0;
realcol = 0;
} }
bool entclass::outside() bool entclass::outside()
@ -586,3 +588,50 @@ void entclass::settreadmillcolour( int rx, int ry )
break; break;
} }
} }
void entclass::updatecolour()
{
switch (size)
{
case 0: // Sprites
case 7: // Teleporter
case 9: // Really Big Sprite! (2x2)
case 10: // 2x1 Sprite
case 13: // Special for epilogue: huge hero!
graphics.setcol(colour);
realcol = graphics.ct.colour;
break;
case 3: // Big chunky pixels!
realcol = graphics.bigchunkygetcol(colour);
break;
case 4: // Small pickups
graphics.huetilesetcol(colour);
realcol = graphics.ct.colour;
break;
case 11: // The fucking elephant
if (game.noflashingmode)
{
graphics.setcol(22);
}
else
{
graphics.setcol(colour);
}
realcol = graphics.ct.colour;
break;
case 12: // Regular sprites that don't wrap
// if we're outside the screen, we need to draw indicators
if ((xp < -20 && vx > 0) || (xp > 340 && vx < 0))
{
graphics.setcol(23);
}
else
{
graphics.setcol(colour);
}
realcol = graphics.ct.colour;
break;
default:
break;
}
}

View file

@ -1,6 +1,8 @@
#ifndef ENT_H #ifndef ENT_H
#define ENT_H #define ENT_H
#include "Graphics.h"
#define rn( rx, ry) ((rx) + ((ry) * 100)) #define rn( rx, ry) ((rx) + ((ry) * 100))
class entclass class entclass
@ -16,6 +18,8 @@ public:
void settreadmillcolour(int rx, int ry); void settreadmillcolour(int rx, int ry);
void updatecolour();
public: public:
//Fundamentals //Fundamentals
bool invis; bool invis;
@ -45,6 +49,8 @@ public:
//Animation //Animation
int framedelay, drawframe, walkingframe, dir, actionframe; int framedelay, drawframe, walkingframe, dir, actionframe;
int yp;int xp; int yp;int xp;
Uint32 realcol;
}; };
#endif /* ENT_H */ #endif /* ENT_H */

View file

@ -2008,6 +2008,10 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
} }
entity.drawframe = entity.tile; entity.drawframe = entity.tile;
if (!entity.invis)
{
entity.updatecolour();
}
entities.push_back(entity); entities.push_back(entity);
} }

View file

@ -1488,8 +1488,6 @@ void Graphics::drawentities()
yoff = 0; yoff = 0;
} }
trinketcolset = false;
for (int i = obj.entities.size() - 1; i >= 0; i--) for (int i = obj.entities.size() - 1; i >= 0; i--)
{ {
if (obj.entities[i].invis) if (obj.entities[i].invis)
@ -1510,7 +1508,7 @@ void Graphics::drawentities()
} }
tpoint.x = xp; tpoint.x = xp;
tpoint.y = yp - yoff; tpoint.y = yp - yoff;
setcol(obj.entities[i].colour); setcolreal(obj.entities[i].realcol);
drawRect = sprites_rect; drawRect = sprites_rect;
drawRect.x += tpoint.x; drawRect.x += tpoint.x;
@ -1599,10 +1597,10 @@ void Graphics::drawentities()
case 3: // Big chunky pixels! case 3: // Big chunky pixels!
prect.x = xp; prect.x = xp;
prect.y = yp - yoff; prect.y = yp - yoff;
FillRect(backBuffer, prect, bigchunkygetcol(obj.entities[i].colour)); FillRect(backBuffer, prect, obj.entities[i].realcol);
break; break;
case 4: // Small pickups case 4: // Small pickups
huetilesetcol(obj.entities[i].colour); setcol(obj.entities[i].realcol);
drawhuetile(xp, yp - yoff, obj.entities[i].tile); drawhuetile(xp, yp - yoff, obj.entities[i].tile);
break; break;
case 5: //Horizontal Line case 5: //Horizontal Line
@ -1620,7 +1618,7 @@ void Graphics::drawentities()
drawgravityline(i); drawgravityline(i);
break; break;
case 7: //Teleporter case 7: //Teleporter
drawtele(xp, yp - yoff, obj.entities[i].drawframe, obj.entities[i].colour); drawtele(xp, yp - yoff, obj.entities[i].drawframe, obj.entities[i].realcol);
break; break;
//case 8: // Special: Moving platform, 8 tiles //case 8: // Special: Moving platform, 8 tiles
// Note: This code is in the 4-tile code // Note: This code is in the 4-tile code
@ -1630,7 +1628,7 @@ void Graphics::drawentities()
{ {
continue; continue;
} }
setcol(obj.entities[i].colour); setcolreal(obj.entities[i].realcol);
tpoint.x = xp; tpoint.x = xp;
tpoint.y = yp - yoff; tpoint.y = yp - yoff;
@ -1669,7 +1667,7 @@ void Graphics::drawentities()
{ {
continue; continue;
} }
setcol(obj.entities[i].colour); setcolreal(obj.entities[i].realcol);
tpoint.x = xp; tpoint.x = xp;
tpoint.y = yp - yoff; tpoint.y = yp - yoff;
@ -1688,14 +1686,7 @@ void Graphics::drawentities()
BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct); BlitSurfaceColoured((*spritesvec)[obj.entities[i].drawframe+1],NULL, backBuffer, &drawRect, ct);
break; break;
case 11: //The fucking elephant case 11: //The fucking elephant
if (game.noflashingmode) setcolreal(obj.entities[i].realcol);
{
setcol(22);
}
else
{
setcol(obj.entities[i].colour);
}
drawimagecol(3, xp, yp - yoff); drawimagecol(3, xp, yp - yoff);
break; break;
case 12: // Regular sprites that don't wrap case 12: // Regular sprites that don't wrap
@ -1705,7 +1696,7 @@ void Graphics::drawentities()
} }
tpoint.x = xp; tpoint.x = xp;
tpoint.y = yp - yoff; tpoint.y = yp - yoff;
setcol(obj.entities[i].colour); setcolreal(obj.entities[i].realcol);
// //
drawRect = sprites_rect; drawRect = sprites_rect;
drawRect.x += tpoint.x; drawRect.x += tpoint.x;
@ -1727,7 +1718,6 @@ void Graphics::drawentities()
} }
tpoint.y = tpoint.y+4; tpoint.y = tpoint.y+4;
setcol(23);
drawRect = tiles_rect; drawRect = tiles_rect;
@ -1748,7 +1738,6 @@ void Graphics::drawentities()
} }
tpoint.y = tpoint.y+4; tpoint.y = tpoint.y+4;
setcol(23);
// //
drawRect = tiles_rect; drawRect = tiles_rect;
@ -1766,7 +1755,7 @@ void Graphics::drawentities()
} }
tpoint.x = xp; tpoint.y = yp - yoff; tpoint.x = xp; tpoint.y = yp - yoff;
setcol(obj.entities[i].colour); setcolreal(obj.entities[i].realcol);
SDL_Rect drawRect = {Sint16(obj.entities[i].xp ), Sint16(obj.entities[i].yp - yoff), Sint16(sprites_rect.x * 6), Sint16(sprites_rect.y * 6 ) }; SDL_Rect drawRect = {Sint16(obj.entities[i].xp ), Sint16(obj.entities[i].yp - yoff), Sint16(sprites_rect.x * 6), Sint16(sprites_rect.y * 6 ) };
SDL_Surface* TempSurface = ScaleSurface( (*spritesvec)[obj.entities[i].drawframe], 6 * sprites_rect.w,6* sprites_rect.h ); SDL_Surface* TempSurface = ScaleSurface( (*spritesvec)[obj.entities[i].drawframe], 6 * sprites_rect.w,6* sprites_rect.h );
BlitSurfaceColoured(TempSurface, NULL , backBuffer, &drawRect, ct ); BlitSurfaceColoured(TempSurface, NULL , backBuffer, &drawRect, ct );
@ -2867,7 +2856,7 @@ void Graphics::bigrprint(int x, int y, std::string& t, int r, int g, int b, bool
} }
} }
void Graphics::drawtele(int x, int y, int t, int c) void Graphics::drawtele(int x, int y, int t, Uint32 c)
{ {
setcolreal(getRGB(16,16,16)); setcolreal(getRGB(16,16,16));
@ -2878,7 +2867,7 @@ void Graphics::drawtele(int x, int y, int t, int c)
BlitSurfaceColoured(tele[0], NULL, backBuffer, &telerect, ct); BlitSurfaceColoured(tele[0], NULL, backBuffer, &telerect, ct);
} }
setcol(c); setcolreal(c);
if (t > 9) t = 8; if (t > 9) t = 8;
if (t < 0) t = 0; if (t < 0) t = 0;

View file

@ -148,7 +148,7 @@ public:
void bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen = false, float sc = 2); void bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
void drawtele(int x, int y, int t, int c); void drawtele(int x, int y, int t, Uint32 c);
Uint32 getRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a); Uint32 getRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a);

View file

@ -1608,4 +1608,15 @@ void gamelogic()
graphics.linedelay--; graphics.linedelay--;
} }
} }
graphics.trinketcolset = false;
for (int i = obj.entities.size() - 1; i >= 0; i--)
{
if (obj.entities[i].invis)
{
continue;
}
obj.entities[i].updatecolour();
}
} }