• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:31
CEST 18:31
KST 01:31
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Weekly Cups (June 30 - July 6): Classic Doubles2[BSL20] Non-Korean Championship 4x BSL + 4x China8Flash Announces Hiatus From ASL66Weekly Cups (June 23-29): Reynor in world title form?14FEL Cracov 2025 (July 27) - $8000 live event22
StarCraft 2
General
The SCII GOAT: A statistical Evaluation The GOAT ranking of GOAT rankings Weekly Cups (June 23-29): Reynor in world title form? Weekly Cups (June 30 - July 6): Classic Doubles Program: SC2 / XSplit / OBS Scene Switcher
Tourneys
RSL: Revival, a new crowdfunded tournament series FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays Korean Starcraft League Week 77
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
Flash Announces Hiatus From ASL SC uni coach streams logging into betting site BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ ASL20 Preliminary Maps
Tourneys
[BSL20] Grand Finals - Sunday 20:00 CET CSL Xiamen International Invitational [BSL20] Non-Korean Championship 4x BSL + 4x China The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile What do you want from future RTS games? Beyond All Reason
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
US Politics Mega-thread Russo-Ukrainian War Thread Stop Killing Games - European Citizens Initiative Summer Games Done Quick 2024! Summer Games Done Quick 2025!
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 630 users

IsoRTS Code

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3188 Posts
February 14 2021 20:58 GMT
#1
I thought I'd be posting this blog sooner, but some life stuff has gotten in the way. I'm actually typing this bit at the top with one hand because I had surgery on my wrist a couple days ago (doing fine, don't worry). But my last blog is still in the sidebar actually, so I guess I'm posting right on time. Is the TL Blog section moving slower these days?

In my previous blog, I was simultaneously impressed with the capabilities of SFML for making simple games, and frustrated with the tutorials and textbooks I had followed so far at the lack of good suggestions regarding how to organize the code. Horton in particular even started to hint at a potential code organization (put all your objects in a big vector of pointers to a base Object class, and give them each an update() and draw() function that you call each frame), only to essentially say "As you can see, it's not obvious how you'd handle something like collisions with this. Anyway, good luck!"

Frustrated, I thought I'd like to go look at an *actual* game, not just an educational tutorial. Then I could get some hint of how real programmers are programming real games. And fortunately, the SFML website has a "Projects" forum where people can post about actual projects they're building! And there's some pretty neat stuff, like a dynamic light and shadow casting library or a GUI library.

That's all well and good, but I wanted a full game. And clicking through I found a tantalizing post titled "Isometric RTS" that, I mean, I couldn't *not* click on, right? It's by a guy with the handle "Switchboy" who the forum identifies as a "Newbie" (only 4 posts). There's a brief introduction to the project: he's been working on it for a couple of months, it's his second big C++ project (he abandoned a previous RPG roguelike because the codebase got too messy), and it's inspired by Age of Empires. He's also got a feature list (already reached, planned, and stretch goals), a github link, and a video (in Dutch):



I'm gonna look at this guy's code in a moment, but I want to pause here to say the stuff he's shown so far is awesome. Fucking incredible. I'm simultaneously impressed and excited that it's possible to build so much as a random guy working on a project in his spare time, and intimidated that other people are managing to do so much more than I would know how to do. I'd be thrilled to have built anything close to the project he's demonstrating there. The post was in June 2020; I wonder how much more he's managed since then! On the off-chance Switchboy ever winds up reading this blog, I hope his main takeaway is that I think his project is fucking sweet and I'd love to play his game if/when he finishes it.

Okay, so I don't really understand how github works, but I figured out how to download his code. First things first, it doesn't build. At some point I'll do a blog solely complaining about the awful and unintuitive interface of Visual Studio and, really, everything you have to start out doing when you want to learn C++, but for starters, there's a whole song and dance you have to do to make an SFML project build, including going into a bunch of different submenus, specifying filepaths to find SFML stuff, specifying specifically what SFML stuff you want to use, and copying some SFML stuff directly into your project folder. Near as I can tell Visual Studio doesn't even want to give you a "Save As..." function to copy a blank project with those adjustments already made, so I've just been having to do that whole song and dance every time I start a new SFML project + Show Spoiler [template aside] +
VS does have a "Template" feature where you can create a blank project, save it as a "template", and it should get copied. Near as I can tell, it just doesn't work? If I create a new project from the template, it still isn't configured in any of the ways that tutorial specifies, so I still have to do all that from scratch
. The upside to that is that I had a pretty good idea what menus I might have to go fuss with to get the thing to build, and sure enough there were filepaths specific to his setup I changed to match my setup. That fixed some of the build errors, but not others; for some reason when I open his project, Visual Studio can't find a bunch of stdlib stuff?

But whatever. I'm not here to play his game, I'm here to look at his code. I don't need it to build for that. But where to start? He's got 13 different header files and 13 different .cpp files, with names of varying clearness about what they actually do + Show Spoiler [list] +
actors.h and .cpp
buildings.h and .cpp
button.h and .cpp
gamestate.h and .cpp
gametext.h and .cpp
globalfunctions.h and .cpp
main.h and .cpp
objects.h and .cpp
orderCursor.h and .cpp
player.h and .cpp
projectile.h and .cpp
randomMapGenerator.h and .cpp
tooltip.h and .cpp
. I'm already a little unhappy that some of these header and source file names use camel case where others just shove lower-case words together, but again, whatever. Gimme the code.

How about main.cpp? That's where the compiler starts, so why shouldn't I? Right off the bat, he's got 13 #include's - 7 of his own creation, 1 from SFML, 3 pretty normal stdlib ones, and <future> and <mutex>. I think that means he's multi-threading? Okay. And then the first thing he does is create a global variable:
gameState currentGame;
Okay, I know global variables are frowned upon, but sometimes they're hard to avoid. Maybe he's just storing a couple convenient objects like the RenderWindow in a global object for easy access. Let's just go check out its declaration... fuck.

gamestate.h starts out by linking to 17 different global variables from other files using the "extern" keyword. Then it declares a couple simple structs. Then it declares the class gameState, which has no less than 60 public functions, 83 public variables (including 37 sprites, 37 textures, and 5 int arrays indicating the world map, building locations, object locations, and more), and a few dozen private variables (a couple of which are misspelled). gamestate.cpp is nearly 2500 lines of code, with scarcely a comment to be found.

Not to put too fine a point on it, but I think I might be starting to see how he wound up abandoning his first project due to the codebase getting too messy. I've been reading Game Programming Patterns by Robert Nystrom, and I thought of this part:

Before you can change the code to add a new feature, to fix a bug, or for whatever reason caused you to fire up your editor, you have to understand what the existing code is doing. You don’t have to know the whole program, of course, but you need to load all of the relevant pieces of it into your primate brain.

We tend to gloss over this step, but it’s often the most time-consuming part of programming. If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves.

Once you’ve got all the right context into your wetware, you think for a bit and figure out your solution. There can be a lot of back and forth here, but often this is relatively straightforward. Once you understand the problem and the parts of the code it touches, the actual coding is sometimes trivial.
source

I'm trying to imagine how you would ever edit this code to make changes. If a function uses gameState for anything (and with 60 different functions locked up in it, it's likely to), you'll have to load that whole thing, all 60 functions, 83 public variables, and 2500 lines of code, into your cerebrum by reading through it line by line in your IDE (which is technically an OCR process, as Nystrom points out elsewhere). I imagine Switchboy only got this far by virtue of having built all this himself, and having relatively clear memory of exactly what he had done. But is even that going to hold up after, say, a year of development? I'm looking at these variable names and wondering why there's a vector<float> called "mousePosition" and another vector<int> called "mouseFakePosition." Why does he need to store a fake mouse position? Is the other its "real" position? How long until Switchboy himself doesn't even remember why these both exist, and what the difference is?

So in my hunt for good examples of effective OOP architecture for building games, I'm gonna pass on Switchboy's (again, fucking awesome) project as an example I should follow. But I might check up on that YouTube channel periodically and see if he ever finishes the thing. I'd love to play it!

"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
Mamasux
Profile Joined December 2020
6 Posts
February 14 2021 23:17 GMT
#2
I don't know how skilled you are in coding, but I guess you are just beginning to learn (since you don't know how github works).
Reading code is good, but writing code is much more important. I think going for a RTS as a beginner is just too much. Also, while theory is good, i think you can get stuck on it. Thats what happened to me and ive started to overthink everything.

Just pick some fun projects, write the best code you can and learn alot of things while doing it. gl man
ChristianS
Profile Blog Joined March 2011
United States3188 Posts
February 15 2021 03:02 GMT
#3
Thanks! Again, I’m not gonna take on a project like building an RTS any time soon. What bewildered me most was the fact that for as long and hard-to-parse as this guy’s project was, if you wrote it “correctly” it would probably be quite a bit *longer*. I can’t imagine doing all that as a solo side project.

I was thinking about my first bigger project maybe being a Puzzle League clone? Maybe I’m wrong but that sounds fairly manageable to me. Plus I absolutely love Puzzle League games.
"Never attribute to malice that which is adequately explained by stupidity." -Robert J. Hanlon
Archeon
Profile Joined May 2011
3253 Posts
Last Edited: 2021-02-16 14:49:06
February 16 2021 14:47 GMT
#4
I think the usual first game projects are racing games, but puzzle games work too. If you work with an engine there are other things these are good at (f.e. jump and runs in unity, shooter are very easy in unreal) but then you move away from "pure" coding and a bit more to script wielding.
low gravity, yes-yes!
Please log in or register to reply.
Live Events Refresh
RotterdaM Event
16:00
Rotti Stream Rumble 4k Edition
RotterdaM443
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 762
RotterdaM 443
Hui .357
MaxPax 334
StarCraft: Brood War
Bisu 1941
EffOrt 1308
Flash 1304
Jaedong 1180
Hyuk 821
Stork 371
actioN 369
Soulkey 276
Soma 275
Snow 187
[ Show more ]
firebathero 175
Mind 98
JulyZerg 71
TY 69
sSak 64
Barracks 57
Sharp 50
JYJ46
Terrorterran 45
PianO 43
Rock 31
HiyA 21
Aegong 20
soO 16
yabsab 15
GoRush 11
Shine 8
IntoTheRainbow 7
Dota 2
Gorgc6615
qojqva3321
League of Legends
singsing2289
Dendi1253
Counter-Strike
fl0m1143
markeloff176
Super Smash Bros
Mew2King204
Other Games
hiko1544
Beastyqt844
ceh9366
Lowko307
crisheroes263
ArmadaUGS149
KnowMe140
Trikslyr62
Organizations
Other Games
gamesdonequick47269
StarCraft 2
angryscii 21
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Reevou 7
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Michael_bg 2
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis6915
• TFBlade833
• Jankos802
Other Games
• Shiphtur316
Upcoming Events
Replay Cast
7h 29m
Sparkling Tuna Cup
17h 29m
WardiTV European League
23h 29m
MaNa vs sebesdes
Mixu vs Fjant
ByuN vs HeRoMaRinE
ShoWTimE vs goblin
Gerald vs Babymarine
Krystianer vs YoungYakov
PiGosaur Monday
1d 7h
The PondCast
1d 17h
WardiTV European League
1d 19h
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
uThermal 2v2 Circuit
1d 23h
Replay Cast
2 days
RSL Revival
2 days
ByuN vs SHIN
Clem vs Reynor
Replay Cast
3 days
[ Show More ]
RSL Revival
3 days
Classic vs Cure
FEL
3 days
RSL Revival
4 days
FEL
4 days
FEL
4 days
BSL20 Non-Korean Champi…
5 days
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
Sparkling Tuna Cup
5 days
RSL Revival
5 days
FEL
5 days
BSL20 Non-Korean Champi…
6 days
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
Liquipedia Results

Completed

BSL Season 20
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
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
IEM Cologne 2025
FISSURE Playground #1
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 © 2025 TLnet. All Rights Reserved.