• Log InLog In
  • Register
Liquid`
TeamLiquid Liquipedia LiquidDota LiquidLegends
EST 23:58
CET 05:58
KST 13:58
  • 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
[ASTL2] Finals - eSport.fund vs LOGINmedia1[TQ] Best of the Best Tour W3 Recap6IEM Katowice RO24 - Group D Preview7IEM Katowice - A Totally Unbiased Trap Preview53IEM Katowice - RO24 Group B Preview9
Community News
2021 GSL Season 1 (Qualifiers)27Saying Goodbye to ASL English439BSL Season 11 - RO16 Group Stage5ASL11 set to start 28/0340New Worlds Map Contest: 1st Edition12
StarCraft 2
General
2021 GSL Season 1 (Qualifiers) Missing/Lost GSL VODs CatZ sat down with our new SC World Champion New ladder maps for first season of 2021? Reynor breaks down his IEM run with Harstem
Tourneys
ITaX Ultimate Battles#6 - INnoVation vs Zest $75 The Pizza Pie: Season 5 Tournament 6 [Alpha Pro Series] Solar vs Zest Korea Lite Cup #5 - $90 on 07th Mar Sun 3pm KST [IEM 2021] Katowice World Championship - Championship Sunday
Strategy
TvT Build Order - Reapers Hellions Liberator How to Break the F2 Hotkey Addiction [G] PvP: 3 Gate Pressure Opening Simple Questions Simple Answers
Custom Maps
Nexus Wars 2021 GUIDE Re-created map Ghost Tower Re-created map Wasteland
External Content
Drogos Recap of 2020 The StarCraft Observer Podcast Episode #4 Mutation #254 Flipping Out Mutation # 253 World on Fire
Brood War
General
ASL11 set to start 28/03 Saying Goodbye to ASL English koget: remastered It's March 3rd Think Quick: Best of the Best Tour
Tourneys
Desert Strike Tournament DS [BSL11] RO16 - Group A - Saturday 18:30 CET ! BSL Season 11 - RO16 Group Stage Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Try My great strategy game More Brood War "Mysteries" explained Sorry's TvP lategame Ghost strategies?
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 In-Development Indie MMORPGs The PlayStation 5 Warcraft III: The Frozen Throne 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! Coronavirus and You Tesla Motors GeoGuessr geography game
Fan Clubs
The TY Fan Club The Scarlett Fan Club INnoVation Fan Club
Media & Entertainment
[Manga] One Piece Anime Discussion Thread Korean Music Discussion Comic Books [Manga] Shingeki no Kyojin
Sports
2020 - 2021 Football Thread 2020 NFL and College Football Corona Season NHL 21: Tony DeActivito Did Nazi That Coming UFC/MMA Discussion Thread Formula1 2019
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
[Girl blog] Liking the wrong …
Garnet
The cost of full time travel a…
Tak3r
The StarCraft O…
TheStarCraftObserver
Some notes on Reynor vs Zest…
Teoita
Have it your way: a …
waywardstrategy
Balance Discussion
NonY
Customize Sidebar...

Website Feedback

Closed Threads



Active: 817 users

IsoRTS Code

Blogs > ChristianS
Post a Reply
ChristianS
Profile Blog Joined March 2011
United States2614 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
2 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 States2614 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
663 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
Rogue City Rumble
01:00
Round of 8 - Day 1
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft1014
SpeCial 402
ViBE332
RuFF_SC2 199
Forgg! 158
ProTech108
PiLiPiLi 91
ROOTCatZ 33
StarCraft: Brood War
Mong 286
ggaemo 165
.gypsy 155
Shine 89
Terrorterran 69
Noble 34
Super Smash Bros
hungrybox1977
C9.Mang01929
Other Games
summit1g37826
Destiny3063
shahzam2695
JimRising 697
Chillindude125
PainUser15
Solid Jake3
Organizations
Counter-Strike: Global Offensive
ESL CS:GO1627
StarCraft 2
OGamingTV SC2 73
SC2 Vod Archives69
Blizzard YouTube
[ Show 20 non-featured ]
StarCraft 2
• SkrOs 104
• HKG_Chickenman25
• undefetable014
• Hupsaiya 13
• Freeedom2
• Genesis Gaming
• AlphaB_SC2
• aXEnki
• intothetv
• Kozan
• IndyKCrew
• Alpha X_
• LaughNgamez Trovo
• Laughngamez YouTube
• Matiz_pl
• Tree_Stump
SC2: Legacy of the Void
• KarlJayG
StarCraft: Brood War
• sscaitournament3
• AfreecaTV YouTube
Other Games
• TSM TheOddOne721
Upcoming Events
Grand Platypus Open
3h 3m
Showmatch
8h 33m
ByuN vs Prince
maraleague
9h 3m
BW Jeez Weekly
12h 3m
BSL
12h 33m
BeAsT Cup
12h 33m
Alpha X Junior Champion…
13h 3m
OSC
14h 3m
Best of the Best Tour
17h 3m
Cross vs TerrOr
Dewalt vs kogeT
Bonyth vs Dandy
OSC
18h 3m
[ Show More ]
The NA Apprentice
20h 3m
AfreecaTV BJ Destructio…
1d 1h
Korea Lite Cup
1d 1h
Alpha Pro Series
1d 3h
Solar vs Zest
maraleague
1d 4h
Afreeca Challengers Sta…
1d 5h
OSC
1d 9h
maraleague
1d 10h
Showmatch
1d 11h
Nina vs MeomaikA
BSL
1d 12h
Alpha Pro Series
1d 14h
Starkiller vs Garitos
The Pizza Pie
1d 18h
AfreecaTV BJ Destructio…
2 days
Shinhan Tank Proleague
2 days
AfreecaTV BJ Destructio…
3 days
KCM Race Survival
4 days
Shinhan Tank Proleague
4 days
KCM Ladies Race Survival
6 days
Online Event
6 days
Bald Guy Classic
6 days
Shinhan Tank Proleague
6 days
Liquipedia Results

Completed

ASTL Season 2
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
BW Jeez Weekly 101
Masters Clash Champ. 2021
Nexus Forces Tour.
NGS Storm Division S2
ESEA S36 - NA Premier
ESEA S36 - EU Premier
ESEA S36 - AU Premier
Pinnacle Cup
Snow Sweet Snow #2

Upcoming

BW Jeez Weekly 105
ASL Season 11
BW Jeez Weekly 104
BW Jeez Weekly 103
King of Kings 52
BW Jeez Weekly 102
2021 ACS Season 1
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.