Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Sunday, March 18, 2012

Episode 7 - Coordinates, New Project, PHP Setup

Revised Coordinate System

Ok, so it turned out my coordinate woos from Episode 4 were indeed "woos", it turned out the coordinate system I implemented before was totally impractical. Here is what I do now:
  • I simply provide the render system with a desired virtual resolution (800x480 in my case) for the view
  • The size of all sprites is interpreted relative to this resolution, i.e. a 80x48 bitmap sprite is 1/10th of the view
  • The render engine automatically applies letterboxing and pillarboxing on systems running a different aspect ratio, to prevent stretching
  • The upper left corner of the screen is at (0, 0), because this is the traditional approach I've been comfortable with since the days of the C64. There will be a flexible camera at a later stage, so this is not set in stone.

Letterboxing on an extra wide viewport

Kicked off a New Project.

I'm trying to get into the habit of starting and finishing short, smaller-scoped projects... so after a (fun!) little brainstorm session with Ye Balde Scribe I've set aside Seesaw Kiwi for the moment, and started a Brand New Shiny Project (tm).

The awesome part about this particular project is that it will be shippable at a very early stage, but still leaves room for massive amounts of improvement. Awesome!


Setting up PHP Development - NetBeans, XAMPP


The new project requires a server component. PHP seems the obvious choice for now, simply because it is the easiest/cheapest to setup... I've got more than a couple of Shared Hosting LAMP websites sitting around, doing mostly nothing.

After installing XAMPP, I hit a small hurdle getting Apache to run, because a running TeamViewer service (which I was pretty sure I'd never enabled) hijacked port 80. On a modern Windows 7 developer system it's quite hard to figure out which of the 70-odd running services is the culprit, especially because netstat -ano returned PID 4... which is the System process. Very helpful, netstat.



This being my first experience with XAMPP and the NetBeans IDE, I was a bit disappointed that I had to manually edit php.ini to get the debugger to work (why bundle it with XAMPP but not configure it?). And why do I have to manually edit httpd.conf to get the active NetBeans project running in Apache? Can I have my IDE a bit more Integrated, please? Good news: the debugging experience is really good thus far.

Rant: it's kinda unfunny how windows projects that originate as Cross Platform Open Source never seem to get UAC right. Same with XAMPP: You have to make sure you don´t install it inside Program Files (because it drops read/write config files inside it's install directory, which is a big no-no in Windows-land), and you need to explicitly launch the XAMPP control panel with elevated rights because it needs to manipulate windows services, and doesn't include a manifest of its own.

Oh well, enough complaining, it's free and it works. Hopefully the Mac/Linux users get a bit more love for their respective platform guidelines :-).


Misc

Sunday, March 4, 2012

Episode 6 - Camera controls and exceptions

Implementing camera controls for Board Game Machine

Worked on some camera controls for our upcoming (multi player, multi device) board games simulator Board Game Machine . Control mechanisms demonstrated in the video below:
  • 90 degree spherical (elliptical) rotation of the camera position to view each side of the game board
  • Continuous vertical rotation of the camera position to get the desired view angle onto the board
  • 90 degree camera rolling when the camera is facing straight down

Notice (or rather, please do not notice) how there is a myriad of debugging text on the screen (the video is recorded straight from the dedicated development tool), and how the graphics are still very much in development.

Making Eclipse stop on Null Pointer Exception (and friends)

By default, debugging an exception in your Android application goes something like this:
  1. Watch the IDE stop into an empty page somewhere in the Dalvik code (no source code available unless you installed the full Android sources) with a rather meaningless call stack.
  2. Hit F8 to continue running.
  3. Look at LogCat to find out what was actually wrong. Find the red lines in the log, scroll down until you find the "caused by" line, doubleclick, and finally be transported to the offending line in your code.
I just learned you can force Eclipse to actually behave like a sane IDE by performing the following simple steps:
  1. From the menu, select Run, Add Java Exception Breakpoint
  2. Find NullPointerException (or whatever exception you are debugging)
  3. Verify Suspend On Caught Exceptions is checked. Click OK.
The debugger will now immediately break (suspend) where the exception occurs. Like, you know, every other (proper) debugging environment on the planet. I'm kinda stumped as to why they didn't make this the default debugging behaviour, but at least you can configure it to work properly.


Mobile client for DMSforSharePoint

Since after a fair bit of swearing and cursing I've got SOAP + NTLM up and running now (hurray, detailed blog post on that topic later), ít's time to develop a little prototype of a mobile client for our SharePoint-based DMS, DMSforLegal / DMSforSharePoint. Here is the first screenshot of this work in progress:

 
Misc

- The Android game engine now plays sound & music through some convenient manager objects. This was really easy to get up and running on android (thanks, MediaPlayer and SoundPool!). Still unsure about the best engine design for handling sound effects, but we'll see how it works out.

Sunday, February 26, 2012

Episode 5 - Input/Output

Accelerometer... cool in theory, ok-ish in practice

I'm implementing basic game input control, so I needed simple tilt values. Android supports this through a rather heavy handed interface called SensorManager and a couple of SensorEvents providing you with such information as acceleration forces and geomagnetic field information, from which a rotation matrix can be deduced. Extracting the right column from that rotation matrix will then yield the tilt.

Which is all nice and dandy, but with such an advanced and complex API I'd expect the sensor output to be phenomenal... and it simply isn't.The accuracy and response times are a disappointment. Disclaimer: I am working on the assumption that my Samsung Galaxy SII is representative of most of the hardware that is currently out there.

Ah well, that just means that direct rotational control (anyone remember the paddles on the C64?) is out of the question, so now I've opted for tilt-controlled velocity. Cool.


Android and SOAP ... not so clean

The de facto standard library for handling SOAP in Android is KSoap 2 (I'd advise using the -android branch from the link, as it is actively maintained). And while it is a pretty extensive library (all due respect to the contributors to this the project!), it most definitely lacks in the ways of KISS.

If you come from a .NET background, or any other platform where SOAP is a serious player (we have run our own custom implementation in Delphi), the thing just reeks of a lack of abstraction. If I just want to make a simple remote call, I sure don't want to be instantiating an "envelope" object (really, I don't want to know). On the other hand, if I do care about soap intrinsics, I sure don't want to get the response back as a property of that same envelope... That's just wrong. But enough ranting, it gets the job done.

I more or less hit a roadblock then, as I discovered doing (Windows 2008 compatible) NTLM authentication isn't exactly trivial, and lots of existing Android/Java projects seem to think it's ok to simply drop support for it anyway because it is deprecated (Kerberos is superior anyway, etc). Hello? People living inside a glass box? There are millions and millions of Windows (business!) users on NTLM networks.... I'm sure they wouldn't mind using their android devices to access their stuff.

Oh well, I guess I'll just have to bite the bullet and modify KSoap 2 a bit to hack the necessary support in. Unfortunately, this is all just a side-project, so it might be a while before I get around to it.


Misc

 - Have been tweaking the camera controls of our Board Game Machine project a bit. It's funny how low frame rates (still on the to-do list) can sometimes make it hard to judge whether your implementation is actually correct.

- Added activity switching and a single option screen (input through touch or accelerometer) to the Android game.

- The barebones Android game engine now has automatic texture reloading on surface change. No rocket science, but the textures disappearing was getting kind of annoying.

This is what lost textures look like. It's not pretty.




Saturday, February 18, 2012

Episode 4 - Grinding through a Sprite System Prototype

Coordinate woos

Picking a convenient coordinate system for a 2D game environment turned out to be a bit harder than expected. Working purely pixel-based sounds nice in theory (coming from an ancient C64 / VGA background), until you realize that you are designing things to run on a wild variety of screen dimensions.

So then I tried working with pure abstract floating point coordinates, assigning the sprites a completely free scale, only maintaining their ratio.  As it turns out, this doesn't work as well as in a pure 3D environment: rescaling bitmap-based sprites to arbitrary sizes does not always come out pretty.

I ended up with a hybrid solution where viewport coordinates are based around the ratio-adjusted unit square, but individual sprite size is in pixels. We'll have to see if it holds up once I have to implement real game stuff.


Alpha woos

All my alpha-blended sprites had ugly black edges around the corner. As it turns out, Android's default approach to texture loading (GLUtils.texImage2D) premultiplies the alpha channel.

Fixing the texture loading seems a bit tricky to implement efficiently, but as a workaround I simply changed the rendering blend function into (GL_ONE, GL_ONE_MINUTES_SRC_ALPHA). This might come back to hunt me, as premultiplying alpha kills information in the other channels that might be important when using a texture for other purposes than simple alpha-blended display.
Proper alpha-blended sprites go in...
...weird borders come out!

The final result looks like the screenshot below. Notice how the pixel aspect ratio of the physical phone is different, just pretend the screenshot is in proper 16:9 ratio. Also notice how the graphics are all placeholders, just building the technology here...
These sprites move around. That's kinda the point.

Misc
- Created a local Subversion repository for my Android work-in-progress using TortoiseSVN. Man, I'd almost forgotten how Subversion is cool that way. Considered experimenting with Mercurial in stead, but decided not to shoot myself in the (distributed) foot at this point.
- Replaced the default TortoiseSVN merge/diff tool with WinMerge. Seriously, if you are still on TortoiseMerge, make sure to do the same... cause you are missing out! Make sure to set the WinMerge font to something sensible (like Consolas 10), and you'll never want to go back. The syntax highlighting alone is worth the switch.
- Learned that it is really hard to predict how colors will come out on the Samsung Galaxy SII AMOLED screen. The screen of my little Dell Inspiron Laptop literally pales in comparison.
- Learned that it is rather difficult to get a proper movie recorded from an Android application without dedicated hardware. Might end up recording the actual phone with a camera.

Sunday, February 12, 2012

Episode 3 - A foray into Android-Land

Android is awesome!

After my first baby steps into the Android Tutorials, I now took the next step and managed to deploy a home brew Hello World Android application from Eclipse (ADT) onto my physical Samsung Galaxy SII phone. Things just got real!

Getting this to work involved installing Samsung Kies on the laptop, as it seems the only way to get the correct USB drivers. The hardest part was to actually get access to the Kies download from the extremely "helpful" Samsung website.

The debugging experience on the physical device is great, much more responsive than the emulator. Once in a while I do need to restart Eclipse because the debugger will not connect to the device... but even then I can still run on the device, and logging works fine. All in all, not too bad.

Debugging OpenGL ES 2.0 is not awesome!

I'll be making games on android, and for that I'll need sprites. And for performant (yes, I'm aware that is not a real word) sprites, I'll need OpenGL. According to the Device Dashboard, ES 2.0 is very wide spread amongst current Android devices, so it's a safe bet to require it.

Now, I've spent the last couple of years doing mostly DirectX, and I'd forgotten how poor the debugging experience of OpenGL really is... especially on the android device. First of all, you don't get to use the emulator if you want to use ES2.0. Then, everything fails silently without so much as a return code, so the only way to pin point silly mistakes in the calls is by liberally sprinkling your code with glGetError-based checks... and even then the errors reported are not very informative. How about proper GLSL debugging? When hell freezes over, probably.

After a fair bit of sweating and cursing, finally I got the first textured quad up and running... free drinks for everyone!

Now my fingers are itching to abstract away the big fat pile of OpenGL calls it took to get this far. I am trying to focus on moving forward and stay way from over-engineering, but man... talk about a high barrier to entry for new programmers! No wonder the internet is full of badly copy-pasted malfunctioning code fragments.

Misc
- As usual, the freshly installed GIMP insisted to have a Dutch User Interface... because I use Dutch formatting in the Windows Regional Settings. This annoys me every single time I run a GTK application, that is not how locales are handled in Windows. Please show some respect for my platform, guys! Rather than overriding the locale through a LANG environment parameter (again... not how things are done in a Win32 environment), I simply deleted the NL folder from [GIMP Install Folder]\share\locale. Works like a charm, and this way I'm pretty sure it will not revert to Dutch anytime soon.
- Learned how to take proper Android screenshots using Dalvik Debug Monitor (ddms.bat). Tried to spice them up with a Android Phone Template .PSD, but the end result looked too cheap and cheesy. Pure screenshots it is!