Added GravityModels, removed gravity switch
- Added GravityModel - can specify gravity varying by location and time - Added GravityModelRegistry - Stored in WorldData - Removed Minecraft gravity mode
This commit is contained in:
parent
fc85eb5658
commit
8c5493f78e
@ -41,6 +41,7 @@ import ru.windcorp.progressia.common.Units;
|
||||
import ru.windcorp.progressia.common.collision.Collideable;
|
||||
import ru.windcorp.progressia.common.collision.colliders.Collider;
|
||||
import ru.windcorp.progressia.common.util.FloatMathUtil;
|
||||
import ru.windcorp.progressia.common.util.Vectors;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||
import ru.windcorp.progressia.test.CollisionModelRenderer;
|
||||
import ru.windcorp.progressia.test.TestPlayerControls;
|
||||
@ -197,16 +198,18 @@ public class LayerWorld extends Layer {
|
||||
entity.getVelocity().mul((float) Math.exp(-FRICTION_COEFF / entity.getCollisionMass() * tickLength));
|
||||
}
|
||||
|
||||
private static final float MC_g = Units.get("32 m/s^2");
|
||||
private static final float IRL_g = Units.get("9.8 m/s^2");
|
||||
|
||||
private void tmp_applyGravity(EntityData entity, float tickLength) {
|
||||
if (ClientState.getInstance().getLocalPlayer().getEntity() == entity && tmp_testControls.isFlying()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final float gravitationalAcceleration = tmp_testControls.useMinecraftGravity() ? MC_g : IRL_g;
|
||||
entity.getVelocity().add(0, 0, -gravitationalAcceleration * tickLength);
|
||||
Vec3 gravitationalAcceleration = Vectors.grab3();
|
||||
ClientState.getInstance().getWorld().getData().getGravityModel().getGravity(gravitationalAcceleration);
|
||||
|
||||
gravitationalAcceleration.mul(tickLength);
|
||||
entity.getVelocity().add(gravitationalAcceleration);
|
||||
|
||||
Vectors.release(gravitationalAcceleration);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.common.world;
|
||||
|
||||
import glm.vec._3.Vec3;
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
||||
public abstract class GravityModel extends Namespaced {
|
||||
|
||||
public GravityModel(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Vec3 getGravity(Vec3 output) {
|
||||
if (output == null) {
|
||||
output = new Vec3();
|
||||
}
|
||||
|
||||
doGetGravity(output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
protected abstract void doGetGravity(Vec3 output);
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.common.world;
|
||||
|
||||
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
||||
|
||||
public class GravityModelRegistry extends NamespacedInstanceRegistry<GravityModel> {
|
||||
|
||||
public static final GravityModelRegistry INSTANCE = new GravityModelRegistry();
|
||||
|
||||
public static GravityModelRegistry getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
}
|
@ -51,6 +51,8 @@ public class WorldData
|
||||
private final TLongObjectMap<EntityData> entitiesById = TCollections.synchronizedMap(new TLongObjectHashMap<>());
|
||||
|
||||
private final Collection<EntityData> entities = Collections.unmodifiableCollection(entitiesById.valueCollection());
|
||||
|
||||
private GravityModel gravityModel = GravityModelRegistry.getInstance().get("Test:TheGravityModel");
|
||||
|
||||
private float time = 0;
|
||||
|
||||
@ -200,6 +202,20 @@ public class WorldData
|
||||
return null;
|
||||
return block.getCollisionModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the gravity model
|
||||
*/
|
||||
public GravityModel getGravityModel() {
|
||||
return gravityModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gravityModel the gravity model to set
|
||||
*/
|
||||
public void setGravityModel(GravityModel gravityModel) {
|
||||
this.gravityModel = gravityModel;
|
||||
}
|
||||
|
||||
public Collection<WorldDataListener> getListeners() {
|
||||
return listeners;
|
||||
|
@ -91,17 +91,6 @@ public class LayerTestGUI extends GUILayer {
|
||||
)
|
||||
);
|
||||
|
||||
panel.addChild(
|
||||
new Label(
|
||||
"GravityModeDisplay",
|
||||
font,
|
||||
tmp_dynFormat(
|
||||
"LayerTestGUI.GravityModeDisplay",
|
||||
() -> tpc.useMinecraftGravity() ? "Minecraft" : "Realistic"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
panel.addChild(
|
||||
new Label(
|
||||
"LanguageDisplay",
|
||||
|
@ -47,6 +47,7 @@ import ru.windcorp.progressia.common.collision.AABB;
|
||||
import ru.windcorp.progressia.common.collision.CollisionModel;
|
||||
import ru.windcorp.progressia.common.comms.controls.*;
|
||||
import ru.windcorp.progressia.common.state.StatefulObjectRegistry.Factory;
|
||||
import ru.windcorp.progressia.common.world.GravityModelRegistry;
|
||||
import ru.windcorp.progressia.common.world.block.*;
|
||||
import ru.windcorp.progressia.common.world.entity.*;
|
||||
import ru.windcorp.progressia.common.world.io.ChunkIO;
|
||||
@ -56,6 +57,7 @@ import ru.windcorp.progressia.server.comms.controls.*;
|
||||
import ru.windcorp.progressia.server.world.block.*;
|
||||
import ru.windcorp.progressia.server.world.entity.*;
|
||||
import ru.windcorp.progressia.server.world.tile.*;
|
||||
import ru.windcorp.progressia.test.gen.TestGravityModel;
|
||||
|
||||
public class TestContent {
|
||||
|
||||
@ -423,6 +425,7 @@ public class TestContent {
|
||||
private static void registerMisc() {
|
||||
ChunkIO.registerCodec(new TestChunkCodec());
|
||||
ChunkRenderOptimizerRegistry.getInstance().register("Core:SurfaceOptimizer", ChunkRenderOptimizerSurface::new);
|
||||
GravityModelRegistry.getInstance().register(new TestGravityModel());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,7 +83,6 @@ public class TestPlayerControls {
|
||||
private double lastSprintPress = Double.NEGATIVE_INFINITY;
|
||||
|
||||
private boolean captureMouse = true;
|
||||
private boolean useMinecraftGravity = false;
|
||||
|
||||
private int selectedBlock = 0;
|
||||
private int selectedTile = 0;
|
||||
@ -199,12 +198,6 @@ public class TestPlayerControls {
|
||||
handleCameraMode();
|
||||
break;
|
||||
|
||||
case GLFW.GLFW_KEY_G:
|
||||
if (!event.isPress())
|
||||
return false;
|
||||
handleGravitySwitch();
|
||||
break;
|
||||
|
||||
case GLFW.GLFW_KEY_L:
|
||||
if (!event.isPress())
|
||||
return false;
|
||||
@ -269,7 +262,7 @@ public class TestPlayerControls {
|
||||
return;
|
||||
}
|
||||
|
||||
getEntity().getVelocity().add(0, 0, JUMP_VELOCITY * (useMinecraftGravity ? 2 : 1));
|
||||
getEntity().getVelocity().add(0, 0, JUMP_VELOCITY);
|
||||
}
|
||||
|
||||
private void handleShift(int multiplier) {
|
||||
@ -313,11 +306,6 @@ public class TestPlayerControls {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleGravitySwitch() {
|
||||
useMinecraftGravity = !useMinecraftGravity;
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
private void handleLanguageSwitch() {
|
||||
Localizer localizer = Localizer.getInstance();
|
||||
if (localizer.getLanguage().equals("ru-RU")) {
|
||||
@ -427,10 +415,6 @@ public class TestPlayerControls {
|
||||
return captureMouse;
|
||||
}
|
||||
|
||||
public boolean useMinecraftGravity() {
|
||||
return useMinecraftGravity;
|
||||
}
|
||||
|
||||
public BlockData getSelectedBlock() {
|
||||
return TestContent.PLACEABLE_BLOCKS.get(selectedBlock);
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package ru.windcorp.progressia.test.gen;
|
||||
|
||||
import glm.vec._3.Vec3;
|
||||
import ru.windcorp.progressia.common.world.GravityModel;
|
||||
|
||||
public class TestGravityModel extends GravityModel {
|
||||
|
||||
public TestGravityModel() {
|
||||
super("Test:TheGravityModel");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGetGravity(Vec3 output) {
|
||||
output.set(0, 0, -9.8);
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,6 @@ LayerTestGUI.IsFlyingDisplay = Flying: %5s (Space bar x2)
|
||||
LayerTestGUI.IsSprintingDisplay = Sprinting: %5s (W x2)
|
||||
LayerTestGUI.IsMouseCapturedDisplay = Mouse captured: %5s (Esc)
|
||||
LayerTestGUI.CameraModeDisplay = Camera mode: %5d (F5)
|
||||
LayerTestGUI.GravityModeDisplay = Gravity: %9s (G)
|
||||
LayerTestGUI.LanguageDisplay = Language: %5s (L)
|
||||
LayerTestGUI.FPSDisplay = FPS:
|
||||
LayerTestGUI.TPSDisplay = TPS:
|
||||
|
@ -8,7 +8,6 @@ LayerTestGUI.IsFlyingDisplay = Полёт: %5s (Пробел x2)
|
||||
LayerTestGUI.IsSprintingDisplay = Бег: %5s (W x2)
|
||||
LayerTestGUI.IsMouseCapturedDisplay = Захват мыши: %5s (Esc)
|
||||
LayerTestGUI.CameraModeDisplay = Камера: %5d (F5)
|
||||
LayerTestGUI.GravityModeDisplay = Гравитация: %9s (G)
|
||||
LayerTestGUI.LanguageDisplay = Язык: %5s (L)
|
||||
LayerTestGUI.FPSDisplay = FPS:
|
||||
LayerTestGUI.TPSDisplay = TPS:
|
||||
|
Reference in New Issue
Block a user