Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 29 Jul 2001
Offline Last Active Today, 12:02 AM

#5187047 How to Separate the Rendering Code from the Game Code

Posted by Promit on 14 October 2014 - 05:41 PM

You guys are all overcomplicating things drastically. I've found that the best solutions are also the simplest. The aforementioned interfaces are appealing to OO-addicts but ultimate serve very little in the way of actual practical purposes, and tend to create more strong couplings and implementation assumptions than you initially realize. (Mike Acton would call them "typical C++ bullshit".) Entity component systems have their uses, but ultimately if you don't understand how to solve this problem in the first place then ECS just adds another mess on top and serves to obscure the failure to tackle the actual problem.


Let's take a simple 2D RTS. What data is needed by just the renderer to compose the main scene?

struct Tile
    struct Texture* tileTexture;
    Vector2D position; //in whatever coordinates you want

struct GameUnit
    struct Sprite* sprite;
    int animationFrame;
    Vector2D position;
    float rotation;
    //add properties like color tint, alpha, etc as needed

That is the only communication that you need between the renderer and the game. The game's render function doesn't call any low level rendering functions; it assembles arrays of these structures. The renderer's job is to accept these structures and put them on screen. That's it. You may wish to elaborate on classes like Sprite and Texture, or leave them as opaque and configure them through some kind of overarching Graphics object. But this is, as written, very simple to express in pure C and it's not necessary to add more complexity even for modern shader based 3D games.


Notice a key difference in how I'm thinking about the problem and how you're thinking about the problem: the game code does not contain the information necessary to render the scene. That creates coupling between components. Instead, the game code builds the information necessary to render the scene, and passes it on. The change in perspective may seem slight, but it's fundamental to how modern graphics systems are designed. If you do this right, then the renderer can completely recreate a frame from its input data with no outside interference, including releasing the entirety of the game objects' memory -- or never creating them in the first place. And now with some judicious save/load code, you can capture, replay, and debug graphics frames in a tool that has NO game code in it.

#5186762 Do you use UML or other diagrams when working without a team?

Posted by Promit on 13 October 2014 - 03:10 PM

I feel that code structure diagrams are unnecessary, period.

#5186595 Should i to compile using static library or shared library?

Posted by Promit on 12 October 2014 - 08:14 PM

Shared libraries introduce potential for mistakes, due to rules about memory management and library versioning. Converting static libraries to shared can lead to huge headaches. My preference is to set things up entirely as static unless I have a specific reason to want a shared library. I rarely do.

#5186198 Are mobile games revenues real?

Posted by Promit on 10 October 2014 - 10:58 AM

Actually I've been curious why more indies don't share more concrete info about their revenues/sales. Is there some reason to not do so?

#5186085 safely researching PC games

Posted by Promit on 09 October 2014 - 06:00 PM

Also, Windows 8 does have an actual app store, though I don't know how much is actually on there.

#5185902 BitmapFont - looking for atlas-packing-function

Posted by Promit on 08 October 2014 - 09:28 PM

This is essentially state of the art, and written by a fellow GameDev member to boot.
There's probably ready made code out there... I believe Freetype-GL has an implementation.

#5185649 If you ever used a vector in c++ could you show...

Posted by Promit on 07 October 2014 - 06:28 PM

I guess this explains why performance might take a hit using vectors. Hopefully my game won't suffer accessing a list of a few hundred at a time.

There's no bigger performance hit in a game than crashing. And my experience in the field has been that aggressive use of vectors (rather than raw memory) helps catch a lot of crash bugs early.

#5185648 How to prepare myself to get a job in a AAA game company?

Posted by Promit on 07 October 2014 - 06:25 PM

Some misc thoughts on the matter:

* Know C++ really, really well. Not just the usage of the language, but a lot of the design internals of the language, how code generation behaves, etc. We can go back and forth all day about the value of other languages in development, but ultimately it's the C++ experts who get the jobs first. 

* Have ONE demo that is GOOD and polished. I've had mixed results on whether studios actually want to see the demo, or see just the code, or ignore it entirely. But simply having it matters, and the more you can show the better. Alternately, have a demo that demonstrates some very sophisticated technical work that you did. This is useful if you're applying for a specialist job (graphics, physics, etc), not so much for a generalist game programmer job.

* Have a broad base of knowledge. Multiple graphics APIs, multiple languages, multiple engines, multiple everything.

* Be willing to work hard. Candidly, game development is not a 40 hour a week job and there's a lot of people willing to put the hours in out there. Some companies might pay lip service to "work life balance" but we all know it's not true.

#5185075 Mobile time killer: How fast to ramp up difficulty?

Posted by Promit on 05 October 2014 - 12:50 AM

It depends somewhat on the type of game, but generally the first ten to twenty minutes should be trivially easy. Then you ramp up exponentially from there. This is the formula that most mobile games tend to go with. It allows even casual players to get a feel for the mechanic, and then forces them to start working for it before boredom hits.

Remember that as a developer, you have little or no perspective on what your difficulty curve is for an outsider. Beta playtests are necessary to calibrate - ideally across wide audiences.

#5185060 Is 3D game development easier with an engine?

Posted by Promit on 04 October 2014 - 10:04 PM

While I agree with everything that's been said, I want to chime in with one thought for posterity's sake. Engines make development easier for nearly everybody. But if your team has a strong background in the necessary engineering work, and your goals are extremely focused and/or extremely unusual, an engine can make things worse rather than better. Existing engines are always designed around existing problems and use cases, and designed to solve those particular cases. If you are doing something that steps outside those bounds, it can be difficult to make an off the shelf engine do the right thing. This is not the norm, it does not apply to most people, but an engine is not a silver bullet solution to everything. 


IF you have to ask, then using an engine is probably the correct way to get a game done.

#5185039 Is upper division Linear Algebra a good idea or necessary?

Posted by Promit on 04 October 2014 - 05:51 PM

Computer graphics is like 70% linear algebra, 20% calculus, 10% misc. But that doesn't mean a course in linear algebra is useful, partly because a lot of courses and books on linear algebra are !@#$ing terrible. The proofs in particular are completely pointless unless you have aspirations towards a master's degree or PhD in mathematics.

#5184220 Ads in pc games

Posted by Promit on 30 September 2014 - 10:35 PM

This is the kind of thing that creates internet backlash, regardless of whether it's fair or justified. I wouldn't do it simply because the players will eviscerate you for it.

#5183895 Why is your computer slow when you close game?

Posted by Promit on 29 September 2014 - 03:55 PM

More likely than not, the game has simply consumed a large amount of system memory, forcing other applications and background services out of memory and onto disk/paging file. Loading everything back into active working memory takes some time.

#5182321 To Day I had to Resort To a FileBack Up

Posted by Promit on 22 September 2014 - 11:54 PM

Bit rot.


Hard drives (and all other forms of storage and memory) are constantly suffering errors, as a natural result of pushing the physical boundaries of what electrons can do. All drives, optical media, etc feature parity correction that attempts to detect and correct these errors. Parity can fail, though, and it's not always possible to figure out which bit is bad or what to do about it. These problems can be exacerbated by a variety of environmental factors, as well as bugs in the underlying platform. Your hard drive has hardware and software components. So does the motherboard. These can all fail in highly creative, undetectable ways. As a hard drive begins to fail, the uncorrectable error rate can spike, and checking SMARTmay be a good idea. Some file systems, notably ZFS, BtrFS, and ReFS are designed to handle these problems in more robust ways.


Alternatively, any random component (hardware or software) of your system may be malfunctioning, or you may have some type of malware. Good luck finding out what the source of the problem is.


Fraps did not break your computer.

#5182271 sqlite as db backend for mmorpg?

Posted by Promit on 22 September 2014 - 05:56 PM

SQLite is, for all practical purposes, single threaded. Anything that is not single threaded will make it behave very badly.