Enable falling through the planet

Falling through the planet basically behaves like falling through a
torus with a hole. There are no special visuals to it, it's basically
just teleporting to the other side of the planet and reversing the
vertical velocity.
master
Jeija 2016-09-09 11:04:42 +02:00
parent c754fed9fa
commit 529455f437
2 changed files with 17 additions and 3 deletions

View File

@ -326,6 +326,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("planet_keep_scale", "true");
settings->setDefault("planet_centrifugal_enable", "true");
settings->setDefault("planet_realistic_gravity", "false");
settings->setDefault("planet_fallthrough_enable", "true");
// IPv6
settings->setDefault("enable_ipv6", "true");

View File

@ -4229,11 +4229,13 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
void Game::handlePlanet(VolatileRunFlags *flags) {
LocalPlayer *player = client->getEnv().getLocalPlayer();
// Quick hack: Teleport to other side of planet at planet edges
if (g_settings->getBool("planet_enable")) {
// Round planet circumference up to even number of blocks, value in x/z coordinates
int planet_circumference = ceil(g_settings->getU16("planet_radius") * M_PI) * BS * MAP_BLOCKSIZE * 2;
int planet_radius = g_settings->getU16("planet_radius");
int planet_circumference = ceil(planet_radius * M_PI) * BS * MAP_BLOCKSIZE * 2;
v3f playerpos = player->getPosition();
// Teleport to other side of planet at planet edges
if (playerpos.X > planet_circumference / 2 - 0.5 * BS)
playerpos.X = -(float)planet_circumference / 2 - 0.5 * BS;
if (playerpos.X < -planet_circumference / 2 - 0.5 * BS)
@ -4243,8 +4245,19 @@ void Game::handlePlanet(VolatileRunFlags *flags) {
if (playerpos.Z < -planet_circumference / 2 - 0.5 * BS)
playerpos.Z = (float)planet_circumference / 2 - 0.5 * BS;
flags->planet_warp_changed = player->getPosition() != playerpos;
// Falling through the planet. The point on the other side is defined as
// pos.X += circumference / 2, as if the planet was a torus.
if (g_settings->getBool("planet_fallthrough_enable")) {
if (playerpos.Y < -planet_radius * MAP_BLOCKSIZE * BS) {
playerpos.Y = -planet_radius * MAP_BLOCKSIZE * BS + BS;
playerpos.X += planet_circumference / 2. * (playerpos.X < 0 ? 1 : -1);
v3f playerspeed = player->getSpeed();
playerspeed.Y *= -1;
player->setSpeed(playerspeed);
}
}
flags->planet_warp_changed = player->getPosition() != playerpos;
player->setPosition(playerpos);
}
}