sdk javahelp: Removed three outdated help files (updated versions exist already in different paths).
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8332 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
663a3ba7d5
commit
dde60c0792
@ -1,37 +0,0 @@ |
||||
<h1><a |
||||
name="jme3_headless_server">jME3 Headless Server</a></h1><div |
||||
class="level1"><p> When adding multiplayer to your game, you may find that your server needs to know about game state (e.g. where are players, objects? Was that a direct hit? etc.) You can code all this up yourself, but there's an easier way.</p><p> It's very easy to change your current (client) game to function as a server as well.</p></div><h2><a |
||||
name="client_code">Client Code</a></h2><div |
||||
class="level2"><p> First, let's take a look at the default way of creating a new game (in its simplest form):</p><pre>public static void main(String[] args) { |
||||
Application app = new Main(); |
||||
app.start(); |
||||
}</pre></div><h2><a |
||||
name="headless_server_code">Headless Server Code</a></h2><div |
||||
class="level2"><p> Now, with a simple change you can start your game in Headless mode. This means that all input and audio/visual output will be ignored. That's a good thing for a server.</p><pre>import com.jme3.system.JmeContext; |
||||
import com.jme3.system.JmeContext.Type; |
||||
|
||||
public static void main(String[] args) { |
||||
Application app = new Main(); |
||||
app.start(JmeContext.Type.Headless); |
||||
}</pre><p><p><div |
||||
class="noteclassic">Although all input/output is ignored, the server <em>does</em> keep game state and <em>does</em> call the <code>simpleUpdate()</code> as expected.</div></p></p></div><h2><a |
||||
name="next_steps">Next steps</a></h2><div |
||||
class="level2"><p> Okay, so you can now start your game in a headless 'server mode', where to go from here?</p><ul><li |
||||
class="level1"><div |
||||
class="li"> Parse <code>String[] args</code> from the <code>main</code>-method to enable server mode on demand (e.g. start your server like <code>java -jar mygame.jar –server</code>.</div></li><li |
||||
class="level1"><div |
||||
class="li"> Integrate <a |
||||
href="/com/jme3/gde/core/docs/spidermonkey.html">SpiderMonkey</a>, to provide game updates to the server over a network.</div></li><li |
||||
class="level1"><div |
||||
class="li"> Only execute code that's needed. (E.g. place all rendering code inside an <code>if (servermode)</code>-block) (or <code>if (!servermode)</code> for the client).</div></li><li |
||||
class="level1"><div |
||||
class="li"> Add decent <a |
||||
href="/com/jme3/gde/core/docs/jme3/advanced/logging.html">logging</a> so your server actually makes sense.</div></li></ul><div |
||||
class="tags"><span> <a |
||||
href="/wiki/doku.php/tag:intermediate?do=showtag&tag=tag%3Aintermediate">intermediate</a>, <a |
||||
href="/wiki/doku.php/tag:server?do=showtag&tag=tag%3Aserver">server</a>, <a |
||||
href="/wiki/doku.php/tag:spidermonkey?do=showtag&tag=tag%3Aspidermonkey">spidermonkey</a>, <a |
||||
href="/wiki/doku.php/tag:headless?do=showtag&tag=tag%3Aheadless">headless</a>, <a |
||||
href="/wiki/doku.php/tag:network?do=showtag&tag=tag%3Anetwork">network</a>, <a |
||||
href="/wiki/doku.php/tag:documentation?do=showtag&tag=tag%3Adocumentation">documentation</a> </span></div></div> |
||||
<p><em><a href="http://jmonkeyengine.org/wiki/doku.php/jme3:intermediate:headlessserver?do=export_xhtmlbody">view online version</a></em></p> |
@ -1,204 +0,0 @@ |
||||
<h3><a |
||||
name="terrain_collision">Terrain Collision</a></h3><div |
||||
class="level3"><p> <strong>*Work in progress</strong>*</p><p> This page will extend (not the Java keyword!) the Hello_Terrain tutorial in a few small ways in order to show you a quick way to create a Collision Shape out of the map we have generated. A Collision Shape allows a player (who is also a Collision Shape in this tutorial) to collide with the map, i.e. clip, walk on, stand on, etc. in order to create the type of world and interactivity most gamers are familiar with in FPS or MMOs.</p><div |
||||
class="tags"><span> <a |
||||
href="/wiki/doku.php/tag:about?do=showtag&tag=tag%3Aabout">about</a> </span></div></div><h3><a |
||||
name="sample_code">Sample Code</a></h3><div |
||||
class="level3"><pre>package mygame; |
||||
|
||||
import jme3tools.converters.ImageToAwt; |
||||
import com.jme3.app.SimpleBulletApplication; |
||||
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape; |
||||
import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape; |
||||
import com.jme3.bullet.nodes.PhysicsCharacterNode; |
||||
import com.jme3.bullet.nodes.PhysicsNode; |
||||
import com.jme3.input.KeyInput; |
||||
import com.jme3.input.controls.ActionListener; |
||||
import com.jme3.input.controls.KeyTrigger; |
||||
import com.jme3.material.Material; |
||||
import com.jme3.math.Vector3f; |
||||
import com.jme3.renderer.Camera; |
||||
import com.jme3.terrain.geomipmap.TerrainLodControl; |
||||
import com.jme3.terrain.heightmap.AbstractHeightMap; |
||||
import com.jme3.terrain.heightmap.ImageBasedHeightMap; |
||||
import com.jme3.terrain.geomipmap.TerrainQuad; |
||||
import com.jme3.texture.Texture; |
||||
import com.jme3.texture.Texture.WrapMode; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class Main extends SimpleBulletApplication { |
||||
|
||||
private TerrainQuad terrain; |
||||
PhysicsCharacterNode player; |
||||
Boolean left = false, right = false, up = false, down = false; |
||||
private Vector3f walkDirection = new Vector3f(); |
||||
|
||||
public static void main(String[] args) { |
||||
Main app = new Main(); |
||||
app.start(); |
||||
} |
||||
|
||||
@Override |
||||
public void simpleInitApp() { |
||||
setupKeys(); |
||||
setupPlayer(); |
||||
|
||||
Material terrain_mat; |
||||
PhysicsNode landscape; |
||||
|
||||
/** 1. Create terrain material and load four textures into it. */ |
||||
terrain_mat = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md"); |
||||
|
||||
/** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */ |
||||
terrain_mat.setTexture("m_Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png")); |
||||
|
||||
/** 1.2) Add GRASS texture into the red layer (m_Tex1). */ |
||||
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); |
||||
grass.setWrap(WrapMode.Repeat); |
||||
terrain_mat.setTexture("m_Tex1", grass); |
||||
terrain_mat.setFloat("m_Tex1Scale", 64f); |
||||
|
||||
/** 1.3) Add DIRT texture into the green layer (m_Tex2) */ |
||||
Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg"); |
||||
dirt.setWrap(WrapMode.Repeat); |
||||
terrain_mat.setTexture("m_Tex2", dirt); |
||||
terrain_mat.setFloat("m_Tex2Scale", 32f); |
||||
|
||||
/** 1.4) Add ROAD texture into the blue layer (m_Tex3) */ |
||||
Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); |
||||
rock.setWrap(WrapMode.Repeat); |
||||
terrain_mat.setTexture("m_Tex3", rock); |
||||
terrain_mat.setFloat("m_Tex3Scale", 128f); |
||||
|
||||
/** 2. Create the height map */ |
||||
AbstractHeightMap heightmap = null; |
||||
Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png"); |
||||
heightmap = new ImageBasedHeightMap( |
||||
ImageToAwt.convert(heightMapImage.getImage(), false, true, 0)); |
||||
heightmap.load(); |
||||
|
||||
<span>/** 3. We have prepared material and heightmap. Now we create the actual terrain: |
||||
* 3.1) We create a TerrainQuad and name it "my terrain". |
||||
* 3.2) A good value for terrain tiles is 64x64 -- so we supply 64+1=65. |
||||
* 3.3) We prepared a heightmap of size 512x512 -- so we supply 512+1=513. |
||||
* 3.4) At last, we supply the prepared heightmap itself.*/</span> |
||||
terrain = new TerrainQuad("my terrain", 65, 513, heightmap.getHeightMap()); |
||||
|
||||
HeightfieldCollisionShape sceneShape = new HeightfieldCollisionShape(heightmap.getHeightMap()); |
||||
landscape = new PhysicsNode(terrain, sceneShape, 0); |
||||
|
||||
|
||||
/** 4. The LOD (level of detail) depends on were the camera is: */ |
||||
List<Camera> cameras = new ArrayList<Camera>(); |
||||
cameras.add(getCamera()); |
||||
TerrainLodControl control = new TerrainLodControl(terrain, cameras); |
||||
terrain.addControl(control); |
||||
|
||||
/** 5. We give the terrain its material, position & scale it, and attach it. */ |
||||
terrain.setMaterial(terrain_mat); |
||||
landscape.setLocalTranslation(0, -100, 0); |
||||
rootNode.attachChild(landscape); |
||||
getPhysicsSpace().add(landscape); |
||||
} |
||||
|
||||
@Override |
||||
public void simpleUpdate(float tpf) { |
||||
Vector3f camDir = cam.getDirection().clone().multLocal(0.2f); |
||||
Vector3f camLeft = cam.getLeft().clone().multLocal(0.1f); |
||||
walkDirection.set(0, 0, 0); |
||||
if (left) { |
||||
walkDirection.addLocal(camLeft); |
||||
} |
||||
if (right) { |
||||
walkDirection.addLocal(camLeft.negate()); |
||||
} |
||||
if (up) { |
||||
walkDirection.addLocal(camDir); |
||||
walkDirection.y = 0; |
||||
} |
||||
if (down) { |
||||
walkDirection.addLocal(camDir.negate()); |
||||
walkDirection.y = 0; |
||||
} |
||||
player.setWalkDirection(walkDirection); |
||||
cam.setLocation(player.getLocalTranslation()); |
||||
} |
||||
|
||||
public void setupPlayer() { |
||||
player = new PhysicsCharacterNode(new CapsuleCollisionShape(1.2f, 3f, 1), .05f); |
||||
player.setJumpSpeed(20); //10 default |
||||
player.setFallSpeed(30); //30 default |
||||
player.setGravity(30); //30 default |
||||
player.setLocalTranslation(new Vector3f(0f, 250f, 150f)); |
||||
rootNode.attachChild(player); |
||||
getPhysicsSpace().add(player); |
||||
} |
||||
|
||||
private void setupKeys() { |
||||
inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_A)); |
||||
inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D)); |
||||
inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W)); |
||||
inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S)); |
||||
inputManager.addMapping("Jumps", new KeyTrigger(KeyInput.KEY_SPACE)); |
||||
inputManager.addListener(actionListener, new String[]{"Lefts", "Rights", "Ups", |
||||
"Downs", "Jumps"}); |
||||
} |
||||
private ActionListener() { |
||||
|
||||
public void onAction(String binding, boolean value, float tpf) { |
||||
if (binding.equals("Lefts")) { |
||||
if (value && player.onGround()) { |
||||
left = true; |
||||
} else { |
||||
left = false; |
||||
} |
||||
} else if (binding.equals("Rights")) { |
||||
if (value && player.onGround()) { |
||||
right = true; |
||||
} else { |
||||
right = false; |
||||
} |
||||
} else if (binding.equals("Ups")) { |
||||
if (value && player.onGround()) { |
||||
up = true; |
||||
} else { |
||||
up = false; |
||||
} |
||||
} else if (binding.equals("Downs")) { |
||||
if (value && player.onGround()) { |
||||
down = true; |
||||
} else { |
||||
down = false; |
||||
} |
||||
} else if (binding.equals("Jumps") && player.onGround()) { |
||||
player.jump(); |
||||
} |
||||
} |
||||
}; |
||||
}</pre></div><h3><a |
||||
name="what_s_going_on">What's Going On?</a></h3><div |
||||
class="level3"><p> To try this code, go into a New Project → JME3 → BasicGame using the default settings (if you haven't already made a default project before) the name should be BasicGame and the package would be called myGame, then just paste this over the entire preconstructed main.java text. Then Add the jme3-test-data library which is available through your library list. This should compile and run from there.</p></div><h3><a |
||||
name="explaining_the_code">Explaining the Code</a></h3><div |
||||
class="level3"><p> I will only briefly describe the sections that are covered in the original Hello_Terrain. Most detail will be given to the additives.</p><p> Imports are to bring in the appropriate class definitions.</p><pre>private TerrainQuad terrain;</pre><p> Holds our map.</p><pre>PhysicsCharacterNode player;</pre><p> Creates our character in the style of FPS that many gamers are familiar with.</p><pre>Boolean left = false, right = false, up = false, down = false;</pre><p> Variables for creating fluid movement.</p><pre>private Vector3f walkDirection = new Vector3f();</pre><p> The direction we determine from combinations of the booleans.</p><p> The main function is standard. |
||||
In simpleInit we run setupKeys() first and create the common WASD and SPACEBAR to jump.</p><pre>inputManager.addListener(actionListener, new String[]{"Lefts", "Rights", "Ups", "Downs", "Jumps"})</pre><p> This line indicates our actionListener function and what to do when each command (the string names) is sent.</p><p> The onAction function basically sets the booleans true based on which directions we're pressing or makes us jump. |
||||
The simpleUpdate function constants changed our direction based on the boolean (ie the directions) we're pressing.</p><p> The real collisioning happens in these parts;</p><pre>player = new PhysicsCharacterNode(new CapsuleCollisionShape(1.2f, 3f, 1), .05f); |
||||
rootNode.attachChild(player); |
||||
getPhysicsSpace().add(player); |
||||
HeightfieldCollisionShape sceneShape = new HeightfieldCollisionShape(heightmap.getHeightMap()); |
||||
landscape = new PhysicsNode(terrain, sceneShape, 0); |
||||
landscape.setLocalTranslation(0, -100, 0); |
||||
rootNode.attachChild(landscape); |
||||
getPhysicsSpace().add(landscape);</pre><p> The first chunk makes our player into a collision shape that's a capsule, kinda like a human right? And then attaches it to the rootNode and gets it's physics (important!). |
||||
The second chunk feeds the heightmap we made into a heightfield collision shape generator to create the collidable shape of the land mass. |
||||
The third chunk sets our land and it's collision down some, attaches em to root, and gets the physics.</p></div><h3><a |
||||
name="conclusion">Conclusion</a></h3><div |
||||
class="level3"><p> You should spawn high up in the area and fall down to the map, giving you a few seconds to survey the domain. Then walk around and see how you like the lay of the land.</p><hr |
||||
/><p> See also:</p><ul><li |
||||
class="level1"><div |
||||
class="li"> <a |
||||
href="/com/jme3/gde/core/docs/jme3/beginner/hello_terrain.html">Hello Terrain</a>,</div></li><li |
||||
class="level1"><div |
||||
class="li"> <a |
||||
href="/com/jme3/gde/core/docs/jme3/advanced/terrain.html">Terrain</a></div></li></ul></div> |
||||
<p><em><a href="http://jmonkeyengine.org/wiki/doku.php/jme3:intermediate:terrain_collision?do=export_xhtmlbody">view online version</a></em></p> |
Loading…
Reference in new issue