Linked GravityModel to a WorldGenerator and added GM comms transfer
- WorldData no longer acquires a GravityModel automatically - On the server, GravityModel is specified by WorldGenerator - On the client, GravityModel is received from the server via a PacketSetGravityModel
This commit is contained in:
parent
d3c5011063
commit
d438d2aa14
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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 java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class PacketSetGravityModel extends PacketAffectWorld {
|
||||||
|
|
||||||
|
private String gravityModelId;
|
||||||
|
|
||||||
|
public PacketSetGravityModel() {
|
||||||
|
this("Core:SetGravityModel");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PacketSetGravityModel(String id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(GravityModel model) {
|
||||||
|
this.gravityModelId = model.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(DataInput input) throws IOException, DecodingException {
|
||||||
|
gravityModelId = input.readUTF();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(DataOutput output) throws IOException {
|
||||||
|
output.writeUTF(gravityModelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(WorldData world) {
|
||||||
|
GravityModel model = GravityModelRegistry.getInstance().get(gravityModelId);
|
||||||
|
world.setGravityModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.common.world;
|
package ru.windcorp.progressia.common.world;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -51,8 +51,8 @@ public class WorldData
|
|||||||
private final TLongObjectMap<EntityData> entitiesById = TCollections.synchronizedMap(new TLongObjectHashMap<>());
|
private final TLongObjectMap<EntityData> entitiesById = TCollections.synchronizedMap(new TLongObjectHashMap<>());
|
||||||
|
|
||||||
private final Collection<EntityData> entities = Collections.unmodifiableCollection(entitiesById.valueCollection());
|
private final Collection<EntityData> entities = Collections.unmodifiableCollection(entitiesById.valueCollection());
|
||||||
|
|
||||||
private GravityModel gravityModel = GravityModelRegistry.getInstance().get("Test:TheGravityModel");
|
private GravityModel gravityModel = null;
|
||||||
|
|
||||||
private float time = 0;
|
private float time = 0;
|
||||||
|
|
||||||
@ -202,18 +202,25 @@ public class WorldData
|
|||||||
return null;
|
return null;
|
||||||
return block.getCollisionModel();
|
return block.getCollisionModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the gravity model
|
* @return the gravity model
|
||||||
*/
|
*/
|
||||||
public GravityModel getGravityModel() {
|
public GravityModel getGravityModel() {
|
||||||
return gravityModel;
|
return gravityModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param gravityModel the gravity model to set
|
* @param gravityModel the gravity model to set
|
||||||
*/
|
*/
|
||||||
public void setGravityModel(GravityModel gravityModel) {
|
public void setGravityModel(GravityModel gravityModel) {
|
||||||
|
if (!chunks.isEmpty()) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Attempted to change gravity model to " + gravityModel + " while " + chunks.size()
|
||||||
|
+ " chunks were loaded"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.gravityModel = gravityModel;
|
this.gravityModel = gravityModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import gnu.trove.map.TIntObjectMap;
|
|||||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||||
import ru.windcorp.progressia.common.comms.CommsChannel.State;
|
import ru.windcorp.progressia.common.comms.CommsChannel.State;
|
||||||
import ru.windcorp.progressia.common.comms.packets.Packet;
|
import ru.windcorp.progressia.common.comms.packets.Packet;
|
||||||
|
import ru.windcorp.progressia.common.world.PacketSetGravityModel;
|
||||||
import ru.windcorp.progressia.common.world.PacketSetLocalPlayer;
|
import ru.windcorp.progressia.common.world.PacketSetLocalPlayer;
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||||
import ru.windcorp.progressia.server.Player;
|
import ru.windcorp.progressia.server.Player;
|
||||||
@ -73,6 +74,10 @@ public class ClientManager {
|
|||||||
|
|
||||||
private void addClientPlayer(ClientPlayer client) {
|
private void addClientPlayer(ClientPlayer client) {
|
||||||
String login = client.getLogin();
|
String login = client.getLogin();
|
||||||
|
|
||||||
|
PacketSetGravityModel setGravityModelPacket = new PacketSetGravityModel();
|
||||||
|
setGravityModelPacket.set(getServer().getWorld().getData().getGravityModel());
|
||||||
|
client.sendPacket(setGravityModelPacket);
|
||||||
|
|
||||||
EntityData entity = getServer().getPlayerManager().conjurePlayerEntity(login);
|
EntityData entity = getServer().getPlayerManager().conjurePlayerEntity(login);
|
||||||
Player player = new Player(entity, getServer(), client);
|
Player player = new Player(entity, getServer(), client);
|
||||||
|
@ -55,7 +55,9 @@ public class WorldLogic
|
|||||||
public WorldLogic(WorldData data, Server server, Function<WorldLogic, WorldGenerator> worldGeneratorConstructor) {
|
public WorldLogic(WorldData data, Server server, Function<WorldLogic, WorldGenerator> worldGeneratorConstructor) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
this.generator = worldGeneratorConstructor.apply(this);
|
this.generator = worldGeneratorConstructor.apply(this);
|
||||||
|
data.setGravityModel(getGenerator().getGravityModel());
|
||||||
|
|
||||||
data.addListener(new WorldDataListener() {
|
data.addListener(new WorldDataListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,14 +25,23 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
import ru.windcorp.progressia.common.world.DecodingException;
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
|
import ru.windcorp.progressia.common.world.GravityModel;
|
||||||
|
import ru.windcorp.progressia.common.world.GravityModelRegistry;
|
||||||
|
|
||||||
public abstract class AbstractWorldGenerator<H> extends WorldGenerator {
|
public abstract class AbstractWorldGenerator<H> extends WorldGenerator {
|
||||||
|
|
||||||
private final Class<H> hintClass;
|
private final Class<H> hintClass;
|
||||||
|
|
||||||
|
private final GravityModel gravityModel;
|
||||||
|
|
||||||
public AbstractWorldGenerator(String id, Class<H> hintClass) {
|
public AbstractWorldGenerator(String id, Class<H> hintClass, String gravityModelId) {
|
||||||
super(id);
|
super(id);
|
||||||
this.hintClass = Objects.requireNonNull(hintClass, "hintClass");
|
this.hintClass = Objects.requireNonNull(hintClass, "hintClass");
|
||||||
|
this.gravityModel = GravityModelRegistry.getInstance().get(Objects.requireNonNull(gravityModelId, "gravityModelId"));
|
||||||
|
|
||||||
|
if (this.gravityModel == null) {
|
||||||
|
throw new IllegalArgumentException("Gravity model with ID \"" + gravityModelId + "\" not found");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,5 +72,10 @@ public abstract class AbstractWorldGenerator<H> extends WorldGenerator {
|
|||||||
protected void setHint(ChunkData chunk, H hint) {
|
protected void setHint(ChunkData chunk, H hint) {
|
||||||
chunk.setGenerationHint(hint);
|
chunk.setGenerationHint(hint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GravityModel getGravityModel() {
|
||||||
|
return gravityModel;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import glm.vec._3.i.Vec3i;
|
|||||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
import ru.windcorp.progressia.common.world.DecodingException;
|
import ru.windcorp.progressia.common.world.DecodingException;
|
||||||
|
import ru.windcorp.progressia.common.world.GravityModel;
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
|
|
||||||
public abstract class WorldGenerator extends Namespaced {
|
public abstract class WorldGenerator extends Namespaced {
|
||||||
@ -42,5 +43,7 @@ public abstract class WorldGenerator extends Namespaced {
|
|||||||
public abstract void writeGenerationHint(DataOutputStream output, Object hint) throws IOException;
|
public abstract void writeGenerationHint(DataOutputStream output, Object hint) throws IOException;
|
||||||
|
|
||||||
public abstract boolean isChunkReady(Object hint);
|
public abstract boolean isChunkReady(Object hint);
|
||||||
|
|
||||||
|
public abstract GravityModel getGravityModel();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public class TestWorldGenerator extends AbstractWorldGenerator<Boolean> {
|
|||||||
private final TestTerrainGenerator terrainGen;
|
private final TestTerrainGenerator terrainGen;
|
||||||
|
|
||||||
public TestWorldGenerator(WorldLogic world) {
|
public TestWorldGenerator(WorldLogic world) {
|
||||||
super("Test:WorldGenerator", Boolean.class);
|
super("Test:WorldGenerator", Boolean.class, "Test:TheGravityModel");
|
||||||
this.terrainGen = new TestTerrainGenerator(this, world);
|
this.terrainGen = new TestTerrainGenerator(this, world);
|
||||||
|
|
||||||
world.getData().addListener(new WorldDataListener() {
|
world.getData().addListener(new WorldDataListener() {
|
||||||
|
Reference in New Issue
Block a user