Game Design, Programming and running a one-man games business…

Sample C++ game loop : Democracy 3

When I first started coding, especially when I first did C++, there was a lot of confusion about where exactly the ‘game’ was, and more specifically, what a main game loop looks like. Because these days, all you hip kids code in Unity or Gamemaker or MyFirstIDE or some other colorful beginners IDE for the under 5s*, you never actually see your game loop, and have no idea where it is, let alone what it does., However, us real-men who code from the ground up have to write one. Here is mine from the PC version of Democracy 3. There are few comments, because in my godlike knowledge, I understand it all at a glance.

======================================================================================
void APP_Game::GameProc()
{
    HRESULT result = GetD3DEngine()->GetDevice()->TestCooperativeLevel();
    if(FAILED(result))
    {
        if (result == D3DERR_DEVICELOST )
        {
            Sleep( 50 );
            return;
        }
        else if(result == D3DERR_DEVICENOTRESET)
        {
            if (!GetD3DEngine()->Restore())
            {
                // Device is lost still
                Sleep( 50 );
                return;

            }
            Restore3D();
        }
        else
        {
            Sleep( 50 );
            return;
        }
    }

    GTimer looptimer;
    looptimer.StartTimer();
#ifndef _GOG_
    GetSteam()->Process();
#endif //_GOG_
    GetInput()->Process();
    GUI_GetCursor()->SetCursorStyle(GUI_Cursor::DEFAULT); //reset each frame...
    if(BActive)
    {

        GUI_GetMusic()->Process();
        GUI_GetSounds()->Process();
        if(PCurrentMode)
        {
            PCurrentMode->ProcessInput();
        }
        SIM_GetThreadManager()->ProcessFrame();
        GetTextureHistory()->Reset();
        LOCKRENDERTHREAD;

        GetD3DEngine()->BeginRender();
        if(PCurrentMode)
        {
            PCurrentMode->Draw();
        }
    
        GUI_GetTransition()->Draw();


        GetD3DEngine()->EndRender();

        RenderFont();
#ifdef _DEBUG
        if(GetInput()->KeyDown(VK_LSHIFT))
        {
            GetTextureHistory()->Draw();
        }
#endif //_DEBUG
        GetD3DEngine()->Flip();    

        RELEASERENDERTHREAD;

        looptimer.Update();
        if(looptimer.GetElapsed() < 16.0f)
        {
            looptimer.Update();
            if(looptimer.GetElapsed() < 16.0f)
            {
                Sleep(0);
            }
        }
    }
    else
    {
        ReleaseResources();
    }

    if(BRestartPending)
    {
        BRestartPending = false;
        SilentRestart();
    }
}

======================================================================================

*yeah I’m mocking different IDEs. deal with it :D This is sarcasm. There is no proven link between masculinity and choice of game development environment.**

**yet.

Oh god the streesssssssssss.

The last few months have been pretty tough for me. I basically did too much at once, and missed a few things, and made some mistakes and I am not the sort of person who shrugs things off and goes ‘well shit happens’. I get angry with myself for screwing up, and I don’t forget it, which means I get more stressed and argghh… I end up a bit like this:

stressed

which is obviously *not good*.

Recently we found a bunch of bugs in the implementation of getting Democracy 3:Electioneering (DLC for democracy 3) to work seamlessly with Democracy 3 Africa (A different game) without people having to re-buy it, or move any files. This sounded like a good idea at the time, as a programmer, but when running a business you have to realize that OH MY GOD it is not that simple.

The problem is that D3 is not just ‘a game’. That would be simple. It’s Democracy 3 on steam, on GoG, on the humble store, the mac game store, direct from us and also on ipad (which does not support the new DLC). Plus…its in OSX and Linux. Oh and also the builds for the French, German and Polish language are ENTIRELY separate (and the DLC is not translated). This means we have D3(direct)D3 German(direct) D3 French(direct) D3 osx(direct) D3 linux (direct), D3 Gog, D3 Gog osx, D3 steam osx, D3 steam Linux, D3 steam. D3 steam French, D3 steam German, D3 steam polish. Humble osx, Humble win, Humble Linux. Oh and there is a browser version on humble (but nowhere else, and only in English).

Holy fucking shit.

Then we added Democracy 3 Africa, which is multiple languages but ALL IN ONE BUILD, and thats on humble, GoG and Steam. Its in Windows and OSX, but not linux. BTW Africa doesn’t have polish, but D3 does, but only on steam, and in retail, because yes…D3 is in retail, but only in Poland.

Again…

stressed

So holy fuck. And I have fucked up a few technical things which I THINK are all now sorted, despite giving cause to angry emails and twitter outbursts and general stress., Plus today is the HOTTEST day of the year in England. (don’t laugh, we have heat some days). Oh and I nearly cut my arm off in a gardening injury (yeah funny huh?) and damaged my neck doing sit ups (you can laugh here), and had to miss DEVELOP which was the first time I’d bought a full conference pass and booked a hotel . FUCK.

So ideally I’d have all this behind me now and be heading back to my favourite relaxing place (st lucia…)

not_stressed

Which I haven’t been to for three years because…being a treehugger, I rarely fly, and games conferences have kinda used up my personal angst budget for long distance trips for a while. But wait! there is good news ahead…

Firstly, barring tech support, Democracy 3:Africa is DONE and shipped, Big Pharma Marketing & Malpractice is DONE and shipped, Electioneering is DONE and shipped. The only planned releases by positech games in the next six months are two third party games, Shadowhand and Political Animals. Both are looking in really good shape, and I am not writing a single line of code for either of them. YAY.

Plus its very sunny out there, the garden looks AMAZING, and today I am going to visit friends for a day and wont do much work. YAY. Plus I *have* actually learned a lot of lessons from all this stress. The most obvious one being that the less builds you have of your game the better. To that end… A lot of this mess is being cleared up by the super-talented Jeff from stargazy (he coded Democracy 3 africa). Soon(ish) we will have a Democracy 3 build for all languages (in unicode no less), and that will kill off a chunk of these useless bastard builds that cause me so much admin hell.

DOUBLE YAY.

Is it worth doing developer video blogs?

So first up, here is the latest exciting video of ME: I talk about stuff, including democracy 3 electioneering, and steam reviews, and modding and schools and injuries.

Maybe more bloggable, is why bother? A fellow dev with decent insight into these things asked me on twitter why I bother when I don’t enjoy it. The answers are that I do ‘kinda’ enjoy it, and also I don’t want to stick my head in the sand and be all easter island about it. I have had this blog for ten thousand years now, but times change. maybe video is the thing now. Remember when everyone used typepad (who?) or even LiveJournal (what?). yeah exactly. These days people use Medium, instead of WordPress, because… I have no idea. Soon a new blogging platform will exist every week. Is youtube even the thing now? does everyone use Vimeo, or twitch or is it all periscope these days?

Anyway..here are some stats:

The combined views so far of the last 4 youtube developer blogs for electioneering that are on youtube only (discounting therefore any facebook views, which would be promoted) are:

2,541 views.

Which is a) pathetic and b) more than 99% of lets plays (ahahahah…my little joke).

Compare that with for example, my last 4 blog posts (going by google analytics) which is only 1,715 views. However, that stats is total bollocks, because most people use the rss link and I have seemingly no username or password any more to find out how many. Arggghhh. The blog also occasionally explodes. For example in the last 30 days, blog hits have been 14,027, which isn’t *that* shabby. Over the last year, average blog views per day is 664, which is 15% *up* on the previous year. So thats not bad. And they have a long tail. I get currently about 300 hits a day (yup!) on a blog post from 2011 about fixing pc game crashes.

So there isn’t an overwhelming crushing argument to say its worth me investing time in youtube. A video blog takes me roughly 4x the time and effort of a normal blog. Why bother?

Firstly youtube is still growing, and doesn’t look like its going to stop. Alexa estimates its the #2 site after google. Secondly, the traditional media increasingly looks like it cannot compete. Everyone talks about how their kids spend all their time watching youtube. Watching has become the new reading. You don’t have to read an article, you watch the writer talk about it, far less hassle. The future seems to be mobile phones + video content,. and if I don’t have any strategy for mobile (and I don’t) I should at least put *some* effort into video.

Thirdly, I suspect video content is ‘worth’ more. Someone reading a review of my game will be fairly informed and aware of the game, but somebody WATCHING me or a reviewer actually playing it gets a MUCH better feel for what the game is like in actual usage. A picture paints a thousand words, and a video, with most games can paint a thousand pictures. Also, if the developer is actually *in* a video, it humanizes the developer a bit. I have no clue who designed or coded Star Wars Battlefront, but when I get used to seeing someone’s face and hearing them talk about the game, it seems a much more ‘real’ connection. I’m pretty sure thats a fairly common reaction, and is why I’ve started sticking my elderly unshaven mug in the videos :D. It also vaguely helps with public speaking confidence in some weird way, which I think might help long term when I promote some new stuff.

Don’t get me wrong, I’m not closing my blog, I love doing the blog, but I aim to produce a lot more video content than before. Now I’ve got (vaguely) into the groove of uploading stuff, its getting smoother and less hassle, and I think from a marketing POV, its sensible and worth doing. Tips on how to make better content are very welcome.