LWJGL Forum
Programming => Lightweight Java Gaming Library => Topic started by: GhostAssasin105 on September 11, 2018, 19:18:46
-
Hi,
I'm currently coding a 3D game in lwjgl 2, and have a problem with my frame rate. I have a key based system of moving the camera, and a mouse based system of looking around, each contained in separate methods. Whenever I move the camera, the game runs at 60fps, however, when I move the mouse to look around, the frame rate drops until I stop moving the mouse.
The look around code:
public void moveMouse(Camera cam) {
int dx = Mouse.getDX();
int dy = Mouse.getDY();
if(inMenu == false) {
Mouse.setGrabbed(true);
cam.yaw(dx * 0.05f);
cam.pitch(dy * -0.05f);
} else {
Mouse.setGrabbed(false);
}
}
and the player movement code:
if (Keyboard.isKeyDown(Keyboard.KEY_W))
{
camera.walkForward(movementSpeed*dt);
}
if (Keyboard.isKeyDown(Keyboard.KEY_S))
{
camera.walkBackwards(movementSpeed*dt);
}
if (Keyboard.isKeyDown(Keyboard.KEY_A))
{
camera.strafeLeft(movementSpeed*dt);
}
if (Keyboard.isKeyDown(Keyboard.KEY_D))
{
camera.strafeRight(movementSpeed*dt);
}
if (Keyboard.isKeyDown(Keyboard.KEY_E))
{
camera.rollLeft(0.5f*dt);
}
*I'm trying to reveal as little code as possible as I plan to market this game in the near future.
Hope I provided enough evidence. Thanks in advance!
-
It's probably not a good idea to call Mouse.setGrabbed(true) (https://github.com/LWJGL/lwjgl/blob/master/src/java/org/lwjgl/input/Mouse.java#L647-L673) in your game everytime you move the mouse.
-
It's probably not a good idea to call Mouse.setGrabbed(true) (https://github.com/LWJGL/lwjgl/blob/master/src/java/org/lwjgl/input/Mouse.java#L647-L673) in your game everytime you move the mouse.
Thanks, this helped, but still dropping frames whenever the mouse is moved.
-
So, how does your moveMouse() method look like now? And have you tried a profiler? You can get fully-functional evaluation versions of good Java profiling tools to see where moveMouse() is spending most of its time.
-
public void moveMouse(Camera cam) {
int dx = Mouse.getDX();
int dy = Mouse.getDY();
if(inMenu == false) {
cam.yaw(dx * 0.05f);
cam.pitch(dy * -0.05f);
} else {
Mouse.setGrabbed(false);
}
}
I simply removed the Mouse.setGrabbed(true); function, and added it into another method.