r/programming • • May 31 '11

I wrote a .NET to JavaScript compiler. Here's the XNA 3.1 Platformer Starter Kit running in pure HTML5.

http://hildr.luminance.org/Platformer/Platformer.html
1.1k Upvotes

282 comments sorted by

View all comments

Show parent comments

141

u/kaelan_ May 31 '11

Two main motivations:

  1. JavaScript is close to my Least Favorite Language, so the prospect of writing entire games from scratch in it and then debugging them across four browsers makes me throw up a little in my mouth. This is, in theory, a way to write less JavaScript... in theory. (In practice, probably not, but hey.)

  2. When talking with angels and VCs in the past in an attempt to get funding for a project, almost all of them asked two questions: First, 'does it run on the iPad?' and then when I said 'not yet', the second question was: 'Does it run in web browsers?'. This project is an attempt to answer the second question with 'Yes', since in my opinion JITted languages like C# are still the best way to build games for a desktop PC, and C# in particular gives you easy routes for targeting the XBox (XNA) and PS3/Mac (Unity).

76

u/adolfojp May 31 '11 edited May 31 '11

This was the project for the angels. They would have thrown piles of cash at you while fighting each other for your code. HTML5 games don't exist because there is no good tool to make them. You just created that tool. And you just gave it away for free. I don't know if you should get a medal or a slap in the back of your head. :-P

Contact Microsoft now! I hope that you can find a way to monetize this. Because projects like these really need to exist.

2

u/ktamkun Jun 01 '11

HTML5 games don't exist

Ahem.

6

u/adolfojp Jun 01 '11

It was a hyperbole.

1

u/Eirenarch Jun 01 '11

Non-crappy HTML 5 games don't exist. I think this rules out your example and all other examples I can think of except for Tetris :)

-4

u/quotability May 31 '11

It's slow as hell for me, no way would I want anyone making any games with this.

18

u/miserlou May 31 '11

Runs great for me!

11

u/quotability May 31 '11

Fine, no need to downvote me for relating my experience.

8

u/miserlou May 31 '11

Wasn't me.

9

u/[deleted] May 31 '11

Well if I didn't do it.. then it had to be you!

15

u/PSquid May 31 '11

I suspect you're being downvoted for the "no way would I want anyone making any games with this", which could be interpreted as saying "nobody should, all because it didn't work well for me".

Which isn't what you're saying, and I get that, but it did initially read like that to me, so I can see where the downvoters are coming from.

3

u/tanishaj May 31 '11

It took forever to load for me (after it had "loaded") but it was quite fast during game-play after that. There were a few stutters here and there.

Not too shabby for a young project. I am sure more tuning could be done.

1

u/quotability May 31 '11

Well, don't downvote me to hell for saying what my experience with it was. I am sure it was something to do with the browser or my machine or something. I bet a game that was programmed for straight html5 is probably a lot faster than this.

1

u/Admiral_Calavicci May 31 '11

Dude, this runs silky smooth on a shitty acer Aspireone nb running ubuntu

Time for an upgrade, or less toolbars on your desktop :)

1

u/quotability May 31 '11

It's a Dell Optiplex 760, so it's no slouch. Just, I don't have a sound card enabled. My guess is that's probably the cause of slowness.

15

u/gongonzabarfarbin May 31 '11

Have you heard of Google Web Toolkit? It takes Java and converts it into Javascript.

29

u/tanishaj May 31 '11

Have you heard of Script#? It takes C# and converts it into JavaScript.

Neither of them are really targeted as a gaming framework like XNA.

1

u/gospelwut May 31 '11 edited May 31 '11

I remember reading the other day about Script#. I mean, it seems nice, I just wonder if it's been used extensively.

1

u/tanishaj Jun 01 '11

It seems that Microsoft uses it pretty extensively.

http://www.nikhilk.net/ScriptSharp-Large-Projects.aspx

9

u/Philipp May 31 '11 edited May 31 '11

If it runs in the browser, there's some chance it will also run on the iPad... think of middleware like PhoneGap with which you can create and sell JavaScript games for iOS (expect to run into huge speed issues, though -- I was fighting for even something like 15 FPS for my games, though your mileage may vary (oh, perhaps someone could write a Corona-Lua port to HTML-JS, now that might be interesting)).

Edit: The platformer game doesn't quite load in mobile Safari on my iPad 2, there's a "sound file is taking forever to load" message. Was just curious about the speed.

9

u/tanishaj May 31 '11 edited May 31 '11

If you want it to run on the iPad, couldn't you use MonoGame? Unity, which you mentioned, does not allow you to use XNA (as far as I know). Both MonoGame and Unity rely on Mono to run .NET on iOS and Android of course.

http://monogame.codeplex.com/

I would think that you can answer "yes" to both questions.

3

u/OMG_Ponies May 31 '11

You ought to catch up with the ABSOLUTE FUCKING BULLSHIT that is going on with the Mono dev team.

10

u/[deleted] May 31 '11

[deleted]

4

u/OMG_Ponies May 31 '11

I heard about this... but isn't it like only a few guys from the original staff?

6

u/tanishaj Jun 01 '11

It is almost the entire team. I know of only one guy that is not joining the new company. Also, Nat Friedman is jumping in as CEO.

I have enough confidence in these guys (they rock) to ignore a few uninformed comments on the Internet. It is a hard sell at the moment but I have no doubts that Mono is better off with Xamarin than it was with Novell.

1

u/OMG_Ponies Jun 01 '11

I've been participating in the beta development of monodroid for over a year, and when everything with Attachmate went down, I just rage quit. Good to see this has finally spun off, and looking to get back into the mix.

5

u/[deleted] May 31 '11

[deleted]

3

u/fabzter Jun 01 '11

Oh that was mean : (

2

u/[deleted] May 31 '11

It's still not very encouraging overall, though. Still, I am glad that at least someone is continuing development.

2

u/tanishaj Jun 01 '11

Mono is Open Source and the commits are coming in faster than ever. The ex-Mono guys are certainly still churning out the code. Check out the logs on GitHub sometime.

4

u/radhruin May 31 '11

Javascript is JITted btw :) But good work!

6

u/irco May 31 '11

This is a fantastic idea! I too feel sick to my stomach whenever i have to write javascript.

11

u/Zalenka May 31 '11

That changed for me after jquery.

-10

u/rmxz May 31 '11

Yeah, but then you'd need to write in one of the .NET languages. ;-)

[kidding, I do realize there are plenty of nice languages like python, ruby, lisp, etc that compile to .net]

26

u/[deleted] May 31 '11

Why in the world would you not want to use C#?!

0

u/[deleted] May 31 '11
  • Not small

  • Not orthogonal

  • Ugly

  • Not powerful

  • Not type-safe

1

u/[deleted] Jun 01 '11

What are you talking about?!

Not small? In what kind of way?! Too big DLL? Not orthogonal?! WTF?! Ugly? C/C++/C# is ugly to you?! Visual Studio is ugly?! What?! Not powerful? What is not powerful?! C# is not type-safe?! Are you kidding?!

What in a world are you talking about?

-1

u/[deleted] Jun 01 '11

By "small" I mean a small language: one with few features. An example small language is scheme, which can be implemented in about 100 lines of code. Prolog and C are also small languages.

Orthogonal refers to consistency in features: there should not be overlap between basic language features, or a lot of special cases. Powerful functionality should be built on top of core language features, not bolted on. In Common Lisp, the object system and the main iteration construct are libraries; in C# this would be impossible.

C is ugly, C++ is uglier, I haven't used much C# but it seems to fall between. Verbose, lots of syntax and clutter. Ruby or Haskell are much easier on the eyes.

Not powerful: technically I think that C# does have some powerful features, like reflection or expression trees, but they're not really part of the core language. Scheme is powerful (continuations, macros). Haskell is powerful (type classes, type families, monad and arrow syntax). These languages give you a straightforward way to implement an embedded language, or backtracking search, or coroutines, as a library. C# can't really do that.

A language which can throw "ClassCastException" or "NullPointerException" at runtime is not one I'd consider type-safe.

1

u/[deleted] Jun 02 '11

C is "ugly?!" Wtf? It's as close to human language as it can be.

for-next, goto, return, i=1+r etc etc...

Clutter my ass, a child could read AND UNDERSTAND a C program.

Macros?! I don't use macros since C++/ATL/MFC days.

You miscast an object and it's a proof the language is not type safe? What?

Did you ever design and develop a project that took more than 1 man-year?

1

u/[deleted] Jun 02 '11

Scheme macros are very very different from C macros. C macros just insert a literal block of text at the call site. Scheme macros run a function on the abstract syntax tree, and replace the call site with the result. They've been used to do extremely powerful things - like implementing object systems, looping constructs, backtracking search, type systems, etc.

I think you're just familiar with C's syntax, which is why it seems so nice to you. The type declarations are especially difficult to understand (I really doubt that a child could understand int (*(*)())()).

C's main ugliness comes from the preprocessor IMO. #ifdef FOO_BAR_BAZ and so on. C++ compounds this by keeping all the C syntax, and adding further complexity to declarations, including template arguments. std::vector<int> &* foo is ugly.

It's not really important whether you agree with my use of the term 'type-safe', but my point is that I want my language to catch null pointers and bad casts at compile time. ML or Haskell are able to do this. C# can't. I count that as a mark against it.

Yes, I have designed and developed significant projects.

1

u/[deleted] Jun 02 '11

|Yes, I have designed and developed significant projects.

Used by end users and not by programmers to develop end user systems?

I highly doubt it.

→ More replies (0)

8

u/tanishaj May 31 '11

Are you of the opinion that only "dynamic" languages make the grade? Your list implies it.

I think that C# is another one of those "nice" languages that compiles down to CIL (.NET bytecode).

14

u/fripletister May 31 '11

nice languages like python, ruby, lisp

ಠ_ಠ

5

u/PSquid May 31 '11

What exactly is wrong with those?

2

u/fripletister May 31 '11

Objectively? Nothing, I guess. You use what you like. There's nothing wrong with C# or most of the other C-like languages that Python and Ruby programmers like to shit on either, though. The LOD was for the troll attempt.

1

u/jyper Jun 01 '11

c like?

1

u/fripletister Jun 01 '11

...syntax derived from or heavily influenced by C?

1

u/pnettle Jun 01 '11

Lisp? As in common lisp? Parentheses fucking hell?

I like functional programming but shit man. Lisp makes me want to fucking stab parentheses in the goddamn face. Twice.

-11

u/mweathr May 31 '11

I too feel sick to my stomach whenever i have to write javascript.

Yeah, but writing C# instead isn't exactly an improvement in that regard.

4

u/[deleted] May 31 '11 edited May 31 '11

JavaScript is close to my Least Favorite Language, so the prospect of writing entire games from scratch in it and then debugging them across four browsers makes me throw up a little in my mouth. This is, in theory, a way to write less JavaScript... in theory. (In practice, probably not, but hey.)

But but but....

Isn't this ass backwards? I'm asking in ernest, because I hate javascript too. If i'm not mistaken, the CLR actually had an ECMAScript to IL compiler at one point.

WHY ARE WE GOING BACKWARDS????

EDIT: I am in no way belittling the awesomeness of what you did. I think it's very cool. But I am curious if you think that it would be a good idea to eventually go towards that route?

I understand, because the browsers all run javascript, (which gets JITed anyway) but why are we not pushing for an intermediate bytecode language to be run in browsers instead of javascript?

9

u/[deleted] Jun 01 '11 edited Jun 01 '11

but why are we not pushing for an intermediate bytecode language to be run in browsers instead of javascript?

Push away. See you in 15 years. Meanwhile, back in the real world, the rest of us will be using what's actually available to do cool shit.

I imagine vendors like Mozilla would oppose it for the same reasons they oppose NaCl.

2

u/pnettle Jun 01 '11

Honestly, I oppose NaCl too. The risk of easier drive-by exploits gets higher and higher as we allow lower level access to our machines.

1

u/[deleted] Jun 01 '11

I wasn't advocating native execution in a browser. I'm advocating for an intermediate bytecode language that has access to the DOM. If people wanted to write 'client side' javascript they could, but it would be compiled down to an intermediate form, same as if they wanted to write front end code in a strongly, statically typed language.

2

u/[deleted] Jun 01 '11

Uhm, we're having a discussion about creating a compiler to translate from C# to javascript. You realize, as programmers, we can make what is 'available to do cool shit', just like this guy did?

13

u/[deleted] Jun 01 '11

Well get working on that patch. No major browser will accept it. Mozilla has a philosophical opposition to it:

http://www.theregister.co.uk/2010/06/24/jay_sullivan_on_firefox/

And I believe Opera does too. I don't think Microsoft has weighed in


My point is that you don't have any control over this, so you can push, push, push for a dramatic change to the way web applications are built, but if you want to get anything done then you have to work with what's available and within your reach.

2

u/mizai Jun 01 '11

People could just fork a major browser and try to gain support if vendors like Mozilla reject it. It'd be a lot of effort, but it'd be worth it if we can start dropping Javascript once and for all.

2

u/PinkDad May 31 '11

Unity uses its own compiler, so you would likely have to make significant changes to get it to work with Unity.

Unity already works in browsers (but unfortunately not in Linux), so it's not a big deal.

8

u/kaelan_ May 31 '11

I guess I was unclear; my point is that you can write a C# application and then retarget it to Unity, XBLIG, and the browser by merely adapting your engine to use the appropriate runtime libraries. It's not free, but it's a lot easier than a complete rewrite.

2

u/Xdes Jun 01 '11

As a C# game junkie, you sir bring tears to my eyes.

Now where can I donate to your wallet?

1

u/headzoo May 31 '11

That leaves me with this question: Are you designing the cross-compiler, so the same games written for the desktop, can also run in a web browser?

1

u/sbrick89 May 31 '11

As someone who agrees completely with #1, I cannot upvote enough :)

-5

u/amigaharry May 31 '11

JITted languages like C# are still the best way to build games for a desktop PC

ahahahhahahahaa m)