Jump to content

  • Log In with Google      Sign In   
  • Create Account


Game Engine from scratch using C++ and python - Where do I start?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
28 replies to this topic

#21 Goran Milovanovic   Members   -  Reputation: 1103

Like
0Likes
Like

Posted 06 October 2012 - 12:43 AM

I was just aiming to simplify the idea, but I failed to elaborate more into the example, as I just wanted it to be simple. My bad.


... ?

No one is arguing that you didn't go into enough detail. We just pointed out some fundamental flaws in what you posted.

By the way: You should never, ever typedef a pointer. That's an unnecessary level of indirection, and it's something that has no place in your example, because you're not even using it anywhere.

posting bad code as a recommended solution isn't the best idea


Well, yes, but on the other hand, you can't really blame people for not knowing any better.

They think they're posting code that is appropriate from one perspective or another, so they post it, because they want to help. I think that's fine, as long as there are other GameDev members who can point out the flaws, and keep everyone informed.

+---------------------------------------------------------------------+

| Need a programmer?        ->   http://www.nilunder.com/protoblend   |

| Want to become one?       ->   http://www.nilunder.com/tutoring     |
| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

Sponsor:

#22 Vodahmin   Members   -  Reputation: 233

Like
1Likes
Like

Posted 06 October 2012 - 01:00 AM

By the way: You should never, ever typedef a pointer. That's an unnecessary level of indirection, and it's something that has no place in your example, because you're not even using it anywhere.

Actually, typedef'ing pointers is common in game industry, smart pointers that is.

#23 Goran Milovanovic   Members   -  Reputation: 1103

Like
1Likes
Like

Posted 06 October 2012 - 12:21 PM

Actually, typedef'ing pointers is common in game industry, smart pointers that is.


I would still argue against it: It's something that carries certain benefits, I'm sure, but it makes code more difficult to read, because now I have to look for what opaqueDataType actually represents.

If I just have SDL_Surface*, it's immediately clear.

+---------------------------------------------------------------------+

| Need a programmer?        ->   http://www.nilunder.com/protoblend   |

| Want to become one?       ->   http://www.nilunder.com/tutoring     |
| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

#24 Pointer2APointer   Members   -  Reputation: 283

Like
0Likes
Like

Posted 06 October 2012 - 01:39 PM

To end my misfortunate and bad example code of a game engine, I'll go back and edit to better suit a problem.

As for type defining an SDL_Surface *, I always do it because it's easier and faster to write out
LOAD SDL_LoadBMP("image.bmp")
than it is to write
SDL_Surface* LOAD = SDL_LoadBMP("image.bmp")
.

I would hope others see the time-saving benefits of using a typedef at times, aside from other use.

Now I'll go and fix what I poorly wrote out.
Yes, this is red text.

#25 Vodahmin   Members   -  Reputation: 233

Like
0Likes
Like

Posted 07 October 2012 - 02:21 AM


Actually, typedef'ing pointers is common in game industry, smart pointers that is.


I would still argue against it: It's something that carries certain benefits, I'm sure, but it makes code more difficult to read, because now I have to look for what opaqueDataType actually represents.

If I just have SDL_Surface*, it's immediately clear.

I think it's only a matter of getting used to it. There is no apparent reason for typedefing SDL_Surface* but if your pointer declaration looks like "shared_ptr<SDL_Surface>" or something longer, then it can be a bit frustrating to rewrite it every time, so why not just typedefing it to "SDL_Surface"? Then, as a matter of good practice, you can add a "p" before the pointer declaration (for example "pSurface"), so there is really little room for mistake.

#26 Goran Milovanovic   Members   -  Reputation: 1103

Like
0Likes
Like

Posted 07 October 2012 - 05:09 AM

To end my misfortunate and bad example code of a game engine, I'll go back and edit to better suit a problem.

As for type defining an SDL_Surface *, I always do it because it's easier and faster to write out

LOAD SDL_LoadBMP("image.bmp")
than it is to write
SDL_Surface* LOAD = SDL_LoadBMP("image.bmp")
.

I would hope others see the time-saving benefits of using a typedef at times, aside from other use.

Now I'll go and fix what I poorly wrote out.


Your comparison is flawed. It should be:

SDL_Surface* image = ...
// vs
LOAD image = ...

It's a virtually inconsequential difference, in terms of length. But even if it wasn't, SDL_Surface* is far more descriptive, and should therefore be preferred.

Anyway, I wouldn't recommend changing your previous posts; they're supposed to serve as examples of what others are not supposed to do, so just leave them as they are. If you want to show some more code for us to review, make a new post/thread, and we can take it from there.

There is no apparent reason for typedefing SDL_Surface* but if your pointer declaration looks like "shared_ptr<SDL_Surface>" or something longer, then it can be a bit frustrating to rewrite it every time, so why not just typedefing it to "SDL_Surface"?


I would ask if a shared_ptr is truly necessary? Maybe that part of the system could be written in a higher-level language (one that comes with a GC).

In either case, I think that "typdefing a pointer to save a few keystrokes" is fundamentally wrong. Unless you have really good architectural reasons for doing that, you should find a better text editor that can automate those "too long to type" situations.

+---------------------------------------------------------------------+

| Need a programmer?        ->   http://www.nilunder.com/protoblend   |

| Want to become one?       ->   http://www.nilunder.com/tutoring     |
| Game Dev video tutorials  ->   http://www.youtube.com/goranmilovano |
+---------------------------------------------------------------------+

#27 Vodahmin   Members   -  Reputation: 233

Like
0Likes
Like

Posted 07 October 2012 - 05:41 AM

In either case, I think that "typdefing a pointer to save a few keystrokes" is fundamentally wrong. Unless you have really good architectural reasons for doing that, you should find a better text editor that can automate those "too long to type" situations.

It's a matter of aesthetics. The code is also more readable, which can save you some time when debugging - that's what typedef was made for.

#28 Pointer2APointer   Members   -  Reputation: 283

Like
0Likes
Like

Posted 09 October 2012 - 02:44 PM

It's like
using
in C++.

After a while, when using the STD library in C++, beginners will probably learn this:

cout << "Hello world!"
instead of
std::cout << "Hello world!"
.

It is less typing.
Yes, this is red text.

#29 Telastyn   Crossbones+   -  Reputation: 3718

Like
2Likes
Like

Posted 09 October 2012 - 02:59 PM

Ugh. The amount of time spent typing in a program is less than 1% of a product's cost. Don't risk the incredible added cost of debugging or patching code errors caused by useless typedef garbage that saved you a few seconds.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS