• Log InLog In
  • Register
Liquid`
TeamLiquid Liquipedia LiquidDota LiquidLegends
EST 18:26
CET 00:26
KST 08:26
  • 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
[BSL11] Ro16 Preview Pt.18[ASTL2] Finals - eSport.fund vs LOGINmedia2[TQ] Best of the Best Tour W3 Recap6IEM Katowice RO24 - Group D Preview7IEM Katowice - A Totally Unbiased Trap Preview53
Community News
2021 GSL Season 1 (Qualifiers)38Saying Goodbye to ASL English475BSL Season 11 - RO16 Group Stage5ASL11 set to start 28/0350New Worlds Map Contest: 1st Edition14
StarCraft 2
General
CatZ sat down with our new SC World Champion 2021 GSL Season 1 (Qualifiers) IEM Katowice 2021- Final four head to sunday showdown Missing/Lost GSL VODs A place to learn for the Platinum level player
Tourneys
[Alpha Pro Series] Solar vs Zest WESG LATM 2021: Kelazhur wins $2100 Alpha X Junior Championships 2021 Circuit ITaX Ultimate Battles#6 - INnoVation vs Zest $75 The Pizza Pie: Season 5 Tournament 6
Strategy
Simple Questions Simple Answers TvT Build Order - Reapers Hellions Liberator How to Break the F2 Hotkey Addiction [G] PvP: 3 Gate Pressure Opening
Custom Maps
Nexus Wars 2021 GUIDE Re-created map Ghost Tower Re-created map Wasteland
External Content
Mutation #255 Growing Threat Drogos Recap of 2020 The StarCraft Observer Podcast Episode #4 Mutation #254 Flipping Out
Brood War
General
24/7 Classic Starcraft VoD Stream All in one Link thread BGH auto balance -> http://bghmmr.eu/ AI Showmatch: Monster vs. Stardust ASL11 set to start 28/03
Tourneys
Desert Strike Tournament DS Jeez Weekly 2021 [STPL] Season 4 Playoffs Week 1 2021 ACS S1
Strategy
More Brood War "Mysteries" explained Try My great strategy game Fog of War Noises Simple Questions, Simple Answers
Other Games
Heroes of the Storm
Balance Patch Notes 53.2 (March 2021) HotS: WP and Funny Moments Welcome to the Heroes of the Storm forum! [HotS] 2020: A Year in the Nexus
General Games
Genshin Impact - Coop RPG Warcraft III: The Frozen Throne In-Development Indie MMORPGs Path of Diablo Diablo 2 thread
TL Mafia
TL Mafia Community Thread [M][N] Mafia Mafia: Mafia Edition {FlaSh}[Mini] Raceday [M][N] I'm a cop you idiot! - Round 4
Hearthstone
Is Hearthstone Gambling?
LoL General
LoL Tournaments
LoL Strategy
Community
General
US Politics Mega-thread Ask and answer stupid questions here! The Games Industry And ATVI Coronavirus and You Tesla Motors
Fan Clubs
Serral Fan Club The TY Fan Club The Scarlett Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Korean Music Discussion Comic Books [Manga] Shingeki no Kyojin
Sports
NBA Season 2019-2020 2020 - 2021 Football Thread UFC/MMA Discussion Thread 2020 NFL and College Football Corona Season NHL 21: Tony DeActivito Did Nazi That Coming
Tech Support
Computer Build, Upgrade & Buying Resource Thread Best Gaming Headset? How do you decide if mobo/cpu dead?
TL Community
Ask TL Staff Anything Recent Gifted Posts The Automated Ban List
Blogs
Exploring Bahia de Las Aguilas…
Tak3r
Returning to broodwar commen…
Diggity
[Girl blog] Liking the wrong …
Garnet
The StarCraft O…
TheStarCraftObserver
Some notes on Reynor vs Zest…
Teoita
Have it your way: a …
waywardstrategy
Customize Sidebar...

Website Feedback

Closed Threads



Active: 864 users

Game Programming with SFML

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States2614 Posts
January 27 2021 01:03 GMT
#1
Irrelevant Metablogging
Every blog has to start with a few irrelevant paragraphs about why you're blogging, right?

I want to write more blogs on stuff I'm ignorant about.

It's not a natural impulse for me. When I first made a TL account I was terrified that these internet strangers would think I was ignorant or immature or bad at Starcraft (it didn't help that I was ignorant and immature and bad at Starcraft), so I tended to want to agonize over every single thing I wrote and make sure it was completely buttoned up and unassailable before I posted it. That went okay, I guess – it doesn't hurt to want to be a good poster. But if there was something I knew I was ignorant about I tended to want to hide it. Either I'd avoid posting about that thing entirely, or, if I had to for some reason, I'd go study up really quick and try to learn about the thing as much as possible, then come back and pretend I'd always known about that thing. That habit continued as I started posting in the politics thread, leading to a tendency to post about trivial things I knew I was right about, rather than important things I didn't feel confident about. I would reread every post about 3 times before posting, and about half the time I'd finish typing it up and then change my mind and close the tab instead of posting.

It's a terrible approach for self-improvement, for one thing. If you only ever talk about something if you're certain you don't need to adjust your thinking about it, you don't give people a lot of opportunities to point out what you're wrong about. But the forum tends to suffer for it, too, especially if other people are doing the same thing you are. USPMT used to suffer from a phenomenon where if someone posted a serious, reasonable attempt at addressing an important question in a nuanced way, nobody would respond to the post; but if some numbskull came in spouting some idiotic nonsense, the thread would light up as 30 posters jumped in to tell them just how dumb and wrong they are (and a couple of those would also be dumb and wrong, prompting another 30 responses, etc.). Once upon a time there were hundreds of new posts in the thread per day, and 90% of them were replies to someone else trying to tell them how wrong they were.

Maybe it's better to talk (humbly, maybe) about the stuff you're most interested in, even if you're not totally confident in your thoughts and you're probably wrong about a lot of it. With that in mind:

Game Programming with SFML
The reason you're here, presumably.

I've been trying to teach myself some programming recently. I've written acouple blogs about my programming skills over the years, and you'd probably get a pretty good idea of my (lack of) skill level from those - I've done a little learning since then, worked (most of the way) through a couple programming textbooks, but I'm still pretty novice.

But one of the textbooks I've worked through (Beginning Game Programming by John Horton) taught me how to use a pretty neat little library called SFML (short for Simple Fast Media Library), a pretty straight-forward graphics library for C++ that seems to be pretty powerful. Horton teaches you how to make a couple very simple games with it (a tree-chopping arcade game, a little zombie arena shooter, and a very simple platformer).

I'm really impressed with SFML. Previously even simple video games seemed like massive undertakings, but after that textbook they seem totally achievable. In fact, here's a video series that uses SFML to make some classic games that writes the code for the entire game from scratch, demonstrates each element of the code as it's added by running the program, and finishes the whole thing in ~5 minutes:


I think this video is more impressive as a performance piece than a tutorial, but damn it's cool.


The obvious thing to do after finishing a textbook about how to program video games is to go try to program a video game. The problem, though, is that none of the game-making resources I've encountered so far actually give very good ideas about smart organization or code design. That Tetris video is just declaring everything it uses in main with one- or two-letter variable names. Horton's code architecture in that textbook starts out atrocious (declaring separate cloud1, cloud2, cloud3 variables) and by the end he's abstracted things out a bit (creating a global Engine object with separate input(), update(), and draw() functions (each in their own source code file) that each run once per frame). Near the end he kind of gestures in the direction of what sounds like some good object-oriented design; but he doesn't actually cover it, he just finishes the platformer and leaves you with "okay, have fun!"

Example:
Now look at this hypothetical code:
+ Show Spoiler +
vector<GameObject> m_GameObjects;

// Code to initialise all game objects
// Including tiles, characters, enemies, bullets and anything else
// In the update function
for (i = m_GameObjects.begin(); i != m_GameObjects.end(); i++)
{
(*i).update(elapsedTime);
}

// That's it!
// In the draw function
// Rub out the last frame
m_Window.clear(Color::Black);
for (i = m_GameObjects.begin(); i != m_GameObjects.end(); i++)
{
m_Window.draw(*i);
}

// Show everything we have just drawn
m_Window.display();
// That's it!


The preceding code is a big step up in terms of encapsulation, code manageability, and
elegance when compared to even this final project. If you look at the previous code, you
will notice there are, however, unanswered questions, such as where collision detection fits
in, for example. Hopefully, however, you can see that further study (by building lots of
games) will be necessary to master C++.
Although we will not be implementing an entire game in this manner...

-Beginning C++ Game Programming by John Horton, pg. 459

I get the impression that game programmers tend to be a... pragmatic bunch. Partly because most of the computational tasks you actually need to accomplish in a video game aren't actually all that complicated - stuff like update each object's position based on its velocity, detect collisions, read inputs and update whatever the input is supposed to change, and draw everything once per frame. But maybe the bigger reason (and this is purely a guess on my part) is that game programmers are a lot more likely to be self-taught nerds that started programming in high school and may or may not have ever had any formal training (like me! ...except the starting in high school part).

That's not to say game programming is easy or game programmers aren't smart. Just that games (especially hobbyist/indie games) are probably more likely to employ the kind of code that folks on Stack Exchange will probably say you really shouldn't be doing. Manually creating objects with new() and killing them with delete(), for instance, and managing them with raw pointers. Brute forcing some conditional with a massive if...else tree. Lots and lots of global objects and variables. That sort of thing.

For instance, from a book by Robert Nystrom I'm thinking of reading next:

In 2001, I landed my dream job: software engineer at Electronic Arts. I couldn’t wait to get a look at some real games and see how the pros put them together. What was the architecture like for an enormous game like Madden Football? How did the different systems interact? How did they get a single codebase to run on multiple platforms?

Cracking open the source code was a humbling and surprising experience. There was brilliant code in graphics, AI, animation, and visual effects. We had people who knew how to squeeze every last cycle out of a CPU and put it to good use. Stuff I didn’t even know was possible, these people did before lunch.

But the architecture this brilliant code hung from was often an afterthought. They were so focused on features that organization went overlooked. Coupling was rife between modules. New features were often bolted onto the codebase wherever they could be made to fit. To my disillusioned eyes, it looked like many programmers, if they ever cracked open Design Patterns at all, never got past Singleton.

source

On the one hand, if I'm going to start on some big project, I'd like to figure out some decent architecture first so it doesn't get too unmanageable (and/or I don't have to spend a lot of time later going back and rewriting everything to fit an architecture I should have thought of in the first place). On the other hand, I'm maybe suffering from some analysis paralysis here – perhaps its best to just write the spaghetti code for a while, until you have a better idea why spaghetti code is bad (and what you could do better).

This blog is already too long, so I'm gonna end it here. But...

[radio voice]Next time on ChristianS's occasional programming blog...

I'm gonna take a look at the code of an actual (more or less) functional RTS, in hopes of learning something about how to smartly organize a game's code.

*****
"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
GroT
Profile Blog Joined January 2004
Belgium2993 Posts
January 27 2021 14:35 GMT
#2
Love your enthusiasm man nice blog post! But if I can say something negative, you remind me of this quote:


The first step of any project is to grossly underestimate its complexity and difficulty.


My advice is to go easy dude! Pick a project that you think will be INSANELY easy because you'll inevitably find out that it's not so easy. Making an RTS by yourself seems like insanity to me, more power to you if you pull that off
bring it
ChristianS
Profile Blog Joined March 2011
United States2614 Posts
January 27 2021 15:18 GMT
#3
Good advice, but to be clear, I’m not gonna build an RTS, I’m gonna look at someone else’s code. My first project was to make a little screensaver where particles bounce around the screen, and I got confused enough trying to do collisions that I think I’m gonna do another book on game architecture first.
"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
GroT
Profile Blog Joined January 2004
Belgium2993 Posts
January 28 2021 07:19 GMT
#4
Ah cool I misunderstood that part and almost had a heart attack lol

That project sounds ideal actually! Good work

I recommend javidx9 on youtube for you. The guy has a good mix of doing amazing stuff while introducing minimal complexity and really teaching some fundamentals. His coding style is also really retro which I think is fun.




bring it
ChristianS
Profile Blog Joined March 2011
United States2614 Posts
February 03 2021 04:18 GMT
#5
Somewhat delayed response: That YouTube channel looks great, and I'm gonna try to watch some of his stuff when I get a chance. In particular I saw a series in which he's making an RPG with some more involved OOP I think I could learn a lot from. Thanks for the recommendation!
"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
Please log in or register to reply.
Live Events Refresh
The Pizza Pie
23:00
Season 5 Tournament 6
Tree_Stump
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 1304
JimRising 443
-ZergGirl 269
ViBE154
Forgg! 139
RuFF_SC2 121
Mackintac 102
NoRegreT_ 77
Heroes of the Storm
Grubby2667
Liquid`Hasu625
Counter-Strike: Global Offensive
Fnx 1584
semphis_21
bouly5
Super Smash Bros
hungrybox4121
AZ_Axe268
Other Games
summit1g14335
fl0m861
MaximusBlack350
Trikslyr189
Hui .125
NeuroSwarm89
Organizations
Counter-Strike: Global Offensive
dreamhackcs13098
Other Games
gamesdonequick3228
Counter-Strike: Global Offensive
ESL CS:GO1162
Other Games
BasetradeTV708
StarCraft 2
OGamingTV SC2 282
SC2 Vod Archives73
Blizzard YouTube
[ Show 21 non-featured ]
StarCraft 2
• scorpling 48
• Zealot Hockey39
• D4rkn0ob1k 11
• DakkoN 7
• CammyGreen 3
• PlayArcher 2
• Mokomi1
• aXEnki
• Genesis Gaming
• intothetv
• AlphaB_SC2
• IndyKCrew
• Alpha X_
• LaughNgamez Trovo
• Laughngamez YouTube
• Matiz_pl
• Kozan
SC2: Legacy of the Void
• KarlJayG
StarCraft: Brood War
• sscaitournament3
• AfreecaTV YouTube
Other Games
• BadBorz10
Upcoming Events
Alpha Pro Series
7h 34m
Solar vs Zest
AfreecaTV BJ Destructio…
10h 34m
Shinhan Tank Proleague
20h 34m
AfreecaTV BJ Destructio…
1d 10h
Afreeca Starleague
1d 10h
Snow vs Soulkey
Rush vs BeSt
OlimoLeague
1d 11h
KCM Race Survival
2 days
Shinhan Tank Proleague
2 days
KCM Ladies Race Survival
4 days
Online Event
4 days
[ Show More ]
Bald Guy Classic
4 days
Shinhan Tank Proleague
4 days
Grand Platypus Open
5 days
BW Jeez Weekly
5 days
Bald Guy Classic
5 days
BSL
5 days
kogeT vs DragOn
TerrOr vs Dandy
BeAsT Cup
5 days
Alpha X Junior Champion…
5 days
IntoTheAlphaX Pro Circuit
6 days
Trap vs TY
INnoVation vs Zest
Bald Guy Classic
6 days
BSL
6 days
Dewalt vs BoA
KwarK vs spx
Liquipedia Results

Completed

BW Jeez Weekly 101
IEM Katowice 2021
30k/CM Off-S. Tour
IEM Katowice 2021

Ongoing

Best of the Best Tour
KCM Race Survival 2021 Season 1
Deathfate Pro League
BSL11 GosuLeague
Bombastic StarLeague 11
Rogue City Rumble
Shinhan Tank Proleague S4
BWCL Season 52
BWCL Season 52: Div-A
2021 ACS Season 1
Masters Clash Champ. 2021
Nexus Forces Tour.
NGS Storm Division S2
Nexus Forces Tour. Q1
ESEA S36 - NA Premier
ESEA S36 - EU Premier
ESEA S36 - AU Premier
Pinnacle Cup
Snow Sweet Snow #2

Upcoming

BWCL Season 53
BW Jeez Weekly 105
ASL Season 11
BW Jeez Weekly 104
BW Jeez Weekly 103
King of Kings 52
BW Jeez Weekly 102
DH Masters Summer: Finals
StayAtHome Story Cup #3
DHM Summer: China
DHM Summer: NA
DHM Summer: Oceania
DHM Summer: Asia
DHM Summer: LatAm
DHM Summer: Europe
2021 GSL Season 1
BLAST Premier Spring Finals
IEM Summer 2021
DH Masters Spring 2021
BLAST Premier Spring Showd.
DreamHack Open Mar 2021: NA
ESL Pro League Season 13
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...

Disclosure: This page contains affiliate marketing links that support TLnet.

Advertising | Privacy Policy | Terms Of Use | Contact Us

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