• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:29
CEST 03:29
KST 10:29
  • 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
[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18Serral wins EWC 202549
Community News
Maestros of The Game—$20k event w/ live finals in Paris20Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195Weekly Cups (Jul 28-Aug 3): herO doubles up6
StarCraft 2
General
2v2 & SC: Evo Complete: Weekend Double Feature Geoff 'iNcontroL' Robinson has passed away What mix of new and old maps do you want in the next 1v1 ladder pool? (SC2) : The GOAT ranking of GOAT rankings RSL Revival patreon money discussion thread
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris Sparkling Tuna Cup - Weekly Open Tournament Monday Nights Weeklies Master Swan Open (Global Bronze-Master 2) $5,100+ SEL Season 2 Championship (SC: Evo)
Strategy
Custom Maps
External Content
Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below Mutation # 484 Magnetic Pull
Brood War
General
Joined effort New season has just come in ladder BW General Discussion Flash On His 2010 "God" Form, Mind Games, vs JD Flash Announces (and Retracts) Hiatus From ASL
Tourneys
BWCL Season 63 Announcement [CSLPRO] It's CSLAN Season! - Last Chance [ASL20] Ro24 Group A [ASL20] Ro24 Group C
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread Dawn of War IV Path of Exile Stormgate/Frost Giant Megathread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread The year 2050 Things Aren’t Peaceful in Palestine European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
High temperatures on bridge(s) Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment"
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
Evil Gacha Games and the…
ffswowsucks
Breaking the Meta: Non-Stand…
TrAiDoS
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3101 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 8h 31m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SpeCial 146
ProTech93
StarCraft: Brood War
ggaemo 58
NaDa 40
Noble 18
Dota 2
monkeys_forever317
capcasts297
NeuroSwarm151
LuMiX1
Counter-Strike
Stewie2K531
Heroes of the Storm
Khaldor134
Other Games
tarik_tv20527
gofns11479
summit1g7220
WinterStarcraft670
JimRising 487
ViBE120
Trikslyr50
Organizations
Other Games
gamesdonequick1148
BasetradeTV100
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 12 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota22533
League of Legends
• Doublelift4308
Upcoming Events
Sparkling Tuna Cup
8h 31m
SC Evo League
10h 31m
Chat StarLeague
14h 31m
Replay Cast
22h 31m
Afreeca Starleague
1d 8h
Queen vs HyuN
EffOrt vs Calm
Wardi Open
1d 9h
RotterdaM Event
1d 13h
Replay Cast
1d 22h
Afreeca Starleague
2 days
Rush vs TBD
Jaedong vs Mong
Afreeca Starleague
3 days
herO vs TBD
Royal vs Barracks
[ Show More ]
Replay Cast
3 days
The PondCast
4 days
Replay Cast
4 days
LiuLi Cup
5 days
Cosmonarchy
5 days
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
BSL Team Wars
5 days
Team Hawk vs Team Dewalt
BSL Team Wars
5 days
Team Hawk vs Team Bonyth
SC Evo League
6 days
[BSL 2025] Weekly
6 days
Liquipedia Results

Completed

Jiahua Invitational
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL Season 18: Qualifier 1
Acropolis #4 - TS1
CSLAN 3
SEL Season 2 Championship
WardiTV Summer 2025
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL Season 18: Qualifier 2
CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
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.