I am working on a small multi player game for my final year project and currently working on the server. It's a Tank Battle game and have two main entities which I will use on the server side which are
Player (Player details like username, password, currentTank, statistics)
Tank (Details of a tank like velocity, rotationVelocity, Turret)
Turret(Details of turret like rotation velocity, fireRate, etc)
Statistics(stats like totalKills, total deaths, total shots etc)
I have recently read about DAO and how they separate out the database concerns and thought to use it in my project because my project does have good amount of data to persist and also due to the fact that I want to learn this technique.
After reading about DAO I realised there will be need to map the DTO to Domain Objects for business logic. As I am going to have quite a bit of logic on these object as well methods which are not really needed on DTO's.
So for example I map :
PlayerDTO -> PlayerObject
Whenever there is a request from player to move his tank, I queue the direction in a queue contained in player's tank. (This shows the need for having Domain Object as I don't need movement queue on the database but I need it on the tank objects to queue movements)
Now let's say in my MovementService of my server, I loop through the PlayerObject list (the logged in players) and update player's tank position in by calling the player.moveTank() which will update his positions according to the movement queued in the movement queue inside the TankObject contained in PlayerObject. I understand it till this point what I need to do.
Now my question is how will I save PlayerObject back to Database? Do I need to map it back to PlayerDTO? What is the most effective way to do it?
For now I have thought that when the player logs out,In my LogoutService I will use the PlayerDAO service and get the PlayerDTO using PlayerObject ID and update the object details and save him back to the database but I feel that I will be making extra database calls just to get the object (An extra select call) and to save it back rather than just updating the object using update query.
I also feel that just for updating let's say his position on the database I will have to use a query which will overwrite everything. Is there any better way of doing it or I am doing it right?
Note: I won't be using any ORM in my project.
P.S. I searched a lot but couldn't find any similar question. I know I haven't put any code and it's a long question but if anything is not clear let me know.