Hello Guest

3D First Person Frame Rate Issues

  • 4 Replies
  • 4941 Views
3D First Person Frame Rate Issues
« 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:

Code: [Select]
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:

Code: [Select]
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!

*

Offline KaiHH

  • ****
  • 334
Re: 3D First Person Frame Rate Issues
« Reply #1 on: September 11, 2018, 20:04:35 »
It's probably not a good idea to call Mouse.setGrabbed(true) in your game everytime you move the mouse.

Re: 3D First Person Frame Rate Issues
« Reply #2 on: September 12, 2018, 03:21:36 »
It's probably not a good idea to call Mouse.setGrabbed(true) in your game everytime you move the mouse.

Thanks, this helped, but still dropping frames whenever the mouse is moved.

*

Offline KaiHH

  • ****
  • 334
Re: 3D First Person Frame Rate Issues
« Reply #3 on: September 12, 2018, 07:16:40 »
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.

Re: 3D First Person Frame Rate Issues
« Reply #4 on: September 12, 2018, 13:19:11 »
Code: [Select]
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.