Upcoming Events! Community Event Calendar

Bugsmashers: Episode 43 - Player Move Requests Written Wednesday 15th of February 2017 at 10:00am by StormyWinters

Mark Abent shows us how optimizing a little bit of game code can improve performance. 

As per usual, anything said during the show is subject to change by CIG and may not always be accurate at the time of posting. Also any mistakes you see that I may have missed, please let me know so I can correct them. Enjoy the show!

TL;DR (Too Long; Didn't Read)

  • A player will send move requests to physics to move but the bug is when player is snapped to a chair/seat he doesn’t need to do all the move requests anymore but he’s still doing all the move requests

  • Some code runs to figure out what it needs to do, sends requests either to physics or animations to do some alignment

  • When bound to an attachment, all moves are local to that attachment so if he sits down and still moves it’s relative to that attachment because he’s being forced to that location

  • So they’re going to check the status of the position and see if the position is active and stop the player from moving

    • With slight optimization of the code to tell physics to stop moving him, so the physics side doesn’t need to do all the calculations while the game side keeps snapping the player     

Full Transcript

Mark Abent: Hey everyone, welcome to Bugsmashers. I’m your host Mark Abent and I’m here to take you behind the scenes on some bugs and how we smash them.   

Hey everyone, we’re here in that awesome test level of mine and I have a Gladius and I’m going to pop right down. So, this bug that we have came from the physics guys, you know, they’re analyzing some things and they found out, ‘well, we could do some slight optimizations’ and when we have the player and he’s just walking around. He sends move requests to physics to move, his physics type is known as a living body, he has ridges and he moves organically.

So, when he gets inside one of these ships, let’s see we’ll hop in right there. We basically take him and snap him to the chair and we keep him there all the time. So he doesn’t need to do any of these crazy move requests but unfortunately when we snapped here, he’s still doing all of the move requests.

So, pop down into the code. In this little bit of code that we have here, this is how we control the player or any actors when you want to move left or move right or if the animation wants to force you to move to a specific location. This little bit of code runs and it figures out what it needs to do and it sends either requests to physics or requests to animations to do some alignment.

So, once we get down to this little bit, if we’re bound to an attachment which is going to be basically here inside the ship or in a seat or some other thing that needs to keep the player in a localized area. We basically, if we have an attachment we move all of his move requests local to that attachment, that way if we sit down here he still moves but it’s relative to the attachment because we’re always forcing him to that location.

In this bit of code is where we tell physics to stop moving because we’re basically just moving the player entity by game code around that location point. So every frame we’re basically saying, ‘hey physics, stop’ and what this actually does is the physics code will actually do some internal stuff that basically wakes him up and maybe does some things that were not necessary because… well, we’re doing our own thing.

So, the guys in the UK specifically Jens decided what we could do instead if we get the movement… we’re going to check the status of our position and we’re going to see if our position is active. We actually want to see the player dynamics. So this is something specific to the player physics, we want to see what the player is actually doing because living entity like I said he’s more organic so he has a lot more features.

So we’re going to check to see that the player is actively walking, so physics is moving him then we’re going to stop it. From this point on we don’t have to tell physics to do anything because he should still be stopped. So, we’ll hit magical recode button. No...recode. Ah, here’s the one fun thing physics, this bull not a bull so we gotta make sure it’s not zero.

Physics does some crazy, crazy optimizations and tricks especially since it’s an old system so what you think is a  bull is actually an ent, joy. Recode. Why are you… ah, recode, recode, go! It would help if I used the correct function, physics has a params and status and why don’t you want to get… ah. Two early in the morning.

So physics has params and status and you have figure out which… basically you just look at the function to see if it’s params or status and call it the appropriate function. Then of course you have to remember that this takes in pointer so you have to send in the reference of the structure so physics can fill it in. Those early mornings when you think have it down, the error code pops up and you’re like, ‘oh, of course’.

All right, so we ran it and now that’s were inside the ship we should not be getting any break point in here and of course as we move around the ship, we get nothing. So if I pop out, where’d my ship go… hop back down, wooo. My guy won’t run in this area of the code but he will do some movement requests down here which will send it to physics. All we care about though is the attachment, so we’ll go back in and I’m still free. The attachment code kicks in, so this is the first time it runs since I was moving around I might be active. I’m not active so it clears it and we’ll see. Yup, so we never hit it again, perfect. There you go, hope you guys enjoyed.

So, as you guys saw we had a fun little optimization there. The physics guys are like, ‘hey, we’re getting these crazy move requests from the player when they’re in the seat, they shouldn’t even be moving’. So if we optimize it a little bit there, the physics side won’t have to do all these crazy calculations when the game side is just going to keep snapping them. So again, just put in a little fix… 1,2,3, bam. Slight easy optimization and we gain quite a big performance in Crusader especially when we have all those AIs running around and we’re snapping them into place, you don’t need to do physics moves. So nice little optimization, speeds up the game and gives you guys that little bit extra FPS. Hope you guys enjoyed, till next time.           


Director of Fiction

Moonlighting as a writer in her spare time StormyWinters combines her passion for the written word and love of science fiction resulting in innumerable works of fiction. As the Director of Fiction, she works with a fantastic team of writers to bring you amazing stories that transport you to new places week after week.