Subliminal
Bugsmashers

Star Citizen: Bugsmashers - Incomplete Ship Insurance

22 November 201700:17:24468 linesWatch on YouTube ↗

Transcript — every row opens the video at that moment

  1. 00:00:16

    Hey everyone, welcome to Mug Smashers. I'm your host Mark Abent, and I'm on vacation this week. So, as I take a sip from my coffee to company cup, Spencer, what you got for me? Hate you. It's Mug Slashers. So, this week we've got an insurance bug. Uh talked about it briefly on ATV a few weeks ago, but this one's pretty funny. You You claim insurance on a ship, you go and spawn it, and then your ship appears right on the uh the landing pad, but there's no seats, there's no doors, there's no landing gear. This is a really scummy insurance company, and they did the bare minimum. So, basically like real life insurance. Yeah, we were trying to be really realistic here. Too realistic for a game. Yeah, so how about we we step into this and I'll show you what's wrong. Mug Smashers!

  2. 00:01:07

    Hello everybody, and welcome to another episode of Bug Slashers, the show where I refuse to let that joke die. Uh this week got an interesting bug to show you. Uh you may have seen this on Burn Down a few weeks ago. I talked a little bit about it, but I wanted to go into a bit more depth about how we solved this problem and explain why it was happening. Uh so, here we are, and we'll just jump right in and show you. So, we're going to go over here to our terminal. We're going to make a claim on a ship. We're going with the Cutlass Black today. So, we're going to go make a claim on this ship, and we're going to expedite. Yep. 8 seconds. Maybe a little bit shorter than what you'd expect to wait in the live version. Um okay, so we've we've claimed our ship, and now that we wait for the time to finish.

  3. 00:01:53

    Now we're going to go and spawn it. So, we retrieve this. Okay. And for the sake of time, we're just going to fly out here. And it should probably be immediately noticeable what's wrong here. Uh I spawned this ship, there is no doors, there's no landing gear. You fly inside, there is no seats. And you know what? There's no turret on top, either. Uh this sham of an insurance company took our money and we get basically a ship on cinder blocks that does not work. You cannot fly this. It's just a husk of a ship. And as you might imagine, this not the the best feature to have. So, what went wrong?

  4. 00:02:42

    Why did this happen to us? Let me explain. So, we're going to pause here. We're going to do hop into our code. And we're going to look at a function called generate persistent items. And this lives in a piece of code called the entitlement processor, which is a really important part of our code base. What the entitlement processor does is when you start up the game, uh we'll we'll say for the first time, after you've bought a ship on the website, you've bought, you know, whatever, Cutlass, Hornet, uh when you sign the first game, we need to take this data of this ship that you own and basically translate it into game data so that you could persist it, it could be in your player database, so that the game knows you own this Cutlass. Uh really important. And this is a

  5. 00:03:30

    pretty sophisticated piece of code. There's a bunch of stuff going on in here to make sure that things uh get sorted properly and players own the things that they need to. And what we're going to do for insurance, we're going to use some of the functionality already here, so that when you insure a ship and you blow it up and you make a claim, you get a brand new one. Uh and it uses the same code path here. But we are going to have to make a few slight modifications because the code wasn't really intended to do this exactly. We're kind of hijacking it to do what we want. Um sort of a clever solution, but as you'll see with many bugs, it always starts off with All right, so we tried to be clever and then this happened. Um so, let's talk a bit about this function and how we're using it. Now, generate persistent items is a

  6. 00:04:18

    recursive function which, if you're not familiar with computer science, uh you're probably familiar with this sort of image. And I'm going to uh have a helper here. I'm going to drag OBS over here. This is recursion. When you see something that contains itself. And in computer science, it's if you have a piece of code, of you know, a function that calls itself, which calls itself, which calls itself, and ad infinitum. Just keeps happening. Uh and it's a really useful piece of tech, and that's what the generate persistent items does. Because when you have an item you have a root, and you have a tree of things that are its children. I've got a helper image here because way more sophisticated than

  7. 00:05:06

    regular bug smashers when I'm hosting the show. Uh and as you can tell, clearly made with my amazing art skills in MS Paint. Um there's a reason why I'm not sitting on the other side of this building in the art department. Uh right. So, this is the item port tree for our cutlass black, or a rough approximation of it to give you an idea of how this works. And I know you might be expecting code. We're going to jump into the code right after this, but let me explain a bit about how this setup is. So, we've got our root here, which is the ship, which has no doors, nothing on it. It's basically just the model of only the ship. And this is the parent. This is the root. And then, you see attached to that on item ports, the seats, the turret, the doors. And then, those things that are attached can also have things attached

  8. 00:05:52

    to them. So, the turret has guns attached to it. The seat has the dashboard attached to it, right? So, this is the tree structure. This is how things are set up, like our ships. And this is very important because the entitlement processor starts at the top and then gives you that ship, and then will give you all of its children, all of its children's children. Now, when we're doing this uh function for insurance purposes, we're basically building a list of all of the pieces so that we can give you all of the pieces individually. And if we hop back into our code here, you can see what we're doing here is we're generating a list of all these items. We're pushing it back into this list. And, very crucially, we need to keep track of each of these items' parent. So, if you look at this image again, we need to know that the

  9. 00:06:41

    seat, its parent is just the ship Now, we're going to jump on to image number two here, where I've labeled all of these images here and given them an ID. So, you can see we start at the root and we're like, "All right, this is zero." Uh in computer science, we start at zero, not one. Um for many reasons. But anyway, we start at zero. And then, okay, go down to children, it's one, its children two, go back up. All right, then we need three. Okay, back up, four, its children five, six, back up, seven. Okay, all right. So, that's the order that we number all of these and give them IDs. And that's what the entitlement processor does. The problem that we run into when using this function for insurance, I can hop in here and show you. We were storing this ID in this variable here.

  10. 00:07:31

    Item VID, right there. Now, in that variable, um every time we do this recursive loop, we add one to that variable, and basically this is used to give new entity IDs to these entities when they are spawned. So, you make an entity, you make its children, you add one, its ID is one higher, its children one higher than that. this doesn't work for our purposes because we're storing slightly different number in that variable. Rather than the entity ID, we're storing the offset in the list, the IDs that were on that this image here. So, it's our offset. The problem here is we were sending these numbers but really we need the parent of those numbers because of uh what we do later on in insurance

  11. 00:08:19

    here. We want the parent number. And so, in my final image here, I'm going to show you the numbers we're supposed to have. Instead of just putting the ID of the part itself, which is what we were doing, we were basically saying, "Oh, my parent is just the same number as me." So, it would entitle you all these pieces of the ship but then not know how to connect them back together. So, you'd spawn the ship and it would just be the root of it and all the other pieces would be in your persistent database, but they're not connected to the ship. They have no knowledge of each other. So, they're just sort of floating out there in space, metaphorically speaking, anyway. So, if we look at our orange number here, this is going to represent the parent that this belongs to. And so, we start at the root here, doesn't really have a parent, so we're going to keep that zero. But then for each of its children, it's

  12. 00:09:08

    like, "Okay, well, I'm number one, but my parent was zero." Or like, "I'm number three, but my parent was zero." Or down here, "I'm number five, but my parent was four." And so on. so, this is really crucial. This is the number that we use later to say, "Okay, I know where my parent is in this list. We can connect them all back together." So, let me show you the code that we did to change this. It's not very much, um but sometimes really complicated bugs get solved with just a small amount of code. So, I'm going to copy and paste a little bit of code that I had saved here. And we're just going to put this there. Right. So, we've got this one little block here, which is checking to see if this variable is -1.

  13. 00:09:56

    Probably should have started with we're going to modify the function very slightly. And it has a ton of arguments, so we got to scroll all the way to the side here. And we're going to add an argument to this function. Called end the list parent index. That's the orange number we were talking about. We're going to add that to the header here. We're going to default value it to -1. Copy this. And we're going to put this in the source file as well. Okay. So, now we've got an extra argument to this function. We need this

  14. 00:10:43

    number to keep track of the parent as I mentioned earlier. Now, this little block of code down here that I accidentally copy and pasted too early is now checking to see if this isn't -1. I'll get back to that. And then if it's not, it we know that we want to be tracking this information. We know that we entered this piece of code through insurance. And so, we're just going to store that in that variable I mentioned earlier. Right? Okay. The reason we're checking if it's not equal to -1 is because we're trying to do several things at the same time here with this function. There's several different code paths that lead here. We only want insurance to be taking advantage of this feature, basically. So, we default this value to -1. -1. I knew I did that.

  15. 00:11:32

    Default that value to -1, and we just ignore if it is that. Um, but if it's not negative one, we know we want to keep track uh keep track of this information. Okay, so we've got that small bit of code down there and then down here, this is a little bit of a funky line I'm going to type out here. So we're going to make a new int here, we're going to call it new parent new parent index in entity list cuz I like my variables to be a mouthful. Okay. Now, this will look a little bit weird. override GUID index not equal to negative one just like I said before. We got to check that. Make sure that we are tracking this information.

  16. 00:12:21

    Okay, so if that's true, we're going to add nullary uh ternary operator here. I'm just going to keep typing this and explain it in a minute. Okay. So we've got this little bit of a mess here, but basically what we're going to tracking is are we tracking the parent index like I mentioned earlier? We are tracking it. And if this uh pointer here is not null, we need to access it so we got to check it's not null.

  17. 00:13:08

    Then, if both of those are true, we are going to take that number that we were keeping track of override GUID, dereference it minus one because remember we started at zero. And if it wasn't true, we're just going to return negative one. Um, and then this integer we just created here goes as the new argument that we just added here. New parent index entity list, which is the thing that we added to this function and that we checked up here. This is the new value and this is why recursion is cool because we made this value on a parent. We're going to go back to our image here. We made that value here and then propagated to each of its children. Make the value here, propagate to the children. Same thing here. Make a value that you call the recursive function and you give it to its children. Uh and that's what's

  18. 00:13:57

    really powerful about recursion. It's super quick to make a change like this. Okay, so we've got that in there and now we have uh what should be everything we need to compile this and try out try again. Maybe this time have a halfway decent insurance company take care of us. I know we're trying to be a realistic game but I think the insurance company should actually give you a working ship. And we'll cut back after this finishes compiling. All right, we're back in game now. So let's uh let's try again. Let's make another claim and hopefully now maybe we're being insured by a less uh seedy organization. Let's make a claim on our Cutlass Black Pay our expedited fee

  19. 00:14:50

    and now we're going to wait a little bit for this to finish up. We'll spawn our ship and hopefully it'll be good as new. Do a little dance. Okay, that's probably 10 seconds. All right, we're going to retrieve our ship. Again, I'm just going to fly out of here for the sake of time and you can see hey, we've got doors this time and not only doors, we've got turrets, we got engines, we got seats, the whole kitten caboodle. This is an actual ship. Didn't show up on cinder blocks this time either. Cool. So, just to recap, to put it quickly, before we were keeping track of the list of all of these new items we needed to

  20. 00:15:37

    give to the player when they claimed insurance, and when trying to keep track of which item had which parent, we were not sending the right ID. So, we needed to get a new ID and propagate that down to each of the children during each of our recursive calls, and that is what allowed us to attach everything when we spawned the ship, and now you got something that's good as new. Hopefully you guys enjoyed this episode and our little bit of a less codey approach to it using images and more just uh descriptions of the problem. And that's it. We good. Vote for bug smashers below. Okay, so insurance was a bit out of whack and gave us some pretty unusable

  21. 00:16:25

    ships, but we went in there and made sure that each new thing in the item port tree knew correctly about what its parent was when we put it out in the list and then gave all that stuff to the player again. So, now your ships work. Uh no more janky insurance company that rips you off. I know don't say I know you want to say it. How's the weather from down there? I I really hate you. So, that's this week's episode of bug smashers. I'm your tallest host, Mark Abent, and Spencer Johnson. Spencer. Until next time, hope you guys enjoyed. Woo. Thank you for watching. So, if you want to keep up with the latest and greatest in the Star Citizen and Squadron 42's development, please follow us on our social media channels. See you soon. Mhm.

Transcript from YouTube’s automatic captions — punctuation and Star Citizen jargon are approximate. The video itself is hosted by CIG on the official channel.

Squadron 42

LiveSQ42 Launch Subathon

$2,094of $3,000

Getting Sub to Manchester for the Squadron 42 launch

Next giveawaySubscriber Store pick
$6.27to go