Is that all of the server-side logic of the game?
SimCity UI Code + DRM
41–50 of 66 posts
Re: SimCity UI Code + DRM
#42What parts of SimCity were written in Javascript? (Before you say "The UI, obvs", I'm wondering if it's a common practice to write UI code in games in javascript. I know that Gnome has a lot of JS that's tied into UI, I didn't expect the practice to make itself into game dev). And if this code is actually from SimCity, does SimCity have some type of v8 or other js engine packaged with it?
Re: SimCity UI Code + DRM
#43There's lots of instances like if (something....) return !0; else return !1; is there any reason why they aren't simply using `true` and `false`? (because !1 is defined to return literally `false` and !0 to return `true`)
Likely was "true" in the original source (and the source in separate files) and was replaced by some minifier. Not clear if these are the files verbatim or if it was automatically formatted from minified js.
Re: SimCity UI Code + DRM
#44Misleading title. This is obviously a formatted version of minified JS, presumably extracted from the shipping game, not a leak.
obviously? care to share for those of us who don't read JS fluently?
var COMPILED = !0
goog.DEBUG = !1
As you would expect in a weakly-typed C-style language, !0 == true, and !1 == false. JavaScript has first-class booleans, and there's not much to be gained by using one of these expressions instead of the literal it evaluates to. It only serves to save character count.Here's another example. Starting at line 91, you get the following:
!COMPILED && goog.ENABLE_DEBUG_LOADER && (goog.included_ = {}, goog.dependencies_ = { // ... and so forth
The above code uses commas in a particular way that usually means it comes from a minifier. JavaScript has a comma operator, which is basically just a statement separator, but it has the interesting property that it joins two statements as a single expression. As in many C-style languages, control flow operators like if and while don't require curly braces, and apply to the immediately following statement if they are absent. The combination of these two means that if(!foo){bar();baz();qux()}
is equivalent to if(!foo)bar(),baz(),qux();
which is shorter by a single character. Because the line of code joined by commas is now an expression, this also lets us abuse the short-circuit property of boolean operators, re-writing the above like so: foo&&(bar(),baz(),qux());
for a further savings of one more character.You pretty much never see the comma operator in code written by humans, because it's not useful for anything. Seeing them in production code, especially the way shown above, almost always means the code came out of a minifier. That actually broke the Opera browser a few months back--apparently the parser ran out of stack space when handling a single expression consisting of over 1,400 comma-separated statements.
Re: SimCity UI Code + DRM
#45I'm not a fan of DRM or what they did to Sim City... I've also got nothing against reverse engineering, excerpting code snippets, and that sort of thing. But violating the terms of GitHub, in addition to someone's copyright? Not cool.
Re: SimCity UI Code + DRM
#46Earlier quoted context omitted.
obviously? care to share for those of us who don't read JS fluently?
In general, the code is dense and difficult to read. If you know what to look for, there are a few idioms scattered around that stand out as awkward, but save a few characters here and there. There are some pretty obvious examples right at the beginning, lines 2 and 4: var COMPILED = !0 goog.DEBUG = !1 As you would expect in a weakly-typed C-style language, !0 == true, and !1 == false. JavaScript has first-class bool…
fireToken : 1 === f.tradeTokens.data.fireToken ? !0 : !1,
Why might that be a desired output from a minifier? Why not simply fireToken : 1 === f.tradeTokens.data.fireToken,
[1] https://gist.github.com/anonymous/5133829#file-simcityui-js-...Re: SimCity UI Code + DRM
#47Earlier quoted context omitted.
>I'm wondering if it's a common practice to write UI code in games in javascript It's becoming more common. Libraries like Awesomium[1] make it trivial to render browser content to an in-game texture and the V8 engine, while not 'easy' to integrate, is quite empowering in that you can have the UI code call directly into your compiled code. >does SimCity have some type of v8 or other js engine packaged with it? Very p…
FWIW, we were much happier with Chromium Embedded [1] than Awesomium. Awesomium is not free for non-commercial use (something like $8,000+ if you wanted source code included, the price of the software isn't even listed on the site now), the support was terrible, and the product seemed to be not nearly as fleshed out at Chromium Embedded. The website is prettier though... We switched to using Chromium Embedded 6-8 mon…
Re: SimCity UI Code + DRM
#48Earlier quoted context omitted.
obviously? care to share for those of us who don't read JS fluently?
In general, the code is dense and difficult to read. If you know what to look for, there are a few idioms scattered around that stand out as awkward, but save a few characters here and there. There are some pretty obvious examples right at the beginning, lines 2 and 4: var COMPILED = !0 goog.DEBUG = !1 As you would expect in a weakly-typed C-style language, !0 == true, and !1 == false. JavaScript has first-class bool…
Re: SimCity UI Code + DRM
#49Re: SimCity UI Code + DRM
#50Earlier quoted context omitted.
On the other hand, if there's no significant calculation on the server, why would EA pretend they were having massive load problems? Sure, maybe they wanted to get some headlines about 'SimCity is so popular it's having launch shortages', but there's got to be a happy medium between "friendly headlines talking about SimCity's popularity" and "seething EA hatred plastered across the Internet".
I think it was just poor scalability engineering. They didn't expect that many users on launch and they didn't implement a system that could scale upwards.