mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Prevent removing the player entity
Removing the player entity has all sorts of nasty effects, such as softlocking the game because many inputs require there to be a player present, such as opening the quit menu. The most infamous glitch to remove the player entity is the Gravitron Fling, where the game doesn't see a gravity line at a specific y-position in the current room, and when it moves the bottom gravity line it moves the player instead. When the gravity line gets outside the room, it gets destroyed, so if the player gets dragged outside the room, they get destroyed, too. (Don't misinterpret this as saying anytime the player gets dragged outside the room, they get destroyed - it's only the Gravitron logic that destroys them.) Also, there are many places in the code that use entity-getting functions that have a fallback value of 0. If it was possible to remove the player, then it's possible for this fallback value of 0 to index obj.entities out-of-bounds, which is not good. To fix this, entityclass::removeentity() is now a bool that signifies if the entity was successfully removed or not. If the entity given is the player (meaning it first checks if it's rule 0, just so in 99% of cases it'll short-circuit and won't do the next check, which is if entityclass::getplayer() says the indice to be removed is the player), then it'll refuse to remove the entity, and return false. This is a change in behavior where callers might expect entityclass::removeentity() to always succeed, so I changed the removeentity_iter() macro to only decrement if removing the entity succeeded. I also changed entityclass::updateentities() from 'removeentity(i); return true;' to 'return removeentity(i);'.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#define removeentity_iter(index) { obj.removeentity(index); index--; }
|
||||
#define removeentity_iter(index) { if (obj.removeentity(index)) index--; }
|
||||
#define removeblock_iter(index) { obj.removeblock(index); index--; }
|
||||
|
||||
enum
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
|
||||
void createblock(int t, int xp, int yp, int w, int h, int trig = 0);
|
||||
|
||||
void removeentity(int t);
|
||||
bool removeentity(int t);
|
||||
|
||||
void removeallblocks();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user