Im tired i need sleep
-Added listeners for saving and loading chunks -Made loading screens for between title and game(they dont work yet) -Added localized text(some) -Safeish deletion and saving of chunks -It still keeps them in memory I think so this needs work too
This commit is contained in:
parent
53f72b068a
commit
94db44e443
@ -20,14 +20,6 @@ package ru.windcorp.progressia;
|
|||||||
|
|
||||||
import ru.windcorp.progressia.client.ClientProxy;
|
import ru.windcorp.progressia.client.ClientProxy;
|
||||||
import ru.windcorp.progressia.client.graphics.GUI;
|
import ru.windcorp.progressia.client.graphics.GUI;
|
||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsBackend;
|
|
||||||
import ru.windcorp.progressia.client.graphics.backend.RenderTaskQueue;
|
|
||||||
import ru.windcorp.progressia.client.graphics.flat.FlatRenderProgram;
|
|
||||||
import ru.windcorp.progressia.client.graphics.font.GNUUnifontLoader;
|
|
||||||
import ru.windcorp.progressia.client.graphics.font.Typefaces;
|
|
||||||
import ru.windcorp.progressia.client.graphics.world.WorldRenderProgram;
|
|
||||||
import ru.windcorp.progressia.client.localization.Localizer;
|
|
||||||
import ru.windcorp.progressia.common.resource.ResourceManager;
|
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
import ru.windcorp.progressia.common.util.crash.analyzers.OutOfMemoryAnalyzer;
|
import ru.windcorp.progressia.common.util.crash.analyzers.OutOfMemoryAnalyzer;
|
||||||
import ru.windcorp.progressia.common.util.crash.providers.*;
|
import ru.windcorp.progressia.common.util.crash.providers.*;
|
||||||
|
@ -18,12 +18,19 @@
|
|||||||
|
|
||||||
package ru.windcorp.progressia.client;
|
package ru.windcorp.progressia.client;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
||||||
import ru.windcorp.progressia.client.graphics.GUI;
|
import ru.windcorp.progressia.client.graphics.GUI;
|
||||||
|
import ru.windcorp.progressia.client.graphics.Layer;
|
||||||
import ru.windcorp.progressia.client.graphics.world.LayerWorld;
|
import ru.windcorp.progressia.client.graphics.world.LayerWorld;
|
||||||
|
import ru.windcorp.progressia.client.localization.MutableString;
|
||||||
|
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
||||||
import ru.windcorp.progressia.common.world.WorldData;
|
import ru.windcorp.progressia.common.world.WorldData;
|
||||||
import ru.windcorp.progressia.server.ServerState;
|
import ru.windcorp.progressia.server.ServerState;
|
||||||
import ru.windcorp.progressia.test.LayerAbout;
|
import ru.windcorp.progressia.test.LayerAbout;
|
||||||
|
import ru.windcorp.progressia.test.LayerTestText;
|
||||||
import ru.windcorp.progressia.test.LayerTestUI;
|
import ru.windcorp.progressia.test.LayerTestUI;
|
||||||
import ru.windcorp.progressia.test.TestContent;
|
import ru.windcorp.progressia.test.TestContent;
|
||||||
|
|
||||||
@ -31,6 +38,11 @@ public class ClientState {
|
|||||||
|
|
||||||
private static Client instance;
|
private static Client instance;
|
||||||
|
|
||||||
|
private static Collection<Layer> layers;
|
||||||
|
|
||||||
|
private static boolean firstLoad;
|
||||||
|
private static LayerTestText layer;
|
||||||
|
|
||||||
public static Client getInstance() {
|
public static Client getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
@ -47,16 +59,51 @@ public class ClientState {
|
|||||||
ServerState.getInstance()
|
ServerState.getInstance()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
firstLoad = true;
|
||||||
|
|
||||||
Client client = new Client(world, channel);
|
Client client = new Client(world, channel);
|
||||||
|
|
||||||
channel.connect(TestContent.PLAYER_LOGIN);
|
channel.connect(TestContent.PLAYER_LOGIN);
|
||||||
|
|
||||||
setInstance(client);
|
setInstance(client);
|
||||||
|
|
||||||
GUI.addBottomLayer(new LayerWorld(client));
|
ServerState.getInstance().getChunkManager().register(bl -> {
|
||||||
GUI.addTopLayer(new LayerTestUI());
|
if (!bl && firstLoad)
|
||||||
GUI.addTopLayer(new LayerAbout());
|
{
|
||||||
|
MutableString t = new MutableStringLocalized("LayerText.Load");
|
||||||
|
layer = new LayerTestText("Text",() -> {t.update(); return t.get();});
|
||||||
|
GUI.addTopLayer(layer);
|
||||||
|
}
|
||||||
|
else if (bl && firstLoad)
|
||||||
|
{
|
||||||
|
GUI.removeLayer(layer);
|
||||||
|
|
||||||
|
LayerWorld layerWorld = new LayerWorld(client);
|
||||||
|
LayerTestUI layerUI = new LayerTestUI();
|
||||||
|
LayerAbout layerAbout = new LayerAbout();
|
||||||
|
GUI.addBottomLayer(layerWorld);
|
||||||
|
GUI.addTopLayer(layerUI);
|
||||||
|
GUI.addTopLayer(layerAbout);
|
||||||
|
|
||||||
|
layers = new HashSet<Layer>();
|
||||||
|
layers.add(layerWorld);
|
||||||
|
layers.add(layerUI);
|
||||||
|
layers.add(layerAbout);
|
||||||
|
|
||||||
|
firstLoad = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disconnectFromLocalServer()
|
||||||
|
{
|
||||||
|
for (Layer layer : layers)
|
||||||
|
{
|
||||||
|
GUI.removeLayer(layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerState.getInstance().getClientManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClientState() {
|
private ClientState() {
|
||||||
|
@ -53,7 +53,8 @@ public class LocalClient extends ClientPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
// Do nothing
|
setState(State.DISCONNECTING);
|
||||||
|
serverComms.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ public class LocalServerCommsChannel extends ServerCommsChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
// Do nothing
|
setState(State.DISCONNECTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,15 @@
|
|||||||
|
|
||||||
package ru.windcorp.progressia.server;
|
package ru.windcorp.progressia.server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
import glm.vec._3.i.Vec3i;
|
import glm.vec._3.i.Vec3i;
|
||||||
import ru.windcorp.progressia.common.world.ChunkData;
|
import ru.windcorp.progressia.common.world.ChunkData;
|
||||||
import ru.windcorp.progressia.common.world.PacketRevokeChunk;
|
import ru.windcorp.progressia.common.world.PacketRevokeChunk;
|
||||||
@ -75,6 +80,12 @@ public class ChunkManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface ChunksLoadListener
|
||||||
|
{
|
||||||
|
void handle(boolean starting);
|
||||||
|
}
|
||||||
|
|
||||||
private final Server server;
|
private final Server server;
|
||||||
|
|
||||||
private final ChunkSet loaded;
|
private final ChunkSet loaded;
|
||||||
@ -82,6 +93,8 @@ public class ChunkManager {
|
|||||||
private final ChunkSet toLoad = ChunkSets.newHashSet();
|
private final ChunkSet toLoad = ChunkSets.newHashSet();
|
||||||
private final ChunkSet toUnload = ChunkSets.newHashSet();
|
private final ChunkSet toUnload = ChunkSets.newHashSet();
|
||||||
|
|
||||||
|
private Collection<ChunksLoadListener> listeners = Collections.synchronizedCollection( new ArrayList<>());
|
||||||
|
|
||||||
// TODO replace with a normal Map managed by some sort of PlayerListener,
|
// TODO replace with a normal Map managed by some sort of PlayerListener,
|
||||||
// weak maps are weak
|
// weak maps are weak
|
||||||
private final Map<Player, PlayerVision> visions = Collections.synchronizedMap(new WeakHashMap<>());
|
private final Map<Player, PlayerVision> visions = Collections.synchronizedMap(new WeakHashMap<>());
|
||||||
@ -101,6 +114,16 @@ public class ChunkManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void register(ChunksLoadListener cll)
|
||||||
|
{
|
||||||
|
listeners.add(cll);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterAll()
|
||||||
|
{
|
||||||
|
listeners.clear();
|
||||||
|
}
|
||||||
|
|
||||||
private void gatherRequests() {
|
private void gatherRequests() {
|
||||||
requested.clear();
|
requested.clear();
|
||||||
|
|
||||||
@ -126,6 +149,12 @@ public class ChunkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void processQueues() {
|
private void processQueues() {
|
||||||
|
|
||||||
|
if (toUnload.size()!=0 || toLoad.size()!=0)
|
||||||
|
{
|
||||||
|
LogManager.getLogger().info(String.valueOf(toUnload.size())+" "+String.valueOf( toLoad.size()));
|
||||||
|
listeners.forEach(l -> l.handle(false));
|
||||||
|
}
|
||||||
toUnload.forEach(this::unloadChunk);
|
toUnload.forEach(this::unloadChunk);
|
||||||
toUnload.clear();
|
toUnload.clear();
|
||||||
toLoad.forEach(this::loadChunk);
|
toLoad.forEach(this::loadChunk);
|
||||||
@ -134,6 +163,8 @@ public class ChunkManager {
|
|||||||
visions.forEach((p, v) -> {
|
visions.forEach((p, v) -> {
|
||||||
v.processQueues(p);
|
v.processQueues(p);
|
||||||
});
|
});
|
||||||
|
listeners.forEach(l -> l.handle(true));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlayerVision getVision(Player player, boolean createIfMissing) {
|
private PlayerVision getVision(Player player, boolean createIfMissing) {
|
||||||
@ -175,6 +206,25 @@ public class ChunkManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unloadAll() // dont use probably
|
||||||
|
{
|
||||||
|
WorldData world = getServer().getWorld().getData();
|
||||||
|
|
||||||
|
//Collection<ChunkData> chunks = world.getChunks();
|
||||||
|
Collection<Vec3i> chunkPoss = new HashSet<Vec3i>();
|
||||||
|
|
||||||
|
world.forEachChunk(c -> {
|
||||||
|
chunkPoss.add(c.getPosition());
|
||||||
|
});
|
||||||
|
|
||||||
|
chunkPoss.forEach(v -> {
|
||||||
|
ChunkData c = world.getChunk(v);
|
||||||
|
world.removeChunk(c);
|
||||||
|
|
||||||
|
TestWorldDiskIO.saveChunk(c, getServer());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void sendChunk(Player player, Vec3i chunkPos) {
|
public void sendChunk(Player player, Vec3i chunkPos) {
|
||||||
ChunkData chunk = server.getWorld().getData().getChunk(chunkPos);
|
ChunkData chunk = server.getWorld().getData().getChunk(chunkPos);
|
||||||
|
|
||||||
|
@ -73,6 +73,11 @@ public class PlayerManager {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removePlayer(Player player)
|
||||||
|
{
|
||||||
|
players.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
public Server getServer() {
|
public Server getServer() {
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
package ru.windcorp.progressia.test;
|
package ru.windcorp.progressia.test;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.ClientState;
|
import ru.windcorp.progressia.client.ClientState;
|
||||||
import ru.windcorp.progressia.client.graphics.Colors;
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
import ru.windcorp.progressia.client.graphics.GUI;
|
import ru.windcorp.progressia.client.graphics.GUI;
|
||||||
@ -28,10 +30,16 @@ import ru.windcorp.progressia.client.graphics.gui.Label;
|
|||||||
import ru.windcorp.progressia.client.graphics.gui.RadioButton;
|
import ru.windcorp.progressia.client.graphics.gui.RadioButton;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.RadioButtonGroup;
|
import ru.windcorp.progressia.client.graphics.gui.RadioButtonGroup;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.menu.MenuLayer;
|
import ru.windcorp.progressia.client.graphics.gui.menu.MenuLayer;
|
||||||
|
import ru.windcorp.progressia.client.localization.MutableString;
|
||||||
|
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
||||||
|
import ru.windcorp.progressia.server.ChunkManager;
|
||||||
|
import ru.windcorp.progressia.server.Player;
|
||||||
import ru.windcorp.progressia.server.ServerState;
|
import ru.windcorp.progressia.server.ServerState;
|
||||||
|
|
||||||
public class LayerButtonTest extends MenuLayer {
|
public class LayerButtonTest extends MenuLayer {
|
||||||
|
|
||||||
|
boolean alive = true;
|
||||||
|
|
||||||
public LayerButtonTest() {
|
public LayerButtonTest() {
|
||||||
super("ButtonTest");
|
super("ButtonTest");
|
||||||
|
|
||||||
@ -64,15 +72,43 @@ public class LayerButtonTest extends MenuLayer {
|
|||||||
getCloseAction().run();
|
getCloseAction().run();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
getContent().addChild(new Button("Menu", "Menu").addAction(b -> {
|
getContent().addChild(new Button("Menu", "Back To Menu").addAction(b -> {
|
||||||
//System.exit(0);
|
//System.exit(0);
|
||||||
for (Layer layer : GUI.getLayers())
|
//for (Layer layer : GUI.getLayers())
|
||||||
{
|
//{
|
||||||
GUI.removeLayer(layer);
|
// GUI.removeLayer(layer);
|
||||||
}
|
//}
|
||||||
GUI.addTopLayer(new LayerTitle("Title"));
|
getCloseAction().run();
|
||||||
|
|
||||||
//ClientState.getInstance().;
|
//ClientState.getInstance().;
|
||||||
|
|
||||||
|
Collection<Player> players = ServerState.getInstance().getPlayerManager().getPlayers();
|
||||||
|
players.clear();
|
||||||
|
|
||||||
|
ClientState.disconnectFromLocalServer();
|
||||||
|
|
||||||
|
MutableString t = new MutableStringLocalized("LayerText.Save");
|
||||||
|
LayerTestText layer = new LayerTestText("Text",() -> {t.update(); return t.get();});
|
||||||
|
|
||||||
|
GUI.addTopLayer(layer);
|
||||||
|
|
||||||
|
ChunkManager cm = ServerState.getInstance().getChunkManager();
|
||||||
|
alive = true;
|
||||||
|
cm.register(bl -> {
|
||||||
|
if (bl && alive)
|
||||||
|
{
|
||||||
|
GUI.removeLayer(layer);
|
||||||
|
GUI.addTopLayer(new LayerTitle("Title"));
|
||||||
|
//cm.unregisterAll();
|
||||||
|
alive = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//ClientState.getInstance();
|
||||||
|
ClientState.setInstance(null);
|
||||||
|
ServerState.setInstance(null);
|
||||||
|
//ServerState.getInstance().getChunkManager().unloadAll();
|
||||||
|
|
||||||
//ServerState.getInstance().shutdown("Safe Exit");
|
//ServerState.getInstance().shutdown("Safe Exit");
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
24
src/main/java/ru/windcorp/progressia/test/LayerTestText.java
Normal file
24
src/main/java/ru/windcorp/progressia/test/LayerTestText.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package ru.windcorp.progressia.test;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
|
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
||||||
|
|
||||||
|
public class LayerTestText extends GUILayer {
|
||||||
|
public LayerTestText(String name, Supplier<String> value) {
|
||||||
|
super(name, new LayoutVertical(20,10));
|
||||||
|
|
||||||
|
//MutableString title = new MutableStringLocalized("Layer"+name+".Title");
|
||||||
|
Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(0.5f);
|
||||||
|
getRoot().addChild(new Label(name+".Text", titleFont, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LayerTestText(String name, String value)
|
||||||
|
{
|
||||||
|
this(name,() -> value);
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ public class LayerTitle extends GUILayer {
|
|||||||
MutableString playText = new MutableStringLocalized("Layer"+name+".Play");
|
MutableString playText = new MutableStringLocalized("Layer"+name+".Play");
|
||||||
getRoot().addChild(new Button(name+".Play", new Label(name+".Play", buttonFont, playText)).addAction(b -> {
|
getRoot().addChild(new Button(name+".Play", new Label(name+".Play", buttonFont, playText)).addAction(b -> {
|
||||||
GUI.removeLayer(this);
|
GUI.removeLayer(this);
|
||||||
|
|
||||||
ProgressiaLauncher.play();}));
|
ProgressiaLauncher.play();}));
|
||||||
|
|
||||||
MutableString quitText = new MutableStringLocalized("Layer"+name+".Quit");
|
MutableString quitText = new MutableStringLocalized("Layer"+name+".Quit");
|
||||||
|
@ -23,8 +23,12 @@ LayerTestGUI.IsFullscreen = Fullscreen: %5s (F11)
|
|||||||
LayerTestGUI.IsVSync = VSync: %5s (F12)
|
LayerTestGUI.IsVSync = VSync: %5s (F12)
|
||||||
|
|
||||||
LayerButtonTest.Title = Button Test
|
LayerButtonTest.Title = Button Test
|
||||||
|
LayerButtonTest.Return = Back To Menu
|
||||||
|
|
||||||
LayerTitle.Title = Progressia
|
LayerTitle.Title = Progressia
|
||||||
LayerTitle.Play = Play World
|
LayerTitle.Play = Play World
|
||||||
LayerTitle.Options = Options
|
LayerTitle.Options = Options
|
||||||
LayerTitle.Quit = Quit
|
LayerTitle.Quit = Quit
|
||||||
|
|
||||||
|
LayerText.Load = Loading...
|
||||||
|
LayerText.Save = Saving...
|
@ -23,8 +23,12 @@ LayerTestGUI.IsFullscreen = Полный экран: %5s (F11)
|
|||||||
LayerTestGUI.IsVSync = Верт. синхр.: %5s (F12)
|
LayerTestGUI.IsVSync = Верт. синхр.: %5s (F12)
|
||||||
|
|
||||||
LayerButtonTest.Title = Тест Кнопок
|
LayerButtonTest.Title = Тест Кнопок
|
||||||
|
LayerButtonTest.Return = Back To Menu [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
|
||||||
|
|
||||||
LayerTitle.Title = Прогрессия
|
LayerTitle.Title = Прогрессия
|
||||||
LayerTitle.Play = ???????
|
LayerTitle.Play = ???????
|
||||||
LayerTitle.Options = ????????
|
LayerTitle.Options = ????????
|
||||||
LayerTitle.Quit = ????????
|
LayerTitle.Quit = ????????
|
||||||
|
|
||||||
|
LayerText.Load = Loading... (Change)
|
||||||
|
LayerText.Save = Saving...(Cahnsf)
|
Reference in New Issue
Block a user