- Home /
How the games are storing Bulk data of players and how they are processing?
Hi friends, I would like to know more about storing of bulk data of players.Bulk means not a bulk but storing of too many values like (player level,health,speed,coins,how many games played,won games,lost games,gems,trophies ....etc). simply an example game is COC. In that game how they are saving each and every level,stats,trophies...etc every thing.And how they are making Multiple device play. I have seen playerprefs, saving in xml and one more saving in database(I think But in this case if 10K players are playing at a time 10K requests are gone to Database. At that time database can't handle thus much of request or some unknown Error we can face). And how they are serialize this data in multiplayer, how to create a multiple device play game. Generally in games what they are doing for this type of data storing ? Any Suggestions please. If already this question is there sorry , But I have not find any answer about this type of question. Sorry for my English. Thanks in advance for clearing of my doubt's.
I'd say you want to make the difference between local data and server data. PlayerPrefs is local, serialising to xml or json can be local or distant. There's also Game Centers API for leaderboards.
@jikkou Thanks for clearing some doubt. Right now iam not developing any game.But i have an lots of doubts about this one.clearing of some doubts thank you. can you give some useful links about this one may be helpful to others also.
Always reply to a comment by a comment.
Answer by AurimasBlazulionis · Dec 04, 2016 at 05:37 PM
If you know exactly how longs is the data (even if you do not, it is still possible), you can write manual byte serializer. It is much faster and uses much less space, but it requires to be handwritten and it is pretty hard to do. You will have to a lot of debugging if you need to store more complex structures like arrays in them.
Basically you put all values into a byte array. If all the data you store is in floats and ints, then for each value you will have to use 4 bytes.
Once you have created an array of the exact size you need, also create a temporary byte array with the length of 4. For each value do something like tempArray = System.BitConverter.GetBytes (theValue)
. Now you have to put all these values to the array you will store somewhere else. Now there is a catch. Platforms have some type of endiannes. It is basically how the values are stored in the RAM. Most systems are little endian, but you should still write the code for the big endian machines. For little endian machines we write all the data to the array in normal order, but if the machine is big endian, read values from temporary array reversed. There is some code from my project:
if (System.BitConverter.IsLittleEndian) {
bytes [i + 1] = flVal [0];
bytes [i + 2] = flVal [1];
bytes [i + 3] = flVal [2];
bytes [i + 4] = flVal [3];
} else {
bytes [i + 1] = flVal [3];
bytes [i + 2] = flVal [2];
bytes [i + 3] = flVal [1];
bytes [i + 4] = flVal [0];
}
The i is there, because I did serialize arrays and the code is from for loop. Now you are done with writing.
To read it back you will have to do the reverse.
There are 2 helper functions for you to use, which take endianness into account:
public static float ToSingle (byte[] bytes, int index) {
if (System.BitConverter.IsLittleEndian) {
return System.BitConverter.ToSingle(bytes, index);
}
else
{
return System.BitConverter.ToSingle(Reverse(bytes), bytes.Length - sizeof(float) - index);
}
}
public static int ToInt32 (byte[] bytes, int index) {
if (System.BitConverter.IsLittleEndian) {
return System.BitConverter.ToInt32(bytes, index);
}
else
{
return System.BitConverter.ToInt32(Reverse(bytes), bytes.Length - sizeof(float) - index);
}
}
Also, the reverse function:
public static T[] Reverse<T> (T[] array) {
T[] ret = new T[array.Length];
for (int i = 0; i < array.Length; i++) {
ret [array.Length - 1 - i] = array [i];
}
return ret;
}
Put them somewhere in your code to access them. To read the value, set it to the function. Put the byte array as the first argument and the index of the first element as the second.
This should achieve what are your needs. If you deal with arrays, then it is going to be more difficult since they are variable sized. You will need to use one element of the byte array to store length of the array, assuming your arrays are not longer than 256 elements. And then, you will have to offset with that length all elements going after the array, the one example line of code from my project looks like this:
bytes [bytes [0] * 2 + bytes [bytes [0] * 2 + 1] * 5 + 1 + 29] = lW [0];
Also, you can try storing values as shorts and not ints to save even more space.
Answer by saikrishna-dasari · Dec 05, 2016 at 06:25 AM
Hi, I found Some more useful information about this topic related in this Link. I think It may be useful for some fellows, who have same doubt about it. Thank you.