Lost in the lands of C++?

Posted by Astryl on May 17, 2012, 10:46 a.m.

I recently found this image floating around on GamaSutra:

Click to see full sized 18.5MB image

I declare 64Digits to be that bit near the North-Eastern corner.

Now discuss the C++0x/11 standard. I'll update my blog a bit later.

The rest of the blog, as promised

Well, I promised an extension on my blog, and boy do I need it. Two short blogs within the week? Am I ill?

Anyway, besides the fact that I nearly used a Lorem Ipsum generator to fill these blank spaces, I did remarkably little on my game in the last two days.

Besides drawing a goblin. I'll upload it tomorrow maybe.

Today I did spend some time extracting the framework code from my game's code, leaving me with a nice template to experiment with new ideas in. Also, it's a great way to create an OpenGL window with all the correct parameters set up (Besides the correct projection, but if you can't do that, you're hopeless).

To the hopeless:

// The quick and easy way to set up an OpenGL perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewPort(0,0,640,480);
gluPerspective(60.0F, 1.33F, 0.01F, 500.0F); // 1.33 can be substituded for 1.337 if you're feeling particularly idiotic :3
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Render as normal

Anyway, tomorrow I hope to animate my goblin (Three required: Standstill, Walk and Attack. Oh, and 'Hit' so that's four), and add him to the game.

I've discovered an interesting and ironic thing while working on this game: The programming of the game is the easy part. It's the art that takes time, patience and every four-letter word you can conjure up.

On the new C++ standard

You know, normally I ignore the C++ standard 'updates', because honestly, when in the last decade did they try and change anything?

Well, now they did. And started to give C++ some handy new features.

Of course, there are already a lot of myths floating around the net about C++11. Such as it's 'slowness'. The only slowness I've encountered with regards to the new standard is the speed at which both Microsoft and the maintainers of GCC are implementing them. Both compilers only support a fraction of the new features.

Anyway, here's an interesting piece of legal C++ code:

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

vector<string> vec = {"This","is","one","of","many","new","features"};

class TClass
{
    public:
        TClass():number(0),data("Nothing"){}
        TClass(int n, string d):number(n), data(d){}
        ~TClass(){}

        string getdata(){return data;}
    private:
        int number;
        string data;
};

// This is previously unheard of:
TClass g_tclass[] = {{0,"Pretty"},{1,"Darned"},{5,"Useful"}};

// How about this?

class CClass
{
    public:
        CClass(int x):x(x){}
        CClass()
	{
	    CClass(5); // Delegation
	}
        ~CClass();
    private:
        int x;
}

// Here, have some more:

int main(int argc, char** argv)
{
    auto var1 = "Auto types";
    // Almost weak-typing, but not really, because 
    // adding in var1 = 4.55F; would be illegal right now.
    // There is also declspec(), but it works differently.
    // Both are determined at compile-time, meaning no speed impact.
    
    // Lets print the data I defined earlier, the new way:
    for(auto i : g_tclass)
	  cout << i.getname << endl;

    // And the vector:
    for(string i : vec)
    	  cout << i << endl;
    
    // Old method would be one of these two:
    for(int i = 0; i < vec.size(); i++)
	  cout << vec[ i] << endl; // That was messing up my [ i] tags...
    for(vector<string>::iterator i = vec.begin(); i != vec.end(); i++)
	  cout << (*i) << endl;
}

Other benefits include Lambda functions (Anonymous functions), base-constructor inclusion, elimination of several 'copy' problems with temporaries, an override keyword, a final keyword (nor really keywords actually, kinda language constructs, but does the same as you'd expect them to do), new smart pointers, and the ability to nuke sites from orbit at the press of a button. [Citation needed]

Anyway, discuss. Point out the supposed issues with the new standard, at which point I will happily condemn you to a C++-less environment, where you can spend your time coding in FORTRAN, COBOL, or FORTH.

I actually have a reason to discard all the 'speed' claims. C++ still does what it does best: Generate efficient machine code, then assemble and link that into executable object code. And so far, looking at the output of gcc -S, it seems pretty darned efficient

Comments

svf 12 years, 4 months ago

I like C++, it's not as complicated as C#. NET based is so confusing. I mean, c'mon,

I have no idea where the core of a Program is with C#, so tangled and it's like "wat".

Although I do like C# so much more then a lot of languages.

Just the C; Branches. :P

blackhole 12 years, 4 months ago

I should point out that I would never, ever recommend actually interfacing with either DirectX or OpenGL using C++, ever, unless you want to develop your own engine instead of actually make a game. Use a library. If this is C# and XNA, fine. If your goal is to make a game, screw everyone else and just use whatever is easiest to use. There's a reason I'm developing language interfaces for my graphics engine - I believe you should be able to use whatever language you goddamn feel like using to make your game, and you should still be able to render 10000 images at the same time at 140 FPS. Performance concerns should be addressed at a low level, in graphics and physics and audio, not in the game logic.

A properly constructed game architecture will be able to annihilate the performance of almost all modern commercial games even if its using freaking python just by interfacing with well-optimized libraries. This includes using C-implemented data structures whenever possible and/or when appropriate. Game logic is so high-level performance almost entirely matters on the overarching layout of the program. So long as you pay attention to performance throughout development, you can write a highly efficient program in anything.

Astryl 12 years, 4 months ago

Basically, in the simplest terms, as long as performance is given the attention it deserves, it's best to write a game (Or anything for that matter) in the language you're most comfortable in.

Though there definitely are cases where Python > C++, for instance.

Rob 12 years, 4 months ago

Quote: svf
C++ is less complicated than C#

What?

svf 12 years, 4 months ago

@Rob, What? This is my opinion. Not the 'literal truth', of how some people say it. Just because everyone else thinks C++ is the god-damn hardest language in the world doesn't mean it is. It all depends on the person learning the language.