Fixing issues, preparing more multiplayer stuff, added credits
This commit is contained in:
parent
4af61ca2c8
commit
0d8f23cb1f
14 changed files with 400 additions and 185 deletions
|
|
@ -56,7 +56,7 @@ public class Server {
|
|||
public static void main(String[] args) throws IOException {
|
||||
Configuration.set("writer.file", "ServerLog.t4jlog");
|
||||
|
||||
ServerSocket server = new ServerSocket(25565);
|
||||
ServerSocket server = new ServerSocket(ServerConnectionThread.ServerPort);
|
||||
Logger.info("\nLaunching New Terrain4J Powered Software!");
|
||||
|
||||
RenderThread.Headless = true;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import net.halbear.Terrain4J.EngineCore.Input.KeyboardInput;
|
|||
import net.halbear.Terrain4J.EngineCore.Input.MouseListener;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
import org.lwjgl.glfw.GLFWImage;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.glfw.GLFWWindowFocusCallback;
|
||||
|
|
@ -53,8 +54,8 @@ public class Window {
|
|||
handle = glfwCreateWindow(width, height, title, MemoryUtil.NULL, MemoryUtil.NULL);
|
||||
if (glfwRawMouseMotionSupported()) {
|
||||
glfwSetInputMode(handle, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
|
||||
}
|
||||
LockCursor();
|
||||
}
|
||||
//LockCursor();
|
||||
if (handle == MemoryUtil.NULL) {
|
||||
//throw new RuntimeException("Failed to create the GLFW window");
|
||||
}
|
||||
|
|
@ -106,11 +107,11 @@ public class Window {
|
|||
|
||||
public void LockCursor(){
|
||||
CursorLocked = true;
|
||||
glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
// glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
public void UnlockCursor(){
|
||||
CursorLocked = false;
|
||||
glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
//glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
|
|
@ -138,6 +139,14 @@ public class Window {
|
|||
}
|
||||
keyboardInput.input();
|
||||
mouseInput.input();
|
||||
/* if(CursorLocked) {
|
||||
int[] width = new int[1];
|
||||
int[] height = new int[1];
|
||||
glfwGetWindowSize(handle, width, height);
|
||||
double centerX = width[0] / 2.0;
|
||||
double centerY = height[0] / 2.0;
|
||||
glfwSetCursorPos(handle, centerX, centerY);
|
||||
}*/
|
||||
EngineConfig.RENDERFRAMES++;
|
||||
}
|
||||
public void UpdateWindowTitle(){
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ public class EngineConfig {
|
|||
public float WeaponVolume = 1.0f;
|
||||
public float AmbientVolume = 1.0f;
|
||||
|
||||
public float PlayerOnline = 1.0f;
|
||||
|
||||
public float PhysicsSpeed(){return PhysicsSpeed;}
|
||||
public void SetPhysicsSpeed(float NewSpeed){PhysicsSpeed =NewSpeed;}
|
||||
|
||||
|
|
@ -366,3 +368,6 @@ public class EngineConfig {
|
|||
return IconPath + IconName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,7 @@ import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidPhysicsCont
|
|||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.WorldPhysicsManager;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Rendering.ModelLoader;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.Gimbal;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.LoadingScreen;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.SettingsMenu;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.StartMenu;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs.*;
|
||||
import net.halbear.Terrain4J.EngineCore.Profiling.CPUMonitor;
|
||||
import net.halbear.Terrain4J.EngineCore.Profiling.GPUProfiler;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
|
|
@ -45,6 +42,7 @@ import org.tinylog.Logger;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
|
@ -73,6 +71,7 @@ public class GameCore implements GameLogic {
|
|||
private LoadingScreen loadingScreen;
|
||||
public final StartMenu startMenu = new StartMenu();
|
||||
public final SettingsMenu Settings = new SettingsMenu();
|
||||
public final CreditsMenu Credits = new CreditsMenu();
|
||||
public boolean StartMenuActive = true;
|
||||
public List<IMoveableActorComponent> ActorEditorComponents = new ArrayList<>();
|
||||
private Vector2f DeltaPos = new Vector2f(0,0);
|
||||
|
|
@ -170,6 +169,8 @@ public class GameCore implements GameLogic {
|
|||
SpawnNewActor(engineInstance, new Vector3f(-5 + (float)Math.random() * 10,10 + (float)Math.random() * 10, -5 + (float)Math.random() * 10), new Vector3f(0, 0, 0), new Vector3f(1, 1, 1));
|
||||
}
|
||||
}
|
||||
Settings.textBuffer.set(ClientConnectionThread.ServerIP);
|
||||
Settings.UsernameBuffer.set("Player");
|
||||
return new InitData(models,materials,guiTextures);
|
||||
}
|
||||
|
||||
|
|
@ -315,7 +316,7 @@ public class GameCore implements GameLogic {
|
|||
LastMousePos.y = CurrentMousePos.y;
|
||||
if(MouseInput.isRightButtonPressed()){
|
||||
|
||||
camera.AddRotation((float)Math.toRadians(-deltaPos.y * Multiplier),(float)Math.toRadians(-deltaPos.x * Multiplier),0);
|
||||
camera.AddRotation((float)Math.toRadians(deltaPos.y * Multiplier),(float)Math.toRadians(deltaPos.x * Multiplier),0);
|
||||
}
|
||||
DeltaPos = new Vector2f(deltaPos);
|
||||
engineInstance.audioManager().UpdateListenerPosition(camera);
|
||||
|
|
@ -420,6 +421,7 @@ public class GameCore implements GameLogic {
|
|||
} else if (StartMenuActive) {
|
||||
startMenu.RenderGUI(engineInstance, frameTimeNS, this);
|
||||
Settings.RenderGUI(engineInstance, frameTimeNS, this);
|
||||
Credits.RenderGUI(engineInstance, frameTimeNS, this);
|
||||
if (startMenu.GameStarted && !StartMenu.ShowSettings) {
|
||||
StartMenuActive = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class PrimaryRuntime {
|
|||
timer.scheduleAtFixedRate(new TimerTask() {;
|
||||
@Override
|
||||
public void run() {
|
||||
String text = "Halbear.Net Launcher : " + PingServer(ClientConnectionThread.ServerIP, false);
|
||||
String text = "Pinging : " + PingServer(ClientConnectionThread.ServerIP, false);
|
||||
if (ClientConnectionThread.Connected){
|
||||
ClientConnectionThread.pinging = false;
|
||||
this.cancel();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs;
|
||||
|
||||
import imgui.ImDrawList;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiViewport;
|
||||
import imgui.ImVec2;
|
||||
import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiCond;
|
||||
import imgui.flag.ImGuiStyleVar;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import imgui.type.ImInt;
|
||||
import imgui.type.ImString;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.AudioInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Scene;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import org.tinylog.Logger;
|
||||
|
||||
public class CreditsMenu implements GUIOverlay {
|
||||
public int[] Music = new int[]{100};
|
||||
public int[] SFX = new int[]{100};
|
||||
public int[] Weapons = new int[]{100};
|
||||
public int[] Ambient = new int[]{100};
|
||||
public ImInt ServerPort = new ImInt(25565);
|
||||
public final ImString textBuffer = new ImString(100);
|
||||
public final ImString UsernameBuffer = new ImString(24);
|
||||
|
||||
@Override
|
||||
public void RenderGUI(EngineInstance engineInstance, long frameTimeNS, GameCore parent) {
|
||||
if (!StartMenu.ShowCredits) return;
|
||||
ImGuiViewport viewport = ImGui.getMainViewport();
|
||||
int menuFlags = ImGuiWindowFlags.NoDecoration
|
||||
| ImGuiWindowFlags.AlwaysAutoResize
|
||||
| ImGuiWindowFlags.NoSavedSettings
|
||||
| ImGuiWindowFlags.NoFocusOnAppearing
|
||||
| ImGuiWindowFlags.NoNav
|
||||
| ImGuiWindowFlags.NoMove;
|
||||
|
||||
float CenterX = viewport.getWorkPosX() + viewport.getWorkSizeX() / 2.0f;
|
||||
float CenterY = viewport.getWorkPosY() + viewport.getWorkSizeY() / 2.0f;
|
||||
ImGui.setNextWindowPos(viewport.getWorkPosX(), viewport.getWorkPosY(), ImGuiCond.Always);
|
||||
ImGui.setNextWindowSize(viewport.getWorkSizeX(), viewport.getWorkSizeY());
|
||||
ImGui.pushStyleColor(ImGuiCol.WindowBg, 0.08f, 0.08f, 0.1f, 1.0f);
|
||||
ImGui.pushStyleVar(ImGuiStyleVar.WindowPadding, 40f, 30f);
|
||||
ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, 10f, 16f);
|
||||
ImGui.pushStyleVar(ImGuiStyleVar.WindowRounding, 8f);
|
||||
|
||||
ImGui.begin("Start Menu", menuFlags);
|
||||
if (ImGui.button("Main Menu")) {
|
||||
StartMenu.ShowSettings = false;
|
||||
StartMenu.GameStarted = false;
|
||||
StartMenu.ShowCredits = false;
|
||||
}
|
||||
ImGui.setWindowFontScale(8.0f);
|
||||
float titleX = (viewport.getWorkSizeX() - ImGui.calcTextSize("Shooter Game").x) / 2.0f;
|
||||
float titleY = viewport.getWorkSizeY() * 0.15f;
|
||||
ImGui.setCursorPos(titleX, titleY);
|
||||
ImGui.text("Game Credits");
|
||||
ImGui.setWindowFontScale(3.0f);
|
||||
ImGui.spacing();
|
||||
ImGui.spacing();
|
||||
String[] Text = new String[]{"Game Engine Development","Harrison Corlett","Christian Lincoln","","Game Programming","Harrison Corlett","William Allen","","Art & Level Design","Harrison Corlett","","Music","Kevin Macleod - Incompetech","Luis Humanoide - Freesound.org","Flower Mantis - Freesound.org"};
|
||||
for(int i = 0; i < Text.length; i++) {
|
||||
String text = Text[i];
|
||||
float rightEdge = ImGui.getMainViewport().getPos().x + ImGui.getMainViewport().getSize().x / 2;
|
||||
ImVec2 textSize = new ImVec2();
|
||||
ImGui.calcTextSize(textSize, text);
|
||||
float textWidth = textSize.x;
|
||||
float targetX = rightEdge - textWidth / 2;
|
||||
ImVec2 currentPos = new ImVec2();
|
||||
ImGui.getCursorScreenPos(currentPos);
|
||||
ImGui.setCursorScreenPos(targetX, currentPos.y);
|
||||
ImGui.text(text);
|
||||
}
|
||||
ImGui.end();
|
||||
ImGui.popStyleVar(3);
|
||||
ImGui.popStyleColor();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Main.Scene.GUIs;
|
||||
|
||||
import imgui.ImDrawList;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImGuiViewport;
|
||||
import imgui.ImVec2;
|
||||
import imgui.flag.ImGuiCol;
|
||||
import imgui.flag.ImGuiCond;
|
||||
import imgui.flag.ImGuiStyleVar;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
import imgui.type.ImInt;
|
||||
import imgui.type.ImString;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.AudioInstance;
|
||||
|
|
@ -13,6 +17,7 @@ import net.halbear.Terrain4J.EngineCore.Main.GameCore;
|
|||
import net.halbear.Terrain4J.EngineCore.Main.PrimaryRuntime;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.GUIOverlay;
|
||||
import net.halbear.Terrain4J.EngineCore.Main.Scene.Scene;
|
||||
import net.halbear.Terrain4J.EngineCore.Threads.ClientConnectionThread;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.DeferredSceneRender;
|
||||
import net.halbear.Terrain4J.EngineCore.Vulkan.Structure.DisplayToScreen.ForwardSceneRender;
|
||||
import org.tinylog.Logger;
|
||||
|
|
@ -22,6 +27,9 @@ public class SettingsMenu implements GUIOverlay {
|
|||
public int[] SFX = new int[]{100};
|
||||
public int[] Weapons = new int[]{100};
|
||||
public int[] Ambient = new int[]{100};
|
||||
public ImInt ServerPort = new ImInt(25565);
|
||||
public final ImString textBuffer = new ImString(100);
|
||||
public final ImString UsernameBuffer = new ImString(24);
|
||||
|
||||
@Override
|
||||
public void RenderGUI(EngineInstance engineInstance, long frameTimeNS, GameCore parent) {
|
||||
|
|
@ -44,6 +52,7 @@ public class SettingsMenu implements GUIOverlay {
|
|||
ImGui.pushStyleVar(ImGuiStyleVar.WindowRounding, 8f);
|
||||
|
||||
ImGui.begin("Start Menu", menuFlags);
|
||||
ImDrawList drawList = ImGui.getForegroundDrawList();
|
||||
ImGui.setWindowFontScale(4.0f);
|
||||
if (ImGui.button("Return")) {
|
||||
StartMenu.ShowSettings = false;
|
||||
|
|
@ -58,10 +67,47 @@ public class SettingsMenu implements GUIOverlay {
|
|||
StartMenu.GameStarted = false;
|
||||
}
|
||||
ImGui.sameLine();
|
||||
int color = ImGui.getColorU32(ClientConnectionThread.Connected ? 0.0f : 1.0f, ClientConnectionThread.Connected ? 1.0f : 0.0f, 0.0f, 1.0f);
|
||||
String text = ClientConnectionThread.Connected ? "ONLINE" : "OFFLINE";
|
||||
float rightEdge = ImGui.getMainViewport().getPos().x + ImGui.getMainViewport().getSize().x;
|
||||
ImVec2 textSize = new ImVec2();
|
||||
ImGui.calcTextSize(textSize, text);
|
||||
float textWidth = textSize.x;
|
||||
float targetX = rightEdge - textWidth - (textSize.y * 2);
|
||||
|
||||
ImVec2 currentPos = new ImVec2();
|
||||
ImGui.getCursorScreenPos(currentPos);
|
||||
ImGui.setCursorScreenPos(targetX, currentPos.y);
|
||||
|
||||
ImGui.text(text);
|
||||
drawList.addCircleFilled(rightEdge - (textSize.y), currentPos.y + textSize.y/2, textSize.y/2, color);
|
||||
|
||||
ImGui.text("Settings");
|
||||
ImGui.setWindowFontScale(3f);
|
||||
ImGui.spacing();
|
||||
if (ImGui.beginTabBar("Settings")) {
|
||||
if (ImGui.beginTabItem("Multiplayer")) {
|
||||
ImGui.setWindowFontScale(4.0f);
|
||||
ImGui.text("Multiplayer Settings");
|
||||
ImGui.setWindowFontScale(3f);
|
||||
ImGui.text("User Configuration");
|
||||
if (ImGui.inputText("Player Username", UsernameBuffer)) {
|
||||
|
||||
}
|
||||
ImGui.text("Server Configuration");
|
||||
if (ImGui.inputText("Server IP Address", textBuffer)) {
|
||||
ClientConnectionThread.ServerIP = textBuffer.get();
|
||||
}
|
||||
if (ImGui.inputInt("Server Port", ServerPort)) {
|
||||
ClientConnectionThread.ServerPort = ServerPort.get();
|
||||
}
|
||||
ImGui.text("Players Online: " + (ClientConnectionThread.Connected ? ClientConnectionThread.PlayersOnline : "Not Connected to Server"));
|
||||
ImGui.text("Client UUID: " + (ClientConnectionThread.Connected ? ClientConnectionThread.clientUUID : "Not Connected to Server"));
|
||||
if (ImGui.button("Apply and reconnect")) {
|
||||
|
||||
}
|
||||
ImGui.endTabItem();
|
||||
}
|
||||
if (ImGui.beginTabItem("Audio")) {
|
||||
ImGui.setWindowFontScale(4.0f);
|
||||
ImGui.text("Audio Settings");
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import org.tinylog.Logger;
|
|||
public class StartMenu implements GUIOverlay {
|
||||
public static boolean GameStarted = false;
|
||||
public static boolean ShowSettings = false;
|
||||
public static boolean ShowCredits = false;
|
||||
public float Volume = 1.0f;
|
||||
|
||||
private void ApplyVolume(EngineInstance engineInstance) {
|
||||
|
|
@ -35,7 +36,7 @@ public class StartMenu implements GUIOverlay {
|
|||
}
|
||||
@Override
|
||||
public void RenderGUI(EngineInstance engineInstance, long frameTimeNS, GameCore parent) {
|
||||
if (GameStarted || ShowSettings) return;
|
||||
if (GameStarted || ShowSettings || ShowCredits) return;
|
||||
ImGuiViewport viewport = ImGui.getMainViewport();
|
||||
int menuFlags = ImGuiWindowFlags.NoDecoration
|
||||
| ImGuiWindowFlags.AlwaysAutoResize
|
||||
|
|
@ -77,6 +78,10 @@ public class StartMenu implements GUIOverlay {
|
|||
ShowSettings = true;
|
||||
}
|
||||
ImGui.setCursorPosX(buttonX);
|
||||
if (ImGui.button("Credits", buttonWidth, buttonHeight)) {
|
||||
ShowCredits = true;
|
||||
}
|
||||
ImGui.setCursorPosX(buttonX);
|
||||
if (ImGui.button("Quit", buttonWidth, buttonHeight)) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ public class Scene implements IScene {
|
|||
} else {
|
||||
CurrentWeapon.SetPositionOffset(new Vector3f(0.5f,1.15f,-1.25f));
|
||||
}
|
||||
if(mouseListener.isRightButtonPressed()) {
|
||||
if(mouseListener.isLeftButtonPressed()) {
|
||||
if (CurrentItem != null&& playerActor != null) {
|
||||
long NewTime = System.nanoTime();
|
||||
float FireRate = 1000f/CurrentItem.FireRate();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.UUID;
|
||||
|
||||
public class Packet {
|
||||
|
||||
public static final byte PACKET_UPDATE_LOCATION = 0;
|
||||
public static final byte PACKET_UPDATE_ROTATION = 1;
|
||||
public static final byte PACKET_UPDATE_LINEAR_VELOCITY =2;
|
||||
|
|
@ -22,7 +23,10 @@ public class Packet {
|
|||
public static final byte PACKET_CLIENT_INPUT = 10;
|
||||
public static final byte PACKET_UPDATE_MODEL_ID = 11;
|
||||
public static final byte PACKET_FIRE_WEAPON = 12;
|
||||
public byte PacketTypeByte; //0 Location 1 Rotation 2 LinearVelocity 3 AngularVelocity 4 CombinedActorDownload 5 Ping 6 PosRotVelAngularVel 7 AssignUUID
|
||||
public static final byte PACKET_SEND_PLAYER_COUNT = 13;
|
||||
public static final byte PACKET_UPDATE_PLAYER_DISPLAY_NAME = 14;
|
||||
|
||||
public byte PacketTypeByte;
|
||||
public byte TargetType; //0 Actor
|
||||
public byte[] Data;
|
||||
public String TargetID;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package net.halbear.Terrain4J.EngineCore.Threads;
|
||||
|
||||
import net.halbear.Executable.Server;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.EngineInstance;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.ConvexMesh;
|
||||
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody;
|
||||
|
|
@ -30,9 +31,10 @@ public class ClientConnectionThread implements Runnable{
|
|||
public static final Queue<Packet> IncomingPacketQueue = new ConcurrentLinkedQueue<>();
|
||||
public static DataOutputStream outToServer;
|
||||
public static DataInputStream in;
|
||||
public static long UUID;
|
||||
public static String clientUUID;
|
||||
public static String OwnedActorID = "NULL";
|
||||
public static String PendingPossessActorID = "NULL";
|
||||
public static int PlayersOnline = 0;
|
||||
|
||||
private static boolean TryPossessActor(String actorID, GameCore gameCore, IScene scene){
|
||||
Actor actor = Actor.Actors.get(actorID);
|
||||
|
|
@ -90,7 +92,9 @@ public class ClientConnectionThread implements Runnable{
|
|||
&& packet.PacketTypeByte != Packet.PACKET_CREATE_ACTOR
|
||||
&& packet.PacketTypeByte != Packet.PACKET_PING
|
||||
&& packet.PacketTypeByte != Packet.PACKET_POSSESS_ACTOR
|
||||
&& packet.PacketTypeByte != Packet.PACKET_DESTROY_ACTOR) {
|
||||
&& packet.PacketTypeByte != Packet.PACKET_DESTROY_ACTOR
|
||||
&& packet.PacketTypeByte != Packet.PACKET_ASSIGN_UUID
|
||||
&& packet.PacketTypeByte != Packet.PACKET_SEND_PLAYER_COUNT) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -241,15 +245,26 @@ public class ClientConnectionThread implements Runnable{
|
|||
actorToChangeModelID.SetModelID(stringdata);
|
||||
}
|
||||
break;
|
||||
case Packet.PACKET_SEND_PLAYER_COUNT:
|
||||
System.out.println("decoding player count packet");
|
||||
stringdata = Packet.DecodeAsString(packet.Data);
|
||||
PlayersOnline = Integer.parseInt(stringdata);
|
||||
break;
|
||||
case Packet.PACKET_ASSIGN_UUID:
|
||||
System.out.println("decoding UUID packet");
|
||||
clientUUID = Packet.DecodeAsString(packet.Data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int ServerPort = 25565;
|
||||
|
||||
public ClientConnectionThread(){
|
||||
Connected = true;
|
||||
try {
|
||||
SocketToServer = new Socket(ServerIP, 25565);
|
||||
SocketToServer = new Socket(ServerIP, ServerPort);
|
||||
SocketToServer.setSoTimeout(5);
|
||||
} catch (IOException e) {
|
||||
Connected = false;
|
||||
|
|
@ -267,6 +282,14 @@ public class ClientConnectionThread implements Runnable{
|
|||
}
|
||||
}
|
||||
|
||||
public static void RequestPlayerCount(){
|
||||
Packet packet = new Packet(Packet.PACKET_SEND_PLAYER_COUNT);
|
||||
packet.SetTargetType((byte) 0);
|
||||
packet.SetData(new byte[]{0});
|
||||
packet.SetID("NULL");
|
||||
OutGoingPacketQueue.add(packet);
|
||||
}
|
||||
|
||||
public static void FireWeapon(String ActorID, float Damage){
|
||||
Packet packet = new Packet(Packet.PACKET_FIRE_WEAPON);
|
||||
packet.SetTargetType((byte) 0);
|
||||
|
|
@ -300,7 +323,6 @@ public class ClientConnectionThread implements Runnable{
|
|||
if(in == null) return 0;
|
||||
|
||||
Packet newIncomingPacket = new Packet(in.readByte());
|
||||
|
||||
if(newIncomingPacket.PacketTypeByte == 5) {
|
||||
return 5;
|
||||
}
|
||||
|
|
@ -344,7 +366,7 @@ public class ClientConnectionThread implements Runnable{
|
|||
try {
|
||||
PacketRead = readPacket(in);
|
||||
} catch (SocketTimeoutException ignored) {
|
||||
// No incoming packet this moment. Continue so outgoing packets can still flush.
|
||||
|
||||
}
|
||||
|
||||
if(PacketRead == Packet.PACKET_PING){
|
||||
|
|
|
|||
|
|
@ -27,10 +27,20 @@ public class ServerConnectionThread implements Runnable{
|
|||
private String OwnedActorID;
|
||||
private final Socket clientSocket;
|
||||
private final UUID ClientID;
|
||||
private String PlayerDisplayName;
|
||||
public static int PlayersOnline = 0;
|
||||
|
||||
public static int ServerPort = 25565;
|
||||
|
||||
public final Queue<Packet> IncomingPacketQueue = new ConcurrentLinkedQueue<>();
|
||||
public final Queue<Packet> OutgoingPacketQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public void SetPlayerDisplayName(String displayName){
|
||||
this.PlayerDisplayName = displayName;
|
||||
}
|
||||
|
||||
public String GetPlayerDisplayName(){return PlayerDisplayName;}
|
||||
|
||||
public UUID GetClientID(){
|
||||
return ClientID;
|
||||
}
|
||||
|
|
@ -47,7 +57,6 @@ public class ServerConnectionThread implements Runnable{
|
|||
UUID uuid = UUID.randomUUID();
|
||||
ClientID = uuid;
|
||||
this.clientSocket = clientSocket;
|
||||
|
||||
try {
|
||||
this.clientSocket.setSoTimeout(5);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -78,6 +87,8 @@ public class ServerConnectionThread implements Runnable{
|
|||
}
|
||||
|
||||
private void InitialiseJoinedClient(){
|
||||
Packet PlayerCountPacket = CreatePlayerCountPacket(Server.ConnectedClients.size());
|
||||
Server.OutGoingPacketQueue.add(PlayerCountPacket);
|
||||
EngineInstance engineInstance = PrimaryRuntime.GetEngineInstance();
|
||||
IScene scene = engineInstance.scene();
|
||||
|
||||
|
|
@ -101,6 +112,8 @@ public class ServerConnectionThread implements Runnable{
|
|||
|
||||
BroadcastCreateActorPacket(player);
|
||||
SendPossessActorPacket(player.GetID());
|
||||
Packet UUIDUpdatePacket = CreatePlayerUUIDPacket(ClientID,this);
|
||||
Server.OutGoingPacketQueue.add(UUIDUpdatePacket);
|
||||
System.out.println("Queued possess packet for joining player's actor: " + player.GetID());
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +136,7 @@ public class ServerConnectionThread implements Runnable{
|
|||
}
|
||||
|
||||
if(PacketRead == Packet.PACKET_PING){
|
||||
WritePacket(new Packet(Packet.PACKET_PING),out);
|
||||
WritePacket(new Packet(Packet.PACKET_PING),out,this);
|
||||
}
|
||||
|
||||
if(PacketRead == -1) break;
|
||||
|
|
@ -131,10 +144,12 @@ public class ServerConnectionThread implements Runnable{
|
|||
if(!OutgoingPacketQueue.isEmpty()){
|
||||
Packet packet;
|
||||
while((packet = OutgoingPacketQueue.poll()) != null) {
|
||||
WritePacket(packet,out);
|
||||
WritePacket(packet,out,this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Packet PlayerCountPacket = CreatePlayerCountPacket(Server.ConnectedClients.size());
|
||||
Server.OutGoingPacketQueue.add(PlayerCountPacket);
|
||||
System.out.println("Connection Closing: " + Thread.currentThread() + "\n");
|
||||
} catch (Exception e) {
|
||||
System.out.println("Connection Closing: " + Thread.currentThread() + "\n");
|
||||
|
|
@ -188,10 +203,7 @@ public class ServerConnectionThread implements Runnable{
|
|||
|
||||
case Packet.PACKET_CLIENT_INPUT:
|
||||
if(!sender.OwnsActor(packet.TargetID)) return;
|
||||
|
||||
// Later: decode input commands here instead of trusting full transforms.
|
||||
// Example future data:
|
||||
// forward/back/left/right/jump/yaw/pitch/sequenceNumber
|
||||
//to be implemented later
|
||||
break;
|
||||
case Packet.PACKET_UPDATE_MODEL_ID:
|
||||
if(!packet.TargetID.equals(ConnectedClients.get(packet.ClientID).OwnedActorID)) {
|
||||
|
|
@ -200,6 +212,11 @@ public class ServerConnectionThread implements Runnable{
|
|||
Packet ReboundPacket = CreateUpdateModelIDPacket(packet.TargetID, Packet.DecodeAsString(packet.Data));
|
||||
Server.OutGoingPacketQueue.add(ReboundPacket);
|
||||
break;
|
||||
case Packet.PACKET_SEND_PLAYER_COUNT:
|
||||
if(!packet.TargetID.equals("NULL")) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +224,23 @@ public class ServerConnectionThread implements Runnable{
|
|||
return OwnedActorID != null && OwnedActorID.equals(actorID);
|
||||
}
|
||||
|
||||
public static Packet CreatePlayerUUIDPacket(UUID clientID, ServerConnectionThread sender){
|
||||
System.out.println("Creating UUID packet for client: " + clientID);
|
||||
Packet packet = new Packet(Packet.PACKET_ASSIGN_UUID);
|
||||
packet.SetTargetType((byte) 0);
|
||||
packet.SetData(clientID.toString().getBytes(StandardCharsets.UTF_8));
|
||||
packet.SetID("New Client");
|
||||
packet.ClientID = sender.ClientID;
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static Packet CreatePlayerCountPacket(int PlayerCount){
|
||||
Packet packet = new Packet(Packet.PACKET_SEND_PLAYER_COUNT);
|
||||
packet.SetTargetType((byte) 0);
|
||||
packet.SetData(Integer.toString(PlayerCount).getBytes(StandardCharsets.UTF_8));
|
||||
packet.SetID("New Client");
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static Packet CreateActorPacket(Actor actor){
|
||||
Packet newOutgoingPacket = new Packet(Packet.PACKET_CREATE_ACTOR);
|
||||
|
|
@ -337,8 +370,12 @@ public class ServerConnectionThread implements Runnable{
|
|||
return 0;
|
||||
}
|
||||
|
||||
public static void WritePacket(Packet outPacket, DataOutputStream Outgoing) throws IOException {
|
||||
if(Outgoing == null ) return;
|
||||
public static void WritePacket(Packet outPacket, DataOutputStream Outgoing, ServerConnectionThread client) throws IOException {
|
||||
if(Outgoing == null || outPacket.PacketTypeByte == Packet.PACKET_ASSIGN_UUID && outPacket.ClientID != client.ClientID){
|
||||
System.out.println(outPacket.PacketTypeByte == Packet.PACKET_ASSIGN_UUID ? "Packet Client ID: " + outPacket.ClientID + " != " + client.ClientID :
|
||||
"Packet not sent to client: " + outPacket.ClientID);
|
||||
return;
|
||||
}
|
||||
byte[] DataToSend = Packet.GetOutgoingData(outPacket);
|
||||
Outgoing.write(DataToSend);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue