System organization question

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • System organization question

      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 ^^
    • Hey Shanee, long time no see. :)

      With the architecture you describe, the best place to put this functionality would be an event that is caught by the player. This keeps them decoupled and allows you to change how these things are caught. Same thing with the HumanView, it can just receive this event. Regarding network lag, as long as these events are relatively small (and they should be), it'll be fine. There's no use in worrying about network optimization prematurely.

      Really, there shouldn't be an actor at all that cares about resources (except maybe a harvester). Resources should be handled by a special player object that lives on the game logic. This player object can be a human player or a computer controlled AI player. This is the object responsible for the strategic-level management of the game for that player. This would be the one to receive the events.

      By the way, congrats on getting a job in the industry. :) Where are you working?

      -Rez
    • Hi Rez! long time :)

      I am working at a local company here in Israel for the time I am staying here - That is: sidekick.co.il/ - it is quite small and inexperienced, very much just starting and maturing but pretty nice :)

      About the subject - well I figured since the views get an ID and don't really need an actor as they have no single units which is them etc and the units and buildings need to be owned, I can just make a PlayerActor and use his ID and his system for resource tracking instead of creating special logic in the GameLogic class, this also feels more object oriented to me.

      Do you think I should move this to the gamelogic then and have a special class handled there?

      So you think the building itself should throw the event and then it will be caught by both the HumanView and the PlayerActor or new player class or whatever?

      Let's have a different example too - say I have two units, one is attacking the other, all inherited from BaseActor and handled inside GameLogic internally - how should damage assignment be done? Does Actor1 just grab Actor2 and assign damage and sends an event for HumanView to catch? Does he instead send an event Attack( id ) and then GameLogic catches it and sends event UnitDealtDamage ( unitAttackedID, unitDamagedID ). Although this one is slightly simpler than the previous problem which I am still trying to understand fully in order to keep clean code.

      I still think I should use the PlayerActor for managing the total amount of resources the players have as it simplifies - having ActorID for players, seralizing logic is there and called already with all other actors... Would like if you could expand on the subject :)

      The post was edited 1 time, last by Shanee ().

    • In fact, at the game company I am working at they seem to be so biased against events and system separation I feel I am going back on so many goods things I learnt.

      I can't get good advice there on the topic which is why I turned back here hoping for someone to help me clear this issue, where should I use events clearly, where should I have direct access. How should things run inside internal systems (like here, all belogns to game logic) and when to use events internally, when for outside and who.

      The post was edited 1 time, last by Shanee ().

    • Originally posted by Shanee
      Hi Rez! long time :)

      I am working at a local company here in Israel for the time I am staying here - That is: sidekick.co.il/ - it is quite small and inexperienced, very much just starting and maturing but pretty nice :)

      Inexperienced companies are a mixed blessing. You get to grow and learn together, but you tend to fall into some pretty major pitfalls. It's a good idea to try and get a few industry veterans.


      About the subject - well I figured since the views get an ID and don't really need an actor as they have no single units which is them etc and the units and buildings need to be owned, I can just make a PlayerActor and use his ID and his system for resource tracking instead of creating special logic in the GameLogic class, this also feels more object oriented to me.

      Do you think I should move this to the gamelogic then and have a special class handled there?

      You certainly could make the player a special form of actor, but the concept of a player (whether human-controlled or AI-controlled) really feels like a new system to me. Still, there's an advantage to having a game view and everything attached to it, so maybe creating a specialization of actor isn't a bad way to go. If I were doing it, I'd probably create an entirely new system owned by the game logic that sent out commands to the game world as events. These events could be triggered from the UI or from the AI making decisions.


      So you think the building itself should throw the event and then it will be caught by both the HumanView and the PlayerActor or new player class or whatever?

      Yep.


      Let's have a different example too - say I have two units, one is attacking the other, all inherited from BaseActor and handled inside GameLogic internally - how should damage assignment be done? Does Actor1 just grab Actor2 and assign damage and sends an event for HumanView to catch? Does he instead send an event Attack( id ) and then GameLogic catches it and sends event UnitDealtDamage ( unitAttackedID, unitDamagedID ). Although this one is slightly simpler than the previous problem which I am still trying to understand fully in order to keep clean code.

      It really depends on how you model combat. On The Sims Medieval, both combatants would be locked into an Interaction (which is like a CProcess from GCC) that would run a synchronized animation on both Sims. When the animation reached a particular keyframe, things like health and damage were updated. The Interaction had references to both Sims, so it would update the stats directly.

      The simplest way to do this would be to have an attack state in the unit's AI. Recall from Chapter 17 that the states in a state machine are subclasses of CProcess, so they get updated every frame. The attack state will have a target actor id and will seek to find a "square" next to the target. Once it does, it will run an attack animation loop. On the appropriate keyframe of the animation, it sends an event with the target as an id, which is caught by the game logic. Damage is then applied appropriately. The game logic should then send a "damage dealt" event so that you UI or another system can catch it and show the updated UI (health bar or whatever).


      I still think I should use the PlayerActor for managing the total amount of resources the players have as it simplifies - having ActorID for players, seralizing logic is there and called already with all other actors... Would like if you could expand on the subject :)

      I think that sounds reasonable, I was just explaining how I would approach the problem. :)

      -Rez
    • Originally posted by Shanee
      In fact, at the game company I am working at they seem to be so biased against events and system separation I feel I am going back on so many goods things I learnt.

      I can't get good advice there on the topic which is why I turned back here hoping for someone to help me clear this issue, where should I use events clearly, where should I have direct access. How should things run inside internal systems (like here, all belogns to game logic) and when to use events internally, when for outside and who.


      Yup, that's one of the disadvantages of working for a company where people are generally inexperienced. We had a lot of those problems at Super-Ego Games because none of us were very experienced game developers. Still, passion and determination can take you a long way.

      -Rez
    • Hi Rez!

      Thank you very much for your thorough and kind reply, I really appreciate it and it helped me put order into things :)

      It is very important for me to understand things well, I am glad I received the answers.

      The company I work for is really nice and enjoyable - it is a lot of fun working there and the atmosphere is great, everyone there is great. Then again, it is a company in Israel and Israel is new in this industry, barely has a toe in it.

      Programmers in the company have quite a bit of ego and think their way is the best. I got into some frustrations which I kind of kept silent seeing how I am the new girl and everyone there has their own opinion of how things should be done...

      I love to learn, I enjoyed Game Coding Complete 3 a lot and this is why I keep coming back to this forum with my questions. I thank you Rez and Mike for both writing the book and being so helpful answering questions on the forum. :)

      I hope some day I will work in a professional company, or even see this one become such - though I am hoping to move to the UK to be with my boyfriend (who is living there already, long distance relationship...)
    • Programmers can definitely develop large egos. Most programmers I know who have really large egos are actually not very good programmers at all. The reason is that they don't listen to anyone and think their way is perfect. Why would they need to change it? We had a programmer like that on the gameplay team at EA. After he left, I spent about 2 weeks refactoring a system he broke.

      The UK definitely has some great companies. I met some of the Media Molecule guys at GDC a few years back; they're great people. :) You should come out to GDC sometime. It's the best opportunity to learn from industry veterans.

      Let me know if you have any other questions.

      -Rez
    • Maybe I could come one day, right now I need to get life kind of sorted as I am shifting between Israel and the UK all the time.

      My boyfriend lives in the UK and got hired at Criterion Games (EA) about half a year ago :)

      I am still in Israel due to a medical problem which required a surgery, which got complicated :-/

      Actually I am flying back to the UK to be with him this Saturday, continuing to work remotely for Side-Kick Motion Games. Going back for a surgery at March.

      I really hope to move to the UK completely soon, though I don't have a visa or a job offer there... (my boyfriend isn't British national)

      Oh well, too many details, too uninteresting.

      Thank you for the help again, I haven't had the time to continue with my project because of a lot of work from my job and CES (Side-Kick was there with Microsoft PC Kinect and Omek) but once I continue I will be sure to come back with any questions I might have so I can learn more :)