Sunday, March 16, 2014

Game A Week - #2 - Asteroid Spacewar?

Here is how the past week went: (Play the game here!)

Monday
I decided that since the first Game A Week (GAW) game (Pong) only had 2D shapes with translation, then the next game should have 2D shapes with translation and rotation.  In keeping with the theme of remaking old games, I chose to create a clone of Spacewar next.  I was only able to set up the initial project in Dart, nothing else.

Tuesday
I created a triangle shaped GameObject and wrote up a simple Ship component that I assigned it.  This component uses keyboard input to rotate the triangle left and right and move the triangle forward and backward.  I also changed the background color to black (whoa!).

Wednesday
I changed the ship to move via forces applied to it instead of just changing its position.

Thursday
No progress.  I went to a concert dinner and drinks. (We discovered the concert was cancelled after arriving at the venue.)

Friday
No progress. I went to a birthday party.

Saturday
I set it up so that the ship warps to the opposite screen edge when it reaches one screen edge.  I added in the ability to fire bullets that also warp around. I made a tough decision that since I had not worked on the game very much during the week, that I had to trim down features.  I knew I wouldn't have time to put in multiplayer, random ship warping, etc. I decided to make it a more simplistic game similar to Asteroids. I implemented an AsteroidManager component that randomly spawns asteroids that fly around the screen.

Sunday
I added in collision detection between the ship, bullets, and asteroids.  I set up scoring as well as game over conditions.  I added in the ability to render the ship with color (everything previously could only render in white).  I tweaked the random creation of asteroids and limited the maximum number of both bullets and asteroids in order to avoid the game being a big mess of objects.

Play the game here!

Final Thoughts
I had even less time this week to work on the game than last week.  I believe I spent about a total of 12 hours on it this week.

Here were the features I had hoped to get in that I had to scrap:
Sounds - Again, sounds for everything didn't make it in.
Planets - Planets with gravity that affected the acceleration/velocity of all objects
Multiplayer - Two ships battling against one another.

I'm really hoping that I'll have more time in the next two weeks for future GAWs due to certain circumstances in my life that I'll explain later.

NOTE: I realized after publishing the game to my server that my changes to some shared shaders broke last week's Pong game.  Nothing is rendering anymore.  I'll need to figure out what's going on with that and fix it (no other game code will be changed except that). NOW FIXED!

Sunday, March 9, 2014

Game A Week - #1 - Pong

I've read about many different indie developers making a game a week, but it was this recent article on Gamasutra that really sold me on the idea.  I decided that I would try to do it myself, using it to strengthen my game design skills as well beefing up my Dart knowledge.

I was tempted to tackle this challenge using Unity, as I have vast knowledge of the ins and outs of that engine, but in the end I decided it would be more educational for me to use something I was not very familiar with.  I figured it would force me to think outside the box to come up with solutions.

Here is how the past week went: (Play the game here!)

Monday
The first issue was figuring out what game to make.  I assumed that making a clone would be best to start off with, and a very simple one at that.  Pong seemed appropriate for many different reasons.

Once I had chosen the game,  I had to set up the basic Dart project structure.  This was rather difficult just because of the Dart Editor.  (I had decided to use the Dart Editor instead of Cloud 9 while I learn the ins and outs of Dart.)  Dart would constantly take up massive amounts of RAM (2.3 GB) and CPU (87%), which would cause it to come to a crawl and even crash repeatedly on my PC.

I also had quite a bit of difficulty trying to load assets in Dart.  I'm developing the base engine as a Dart lib, so I first tried putting the shader files directly in the lib folder.  I couldn't figure out any way to actually access them at run-time, so I tried putting them in the asset folder, since that is what is described here.  That also didn't work since it requires pub build which apparently doesn't work on Dart libs.  So, I ended up simply putting them in the example folder.  It's not ideal, but it works for the present.

I eventually figured out how to make the Dart Editor stable.  I deleted all of the metadata under C:/Users/[user]/DartEditor and then deleted all of the packages folders in my project, since they are generated by Dart anyway.  I rebooted the Dart Editor and pulled in my project.  It ran smoothly after that.

I didn't get as far as I had planned since I was battling against the Dart Editor most of  the time.  I did end up with a square and triangle rendering via WebGL in Dart using my own custom shader loading.

Tuesday
The next major part to implement was an actual game loop instead of having one single Render call.  I set up requestAnimationFrame to achieve this, which was relatively straight-forward.  It currently calls both Update and Render at the same framerate.  I may change this in the future, since most engines/APIs have Update called much more often than Render, but it works fine for me now.

I then created a GameObject base class as well as Renderer and Transform components that can be attached to GameObjects.  I updated the square and triangle test from Monday to use these new structures which greatly simplified the set up code.

A small tweak was made so that the WebGL rendering context (Canvas) will be automatically resized along with the browser window.

It doesn't really look like a productive day, but I actually accomplished a lot by putting in those base components.  It should make all future work much easier.

Wednesday
I didn't get much time to work on the game due to other things in life, but I did get some important pieces in. I created a Camera component to help alleviate the hassle of dealing with projection and view matrices all the time.  I created a Scene manager to manage GameObjects and to automatically call their Update and Render methods.  I also created a very simple Color class that acts as a simple wrapper around Vector4 to provide static properties to commonly used colors.  The square and triangle test is now only a few lines of code to set up.

Thursday
It was another short day for me, yet very productive.  I implemented Keyboard class to handle all keyboard input.  I created a Paddle component that uses the keyboard to move up and down. I created a Ball component that moves across the screen and detects collision with the screen edges and the paddles.

Friday
I didn't even touch Pong on Friday because I went out for pizza and beer with my girlfriend. I don't want to sacrifice my social life for the sake of a game a week.

Saturday
I spent most of the day going for a long bike-ride.  I tried fixing some issues, which was mainly fruitless.  I tried forcing the canvas to have focus as soon as the webpage loads so that it immediately can accept keyboard input.  It works most of the time, however it doesn't work when the browser is first loaded, which is quite common when debugging using the Dart Editor.  I tried fixing some wonky collision behavior between the ball and paddle.  I made it a little better, but it's still nowhere near perfect.  I also added in simple scaling to the Transform component to allow easily re-scaling the paddles.  It works well right now for axis-aligned 2D shapes, but it may have to be re-visited in the future to be more robust.  Also, scaling currently only scales the rendering mesh, not the collider mesh.

Sunday
I spent the afternoon at a friend's house playing various board games.  I set up a scoring system with normal HTML used for displaying the score.  I implemented a crude AI system so that you are playing against the computer.  This brought to light a big bug with the collision system.  I had to put in a hack to alleviate that.  I also added in a random element to the ball velocity after a player scores.  I then adjusted collision between the ball & paddles with the screen edges.  Finally, I deployed the game to my server.

Play the game here!

Final Thoughts
I was surprised by how little time I actually had put into the game over the past week.  It is an incredibly difficult task balancing my time between my full time job, my bike-riding, my girlfriend, my friends, etc.  I had hoped to accomplish much, much more.

I have an entire list of features I had hoped to put in, including:
Networking - Allow multiple players across various web browsers
Different Paddle Shapes - Not just | shapes, but < and > and curved surfaces
Increasing Speeds - Make the ball go faster as the score increased
Varying Angles - Make the angles of the ball not always 90 degree bounces
Sound - Simplistic sounds to indicate when the ball hits a paddle
Circle Ball - Use an actual circle mesh for the ball instead of a square
Scale Properly - Currently the game doesn't scale the collision zones with the visible window

In the end, I did get a working (albeit simplistic) version of Pong up and running via Dart and WebGL.  I suppose that's as good of a first Game A Week as I can get.  I'm already looking forward to the next game! (Whatever it may be.)

Sunday, February 23, 2014

Dart on Cloud 9 IDE

Although I haven't talked much about it, I've been doing quite a bit of JavaScript & HTML development in my free-time for the past year.  I had done web development for several years before that, but it was very basic and involved simply editing files via Notepad and uploading them to my server.  This workflow was very inefficient for me and made me hesitant to continue development since it was so cumbersome.  I sought out a solution for being able to develop directly in a web browser using a browser-based IDE.

I discovered that there were several solutions, each at various levels of features, stability, and ease of use.  I tried KodingOrion, and Cloud 9.  Cloud 9 stood out as the best of the bunch with a very friendly layout, tons of supported languages, a variety of software pre-installed (Java, Python, Git, etc), and a full Linux terminal to use.

While I was able to write a powerful HTML5 music player and lay down a nice foundation for a WebGL engine all using JavaScript & HTML, it was rather painful for me.  JavaScript is not a very fun or easy language to use.  I found I was constantly fighting against the language to build even the simplest of structures.

I had briefly looked at Dart a year ago and decided that I would rather write "pure" JavaScript instead of writing in a higher level language that simply compiled down to JavaScript.  However, after looking at various benchmarks that compared Dart compiled JavaScript with native JavaScript, it made me reconsider my decision.  Another big push was from one of my co-workers who was writing a simple WebGL game using Dart.  We were able to sit down and compare Dart and JavaScript code side by side to see similarities and differences.  That convinced me to install the Dart IDE and give it a whirl.  There are some odd quirks to it since it does get compiled down to JavaScript, but for the most part it felt like C# or Java, which is great for me (10 years of C# development experience).

However, switching to Dart means that I have to resort to the old style of editing code on a specific machine and then uploading it to my server over and over.  I would prefer to use a web IDE like Cloud 9.  While Cloud 9 supports syntax highlighting for Dart, it doesn't provide the Dart VM or any way to compile the Dart code to JavaScript.

Since Cloud 9 is simply running Red Hat Enterprise Linux (RHEL), I decided to import the Dart SDK for Linux directly into a new workspace.  Unfortunately, I immediately ran into a problem.  I couldn't run the Dart VM because the binary had been compiled using GNU C Library (glibc) version 2.15.  In fact, Google uses Ubuntu 12.04 "Precise Pangolin" to compile Dart which uses glibc 2.15.  It turns out that the version of Red Hat on Cloud 9 (RHEL 6.5) only has glibc version 2.12.

I tried three different options to try and get Dart working on Cloud 9.

1) Compile Dart in a virtual machine
I downloaded Virtual Box and the latest 64-bit version of Ubuntu (13.10).  Unfortunately, Virtual Box doesn't support 64-bit OSs on my machine because it apparently doesn't have some visualization enhancements. Not only that, but I also found out that Ubuntu 13.10 uses an even higher version of glibc (2.17).

2) Compile Dart directly in Cloud 9
I figured since Cloud 9 supports Java, C, Python, Git, Subversion, etc I would just try to pull in the source directly into a Cloud 9 workspace and compile it there, using this as a guide.  I spent massive amounts of time trying to get this to work, but alas I was not successful.  I could list all of the things I tried, but in the end it simply did not work.  Whenever I would try to compile, the compiler would crash trying to compile SQLite.  I believe it has something to do with the version of the compiler (Cloud 9 has GCC v4.4.7 and Dart apparently needs 4.6.0).

3) Use a patched Dart SDK
Some people were having very similar issues to me when trying to use Dart on CentOS.  One guy built a patch that would pull in the dependencies directly from the Ubuntu repo and put them alongside the Dart SDK.  This caused all sorts of bad things to happen such as random files getting locked by Cloud 9 itself and random seg faults.

So ... I decided to go back to step 1

1 - Again) Compile Dart in a virtual machine
I downloaded the 32-bit Ubuntu 10.04, which uses glibc 2.11, and installed it in Virtual Box.  I followed this guide in order to get the latest Dart source code and build the SDK.  I then zipped up the built Dart SDK, uploaded it via FTP to my server, and then pulled it back down onto my Windows machine.  I extracted the SDK, and then uploaded it to Cloud 9.  I did have to force all of the binaries to have executable permissions, since Cloud 9 doesn't give them it by default.

I then uploaded the default "Hello World" text reversal Dart project, and wrote simple Node.js wrappers around dart2js and pub to make them easier to access.  I now have Dart compiling and running on Cloud 9!

Let me know if you have any questions or want examples/details of anything.




Thursday, December 12, 2013

Breaking Radio Silence!

Boy have things been busy for me!  I'm now going to do something rare and dive into more detail into my personal life, so feel free to skip this entire post if you want development related information.

Since my last post, I've moved twice and changed jobs.  In August and September 2012, my previous employer's parent company had tasked us with the simultaneous development of four games in order to present them at a big expo in Las Vegas.  For a team of 12 people, this was quite a task, but we were successful and were all quite happy to see the games on the show floor in October 2012.

We returned home in high spirits and full of new ideas to implement.  There was a meeting scheduled with our parent company just days after we got back.  We all thought it would be congratulatory and a discussion of future projects.  Instead, they announced that our entire studio was being laid off and we had three hours to gather our things and leave.  Being the first time I've ever been laid off, it was quite shocking to me.

I immediately began searching everywhere for a new job: San Francisco, Sacramento, Salt Lake City, Montreal, Orlando, etc.  I ended up accepting a position in Reno for a small-ish casino game developer.  I'm basically the resident "Unity expert" and I help guide the best practices in it's use (reduce memory usage, improve artist workflow, etc). I also help plan and develop Unity tools and template projects as well.

I decided to move to be closer to the new office.  Plus, I figured it was finally time for me to move out of an apartment into a house.  That involved not only moving all of my stuff, but also getting much more furniture to fill the house.  One of my major intentions of moving into a house was to get a puppy, but it turned out I was misinformed and my landlord didn't allow dogs. So, I had to move again to a house that really did allow dogs.  I now have a Chocolate Labradoodle puppy named Fenrir.

I've also been occupied with developing a relationship with a fantastic woman, but that's all I'll say about that, since that is a little too personal.

So, although life has been quite busy the past several months, it has also been relatively good!

I've been tinkering around with Unity 4.x as well as testing out various web IDEs for doing WebGL development.  The 2D workflow in Unity 4.3 looks fantastic and I want to play around with it more.

Oh, and I also got braces on my teeth since my last post.  So I'm one of those weird adults with a brace-face.

I'll probably be looking into actually updating my assets on the Unity Asset Store sometime soon.

Monday, July 23, 2012

Unity GPU Noise 1.3 Released!

As you can tell from the title, I've been able to release several updates for GPU Noise since my last post.

I borrowed a MacBook from one of my friends and installed Unity on it.  That allowed me to quickly port all of the noise functions to GLSL and ensure they all worked on Mac.  However, I was still having issues with the noise functions on my Android devices.  Unity on Android is actually incredibly unhelpful in this regard.  It doesn't report any errors or anything. The shader simply fails and runs a fallback shader.

I decided to create a WebGL test page using the same GLSL code since WebGL uses OpenGL ES 2.0 (the same as mobile devices).  I quickly found out (and remembered, as I've posted about this in the past) that OpenGL ES doesn't allow variables in for loop expressions.  It must be a constant expression (i.e. loop a fixed number of times). I made a mobile port of my GLSL noise that forced all summation functions (fBm, Turbulence, and Ridged) to loop 8 times.  Even though this changed allowed the code to work properly in WebGL, it was still not working on Android.

I then took a different direction and tried writing a straight Java test app for Android.  I found out there is a major bug where Android won't report the shader compilation errors.  It just gives you an empty string.  Not very helpful.  I managed to get the shader to compile, but I ran into more OpenGL issues due to mismatched vertex attributes.  I cast aside the example in frustration.

Someone who purchased a copy of GPU Noise let me know that Xcode on Mac actually reports shader compilation errors, so I begged a coworker of mine who has a Mac, Unity, and an iOS developer license to give it a try.  As soon as he deployed it to his iPad, we saw the error that has been eluding me this entire time.  There was a "Uniform precision mismatch" with some of my variables.  I did some investigation and found out that vertex shaders in GLSL default to high precision while pixel shaders default to medium.  I hard coded my vertex shaders to use medium precision and now almost all of my functions work on Android!  I say almost because all of the Voronoi 3D Displacement functions seem to peg out the CPU (as before) and cause the device to freeze and crash.  I think they're just too resource intensive to use on current mobile devices (they work on Windows and Mac just fine).  At least the 2D Animated Voronoi functions all work on Android.

Related to an earlier post, I still need to figure out why a Tegra 3 sucks so much.  It's not just speed, but also the rendering quality.  Here are a few comparisons for example.

EVO 3D

Transformer Prime

EVO 3D

Transformer Prime

As you can see, the Transformer Prime looks horrendous!  I'm not sure what's causing such terrible visual artifacts.  Hopefully someone online has an idea.

Until next time...

Thursday, June 28, 2012

Unity GPU Noise 1.0 Released!

GPU Noise has finally been released on the Unity Asset Store!  Check it out here!

As you can tell from all of the past posts, this has been a long road.  It's still not perfect though.  It works great on Windows, but the reviewers let me know that it has some issues on Macs.  I borrowed my friend's Mac for a little bit and found out that the issue is most likely due to the cross compiler that Unity uses to convert Cg code into GLSL. (It was creating multiple variables with the same name.)

I decided to directly port the Cg code to GLSL, but it's been a rough process since the Windows version of Unity doesn't compile GLSL at all.  This means that you don't get any errors or feedback at all to let you know if you wrote some code incorrectly.  I had to write code, deploy to my Android phone, see if it works, and repeat.  Over and over and over.  Painful.  I'm thinking about picking up a cheap Mac (gasp!) just to have something that can compile GLSL code and give me feedback.  I'm hoping porting to GLSL fixes the problems on Mac, but I have no way to know for certain until I actually do it.

As usual, I'll be tracking my progress here.

Friday, June 22, 2012

Unity GPU Noise (Part 5)

And somehow 9 months have passed...

To be honest, I had a lot going on in my life since my last post.  My development laptop got stolen, my work laptop's hard drive failed, and other, more personal, things happened, which I won't get into.  As a result of the theft, I lost some of my work.  Not too much, just a week or two, but enough to make me unmotivated to return to my project and do the same work again.

About a week ago, I decided to finally dive back into it all.  I installed the latest Unity on my desktop and dusted off my old USB flash drive with the old copy of GPU Noise on it.  I decided to redo almost everything in the project to base it off of the texture-less implementations of noise in order to make it as easy and cross-platform as possible to implement in Unity (and hand off to other developers).

It was pretty smooth going, for the most part.  Based on my prior experience, I knew what I was doing.  The only big problem I ran into was trying to port mod from GLSL over to Cg.  I first used fmod in Cg, but that made the results all messed up.  I finally found this answer that explains the problem and how to fix it.  Once I implemented my own mod function in the same manner as GLSL's, everything was fine again.

Regarding the Android front, I'm not sure if it was something that got fixed in the Cg compiler between Unity versions, but all of my noise functions seemed to run on Android, for the most part.  The only issue I ran into is when I tried doing the 3D Voronoi displacement, the functions consumed too much processing and crashed the device.  This is because the displacement example has to call the function twice, which is a lot of processing.

Another Android "issue" I had was the performance of my devices.  I have an HTC EVO 3D and an ASUS Transformer Prime.  My EVO got about 47 FPS running the simple Perlin displacement.  I assumed the Transformer Prime would do better, but it only got 9 FPS.  Apparently the Adreno 220 outperforms the Tegra 3.  I ran some other benchmarks which came to the same conclusion.  I even looked at the Unity SystemInfo objects on both devices and I was really surprised to see the that Transformer Prime only has 61 MB of video memory while the EVO 3D has 216 MB.  I was greatly disappointed to see how poorly my Tegra 3 tablet performed.  I'll continue to investigate the issue in order to see if there's something I can do to improve its performance.

Just tonight I finally submitted my GPU Noise project to the Unity Asset Store.  If all goes well, it should be appearing on the store in a week or less.  Here's hoping!

Check out the latest demo!

Until next time!