Live data from Hacker News

SimCity UI Code + DRM

gist.github.com

41–50 of 66 posts

Re: SimCity UI Code + DRM

#42

What 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?

It's webkit: https://sites.google.com/site/eawebkitwiki/

Re: SimCity UI Code + DRM

#43
post #38

There'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.

It is one of the peephole optimizations that Closure Compiler performs to save some space (read: 2-3 characters) in the final output: http://code.google.com/p/closure-compiler/source/browse/src/.... The compiler actually has a lot of cool little tricks like that to save space (since saving even a few bytes for a property like, say, Gmail, can translate to very large numbers very quickly)

Re: SimCity UI Code + DRM

#44
post #10
post #8

Misleading 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?

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 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

#45
How is it cool to put someone else's non-free copyrighted work on github?

I'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

#46
post #44
post #10

Earlier 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…

On the subject of minification, I see a lot of lines that look like this[1]:

  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

#47
post #30
post #22

Earlier 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…

That was also my experience with Awesomium. It was buggy and support is awful. I actually tried to contact them for a company which was interested in buying a commercial license -- blows my mind that they'd get emails basically saying "we want to give you thousands of dollars" and not even answer. It may have improved since then but I'd be wary of introducing a dependency on it...

Re: SimCity UI Code + DRM

#48
post #44
post #10

Earlier 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…

Cool observations. Thanks!

Re: SimCity UI Code + DRM

#50

Earlier 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.

They knew exactly how many users to expect, I'm sure. But you aren't going to pay for a solution to handle all of them when you expect the demand to taper off after a few days.
Post reply on HN