MVC

Started by
2 comments, last by GameDev.net 18 years, 10 months ago
I am trying to write a networked game and have come across Model View Controller as one possibility as to how to organise the entity management code. Part of the inspiration was this article on gamasutra : http://www.gamasutra.com/features/20050414/rouwe_01.shtml. These are my thoughts are so far : Model - subclassed for entity types - holds entity state eg position/rotatation/hits - it provides access functions to change these attributes. View - has a subclass for different entity types - holds mapping of meshes/sounds/animations/particle effects for given state - virtual init() and update() function implemented for each subclass Controller - has a subclass that processes player input (mouse/keyboard) and updates model. - another subclass will be for an AI/server controlled entity My questions Should the model check controller for updates or should controller update model during it's update phase. Which of these 3 classes should be 'master' class that manages constuction/destruction of all 3. What virtual functions should be in controller class - does the AI code for eaxmple reside in the controller class or is the AI class separate from contoller. Should the mouse/keyboard input code be in controller or separate. How do I account for the network controller - ie the client gets out of sync with the server and needs to adjust its position - does the network contoller take control of the controller or does it update the model directly. Is this the best architecture to use in this case. [Edited by - tonyhnz on June 1, 2005 8:21:20 AM]
Advertisement
If the object's state is dictated by the remote server/node then I would only have a network controller, no local one. Local input would be sent to the server which would respond with the position updates. Later if you find this performs too poorly, you can add interpolation, and it ought to be clearer by then where to perform that interpolation.


Pet Peeve: MVC is an architecture not a pattern, you can tell because it's composed of several patterns (design patterns are atomic).

- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I edited the pattern reference.

The complication with having the network controller control the player entity is that I want network spikes to be not noticed by the client. So if player is moving then the player should keep moving even if the server is unreachable for a period of time.
I was therefore thinking best approach would be local controller controls the player entity and it gets periodic validations of its position from server. If it gets out of sync with server then it has to adjust the local position to match. Also the local controller can only run for a certain time without server validation at which point it stops.
This sounds like what UT does

This topic is closed to new replies.

Advertisement