7 ms·
SimCity UI Code + DRM
- pooriaazimi 14y agoThere'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`)
- esrauch 14y agoLikely 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.
- jschorr 14y agoIt 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/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java 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)
- gee_totes 14y agoWhat 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?
- thomasvendetta 14y agoI can't really speak for how common it is, but the Battlefield Play4Free server browser is written in Javascript [1]. [1] http://documentcloud.github.com/backbone/#examples-battlefield http://documentcloud.github.com/backbone/#examples-battlefie...
- emehrkay 14y agoI learned that a lot of game menus are/were written in flash which was a huge shock to me, js would be as much, if not more, of one
- smiddereens 14y agoA lot of games use Flash for in-game UIs. See Scaleform.
- ErikGelderblom 14y agoQuite some game UI's are done in Flash (check out ScaleForm by Autodesk: http://gameware.autodesk.com/scaleform http://gameware.autodesk.com/scaleform) so using JavaScript seems plausible as well.
- stephengillie 14y agoSome older games had the menus fully rendered in openGL. I'm not sure which is better, but I would think our society has more domain experience making menus with flash than with openGL.
- seanalltogether 14y agoexactly, the tooling and skillset for interface design/dev is extremely mature these days, and it probably isn't economical to move people onto custom solutions.
- Bjartr 14y ago>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 probably. Most games have some scripting layer in their engines to simplify implementing non-performance-critical game logic. Lua and JS are two of the most popular languages for achieving that these days. [1] http://awesomium.com/ http://awesomium.com/
- notdan 14y agoFWIW, 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 months ago and haven't regretted it a bit. [1] https://code.google.com/p/chromiumembedded/ https://code.google.com/p/chromiumembedded/
- TheMakeA 14y agoWe are starting to use Chromium Embedded for all of our in-game UIs, after going through Flash and (for a brief period) CEGUI. No major regrets here. In fact, we like HTML so much that we are considering moving our game tools (level editors, etc) to HTML as well, ala Insomniac [1]. [1] http://www.insomniacgames.com/new-generation-of-insomniacgames-tools-as-webapp/ http://www.insomniacgames.com/new-generation-of-insomniacgam...
- ramchip 14y agoThat 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...
- revoked 14y agoI asked one of the SimCity devs a question along those lines this weekend: https://twitter.com/MaxisScott/status/310835756107177984 https://twitter.com/MaxisScott/status/310835756107177984 Q: Is the launcher built on WebKit or some other layout engine? Are there things in game that are WebKit too? A: The whole UI is done in javascript running a custom version of webkit. :D
- dsl 14y agoIt's webkit: https://sites.google.com/site/eawebkitwiki/ https://sites.google.com/site/eawebkitwiki/
- drivebyacct2 14y agoAt the very least it seems cut off...
- ghayes 14y agoGithub lists a non-truncated version [1] [1] https://gist.github.com/anonymous/5133829/raw/9340a6fdc354537b878291f591987e27c1605335/SimCityUI.js https://gist.github.com/anonymous/5133829/raw/9340a6fdc35453...
- deleted 14y ago[deleted]
- toufka 14y agotop link: "This file has been truncated, view the full file [by clicking]."
- comex 14y agoMisleading title. This is obviously a formatted version of minified JS, presumably extracted from the shipping game, not a leak.
- toufka 14y agoobviously? care to share for those of us who don't read JS fluently?
- SammoJ 14y agoWasn't obvious to me on a first skim through either, but on second viewing all simple variable names are single letters - exactly as one would get through minifying. See for example here and below: https://gist.github.com/anonymous/5133829#file-simcityui-js-L11114 https://gist.github.com/anonymous/5133829#file-simcityui-js-...
- dm2 14y agoThe fact that the function parameter are (a, b, c) indicates that it was minified code.
- lmkg 14y agoIn 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.
- SchizoDuckie 14y ago3.5 mb of Javascript. Glug. Looks like just the game ui. I cannot really find references to DRM like the title says. Lots of nice references to cheats though! They all rely on simcity.DEBUG being true, if (simcity.DEBUG) switch (a) { case scrui.kKeyCodeDigit1: c && (e && !d) && scrui.RunCheat("scgameui -unlockalltools"); break; case scrui.kKeyCodeLetterW: c && (e && !d) && simcity.CreateUnit("T_RCI_AddHourlyIncomeCheat") } Also pretty nifty: There's a rest api built into the game for communication, (as wel as websockets) and the name and email of one of the programmers are still in the code. simcity.TutorialFakeUserData.creator = { uri : "/rest/user/0", tutorialState : 1, id : 0, screenName : "Chet Keno", email : "mayorkeno@simcity.com", nucleusId : 0, lastLogin : 0, isOnline : "true", avatarImage : "Graphics/Tutorial/tutorial_avatar_keno.png", cities_count : 1 }; Also interesting is that it seems that this is not just a stripped v8 engine. There's things in the code that make me think the whole game UI is actually a pretty decent webkit engine: simcity.gEventManager = new simcity.cEventManger; simcity.gEventTypes = { CLICK : "click", MOUSEUP : "mouseUp", MOUSEDOWN : "mouseDown", MOUSEOVER : "mouseOver", MOUSEOUT : "mouseOut", ITEMSELECTED : "itemSelected", KEYUP : "keyup", KEYDOWN : "keydown", DATACHANGED : "dataChanged", HASHCHANGED : "hashChanged", GENERICEVENT : "genericEvent", SOCKETEVENT : "socketEvent", SOCKETCONNECT : "socketConnect", SOCKETDISCONNECT : "socketDisconnect" }; simcity.SocketManager = {}; simcity.cSocketManager = function () { this.mSocketListeners = []; this.mSocketRequests = []; update: It could be leftovers, but this indicates that this is code from a prerelease/debug build. simcity.SetUpDemoScreen = function () { simcity.persistentLayout = gUIManager.LoadLayout("Layouts/PersistentPreAlpha.js", gUIManager.GetRootWindow()); simcity.SetTextOnElement(simcity.DemoExitButtonTxt, new scrui.cLocaleString("Tutorials.json", "0x0eaf7bc9", "EXIT")); simcity.SetTextOnElement(simcity.DemoAvailableReleaseDateTxt, new scrui.cLocaleString("Tutorials.json", "0x0eaf7bb2", "AVAILABLE FEBRUARY 2013")); simcity.SetTextOnElement(simcity.DemoThanksForPlayingTxt, new scrui.cLocaleString("Tutorials.json", "0x0eaf7b4b", "THANKS for PLAYING")); simcity.SetTextOnElement(simcity.DemoPreOrderTxt, new scrui.cLocaleString("Tutorials.json", "0x0eaf7bb1", "PRE-ORDER AT SIMCITY.COM")); simcity.SetTextOnElement(simcity.DemoNotFinalSoftwareTxt, new scrui.cLocaleString("Tutorials.json", "0x0eaf7b3c", "Not Final Software")) };
- 14y ago
- devindotcom 14y agoIt would be an interesting project to offline the game - but I do wonder how hardcore the calculations are that run it. Would it be realistic to run the game itself and the server-side simulation stuff (nulling input from other cities) on an ordinary desktop computer? Or would you definitely need a secondary machine?
- nwh 14y agoI highly doubt there's any significant calculation. If there was, EA would have to rent hundreds of thousands of EC2 instances to cover the running of the game.
- thristian 14y agoOn 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".
- thethimble 14y agoI 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.
- bluedanieru 14y agoThey 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.
- anonymous 14y agoI'm pretty sure the server is running some, if not all, of the simulation code, in order to prevent cheating. If they just blindly trust client updates, I can simply send an update that gives me another million simoleons.
- Mahn 14y agoIs that all of the server-side logic of the game?
- SleekoNiko 14y agoNo, that's Javascript that handles the user interface.
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]
- oinksoft 14y agoGood to see people using the Closure Tools. It really is a powerful toolkit. Just a reminder that I (and some others, hopefully) are in ##closure-tools on Freenode to help you out if you have questions. Make sure to stay in the channel if you ask, as it's low-volume. I don't believe I've let a question go unanswered in well over a year, unless the person left right away and there was no point in answering it. The channel itself is in no way affiliated with Google, nor am I.
- asveikau 14y agoHow 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.
- belorn 14y agoThe uploader has a decent argument of fair use. Its uploaded in a nonprofit way, for educational purposes. It is a very small portion of the complete work. The effect of the use upon the potential market is either small or non-existant. That is three out of the four-factor balancing test regarding fair use. If we guess that this is about 0.3% of the complete work (3MB of a very very large final product), that would be comparable to use 30s clip of a film.
- magicalist 14y agoI don't think this is a huge deal, but I'm going to have to go with the GP. This would be an extremely poor example of fair use, and would really only dilute the positive meanings of "fair use". Fair use is meant to preserve access to copyrighted works by the public that granted copyright in the first place--to maintain certain rights for the public and to ensure that any works built upon copyrighted works (whether that's through inspired creativity or just commentary on the original) aren't themselves held hostage by the original copyright holder. Nothing in this example is transformative of the original work. The poster just released something that somebody else holds the copyright to. The educational aspect is an extremely weak argument; something merely existing in front of your eyes is not educational. The classic take on educational fair use for this would be taking minimal samples from the source and providing commentary upon them (why they did something the way they did, how they solved a problem that plagues a lot of developers, etc). It's also certainly not a minimal sampling of the material. The code has been minified, but there appears to be a substantial portion of their UI code intact here, and I wouldn't be surprised if it is largely functional without much more work. It would be dishonest to compare 3MB of scripts to a final game including assets, and even with substantial commentary and insight added to the code, you would not be able to justify redistributing this amount of the source. Again, it isn't quoting from a larger source, it's providing the entire source for large portions of the game engine. IP law aside, I feel the same way about this as I imagine I would have felt if the Doom 3 source had leaked early: no, you won't be able to play the game for free with it, and it is cool to see, but it's shitty that the people that actually wrote it had no say in its release.
- mandariini 14y agoso there is some browser based simcity or is this ui for the last released(and controversial) game?
- goggles99 14y agoPerfect example of how JavaScript is not good for app programming. It is great for little tasks, but does not scale well. Please create a standard for a browser VM instead of this JS as ASM workaround that everyone is starting to use.
- espadrine 14y agoThat's the exact contrary. What didn't scale was the server-side. The client-side is just fine. As for the idea of a browser VM, it is a world we live in. Welcome to the wonders of Java applets.
- deleted 14y ago[deleted]
- MartinZhel 14y agoI'm wondering if they are going to do the same with other games. I'm really happy EA decided to use JS to build the UI for the new Sim City game. At the moment my team is working on a solution that allows other game dev companies to do the same thing and I'm glad to see big players taking a step in that direction.
- mike503 14y agoCurious. Decided to explore. http://telemetry.simcity.com/simcity/rest/user/1 http://telemetry.simcity.com/simcity/rest/user/1 - user ID 1 http://telemetry.simcity.com/simcity/rest/user/1/friends http://telemetry.simcity.com/simcity/rest/user/1/friends - their friends but I thought friends can only seem to see each other on their respective server region. this seems to be storing centralized data? playing around with other nouns... http://telemetry.simcity.com/simcity/rest/region/1 http://telemetry.simcity.com/simcity/rest/region/1 - even includes some of their S3 URLs. http://telemetry.simcity.com/simcity/rest/box/2 http://telemetry.simcity.com/simcity/rest/box/2 - seems list CITY and REGION i'm trying to think of other nouns to throw in there. http://telemetry.simcity.com/simcity/rest/user/1027/regions http://telemetry.simcity.com/simcity/rest/user/1027/regions - a list of user ID 1027's regions http://telemetry.simcity.com/simcity/rest/user/10278/regions http://telemetry.simcity.com/simcity/rest/user/10278/regions - this guy has 4 regions! (I love RESTful services)
- jtheoof 14y agoI've created a gist containing a resume of the architecture used for simcity object if anyone is interested. http://goo.gl/eExRF http://goo.gl/eExRF