Friday, 3 April 2015

Testing Parse

Before you read what follows, consider that setting up and testing Parse took only 33 minutes. Not bad.
I probably had a break in the middle of that. Or maybe not. So, Parse is definitely worth a look, not hard to use. Your grandma can't set it up, but your 12 year old nephew will figure it out in no time.

Recently I discovered a web service named Parse, which claim to eliminate the need for a web server.
I decided to give it a shot and downloaded their test project.

Really funny how people advertise "easy to use solutions" then proceed to rubbing in your face a broken setup while providing shiny examples of bad practices in how not to implement error handling (aka don't muddle through, don't fail silently).

Parse have a startup guide that shows you how to connect your application to the game server. Apparently they haven't realised that people will head over to the startup guide first thing, to find out whether their service is working for them. Anyway this is how it went for me.

  • Downloaded the sample project. Since they don't say anything about Unity 5 (probably corrected by the time you read this) went with their 4.x project anyway.
  • Updated to U5 without glitch. Yay.
  • Oops, they say I should configure a scene object that doesn't exist (dang, took me a while to realise that this is because Unity creates an empty scene whenever opening a new project. C'mon guys it's much more logical than opening the only scene that's in there, isn't it?)
  • Oh my, there's a lonely DLL in there, what am I doing?
  • Scanned their forums, found a rather depressing entry which, well, somehow pointed at the simple operations (create a blank project, add the required script; yes, it is because it is simple that it's so weird they leave it broken) needed to repair the template project.
  • Nnh. They're asking me to input a .net key (lord knows what this is for) and app ID (shall I input something random)
  • So, of course it didn't work. The part that's really beyond me is that, it wasn't didn't work as in "pressing that test button" doesn't do anything. The test button simply wasn't there. I had to guess that it wasn't there because I wasn't logged into Parse. What were you guys thinking I would be thinking when trying to press a button that wasn't there? Yes, it crossed my mind that their server may be down. Yes, it crossed my mind that maybe these guys went out of business. Feeling good about Parse.
  • I logged in and they ask way way way too much details about your app, pretty please pray tell me now, why do you even need to know? Of course I don't have an app name, ID, user facing name and so forth. My mind is a white, snowy blank slate I'll have you know since I'm just testing the test - sorry, tech. Correspondingly, I did left most of everything blank which fortunately they allow.
  • By then I had an inkling that the .net key should be associated with the app (Duuuh, I'm so smart now am I?). Got hold of the key and retried. And of course it didn't work.
  • In the meantime, note that navigating back to the test / easy setup page from inside your user account page is somewhat roundabout.
  • Heading back to the settings. OMG they got an App ID in there, not just a .net key. This stuff is looking so amazing and slick I feel dizzy.
  • Input the other key. Press the test button (quickly, before it un-appears again).
Not much else to say. Very creepy how the client / initialisation goes MIA when something doesn't work. How am I ever supposed to know what went wrong, before I even noticed it did?

I will let you know whether I'm having fun with parse.

Tuesday, 31 March 2015

Unity 3D: Using curves in inspectors

Today I took a quick jab at using curves in edit mode.
Chances are you already know these since they are commonly used to configure particle effects.

While primarily intended for animation, all you need is declare a parameter of type AnimationCurve and this gives you a nifty interface for parameter mapping. For example you could use it to relating the strength of an attack to resulting damage:

The built-in curve editor. Numbers are grey-on-grey and it 
doesn't seem possible to snap or input numerical values.

Although it isn't immediately obvious, it is possible to edit curves beyond the default [0,0] [1,1] range  (2-fingers gesture or wheel-scroll to zoom in/out).

Tips for working with curves

  • Don't use these where you don't need them. The curve editor isn't good enough to encourage abuse.
  • Bootstrap keyframes with meaningful values to help your designer.

Either/And/Or - How we find bugs

While I was chasing a bug this morning it occurred to me that I was caught in the usual trace/run/redo cycle, a cycle that's time-consuming though not nearly as using breakpoints.

How do programmers find and fix bugs? Setting breakpoints and tracing ultimately do the same thing, and seem to have roughly the same cost:

  • Set a breakpoint (or trace) to find out whether code is traversed or not.
  • Set a breakpoint (or trace) to find the value of something.
As to bugs, they tend to fall in 3 categories:
  1. Something happens, that shouldn't.
  2. Something doesn't happen, but should.
  3. Something happens in the wrong way.
#1, #3 are probably easier since we only need to map the symptom (bug report) to its immediate cause (code fragment) and get a stack trace for it. Finding this kind of bug becomes more time consuming when the target code is traversed very often, since we then have endless false positives.

#2 is often a lot trickier. It is solved by finding out how close we are to executing the desired code fragment so we have to use static analysis and potentially trace / break into all ancestors of a given target.

It seems to me that we could avoid spending so much time into the run/rerun/break/trace cycle.

Accessing local files using Unity 3D

On desktop platforms, you can access the local file system.

Sunday, 22 March 2015

Using Hash values to detect whether the parameters associated with a script have changed

As I am doing work involving procedural content generation, I often want to know whether the parameters associated with a given script have changed.

Although Unity may call Update() or Validate() to indicate that a script may have changed, this causes redundant updates, slowing down interactive updates.

In order to detect whether a variable has changed, a simple pattern can be used:

class X

public var foo
private var _foo

function fooChanged
--- return foo!=_foo

function validate
--- _foo = foo

Often, however, it is expedient to update everything whenever a parameter changes; in this case we do not need to track each variable separately. Instead, a simple checksum can be used:

class Y

public var foo
public var bar

private var _checksum

function hasChanged
--- return checksum() != _checksum

function checksum()
--- return 

function validate
--- _checksum = checksum()

Hash values strings, enums and references

When evaluating a checksum, we need hash values for all parameters. For numbers and vectors, this is straightforward. For strings, enums and references, the following can be used:
  • parseInt(enumVar) => convert an enum value to an int
  • anObject.GetInstanceID() => suitable hash value for any object.
  • anObject.GetHashCode() => suitable hash values for most objects, including strings


Monday, 16 March 2015

I am currently working on an interactive clone tool.

All elements except the water are created using spheres.


Array distributions