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:
opfromthestart 2021-08-03 22:42:46 -04:00
parent 53f72b068a
commit 94db44e443
11 changed files with 185 additions and 21 deletions

View File

@ -20,14 +20,6 @@ package ru.windcorp.progressia;
import ru.windcorp.progressia.client.ClientProxy;
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.analyzers.OutOfMemoryAnalyzer;
import ru.windcorp.progressia.common.util.crash.providers.*;

View File

@ -18,18 +18,30 @@
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.graphics.GUI;
import ru.windcorp.progressia.client.graphics.Layer;
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.server.ServerState;
import ru.windcorp.progressia.test.LayerAbout;
import ru.windcorp.progressia.test.LayerTestText;
import ru.windcorp.progressia.test.LayerTestUI;
import ru.windcorp.progressia.test.TestContent;
public class ClientState {
private static Client instance;
private static Collection<Layer> layers;
private static boolean firstLoad;
private static LayerTestText layer;
public static Client getInstance() {
return instance;
@ -46,6 +58,8 @@ public class ClientState {
LocalServerCommsChannel channel = new LocalServerCommsChannel(
ServerState.getInstance()
);
firstLoad = true;
Client client = new Client(world, channel);
@ -53,10 +67,43 @@ public class ClientState {
setInstance(client);
GUI.addBottomLayer(new LayerWorld(client));
GUI.addTopLayer(new LayerTestUI());
GUI.addTopLayer(new LayerAbout());
ServerState.getInstance().getChunkManager().register(bl -> {
if (!bl && firstLoad)
{
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() {

View File

@ -53,7 +53,8 @@ public class LocalClient extends ClientPlayer {
@Override
public void disconnect() {
// Do nothing
setState(State.DISCONNECTING);
serverComms.disconnect();
}
}

View File

@ -54,7 +54,7 @@ public class LocalServerCommsChannel extends ServerCommsChannel {
@Override
public void disconnect() {
// Do nothing
setState(State.DISCONNECTING);
}
}

View File

@ -18,10 +18,15 @@
package ru.windcorp.progressia.server;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.WeakHashMap;
import org.apache.logging.log4j.LogManager;
import glm.vec._3.i.Vec3i;
import ru.windcorp.progressia.common.world.ChunkData;
import ru.windcorp.progressia.common.world.PacketRevokeChunk;
@ -74,6 +79,12 @@ public class ChunkManager {
}
}
@FunctionalInterface
public interface ChunksLoadListener
{
void handle(boolean starting);
}
private final Server server;
@ -82,6 +93,8 @@ public class ChunkManager {
private final ChunkSet toLoad = 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,
// weak maps are weak
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() {
requested.clear();
@ -126,6 +149,12 @@ public class ChunkManager {
}
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.clear();
toLoad.forEach(this::loadChunk);
@ -134,6 +163,8 @@ public class ChunkManager {
visions.forEach((p, v) -> {
v.processQueues(p);
});
listeners.forEach(l -> l.handle(true));
}
private PlayerVision getVision(Player player, boolean createIfMissing) {
@ -174,6 +205,25 @@ public class ChunkManager {
TestWorldDiskIO.saveChunk(chunk, getServer());
}
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) {
ChunkData chunk = server.getWorld().getData().getChunk(chunkPos);

View File

@ -72,6 +72,11 @@ public class PlayerManager {
return player;
}
public void removePlayer(Player player)
{
players.remove(player);
}
public Server getServer() {
return server;

View File

@ -17,6 +17,8 @@
*/
package ru.windcorp.progressia.test;
import java.util.Collection;
import ru.windcorp.progressia.client.ClientState;
import ru.windcorp.progressia.client.graphics.Colors;
import ru.windcorp.progressia.client.graphics.GUI;
@ -28,9 +30,15 @@ import ru.windcorp.progressia.client.graphics.gui.Label;
import ru.windcorp.progressia.client.graphics.gui.RadioButton;
import ru.windcorp.progressia.client.graphics.gui.RadioButtonGroup;
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;
public class LayerButtonTest extends MenuLayer {
boolean alive = true;
public LayerButtonTest() {
super("ButtonTest");
@ -64,15 +72,43 @@ public class LayerButtonTest extends MenuLayer {
getCloseAction().run();
}));
getContent().addChild(new Button("Menu", "Menu").addAction(b -> {
getContent().addChild(new Button("Menu", "Back To Menu").addAction(b -> {
//System.exit(0);
for (Layer layer : GUI.getLayers())
{
GUI.removeLayer(layer);
}
GUI.addTopLayer(new LayerTitle("Title"));
//for (Layer layer : GUI.getLayers())
//{
// GUI.removeLayer(layer);
//}
getCloseAction().run();
//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");
}));

View 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);
}
}

View File

@ -24,6 +24,7 @@ public class LayerTitle extends GUILayer {
MutableString playText = new MutableStringLocalized("Layer"+name+".Play");
getRoot().addChild(new Button(name+".Play", new Label(name+".Play", buttonFont, playText)).addAction(b -> {
GUI.removeLayer(this);
ProgressiaLauncher.play();}));
MutableString quitText = new MutableStringLocalized("Layer"+name+".Quit");

View File

@ -23,8 +23,12 @@ LayerTestGUI.IsFullscreen = Fullscreen: %5s (F11)
LayerTestGUI.IsVSync = VSync: %5s (F12)
LayerButtonTest.Title = Button Test
LayerButtonTest.Return = Back To Menu
LayerTitle.Title = Progressia
LayerTitle.Play = Play World
LayerTitle.Options = Options
LayerTitle.Quit = Quit
LayerTitle.Quit = Quit
LayerText.Load = Loading...
LayerText.Save = Saving...

View File

@ -23,8 +23,12 @@ LayerTestGUI.IsFullscreen = Полный экран: %5s (F11)
LayerTestGUI.IsVSync = Верт. синхр.: %5s (F12)
LayerButtonTest.Title = Тест Кнопок
LayerButtonTest.Return = Back To Menu [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
LayerTitle.Title = Прогрессия
LayerTitle.Play = ???????
LayerTitle.Options = ????????
LayerTitle.Quit = ????????
LayerTitle.Quit = ????????
LayerText.Load = Loading... (Change)
LayerText.Save = Saving...(Cahnsf)