Again, long post, so please read in its entirety. To answer your question, nope, not doing anything else when running that test. I even went into task manager and shut down a bunch of background processes like cortana and other windows shit, and still got 43 FPS when set to 50.
As far as players agreeing, I tried doing that initially, although I think I got it wrong. I tried sending shot strength and direction , to the opponent when I struck the ball. My thinking was that if the opponent has the same shot strength I do and direction, his machine would call the move method, and the ball should move the same way on both machines. As I said before, math is immutable, so 2 + 2 will always be four. So I figured that the formula of calculating the shot had the same values on both machines, there shouldn't be an issue. If I have a shot strength of 5, and I hit the ball 45 degrees to the right, then if I pass shot strength to him and the direction, albeit mirroring it for sound pool, his machine should call the move method and move the same amount, given that shot strength is equal. However, the ball was intermittently landing off by one coordinate between the two machines. Always one coordinate, never more, and always in the direction that the ball was struck. That might be because of the way I initially had movement running, solely based on timers. I suspect that the timers were getting different results on both machines, and there were so many that it was causing issues. I don't know whether changing it to the way I have it now, where it actually uses equations of physics and DT will fix that, but theoretically it should, since velocity isn't going to change based on timers. I have removed all of the timers from my code with the exception of the one to measure DT, and the one for player movement, but that one only controls how fast the player walks, and that has nothing to do with the ball. There are no ball timers in my code anymore. But this frame rate issue is disturbing the hell out of me. What the fuck is the problem? There's absolutely nothing in my loop that should cause this level of drop. The main game loop, with comments, looks like this:
void CheckEvents()
{
network_event Event;
Event = Server.request();
switch(Event.type)
{
case 1:
speaker.speak("Peer has connected to server from address "+Server.get_peer_address(Event.peer_id)+".");
break;
case 2:
//So that opponent position updates correctly.
if(string_contains(Event.message, "__", 1) > -1)
{
string[] position = string_split(Event.message, "__", true);
opponent.x = string_to_number(position[0]);
opponent.y = string_to_number(position[1]);
env.update_listener_2d(opponent.x, opponent.y);
env.play_2d("sounds/step.ogg", user.x, user.y, opponent.x, opponent.y, false);
}
//Sends the shot info to the opponent so that the opponent's machine can calculate ball trajectory correctly.
if(string_contains(Event.message, ",", 1) > -1)
{
string[] NewShot = string_split(Event.message, ",", true);
opponent.NewShot(string_to_number(NewShot[0]), true);
}
//Sends the coordinates of the ball to machine 2 when user of machine one is holding the ball before the ball is tossed.
if(Event.message == "toss")
{
B.pos.x = opponent.x;
B.pos.y = opponent.y;
B.pos.z = 4;
env.play_2d("sounds/toss.ogg", user.x, user.y, opponent.x, opponent.y, false);
}
//Sends position of the ball to machine 2 at the time of serve along with relevant shot info so that machine 2 can calculate trajectory with the same values.
if(string_contains(Event.message, "::", 1) > -1)
{
string[] serveState = string_split(Event.message, "::", true);
B.pos.x = string_to_number(serveState[0]);
B.pos.y = string_to_number(serveState[1]);
B.pos.z = string_to_number(serveState[2]);
opponent.ShotStrength = string_to_number(serveState[3]);
}
break;
case 3:
speaker.speakInterrupt("Peer "+Server.get_peer_address(Event.peer_id)+" has disconnected.");
break;
}
That's all of the network stuff. Now this is just the main loop:
C.tick();
//Testing FPS.
if(RealTime.elapsed>= 10000)
logtime();
//This is to check to see that the player serves from the correct side of the court as per the rules of tennis.
if(rules.serving)
{
if(!rules.even(rules.p))
rules.DC = true;
if(rules.even(rules.p))
rules.DC = false;
}
//To allow the move function to iterate.
if(B.moving)
B.move();
//Same for tossing the ball.
if(B.tossing)
B.toss();
//This makes sure that server never goes past 2, since only 2 players are involved.
if(server > 2)
server = 1;
//Just a fuck load of key checks, a lot of which are in here right now for testing and debugging purposes.
if(key_pressed(KEY_ESCAPE))
{
env.destroy_all();
exit();
}
if(key_pressed(KEY_T))
speaker.speak(deg + ", " + theta + ".");
if(key_pressed(KEY_D))
speaker.speak(rules.DC);
if(key_pressed(KEY_C))
speaker.speak(user.x + ", " + user.y + ". ");
if(key_pressed(KEY_O))
speaker.speak(opponent.x + ", " + opponent.y + ". ");
if(key_pressed(KEY_N))
speaker.speak("User is " + user.name + ", and opponent is " + opponent.name + ".");
if(key_pressed(KEY_RETURN))
B.GetBall();
if(key_pressed(KEY_V))
speaker.speak(V0.z + ", " + A.z + ", " + VF.z + ".");
if(key_pressed(KEY_F))
speaker.speak(C.frame);
if(key_pressed(KEY_E))
speaker.speak(RealTime.elapsed);
if(key_pressed(KEY_P))
speaker.speak(B.pos.x + ", " + B.pos.y + ", " + B.pos.z + ".");
if(key_down(KEY_LEFT))
user.move(left);
if(key_down(KEY_RIGHT))
user.move(right);
if(key_down(KEY_UP))
user.move(forward);
if(key_down(KEY_DOWN))
user.move(back);
//Key checks to toss the ball.
if(MustServe)
{
if(key_pressed(KEY_LCONTROL))
{
if(!HasBall)
{
speaker.speak("Really? You don't have a ball, dumb ass.");
}
else
{
B.StartToss();
}
}
}
//Key check for a shot during a rally.
if(!MustServe)
{
if(key_pressed(KEY_LCONTROL) and LastShooter == 2)
user.NewShot();
//Check to insure that last shooter stays between 1 and 2, as there are only 2 players.
if(LastShooter > 2)
LastShooter = 1;
}
}
As you can see, there's nothing huge here. Certainly nothing that should be massively draining my PC to the point that it runs at 50 FPS when set to 60, and 43 when set to 50. If it runs at 50 FPS when set to 60, that means it should be able to run at 50 no problem when set to 50. If you've got any ideas, or you see something massively screwed up, feel free to let me know. I am at a loss as to the cause. Are there any profilers outside of the BGT one that are language-independent that will work with BGT to show me what's going on with my code? Something's happening, but I don't see where it could be. None of my classes are huge, my game loop isn't exactly huge. I'm just at a loss. UPDATE NOTE: I ran my game code just to allow for the FPS test. I did not move the ball during this test. I simply started the game, then sat there for around 50 seconds or so to see what the frame rate would be and to allow a profile to be generated by BGT. The FPS test log shows:
Amount of real time that has passed is 10.027seconds. DT is 0.02. Number of frames that have passed is 435.
Profile results are below. My game loop doesn't appear to be the culprit. Look:
Profile Results
Total execution time: 53670 ms
Number of functions called: 9
void clock::tick(): 37414 ms (69.71%)
void StartMatch(bool = true): 13620 ms (25.38%)
int dynamic_menu::run_extended(string, bool, int, bool): 1351 ms (2.52%)
void main(): 1266 ms (2.36%)
void MainMenu(): 6 ms (0.01%)
void Voice::speak(string): 5 ms (0.01%)
bool logger::write(string, bool): 4 ms (0.01%)
void CheckEvents(): 2 ms (0%)
Thoughts? I am still at a loss.