• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:39
CEST 06:39
KST 13:39
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Voting7[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Weekly Cups (Oct 6-12): Four star herO65.0.15 Patch Balance Hotfix (2025-10-8)79Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition325.0.15 Balance Patch Notes (Live version)119
StarCraft 2
General
Revisiting the game after10 years and wow it's bad 5.0.15 Patch Balance Hotfix (2025-10-8) TL.net Map Contest #21: Voting How to Block Australia, Brazil, Singapore Servers The New Patch Killed Mech!
Tourneys
RSL Offline Finals Dates + Ticket Sales! SC4ALL $6,000 Open LAN in Philadelphia Crank Gathers Season 2: SC II Pro Teams LiuLi Cup - September 2025 Tournaments Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
External Content
Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More
Brood War
General
[Interview] Grrrr... 2024 Question regarding recent ASL Bisu vs Larva game BW General Discussion BW caster Sayle Map with fog of war removed for one player?
Tourneys
[ASL20] Semifinal B [Megathread] Daily Proleagues [ASL20] Semifinal A SC4ALL $1,500 Open Bracket LAN
Strategy
Current Meta Relatively freeroll strategies BW - ajfirecracker Strategy & Training Siegecraft - a new perspective
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread Path of Exile
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
SPIRED by.ASL Mafia {211640} TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
[Manga] One Piece Series you have seen recently... Anime Discussion Thread Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Inbreeding: Why Do We Do It…
Peanutsc
From Tilt to Ragequit:The Ps…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1526 users

Game Programming Primer - Page 5

Forum Index > General Forum
Post a Reply
Prev 1 2 3 4 5 6 7 Next All
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
November 28 2012 21:10 GMT
#81
On November 29 2012 03:48 CecilSunkure wrote:
Show nested quote +
On November 29 2012 01:56 spinesheath wrote:
On November 28 2012 05:29 CecilSunkure wrote:
As for optimization, I only talked about delayed construction and said not to pass-by-value. These are the sort of things I learned my first semester working in C. They aren't really something you can get lost in while programming in a bad way as you'll be learning fundamentals essential to programming in general.

Not using pass by value to improve speed is a trap too. Sometimes you want to pass by value, sometimes you don't.
See: http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/


Generally you never even want to think of optimization until after you ran a detailed performance analysis. Before that point all your efforts should be spent on producing simple, readable, understandable, reusable, testable and maintainable code.

You know, intentionally setting up RVO is in and of itself programming while being mindful of optimizations. Some optimization really is just low hanging fruit you can be sure of.

It's stuff that you'll do automatically more and more as you gain experience, but it still has pretty much zero impact on performance for the vast majority of code. You will still need to optimize bottlenecks, and only those matter.

For example, I always write ++i instead of i++ unless I specifically need i++ (and even then I prefer to split the statement into two lines because it's easier to read/understand and maintain), but it never makes a difference with most of it being optimized by the compiler, and the rest simply not being in a critical section.

All I'm saying is: The optimizations without drawbacks are nice and all, but it's not something one should prioritize (especially beginners!). Optimize bottlenecks after performance analysis. Saves time, money, and your sanity.
If you have a good reason to disagree with the above, please tell me. Thank you.
Ender2701
Profile Blog Joined January 2012
United States581 Posts
November 29 2012 07:59 GMT
#82
On November 28 2012 03:43 Random() wrote:
While this is a great article, I think you are overemphasizing the "internals" of game programming. Those parts that work with the hardware and all the low-level implementation details are, of course, quite important, but in all honesty they have little to do with your actual game.

When you look at it this way, then game development (as in implementing the actual gameplay mechanics) is very often done in a higher-level language. People use all sorts of languages (Python, Lua, Java, C#, ...) to abstract themselves away from the engine internals and the horrors of C++, and that is a very good thing. Writing good C++ programs is extremely difficult, and even the state-of-the-art engines written by the most talented programmers in the world are ridden with bugs. C++ programs written by average programmers are a minefield.

So unless you are determined to be a very technical sort of developer, working on the engine, I don't agree that you HAVE to use C++ for game development, in fact I would argue that you should try to avoid it at all if that is possible within your workflow.

Also, you write "there are a few different simple guidelines that one can follow to ensure their code isn’t running sub-optimally" as if running sub-optimal code is something to be ashamed of. Saying such things, especially to new programmers, is a recipe for disaster. Premature optimization is the root of all evil, and for whatever reason many people really seem to like spending their effort "optimizing" absolutely unimportant stuff which they don't even know to be the bottleneck, while at the same time their program is not working correctly overall.


As far as I know most big name games are done in C++. It's actually not bad if you follow good coding practices and code reviews. Starcraft II for instance is primarily C++, and I also know for sure that every game that comes out of http://www.vvisions.com/ and http://www.1stplayable.com/. At the very least, games on console will likely remain primarily in C++ due to the limited hardware specs.
Kerm
Profile Joined April 2010
France467 Posts
Last Edited: 2012-11-29 14:49:59
November 29 2012 14:47 GMT
#83
On November 28 2012 03:43 Random() wrote:
While this is a great article, I think you are overemphasizing the "internals" of game programming. Those parts that work with the hardware and all the low-level implementation details are, of course, quite important, but in all honesty they have little to do with your actual game.

When you look at it this way, then game development (as in implementing the actual gameplay mechanics) is very often done in a higher-level language. People use all sorts of languages (Python, Lua, Java, C#, ...) to abstract themselves away from the engine internals and the horrors of C++, and that is a very good thing. Writing good C++ programs is extremely difficult, and even the state-of-the-art engines written by the most talented programmers in the world are ridden with bugs. C++ programs written by average programmers are a minefield.

So unless you are determined to be a very technical sort of developer, working on the engine, I don't agree that you HAVE to use C++ for game development, in fact I would argue that you should try to avoid it at all if that is possible within your workflow.

[...]


This is just plain wrong. Game programmers do work on C++ too, and although their are more concerned with iterating fast on a feature so that the game designer is happy than with raw performance (as are engine programmers), they need to be excellent at C++. Just read any gameplay programmer job offer (see http://www.gamasutra.com/jobs/board.php?category=16 for instance) you will see than "strong C++ skills" are a pre requisite in 95% of the cases.

Please do avoid to misinform people around here, that are not necessarily schooled with the inner working of the game industry.


[Edit: Ooops actually Cecil already answered pretty much the same thing, sorry about that]
What i know is that I know nothing - [http://twitter.com/UncleKerm]
bbm
Profile Joined April 2011
United Kingdom1320 Posts
November 29 2012 15:39 GMT
#84
Not bad (though rushes through a bit quickly but whatever)

as a note, there's no good reason I can think of to use #define for global ints and things. Use enums or const variables.

You can't for example call the following code snippet:

#define NUM_MAX 256
//...
SomeFunction(&NUM_MAX);

But you can do

const int NUM_MAX = 256;
//...
SomeFunction(&NUM_MAX);



not to mention better error checking and reporting with const vars, and problems if you define the same thing twice.

The only time I'd use #define is when creating some kind of debug and i might want to use ugly macros like __LINE__. something like this:


#define ERROR(x) \
do { \
std::cerr << "ERROR: \"" << x << "\" - Line: " << __LINE__ << ", File: " << __FILE__ << "." << std::endl; \
}while(0)


Or of course if you have a bunch of different flags, you should probably use an enum instead for better type safety and less confusion in parameters and such.
By.Sun or By.Rain, he always delivers
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
November 29 2012 15:50 GMT
#85
Macros are for actual preprocessor operations like include guards and stuff where you select some code based on the architecture you're compiling for (note: use this very sparingly) or debugging (although you should use a logger for that). In some rare occasions you might want to use it to greatly improve readability (for example Typelists). Macros as a replacement for functions, constants, inlining or templates are bad.
If you have a good reason to disagree with the above, please tell me. Thank you.
Random()
Profile Blog Joined August 2004
Kyrgyz Republic1462 Posts
Last Edited: 2012-11-30 17:15:40
November 30 2012 17:09 GMT
#86
On November 29 2012 23:47 Kerm wrote:
Show nested quote +
On November 28 2012 03:43 Random() wrote:
While this is a great article, I think you are overemphasizing the "internals" of game programming. Those parts that work with the hardware and all the low-level implementation details are, of course, quite important, but in all honesty they have little to do with your actual game.

When you look at it this way, then game development (as in implementing the actual gameplay mechanics) is very often done in a higher-level language. People use all sorts of languages (Python, Lua, Java, C#, ...) to abstract themselves away from the engine internals and the horrors of C++, and that is a very good thing. Writing good C++ programs is extremely difficult, and even the state-of-the-art engines written by the most talented programmers in the world are ridden with bugs. C++ programs written by average programmers are a minefield.

So unless you are determined to be a very technical sort of developer, working on the engine, I don't agree that you HAVE to use C++ for game development, in fact I would argue that you should try to avoid it at all if that is possible within your workflow.

[...]


This is just plain wrong. Game programmers do work on C++ too, and although their are more concerned with iterating fast on a feature so that the game designer is happy than with raw performance (as are engine programmers), they need to be excellent at C++. Just read any gameplay programmer job offer (see http://www.gamasutra.com/jobs/board.php?category=16 for instance) you will see than "strong C++ skills" are a pre requisite in 95% of the cases.

Please do avoid to misinform people around here, that are not necessarily schooled with the inner working of the game industry.


[Edit: Ooops actually Cecil already answered pretty much the same thing, sorry about that]


EDIT: Nevermind.
zak_attack
Profile Joined November 2012
Wales6 Posts
November 30 2012 19:14 GMT
#87
yeh man nice thread i have a Bsc in computer game development
'I am the punishment of God...If you had not committed great sins, God would not have sent a punishment like me upon you.
LunaSaint
Profile Blog Joined April 2011
United Kingdom620 Posts
December 03 2012 03:08 GMT
#88
Yikes. This is impressive.

I've dabbled in Python and C++, but I'm still a complete novice. Brilliant stuff.
dae
Profile Joined June 2010
Canada1600 Posts
December 03 2012 23:07 GMT
#89
Wow.. this is like the entire contents of first and 2nd year CSC in one spot. Amazing.
Incze
Profile Blog Joined December 2011
Romania2058 Posts
December 04 2012 17:28 GMT
#90
Posts like your help give me motivation to pursue programming. I'm actually going to buy those books.
Thanks a lot!
Religion: Buckethead
ShadowWolf
Profile Joined March 2010
United States197 Posts
December 06 2012 16:02 GMT
#91
Tons of people use Java all the time - there are plenty of hobbyist games built in Java. I absolutely think making a few smaller games in e.g. Python or Java is a great idea. Arguably, while you're learning, the python/java implementation can be faster than your C++ implementation as long as you do things somewhat reasonably. You will be a far better programmer (especially in C++) by experiencing what other languages can do for you. Even getting in to some functional concepts is powerful because a lot of those ideas fit really well in to building parallelizable systems.

Plus, let's face it, there's a really solid chance most people in this thread won't enjoy doing gamedev for a living. It's a very taxing, very difficult, and very competitive industry with low pay and horrific hours. Very rewarding if you're the type of person who likes making games, but, as someone who is strong in C++, I can assure you having a C++ background isn't really an ultra-desired skill set right now. You can make do (and good money) but your industries are limited (basically you can kiss startups goodbye).

Arrays cannot be passed around from one location to another directly. If attempted, the name of an array will be converted to a pointer to the first element in the array. This incurs a loss of information, as a pointer stores information about location and type, whereas an array stores location of first element, type of the elements and number of elements. This “feature” of C and C++ can actually be viewed as a “language bug”.


In C++, references to arrays are not decayed when passed. This allows you to eliminate this decay at no cost with a parameter that looks similar to the below. Just a sample from an implementation of one of those internet question things, but demonstrates the prototype:
template <size_t Sz>
Node* TreeFromSortedArray(int (&arrayList)[Sz], int start, int end)

With this, sizeof does work correctly (which means you can use _countof or ARRAY_SIZE). You can even replace int with a template if you wanted and that works, too.

I'd probably suggest striking the optimization section entirely; I agree with everything in it but I think it would be stronger in a "Coding for the future" type of section. i.e. postfix/prefix - I use the prefix operator too but it hasn't reasonably mattered in years and I've literally never had a line of code's speed increased by any measurable factor by a postfix ++ operator even in the one situation I can think of where it create unnecessary copies, delayed construction is more just a code organization thing - it can be the right answer in some situations but only if you've done the necessary legwork (profiling and analysis) to know why. And so on with the remaining things. They're all great suggestions but also they're all premature optimizations. More important is focusing on complexity (avoiding n^2 or worse - especially in a loop), profiling, and timing. Every foray in to game making I've made usually involves a section where I forget I only have like 15ms or something to complete the game loop.

Overall it's a great article. I liked the sections on design patterns and data structures. I definitely feel like the #1 mistake I see at work is people overlooking both of those things.
MChrome
Profile Joined May 2011
Netherlands201 Posts
December 07 2012 10:36 GMT
#92
One thing... Do you need to learn C and C++ side by side or is learning just C++ enough?
If you do things right, people won't be sure you've done anything at all.
iaretehnoob
Profile Joined June 2004
Sweden741 Posts
December 07 2012 17:45 GMT
#93
I would advice learning either C or C++, not the abomination that is C/C++ or C with classes.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
December 07 2012 17:58 GMT
#94
Just learn C++. C is used only in some rare and very specific circumstances nowadays.
If you have a good reason to disagree with the above, please tell me. Thank you.
LTY
Profile Joined November 2012
United States223 Posts
December 08 2012 18:14 GMT
#95
oh my, i'm working on whac a mole program in java, i'm totally lost now..
Known as Miso or LTY
Azerbaijan
Profile Blog Joined January 2010
United States660 Posts
December 10 2012 09:58 GMT
#96
I have Visual Studio 2012 and I can't figure out how to set it up for C programming. Options for C++ and C# are pretty obvious but allegedly I can use it for plan C ( I think). I was using codeblocks on my old computer, which I liked a lot, but I have a class that is using C# and I would like to us VS for both languages if I can.
e-Goh
Profile Joined January 2012
New Zealand18 Posts
December 10 2012 14:00 GMT
#97
On December 10 2012 18:58 Azerbaijan wrote:
I have Visual Studio 2012 and I can't figure out how to set it up for C programming. Options for C++ and C# are pretty obvious but allegedly I can use it for plan C ( I think). I was using codeblocks on my old computer, which I liked a lot, but I have a class that is using C# and I would like to us VS for both languages if I can.


Create a C++ console project, and code away in C. You may get warnings for including C headers like <stdio.h> instead of their C++ counterparts <cstdio>, but it won't be a big deal for the foreseeable future.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
December 10 2012 21:31 GMT
#98
On December 10 2012 18:58 Azerbaijan wrote:
I have Visual Studio 2012 and I can't figure out how to set it up for C programming. Options for C++ and C# are pretty obvious but allegedly I can use it for plan C ( I think). I was using codeblocks on my old computer, which I liked a lot, but I have a class that is using C# and I would like to us VS for both languages if I can.

Just create your file as a .c file.
Azerbaijan
Profile Blog Joined January 2010
United States660 Posts
December 10 2012 22:06 GMT
#99
Ah, thanks. And thanks for the article; I'm hoping to pick up the C and C++ books for christmas and I've just grabbed the Code one from the library. Should keep me busy for a while.
3FFA
Profile Blog Joined February 2010
United States3931 Posts
Last Edited: 2012-12-11 22:49:52
December 11 2012 21:48 GMT
#100
CecilSunkure just curious, what compilers do you use to program with and what compilers have you used to program with in the past? Any short reviews you would be willing to give of a few?

edit: Also, when reading through this I noticed this odd sentence
In the first sentence about Heap:
The heap is memory is a large location of memory that dynamic memory can be requested from.
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Prev 1 2 3 4 5 6 7 Next All
Please log in or register to reply.
Live Events Refresh
Next event in 6h 21m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Nathanias 178
RuFF_SC2 167
Nina 113
StarCraft: Brood War
PianO 187
Noble 37
Bale 23
Icarus 9
NotJumperer 2
League of Legends
JimRising 743
Counter-Strike
Stewie2K426
PGG 216
Coldzera 140
Other Games
summit1g9046
gofns3612
C9.Mang0359
Mew2King64
Models7
Organizations
Other Games
gamesdonequick3038
Counter-Strike
PGL738
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH166
• practicex 23
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Rush1503
Upcoming Events
Wardi Open
6h 21m
CranKy Ducklings
1d 5h
Safe House 2
1d 12h
Sparkling Tuna Cup
2 days
Safe House 2
2 days
Tenacious Turtle Tussle
5 days
The PondCast
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.