• Advertisement
Sign in to follow this  

Optimization info about 'world' in MVC design

Recommended Posts

Hello all,

My question is a bit hard to describe but hopefully it will do...

I just wonder what you guys think is the 'best' way of getting info about the model in your view(s)..

To clearify (i hope ;-) )

If the model is updating itself every game-cycle and the  (deep) nested objects all do there jobs how do you get info where only the view is interested in?

So my question is not how to do it but more what do you people think is the best way to do it ?

 

Regards,

 

Alex   

Share this post


Link to post
Share on other sites
Advertisement

Firstly, if you have a complex nested set of models, you should consider whether each of those objects should have its own view, instead of trying to have one view represent a lot of different things.

Secondly, it's usually simple to have a model tell a view when something has changed, and then the view knows to refresh data from the model. Does that not work for you?

Thirdly, the MVC approach is not very common in games, because it's not always a great fit. MVC was originally designed for event-driven user interfaces, and it works well for that system, where the model changes in response to user input from the controllers. It doesn't work so well for games and simulations where the model changes independently of user input and therefore the view needs updating often - typically on a fixed rate (e.g. 60 times a second) regardless of what has changed or what input has occurred.

Share this post


Link to post
Share on other sites
52 minutes ago, Kylotan said:

Hi Kylotan,

First of all thx for your fast and senseful reply ;-)

"Firstly, if you have a complex nested set of models, you should consider whether each of those objects should have its own view, instead of trying to have one view represent a lot of different things. "

That's an interesting approach....

"Secondly, it's usually simple to have a model tell a view when something has changed, and then the view knows to refresh data from the model. Does that not work for you? "

I guess you are reffering to the Observer pattern which i know would probably work, but i just would like to know whats the best way (how do you do it) to do it in design respective OO way...

In my situation it is not a 'solid' MVC design but its for an project on android..where the view (surfaceview) instantiate the world which updates itself every cycle and tells the  'important' stuff through states (i.e. collision,game over etc)  But let's say there is a car amazingly nested all the way to a bolt(s) object(s)  and you want to tell something in your view about that specific bolt (lets say it becomes loose).

Would you 'ask' (method) the world->->->->n (bolt) ?

 

 

 

 

 

Share this post


Link to post
Share on other sites

If the model changes infrequently, then the observer approach is the standard way to tell the view that it needs to redraw. In most games, the view is redrawing constantly, so there's no need for any notification, just do it every frame. I don't know how Android wants to work at the level you're working at, so I can't advise beyond that, unfortunately.

If I had a game where there were visible objects all the way down to a car's bolt, then that bolt would have its own visual representation, i.e. its own view. This might be a 3D model, a 2D sprite, or similar.

Share this post


Link to post
Share on other sites
19 minutes ago, Kylotan said:

If I had a game where there were visible objects all the way down to a car's bolt, then that bolt would have its own visual representation, i.e. its own view. This might be a 3D model, a 2D sprite, or similar.

And if its a non-visual ? (container-n class) 

Share this post


Link to post
Share on other sites
41 minutes ago, Tanzan said:

In my situation it is not a 'solid' MVC design but its for an project on android..where the view (surfaceview) instantiate the world which updates itself every cycle and tells the  'important' stuff through states (i.e. collision,game over etc)  But let's say there is a car amazingly nested all the way to a bolt(s) object(s)  and you want to tell something in your view about that specific bolt (lets say it becomes loose).

This is strange, because the view is passive in all variants of model presentation patterns. It shows what is there, but it does not create something. A game world is created by the level loading system. The view is just the output media of the rendering system, not more. Moreover, the renderer system just renders the view as a presentation of the current state of the world, so the renderer and especially the view need not be notified about world state changes. The only necessary thing (dependent on the OS) may be to set the view to dirty, so causing a redraw on the next opportunity.

23 minutes ago, Tanzan said:

And if its a non-visual ? (container-n class) 

I don't understand. Could you perhaps describe your problem by an example?

Share this post


Link to post
Share on other sites

Hello Haegarr,

 

Thx for your reply as well ;)

On android the 'view' is not so passive i think (like i said its not really mvc but...)

The surfaceview gets the update tick from the OS...so it creates the world (model) which creates all the other stuff then updates itself every cycle ...the surfaceview asks about all visual objects and draw them on the screen.

main  game state is guarded by return enumeration from world.update (levelover,gameover)

But what if the level had waves which have rounds which have parts etc etc...and you want to display the end and beginning of the nested stuff? (level 10->wave8->round14->part1 ) i know its a stupid example but just to make the point ;) would you ask every cycle if they are changed or make a message queue in world or like Kylotan suggests do it with subscribing through observer pattern

 

( i might do it wrong thats why i ask what's the best practice, i just want to learn from you guys)

Share this post


Link to post
Share on other sites

"if the level had waves which have rounds which have parts"... none of this is relevant to the view. Nor is anything about "return enumerations".

The view needs to know what to draw. That's it. In a game, the things to draw tend to fall into 2 clear categories:

  • concrete things with a dedicated visual representation. That visual representation might be a 3D model, a 2D sprite, or similar. You set up the view for those objects when the object is created. That object usually has a way of getting itself onto your screen.
  • abstract things that need to be displayed some other way, such as a current score or some floating text. Usually you work around this by changing the problem into the first problem and either creating a concrete representation (e.g. a TextBox that references the data).

The model needs to expose whatever methods are necessary for the view to get the information it needs. There's no super trick here - you just need to edit your model to make this possible. This is much easier if each entity has its own View object and its own Model object, because the View can reference the Model in each case, without needing to dig into hierarchies or whatever. But if you really want 1 View to be able to display a whole hierarchy of things in a Model, that is fine - you just need to make sure that the Model exposes methods to return that data. What data is that? No idea, it's your game.

Talk of message queues and ticks are also missing the point. Your options are simply these:

  • If the model is changing all or most of the time, the view needs to reflect that, so it should poll for updates frequently.
  • If the model is changing infrequently, it can notify the view of a change via an observer.

That's it. You don't need a message queue. The view just reads the data from the model when it needs it. If you find yourself doing too many updates because a small part of the model changes frequently, you probably need to break down your model into smaller parts.

Share this post


Link to post
Share on other sites

Thx Kylotan, like i said just tried to find the magic OO trick ;-) to poll constantly feels inefficient (allthough it's how i do it now)

Share this post


Link to post
Share on other sites
47 minutes ago, Tanzan said:

On android the 'view' is not so passive i think (like i said its not really mvc but...)

As Kylotan already mentioned, a game usually runs in another way than an application does. The surfaceview is a vehicle that the operating system is enforcing you to use. Nevertheless you can just use it as the driver to tick your own game loop. Such a game loop is usually build as a defined sequence of systems / modules / services / how ever you name it. All stuff that belongs to world updating (e.g. player input, animation, physics, collision resolution) is done early in the sequence. The graphical rendering is done at the very end of the sequence. Because the belonging modules are already updated, the world state is fix at the moment of rendering. Due to this, the view (understood as the presentation of what the renderer renders) is passive.

40 minutes ago, Tanzan said:

Thx Kylotan, like i said just tried to find the magic OO trick ;-) to poll constantly feels inefficient (allthough it's how i do it now)

If rendering is done all the time anyway, stuff like the level name, wave number, etc are just data values within the world. The renderer considers them simply by - well - rendering some text of other visual representation in its normal update phase within the game loop. It is not exactly polling. It is more like an immediate mode user interface stuff. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By TheDerpGamer
      (I realized I should probably just make a new thread now that I've gotten a plan together)
      Skies of Eden
      Skies of Eden would be a multiplayer voxel-based space sandbox where you could build anything you want. It would have procedurally generated planets, and you could deploy tanks and ground craft. You would also be able to create large stations.
       
      Planets
      Planets would be generated as soon as you hopped into a sector with one. The planet generator would first generated an image of the planet to be shown outside of it's atmosphere, then the actual planet chunks itself would be generated based off the values from the planet image generator (for example: an orange gassy planet would have orange/dusty terrain). The chunks would be large hexagons that would be loaded and unloaded as players passed near them, rather than rendering the whole thing at once, which would save a lot on performance. The player wouldn't be able to see the chunks loading in as the atmosphere would cloud their vision until the chunks were loaded (kinda like a loading screen).
       <-- A close example of how chunks would work
      The chunk layout on the ground would not actually be a sphere, rather it would all be a flat plain. However, the chunks would load so that it would appear to be one continuos sphere.
      (Note: Planets will most likely not be in the first alpha release)
       
      Weapons and Turrets
      Energy Weapons
      Energy Weapons will only use ship power, and have no ammo costs
      Cannons: Broadside close range cannons that have little penetration, but a lot of destructive power.
      Beams: Long range weapon with high penetration, but also high power cost and recharge time.
      Pulse: Kind of like a wave or something, good for EMP weapons.
      Physical Weapons
      Physical Weapons do more damage than energy weapons, but require power and ammo
      Missiles: Self explanatory. Literally just missile pods.
      Mines: Again, self explanatory. Space mines that can have stealth modules in exchange for less damage.
      Bolts: Sort of like a railgun. Shoots a single shell that has high penetration and explodes once inside an enemy ship.
       
      Energy weapons can also have effects added, such as EMP or anti-shield. This will greatly reduce their actual block damage, but will give it a useful effect for combat.
       
      Shield Systems
      Shield systems will not absorb all damage. Instead, they will take only the brunt of the damage, and the player can choose where to focus the most shielding. Anti-shield weapons can briefly weaken enemy shields so that their ship takes more damage.
       
      Stations
      Players will be able to make stations in SoE. These stations can have many uses, but are vulnerable to enemy forces. All factions will be allowed to have 1 "home station", where they can dock their ships and respawn. It will serve as their hub, and cannot be damaged. However, when a sector has a faction's home station in it, the sector will not automatically spawn resources (like asteroids) over time. This is to encourage players to spread out and make bases in other sectors. Factions can also claim planets using a claim block. This claim block will be how faction members can manage their forces on the planet and can provide a real time map of loaded chunks if they have support satellites. Planets cannot be destroyed, but they can be captured by an enemy faction if they break the claim block.
       
      Resource Gathering
      Players will have to mine asteroids for resources in order to make stations. Eventually, they will be able to create mining and shipyard stations in order to boost production.
      Mining stations will automatically mine nearby asteroids, and shipyard stations will automatically process materials and can build ships from those resources on demand.
       
      AI
      Players will be able to create AI fleets, which can patrol and assist in combat. Eventually, there will also be NPC crew mechanics and lua scripting.
       
      What We Need
      We will need programmers, artists, and modelers. The game will be in the Unity engine, as I feel it is best for this type of game.
      To apply, please join our discord below.
      https://discord.gg/BuxPsDs
       
    • By standinonstilts
      Hi, I am new to Game Development and am currently making my first game in Unity using c#. I am a second year uni student studying computer science (internet security specialization). I am new to unity and have had trouble understanding how the game engine actually functions and how I should use the engine to my advantage when programming. Currently I am making a RPG and want to implement an efficient and scalable item database. My plan is to store all items in the game in an xml database using the built in unity xml serializer. I have an abstract class item -> weapon, armour, potion, ring etc. Each of these classes have respective values (damage, cost etc.). For a relatively generic and straightforward item system: How would you organize your code? What interfaces/classes/other would you implement; why? In your experience what kinds of issues have you run into and how did you work around them? Is there any other advice with regards to rpg design in general?
    • By Giusto Piedimonte
      Hi everyone, my name's Giusto and this is my first post in this forum
      First of all sorry for my english but i'm from italy so i might go wrong in some words
      I would like to start programming games, like a lot of people, but i would like to program them litterly and not using something like Unity even if i know it would help a lot
      I'm a student, i'll take the diploma in 2 year, i'm studing to program at school, i know basic c++, java and javascript but i would learn more about game programming
      So my question is simple, which language should i learn? I know that C++ is used a lot as well as java
      Where could i learn some function or things based on games
      I listen to all hint that you give me, thank you for reading all this, this means a lot for me
    • By Affgoo
      https://play.google.com/store/apps/details?id=com.NE.Alien
      still a lot of work to do, but its pretty stable  please let me know what you think <3
      Atlas Sentry is a game of destroy everything. Using your turret, simply swivel and shoot your way to victory, upgrading your weapons to unleash destruction on the variety of spaceships. The bigger your combo’s the more score you get! Earn silver as you play and then purchase new weapons and abilities to better deal with your enemy. Different enemies use different tactics and weapons, work out your own priorities in their destruction order. 

      Features: 
      **2 different game modes 
      **A level select mode with 20 difficult levels including a final boss, can you defeat it? **Arcade mode of endless destruction, how long will you last? 
      **High scores to compete against others, see who can take the top spot. 
       
    • By DustyEffsky
      TL;DR:  zombie shooter game, looking for UE4 Coder and writer
      Cold Comfort is an asymmetrical Multiplayer Zombie Tactical Shooter (MZTS?!) with a focus on co-op and environmental destruction. (Currently under development)
      I started this project two years ago on my own, and in the last 6 months I've been getting more people involved in the project. Presently there are 20 of us! As most of the team is spread out across the globe, we do the majority of our collaboration online on Discord.
      This is a deferred payment project. We use HackNPlan to organize the project and to log hours, which will be paid out once the game has been released.
      We are planning on doing a Kickstarter the first half of this year and hopefully release the game in 2019..
      We are in need of:
      - a UE4 Coder
      - an author ( for the audio script, and lore)
      . VFX Artist
      More info on the project can be found on our website and on our community discord channel. 

      Interested? PM me for details! 
       
  • Advertisement