diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..da5eaf0 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.j3o filter=lfs diff=lfs merge=lfs -text diff --git a/assets/Materials/Generated/model2-Hair001_baked_006.j3m b/assets/Materials/Generated/model2-Hair001_baked_006.j3m new file mode 100644 index 0000000..0a830cc --- /dev/null +++ b/assets/Materials/Generated/model2-Hair001_baked_006.j3m @@ -0,0 +1,27 @@ +Material MyMaterial : Common/MatDefs/Light/PBRLighting.j3md { + MaterialParameters { + Glossiness : 1.0 + EmissivePower : 3.0 + BaseColor : 1.0 1.0 1.0 1.0 + ParallaxHeight : 0.05 + Metallic : 0.0 + BackfaceShadows : false + Roughness : 0.0 + NormalType : -1.0 + Emissive : 0.0 0.0 0.0 1.0 + EmissiveIntensity : 2.0 + BaseColorMap : Texture2D[name=image6.png, image=Image[size=1024x256, format=ABGR8, id=323]]:returned null key + Specular : 1.0 1.0 1.0 1.0 + } + AdditionalRenderState { + PointSprite On + FaceCull Off + AlphaTestFalloff 0.0 + DepthWrite On + ColorWrite On + PolyOffset 0.0 0.0 + DepthTest On + Blend Off + Wireframe Off + } +} diff --git a/assets/Materials/Generated/model2-Hair001_baked_2391.j3m b/assets/Materials/Generated/model2-Hair001_baked_2391.j3m new file mode 100644 index 0000000..644fd8f --- /dev/null +++ b/assets/Materials/Generated/model2-Hair001_baked_2391.j3m @@ -0,0 +1,23 @@ +Material MyMaterial : Common/MatDefs/Light/Lighting.j3md { + MaterialParameters { + Diffuse : 0.64000005 0.64000005 0.64000005 1.0 + UseMaterialColors : true + ParallaxHeight : 0.05 + Ambient : 1.0 1.0 1.0 1.0 + BackfaceShadows : false + DiffuseMap : Texture2D[name=Atlas_40637.png, image=Image[size=8192x4096, format=RGBA8, id=481]]:returned null key + Specular : 0.4 0.4 0.4 1.0 + Shininess : 128.0 + } + AdditionalRenderState { + PointSprite On + FaceCull Back + AlphaTestFalloff 0.0 + DepthWrite On + ColorWrite On + PolyOffset 0.0 0.0 + DepthTest On + Blend Off + Wireframe Off + } +} diff --git a/assets/Materials/PinkHair.j3m b/assets/Materials/PinkHair.j3m new file mode 100644 index 0000000..be5428c --- /dev/null +++ b/assets/Materials/PinkHair.j3m @@ -0,0 +1,9 @@ +Material PinkHair : Common/MatDefs/Light/Lighting.j3md { + MaterialParameters { + Diffuse : 1.0 0.2 1.0 1.0 + VertexLighting : false + UseMaterialColors : true + } + AdditionalRenderState { + } +} diff --git a/assets/Models/Oto.mesh.j3o b/assets/Models/Oto.mesh.j3o index d35803a..78a56be 100644 Binary files a/assets/Models/Oto.mesh.j3o and b/assets/Models/Oto.mesh.j3o differ diff --git a/assets/Models/model5/model5.j3o b/assets/Models/model5/model5.j3o new file mode 100644 index 0000000..22e7515 --- /dev/null +++ b/assets/Models/model5/model5.j3o @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:176f45a93d4e1074dd77f53868dba0a1b05dbbd858a4f2a2b67311ec13308331 +size 120792010 diff --git a/assets/Models/model5/model5.j3odata b/assets/Models/model5/model5.j3odata new file mode 100644 index 0000000..f73bdad --- /dev/null +++ b/assets/Models/model5/model5.j3odata @@ -0,0 +1,3 @@ +# +#Sun Jun 28 15:49:26 KST 2020 +ORIGINAL_PATH=Models/model5/model5.gltf diff --git a/assets/Models/test ava/test ava.j3o b/assets/Models/test ava/test ava.j3o index d33fb76..ecc453d 100644 Binary files a/assets/Models/test ava/test ava.j3o and b/assets/Models/test ava/test ava.j3o differ diff --git a/assets/Scenes/TestLevel.j3o b/assets/Scenes/TestLevel.j3o index 65061fd..5a454a5 100644 Binary files a/assets/Scenes/TestLevel.j3o and b/assets/Scenes/TestLevel.j3o differ diff --git a/assets/Scenes/TestLevel2.j3o b/assets/Scenes/TestLevel2.j3o new file mode 100644 index 0000000..d5a1c53 --- /dev/null +++ b/assets/Scenes/TestLevel2.j3o @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7a1e76295163b1d07e43a734e54c4e8ea440ebb6af63240eb015a095311d6765 +size 155133 diff --git a/assets/Scenes/TestLevel2.j3odata b/assets/Scenes/TestLevel2.j3odata new file mode 100644 index 0000000..8a842a7 --- /dev/null +++ b/assets/Scenes/TestLevel2.j3odata @@ -0,0 +1,3 @@ +# +#Wed Jun 17 10:55:55 KST 2020 +ORIGINAL_PATH=Scenes/TestLevel.j3o diff --git a/build/classes/mygame/Main.class b/build/classes/mygame/Main.class index 98689ab..083f205 100644 Binary files a/build/classes/mygame/Main.class and b/build/classes/mygame/Main.class differ diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index bd3a23f..f15cd3b 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -5,8 +5,10 @@ file:/E:/GameProjects/Rabi-Bounce-Bounce-R/src/mygame/Main.java file:/E:/GameProjects/Rabi-Bounce-Bounce-R/src/mygame/appstate/RunLevel.java + file:/E:/GameProjects/Rabi-Bounce-Bounce-R/src/mygame/control/PhysicsControl.java file:/E:/GameProjects/Rabi-Bounce-Bounce-R/src/mygame/control/PlayableCharacter.java file:/E:/GameProjects/Rabi-Bounce-Bounce-R/src/mygame/server/ServerMain.java + file:/E:/GameProjects/Rabi-Bounce-Bounce-R/src/mygame/server/Instance.java file:/E:/GameProjects/Rabi-Bounce-Bounce-R/src/mygame/control/NetworkPlayableCharacter.java diff --git a/nbproject/project.properties b/nbproject/project.properties index 3e5ae05..44764bc 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -51,8 +51,8 @@ javac.deprecation=false javac.external.vm=false javac.processorpath=\ ${javac.classpath} -javac.source=1.7 -javac.target=1.7 +javac.source=1.8 +javac.target=1.8 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff --git a/src/mygame/Main.java b/src/mygame/Main.java index 3f284a3..3287803 100644 --- a/src/mygame/Main.java +++ b/src/mygame/Main.java @@ -23,6 +23,7 @@ import mygame.server.ServerMain; import mygame.server.ServerMain.EntityMessage; import mygame.server.ServerMain.JoinMessage; import mygame.server.ServerMain.PlayerActionMessage; +import mygame.server.ServerMain.PlayerLeaveMessage; import mygame.server.ServerMain.PlayerPositionMessage; import mygame.server.ServerMain.ServerMessage; import mygame.server.ServerMain.SyncLevelMessage; @@ -44,6 +45,7 @@ public class Main extends SimpleApplication implements ClientStateListener{ client.addMessageListener(new ClientListener(), JoinMessage.class); //client.addMessageListener(new ClientListener(), PlayerJoinMessage.class); client.addMessageListener(new ClientListener(), PlayerActionMessage.class); + client.addMessageListener(new ClientListener(), PlayerLeaveMessage.class); client.addClientStateListener(this); client.start(); @@ -68,8 +70,9 @@ public class Main extends SimpleApplication implements ClientStateListener{ public void simpleInitApp() { flyCam.setEnabled(false); //flyCam.setMoveSpeed(50); - level = new RunLevel("TestLevel"); + level = new RunLevel("TestLevel2"); stateManager.attach(level); + //stateManager.detach(level); } @Override @@ -110,6 +113,9 @@ public class Main extends SimpleApplication implements ClientStateListener{ } else if (message instanceof JoinMessage) { level.getPlayerJoinMessage((JoinMessage)message); + } else + if (message instanceof PlayerLeaveMessage) { + level.getPlayerLeaveMessage((PlayerLeaveMessage)message); } } } diff --git a/src/mygame/appstate/RunLevel.java b/src/mygame/appstate/RunLevel.java index 33bb334..3bba9df 100644 --- a/src/mygame/appstate/RunLevel.java +++ b/src/mygame/appstate/RunLevel.java @@ -34,7 +34,9 @@ import mygame.control.PlayableCharacter; import mygame.server.ServerMain.JoinMessage; import mygame.server.ServerMain.SyncLevelMessage; import mygame.server.Entity; +import mygame.server.ServerMain; import mygame.server.ServerMain.PlayerActionMessage; +import mygame.server.ServerMain.PlayerLeaveMessage; public class RunLevel extends BaseAppState @@ -50,10 +52,13 @@ public class RunLevel extends BaseAppState private List players = new ArrayList<>(); private Vector3f[] player_locations; public static List queuedPlayerActionMessages = new ArrayList<>(); + public static List queuedPlayerJoinMessages = new ArrayList<>(); + public static List queuedPlayerLeaveMessages = new ArrayList<>(); public static List queuedSyncLevelMessages = new ArrayList<>(); public static Node world; Node entityNode; public static Node networkedPlayersNode; + float timer; public RunLevel(String levelName) { //System.out.println("In here. Initialize"); @@ -94,7 +99,7 @@ public class RunLevel extends BaseAppState //DirectionalLight sceneLight = (DirectionalLight)world.getLocalLightList().get(0); Node player = (Node)assetManager.loadModel("Models/Oto/Oto.mesh.xml"); - Node playerNode = new Node(); + Node playerNode = new Node("Player"); playerNode.attachChild(player); playerNode.addControl(new PlayableCharacter()); @@ -157,7 +162,7 @@ public class RunLevel extends BaseAppState reflectedScene.attachChild(TestLevel); reflectedScene.attachChild(playerNode); reflectedScene.attachChild(SkyFactory.createSky(assetManager,"Textures/Sky/Bright/BrightSky.dds",false)); - + FilterPostProcessor fpp = new FilterPostProcessor(assetManager); //viewPort.addProcessor(fpp); Vector3f lightDir = new Vector3f(-2.9f,-1.2f,-5.8f); @@ -202,6 +207,8 @@ public class RunLevel extends BaseAppState protected void cleanup(Application app) { //TODO: clean up what you initialized in the initialize method, //e.g. remove all spatials from rootNode + //((Node)rootNode.getChild("Player")).removeControl(PlayableCharacter.class); + ((Node)rootNode.getChild("Reflected Scene")).detachAllChildren(); } //onEnable()/onDisable() can be used for managing things that should @@ -230,6 +237,30 @@ public class RunLevel extends BaseAppState createPlayers(); } queuedSyncLevelMessages.clear(); + for (JoinMessage msg : queuedPlayerJoinMessages) { + MakeNetworkPlayer(msg.getEntity().id,msg.getEntity().position); + players.add(msg.getEntity().id); + createPlayers(); + System.out.println(msg); + } + queuedPlayerJoinMessages.clear(); + for (PlayerLeaveMessage msg : queuedPlayerLeaveMessages) { + for (int i=0;i5) { + main.getStateManager().detach(this); + this.setEnabled(false); + }*/ } @Override @@ -259,9 +290,7 @@ public class RunLevel extends BaseAppState public void getPlayerJoinMessage(JoinMessage playerJoinMessage) { JoinMessage msg = playerJoinMessage; - MakeNetworkPlayer(msg.getEntity().id,msg.getEntity().position); - players.add(msg.getEntity().id); - createPlayers(); + queuedPlayerJoinMessages.add(msg); } private void MakeNetworkPlayer(int id, Vector3f pos) { @@ -290,4 +319,9 @@ public class RunLevel extends BaseAppState networkPlayer.setUserData("lastCamLeftDir", playerActionMessage.getCameraLeft()); } + public void getPlayerLeaveMessage(PlayerLeaveMessage playerLeaveMessage) { + PlayerLeaveMessage msg = playerLeaveMessage; + queuedPlayerLeaveMessages.add(msg); + } + } \ No newline at end of file diff --git a/src/mygame/control/PlayableCharacter.java b/src/mygame/control/PlayableCharacter.java index 995146c..ab5c9c7 100644 --- a/src/mygame/control/PlayableCharacter.java +++ b/src/mygame/control/PlayableCharacter.java @@ -25,6 +25,7 @@ import com.jme3.scene.Spatial; import com.jme3.scene.control.AbstractControl; import com.jme3.scene.control.Control; import java.io.IOException; +import static mygame.Main.level; import static mygame.Main.main; import mygame.server.ServerMain.PlayerActionMessage; import mygame.server.ServerMain.PlayerPositionMessage; @@ -60,34 +61,40 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone @Override public void setSpatial(Spatial spatial) { super.setSpatial(spatial); - //control = spatial.getControl(BetterCharacterControl.class); - Node myNode = (Node)spatial; - - physics = new PhysicsControl( - 0.1f, - -0.25f, - 5f - ); - myNode.addControl(physics); - - control = ((Node)spatial).getChild(0).getControl(AnimControl.class); - control.addListener(this); - channel = control.createChannel(); - channel.setAnim("stand"); - /*channel_lowerbody = control.createChannel(); - channel_lowerbody.addBone("hip.right"); - channel_lowerbody.addBone("hip.left");*/ //There is no strafing animation - - main.getInputManager().addMapping("WalkForward", new KeyTrigger(KeyInput.KEY_W)); - main.getInputManager().addMapping("WalkBackward", new KeyTrigger(KeyInput.KEY_S)); - main.getInputManager().addMapping("StrafeLeft", new KeyTrigger(KeyInput.KEY_A)); - main.getInputManager().addMapping("StrafeRight", new KeyTrigger(KeyInput.KEY_D)); - main.getInputManager().addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE)); - main.getInputManager().addListener(this, "WalkForward"); - main.getInputManager().addListener(this, "WalkBackward"); - main.getInputManager().addListener(this, "StrafeRight"); - main.getInputManager().addListener(this, "StrafeLeft"); - main.getInputManager().addListener(this, "Jump"); + if (spatial!=null) { + //control = spatial.getControl(BetterCharacterControl.class); + Node myNode = (Node)spatial; + + physics = new PhysicsControl( + 0.1f, + -0.25f, + 5f + ); + myNode.addControl(physics); + + control = (((Node)spatial).getChild(0)).getControl(AnimControl.class); + //System.out.println(control.getAnimationNames()); + control.addListener(this); + channel = control.createChannel(); + channel.setAnim("stand"); + channel.setLoopMode(LoopMode.Cycle); + /*channel_lowerbody = control.createChannel(); + channel_lowerbody.addBone("hip.right"); + channel_lowerbody.addBone("hip.left");*/ //There is no strafing animation + + main.getInputManager().addMapping("WalkForward", new KeyTrigger(KeyInput.KEY_W)); + main.getInputManager().addMapping("WalkBackward", new KeyTrigger(KeyInput.KEY_S)); + main.getInputManager().addMapping("StrafeLeft", new KeyTrigger(KeyInput.KEY_A)); + main.getInputManager().addMapping("StrafeRight", new KeyTrigger(KeyInput.KEY_D)); + main.getInputManager().addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE)); + main.getInputManager().addListener(this, "WalkForward"); + main.getInputManager().addListener(this, "WalkBackward"); + main.getInputManager().addListener(this, "StrafeRight"); + main.getInputManager().addListener(this, "StrafeLeft"); + main.getInputManager().addListener(this, "Jump"); + } else { + main.getInputManager().removeListener(this); + } } /** Implement your spatial's behaviour here. @@ -216,6 +223,7 @@ public class PlayableCharacter extends AbstractControl implements Savable, Clone switch (name) { case "Jump":{ if (isOnGround() || physics.airTime<=physics.walkOffTime) { + //System.out.println("Jump"); physics.jump(); if (!(this instanceof NetworkPlayableCharacter)) { //Only send if this is the source client. PlayerActionMessage action = new PlayerActionMessage(name,"",main.client.getId(),spatial.getLocalTranslation(),spatial.getLocalRotation(),main.getCamera().getDirection(),main.getCamera().getLeft()); diff --git a/src/mygame/server/Instance.java b/src/mygame/server/Instance.java index 0a0a8ff..0e063fa 100644 --- a/src/mygame/server/Instance.java +++ b/src/mygame/server/Instance.java @@ -27,6 +27,7 @@ public class Instance { protected HashMap lastKnownPositions = new HashMap<>(); protected List entities = new ArrayList<>(); //Entity data specific to this instance. List nullEntities = new ArrayList<>(); //A list of "null" entities. When adding new entities, these slots will be consumed first. + public int INSTANCE_ID = -1; Instance(String levelName) { this.levelName = levelName; } diff --git a/src/mygame/server/ServerMain.java b/src/mygame/server/ServerMain.java index d327808..3ff7633 100644 --- a/src/mygame/server/ServerMain.java +++ b/src/mygame/server/ServerMain.java @@ -34,6 +34,7 @@ public class ServerMain extends SimpleApplication{ int clientIDMax = 0; public static HashMap instances = new HashMap<>(); public static HashMap players = new HashMap<>(); //The last instance location this player was seen in. + public static int INSTANCE_UNIQUE_ID = 0; ServerMain() { try { @@ -51,7 +52,9 @@ public class ServerMain extends SimpleApplication{ if (players.containsKey(conn.getId())) { Instance i = players.get(conn.getId()); i.removePlayer(conn); + server.broadcast(Filters.in(i.clients),new PlayerLeaveMessage(i.levelName,conn.getId())); } + players.remove(conn.getId()); } }); @@ -61,6 +64,7 @@ public class ServerMain extends SimpleApplication{ Serializer.registerClass(JoinMessage.class); Serializer.registerClass(SyncLevelMessage.class); Serializer.registerClass(Entity.class); + Serializer.registerClass(PlayerLeaveMessage.class); //Serializer.registerClass(PlayerJoinMessage.class); Serializer.registerClass(PlayerActionMessage.class); @@ -71,6 +75,7 @@ public class ServerMain extends SimpleApplication{ server.addMessageListener(new ServerListener(), SyncLevelMessage.class); //server.addMessageListener(new ServerListener(), PlayerJoinMessage.class); server.addMessageListener(new ServerListener(), PlayerActionMessage.class); + server.addMessageListener(new ServerListener(), PlayerLeaveMessage.class); server.start(); } catch (IOException ex) { @@ -123,8 +128,11 @@ public class ServerMain extends SimpleApplication{ } else if (message instanceof PlayerPositionMessage) { System.out.println("Position update for client "+source.getId()+". Broadcasting to others."); - server.broadcast(Filters.notEqualTo(source), message); - server.broadcast(Filters.in(source), new ServerMessage("Sent an update to other clients!")); + if (players.containsKey(source.getId())) { + Instance i = players.get(source.getId()); + SendToAllButMe(i, source, message); + } + //server.broadcast(Filters.in(source), new ServerMessage("Sent an update to other clients!")); } else if (message instanceof JoinMessage) { JoinMessage msg = (JoinMessage)message; @@ -139,6 +147,7 @@ public class ServerMain extends SimpleApplication{ instance = new Instance(msg.levelName); System.out.println("Instance "+msg.levelName+" does not exist. Creating... "+instance); CreateTestObj(instance); + instance.INSTANCE_ID=INSTANCE_UNIQUE_ID++; System.out.println(instance); instances.put(msg.levelName, instance); } @@ -146,15 +155,15 @@ public class ServerMain extends SimpleApplication{ instance.addPlayer(source); SyncLevelMessage sync = new SyncLevelMessage(instance.getEntities(),instance.getPlayers(),instance.getPlayerPositions()); server.broadcast(Filters.in(source),sync); - server.broadcast(Filters.notEqualTo(source),message); + SendToAllButMe(instance, source, message); } else if (message instanceof PlayerActionMessage) { System.out.println("Received player action message: "+message); - server.broadcast(Filters.notEqualTo(source), message); PlayerActionMessage msg = (PlayerActionMessage)message; if (players.containsKey(source.getId())) { Instance i = players.get(source.getId()); i.updatePosition(source.getId(),msg.getPosition()); + SendToAllButMe(i, source, message); } } /*else if (message instanceof PlayerJoinMessage) { @@ -162,6 +171,14 @@ public class ServerMain extends SimpleApplication{ server.broadcast(Filters.notEqualTo(source), message); }*/ } + + private void SendToAllButMe(Instance i, HostedConnection source, Message message) { + for (HostedConnection conn : i.clients) { + if (conn!=source) { + server.broadcast(Filters.in(conn),message); + } + } + } } public void CreateTestObj(Instance instance) { @@ -248,6 +265,28 @@ public class ServerMain extends SimpleApplication{ } } @Serializable + public static class PlayerLeaveMessage extends AbstractMessage { + String levelName; + int id; + + public PlayerLeaveMessage() { + } + + public PlayerLeaveMessage(String levelName, int id) { + this.levelName = levelName; + this.id=id; + } + + @Override + public String toString() { + return "Client ID "+id+" left. In Instance "+levelName.toString(); + } + + public int getId() { + return id; + } + } + @Serializable public static class SyncLevelMessage extends AbstractMessage { Entity[] entities; Integer[] clients;