hi,
Pleas someone help, I was making game client server architecture. it was working, player can move in all direction but on server i was using :
getGameWorldById(worldId).start();
And i decided use:
getGameWorldById(worldId).start(JmeContext.Type.Headless);
And it’s gone terrible, nothing was working, simpleUpdate looping each 5-15 seconds, just disaster. Phisics is not calculating anymore.
sometimes simpleUpdate loop runs fast and after while stops and go slow.
[java]
@Override
public void simpleUpdate(float ftp) {
for (Player pl : allRoomPlayers) {
System.out.println(pl.getName() + " zaidejas " + pl.getPlayerController().B_FOWARD);
Vector3f modelFowardDir = pl.getPlayerController().getPlayerNode().getWorldRotation().mult(Vector3f.UNIT_Z);
//go foward or backward
walkDirection.set(0, 0, 0);
if (pl.getPlayerController().B_FOWARD) {
System.out.println("foward pressed ");
walkDirection.addLocal(modelFowardDir.mult(14f));
pl.getPlayerController().getPlayerControl().setWalkDirection(walkDirection);
} else if (pl.getPlayerController().B_BACKWARD) {
walkDirection.addLocal(modelFowardDir.mult(pl.getSpeed()).negate());
}
pl.getPlayerController().getPlayerControl().setWalkDirection(walkDirection);
positionMessage.viewDirection = pl.getPlayerController().getPlayerControl().getViewDirection();
positionMessage.location = pl.getPlayerController().getPlayerNode().getLocalTranslation();
positionMessage.name = pl.getName();
this.sendToAllPlayers(positionMessage);
}
}
[/java]
this is part of my code, it was working, but after changed mode in headless everything have stop. Can someone give advice how i can fix it ?
After couple hours:
I have figured out one thing, I can create new world by creating new state AbstractAppState.
Is it ok to create new state for each new world in my game ?
in one world will be max 6 people 3x3
Its very simple
You need to create main in headless
[java]
public static void main(String[] args) {
ServerMain app = new ServerMain();
app.start(JmeContext.Type.Headless);
}
[/java]
After it you need create new game world
[java]
private void startGame(final int worldId) {
GameWorld gw = new GameWorld(worldId);
stateManager.attach(gw);
}
[/java]
GameWorld class should be laike:
public class GameWorld extends AbstractAppState {
private int id;
private SimpleApplication app;
private Node rootNode;
private AssetManager assetManager;
private AppStateManager stateManager;
// separated physics world
private BulletAppState bulletAppState;
public GameWorld(int id) {
this.id = id;
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app = (SimpleApplication) app; // can cast Application to something more specific
this.rootNode = this.app.getRootNode();
this.assetManager = this.app.getAssetManager();
this.stateManager = this.app.getStateManager();
bulletAppState = new BulletAppState(); //<-- question about this
}
}
[/java]
sorry if i have made some mistakes, I just was taking parts of my code
I just have question is it okay create new worlds like this ? And for each world new BulletAppState ?