12.02.2015, 22:05
The alternative is to use 14 separate columns, just for the components, where many fields would just hold "0".
I'm also storing all vehicle-components in one column, where each component is separated by a "-".
It's also very easy to load the all at once into a string of an enum.
It only takes 1 sscanf line to load all 14 components into the enum.
What if you would remove one value from your enum?
Then your data is split up in memory.
For your saving:
I would rather update data in MySQL whenever it changes to prevent dataloss.
If your player is playing for over an hour after buying his components for example, and your server gets attacked or suddenly crashes, all that data is gone and you can't save it anymore.
When your server comes back online and the player logs in, his vehicles won't have their components anymore, but he might have paid for them already (if you save his money whenever it changes).
He'll have to buy the same stuff again and pay twice for the same thing.
That's why I'm saving data whenever it changes. Money, vehicle-data, scorepoints, statistics, anything.
If the server crashes suddenly, you won't have ANY dataloss.
And you could split up your queries into smaller ones.
It has no use to update ALL data about a vehicle when the player only adds 1 component.
You would just update the components as the other data remains unchanged.
Or if your player only changes the color of his vehicle, you would only update those fields for that specific vehicle.
Spawn-position for example won't need to be updated as changing colors doesn't change the spawn-location.
This also puts less stress on your database and your server as well.
You'll get a more efficient server in the process.
I'm not saving ANY data during OnPlayerDisconnect because I know all my data is saved whenever it changes and I don't need to send huge queries to save EVERYTHING at once when a player logs out, just to make sure everything has been saved properly.
I'm also storing all vehicle-components in one column, where each component is separated by a "-".
It's also very easy to load the all at once into a string of an enum.
It only takes 1 sscanf line to load all 14 components into the enum.
What if you would remove one value from your enum?
Then your data is split up in memory.
For your saving:
I would rather update data in MySQL whenever it changes to prevent dataloss.
If your player is playing for over an hour after buying his components for example, and your server gets attacked or suddenly crashes, all that data is gone and you can't save it anymore.
When your server comes back online and the player logs in, his vehicles won't have their components anymore, but he might have paid for them already (if you save his money whenever it changes).
He'll have to buy the same stuff again and pay twice for the same thing.
That's why I'm saving data whenever it changes. Money, vehicle-data, scorepoints, statistics, anything.
If the server crashes suddenly, you won't have ANY dataloss.
And you could split up your queries into smaller ones.
It has no use to update ALL data about a vehicle when the player only adds 1 component.
You would just update the components as the other data remains unchanged.
Or if your player only changes the color of his vehicle, you would only update those fields for that specific vehicle.
Spawn-position for example won't need to be updated as changing colors doesn't change the spawn-location.
This also puts less stress on your database and your server as well.
You'll get a more efficient server in the process.
I'm not saving ANY data during OnPlayerDisconnect because I know all my data is saved whenever it changes and I don't need to send huge queries to save EVERYTHING at once when a player logs out, just to make sure everything has been saved properly.