• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 06:05
CEST 12:05
KST 19:05
  • 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] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5TL.net Map Contest #21 - Finalists4Team TLMC #5: Vote to Decide Ladder Maps!0[ASL20] Ro8 Preview Pt1: Mile High15
Community News
Weekly Cups (Sept 29-Oct 5): MaxPax triples up2PartinG joins SteamerZone, returns to SC2 competition245.0.15 Balance Patch Notes (Live version)98$2,500 WardiTV TL Map Contest Tournament 151Stellar Fest: StarCraft II returns to Canada11
StarCraft 2
General
Weekly Cups (Sept 29-Oct 5): MaxPax triples up 5.0.15 Balance Patch Notes (Live version) PartinG joins SteamerZone, returns to SC2 competition ZvT - Army Composition - Slow Lings + Fast Banes Stellar Fest: StarCraft II returns to Canada
Tourneys
Tenacious Turtle Tussle Stellar Fest $2,500 WardiTV TL Map Contest Tournament 15 Sparkling Tuna Cup - Weekly Open Tournament LANified! 37: Groundswell, BYOC LAN, Nov 28-30 2025
Strategy
Custom Maps
External Content
Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More Mutation # 491 Night Drive
Brood War
General
Question regarding recent ASL Bisu vs Larva game RepMastered™: replay sharing and analyzer site [ASL20] Ro8 Preview Pt2: Holding On BarrackS' ASL S20 Ro.8 Review&Power of Friendship BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[Megathread] Daily Proleagues [ASL20] Ro8 Day 4 [ASL20] Ro8 Day 3 Small VOD Thread 2.0
Strategy
Current Meta 9 hatch vs 10 hatch vs 12 hatch TvZ Theorycraft - Improving on State of the Art I am doing this better than progamers do.
Other Games
General Games
Dawn of War IV Nintendo Switch Thread ZeroSpace Megathread Stormgate/Frost Giant 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
TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine The Games Industry And ATVI Canadian Politics Mega-thread
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Manga] One Piece
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
Recent Gifted Posts The Automated Ban List BarCraft in Tokyo Japan for ASL Season5 Final
Blogs
[AI] From Comfort Women to …
Peanutsc
Mental Health In Esports: Wo…
TrAiDoS
Try to reverse getting fired …
Garnet
[ASL20] Players bad at pi…
pullarius1
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1224 users

IsoRTS Code

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States3203 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 States3203 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
3260 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
Replay Cast
10:00
Master Swan Open #96
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 228
StarCraft: Brood War
BeSt 1789
Bisu 1297
Larva 512
actioN 492
ToSsGirL 43
yabsab 38
Sacsri 31
Hyun 20
NotJumperer 17
Dota 2
Dendi424
XcaliburYe179
ODPixel171
Counter-Strike
olofmeister1346
shoxiejesuss213
allub117
Heroes of the Storm
Khaldor190
Other Games
singsing1519
ceh9736
Pyrionflax210
crisheroes156
Mew2King74
rGuardiaN36
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Berry_CruncH201
• LUISG 66
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Stunt613
• HappyZerGling112
Upcoming Events
Monday Night Weeklies
5h 55m
Map Test Tournament
1d
PiGosaur Monday
1d 13h
Map Test Tournament
2 days
Tenacious Turtle Tussle
2 days
The PondCast
2 days
Map Test Tournament
3 days
Map Test Tournament
4 days
OSC
4 days
Korean StarCraft League
4 days
[ Show More ]
CranKy Ducklings
4 days
Map Test Tournament
5 days
OSC
5 days
[BSL 2025] Weekly
5 days
Safe House 2
5 days
Sparkling Tuna Cup
5 days
Map Test Tournament
6 days
OSC
6 days
IPSL
6 days
dxtr13 vs Napoleon
Doodle vs OldBoy
Liquipedia Results

Completed

BSL 20 Team Wars
Maestros of the Game
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
Acropolis #4 - TS2
C-Race Season 1
IPSL Winter 2025-26
EC S1
ESL Pro League S22
Frag Blocktober 2025
Urban Riga Open #1
FERJEE Rush 2025
Birch Cup 2025
DraculaN #2
LanDaLan #3
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

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
WardiTV TLMC #15
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 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...

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.