• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Reactorcore

[Help] How do you properly organize game architecture?

10 posts in this topic

Hello!

For the past months I've been studying programming and I've finally learned how to code, but one thing that is confusing me is how to properly organize the design of a game project - code wise.

The game I'm building is a pretty standard commercial game. It has the basic components of a normal game: A world, characters and items interacting with each other and all of this is run by game manager. Basically you play as a hero in a world and do stuff. Fight, explore and interact.

Think of your standard adventure game that starts off with an intro, goes to the menu system, then gets into the game and back to the menu. Pretty much like 99% of any commercial game or otherwise serious game projects. Thats what I'm aiming at.


[size=5][b]The problem is:[/b][/size]

How do you properly code a commercial game architecture?

How do you organize it?

How do you make it not become unmaintainable spaghetti code?

What specific things to keep in mind when building this, codewise?


[size=5][b]How you can help me:[/b][/size]

[b]a)[/b] Please tell how do you code your own game projects. What is your thought-process when designing the architecture?

[b]b)[/b] Recommend books, blogs, tutorials, videos or anything else on how to organize a commercial video game.

[b]c)[/b] Give hints and tips on do's/don'ts when building a game, codewise.


Please help! Edited by Reactorcore
0

Share this post


Link to post
Share on other sites
Hey,

Well
1 [color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]How do you properly code a commercial game architecture?) Keep everything slip, so if you have a hero keep everything that is related to hero in hero, if every class looks after itself you wont have any problems down the line[/background][/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]2 [/background][/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]How do you organize it?) Like above, just keep every class specific.[/background][/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]3 [/background][/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]How do you make it not become unmaintainable spaghetti code?) There is nothing wrong with white space and comments, just comment every method so you know what that method does.[/background][/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]4 [/background][/left][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]What specific things to keep in mind when building this, codewise?) The class you are coding, thing of everything it needs to do and what it needs to return, or you will be going backwards and forwards adding new code.[/background][/left][/size][/font][/color]

[b]a)[/b][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)] Please tell how do you code your own game projects. What is your thought-process when designing the architecture? [/background][/left][/size][/font][/color]
[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)]notes, lots and lots of notes with explaining what each "thing" will do.[/background][/left][/size][/font][/color]

[b]b)[/b][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)] Recommend books, blogs, tutorials, videos or anything else on how to organize a commercial video game. Well to be honest it depends on what you are coding it? Java? C++? C? C#? XNA? SDL? SFML? Clutter?[/background][/left][/size][/font][/color]

[b]c)[/b][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][left][background=rgb(250, 251, 252)] Give hints and tips on do's/don'ts when building a game, codewise. Well in my experience I have made many mistakes, and the best thing to keep in mind, if your new this isn't easy, don't try and make your first project huge, like a 3D fps with multiplayer and in game currency bla bla bla, make pong or snake.[/background][/left][/size][/font][/color]
1

Share this post


Link to post
Share on other sites
[quote name='Reactorcore' timestamp='1341158310' post='4954560']
How do you properly code a commercial game architecture?
How do you organize it?
[/quote]
Design it in UML first. Approach your designs using a software methodology that are you comfortable with with, and get used to using things such as a subversion system. If your really interested in mastering game architecture, study it, [url="http://www.amazon.com/Game-Engine-Architecture-Jason-Gregory/dp/1568814135/"]Game Engine Architecture[/url], [url="http://www.amazon.com/API-Design-C-Martin-Reddy/dp/0123850037"]API Design for C++[/url], [url="http://www.amazon.com/Game-Engine-Architecture-Engineering-Applications/dp/012229064X"]3D Game Engine Architecture: Engineering Real-Time Applications with Wild Magic[/url].

[quote name='Reactorcore' timestamp='1341158310' post='4954560']
How do you make it not become unmaintainable spaghetti code?
What specific things to keep in mind when building this, codewise?[/quote]
Organize your code well, comment it VERY well. Design a coding "style" and do not skew from it. Take and implement insights from books such as [url="http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670/"]Code Complete[/url]. Edited by DevLiquidKnight
2

Share this post


Link to post
Share on other sites
Thank you so much for your replies, everyone.

[b]@ Canvas:[/b] I'm doing this in C# while using the Unity3D engine.
The things you talk about are pretty much the SOLID principles I've read somewhere, which reinforces how important they are.


[b]@ DevLiquidKnight:[/b] Alright, UML will be useful, but not until I know how to design the architecture in the first place, so those books you recommended will be the first step.


[b]@ Zoomulator:[/b] Your answer was very helpful. This is exactly the kind of information I was asking for, especially this bit:

[quote]
Doesn't have to be UML, just atleast graph it out on paper so you have a rough idea how things are connected that is clear to [i]you[/i] (and the future you). Some people like going with the top-down approach, all the way down. I don't remember which book it was that described the process, but it went something like this:
Start with a general overview of the whole system. Then for each object, make a general overview of it that's more specific. Re-iterate until it'd be easier to code it than to describe it, and so code it.

[/quote]

Also I really like how the event driven system sounds and is exactly what I'd prefer to build. Can you give any pointers on how you start building such architecture?
Again, I'm doing this in C#, if it matters.


[b]@ L. Spiro:[/b] While I do agree with you that experience is a great way to learn, I'd argue that a good preparing education is a even better. Even now, I could just go ahead and start cowboy coding blindly and get something working, but it will be a mess and not robust, which is vital to this project of mine, because its meant to last.

I'd rather spend time studying and understanding how to properly use the tools I've got and have good understanding of healthy coding principles before starting to build anything. Doing otherwise is pretty much the same thing as shooting yourself in the foot. It will be frustrating and the end result won't be good either.

Sure, you could refactor constantly if you choose to develop your game in this brute-force like manner, but in the end that will also take time and effort, which you could have used to study the subject properly in the first place. Thats my opinion on this.

Anyway, I find your blog really helpful and not just the links you posted too, you've got some other very neat posts there too like, [url="http://lspiroengine.com/?p=351"]this one[/url] and [url="http://lspiroengine.com/?p=378"]that one[/url], so I'm going to spend a good amount of time reading your blog, so thank you for writing it. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] Edited by Reactorcore
0

Share this post


Link to post
Share on other sites
[quote name='Reactorcore' timestamp='1341409963' post='4955621']
I really like how the event driven system sounds and is exactly what I'd prefer to build. Can you give any pointers on how you start building such architecture?
Again, I'm doing this in C#, if it matters.
[/quote]

Well, I'm using C++ and I don't know what extra tools you get in C# at all, unfortunately. [url="http://www.gamedev.net/page/reference/index.html/_/technical/game-programming/effective-event-handling-in-c-r2459"]This article[/url] inspired me a lot for my current event system. What I've done most recently is to wrap an interface such as this around ØMQ, allowing me to fairly safely send complete objects as messages. Using ØMQ allows it to be either thread safe in-process messaging, inter-process or over TCP almost completely fluidly. ØMQ is blazing fast too and optimized to take some million requests a second on large servers but still really easy to use compared to handling classic connection sockets. There's C# api (and many others) but I can't vouch for it. It's also not all that common in games from what I understand.

The basic idea anyway, is to have listener objects registering to a dispatcher object. It's basically the observer pattern, but a bit more centralized. You register to certain 'global' events, rather than all events from a specific object. Any object wanting to send an event does so via the dispatcher. Fight the temptation of making it a singleton though.

Event systems have one downside, especially if you're using one big (or a couple*) central one(s) such as I do. It's not very performance optimized, since you've got a big middle hand between all objects that communicate via it. The flexibility added usually outweighs this problem [i]imo [/i]and the more performance intensive algorithms are usually isolated in one of the modules. But keep in mind that they can be saturated if there's a lot going on in a real time game.

I'm using two dispatchers in my current project. One for strictly local application events, such as window, input and inter-module communication (I've got a server object running on it's own thread). The other one is for the game events which the rendering and network listens to.

There's also a few varieties of how and when to handle the messages. You can put messages into a queue and poll them when it's the objects turn to update. This is what I do with my ØMQ version. This means the queue has to be handled at regular intervals. A second and not very thread safe way is to make them call instantly. My first did so. The message handling took place inside the send method of the dispatcher, as it looked up and triggered the event handlers of the listeners. It's a matter of taste and need which you'll chose.

Since you're not familiar with the concept yet I'd recommend not to use ØMQ or threads for your first few projects. Make a simple 'instant' message dispatcher and tweak it until you're happy with what it's capable of doing. When you feel more comfortable with that, move on to the more advanced and flexible ones. Edited by Zoomulator
1

Share this post


Link to post
Share on other sites
[quote name='Zoomulator' timestamp='1341485406' post='4955925']
Event systems have one downside, especially if you're using one big (or a couple*) central one(s) such as I do. It's not very performance optimized, since you've got a big middle hand between all objects that communicate via it. The flexibility added usually outweighs this problem [i]imo [/i]and the more performance intensive algorithms are usually isolated in one of the modules. But keep in mind that they can be saturated if there's a lot going on in a real time game.
[/quote]

This is something I was very curious of when I was reading out about delegates and events, turns out that yes there is an overhead when doing this. I don't know if I'll be using events for the entity system, but two areas where events seem to be very good for are the menu system, which one should be able to evoke anywhere, even during gameplay, and the other is the metalogic of the game that deals with win/loose conditions as well as other major events happening during gameplay.

Not sure about the whole ZeroMQ thing. If I understood right, its something you can use for networking in your game, either between 2 programs on the same machine or between 2 programs over different machines? My game will not have online multiplayer, so I'm not entirely sure if its for me.
0

Share this post


Link to post
Share on other sites
[i]About performance:[/i] It still requires a very large amount of events before it's bogged down and as I said: it's not always the event system that needs to be fast. The logic gets a message, it does something that's probably pretty heavy relative to the actual event transmission and then it sends it's own event. The most performance will most likely still be required in the logic itself and the observer pattern will most likely remain one of the better options for that, since it's more direct. The best way is simply to stress test your event system if you're unsure and see how many calls to how many handlers you can pull off per second. If it were to happen that an event system would be saturated you can lessen the load by batching and revisiting the need for some events. It's likely you can stretch it quite far. All I'm saying, don't write it off until you've tested it for the current case.

I'm using events only as a glue between input handling, logic, networking, rendering and other systems. You [i]can[/i] use it internally in the logic as well, but that could become a performance issue a lot faster. There's another issue of event systems: it can make the larger picture more difficult to follow and the order of execution between events may not be explicit which can cause determinism issues. This is especially true if used in the game logic because it tend to become quite intricate. Using it just to notify other systems keeps it rather simple.

An event system can also help if you plan on adding some sort of scripting. The scripting engine can be detached and communicate with the logic via events, rather than littering the logic with the scripting. Same with AI, which most likely will be using some scripting itself. Make higher level functions in the logic be accessible via events, and both GUI and scripting will be able to access them easily.

[i]About ØMQ:[/i] it gives you a highly efficient queuing system. I'm mainly using it because it lets me have a thread safe messaging system. ØMQ's context is completely thread safe which makes it possible for different threads to pass events between them. If you keep the messaging system the only means of communication between threads, it practically removes the issues with race conditions and many other problems related to threads. It's not a holy grail of multithreading, but I find it fitting for my purposes and you might not. Main issue would be it's asynchronous nature, which isn't as efficient in a single threaded environment.

I see the possibility of networking as an added benefit. I lay out the structure of my game so that communicating with a remote client is virtually the same as communicating with the local neighboring thread client. It sends the same messages, only via a different pipe. ØMQ will also gladly take any number of channels to communicate, meaning an indefinite number of clients (network or threads or just objects) can be added with relative ease. I've heard claims of some mmo's using ØMQ and that it was quite sufficient, but I can't really back it up..That's enough of me selling ØMQ for now =P

I'm not making a real time game, which wouldn't be as simple as just 'hooking it up remotely' the way I put it. You have to do prediction algorithms and other jazzy stuff.. a good reason why network multiplayer is such a pain in most cases.

But as I said, it's probably a good thing to wait with ØMQ anyway but it's good to know that it's there.
1

Share this post


Link to post
Share on other sites
I've never heard of a queuing system in programming before, what would one use it for and why?

The game I'm making is a singleplayer-only real time action game and it is not scripted in any strict way, besides how you start and how you end. You are put in a world, given a character and a big goal, which how you complete it, is completely up to you using the environment and other stuff you have. So from that standpoint, I could guess a queue system would be important for a game that is story driven or very scripted in how it unfolds, so in my case it would be irrelevant, right?

Sorry if I sound stupid, I'm a bit of a newbie-in-the-process-of-learning when it comes to programming.
0

Share this post


Link to post
Share on other sites
In simple words, a message queue is where messages are stored until they're handled. Call it a buffer if you'd like. If you've ever used SDL, its events are put into a queue, which you pull the events from at a good time in your main loop. A message queue is required here because your program can't just stop in its tracks when ever SDL receives a new input and asks your program to handle it. Instead, you get the option to look at it later.

This is called asynchronous message handling. You fire off an event and it may be handled at what ever time the receiver thinks is a good time. Much networking works like this and things like Node.js make use of it to a great extent.

The opposite is synchronous message handling in which case something fires off the event and wont continue execution until the event is handled. No queue is required here, because the receiver will only handle one message because the sender wont be able to send more than one message at the time.

Apart from being essential for networking and multi-threading, a message queue can also be used if you want to send events that wont be handled until the next game turn or "tick". Of course, a message queue can be polled at less frequent intervals.. I don't have much say in that. But the most normal use would be for it to handle events each iteration of the game loop. Edited by Zoomulator
1

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  
Followers 0