Jump to content
  • Advertisement
Sign in to follow this  
Somnia

Communication between game objects and the UI

This topic is 4118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having trouble getting my head round how to organise this. At the moment I have a sort of main controlling class which organises the game objects and the UI object. My UI class at the moment is pretty dull, is just has a draw function which puts a textured quad towards the bottom of the screen. I want to try and take things forward. I've been aiming for a game type which mimics the Total War series. (Which isn't to say that I think I'm actually going to make a total war type game anytime soon, it's just the problem set I've decided to start with as a learning thing.) Anyway, some parts of this could be straightforward. For example the UI needs to display unit information such as the number of men and so on, but that information only needs to go one way, since it can't be changed from interacting with the UI directly, so you could just loop over the units each frame and copy the information over to the unit icons. Similarly there is stuff that only goes the other way, like unit formations and so on. However, there are some properties that can be changed in both the game and UI. Selecting a unit for example can be done by picking the game objects or by clicking on the unit icon. In this case the UI and the game might end up with different ideas about what is the selected unit without knowing who is right. My first thought to get round this is to have some sort of message class. The main controlling class would then have a list of these message objects, and would pass a reference to this list to the relevant places, and then the list could be processed the next frame. I'm not really sure how to make my message class work in a way that's efficient and easily extendable though. The most completely naive way to do it would be just to store an ID, say either a string or an enum, and then have a big list of rules like if(ID=="setformationwedge") then ... and so on. You can obvioudsly make that better, although I wondered if this isn't on completely the wrong track and perhaps there are better standard ways of doing this. (Also, I noticed an interesting thing while browsing the modding section for Neverwinter Nights 2. Apparently they allow modders to make specify new UI elements, I think in terms of functionality and presentation, just by writing files in a markup language. This sounds quite fancy, I don't know if it's the standard for professional games, although it's probably not the sort of thing a noob should be worrying about.)

Share this post


Link to post
Share on other sites
Advertisement
"Just because two bits of code shouldn't know about one another does not mean that another piece cannot know of both."


That said, a message setup or event system are two very common methods of abstracting that sort of communication.

Share this post


Link to post
Share on other sites
Quote:

Also, I noticed an interesting thing while browsing the modding section for Neverwinter Nights 2. Apparently they allow modders to make specify new UI elements, I think in terms of functionality and presentation, just by writing files in a markup language. This sounds quite fancy, I don't know if it's the standard for professional games...


Its quite common to allow a game to be customised with some kind of scripting language.

Hell, even my little Asteroids game uses Lua scripts to control most of the entity logic, and some random other bits of functionality. As you can imagine Asteroids isn't really a GUI oriented game, so I haven't added GUI oriented stuff like buttons, etc. But I do have a scripted input system and image display, so I could throw something like that together (keyboard controlled).

Stop it, you're giving me ideas! [grin]

Scripting is not insanely hard either. Not saying that it is trivial or anything, its just I was expecting something so flexible to be a lot harder.

Quote:

...although it's probably not the sort of thing a noob should be worrying about.)


Quite true, but I never imagined my games ever containing such things. You will get there yet! [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!