Sunday, March 28, 2010

The path to JavaScript

When I first started web game development last millennium, the landscape was quite a bit different. Java had just come out and was being pushed as the next-best thing in web development. While there are a lot of programmers who hate Java with a passion, a large chunk of my savings account is the result of third party work I have done using that language. At the time, Netscape adopted Java as the way to make the internet more interactive and even altered the browser scripting language they were working on renaming it JavaScript. Sadly, largely due to a battle between Microsoft and Sun, use of Java in browsers never became the dominate force it should have.  Java became more of a server side or back-end language with a lot of businesses adopting it.

On the browser side, Flash seemed to grow. This was largely because Flash was flashy. Flash was designed to be a vector animation program but added scripting and in Flash 5 an ECMAScript based scripting language called ActionScript. ECMAScript is the name given to the standard for JavaScript. Purists are free to correct my oversimplification of this but I am a programmer not a bureaucrat. Still, the scripting language that Flash uses is essentially the same as JavaScript.

I have dabbled with JavaScript in the past, but have never attempted to create a serious project in it. Still, with my ActionScript background, I figured it should be a piece of cake. Syntax-wise I was correct. DOM-wise, I couldn't have been more wrong. The DOM is the Document Object Model. It is essentially the API for browser-based JavaScript. I could not find an Java-Doc style guide to the DOM, which may be part of my frustration.  The part that really annoys me is how different the different browsers are at supporting it. Code that works great in Firefox and Safari does not run in IE. This means that I have to test a lot more than I would like which is why I think it may be a while before HTML5 replaces Rich Internet Applications written in Flash, Java, or other  RIA platforms. This is really too bad as I personally think open standards are better then proprietary platforms.

Still, next month will be my first JavaScript game. Working in it has certainly been interesting. One thing I will be looking into is better JavaScript libraries that make it easier to write cross-browser code. There are a lot of them out there, though the two I keep hearing about are Dojo and jQuery. I am not sure how necessary this will be as most of my stuff will be using the canvas for the user interface. That said, Flash CS5 is probably still in my future but I am going to slowly try to move to JavaScript for my client side programming.

Monday, March 22, 2010

Negotiations are a gamble

JavaScript and the HTML 5 canvas are the things that were going to be discussed yesterday but too many other things prevented me from writing the post. I wrote an interesting email today. The contents of that email was "I did not authorise or send any press release as the project was still being negotiated and is currently in an impasse. I assume that this press release was sent by my potential client prematurely, for which I apologise." Perhaps it is best that my "weekly" post was delayed as I have a different topic now.

There is a song about poker that states "you have to know when to walk away, and know when to run." This applies to negotiating as well. There were many warning signs that should have been picked up on, but I don't enter negotiations very often so never acted on them. The problem is that the project sounded rather interesting and if successful would have really given a boost to Blazing Games. When there were more and more misunderstandings, I should have walked away. The problem appears that I came at the project from a web developers perspective while the potential client was looking at the project through a commercial game perspective. Our assumptions simply did not match.

While it is possible that things could have been worked out, this morning I found some strange emails about a press release that I did not send. Worse, the emails were to my private email address that I rarely give out and would never use for a Blazing Games related press release if I ever made a press release.  The press release was about the proposed game. It is possible that this was a mistake and that whoever issued the press release did so by mistake. The cynical side of me, which sadly is right far too often, thinks other things. Too many false assumptions when combined with this premature announcement clearly are telling me it is time to run.

Sadly, the only time negotiations are worth-while is when they end in a deal. The rest of the time they just waist time. Time is my most precious resource so it is truly a sad day today. At least Penny Arcade cheered me up.

Sunday, March 14, 2010

Canvassing HTML 5

As I am sure most people who read this already know, HTML is the file format that Internet browsers use. While it is certainly possible to create a web site in php, perl, python, jsp, or a myriad of other server-side languages; these languages ultimately send an HTML file to the browser. HTML 5 is currently a draft standard, which means it is still being developed. In fact, it probably won't be an official standard until 2012 so my starting to use HTML 5 might seem strange. I had planned to stick with Flash/Flex which requires a proprietary plug-in to work but is very widespread. Apple, Google, Opera, and Mozilla are pushing for the new standard and have support for many of the features already. Notice that Microsoft is absent from this list. While I personally don't like Internet Explorer, it is very commonly used. Thankfully, a lot of the HTML 5 features that are not supported directly by Microsoft have had open source implementations so it is possible to use these features. When I discovered ExplorerCanvas (http://excanvas.sourceforge.net/) last year, I figured it was time to start playing with HTML 5, or at least the canvas portion of the upcoming standard.

I remember how excited I was going to Star Wars Episode 1. I had seen the other Star Wars movies many times and was thrilled that a new Star Wars movie was finally coming out. While Episode 1 was not as bad as many old-school Star Wars fans claim, it certainly did not meet my overly-high expectations. This is the way I feel about the canvas tag. For general purpose drawing, it is really good. From a game developers perspective, however, it is lacking. The biggest flaw is there does not appear to be double buffering support. While it is possible to create off-screen buffers of pixels which let you manipulate each pixel individually, these buffers are glorified arrays and don't have any advanced drawing support. In most animated applications you do not want people seeing the frame being drawn which is why double buffering is used. Still, there are a number of ways around this problem so all is not lost.

I have not played around with this idea,  but one way to emulate a double buffer would be to simply have a hidden canvas that all the drawing is done to and then the contents of that canvas get copied over to the visible canvas.  I have heard of tricks like this being used before, and it would be a simple solution if it can be implemented in a cross-browser compatible way. Dirty rectangle algorithms could also be used, especially since there is really good clipping support built into the canvas class. I suppose writing some low level per-pixel drawing methods and doing the drawing inside the ImageData objects would work, but JavaScript is really slow so I can't see this being a good solution unless your game already has to do a lot of per-pixel work. A raycaster come to my mind immediately. Sadly, I suspect that flicker will be a part of a lot of future HTML 5 games, but computers are very fast now so lets hope this is one thing I am proven wrong about.

Sunday, March 7, 2010

Programming, the Coming of Language

(Continued from Programming, the Early Years)

The thought was that if the languages would be more human like so it would be easy for people to create software then there would be no need for programmers. The earliest programming languages were created to allow scientists and researchers the ability to write programs themselves which is why FORTRAN is considered to be the first high-level programming language. The idea here being that  The programs in these higher level languages would be run through a tool called a compiler which either converted the program into assembly language (which would then have to be ran through an assembler) or straight into machine language.

While higher level languages made it easier to create programs, learning how to program was still a chore. The fact that the programs were ran in batches so there was a long delay between writing code and seeing the results was the biggest culprit. Computers, thankfully, continued to grow in power to the point that there were a lot of waisted computer cycles. To better utilize the hardware, time-sharing systems and terminals started appearing. This lead to the obvious idea of having programming languages that were interactive in nature. By interpreting the code instead of compiling the code it was possible to write programs in real time.  The downside to interpreters were that they were significantly slower than compilers.

Another issue that was becoming bothersome was the fact that every machine had a different machine language. Sure, you could simply write programs in high level languages and compile it for the different computers that the program had to be ran on, but different compilers for the same language would compile the code differently so idiosyncrasies were common place. The term for moving code from one computer to another is porting. The fact that a term was created to describe this problem (which still persists today) should tell you that it was not a trivial problem. UCSD Pascal solved this problem by compiling code to a virtual p-machine language. The computer would then interpret this virtual p-code. Because p-code was essentially machine language, the computer could interpret this code much faster than an interpreted language could be ran. Still, it was slower than code compiled for a particular machine. When micro-computers started taking off, the speed difference became a big factor in commercial software sales.

While it seemed that compiled code won, computers continued to grow faster to the point where they were more than fast enough to accomplish most common tasks. At the same time, the internet  started taking off. Sites wanted to be more dynamic but had to be not only cross-platform but cross-browser compatible. Both interpreters (JavaScript) and virtual machines (Java) were used to accomplish this. To make the virtual machine fast enough, a new technique called Just-In-Time compiling was developed. The idea here is that the virtual machine code is compiled into native machine language as it is ran so code will run much faster.

The concept of a virtual machine running on the browser seemed to me to be the best solution. Sadly, for a variety of reasons Java never became the browser language of choice but instead ended up largely on the server. Flash is currently the virtual machine of choice for browser programming, but JavaScript is probably the most common choice for web development. The only thing holding JavaScript back is the lack of some of the Rich Internet Application features, but HTML 5 is pretty much solving those issues. It will be a few years before HTML 5 becomes the standard, but with Google, Apple, and Mozilla pushing for the standard it is possible to take advantage of a lot of HTML 5s features right now.

So we have gone from writing code in machine language to compiling the code into machine language to running the code in an interpreter. What is really interesting is that changes in hardware is what drove programming evolution. Computers are now so fast and have so much memory that programmers no longer need to concern themselves with writing efficient code. What matters now is that the code that is written is finished quickly. Sure, many programmers want to write efficient code but they only have to write efficient code in the increasingly rare case where the program runs too slow. What is worse is the fact that programming has moved further away from machine language that there are many programmers who don't really understand what the computer is actually doing. That, however, is a subject for another day.

Sunday, February 28, 2010

Making Space Station Defence

The Space Station Defence game that has just been posted on Blazing Games is not the game that I planned to release in March. I was actually planning on releasing another episode of Dozen Days of Words, possibly both of the final episodes. After just starting work on episode 11, I came up with a concept for an arcade game. I figured I would take a few hours and build a quick prototype of this game. While assembling the prototype, I realized that the game would simply not be fun. Before dropping my prototype, I went for a walk as in the Okanagan Valley we are having an unusually warm winter with all our snow melted already. While some people may blame our warm weather on global warming, I know that the real reason is because I bought a bunch of exercise games for my Wii. While I have lost a lot of weight, I still have a way to go. My own long history of dieting has taught me that the only way I can lose weight and keep it off is by exercising. Now that I have audiobooks and podcasts to listen to while walking, I have drastically increased the amount of exercise I do. While this might not seem to have anything to do with game development, walking helps my mind sort through it's myriad of thoughts. A simple change turned a dead prototype into a released game.

The original concept was a shield game. The player would have a shield around their space station. This shield would slowly recover but could be rotated. As the player took damage, they would simply rotate the shield. In theory this sounds interesting. The problem is that actual game-play isn't much fun.

During my walk, I came up with two different solutions. The first would be to have a non-destructible shield but one that only protected a small portion of the space station. The other method was to slow down shield recharging and give the player missiles to shoot back. As the later idea sounded more fun I went with that. The game lasted too long with recharging shields, so in fine tuning I removed that feature. As I already had three different shield levels, I also opted to have three different difficulty levels. I think another pass or two would have been nice, but I simply have not had the time.

Does this mean that the eleventh episode of Dozen Days of Words is going to be released in April? To be honest, I don't know. I do want to start experimenting with HTML5 so I hope to have a game that takes advantage of the canvas element. This feature is already supported by most browsers, and there is a JavaScript library that adds canvas support to Internet Explorer. Microsoft seems to be exceedingly slow at adding HTML5 features to their browser. I suspect they are trying to shove Silverlight down everyone's throat. HTML5 would make Silverlight mostly irrelevant. To be honest, I am starting on my HTML5 migration much sooner than I ever anticipated largely due to Mozilla, Google and Apple's push for HTML5 features.

Sunday, February 21, 2010

Programming, the Early Years

Efficient code is not as important as it use to be. What is worse is that the situation is getting worse not better. While the vital parts of a program are likely to be written efficiently, a growing percentage of the code is going to be quickly written and probably inefficient. Making this situation even worse is that the code being written is often going to be interpreted or ran on a virtual machine. To understand why this is the case and why things will get worse before they get better one just has to look at how programming has evolved over the years.

The earliest computers were programmed in machine language. In the very early days this was done by re-wiring machine components though this quickly changed to flipping switches and then into punched cards or paper tape. Computers were huge expensive machines so every second of machine time was precious. Programs were often ran in batches meaning that you would submit your cards or tape and wait (sometime days or weeks) to get your results. When you got your results, if there were problems then you would have to re-submit. As computer time was golden, sloppy code was frowned upon. Likewise, because there was a fair amount of time between tests, programmers had plenty of time to make sure their code was well written.

Computer programs were much simpler back then due to the fact that the machines had almost no memory and were slow. Memory in early computers were measured in Kilo-words with the number of bits in a word being machine specific though 18 seemed to be a common number. A gigabyte is 1,048,576 kilobytes or 1,073,741,824 bytes so to think back in terms of kilo-words is scary. Speed was in kilohertz. Yes, a gigahertz is 1,000,000 kilohertz. Still, programming in Machine Language would have been painful work. What most programmers did was write their programs in an English-like format where machine instructions were given simple names such as LOAD, STORE, JUMP. This code was then converted into the numbers that had to be put into the computer.

Hand coding machine language was a big waist of programmer time, but the cost of programmers was a lot less than the machines that were being programmed. I am sure that many early programmers came up with the idea of a tool that would take a human readable form of machine language and converting it into the actual machine language instructions. It wasn 't until the 1950s that such programs started being used. This made programming much more efficient. When a program was written in assembly language, it had to be run through a program called an assembler which converted a human-readable form of machine language into a machine-readable form of machine language. While this added an extra step to the process, the assembly step only had to be done once and the resulting output could then be used any number of times. The assembler resulted in boosted productivity for the programmers.

The cost of computers began to decline while the capabilities continued to grow. This resulted in computers becoming more common. Soon big business and research facilities all wanted to have their own computers. The problem with computers then became the requirement for programmers to write the programs in assembly language (which at this point was starting to be referred to as machine language even though technically speaking there is a difference). If only there was a way for "normal" people to write programs.


This article will continue in a couple of weeks as next week I will be writing about the March release on Blazing Games which is a game that came from a quick protoype I created. This game is an example of how plans for a game can drastically change.

Sunday, February 14, 2010

Is Trivia Trivial?

The enhanced version of history bomb has been posted on Blazing Games. My rant on efficient programming will continue next week, this week I am going to talk a bit about trivia as the game just releases is a type of trivia game.

On the surface, trivia games seem to be something that is easy to create. As someone who has written a fair number of them, some for third parties, my knowledge of the subject is fairly high. Programming a trivia game is in fact very simple. The game logic for a trivia game is in fact trivial to write. The server-side database/score handling and the user interface were what took up the vast majority of time. This makes sense when you think about it as ultimately trivia is just a variation of the simplest of all computer games. That game being the pick-a-number game. The difference is that the numbers are answers and random numbers are used to scramble the potential answers. There is one thing that makes the trivia games on my site different from the third-party games that I have written. For the third-party games I wrote, I didn't have to come up with questions.

Coming up with the questions for a trivia game may sound simple but it is a fairly time-consuming process. First you need to come up with a subject that you think that the people playing the game will be interested in that you also have some knowledge of. Next you have to come up with a question. This would be similar to writing a question for a test, except the question has to fit a particular format. In Trivia Bomb it was a simple multiple-choice question. History Bomb, on the other hand, is a sorted list. I will say that multiple-choice is much easier to come up with questions as one only needs to make sure his or her answer is correct then come up with wrong answers. Sure, it is time consuming, but it is very flexible. Lists requires finding something that has a distinct order to it. Then verifying that order. In some cases, this meant not only researching the subject, but then having to do additional research on each item on the list.

The bright side, though, is that the extended version of History Bomb has no time limit for its development. When the game-in-a-day pressure is removed, researching questions was much more enjoyable though probably even more time consuming. What trivia-question-writers probably don't want you to know is that just diving into a subject to verify facts often leads to much further exploration of a topic. I suppose there is the obvious "looking for other potential questions" excuse.

While coming up with questions is not hard work, it is time consuming work. Still, when creating a trivia game, it is probably best to remember that the questions are going to have to be created (unless you do the low-life thing and steal questions from other people). When I play a trivia game in the future, I am going to remember that each question probably took far longer to create then I will ever spend answering it.