Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

About C++, a question.

desocupado

Magister
Joined
Nov 17, 2008
Messages
1,802
So, I have had this pipe dream for a while, of making a simple strategic game.

I had some experience with FORTRAN in college, so the last year, I started reading it and trying out a C++ book. I don't remember having much trouble until I reached classes, and stopped there, run out of interest. I was losing interest since pointers, actually, because I was not seeing the tools to build a game. Where were the stuff to show sprites, mouse support, grids, etc? I mean, I know you do some of these stuff with arrays and loops, but I was about 1/3 to 1/2 through the book and all I was doing were DOS programs...

So, yesterday I read that indie tools thread, and someone mentioned python, and gave a link to a book, which I downloaded, and when I looked at the index, there it was, making windows boxes, collision detection, grids for simple games (tic tac toe), in the examples there was even mouse support.

But that was recommend to someone who did not want to complicate his head with programming, which is not my problem, I think I do like programming, so would not C++ be a better tool? But if so, what I am missing? How do you do that stuff in C++? Not seeing how I would use what I had was what made me loose interest.

Sorry for the wall of text. Also, I was shocked when I had to include math.h for a C++ program be able to a square root. FORTRAN does that shit from start.
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
Hell, first you got to understand that frameworks will not help you a lot.
If you want to do a game - you gotta conceptualize the gameplay into a algorithm for the computer, even if your algorithm is something like "always move left to get out of the maze". No worthwhile framework will help with that - that way lie gamemaker games.

This complexity is for everything, not only gameplay. It gets fantastically complicated. It's like trying to build a jet engine from first principles. Though you should use a framework for the non-core parts of the game.

Anyway a few years ago, the best option that i knew of for a beginner was to sell your ass to microsoft and use XNA.

Languages are funny - using c++ if you don't know it very well is begging to be raped, but the only way to know it well is to use it.
Read this for a laugh: http://yosefk.com/c++fqa/

Compiler/language technology is in the dark ages still, and only taking off now (in universities, not the industry).
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
About python: You gotta understand their aproach: They try to have only one "perfect" way to do tasks (reflected in the api) - i agree with this.
But they also have no type system. Types are the "noise" a non-compiled source has. String declarations, not only the variables, casts, etc (there are more complicated ones that give other properties than just identity like contracts, but that is another story).
Types are used by the compiler to detect some logical errors in the program at compile time (ideally). Having no types means that it is more likely to be errors at runtime (there are other classes of errors that exist at runtime, but they are not type errors).

Python doesn't give a shit about that - it's a cowboy programmer language. Of course the wise cowboys are very, very careful.
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
I just realized i may have been condescending if you read a c++ book and worked through the examples.

But still. You don't "complicate your head with programming". It is always present. Programming is not juggling pointers. It's the fucking algorithm. It's the framework that does or doesn't help.
 

Catbert

Scholar
Joined
Apr 26, 2010
Messages
104
I too once read a C++ book and waiting for the "beef" to come. The fact of the matter is that the beef isn't coming, because C++ isn't a game maker and it doesn't have standardized libraries that do what you need.

Consider that C++, like its predecessors, is a general purpose systems programming language and as such, it only provides you by default with the facilities to do what virtually every program needs to do: input, output and some system calls.

What you're really looking for is a book like "building games with C++ and <insert graphics API of choice>" to read once you've gained some experience with the language (and C++ has its quirks).

Don't even think about using popamole scripting languages to create games. Might as well use Flash and put your shit on Facebook. :x
 

shihonage

Subscribe to my OnlyFans
Patron
Joined
Jan 10, 2008
Messages
7,163
Location
location, location
Bubbles In Memoria
If you know Fortran, and have a good Fortran compiler that lets you do input polling/graphics/whatever you want, then just stick with it for your first project.

Language specifics can drown you like the pedantism of a Soviet bureaucrat.

The important skills are language-independent.If you can make the monster follow player in Basic, then you can do it in Pascal and C++, too.
 

desocupado

Magister
Joined
Nov 17, 2008
Messages
1,802
Python is weird. You don't declare your variables, and the loop doesn't count by itself. At least not the one I have seen so far.

YOU KIDS GET OFF MY LAWN WITH YOUR NEWFANGLED UNDECLARED VARIABLES! IN MY TIME VARIABLES HAD TO BE DECLARED, AND THAT'S HOW WE LIKED IT!

But seriously, how does the program use the memory? Does it alocate the memory as you go assigning your variables? But what if you assign an integer to a variable, and then later in the program assign a double? He will place the variable in a different address in the memory? Won't that expend your memory faster?
 

J1M

Arcane
Joined
May 14, 2008
Messages
14,663
For the kind of game you want to make the speed of the language doesn't really matter. What you need is a game engine to mod if you don't want to build a game engine. XNA is a good suggestion. There are other choices, but understanding object oriented programming is probably a must. You could try switching to Java if you wanted.
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
Python works with reference counting garbage collection. It counts the numbers of your objects, and it's references. When it reaches zero, it frees the memory allocated.

This is only for heap memory. Stack memory works like c++, java and all the others (simplification of Stack : variables declared in method). It is dynamic and efficient.

Java uses another kind of garbage collection that is more efficient in the general case, but more complicated to implement. It has someother features i forget.

The references in most interpreters, compiled code and virtual machines for sane languages are all standardized to a reference pointer, normally 32bits. This indeed wastes memory in the general case (witness the 5 mb just to run java hello world), but saves both portability problems in the compiled code (almost none) and complexity in the virtual machines. Though the JVM is toying with something tricky called compressed pointers for the 64 bits JVM.
 

DriacKin

Arbiter
Joined
Oct 9, 2008
Messages
2,588
Location
Inanescape
Catbert said:
Don't even think about using popamole scripting languages to create games.

Stop the bullshits. There are plenty of scripting libraries that have C/C++ connectors and integrate quite painlessly. For example, Lua.
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
BTW a simple advice. Don't choose your language based on speed, especially if you're not going to have a complex and demanding AI and Software rendered Graphics and dynamic terrain and physics and shit like that.

Just do the simplest you can (look at the industry standard algorithms ofcourse) and profile.
 

soggie

Educated
Joined
Aug 20, 2009
Messages
688
Location
Tyr
Here's my recommendation.

1. Don't jump into the deep end of the pool

Go python. Trust me, it's not worth pouring over pointers, references, memory management, operator overloading, and all those OO stuff when all you want is to build a game. Start off with pygame, and learn game programming first.

This is very important because game programming involves a very different set of skills than engine programming. The former is much higher level, which teaches you how to code game logic.

And the most important of all, it teaches you what kind of engine would suit your need. When everybody programs their own game, they build it with a specific architecture. How do you manage application states? Game states? Counters and variables? All these requires knowledge in software architecture, and by building a game and focusing on the high level logic rather than the low-level wrangling, you'll learn a lot on proper engineering.

2. Know what you want

Once you're comfortable with python programming, especially with pygame, you'll start to notice some drawbacks. This is the part where you would start to wish that there were something that could simplify your job. When you get to this level, you're ready to talk about engines.

Every engine has a different development process and locks you into a very specific pipeline. Choosing a proper engine cannot happen without prior knowledge of what kind of pipeline suits you and your game.

When you get to this point, you start to look at languages as tools, which are meant to solve problems, not revolutionize the free world of capitalism. This is the point where you stop asking what language is best and start asking which of them are most suited to that specific problem you have.

3. Conclusion?

There is NO best language. For you, as a newbie to game programming, start off easy. Use python. Heck, use Lua and do a mod if its easier for you. The idea is to stop struggling with the language and actually get down and DO SOMETHING.

When you get enough idea of what you want, and a good high-level understanding of HOW you want to accomplish things, that's when you come back to this thread and start asking more specific questions, which will definitely net you better answers than language A vs language B debates.

So like I said, start with python.
 

Catbert

Scholar
Joined
Apr 26, 2010
Messages
104
DriacKin said:
Catbert said:
Don't even think about using popamole scripting languages to create games.

Stop the bullshits. There are plenty of scripting libraries that have C/C++ connectors and integrate quite painlessly. For example, Lua.

That's not what he meant. He meant using Python to code the entire game, not just control scripts. Lua is nice indeed, but I wouldn't use it to code an entire game. It's too slow compared to C++ and doesn't have enough facilities to make programming a large application convenient.

For control scripts, Lua is the best.
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
I confess i didn't want to make a big deal about it. As you can tell by my little dig at c++, i'm a java programmer - i don't love it but...

I tried to stay neutral and say it's not the language and all. It's the programming, and this is true from a certain perspective. The perspective that you are someone working alone with 5 years of experience.

I've always hated c++, even when i didn't know anything (i still don't really). I read a introduction to c++ for dummies even before entering university, i was already FUUUU-ing. Maybe i'm just a poseur. But -

THESE WOUNDS - THEY WILL NOT HEAL - FUCK THIS FUCKING LANGUAGE WITH A STICK UP IT'S ASS. YOU CAN'T EVEN IMAGINE THE GREAT RAGE I HAVE AT MOST COMPLEX DESKTOP PROGRAMS BEING IN C++. EVERYTIME I SEE A FUCKING STACK DUMP I YELL "STROUSTRUP YOU WILL SUCK COCKS IN HELL!".

That is my considered opinion. But i don't know anything about c++. I refuse to learn more.
 

soggie

Educated
Joined
Aug 20, 2009
Messages
688
Location
Tyr
SCO said:
I confess i didn't want to make a big deal about it. As you can tell by my little dig at c++, i'm a java programmer - i don't love it but...

I tried to stay neutral and say it's not the language and all. It's the programming, and this is true from a certain perspective. The perspective that you are someone working alone with 5 years of experience.

I've always hated c++, even when i didn't know anything (i still don't really). I read a introduction to c++ for dummies even before entering university, i was already FUUUU-ing. Maybe i'm just a poseur. But -

THESE WOUNDS - THEY WILL NOT HEAL - FUCK THIS FUCKING LANGUAGE WITH A STICK UP IT'S ASS. YOU CAN'T EVEN IMAGINE THE GREAT RAGE I HAVE AT MOST COMPLEX DESKTOP PROGRAMS BEING IN C++. EVERYTIME I SEE A FUCKING STACK DUMP I YELL "STROUSTRUP YOU WILL SUCK COCKS IN HELL!".

That is my considered opinion. But i don't know anything about c++. I refuse to learn more.

Just curious - do you use the step-through debugger and the real-time debugger when you were facing problems in C++? I asked this because most of my pain came from not realizing the existence of those in the first place.

I'm okay with C++, and while I've worked with Java for 6 years, I still enjoy C++ more than I do with Java. I guess most of it has to do with eclipse being a pain in the ass most of the time (fuck its intellisense crap), but writing code in C++ just make me more alert to the effects my code have, and in a way forces me to write in an efficient way that would not have been possible if I were to use Java, because I tend to (foolishly) trust Java's conveniences a little too much than I should.

It's personal preference, really. By the end of the day, as long as the language gives you the facilities to get things done YOUR way, it doesn't really matter whether you're fiddling around with pointers or having automated reference counting and garbage collection.
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
Taken directly from the fqa (because i don't know c++) - not sure if still applicable.
What does this code do?
Code:
void foo(const std::string &) {}
int main() 
{
    foo(false);
}

It compiles!
bool -> implicit conversion -> char* -> implicit conversion -> string

Truth to be told i'm not experienced in either the language or the tools. I barely scratch c now.

I'm such a idealist that i'm waiting for a language that has session types (contracts for protocols) aided gc (no scanning in this implementation, just the compiler knowing when the free is needed), contracts and non null type by default. I wouldn't mind dependency inversion in the language too - object orientation is (mis)-used a lot, with di is where you start to see who just talks the game or who plays it (not many play it).
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
Preemptive strike:
Yes i know that java is full outright rage inducing decisions like the non type carrying Generics and their enormous faq.
 

Catbert

Scholar
Joined
Apr 26, 2010
Messages
104
They say that C++ makes it too easy for you to shoot yourself in the foot, but I disagree. I think that if you've shot yourself in the foot, C++ makes it easier for you to notice.
With Java (basically applies to any scripting language like Java, C#, Python, etc) you have a huge framework of code that you can invoke at your leisure, so you can do something very inefficient with relatively little effort, while with C++ you have to work harder and there are fewer possibilities to hide things from the programmer. You generally know what's going on with each line of code, despite all the abstractions and meta-mechanisms (sometimes even C++ has too much capacity to make things unclear and this is why operating system kernels, like Linux, are mostly written in pure C).
This is why C++ is still the preferred language for writing very intricate systems (no, your enterprise database frontend isn't intricate) like game engines and kernels (that certainly rival each other in complexity these days) and that isn't going to change soon (no, XNA is only going to kill C++ for xbawks development).

I've always considered Java's garbage collector shit that refuses to work as intended. If it did, programs written in Java would self delete on execution. :smug:

The best garbage collector is the programmer. With C++, if you decide that deallocating shit takes too much time, you can overload delete and implement deferred deallocation the way it makes sense for your application/project. Guess what? You can't do that in Java because there's no mechanism to really indicate the end of an object's life span and destroy it, so you can't implement truly efficient memory management in Java. Not that Java programmers care about efficiency to start with. They're too busy taking a managed cock up their ass.

@SCO:
In the army they say that every safety procedure was written with blood. Likewise, every compiler warning stems from a once obscure bug. If you haven't set up your compiler to treat warnings as errors, at least don't ignore them. Your code doesn't compile under GCC, by the way, even after adding the necessary includes. Plus, if you pull stupid shit like this in actual code meant for a real system, don't blame Stroustrup when shit blows up in your face.
 

SCO

Arcane
In My Safe Space
Joined
Feb 3, 2009
Messages
16,320
Shadorwun: Hong Kong
Derp, if it was only that.

Read the damn fqa.

BTW i do recommend python, use that + some other sane language as a engine core.

(like C).

I can't recommend java for many games unless you are a openGL god and know the language back and forwards. The lack of structs hurts it specially in the data->hardware pathway that is optimized by drivers to take arrays of structs.
 

Antihero

Liturgist
Joined
May 8, 2010
Messages
859
Catbert said:
Your code doesn't compile under GCC, by the way, even after adding the necessary includes. Plus, if you pull stupid shit like this in actual code meant for a real system, don't blame Stroustrup when shit blows up in your face.
It compiles for me with gcc 4.0.1 and with VS2010 (after #include <string>). However, it throws an exception at runtime because you're trying to create a string with a null pointer. It doesn't compile with true, so I assume going from bool to char* is basically false -> 0 -> (char*)0, which zero can do, and C++0x with nullptr should suck less there.

I'm not sure which exact entry SCO is referring to, but there are real cases where that can mess somebody up:
Code:
#include <iostream>

void doit(int i)
{
   std::cout << "doit 1" << std::endl;
}

void doit(char *i)
{
   std::cout << "doit 2" << std::endl;
}

int main()
{
   char *nullchr = 0;
   doit(0);
   doit(NULL);
   doit(nullchr);
   doit((char*)0);
   doit(static_cast<char *>(0));
   return 0;
}

Prints doit 1, doit 1, doit 2, doit 2, doit 2, where somebody could get burned using a NULL or zero literal without a cast.

The one thing I hate about python is that breaking backwards compatibility doesn't seem restricted to documented changes, and using the API one way is fine for one version and then starts throwing undocumented exceptions in another release. That could happen for anything, but python just seems worse to me in that regard.

Edit: left in the wrong #include, and preemptive pedantry: yeah NULL is a macro for 0, not a literal value itself
 
In My Safe Space
Joined
Dec 11, 2009
Messages
21,899
Codex 2012
What would be the best when someone wants to make a game that looks like Exile?
 

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom