1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-28 23:48:30 +02:00

Initialize oldxp/oldyp in createentity()

This prevents undefined behavior because we use oldxp/oldyp to do linear
interpolation.

It's also initialized in entclass::entclass(), just to be sure. And I've
deduplicated the regular xp/yp initialization in createentity(), too.
This commit is contained in:
Misa 2020-04-28 16:17:10 -07:00 committed by Ethan Lee
parent 4f4d400ce0
commit c6659ef656
2 changed files with 13 additions and 66 deletions

View File

@ -27,6 +27,8 @@ entclass::entclass()
cy = 0; cy = 0;
newxp = 0; newxp = 0;
newyp = 0; newyp = 0;
oldxp = 0;
oldyp = 0;
x1 = 0; x1 = 0;
y1 = 0; y1 = 0;
@ -99,6 +101,7 @@ void entclass::setenemy( int t )
else if ( (para) == 1) else if ( (para) == 1)
{ {
yp += 10; yp += 10;
oldyp += 10;
tile = 63; tile = 63;
animate = 100; //LIES animate = 100; //LIES
colour = 6; colour = 6;
@ -138,7 +141,9 @@ void entclass::setenemy( int t )
else if ( (para) == 1) else if ( (para) == 1)
{ {
xp += 4; xp += 4;
oldxp += 4;
yp -= 4; yp -= 4;
oldyp -= 4;
tile = 76; tile = 76;
animate = 100; // Clouds animate = 100; // Clouds
colour = 6; colour = 6;

View File

@ -1163,6 +1163,10 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
//Rule 6 is a crew member //Rule 6 is a crew member
entclass entity; entclass entity;
entity.xp = xp;
entity.yp = yp;
entity.oldxp = xp;
entity.oldyp = yp;
entity.type = t; entity.type = t;
switch(t) switch(t)
{ {
@ -1170,8 +1174,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.rule = 0; //Playable character entity.rule = 0; //Playable character
entity.tile = 0; entity.tile = 0;
entity.colour = 0; entity.colour = 0;
entity.xp = xp;
entity.yp = yp;
entity.cx = 6; entity.cx = 6;
entity.cy = 2; entity.cy = 2;
entity.w = 12; entity.w = 12;
@ -1184,8 +1186,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
break; break;
case 1: //Simple enemy, bouncing off the walls case 1: //Simple enemy, bouncing off the walls
entity.rule = 1; entity.rule = 1;
entity.xp = xp;
entity.yp = yp;
entity.behave = vx; entity.behave = vx;
entity.para = vy; entity.para = vy;
entity.w = 16; entity.w = 16;
@ -1248,8 +1248,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
if (gridmatch(p1, p2, p3, p4, -32, -40, 352, 264)) entity.tile = 27; if (gridmatch(p1, p2, p3, p4, -32, -40, 352, 264)) entity.tile = 27;
} }
entity.xp = xp;
entity.yp = yp;
entity.w = 32; entity.w = 32;
entity.h = 8; entity.h = 8;
@ -1318,8 +1316,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
if (game.roomx == 50 && game.roomy == 52) entity.tile = 22; if (game.roomx == 50 && game.roomy == 52) entity.tile = 22;
} }
entity.xp = xp;
entity.yp = yp;
entity.cy = -1; entity.cy = -1;
entity.w = 32; entity.w = 32;
entity.h = 10; entity.h = 10;
@ -1335,8 +1331,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 3; entity.type = 3;
entity.size = 1; entity.size = 1;
entity.tile = 10; entity.tile = 10;
entity.xp = xp;
entity.yp = yp;
entity.cy = -1; entity.cy = -1;
entity.w = 8; entity.w = 8;
entity.h = 10; entity.h = 10;
@ -1352,8 +1346,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 4; entity.type = 4;
entity.size = 0; entity.size = 0;
entity.tile = 11; entity.tile = 11;
entity.xp = xp;
entity.yp = yp;
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.behave = vx; entity.behave = vx;
@ -1366,8 +1358,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 5; //Particles entity.type = 5; //Particles
entity.colour = 1; entity.colour = 1;
entity.size = 3; entity.size = 3;
entity.xp = xp;
entity.yp = yp;
entity.vx = vx; entity.vx = vx;
entity.vy = vy; entity.vy = vy;
@ -1378,8 +1368,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 5; //Particles entity.type = 5; //Particles
entity.colour = 2; entity.colour = 2;
entity.size = 3; entity.size = 3;
entity.xp = xp;
entity.yp = yp;
entity.vx = vx; entity.vx = vx;
entity.vy = vy; entity.vy = vy;
@ -1390,8 +1378,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 6; entity.type = 6;
entity.size = 4; entity.size = 4;
entity.tile = 48; entity.tile = 48;
entity.xp = xp;
entity.yp = yp;
entity.w = 8; entity.w = 8;
entity.h = 8; entity.h = 8;
entity.onentity = 1; entity.onentity = 1;
@ -1406,8 +1392,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 7; entity.type = 7;
entity.size = 0; entity.size = 0;
entity.tile = 22; entity.tile = 22;
entity.xp = xp;
entity.yp = yp;
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.colour = 3; entity.colour = 3;
@ -1423,8 +1407,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 8; entity.type = 8;
entity.size = 0; entity.size = 0;
entity.tile = 20 + vx; entity.tile = 20 + vx;
entity.xp = xp;
entity.yp = yp;
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.colour = 4; entity.colour = 4;
@ -1448,8 +1430,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 9; entity.type = 9;
entity.size = 5; entity.size = 5;
entity.life = 0; entity.life = 0;
entity.xp = xp;
entity.yp = yp;
entity.w = vx; entity.w = vx;
entity.h = 1; entity.h = 1;
entity.onentity = 1; entity.onentity = 1;
@ -1459,8 +1439,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 10; entity.type = 10;
entity.size = 6; entity.size = 6;
entity.life = 0; entity.life = 0;
entity.xp = xp;
entity.yp = yp;
entity.w = 1; entity.w = 1;
entity.h = vx; entity.h = vx;
//entity.colour = 0; //entity.colour = 0;
@ -1471,8 +1449,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 11; entity.type = 11;
entity.size = 0; entity.size = 0;
entity.tile = 18; entity.tile = 18;
entity.xp = xp;
entity.yp = yp;
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.colour = 10; entity.colour = 10;
@ -1487,8 +1463,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 100; entity.type = 100;
entity.size = 7; entity.size = 7;
entity.tile = 1; //inactive entity.tile = 1; //inactive
entity.xp = xp;
entity.yp = yp;
entity.w = 96; entity.w = 96;
entity.h = 96; entity.h = 96;
entity.colour = 100; entity.colour = 100;
@ -1501,8 +1475,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 12; //A special case! entity.type = 12; //A special case!
entity.tile = 144; entity.tile = 144;
entity.colour = 13; //144 for sad :( entity.colour = 13; //144 for sad :(
entity.xp = xp;
entity.yp = yp;
entity.cx = 6; entity.cx = 6;
entity.cy = 2; entity.cy = 2;
entity.w = 12; entity.w = 12;
@ -1518,8 +1490,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 12; //A special case! entity.type = 12; //A special case!
entity.tile = 144+6; entity.tile = 144+6;
entity.colour = 14; //144 for sad (upside down+12):( entity.colour = 14; //144 for sad (upside down+12):(
entity.xp = xp;
entity.yp = yp;
entity.cx = 6; entity.cx = 6;
entity.cy = 2; entity.cy = 2;
entity.w = 12; entity.w = 12;
@ -1535,8 +1505,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 12; //A special case! entity.type = 12; //A special case!
entity.tile = 144; entity.tile = 144;
entity.colour = 16; //144 for sad :( entity.colour = 16; //144 for sad :(
entity.xp = xp;
entity.yp = yp;
entity.cx = 6; entity.cx = 6;
entity.cy = 2; entity.cy = 2;
entity.w = 12; entity.w = 12;
@ -1560,8 +1528,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
{ {
entity.tile = 144; entity.tile = 144;
} }
entity.xp = xp;
entity.yp = yp;
entity.cx = 6; entity.cx = 6;
entity.cy = 2; entity.cy = 2;
entity.w = 12; entity.w = 12;
@ -1583,8 +1549,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 12; //A special case! entity.type = 12; //A special case!
entity.tile = 0; entity.tile = 0;
entity.colour = 6; //54 for sad :( entity.colour = 6; //54 for sad :(
entity.xp = xp;
entity.yp = yp;
entity.cx = 6; entity.cx = 6;
entity.cy = 2; entity.cy = 2;
entity.w = 12; entity.w = 12;
@ -1600,8 +1564,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 13; entity.type = 13;
entity.size = 0; entity.size = 0;
entity.tile = 16 + vx; entity.tile = 16 + vx;
entity.xp = xp;
entity.yp = yp;
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.colour = 4; entity.colour = 4;
@ -1614,8 +1576,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 13; entity.type = 13;
entity.size = 0; entity.size = 0;
entity.tile = 16 + vx; entity.tile = 16 + vx;
entity.xp = xp;
entity.yp = yp;
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.colour = 4; entity.colour = 4;
@ -1628,8 +1588,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 7; entity.type = 7;
entity.size = 0; entity.size = 0;
entity.tile = 22; entity.tile = 22;
entity.xp = xp;
entity.yp = yp;
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.colour = 3; entity.colour = 3;
@ -1644,8 +1602,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
//Given a different behavior, these enemies are especially for SWN mode and disappear outside the screen. //Given a different behavior, these enemies are especially for SWN mode and disappear outside the screen.
entity.rule = 1; entity.rule = 1;
entity.type = 23; entity.type = 23;
entity.xp = xp;
entity.yp = yp;
entity.behave = vx; entity.behave = vx;
entity.para = vy; entity.para = vy;
entity.w = 16; entity.w = 16;
@ -1693,8 +1649,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
{ {
entity.tile = 144; entity.tile = 144;
} }
entity.xp = xp;
entity.yp = yp;
entity.cx = 6; entity.cx = 6;
entity.cy = 2; entity.cy = 2;
entity.w = 12; entity.w = 12;
@ -1720,8 +1674,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.rule = 3; entity.rule = 3;
entity.type = 15; entity.type = 15;
entity.size = 0; entity.size = 0;
entity.xp = xp;
entity.yp = yp;
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.colour = 4; entity.colour = 4;
@ -1897,8 +1849,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 11; entity.type = 11;
entity.size = 0; entity.size = 0;
entity.tile = 18; entity.tile = 18;
entity.xp = (xp);
entity.yp = (yp);
entity.w = 16; entity.w = 16;
entity.h = 16; entity.h = 16;
entity.colour = 3; entity.colour = 3;
@ -1913,8 +1863,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 51; entity.type = 51;
entity.size = 6; entity.size = 6;
entity.life = 0; entity.life = 0;
entity.xp = xp;
entity.yp = yp;
entity.w = 1; entity.w = 1;
entity.h = vx; entity.h = vx;
//entity.colour = 0; //entity.colour = 0;
@ -1927,8 +1875,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 52; entity.type = 52;
entity.size = 6; entity.size = 6;
entity.life = 0; entity.life = 0;
entity.xp = xp;
entity.yp = yp;
entity.w = 1; entity.w = 1;
entity.h = vx; entity.h = vx;
//entity.colour = 0; //entity.colour = 0;
@ -1941,8 +1887,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 53; entity.type = 53;
entity.size = 5; entity.size = 5;
entity.life = 0; entity.life = 0;
entity.xp = xp;
entity.yp = yp;
entity.w = vx; entity.w = vx;
entity.h = 1; entity.h = 1;
entity.onentity = 1; entity.onentity = 1;
@ -1954,8 +1898,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.type = 54; entity.type = 54;
entity.size = 5; entity.size = 5;
entity.life = 0; entity.life = 0;
entity.xp = xp;
entity.yp = yp;
entity.w = vx; entity.w = vx;
entity.h = 1; entity.h = 1;
entity.onentity = 1; entity.onentity = 1;
@ -1973,8 +1915,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
entity.tile = 0; entity.tile = 0;
} }
entity.colour = crewcolour(int(vy)); entity.colour = crewcolour(int(vy));
entity.xp = xp;
entity.yp = yp;
entity.cx = 6; entity.cx = 6;
entity.cy = 2; entity.cy = 2;
entity.w = 12; entity.w = 12;
@ -1994,8 +1934,6 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo
case 56: //Custom enemy case 56: //Custom enemy
entity.rule = 1; entity.rule = 1;
entity.type = 1; entity.type = 1;
entity.xp = xp;
entity.yp = yp;
entity.behave = vx; entity.behave = vx;
entity.para = vy; entity.para = vy;
entity.w = 16; entity.w = 16;
@ -2380,17 +2318,20 @@ bool entityclass::updateentities( int i )
{ {
entities[i].tile = 120; entities[i].tile = 120;
entities[i].yp = (28*8)-62; entities[i].yp = (28*8)-62;
entities[i].oldyp = (28*8)-62;
} }
else else
{ {
entities[i].tile = 96; entities[i].tile = 96;
entities[i].yp = 24; entities[i].yp = 24;
entities[i].oldyp = 24;
} }
//now, x position //now, x position
if (player > -1 && entities[player].xp > 20 * 8) if (player > -1 && entities[player].xp > 20 * 8)
{ {
//approach from the left //approach from the left
entities[i].xp = -64; entities[i].xp = -64;
entities[i].oldxp = -64;
entities[i].state = 2; entities[i].state = 2;
bool entitygone = updateentities(i); //right bool entitygone = updateentities(i); //right
if (entitygone) return true; if (entitygone) return true;
@ -2399,6 +2340,7 @@ bool entityclass::updateentities( int i )
{ {
//approach from the left //approach from the left
entities[i].xp = 320; entities[i].xp = 320;
entities[i].oldxp = 320;
entities[i].state = 3; entities[i].state = 3;
bool entitygone = updateentities(i); //left bool entitygone = updateentities(i); //left
if (entitygone) return true; if (entitygone) return true;