4

So, I have a game idea in mind, and for that I need to record the game around the player. I'me not talking about recording it as video, but rather recording the scene objects, and their positions within the game, and then render them, giving the player the ability to go back and forth, to stop time and move around.

I've made a prototype with some data structures in C#, since this is going to be the programming language we'll be using in our game, but if we want the player to be able to go back just five minutes back with the data of just 100 NPC's, it takes almost 1GB of RAM.

Right now, I'm just storing a Doubly linked list, each item with the object position. In the game, I'll need to store even more data in each node, so I need something even more ligher. Of course, this algorithm is zero optimized, but still, that is a lot.

The alternatives would be create the NPC's that aren't really important to the game when the user is viewing the past, but I don't really like it very much for the sake of realism.

I wonder if there is a better way to store this?

Thanks in advance, Scorch

Philipp
  • 119,250
  • 27
  • 256
  • 336
Scorch
  • 143
  • 2

3 Answers3

2
  1. Don't use a linked list, use a linked list of arrays that each have (say) 1min reserved

  2. You probably don't need to be recording most frames. Recording only every 3rd frame would save a lot of space, and you could get away with less than that.

  3. If your game is deterministic, you could just record the player input

  4. Your position is most likely being stored as either 3 floats or 3 doubles (12/24 bytes, possible 16/32 if the memory is being padded). You could probably save some space and save them as integer shorts (short x=position.x*10). This would be lossy saving, as you would lose precision (only one decimal place if you multiply by 10, and your positions couldn't be greater than 3,276)

zacaj
  • 211
  • 1
  • 3
  • I really can't see what this could do to help (sorry for my ingorance in this field). The values would need to be there anyway. About the second, I do that, mainly for frames that are the same or similar to the last one. About the third one, no that doesn't help. Som actions are kind of pre-calculated, but others are random, like NPCs and cars, so that the player will feel the game is more realistic, instead of seeing the same thing over and over and onver. Thanks. :)
  • – Scorch Nov 20 '12 at 21:39
  • A linked list would (in a non memory managed language) be storing an extra two pointers per object in the list (which could be 16 bytes in 64bit).

    You're saying 100 NPCs over five minutes takes 1GB of RAM, which means each NPC is taking ~500 bytes to store per frame, which can't be right if you're just storing position. (1,000,000,000/(56060 * 100))=555 bytes. Either you're storing WAY too much, or your measurement is wrong

    – zacaj Nov 20 '12 at 21:49
  • (using a straight array instead of a linked list should cut your memory usage in half at a minimum, if all you're storing is position) – zacaj Nov 20 '12 at 21:51
  • I must apoligize. In fact, I was measuring it mistakenly. I looked into the calculations, and it was doing 100 minutes instead of 5. Anyway, I'll try to use a list of arrays and see how much I gain, and then post it here. :) – Scorch Nov 20 '12 at 21:58
  • Right now, with 100 entities and five minutes of recording, it takes 150 MB of RAM, with two integers and two Vector3D (three doubles each), which is pretty more satisfying. Still, I'll try to use some kind of interpolation to decrease the memory even further. Any suggestions on this? – Scorch Nov 20 '12 at 22:53
  • Definitely change your doubles to floats, and (unless you really need the extra range) your ints to shorts.

    As to interpolation, I would just go with cubic or hermite interpolation ( http://paulbourke.net/miscellaneous//interpolation/ ), then just play around with your "save/don't save this frame" code to minimize usage)

    – zacaj Nov 20 '12 at 23:09
  • What about deterministic NPC behavior? Like, say, the output of a script? You may be able to reduce some things a bit better that way. – Clockwork-Muse Nov 21 '12 at 00:08