Skip to content

Commit 33e266a

Browse files
committed
feat: better first person
Signed-off-by: orangishcat <fdsnail2@gmail.com>
1 parent 8314d40 commit 33e266a

14 files changed

Lines changed: 418 additions & 48 deletions

File tree

src/main/java/basewindow/BaseWindow.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public abstract class BaseWindow
108108

109109
public static final HashMap<Integer, String> keyNames = new HashMap<>();
110110

111+
public float[] outOfBoundsColor = new float[]{1f, 1f, 1f, 1f};
112+
111113
public BasePlatformHandler platformHandler;
112114

113115
public ModelPart.ShapeDrawer shapeDrawer;
@@ -193,6 +195,14 @@ public void stopTiming()
193195

194196
public abstract void setColor(double r, double g, double b);
195197

198+
public void setOutOfBoundsColor(float r, float g, float b, float a)
199+
{
200+
outOfBoundsColor[0] = r / 255;
201+
outOfBoundsColor[1] = g / 255;
202+
outOfBoundsColor[2] = b / 255;
203+
outOfBoundsColor[3] = a / 255;
204+
}
205+
196206
public abstract void setUpPerspective();
197207

198208
public abstract void applyTransformations();

src/main/java/lwjglwindow/ShaderHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.lwjgl.opengl.GL13;
44

55
import java.nio.ByteBuffer;
6-
import java.util.Arrays;
76

87
import static org.lwjgl.opengl.EXTFramebufferObject.*;
98
import static org.lwjgl.opengl.GL20.*;
@@ -44,6 +43,8 @@ public void createDepthTexture(int size)
4443
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4544
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
4645
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
46+
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, window.outOfBoundsColor);
47+
4748
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size, size, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, (ByteBuffer) null);
4849
glBindTexture(GL_TEXTURE_2D, 0);
4950
}

src/main/java/tanks/Game.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ public int hashCode()
154154
public static boolean drawFaces = false;
155155
public static boolean drawAvoidObjects = false;
156156
public static boolean recordMovableData = false;
157+
public static boolean recordEventData = false;
157158
public static final boolean cinematic = false;
158159

159160
public static long steamLobbyInvite = -1;

src/main/java/tanks/Panel.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tanks;
22

33
import basewindow.InputCodes;
4+
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
45
import tanks.extension.Extension;
56
import tanks.gui.*;
67
import tanks.gui.ScreenElement.*;
@@ -100,7 +101,10 @@ public class Panel
100101
/** Set to a directory to have the game screenshot the next frame and save it to that directory */
101102
public String saveScreenshotDir = null;
102103

103-
public static void initialize()
104+
public final Object2IntOpenHashMap<Class<? extends INetworkEvent>> eventsInCount = new Object2IntOpenHashMap<>();
105+
public final Object2IntOpenHashMap<Class<? extends INetworkEvent>> eventsOutCount = new Object2IntOpenHashMap<>();
106+
107+
public static void initialize()
104108
{
105109
if (!initialized)
106110
panel = new Panel();
@@ -348,11 +352,23 @@ else if (Game.deterministicMode)
348352
if (!(Game.eventsIn.get(i) instanceof IOnlineServerEvent))
349353
{
350354
INetworkEvent e = Game.eventsIn.get(i);
355+
INetworkEvent prev = null;
351356

352357
if (e instanceof IStackableEvent)
353-
stackedEventsIn.put(IStackableEvent.f(NetworkEventMap.get(e.getClass()) + IStackableEvent.f(((IStackableEvent) e).getIdentifier())), (IStackableEvent) e);
358+
prev = stackedEventsIn.put(IStackableEvent.f(NetworkEventMap.get(e.getClass()) + IStackableEvent.f(((IStackableEvent) e).getIdentifier())), (IStackableEvent) e);
354359
else
355-
Game.eventsIn.get(i).execute();
360+
Game.eventsIn.get(i).execute();
361+
362+
if (Game.recordEventData && prev == null)
363+
{
364+
if (e instanceof EventStackedGroup)
365+
{
366+
for (INetworkEvent e2 : ((EventStackedGroup) e).events)
367+
eventsInCount.addTo(e2.getClass(), 1);
368+
}
369+
else
370+
eventsInCount.addTo(e.getClass(), 1);
371+
}
356372
}
357373
}
358374

src/main/java/tanks/gui/input/InputBindings.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class InputBindings
4848
public InputBindingGroup chat = new InputBindingGroup("game.chat", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_T));
4949
public InputBindingGroup hidePause = new InputBindingGroup("game.hidePauseMenu", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_F1));
5050
public InputBindingGroup fullscreen = new InputBindingGroup("game.fullscreen", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_F11), new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_F10));
51+
public InputBindingGroup perspective = new InputBindingGroup("game.perspective", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_F5));
52+
public InputBindingGroup tilt = new InputBindingGroup("game.pitch", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_F), new InputBinding(InputBinding.InputType.mouse, InputCodes.MOUSE_BUTTON_5));
5153
public InputBindingGroup screenshot = new InputBindingGroup("game.screenshot", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_F12));
5254

5355
public InputBindingGroup editorPause = new InputBindingGroup("editor.pause", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_ESCAPE));
@@ -63,6 +65,7 @@ public class InputBindings
6365
public InputBindingGroup editorRotate = new InputBindingGroup("editor.rotate", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_R));
6466
public InputBindingGroup editorHeight = new InputBindingGroup("editor.height", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_H));
6567
public InputBindingGroup editorGroupID = new InputBindingGroup("editor.groupID", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_G));
68+
public InputBindingGroup fcZoom = new InputBindingGroup("game.fcZoom", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_C));
6669

6770
public InputBindingGroup editorBuild = new InputBindingGroup("editor.build", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_B));
6871
public InputBindingGroup editorErase = new InputBindingGroup("editor.erase", new InputBinding(InputBinding.InputType.keyboard, InputCodes.KEY_E));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package tanks.gui.screen;
2+
3+
public interface IGameOverlayScreen
4+
{
5+
ScreenGame getGameScreen();
6+
}

src/main/java/tanks/gui/screen/ScreenControlsCamera.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
public class ScreenControlsCamera extends Screen
88
{
9-
InputSelector toggleZoom = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 - 135, 700, 40, "Toggle zoom", Game.game.input.zoom);
10-
InputSelector zoomIn = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 - 45, 700, 40, "Zoom in", Game.game.input.zoomIn);
11-
InputSelector zoomOut = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 + 45, 700, 40, "Zoom out", Game.game.input.zoomOut);
12-
InputSelector zoomAuto = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 + 135, 700, 40, "Toggle automatic zoom", Game.game.input.zoomAuto);
9+
InputSelector toggleZoom = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 - 225, 700, 40, "Toggle zoom", Game.game.input.zoom);
10+
InputSelector zoomIn = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 - 135, 700, 40, "Zoom in", Game.game.input.zoomIn);
11+
InputSelector zoomOut = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 - 45, 700, 40, "Zoom out", Game.game.input.zoomOut);
12+
InputSelector zoomAuto = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 + 45, 700, 40, "Toggle automatic zoom", Game.game.input.zoomAuto);
13+
InputSelector togglePerspective = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 + 135, 700, 40, "Toggle Perspective", Game.game.input.perspective);
14+
InputSelector cameraPitch = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 + 225, 700, 40, "Third person camera tilt", Game.game.input.tilt);
15+
InputSelector cameraZoom = new InputSelector(Drawing.drawing.interfaceSizeX * 2 / 3, Drawing.drawing.interfaceSizeY / 2 + 315, 700, 40, "Third person camera zoom", Game.game.input.fcZoom);
1316

1417
public ScreenControlsCamera()
1518
{
@@ -24,6 +27,9 @@ public void update()
2427
zoomIn.update();
2528
zoomOut.update();
2629
zoomAuto.update();
30+
togglePerspective.update();
31+
cameraPitch.update();
32+
cameraZoom.update();
2733

2834
ScreenOverlayControls.overlay.update();
2935
}
@@ -37,6 +43,9 @@ public void draw()
3743
zoomOut.draw();
3844
zoomIn.draw();
3945
zoomAuto.draw();
46+
togglePerspective.draw();
47+
cameraPitch.draw();
48+
cameraZoom.draw();
4049

4150
Drawing.drawing.setInterfaceFontSize(this.titleSize);
4251
Drawing.drawing.setColor(0, 0, 0);

0 commit comments

Comments
 (0)