Compare commits
5 Commits
d3f0de81b1
...
fd9aabb6a1
| Author | SHA1 | Date | |
|---|---|---|---|
| fd9aabb6a1 | |||
| 1b31643f0b | |||
| fefb826b38 | |||
| 56f2aa3c56 | |||
| 0e8ee9eacd |
@@ -11,7 +11,7 @@ public class OpenGLMain {
|
||||
Game game = new Game();
|
||||
CommandExecutor commandExecutor = new CommandExecutor(game);
|
||||
|
||||
PgnFileSimulator fileSimulator = new PgnFileSimulator(commandExecutor, "games/CastlingTest.pgn");
|
||||
PgnFileSimulator fileSimulator = new PgnFileSimulator(commandExecutor, "games/FoolCheckmate.pgn");
|
||||
|
||||
DDDView ddd = new DDDView(commandExecutor);
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import java.util.function.Consumer;
|
||||
|
||||
import chess.controller.commands.*;
|
||||
import imgui.ImGui;
|
||||
import imgui.type.ImBoolean;
|
||||
import imgui.ImVec2;
|
||||
import imgui.flag.ImGuiCond;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
@@ -44,7 +46,6 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
private float moveProgress = 0.0f;
|
||||
|
||||
private String waitingPopup = null;
|
||||
private final ImBoolean popupOpened = new ImBoolean(false);
|
||||
|
||||
public DDDView(CommandExecutor commandExecutor) {
|
||||
this.commandExecutor = commandExecutor;
|
||||
@@ -148,7 +149,7 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
private void onCellExit(Coordinate coordinate) {
|
||||
if (this.click == null) {
|
||||
this.boardEntity.resetCellColor(coordinate);
|
||||
Piece p = pieceAt(coordinate);
|
||||
Piece p = getPieceAt(coordinate);
|
||||
if (p == null)
|
||||
return;
|
||||
|
||||
@@ -168,7 +169,7 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
|
||||
private void cancelPreview(Coordinate coordinate) {
|
||||
this.boardEntity.resetCellColor(coordinate);
|
||||
Piece p = pieceAt(coordinate);
|
||||
Piece p = getPieceAt(coordinate);
|
||||
if (p == null)
|
||||
return;
|
||||
this.world.getPiece(coordinate).setColor(p.getColor() == Color.White ? WHITE : BLACK);
|
||||
@@ -180,12 +181,6 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
}
|
||||
}
|
||||
|
||||
private Piece pieceAt(Coordinate pos) {
|
||||
GetPieceAtCommand cmd = new GetPieceAtCommand(pos);
|
||||
this.commandExecutor.executeCommand(cmd);
|
||||
return cmd.getPiece();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGameStart() {
|
||||
this.window.scheduleTask(() -> {
|
||||
@@ -251,7 +246,7 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
|
||||
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
|
||||
Coordinate pos = new Coordinate(i, j);
|
||||
Piece piece = pieceAt(pos);
|
||||
Piece piece = getPieceAt(pos);
|
||||
if (piece == null)
|
||||
continue;
|
||||
|
||||
@@ -377,8 +372,16 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
}
|
||||
|
||||
private void renderPopup(String title, String text) {
|
||||
if (ImGui.beginPopupModal(title, popupOpened)) {
|
||||
ImVec2 center = ImGui.getMainViewport().getCenter();
|
||||
ImGui.setNextWindowPos(center, ImGuiCond.Appearing, new ImVec2(0.5f, 0.5f));
|
||||
if (ImGui.beginPopupModal(title, null, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoMove)) {
|
||||
ImGui.text(text);
|
||||
if (ImGui.button("Close")) {
|
||||
ImGui.closeCurrentPopup();
|
||||
synchronized (this) {
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
ImGui.endPopup();
|
||||
}
|
||||
}
|
||||
@@ -397,8 +400,15 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
}
|
||||
|
||||
private void openPopup(String title) {
|
||||
this.popupOpened.set(true);
|
||||
this.waitingPopup = title;
|
||||
// block the current thread until the popup is closed
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -419,6 +429,12 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
@Override
|
||||
public void onGameEnd() {
|
||||
openPopup("End");
|
||||
this.window.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWin(Color color) {
|
||||
openPopup(color == Color.White ? "Black victory" : "White victory");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,7 +445,6 @@ public class DDDView extends GameAdapter implements CommandSender {
|
||||
@Override
|
||||
public void onSurrender(Color color) {
|
||||
openPopup(color == Color.White ? "White surrender" : "Black surrender");
|
||||
openPopup(color == Color.White ? "Black victory" : "White victory");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -72,5 +72,6 @@ public class Renderer implements Closeable {
|
||||
public void close() throws IOException {
|
||||
this.boardShader.close();
|
||||
this.pieceShader.close();
|
||||
this.frameBuffer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,8 @@ public class Window implements Closeable {
|
||||
private ImInt detailLevel = new ImInt(10);
|
||||
private ImBoolean pixelatedFrame = new ImBoolean(true);
|
||||
|
||||
private boolean shouldBeClosed = false;
|
||||
|
||||
public Window(Renderer renderer, World world, Camera camera) {
|
||||
this.renderer = new Renderer();
|
||||
this.cam = camera;
|
||||
@@ -280,7 +282,7 @@ public class Window implements Closeable {
|
||||
|
||||
// Run the rendering loop until the user has attempted to close
|
||||
// the window or has pressed the ESCAPE key.
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
while (!shouldBeClosed && !glfwWindowShouldClose(window)) {
|
||||
|
||||
newFrame();
|
||||
|
||||
@@ -304,8 +306,13 @@ public class Window implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
shouldBeClosed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
shouldBeClosed = true;
|
||||
this.renderer.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,12 @@ import static org.lwjgl.opengl.GL11.glClear;
|
||||
import static org.lwjgl.opengl.GL11.glTexImage2D;
|
||||
import static org.lwjgl.opengl.GL11.glViewport;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.lwjgl.opengl.GL30;
|
||||
|
||||
public class FrameBuffer {
|
||||
public class FrameBuffer implements Closeable {
|
||||
|
||||
private int fbo;
|
||||
private int renderTexture;
|
||||
@@ -103,4 +106,11 @@ public class FrameBuffer {
|
||||
return renderTexture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
GL30.glDeleteFramebuffers(this.fbo);
|
||||
GL30.glDeleteRenderbuffers(this.depthBuffer);
|
||||
GL30.glDeleteTextures(this.renderTexture);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user