Hello,
Ok, so after finish a lot of work with my engine ( youtube.com/watch?v=KHMtuLEMbb…DskJvtWKMYGhSyNAKpdj61otI ), taking a long break, getting hired in an actual game company , etc, etc - I have decided to go on and make a small game, for fun.
Now for now I mostly worked on the rendering part of the engine, using the architecture given in GameCodingComplete 3... I must admit I left the GameLogic behind for quite long, too long even.
I have a question regarding the system separation and how I should approach some logic.
I am making a small RTS game, and here is a quick sample of what I have and my problem.
I made classes such as BuildingActor, UnitActor, PlayerActor - all inheriting from BaseActor.
Among them is a class called FarmActor which should add food to its owner every x time.
So I overloaded its update and made an internal timer, now I need to increase the player's resource and in order to keep system separation, I am wondering how should I approach it?
1. use Application->GetGameLogic()->GetActor( playerID )->AddResource( resourceType, amount );
2. use Application->GetGameLogic()->AddResource( playerID, resourceType, amount );
3. Send an event and have PlayerActor catch it.
4. Send an event and have GameLogic catch it.
Now there is also the question of telling the HumanView of the updated resources - who should be in charge of sending the event to them? If used method 3 and 4 I can just listen to that event - which might be bad as it may be spammed all over the place which would hinder networking for example. Please comment on this.
In case I chose method 1 - should the PlayerActor send the event? In order to avoid flooding network packets, should it gather all ResourceAdds into temp variables and then send the event on the next PlayerActor->Update() so it can only update once per frame? Although I doubt this will do much good if every resource building (farm, mine, lumbermill) has its own timer. Also I think the GUI should reflect the change instantly.
Please someone comment about this, I want to put the structuring of this straight so I can feel comfortable with how I proceed.
My current feeling tells me to go with option 1 - since this is a BaseActor inside GameLogic, allow it to have access directly to PlayerActor and call a function to add the resource, then either call an event for the HumanView to update the GUI with the new resource inside the PlayerActor->AddResource function or accumulate for at least a whole frame and call it inside Update. I am thinking GameLogic doesn't need to link between two internal actors of the same system. Am I on the right track?
If I am on the right track on the actors parts, I just need to straight out when to call update resources event for everyone else (HumanView and remote players) to know of the change... and who should call the event also.
Thanks and sorry for the mess
Ok, so after finish a lot of work with my engine ( youtube.com/watch?v=KHMtuLEMbb…DskJvtWKMYGhSyNAKpdj61otI ), taking a long break, getting hired in an actual game company , etc, etc - I have decided to go on and make a small game, for fun.
Now for now I mostly worked on the rendering part of the engine, using the architecture given in GameCodingComplete 3... I must admit I left the GameLogic behind for quite long, too long even.
I have a question regarding the system separation and how I should approach some logic.
I am making a small RTS game, and here is a quick sample of what I have and my problem.
I made classes such as BuildingActor, UnitActor, PlayerActor - all inheriting from BaseActor.
Among them is a class called FarmActor which should add food to its owner every x time.
So I overloaded its update and made an internal timer, now I need to increase the player's resource and in order to keep system separation, I am wondering how should I approach it?
1. use Application->GetGameLogic()->GetActor( playerID )->AddResource( resourceType, amount );
2. use Application->GetGameLogic()->AddResource( playerID, resourceType, amount );
3. Send an event and have PlayerActor catch it.
4. Send an event and have GameLogic catch it.
Now there is also the question of telling the HumanView of the updated resources - who should be in charge of sending the event to them? If used method 3 and 4 I can just listen to that event - which might be bad as it may be spammed all over the place which would hinder networking for example. Please comment on this.
In case I chose method 1 - should the PlayerActor send the event? In order to avoid flooding network packets, should it gather all ResourceAdds into temp variables and then send the event on the next PlayerActor->Update() so it can only update once per frame? Although I doubt this will do much good if every resource building (farm, mine, lumbermill) has its own timer. Also I think the GUI should reflect the change instantly.
Please someone comment about this, I want to put the structuring of this straight so I can feel comfortable with how I proceed.
My current feeling tells me to go with option 1 - since this is a BaseActor inside GameLogic, allow it to have access directly to PlayerActor and call a function to add the resource, then either call an event for the HumanView to update the GUI with the new resource inside the PlayerActor->AddResource function or accumulate for at least a whole frame and call it inside Update. I am thinking GameLogic doesn't need to link between two internal actors of the same system. Am I on the right track?
If I am on the right track on the actors parts, I just need to straight out when to call update resources event for everyone else (HumanView and remote players) to know of the change... and who should call the event also.
Thanks and sorry for the mess