Tuesday, October 28, 2008

Game design time

I've decided to continue on the cave flying game, at least for now. Well truth be told, I've spent the entire day just slacking off and reading game design related articles. Lost Garden has an interesting presentation called Mixing Games and Applications. It skims some common game mechanics, so it was an interesting thing to read while trying to decide what kind of levels my game should have, how the learning curve should go. I've never been a fan of tutorials inside games, and reading that presentation made me even more determined that the user should be allowed to discover how to play, instead of being explicitly told what to do.

In my prototype, I can tilt the phone in two axis to move the ship along the X and Y coordinates. In the proto the only activity is obstacle avoidance. If I merely throw the player into this and have different kinds of obstacle courses, that would seem to be quite boring. Instead I should have them on a nice curve where they learn new things and are challenged after each level. I don't think I need to have new types of things on every level, sometimes I'll probably get away with just using older challenges and just increase the speed and amount of obstacles a bit, but new elements should be introduced at times.

I'm even considering restricting movement to the X axis at first, pinning the player to the bottom of the screen. Perhaps I can then surprise them in a later level with the ability to also fly up and down. How to show them that they are now able to move their ship along Y axis without explicitly telling them to tilt their phone, I'm not sure.

Monday, October 27, 2008

Collision detection works!

2D collisions seem to be working well. In this case they are a bit more accurate than using a bounding sphere. So filled with enthusiasm (okay, stock market fear, but somewhere deep down there was some enthusiasm too) I went to show my project in its current state to a friend. What was his reaction? It was: "omg have you gone mad, you bought a mac, traitor!". It took a while for the situation to recover from that, but eventually he recognized that the iPhone is a pretty cool platform.

Sadly he wasn't all that into my project, and instead we started to brainstorm what I should REALLY be doing. That isn't so bad, as mostly coding this has been a learning experience. We agreed that it should be something with clear mass appeal, and something challenging enough that competition would be a bit less. We figured that maybe most developers are not as comfortable with network programming as we are, so we should make an Internet-based game. As bonus there don't seem to be very many of those yet on the platform.

But should I really just abandon this project I've been working on? It's been my experience that if you always abandon what you are doing when you discover something even better to do, you end up never completing anything. Have to admit though these lobby-based games would seem to have way wider appeal.

Thursday, October 23, 2008

Collision detection thoughts

So now that I have my method lovingly called "getTrianglesTransformedByCurrentOpenGLMatrix", which does seem to produce identical results with accelerated transforms, how do I use that for my collision detection? Well, for the needs of this game I would like to know if the spaceship is going to collide with the next obstacle or not. I would like to know that even before the collision happens, so that I can warn the user. Then when the obstacle is near enough and if the player has not adjusted their position, the ship should explode.

Before I was planning on doing this properly, to actually see if the polygonal objects intersect or not, but a friend convinced me otherwise. It won't matter as long as it works well enough so that the play experience isn't disturbed by it. So I will instead just have a two-dimensional collision volume for a ship. I will disregard the Z coordinate in the collision detection. I think I'll place this collision volume to the base of the ship, because that part is most visible to the player and any error there would be too glaring.

My obstacles are very low-poly, but I have some power-ups that may be smaller than the ship itself. If I do the detection by simple is-vertex-inside-any-triangle -tests, then I should probably subdivide the collision volume to have some extra vertices so that it doesn't happen that a power-up would just slide through it because no vertex in the ship happened to be inside any of the power-up's vertices.

Matrices from OpenGL, without OpenGL

"For programming purposes, OpenGL matrices are 16-value arrays with base vectors laid out contiguously in memory. The translation components occupy the 13th, 14th, and 15th elements of the 16-element matrix, where indices are numbered from 1 to 16 as described in section 2.11.2 of the OpenGL 2.1 Specification."

This at least clarifies the order of the values given to me by the glGetFloatv call. Now if I have a x,y,z vertex, how do I transform it by the returned matrix? I found mention on the web that I'm supposed to divide by W. But if I don't have W to begin with, then what should it be? Hmm, makes sense it should be one. Now I should be able to do the multiplication. Let's see if I'll manage to introduce a bug here:


// got vertex[0..2] already, multiply by matrix, divide components by w
vertex[3] = 1; // w
for (i=0;i<=4;i++) {
newVertex[i] = m[i]*vertex[0] + m[4+i]*vertex[1] + m[8+i]*vertex[2] + m[12+i]*vertex[3];
}
newVertex[0] /= newVertex[3];
newVertex[1] /= newVertex[3];
newVertex[2] /= newVertex[3];


Edit: Wow, it works.

Collision detection continued

I've been working on, or at least thinking about the collision detection problem for the past few days, at least while not distracted by the financial crisis. I'm an eternal optimist and have been buying stock regardless of the downturn, but it has not changed direction yet, and it makes me almost physically nauseus to watch my money disappear at an alarming pace from my etrade account. So I tend to log on to etrade and click refresh refresh refresh instead of working.

One slight problem I encountered with being able to even begin test for collisions is that I have just access to local coordinates, but I need world coordinates. Normally local -> world transformation is performed by OpenGL, but it is not possible to access the transformed coordinates because they only exist in the 3D accelerator chip for an instant. AFAIK I now have to ask OpenGL to give me the matrix (glGetFloatv), gather all vertex coordinates from meshes and then do the matrix multiplication myself. Currently I'm really confused about the order of components in the matrix given to me by OpenGL. Also I'm not sure what to do with the extra row and column that matrix has. I suspect it is about the "w component" which I have to somehow multiple or divide x, y, z with, but not sure exactly how.

Until I understand this, I suppose any attempt to code this will just result in a tangled mess.

Ralph Waldo Emerson

Poet/philosopher Ralph Waldo Emerson seems to be a startuppy kind of guy. I enjoyed this quote particularly:

"What I must do is all that concerns me, not what the people think. This rule, equally arduous in actual and in intellectual life, may serve for the whole distinction between greatness and meanness. It is the harder, because you will always find those who think they know what is your duty better than you know it. It is easy in the world to live after the world's opinion; it is easy in solitude to live after our own; but the great man is he who in the midst of the crowd keeps with perfect sweetness the independence of solitude."

Tuesday, October 21, 2008

Another way to do the collision detection


Here's another idea I had for detecting the collision. I'm not sure how to do the line-triangle intersection detection though, so whether this is simpler would depend on that.

Read a bit on the subject. It seems to be simple. To know if a line segment defined by two points goes through a triangle, first you check if the line goes through the plane defined by the triangle. This is actually cleverly easy: see if the start point of the line segment is on the other side of the plane than the end point. But hmm... somehow I need to know the intersection point to do the point-in-triangle check after that...

iPhone tunnel game progress

It's been a few days, so how is the game coming along? Quite well, actually. I took a step back to think about how I could have multiple levels of content. If I set everything in code, then it will too laborous to create any amount of meaningful play. I came up with a simple level system that allows me to make each level a single text file that events can easily be added to.

The ship slides forward in the level at variable speed and there is a certain draw distance that the program tries to maintain. If it notices that an object mentioned in the level file has come into draw distance, then it makes an instance of it. At first it did this by loading the model file from disk (or is it flash ram?), but that created a one-frame pause in the game when an object was loaded, so I had to preload everything in the beginning of a level, and then just make references to the already in-memory objects when they come into view.

Currently the level file has just two different lines. Either the graphics for a tunnel should change at some depth, or an obstacle should appear at some depth. This seems to work well now, I created a level about 10 seconds long with various obstacles appearing that the player can avoid by tilting the device. It's not clear from this whether or not this would be an enjoyable game, but I think it might be. Obstacle avoidance is a pretty common game element, and players do seem to enjoy it.

I've now come to a sort of mental block. The player cannot crash with the obstacles, they'll just slide through them. I feel that the collision detection code is absolutely crucial to get right. If the player feels that the collisions aren't handled properly, they may feel betrayed by the game. If you die, it should be your own fault, not the fault of inadequate collision detection in the game. But 3D collision detection is not an easy problem. Luckily in my case the player object is very simple, and the obstacles are totally flat.

I was really happy that OpenGL was doing all the matrix operations for me, but now it's coming back to bite me. To do collision detection, I need to know where the vertices are in world space. So I think I'll have to make matrix multiplication code anyway that can mimic what OpenGL is doing, so I can get the post-transform data. After I have the ship and an obstacle in world space, I should be able to see where the flat obstacle is in relation to the ship, then take a z-slice of the ship at that point. After this the collision detection becomes a 2D issue of seeing whether the flat obstacle should collide with a flat slice of the ship.





I also plan to have spherical power-ups and bonuses that can be picked up. In those it could be sufficient to see if any vertice of the world-space ship is inside the sphere.

Thursday, October 16, 2008

iPhone 3D object spinning retrospect

Wow, it works. Last time I was trying to outline what I would need to get a 3D object loader and displayer working, and now about three days later it works -- I have a mushroom I created in Meshworks spinning smoothly on the iPhone. Quite pretty. Now let's see what I listed three days ago and see how it panned out.

I thought I would need bitmaps for the textures and which texture to use with which mesh. Well of course that would be more complicated, I realized I would need texture coordinates as well for each vertex. I decided that texture mapping at this point is not important, I cannot allow myself to become one of those people who tinker on a 3D engine on their spare time. No, this has to become a playable game as fast as possible, and texture mapping usually isn't totally essential to gameplay.

I figured I'd need to have a list of meshes. Now I have a nice 3D object class, each object of which contains 3D mesh instances. Each mesh then contains a vertex list and additionally the color of the mesh, which I could easily get from the file I parse. I was worried about the vertex etc. data loader being complex, but actually taking some shortcuts it is easy to get that information out from a WRL file outputted by Meshworks. I didn't attempt to write a general WRL reader, mine only understands the specific output of Meshworks, so if there is some extra whitespace in the wrong place, it wouldn't work. That means I made the decision to stick with Meshworks, even this particular version of it.

I supposed there would be a list of vertices, then another list of triangles referring to the vertice list. That's how it really was in the WRL file. I made the unnecessary move of rolling out from that data a plain polygon list with no shared vertices, but turns out OpenGL ES would have known how to do that by itself.

I had totally ignored lighting in my original list. To know the brightness of each polygon, I had to specify where the lights are, and the material properties like how strong specular highlights should be on a surface. And to be able to compute these things, of course OpenGL then wanted to know where the surface normals are pointing. I tried to refer to my linear algebra text, but in the end did the copypasta PHP coder thing and just copied the normal calculation routine from some sample code. Well, maybe I mistyped something, but I had to tweak it for hours before it actually calculated the normals correctly. It was really difficult to debug, because just looking at float values in a debugger it's not so easy to say if a vector is pointing to the correct direction.

Another thing I ignored was setting up the projection to look OK. When you create a sample project in Xcode, initially it sets you up with 2D projection. All the sample code on the net refers to some GLU functions to set up a perspective projection, but those are missing from my framework. I guess the right thing to do may have been to again learn from my lin. algebra text how to REALLY do it, but instead I again just copied a working projection matrix from an example. Just too eager to get this project forward!

I've learned a great deal about OpenGL in the past 3 days, and it's exciting to be able to rather easily display 3D objects now. Hopefully this will be useful later, and not just a distraction. I'll try to blog some more about my progress soon.

Monday, October 13, 2008

Graphics time - 3D

I did some profiling and noticed that around half of the time was spent doing the rand() calls. Also I was writing data 8 bits at a time. Changing that to 32 bits immediately boosted performance, but CPU usage was still 100% and FPS was only around ~13 and fluctuating depending on background processes. If what in fact is happening is that Quartz is making a texture of my bitmap and uploading the texture to the GPU and rendering it that way, then I would actually be closer to the metal by just using OpenGL ES directly. Now this is a bit scary for me though, as I don't really know anything about OpenGL. I do know some basics about vectors, matrices etc. but the biggest thing I've done is a rotating cube (which did come 3rd place in a Javascript competition though haha).

I read some introductory text, but the concept of "shaders" bothers me. What the heck is a shader? I remember checking it on wikipedia before, but the best I could understand is that it's some kind of routine executed on the GPU against a vertex, or maybe they can be executed per-pixel too? Just guessing from the names "vertex shader" and "pixel shader". But what is a "fragment shader"? No idea. Wikipedia: "A pixel shader is a shader program, often executed on a graphics processing unit. It adds 3D shading and lighting effects to pixels in an image, for example those in video games. Microsoft's Direct X and Open GL support pixel shaders. In OpenGL a pixel shader is called a fragment shader." Ah, just a synonym.

Now, I have to admit it would be very sexy to display some 3D models of my own. But seriously, no more cubes! I've done so many of them. Always a cube on a new platform, then I get bored and make another cube a year later on another platform. Na-ah, should be a proper model at least now if I try this at all. But how do I get models with some data easy enough to load? I'm scared. Stuff I imagine I will need to load:

- bitmaps of the textures
- list of meshes
- which texture goes with which mesh
- coordinates of vertices in each mesh
- which vertices form polygons

Then to spin a 3D object...

- load object & textures
- do opengl magic to let it know about list of vertices and polygons
- maybe enter into some texture modes before each mesh? dunno.
- to spin, perhaps alter the object space -> world space transformation matrix?
- will opengl remember my vertex list etc. or do I tell it again on each frame? no idea.

So you can see I'm a bit confused about this. Let's see if there is some simple modeling tool for mac.

Saturday, October 11, 2008

Graphics time

I've been attending demo scene events for years, so I have a certain respect for software rendered gfx effects. Now I'm curious about how to push pixels on the iPhone, so let's see how far I can get with that tonight!

First up: diving into the Core Graphics documentation. Hmm.. tried to check how many colors the iPhone screen can actually display. Specs on Apple's page don't mention it. Certainly looks like more than 64k colors, but must be less than full 24-bit color or otherwise they would prominently advertise it as a feature. Just wondering if my framebuffer should be 24bits to make it as native as possible.

... 6 hours pass ...

I created and displayed my first raw bitmap data! Feel free to copy my code (please note it turned out to be too slow for much use). As a disclaimer I just got this to display anything without crashing minutes ago, so there's likely something still wrong with the code. Here's the init part.


CGDataProviderRef provider;
bitmap = malloc(320*480*4);
provider = CGDataProviderCreateWithData(NULL, bitmap, 320*480*4, NULL);
CGColorSpaceRef colorSpaceRef;
colorSpaceRef = CGColorSpaceCreateDeviceRGB();
ir = CGImageCreate(
320,
480,
8,
32,
4 * 320,
colorSpaceRef,
kCGImageAlphaNoneSkipLast,
provider,
NULL,
NO,
kCGRenderingIntentDefault
);


And then when I want to show a buffer:


for (int i=0; i<320*480*4; i++) {
bitmap[i] = rand()%256;
}
CGRect rect = CGRectMake(0, 0, 320, 480);
CGContextDrawImage(context, rect, ir);


My only problem now is that I'm obviously leaking memory by not deallocating anything (I should at the very least free() the bitmap data) and secondly that my code lives in drawRect and is only shown once. I don't know how to get the screen to refresh. Also I have no idea if this will be fast enough to refresh at 30fps, but I'm guessing it should be. It scares me a bit that I can't really know what unnecessary hoops this code is doing on the iPhone, since I'm not really getting a raw display buffer pointer but instead going through some classes that do who knows what before the data actually ends up on the screen.

I discovered another adventure gamish thing that you can do in the Interface Builder - sometimes it's possible to drag code files from Xcode to IB to get IB to notice they exist. I would have never thought about even trying that, just saw it mentioned on another blog. Still trying to wrap my head around the relationship between Xcode and IB.

Ugh! I tried running the above code on a real iPhone device and was only getting around 5fps! Clearly I'm doing something wrong, the iPhone is definitely powerful enough to push pixels if I just figure out a better way to do the updates. But right now I'm too sleepy to think about anything except maybe getting some quality time with HL2DM before getting some sleep =)

Thursday, October 09, 2008

Interface Builder strikes again

Just spent hours on a simple things I couldn't understand. I had a tab view controller in the interface builder, then in my own code in the project I had a class called FirstViewController. To reference this, I figured I should add a FirstViewController type view controller into the interface builder as well. Hilarity ensues as I now have a FirstViewController which is unbeknownst to me already being instantiated by the tab view controller (not sure how that works) so I had TWO instances of the same controller. At first I was really perplexed how on earth my instance variables are suddenly changing values in the debugger, then happened to notice that the address for "self" was different.

I just wanted my FirstViewController to be the delegate of a picker object, but now I had a different instance being the delegate and a different instance doing other things. After learning my mistake I was trying to hunt down the extra instance, and noticed that one of the tabs in the tab controller was already declaring itself a FirstViewController. Well, how to reference that, since the class isn't visible in MainWindow.xib along the other stuff? Took a bit longer to realize I can drag delegate references not only to the xib window, but also to certain visible controls! Felt like one of those Lucasarts adventure games where you miss a puzzle because you don't notice that a certain object was clickable.

Audio works!

Can't believe it's only been two days, because I feel like I've been battling with iPhone audio forever. I was trying to set it up, but somehow my callback was never called and I was starting to lose hope. I tried to keep things minimal, but turned out I was keeping it too minimal because I was neglecting to prime my sound buffers. I thought I wouldn't need to prime it, that I could just start the playback and then fill the buffers as they are requested from the callback function. Turns out the callback is only called when a buffer runs out, and since I had added no buffers it never got called!

To keep the callback function simple, I thought I would just create noise with rand() and fill the buffer with that instead of reading from a file. Again I neglected something important: setting bufferReference->mAudioDataByteSize. It was 0 by default, so the sound system must have figured there is no more sound to play. After fixing that I heard the sweetest sound ever: white noise being played from my phone!

Next up: learning how to use picker view to select sound waveform.

Tuesday, October 07, 2008

Next step: audio

Now that the first test app works and I somewhat understand what outlets are, I wonder what would be the next step? At least I should know how to have multiple views and change between them using a tab bar or similar control. So I should learn basic navigation.

As a brief detour though I am curious about how recording sound works. I have some ideas for apps that need sound recording, upload and download, but am a bit concerned that it might be a bit difficult. At least the network part. How do I know if the net connection is on? How do I show a progress bar for download/upload? Should there be a cancel button in case transfer is taking forever, for example if it happens over normal GPRS? What about compression, is there some basic compression algorithm included in the API?

I recall seeing some example code about sound recording, let's dig that up.

The example is called SpeakHere. Seems that there is no simple recordAudioOKThxBye-style function, but you have to stream it to a file yourself. Fair enough, it doesn't seem to be all that complicated to do, and is probably something I will eventually have to learn how to do anyway. There seems to be PCM encoding built in. Saw passing mention of MP3. I wonder which ones iPhone supports. MP3 would be sweet for shortening transfer times and also using the same files later when playing back from Flash, but is it possible?

Read up on "Audio Queue Services". Documentation mentioned the following "kAudioFormatMPEGLayer3 - MPEG-1/2, Layer 3 audio. Uses no flags. Available in iPhone OS 2.0 and later.", so it would appear the encoder is present. It's a bit overwhelming to set all of the structures at once and hope that I don't miss any vital flags or attributes, so I'll try to start with something really simple. Simplest thing I can imagine is setting up a callback function for sound playback and just fill the buffers with rand(), hopefully white noise can then be heard from the speaker.

Found a useful tutorial on the subject.

First test app works!

Phew, took a nice while to wrap my mind around how the controls work, but now I have a small app with three text fields constantly updating with the accelerometer data. For extra credit I added an image too which moves based on the accelerometer data.

Funny "bug" I had was registering to receive accelerometer events, then not receiving any. For the life of me I couldn't understand why. I was running the app in the simulator at this time. Went to meditate on this by pwning some noobs on Half-Life 2 DM and after coming back and looking at it again it was stupidly obvious - it's a SIMULATOR. It HAS NO accelerometer! So after running it on the real device it worked just fine :-)

How Xcode and Interface Builder relate

I'm starting to understand now how Xcode ties in with the Interface Builder.

My first confusion was this: in the main function when UIApplicationMain is created, how can it know what its delegate is when it is not explicitly mentioned in the arguments? Answer: It's mentioned in the MainWindow.xib file. This file is an XML file which is turned into a "nib file" later (when building?). Double clicking on it in Xcode brings up the Interface Builder. Clicking on "file's owner" and then pressing apple-shift-I brings up the Inspector, where I could then see the delegate -› MoveMeAppDelegate relationship (wtf had to press alt-b to get the › character).

Next I'd like to understand how to reference things set from the Interface Builder from my code. Specifically, how to change the text in a label? What identifies the label in my code?

[24 hours pass]

Okay wow, somehow that was really tough to figure out. To change a text in a label, I needed to get a reference to the label object. I was really confused trying to drag a line from "referencing outlet" to somewhere, with nothing accepting the drag. Turns out this is where the IBOutlet comes into play. I had to have IBOutlet UILabel *label; in the class to which I am dragging to, then the drag will be accepted (although at one point I seemed to sense a delay before Interface Builder realized now the drag can be accepted?).

So the controller that accepted a drag from a textfield "referencing outlet" looks like this:

@interface ThreeFieldsViewController : UIViewController {
IBOutlet UILabel *label;
}
@property (nonatomic, retain) IBOutlet UILabel *label;

Then additionally in the .m file I had to @synthesize label. Didn't check if it would work without that. Actually, it would be interesting to test if the Interface Builder code that gets generated just sets the attribute directly, or calls setLabel? Let's see. Yep, setters and getters are called if and only if there is a referencing outlet.

As a bonus I discovered that if you make a method and tag it IBAction, you can drag action references from components to that in Interface Builder. Not sure if there are some interesting arguments passed that could somehow be read. Next up: trying to make an app with three labels that get updated by a timer with data from the accelerometer.

Monday, October 06, 2008

Interface Builder

For someone who hasn't coded much, I think it's a bit dangerous to start with a graphical interface builder in an IDE. It gives you the wrong idea that everything is really easy. Just drag and drop stuff and BAM (channeling Steve Jobs here)! Of course you'll end up spending most of the time (as you should) in the actual code, and building interfaces will just be a short break. At school we had tools like this, then there would be people who confused building applications with designing their interfaces, and for them it was a shock how much work there was underneath, not just dragging stuff to build the interface.

With this in mind I am approaching the Interface Builder a bit carefully, almost trying not to have too much fun with it. It of course does make sense to use it. I could create all the components in code, and almost prefer to do so, but still I have to admit that it must be faster to use this tool if I can just learn to use it properly. I want to get stuff done fast, therefore I must learn this. So I've started it up, started dragging stuff around. At this point I still don't understand how this ties to Xcode. I do know there are some "nib files" and that the controls can be raised from it, somehow relating to the initWithCoder method.

The goal for tonight will be to understand how to create some simple text labels in the Interface Builder and then how to set the text to those labels from Xcode.

Sunday, October 05, 2008

iPhone dev 17

Oh lord, I just discovered that curly braces require one extra keystroke on the Finnish keyboard layout on the mac. Somehow the keyboard layout isn't the familiar one from Windows. I would use the USA layout, but then writing scandinavian characters would be a pain. I have to press alt - shift - 8 to get a curly brace!

Spent hours today trying to find out why a sample application won't run on the iPhone. Turned out in my Info.plist file the bundle identifier was the same as with another app, so it wouldn't install another one with the same id.

Next I challenged myself to create a small app which would have three textfields that display the raw data coming from the accelerometers. I got stuck early -- I wanted to use a timer to fire an event at certain intervals. Spent a very long time trying to find info in the docs. Looked at some sample applications, but they were more hardcore and had actual threads to do the timing. Then finally NSTimer was mentioned in a forum post.

timo = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];

- (void)onTimer {
int test;
test = 10;
}

Disappointed a bit that I couldn't finish this dead simple app in one evening. I'm starting to get a feeling where iPhone development falls on the difficulty scale. Maybe 5 times easier than Symbian development, but still 2-3 times more time consuming than Flash development.

Hello World in Flash from nothing: 5 minutes
Hello World on the iPhone simulator: 2 hours
Hello World on the iPhone: 6 hours (mostly figuring out app signing, device id blah blah issues)
Hello World in Symbian: coder pronounced dead at the hospital due to massive internal bleeding

Code Signing Provisioning Profile

Came across a problem that I noticed others were also having on some forums.

When you create a provisioning profile in apple's portal, then download it and try to go to target info to use it, it often isn't there. You try to click on Code Signing Provisioning Profile > Any iPhone OS Device, but it doesn't show on the list. I'm not sure if there is a more clever way to do this, but I can get it to show by right clicking and selecting "show definitions", then replace the hexadecimal values shown with what I find in /Users/YOURUSERNAMEHERE/Library/MobileDevice/Provisioning Profiles. Then when I right click again "show values", it's there.

Hope this helps someone =)

iPhone dev 16 - memory management

Found an article about the memory management issues. Noticed that I am indeed making a mistake. After allocing and initing an object, I am increasing the retain count by one. This is not necessary, the retain count is already one at this point.

Second mistake I think I am making is failing to release my textfielddelegate and UITextField. Maybe I could use autorelease?

But what happens when I set the delegate by doing testText.delegate = x. Is the retain count of x now incremented by the delegate setter method? In API docs it shows that the property is declared like so:
@property(assign) id delegate

"assign Specifies that the setter uses simple assignment. This is the default."

Okay, so it would seem that the retain count does not get incremented, which means it is my responsibility to release the object at the end. Great, seems to work!

iPhone dev 15 - How do I monitor the events that the textfield sends? Where does it send them to?

Last time I wondered what happens with the textfield events. Now I've read a bit more about delegates, how to use them in practice. Controls have a "delegate", called such because application-specific behavior is delegated to it. For textfields the delegate protocol is UITextFieldDelegate. To implement protocols, angle brackets are used when declaring a class, so here is the code I used in my declaration in MyTextFieldDelegate.h:

#import
@interface MyTextFieldDelegate : NSObject {
}
- (BOOL)textFieldShouldReturn:(UITextField *)exTextField;
@end

Then implementation in MyTextFieldDelegate.m is very simple:

#import "MyTextFieldDelegate.h"
@implementation MyTextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)exTextField {
[exTextField resignFirstResponder];
return YES;
}
@end

I found that "resignFirstResponder" line on some Mac development forum. I tried to read the docs a bit to learn what it means. The docs say unhelpfully that it makes something release the first responder status, whatever that is. In plain english I discovered it means that it makes the soft keyboard disappear, at least in this case.

Well above you see the delegate class, but that wouldn't do much if the textfield doesn't know about its delegate. I think this part must be slightly wrong because I'm never releasing the objects I create, but as an initial test this worked:

MyTextFieldDelegate *x = [[MyTextFieldDelegate alloc] init];
[x retain];
UITextField *testText = [[UITextField alloc] initWithFrame:testFrame];
testText.delegate = x;

The dot notation surprised me. After all the talk about automatically synthesized getters and setters, I expected to actually have to call methods to set variables. After reading the docs a bit more, it turns out that I actually AM calling a method here! The dot notation in Objective-C turns out to be exactly the same here as calling [testText setDelegate:x] and the dot notation is just a shortcut to it. This is very clever, because it allows you expose properties conveniently, but at the same time if necessary allows you to run code when they are accessed.

I'm starting to like this more and more, but memory management still confused me. I wonder how to see what I am failing to release? I don't want to leak memory on someone's iPhone.

Saturday, October 04, 2008

iPhone dev 14 - my first control!

Created my first control in the MoveMe sample program in the file MoveMeAppDelegate.m, method applicationDidFinishLaunching. Defined size of a text field as a CGRect like so:
CGRect testFrame = CGRectMake(10, 10, 100, 100);

Next I created the object itself:
UITextField *testText = [[UITextField alloc] initWithFrame:testFrame];

To see it, I had to do some extra magic. This somehow adds it as subview. Had to call this after other similar calls to make sure it's not obscured:
[window addSubview:testText];

It wasn't immediately obvious that the field even appeared, but when clicking on the upper left where it is supposed to appear a keyboard did pop up and I was able to type. Stuff I'd like to understand next:

- When am I supposed to release this field?
(in dealloc do [testText release] maybe? nope, didn't work.)
- Why when creating UIViewController it is stored in self, and then released? Won't that destroy it? Apparently not.
- How do I output some debug text?
- How do I monitor the events that the textfield sends? Where does it send them to?

Friday, October 03, 2008

iPhone dev 13

Already the fifth day of development, with not much to show for it. Going through the MoveMe sample application now. Yesterday got an OpenGL ES sample running. So cool that a little device like this actually runs OpenGL. I don't yet grasp the structure of programs very well. I know that there is some function you call in main, which starts off the message loop and apparently your own code goes into a delegate class.

Learned that building an Xcode project turns it into a "bundle", which a directory on the iPhone that contains code and data. Since I don't believe anyone reads this (just talking out loud to concentrate more on the task), I guess I can reveal what it is that I'd like to build. Well, I thought the iPhone would be great for drawing for the "draw and guess" game. I have a Flash version of it mostly working on MySpace (haven't released though). You draw something, others guess what it is, others draw, you guess. Guessers and drawers get points, repeat. People seem to like that game, and it would be cool to draw with your finger. I'm now pondering whether iPhone users should only be able to draw, or to guess too. Maybe it's my unfamiliarity with the iPhone soft keyboard, but it seems too painful to seriously use as a part of the game. Maybe I can let players choose a game mode. But if everyone is just drawing, will there be enough people left to guess?

Another game which occurred to me after getting this phone is one where you are given a topic, then have to try to photograph that thing in a very limited time using the camera. For example "take a picture of a fork!", then you rush out to your kitchen (hopefully connected to the net with WiFi), take the picture. Judging whether people took pics of forks or not would be done peer-to-peer. You get a picture and have to decide whether it is a fork or not. Maybe with some Slashdot style meta-judgement too to make sure you are giving correct judgements. Well, just a crazy idea.

iPhone dev 12

Sample app is now running on my iPhone! It took a good while to wrap my head around the app signing procedure. I don't think I completely understand it even now. I had to get a certificate (for signing my code?), put my name in some settings, create some kind of "provisions" (some kind of combination of everything else), app id and other stuff too. Important thing is that it runs, and I can now concentrate on coding. Perhaps I will have to really understand this better if I get other members in my team, or maybe deployment won't work without understanding it (although I hope it will).

It's now 5 am and this could be a good point to get some sleep at least after the biden - palin debate. Xcode seems awesome and I'm excited to learn more about using it.

iPhone dev 11

Couldn't even sleep with all this new stuff beckoning me to hack some more. Trying to install iPhone SDK, but realized I don't even know where installed software appears on a mac. Managed to open a terminal and started building the locate db in order to find it. It was also weird that the pipe character moved to alt-7. Not complaining, I was getting bored with my current system, this is refreshing. DB is built. Locate says it's in /Developer but how to start the IDE?

Oh yeah, those strange plus and minus signs in method declarations mean whether the method is an instance method or a class method.

iPhone dev 9 - got the hardware

Today all the hardware arrived. An iPhone, a WLAN box and a Mac Mini. This stuff really was disruptive to getting things done -- I haven't felt this much like a child since... well since I was a child! Walking to the post office to get the iPhone almost turned into a run because I couldn't wait to play with it. Then when I had everything, stuff worked really well right from the box. Noticed though that I accidentally got a 2G iPhone instead of 3G one, but that doesn't really make any difference for development (good bye to my plans on starting to use VoIP w/ Asterisk though). I feel like I joined some cult now that I have this stuff. I even read the holy texts of Apple -- namely the folklore about pirate flags and Woz's pranks. I have truly joined the dark side.

I have tried to get back to reading the cocoa fundamentals documentation even while I feel a bit giddy and would prefer to just play around with this stuff. I have to remind myself I got these for a purpose -- to develop an app for the iPhone which will then pay for this expensive hardware. So with this in mind I've muddled through the fundamentals documentation, but it's getting awfully abstract. Well of course it is abstract, because I just reached the design patterns part. Fun to read about abstractions in something which in itself already feels abstract to me at this point (Cocoa programming). I think for my motivation's sake I should try to get something going with Xcode while I read forward.

Thursday, October 02, 2008

iPhone dev 8

My iPhone and Mac Mini will arrive today. Might be disruptive to my Cocoa study.

"Sometimes using a protocol can avoid subclassing". Not sure what that means, not sure what "delegates" are. Code is in .m files, headers in .h files. Saw how to declare classes. Instead of C-style "#include", "#import" is used instead. It's like require_once in PHP.

#import
-- function and data type declarations --
@interface ClassName : Superclass {
-- instance variables --
}
-- method and property declarations --
@end

The .m file could then look something like this:

#import "ClassName.h"
@implementation ClassName
-- stuff --
@end

If I see "IBOutlet" in code later, that is somehow related to "nib files" and the Interface Builder synchronizing with Xcode. Vague at this point. Documentation mentioned that on the iPhone the applicationWillTerminate method gets called when the app shuts down and is the place where state should be saved.

Getters and setters can be automatically synthesized. "copy" and "retain" tell whether object variables should be copied or if the pointer should be stored instead and retain count incremented. Something very strange was mentioned about "KVB", "KVC" and "KVO" that I had no idea about.

Cool thing: in printf strings you can say %@ and then provide an object, and at that point any string returned by that object's "description" method will be inserted. There was a page about threads. Said exceptions should be handled by each thread, cannot be thrown away from thread. Talked about how error-prone thread programming is, that I should copy data and try to minimize possible conflicts arising from shared data. Events should just be handled by main thread, also UIKit objects should only be used in main thread. I imagine I may use threads with socket programming. Said not all Cocoa classes are thread safe.

iPhone dev 7

There is a windows style event loop. On Mac it lives in NSApplication and on the iPhone it's in UIApplication. In AppKit.h there is a method NSApplicationMain that creates the application object, sets up an autorelease pool, loads UI from something called a "nib file" (apparently a file that contains files, maybe even directories?) and starts handling events. On iPhone the equivalent method is called UIApplicationMain.

@"test" is shorthand for creating an NSString that contains "test". In some cases empty string @"" can mean no value / default value. String literals shouldn't be used as dictionary keys? Setter methods are called setSomeVariable, but getters are just "someVariable". Typical framework usage: create subclass, override methods to implement own functionality. Cocoa uses MVC.

Wednesday, October 01, 2008

iPhone dev 6

Init may return a different object than was allocated. For example in singleton case it may return the already existing object. For this reason should always use the one returned by init. Objective-C seems to support exceptions (or is it a Cocoa feature? I'm confused about the distinction). Self, super. Strange plus and minus signs near method declarations. Maybe plus signs have something to do with factories? Noted in explanation about the "respondsToSelector" introspection method, that it tells if an object responds to a certain method -- so "selector" does indeed mean a method? "autorelease" was mentioned many times, but don't know what that is. Section about class clusters: public superclass with many private subclasses, you instantiate the subclasses through factory methods in the superclass. For example Number superclass which can create Ints, Floats and so on. Skipping sections about class cluster details and "creating a singleton instance". I'll return back to them if the need arises to create my own cluster objects or singletons, just too tiring to read about them now.

iPhone dev 5

SEL is data type of a selector, but couldn't really understand selectors are. Are they methods? Reference counting is called "retain counting". On alloc the retain count is 1. If the retain count reaches zero, the "dealloc" method gets called on an object and after that the memory is released. If you "copy" an object the retain count (usually?) becomes one for the copy. There are things called "autorelease pools", but their use is discouraged in iPhone. Somehow everything in the pool gets released at the same time, and somehow objects can be added to such a pool without directly referencing the pool by name (at least the sample code looked like that). App kit on Mac has some kind of autorelease pool already created in the beginning. There are some conventions on when to call release on objects. If an object is created by you, then you should also release it. If you get an object from somewhere else, you shouldn't. There was something related to class factory created object releasing that I didn't understand. alloc -> init -> usable object. In addition to allocating memory, the alloc method also sets a cool explicit "isa" property for the object, that points to the object's class. Also zeroes all properties.

iPhone dev 4

@property is syntax for declaring class methods that automatically create getter and setter methods. Enumeration of sets can be done with the nice "in" syntax as in some other languages. Calling object methods has a bit strange syntax, [object method]. Also possible to give some named arguments, but not sure if the first before : is a method name or an argument name. [object keyword1:something keyword2:somethingelse]. Where is the method name? Is it "something"? Not sure. NSObject is root class of everything, and defines some methods like init (constructor?) and reference counting (retain, release).

iPhone dev 3

NSObject is the root class for Cocoa classes. Stuff starting with UI prefix is UIKit related. Objective-C has garbage collection after version 2.0, but it cannot be used on the iPhone because of performance. Cocoa classes seem cleanly designed. Didn't encounter a regexp class, although didn't check if it's in NSString methods. Event mechanism in iPhone UIKit differs from Mac Application Kit. Looked at Objective-C example code, saw lots of weird square brackets. "id" datatype can hold any Cocoa object, so convenient for enumeration. Dynamic typing, binding, loading. New feature: "categories". By dropping mysterious @ marks in strategic places in your code, you can add methods to existing classes without subclassing. Protocols are like Java interfaces.

Tuesday, September 30, 2008

iPhone dev 2

There seem to very cool tools for debugging and coding. The "Instruments" application seems impressive, creating data porn from your app as it runs. It isn't mentioned whether that can be used when developing for iPhone. I learned for iPhone there is a different compiler, on Mac gcc is used. The iPhone simulator needs to be compiled for, so it really is a simulator and not an emulator. The iPhone needs some special configuration to start development on it.

iPhone dev

I have never used a mac. Once I sat at one in a computer room because other computers were taken, but I couldn't figure out how to turn it on! So with this background let's see how far I can get with iPhone development. I started off by ordering a Mac Mini, buying a jailbroken iPhone from an auction and signing up for the developer program. While waiting for the hardware to arrive I can use the time productively by reading the documentation. Stuff I've learned in the first hour:

"Aqua" is probably what the UI is called on a Mac and "Quartz" is some kind of rendering system for it. You develop software with "Cocoa", which historially comes from NeXTSTEP. The docs talk about "Darwin", which according to Wikipedia is a flavor of UNIX (isn't that Mac OS X? I'm confused). "Carbon" is something I should ignore. Apparently Cocoa also comes with an IDE, which is perhaps called Xcode. When developing for the iPhone my app will take over the whole device -- only one program is running at a time + some background daemons. SQLite and OpenGL are used somewhere by something. On the Mac Cocoa consists of "foundation" and "application kit", but on the iPhone the app kit is called "UIKit". Foundation does non-gfx things. The language stuff is developed on is "Objective-C", which is some kind of superset of ANSI C but with additional OOP features inspired by Smalltalk. Some lower levels use just plain C, but in Cocoa there are OOP wrappers for them.

Let's see if I have the energy to continue, or if I decide to auction off my hardware when it comes :)

Thursday, August 07, 2008

Dead-end stocks?

It's funny how some companies seem to be riding on trends that seem doomed to me. I've been going alphabetically through Scandinavian stock listings, and so far I've encountered three such companies: AudioDev, Anoto and Cash Guard. AudioDev makes testing equipment for optical media. Anoto makes system to read hand-written forms. Cash Guard makes cash handling systems.

In my image of the future all content is accessed through the Internet, therefore there will be no optical media, and so there won't be any need for testing equipment for it. All official forms, questionnaires, multiple-choice exams etc. will be filled electronically, so there won't be so much need for OCR / choice-reading machines. Cash will be phased out gradually, where it might always exist but will be used less and less.

These three companies don't seem to be riding on very good trends :)

Media circus has arrived

Finnish media companies have gotten excited about "social media". They see it as a trend, and they must report trends. To support trend reporting, they want to raise individual examples, hopefully ones that people can relate to. I happen to be one of the few serious Facebook developers in Finland, so I tend to be that example.

It's been fun. First I was featured in some magazine called "Happi". I'd never heard of it, and even with numerous requests they never sent me the issue that my interview appeared in. But apparently someone read it, because next I was contacted by another magazine called "Image". Now this one I had heard of, it's a very high profile magazine. I got my face filling an entire page, it feels unreal. Seems that stories in media inspire more stories in other media, because next I was contacted by "YleX" radio channel and "Helsingin Sanomat", the largest circulation newspaper in Finland. Just wow.

Friday, April 11, 2008

Silly Facebook apps are keeping my stomach full and a roof over my head

This is a long post, but lots of exciting things have happened since the last one!

The Facebook melody composing app I was making in August 2007 didn't take off. Perhaps it just wasn't a very good app for making melodies, or perhaps people just aren't creative enough for it to become viral. I abandoned it and carried on making other ones.

Boy, was that a good decision! It's been a jumble, so I can't even remember the proper chronological order of things, but I think the next app I made was "Your Japanese Name". I thought it would have a very limited appeal, but actually half a million people have installed it now! Wow. Also, it's now making enough money for me to pay my rent.

This got me thinking that perhaps other easy-to-use things that let people express their identity on their profile would do well also. Therefore I started adding to my list all kinds of other apps that fit that description. Some people are looking down on these apps and calling them "badge apps" with no real value, but I believe that ultimately it is the users who decide what is entertaining for them.

I made several. Lots failed. I think failure is good too, it's great to know what doesn't work and try to ponder why. I made one which comes up with a description of the past life of the user. Like it might say that you were a cave explorer in your past life, and that's why you are so adventurous now. Perhaps that was a bit too random, showing that off in your profile doesn't really tell anything about your identity. I'm happy that it failed, because it raised my belief in humanity a bit, that people won't accept just any crappy app :)

Just to make sure though, I had another app made which is similar, but it shows you what you will be reincarnated as in the future. That failed even harder. Strangely though later someone else made a past life app similar to mine, except it was a huge huge success. I believe it was because of the forced invite system though, and not because the app itself had some merit above mine. Well, the author got away with that and made a lot of money, so maybe I should have put such a system in place too.

There are about a dozen failed apps which I made. I'll describe more of those in other posts. Let's talk about one success for a change. It's called "Name Analyzer", and like "Your Japanese Name" it displays your name in your profile, but just in plain english, with some adjectives attached to explain what each letter in your name means. I can't claim it's an original idea, but it hadn't been done for Facebook yet. Basically it has the merits of "Your Japanese Name", but doesn't limit the userbase to only those with an interest in Japan.

It took off like a rocket and now has nearly 7 million installs, with a hundred thousand people using it every day. I wrote last year about my scalability and bandwidth worries, but now in retrospect that hasn't been an issue. I'm not paying significantly more for hosting now, and just one server has been enough to handle the load, and even that server has been mostly idle, even though the server logs are really flying.

Oh, I lost a lot of impressions though because the logs are REALLY flying, and I hadn't realized how large they would become! I had 8GB of space left, so I thought I would be OK. However, with 100k people each doing several page loads and causing longish lines to be appended to ever growing log files, I actually ran out of space. Many times. Every time the velocity of the expansion of the server logs took me by surprise! Running out of space is a bit nasty though, because it corrupts MySQL tables. Luckily the repair worked!

After seeing that people have an interest in it, I have added more features to make the app stickier, with pretty good success. Now there is functionality to decide analyses for your friends, change colors and fonts and backgrounds, make your own themes that others can use etc., all ever so slightly increasing the frequency of people visiting the app and the length of time they spend in it. Not a big difference, but with user numbers this large even a small percentage difference can be significant.

With monetization, I believe I have signed up for the best advertising network, which is Social Media. I do feel that I haven't really tried out all the other alternatives, but they pay so well that it's difficult to imagine that the others could be better. From discussions on the developer forum, there seems to be a consensus that Social Media pays the best. Only other options I have tried are Google AdSense and selling merchandize through Zazzle, but both of them paid an order of magnitude less than Social Media. Perhaps I should properly try out Cubics, VideoEgg and the others though, just to be sure.

Even though the merchandize (mug cups with your name on it) failed, I'm not sure that it was because the idea itself was flawed. Maybe the product, or having a link to an external site was the problem. Maybe if there was something that could be easily purchased while on Facebook, I could monetize better. Only ideas I've had so far are mobile phone background images or premium SMS subscriptions to get your name analyzed for your phone. That's something I might explore more.

So, how has this increased ad inventory affected my life? Well, I already told you that "Your Japanese Name" has allowed me to pay my rent, so you can guess that "Name Analyzer" has been even more significant in that respect. I won't make any big purchases though, only major thing is that I'll probably travel a bit more, still on a shoestring budget though. I'd like to think I'm pretty responsible when it comes to my spending. I don't have a car, I live in a normal sized shared apartment. I eat pea soup out of a can for dinner. I even have a spreadsheet with an inflation-adjusted plan for until I am 74, the age at which an average Finnish male tends to die. I don't have enough to live until then, so I'll keep saving. Couldn't resist getting a projector and a Nintendo DS though ha ha :p

I've gotten some very VERY interesting requests to appear at job interviews, but I don't really feel comfortable letting others decide what I should be making, now that I'm having so much fun thinking up new apps :) And I do have a lot of ideas! That list I started last year is getting really long. Lots of them are obviously stupid ideas when I look at them now, but for some it's hard to say! I hope I'll have success making some other type of app, I wouldn't want to be a one trick pony!

Wednesday, September 19, 2007

Five US citizens seeking asylum in Finland

This news was ignored in foreign media, so I guess I have to translate it.

"Finnish border officials were amazed when five US citizens applied for asylum status yesterday evening at the Helsinki-Vantaa airport.

The applicants had arrived to Finland from inside the Schengen area and informed The Border Guard of their desire for asylum status. From here on the actual application process will be handled by Directorate of Immigration.

- In near history this is the first time adult US citizens have applied for asylum status in Finland, major Janne Piiroinen told reporters.

According to the information made available to reporters, the US citizens are part of the same group. Officially the reason of the asylum application is still unknown, but it is not related to protests of Iraq war."

Wednesday, August 08, 2007

Decided which Facebook app to make .. NEXT =)

This post is mainly meant for myself to organize my thoughts.

I finished my composing app mostly. I got around 200 people to install it, now I am waiting to see whether it is viral at all or not. Currently it is showing growth of 2% per day, but I'm not sure if it's really spreading at that rate, it could just be chance. Would be wonderful if it were true, because 2% increase per day is over a thousandfold increase per year. Personally I think the app sucks, but I've seen other apps get popular which suck even more, so I guess it's not totally impossible ;)

My friend made a great suggestion for the subject of the next app -- one which would let people take and make tests. It seems extremely viral, because it has two ways of spreading. Firstly, if a user creates a test, it seems very likely they would send it to their friends. Secondly, people always like to share with friends their test results and encourage them to also take the same test, so that the results can be compared. I'm amazed nobody has made this kind of app yet. I might feel paranoid about sharing this idea, but luckily nobody except you reads this blog.

There are tons of different types of tests, so I am now trying to decide which ones to include and which not. For example there are IQ tests where the question and possible answers are images ("which picture comes next in this series?"). Then there are knowledge tests where the question and answer are text ("what is the capital of Japan?"). Also there are image recognition quizzes ("which Simpsons character is this?") where the answers are text. Rarer, but possible would be reverse image quiz, where the question is text and the answer a multiple choice out of a set of images. Then there are multivariable quizzes which are a bit more complex ("answer this set of questions to discover which 24 character you are"). I think I came up with a way to create even multivariable quizzes that isn't all that confusing ...

Those were the different quiz types I could come up with, but there are also some features that could be included or left out. When answering a question, sometimes in quizzes additional information is provided about the correct answer ("what is the capital of Japan?" - "Tokyo" - "correct, did you know Tokyo is blah blah"). There could be time limits when answering. In addition to getting how many percent were correct, sometimes there is textual feedback ("80% - very good"). The questions could come in a predetermined order, or at random.

On implementation side the normal way to do this would be a straightforward HTML (well FBML) interface, but to make it faster it could be done with Flash or javascript. It's kind of annoying to wait for page loads after each question. I have done some scripts like these before, and the biggest problem I had was keeping track of which questions have already been displayed to the user (when random order) and making sure that no duplicate options are included in multiple choice questions. Why is that tricky? Well suppose there are two questions "what is the second largest city in the state of New York?" and "what type of animal is the wild Arni?". Both of the answers are "Buffalo". This means that randomly chosen multiple choice answers could contain two identical answers with different meanings, which should be avoided.

Friday, August 03, 2007

App mostly finished

Alright, I worked hard for a week straight and managed to finish the Mini Mini Melody application for facebook. Please follow that link and install it if you have a Facebook account, then send me some feedback!

Wednesday, August 01, 2007

Tay Zonday, tour for us!

Dear mr. Tay Zonday. You rule. For now. People want to see you, but soon they will forget. That's the fate of an Internet star. So go along with this, live your "Internet dream". See the world. Make a zillion dollars in the process.

Let go of the hesitation.

Monday, July 30, 2007

Totally tired with this app

I'm exhausted! I've been working on this melody Facebook app for around a week now. At first it was very exciting. I had big dreams of making a hugely popular app, but now that the app is becoming more concrete it is starting to become obvious that this will be marginally popular at best. Why? Well, turns out it's a lot more difficult to express yourself with music than by drawing!

Currently in the app you can selected between a piano, a cat's meow, a dog's bark, human voices or drums. The app allows you to make a very short composition, around 30 seconds at the longest perhaps. There is a staff on which you can place notes to make your tune. I haven't done the sending part completely yet, but the idea is that you could send these tunes to your friends.

The path from an idea to reality is always less smooth than one would hope. An idea is very vague. Even if you try to work out an UI on paper, it's still vague, even if you don't know it. There are just so many little details that you will never be able to think about until you make the app. And that's fine, because making the app is all about describing those little details to the computer anyways. I'm struggling to provide a concrete example here, but for example in this case the idea was "a graffiti-like app for sending melodies". Then in the paper UI mockup I realize that there has to be some way to put different instruments on a staff. Then when really trying to make it, I realize that when you are placing those instruments, there has to be some kind of indicator of what you are selecting. But that indicator shouldn't be shown if you are outside the area ... and if you select drop-down menus they should appear ABOVE all the notes, not below. And a million details like that.

After you spend days just basically tangled with these small details, you become very exhausted even though from previous experience you knew that it would be like this, while of course secretly hoping that this time would somehow be different. There is some satisfaction in seeing your idea become a reality, to interact with what you have created, but at the same time you have to face the depressing reality that perhaps your idea wasn't as great as you had hoped. What seems like a fun idea often isn't as much fun in reality.

A tale of two Graffiti

If you use Facebook, you have probably used or at least seen the Graffiti app, which makes it possible to send doodles to your friends. But did you know that there are actually two different Graffiti apps? One wildly popular (5,713,050 users and counting) and another more obscure one (mere 11,367 users). Surely the one with less users is just a clone? No, according to the creators, the more obscure one came first.

I remember installing the more popular one and instantly writing graffiti to my friends, which was kind of fun for a while. Out of curiosity I installed the more obscure one as well, but the thing is that I can't figure out how to use it. It keeps showing error messages. The lesson here of course is that it doesn't matter how cool your idea is -- if it doesn't work or the users can't figure it out (which amounts to the same thing) then it will never be popular.

The creators of the original graffiti must be kicking themselves now...

Saturday, July 28, 2007

Melody app progress

I have been actively working on the melody app lately. Learned basic Facebook API usage and started making the UI part in Flash. Progress is nice, I can already arrange piano and drums on the tracks. A surprisingly difficult thing has been trying to find the different sound samples to use.

I need at least a basic piano sound, a guitar sound, drums and some funny sounds. The temptation is great to go to one of those "free samples" sites to grab something, but I want to be sure that any sounds I use are properly licensed. So instead I have been trying out sites where you can download sample packs. I am really surprised at the poor quality of the sites and the sounds they provide. For example some drum hits might have an audible hiss in the background, in some cases almost to the point of being static. Finding drum loops is easier, but I want single hits, not loops.

Come on, I just need around 28 different sounds, hopefully for under $100 total. How hard can this be?

Wednesday, July 25, 2007

Decided which Facebook app to make

The idea that found its way to the top of my ideas list (it's a long list!) is a music composing app. Basically like Graffiti, except that instead of drawing stuff, you can compose little musical pieces and send them to your friends. You would do this by arranging notes on a small staff (the classic "like X except Y" pitch). Taking Graffiti as the inspiration, everyone would have a wall of composed musical pieces.

What I am concerned about a bit is the bandwidth. I wouldn't even be doing this if I didn't intend it to be popular. So assuming it is popular, perhaps people would be loading the composing/playback Flash application about 100k times per day. I did some calculations in my notebook (in a section titled "slimy biz talk corner") and this could mean a bandwidth cost of about $600/month. From my prior experience 100k page views per day for random people isn't necessarily greater than $600/month, so it might be that initially this makes no sense. However bandwidth is getting cheaper, and with Flash 9 there are things that would let me cut the size of the player/composer down A LOT so perhaps it would make sense in the future if not right away.

Oh yeah before settling (at least for now) on this idea, I spent two days basically pondering nonstop about which Facebook application to make. I wrote a long list of ideas that occurred to me, then ranked them based on how promising they seem. It's funny how many ideas for social apps you can find by reading a book containing playground games for children. For example there was a game where you must come up with something that you have done, but none of your friends have done. That would make a nice app as well. Anyway the point is that playground games books are a great resource =)

Sunday, July 22, 2007

But what to develop?

I have been trying to come up with something to create for Facebook, but how to know what is worth spending a week of development time on? Some criteria I have come up with:


  • Coolness - If a potential user encountered this app all alone, with just a few sentences to describe it, would they likely be excited about it?

  • Virality - How likely would they tell their friends about it?

  • Monetization - How much money does each user translate to? Sometimes the right crowd (people wanting to install awnings in their home) is better than a big crowd (people looking for free software).

  • Stickiness - How likely would they use the app for long periods of time?



It's interesting to think about the top Facebook apps in these terms.

Top Friends - Slightly cool, very viral, not very monetizable, not very sticky.
Graffiti - Very cool, not so viral, not very monetizable, pretty sticky.
iLike - Cool, viral, monetizable, sticky.
... and so on

Developing for Facebook

Easiest hello world I've ever made was in Commodore 64 basic. The most difficult one was with Symbian -- I never had the patience to finish it! Facebook seems to fall much nearer to the C64 experience. Starting to develop a Facebook app feels really sweet. Seeing what you create instantly embedded on a major site is a strange feeling, because it's something that's completely new.

The thing I was most confused about at first was how the content you create would find its way to appear on a Facebook page. At first I figured that code must somehow be running on Facebook's servers, like in a sandbox. But it doesn't work like that, rather Facebook calls your server and displays the response it gets as part of the page it renders.

One surprise was that things are a lot simpler than you would expect. The PHP API include file is just around a thousand lines of code! I feel that now is the time to get in the game of building Facebook apps, because certainly after a while they will add a zillion new things you can do with the platform, which will make it even better, but also that much more confusing for those just starting out.

In my mind Facebook has won. With all the apps that have been created and are being created, Facebook will have thousands of times the functionality that MySpace is offering. The change in Facebook has been so sudden that people have not yet realized what happened, it will take a while before people understand that there are now these things called "apps" and that you can add them to your profile. People will gradually learn, and a few of those apps will be such gems that people will wonder how a social network could ever be considered complete without them.

Monday, July 09, 2007

Would you pay $10 per gallon?

Sweden is considering meeting its goal of reducing emissions by doubling the price of gasoline by the year 2020. This may raise the price of gas in Sweden to over USD $10 per gallon (2 euro per litre). Sweden has promised to lower their carbon dioxide emissions by 20 percent by the year 2020 and according to calculations the price hike would cause this goal to be met.

This news seems to have been ignored by the English media, so this was a quick translation of the source articles.

Saturday, March 24, 2007

Daniel Tammet

I read the book Born on a Blue Day, which is about a savant called Daniel Tammet. I got the book after seeing the documentary "Brainman" on YouTube. The name of the documentary is a word play on the famous movie "Rain Man", where Dustin Hoffman plays an autistic savant. The documentary is over-dramatized, but by concentrating my attention only on the interviews it was an interesting watch.

In the Brain Man documentary Daniel Tammet describes his number synasthesia. "Synasthesia" means the property of associating two seemingly unrelated senses with each other. In the case of Tammet his synasthesia manifests as seeing numbers in different shapes, textures and colors. We might see the number "117" as a boring compination of three digits, but for Tammet it is a very distinct visual object. By using these associations he was able to recite 22,514 decimals of the irrational number pi without a single error. He also has some enrichened sense of words, which enabled him to learn the icelandic language in a week (to some level).

After seeing the documentary I had this image of a super-intelligent person, devoted to mathematics and indifferent to what others thought about him. In his book I discovered a different kind of Tammet however, one seeking acceptance and trying to fit in, all the while having trouble with small issues in life, such as brushing his teeth. A person not single-mindedly devoted to numbers, but one with a personal life with his husband Neil, staying at home cooking meals for him out of materials grown in their own garden. Crying over their dead cat. For Tammet numbers aren't the sole content of his life to the level I had imagined. In his book he hardly talks about numbers, rather concentrating on describing his exchange study in Lithuania and his attempts to be a part of the world which surrounds him.

However precisely because the book was so different from my image of Tammet, it was a very refreshing read. Without realizing it, I had this stereotypical image of what a savant "should be like". Real life is not just numbers, it is about having a daily life which you can feel content with, it is about fitting in, making friends, being accepted. Savant skills for him were not only a gift, but came with significant downsides as well. He had to try hard to make it in the world, but seems that he succeeded.

Thursday, March 08, 2007

AdSense - things I love and hate about it

  • It tempts me to create spammy sites which provide no actual value to the visitors, that in turn makes me feel superficial, greedy and in turn unhappy. My most embarrassing secret: I have actually made a page about mesothelioma once. No more! Valuable content and functionality only! (yeah yeah)
  • It never pays enough. I console myself with the thought that my AdSense ads still make me more than the daily average in some super poor nations, but on the other hand at times I feel like I've worked for that money as hard as someone in a super poor nation (okay not true).
  • Sometimes it displays really unsuitable ads and it angers me that I cannot just tell it what types of ads to display and instead have to rework my content to help AdSense guess better. Example: I wrote a page about how to create objects using a toolkit for a computer game, using a beer bottle as an example of an object you could create. Of course, now AdSense is displaying ads about beer, not about games. Grrr.
  • Spending countless hours excitedly monitoring my pathetic AdSense revenue and click-through rates. Wow, I made $1 today! Hooray! (what?)
  • Moving to a different country requires you to close your AdSense account and open a new one, accumulated funds are saved in the process but it still feels like an unnecessary hassle.
  • The fear that my account would suddenly be closed, without any explanation, with all my funds frozen and not getting an answer when I ask why (apparently has happened to people who at least claim to have done nothing wrong). Not sure if this issue is real, but the fear is, and Google doesn't seem to be very open about it.
Time to get positive...
  • It is a real joy to set up, copy & paste goodness.
  • It provides a somewhat predictable revenue stream when contemplating about starting new sites, a real enabler for webmasters everywhere.
  • It gives Google a lot of money -> Sergey & Larry seem to be into using some of it for space and artificial intelligence research -> I get to take a ride to a distant planet in an AI controlled spaceship and have an intense battle with the AI when it goes berserk midway.
EOF

Tuesday, March 06, 2007

Thank you Sierra for all the great moments

The first time I saw Space Quest 3 was at the house of the literally richest kid in town. I mean really, his dad owns a factory and even a a theme park! So they had this computer called the "PC", with a nice sound system and an expensive Roland sound card. I was standing there while he was playing SQ3 and I was blown away, not even really thinking I could ever own such a system myself.

Later I got an Amiga 500 computer, which looking back kicked the PC's ass when it comes to gaming. I was so happy that Space Quest 3 was available for it, now I could actually play it myself. Of course with all Sierra games there were several disks that you had to change during the game, and you often spent more time waiting for things to load and swapping disks than actually playing. I couldn't afford to get an extra disk drive, let alone a "hard disk" (I had read about those in a computer magazine, apparently it was a device that eliminates changing disks!).

Well, actually I once thought that the disk swapping might come to an end. In that magazine they were talking about this new type of disk, which is readable in a normal floppy drive, but could store as much as 10 megabytes on it. With that I could possibly store the entire game on a single disk and actually afford it! It was called "bubble memory", the technique was apparently that the data was stored as the state of a layer of bubbles on the disk. I was so excited I could hardly contain myself. Then I found out that it was an april fools' day hoax and... I cried.

The most emotional moment from playing Space Quest 3 was definitely walking around in a space scrap yard in the game, discovering something that looks like a ship, then actually getting it turned on and flying off with it! After that discovery I didn't want to fly off right away, but rather I called a friend over and we continued from there together. I think I was so excited I hit my head on my loft bed when getting up from my computer.

Thank you Sierra for all those great moments!

Monday, February 26, 2007

Microsites - progress with image quizzes

My PhpBB extension for image quizzes is coming along quite nicely. 18 hours, 657 lines of PHP and 250 lines of HTML later users are now able to create quizzes and take quizzes. Most headaches I had were session handling, I couldn't figure out how to do it properly with the session handling build into PHP, so I resorted to just passing stuff around in very non-SEOed (lately the word SEO makes me cringe) obnoxiously long URLs.

If I had tried to do everything perfectly then I would have never finished, I think it's important to get a first version out before polishing it too much, see what the users do and then improve on it. Obviously it should mostly work, and it does. Currently it's just in Finnish and I enabled it just on one forum to have a limited test. I hope that people will like it and that it would cause people to spend more time on the forum (which I'm not sure Google Analytics knows how to measure), maybe even get some new visitors that come just to take the quizzes.

One benefit I didn't anticipate from integrating with PhpBB was that it's possible to know who the people taking the quizzes are, so I can construct a scoreboard for them. People love scoreboards, it makes them want to improve their score over and over in order to not look bad. My plan now is to see the effect the quizzes have, polish the code a bit, then create a new PhpBB installation (actually all my installations are virtual, not actually separate instances of the software, using a mod I made) which is focused just on image quizzes and redirect my existing quizzes there.

I love the feeling of publishing stuff on the web, not knowing at all if it might be popular or not.

Monday, February 19, 2007

Microsites - extending PhpBB to support image quizzes

One of the features I imagined any fansite should have is a quiz of some kind to test your knowledge of the series in question. One popular site I have is a Naruto quiz, which I made one evening just for fun. Adding images to that quiz required me to edit things in the database manually and copy images into the image directory manually as well. I want to improve that by creating a PhpBB extension that lets forum users create their own quizzes by uploading images. I have several motivations for making this.


First of course that it is one of the planned features for the microsites I've been talking about for the past few posts. Secondly it allows me to easily create new quiz sites similar to the Naruto Quiz, which seem to easily become popular. Thirdly I can use the feature right away on the forums which I host and get people to make their own quizzes - I'm sure they'll be more creative than me and create kick-ass quizzes.

Tuesday, February 13, 2007

Microsites - Kickstarting a forum

In previous posts I have been describing my idea of using my online Japanese book & record store as a platform for kickstarting microsites around the bands / series sold, the theory being that if there is a popular microsite hosted under the site's domain and with a link back to the products being sold, this will attract customers and result in more valuable conversions than if the microsite was just a separate entity with AdSense ads or Amazon Affiliates ads on it (one purchase from my own store is A LOT more valuable to me than a purchase through Amazon would be).

I'm already very busy with my studies and running the web store as it is, so as the first easy part of the microsite experiment I decided to attempt to launch a forum around the band Antic Cafe. One thing I have learned is that people go crazy over prizes, so I decided to offer a prize to the most active person on the forum. In addition I dedicated some valuable screen estate on the store's main page to promote the forum. Here's what happened:

(162 absolute unique visitors)

The forum was promoted on the web store from the beginning. I marked the beginning and ending dates of the competition in black. It is clear that the competition had a major effect on amount of visits. The 11 members of the forum have written 147 posts up to now, which while modest seems like a good start for such a niche (Finnish fans of the Japanese band Antic Cafe) forum. I neglected to measure how many conversions this forum has created, but I'm not sure if that's even possible. Suppose a web store visitors goes to the forum, then comes back and buys an Antic Cafe record, is that a conversion? There seems to be no way to know if they got excited about the band on the forum or would have bought that record anyway.

I would like to launch the main microsite as well (this forum would be just one part), but I don't want to do that with completely pathetic production values. Also the forum might well be 80% of the microsite's value in the end, so why even bother with the rest?

Features I imagine that each microsite could have:
  • forum
  • polls (but forum already has polls...)
  • quizzes (can you recognize these members/characters from the band/series X?)
  • personality tests (which X are you?)
  • embedded videos (">veoh! youtube is so last year)
  • fanart submission, voting (maybe just a thread in the forum from which these are pulled?)
  • info pages for the series (through a wiki or pulled from forum threads)
  • news (perhaps an embedded RSS reader)
  • gallery (some clever system to get legal-size thumbnails linking to images elsewhere)
  • fan fiction
  • links (perhaps by automatically monitoring server logs for incoming links and favoring those)
Cool but impossible things:
  • exclusive band member / manga author interviews
  • exclusive content from the band / author
Perhaps most of these could use some embedded elements from other sites and would let me avoid actually coding them. If I could just find some good solutions for doing these, then I can use the same formula for a hundred different sites and save a ton of work compared to people who start single fansites for fun.

One option to consider might be to extend PhpBB to support these things. Perhaps there are already plugins for these? That would at least make it very easy to have just a single login that could be used for all of the microsites (since OpenID isn't here yet).

Saturday, February 03, 2007

Did some site reorganizing

I run a small village of microsites on different topics, it's sort of an experiment to see what sorts of traffic I can get. I had the domain jackvalenti.com, which I bought on a whim and set up an unofficial page about Jack Valenti there along with AdSense ads. Well, after spending nearly $100 on the site I am averaging ZERO visitors per day, so to avoid some site fees I am moving the content to a subdomain instead. From now on Jack Valenti page will be here instead.

Another more successful, but still an infuriatingly unsuccessful small site I had was a sweepstakes site. It runs on pligg and used to be in English. Every day I would check the stats on Google Analytics and every day I was getting around 200 visits, but nearly 100% from Finland through one nice inbound link I managed to get, so I will yield under the pressure and turn the site into a Finnish site to serve those visitors better. From now on it will be here: kilpailut.

One thing I have learned while trying to promote my sites is that people respond well to prizes. I had a forum that I was spending some promotion efforts on, but hardly nobody registered to that forum. Then I offered a prize for registering and posting on the forum and suddenly people (in the target group, not just prize scavengers!) started registering and posting. Prizes are expensive though, difficult to say if it makes sense to give them out. On a forum it is very important to reach a critical mass of posts at first, so it may help at that and possibly pay off in the long run.

Sunday, January 21, 2007

Microsites feature - forums

In my previous post I wrote about my intention to leverage the traffic I get to my online store to start microsites around product groups, such as different bands. I took my first step into that direction by tweaking PhpBB and doing some mod_rewrite trickery to allow me to easily create several forums which appear distinct, but are actually all running on the same software and database. This allows me to maintain only one installation of PhpBB and create a new forum in about 20 minutes instead of a complete new installation.

Obviously a microsite is going to need more than just a forum, but I imagine that for a successful microsite the forum would be the most important part of it. To test out the system I created two forums around two bands whose products I sell, Maruru forum and Antic-cafe forum.

Deciding scope


The reason for starting several small forums instead of one big one is to create a sense of belonging / identity for those using them. People seem to feel stronger attach ment to smaller circles. For example people will feel a connection to those attending the same school as them, at a lesser level to those living in the same city as them, even lesser to those from the same country. I want to find the optimal "circle size" to get people to feel that attachment, while not limiting fruitful conversations that could have happened if those circles were combined.

For example I could have created a "japanese music" forum instead of having "maruru" and "antic-cafe" as separate forums. Perhaps I should have, not sure, still experimenting. Certainly someone who is an enthusiastic fan of Antic Cafe would feel less at home at a generic forum for all Japanese music. Still there clearly has to be some minimum size at which an active forum is still possible, if there wasn't I could create a forum for people from Vatican who like Michael Jackson and are into cross-dressing. It would be a small group, but man would they be into it.

Wednesday, January 17, 2007

Microsites

I run a webstore, which means that I get very targeted audiences to my website. They will often even specify their interest by doing searches, or by looking at certain items. Mostly they are only looking, not buying, which is fine of course. Lately I have been wondering whether these targeted visitors could not be used to launch "microsites" related to certain products or product groups.

Take for example a person who searches for "dir en grey", then looks at products from the band dir en grey. Clearly they are quote interested in this band. Perhaps I could tell them "hey have you checked this fanpage for the band?". This could be a very relevant thing to say, and when things are relevant they tend to not be irritating. The trick of course would be that these fansites would actually be sites that I have launched myself (perhaps clearly indicated by being a subdomain of my site, say dir-en-grey.bemmu.com). They would become destinations in themselves, possibly growing and sending back more traffic to the webstore than I originally sent to them, also being nice baits for Google to index.

The microsites could contain a standard feature set and customized skin. For example a forum for talking about dir en grey, but with a forum template showing the dir en grey members. Forums have the effect of getting people to come back to check if their posts have been answered. Another good one is quizzes, which tend to be viral since people like to post the results on their homepages or recommend the quizzes to their friends.

Of course this is nothing new, there are plenty of dir en grey fansites out there, but I would like to make the process of launching these microsites very organized. All the sites would actually share one codebase. There might be 100 different microsites for different bands or manga series for example, but only one forum software running, customized to display a different skin for different audiences, but only requiring one login to use any of those sites. Same for the quizzes or possibly other features. The skins might have been outsourced somewhere, quizzes could be created by the users.

This whole idea might be impossible in that a certain amount of manual labor is always required for the maintenance of those sites. Forums need moderators. Quizzes also need moderation, since if they can be freely created by users there can be inappropriate content. Still by being clever I imagine that I could organize the creation of such microsites to be more efficient than the normal work of creating a fansite (of course these would not really be fansites in the traditional sense, but feature-wise they would be the same).

Amazon and other big webstores might be missing a great opportunity when they are only pushing products at the visitors, where they could be pushing communities as well.

Saturday, January 13, 2007

eBay API experiences

Lately I have been trying to learn how to use the eBay API to list items and learning exponential representation for complex numbers in Algebra. Using the eBay API is the harder one out of those. Just a minute ago I finally succeeded at listing my very first item by using the XML API, it was a bit more complex than I thought! My mental model for how the API would work was that I would pass my eBay user id and password, along with the item details wrapped in some XML.

Nope, there are several different kinds of keys involved. All in all I currently have NINE different pieces of authentication! I have a DevID, an AppID and a CertID. Then there is the eBayAuthToken and the REST API key (which I admittedly only used once for testing, it is not needed for the XML API). But wait, that's only five? Yes, but you see eBay has two servers -- production and sandbox. The sandbox is for testing, which is useful since listing things on the production server costs money, so you definitely don't want to end up listing ten thousand items by accident. The sandbox and production servers have completely different authentication keys, except the DevID appears to be the same (making it nine different keys total).

The eBay developer site doesn't make this sandbox and production server difference clear. When talking about authentication keys, they casually mention that oh yeah, there is the sandbox server too. But what they don't say (on the intro pages at least) is that you need completely different keys for those. So imagine my frustration at attempting to access the sandbox with my shiny new production keys. With all those different keys I was getting really hopeless and uninformed, mostly reading reddit instead of focusing on the problem.

Somehow after a lot of digging I managed to figure it out. A DevID identifies a developer. A developer may have multiple applications, with each application identified with its own AppID. CertID is a magical entity the purpose of which I don't understand, but things seem to work when I bundle the same CertID that came with the AppID. The eBayAuthToken must be generated on their web page, and generating that requires providing correct DevID, an AppID and a CertID for the server which you are trying to use (sandbox or production). In other words you cannot get an eBayAuthToken for the sandbox server by using the production DevID, an AppID and a CertID + vice versa. The REST key is needed only for... you knew it, making REST calls.

After I finally had my keys I started to read the API reference. I tried to pretend calmness, but actually I was a bit shocked of seeing all the possible method calls and the arguments they take. Huge list. Maybe I'm not enough in the XML camp, but in my mind things work like this: you get a template string of a working XML call, then you change the things which are different from what you want and send that string at the server, which then does something cool. It's pretty difficult to try to come up with something that works by just looking at an API reference if there are 20 different arguments that could go wrong! Luckily, the developer center has very nice examples of using the API, so I was able to get things working by copying and pasting their examples.

Another thing which seemed like a showstopper at first was that they require usage of SSL to access their server. That is an excellent thing of course for security, but complicates things a bit when you are just trying to get a minimal example to work. I was planning on using PHP, but felt a bit intimidated at the thought of figuring out how to get SSL working on it. Just to get acquainted with the API, I decided to stick with Perl as they had some nice Perl examples in the developer center, complete with instructions on how to install SSL support for Perl.

So I had my keys, I had an XML request constructed from the example and I had ActivePerl installed on my box, with LWP and SSL support, aaand... it worked!

Update: After 30 mins of reading some example code I managed to figure out how to make the same request using PHP, HTTPS with cURL! One thing I was worried about was how image uploading would work, but turns out that you can just specify an image URL and eBay's server will go and fetch it -- no need to figure out how to actually upload the data, what a time saver! Just a bit more effort and I'll have this code integrated with my web store.

Saturday, December 23, 2006

Another day another launch

Check my new site out if you are looking for expired domain names. It's the best list available, period.

Internet Explorer quirks

I am hacking my new site to get it to work on IE. After trying for a while I am instead applying for a gun permit and looking for the home address of the Microsoft employee responsible for implementing PNG support for IE.


Monday, December 04, 2006

Friday, November 17, 2006

Neverwinter Nights 2

Instead of writing tutorials on Half-Life, I decided to start writing tutorials on Neverwinter Nights 2 instead.

Wednesday, August 30, 2006

Google makes ads more difficult to recognize

I was searching for Yu-Gi-Oh card information and clicked on the first organic link I found, like I usually do.




The page I arrived to was an MFA (made for adsense) site. I thought gee, how is it possible that an MFA site got such a high pagerank that they could be the first result?

At first I thought there must be some new SEO trick out there, but then I noticed that what I had clicked on was in fact an advertisement. They used to be separated with a different color but now seem to have a white background like other search results. Aligned to the right there is a "sponsored link" disclaimer, but on a wide screen it is easy to miss.