Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Jul 2004
Offline Last Active Today, 03:18 AM

#5142998 Browser-Based Game: Best Language?

Posted by smr on 28 March 2014 - 10:11 PM

I also must disagree with Karsten about staying away from jQuery. Jquery is very well supported by current AND older browser versions going back to IE 8. If you want prior to IE 8 support that is available too by using the 1.9 branch of jQuery. Its API is the same as the 2.0 branch but with the cruft for crappy browsers left in. Keep in mind that using jQuery electors does incur overhead, so be sure to cache them and to profile when you suspect jQuery might be a performance issue. My experience is that in the few cases when jQuery is a bottleneck, caching selectors or direct DOM manipulation closes the gap. Use jQuery when it helps (95% of the time), and direct dom when it doesn't. Simple.

#5142996 Browser-Based Game: Best Language?

Posted by smr on 28 March 2014 - 10:03 PM

I recommend JavaScript with node for the server side. All you need is a text editor (notepad++, gedit, etc.).

As far as compatibility, you're OK. All modern browsers support canvas (2D context, not webGL) and JavaScript. The challenge is performance, screen size and input. Three of the four current versions of the popular browsers (Firefox, Chrome, Safari) perform pretty well on the desktop and mobile. Of course IE lags behind but is still OK for all but the most demanding of work, such as fluid Canvas animation.

Obviously the physical size of the screen and whether or not there is a keyboard or other physical input device attached will have a strong influence on how your game will be experienced on different platforms.

#5142746 Browser-Based Game: Best Language?

Posted by smr on 27 March 2014 - 08:07 PM

In the browser itself, barring plugins, you're pretty well limited to JavaScript. There are other languages you can use which can be compiled to JavaScript, but you can't escape the semantics of JS, so any such language is more or less syntactic sugar. They may add some static analysis, but my experience with TypeScript and CoffeeScript has been they are not worth the trouble.

For the server your choices are far more vast. Most contemporary languages have a web app stack (rails, grails, django, flask, ASP.NET MVC, sails, meteor...) that will help keep things organized and prevent you from rebuilding the wheel.

If you are new to programming or have absolutely no bias I'd go with Node.js along with one of the popular full stack frameworks like express or sails. This way you need only learn one language, and there's a chance you could share some code on the client and server side, though this usually is a minimal amount.

#5135455 Unmaintainable code

Posted by smr on 28 February 2014 - 02:24 PM

I also thought for sure that this was generated code...

#5125356 Is HTML5 a legit language for developing game?

Posted by smr on 21 January 2014 - 08:52 AM

Overall my experience using HTM5 has been positive. That being said, the issues I have experienced are due to the Canvas not cooperating with what I want it to do (for example, no way to disable min/mag filter when scaling images), JavaScript performance which is overall quite good on the desktop, but varies wildly on mobile as you could imagine. And also the difficulty in managing a large codebase in a dynamic language.

#5100823 BASIC

Posted by smr on 12 October 2013 - 11:02 AM

Any instructor who says "NEVER" use GOTO  may never have done much serious programming  (where they are very useful for abnormal exiting of complex subroutines,  and the horrors of number goto labels are long gone)

I've been programming for 20 years, professionally for 12, and I can say this is the first time in probably about six years that I've typed the four letter sequence "g o t o". When I did use goto, it was always preceded by "on error", because that's the exception handling idiom in VBScript - "On error goto label". I program at least 40 hours per week.

#5094440 Correctly casting serialised objects

Posted by smr on 16 September 2013 - 07:31 AM

Too much. You need a factory that can select the appropriate class based on the int type code. This class can instantiate the specific message class using a parameterless constructor. A switch statement is not a terrible way to go when selecting the class to create. Then the payload is given to the message class's deserialize method. That's all.

#5092744 Stick with C++ or venture into C#?

Posted by smr on 09 September 2013 - 10:17 AM

I would recommend using C# with one warning: Have a plan. If you know ahead of time you know what you're going to do, you'll be able to make the decision to use C++ in those narrow range of circumstances when C# would not be suitable. It sucks to have hundreds of hours into something then realize you're at a dead end.


* C# is inconvenient on your target platform: iOS, Android, Blackberry

* Some third-party library does not support .NET, or some third party tool you want to use produces files in a proprietary format, and the libraries to read the format are not available to C#.

* C# performance, for example, you need very tight control over memory allocations, layout, etc.


You can get around each of these issues if you just have to use C#, and the performance is not likely to be a bottleneck except in the most demanding of games.

#5091711 Why are static variables bad?

Posted by smr on 04 September 2013 - 11:31 PM


#5091654 Why are static variables bad?

Posted by smr on 04 September 2013 - 03:58 PM

Personally I like to make objects that can always be default constructed and design paramaters as simply ways to set specific properties on creation. I'm not really a fan of objects that do complicated behavior just by being created.


Just because you are passing dependencies to the constructor does not mean that the constructor is doing anything more than storing a reference to those dependencies. It doesn't have to use them or access them in any way.




The problem with that is you're assuming it is an object that is useless without its full set of data and useful with it. Which in reality is not the case most of the time, especially concerning games. A good example might be a game entity, say you wanted to create it and set certain data about it and then add it to a world. Should it ask for a world and add itself in the constructor? Well it could but that means you have to add it to the world the second you create it, it also means you are essentially required to pass all of the information the object needs into the constructor and to also assume it is all correct.


The constructor is not the only place to inject dependencies, it's just a convenient and fail-safe one. Obviously if you need a parameterless constructor, or otherwise need to construct an object before you have a reference to its dependencies, or that dependency is not available within the scope that it is being constructed, then you'll have to use another means. Personally, in the case of game objects, I typically require the "world" reference as an argument to any methods that depend on it, likewise for any other dependencies. The parameterless constructor is needed for deserialization and/or constructing entities to add components to via configuration files or using some sort of fluent interface.

#5091452 Why are static variables bad?

Posted by smr on 03 September 2013 - 06:39 PM


and every constructor will have like 5 arguments


And if you do need to pass in five dependencies to one constructor (which is extremely unlikely if you design your classes properly), you can always wrap them in an instance of a FooContext class.



There's nothing wrong with a constructor having five arguments per se, if that class has five dependencies and/or required parameters. If your class genuinely has five dependencies, passing them to the constructor is better than the alternative of global variables. If your class feels like it has too many dependencies, maybe it really does and needs refactoring. That's going to be a judgement call based on the specific situation.

#5091397 Why are static variables bad?

Posted by smr on 03 September 2013 - 01:47 PM

Right. Static variables are bad when used incorrectly. Making static variables globally accessible invites the programmer to access that variable at any point in the code without any clear indication from outside that code that there is a dependency on that global variable. This makes it impossible to test or reuse software components as individual units. Incorrectly used global static variables also threaten to wreak havoc all over your codebase whenever you attempt to change the way the variable is used or what it means. The alternative to using global static variables is usually to implement form of dependency injection so that any unit that depends on the variable will have its dependency clearly and explicitly indicated. Often this also has the benefit of compile-time error checking -- if you forget to pass that variable to your constructor or method that depends on it, then it won't compile.


Another potential drawback to using bare statics is that they are not thread safe. Any thread can access and modify the static without any sort of locking.

#5083956 Event Handlers In C

Posted by smr on 07 August 2013 - 02:52 PM

I would omit the name field for the event listeners. The only reason I can think that you'd want to have names attached to your event callbacks is so that you can identify them later for removal or to ensure that the same callback isn't registered for the same event more than once. Since this is C it's easy enough just to use the callback's address as the identifier. This will save some space in each callback, as well as spare you from having to work with strings (which in C, sucks pretty hard).

#5081687 Oh my glorious code!

Posted by smr on 30 July 2013 - 06:57 AM

I don't have any code from when I was that age, as around the age of 14 or so, an HDD crash had wiped out everything I had before this point


Same, only my HDD was random girly-pop cassette tapes I "found" somewhere in the vicinity of my sister's tape player...

#5078062 Emo framework for mobile games?

Posted by smr on 16 July 2013 - 12:17 AM

Dude, you realize that pygame's core is written on c++ right? Same is truth for most part of kivy (some of its classes are still use python).
I hardly see how its performance can be a problem on the logic of the game (it will be an incredible small performance lost if you consider the cost of rendering), and even if it is, use cython to optimize your code and you reach the C speed.
I recomend reading this: http://docs.cython.org/src/quickstart/cythonize.html


Have you written anything using pygame? Pygame is not a game engine where most of the work is coded in high performance C code. There is no "render my scene and call these functions when stuff happens." Pygame does not have a "render_mesh" function. There is no "pathfind_astar" function there for you. There isn't even a "render my 2D scrolling tile map" function. You'll be coding these tight loops in python, and they will be slow because python is slow. On top of that, most of your calls to pygame APIs will need to cross the python to native ABI bridge. Marshaling these calls from python is slow, slow, slow. Each primitive you draw, each OpenGL call, every call to blit a surface will incur significant overhead. Not to mention many mobile devices have as high and in some cases higher screen resolutions than a typical desktop, which introduces even more overhead because you will probably be doing more blitting and drawing of primitives. AND further again, using high resolution images and textures, meaning more memory pressure, meaning ultimately to even more GC stutter.

So, dude. I know all about pygame. I use it. I love it. It's not for anything other than the
simplest of mobile games.