February 24, 2012

Lost arts of octal numbers

Filed under: Uncategorized — zet @ 00:19

Every once in a while developers spend painful hours on figuring out why something is not working just to find out in the end that there is some even more painful truth behind it. I had such an experience just today. Ingredients: Actionscript 3, a hexagonal map, bitwise operating and, the cause of this post, octal number definition.

(more…)

February 4, 2012

Some more cave-ins

Filed under: Uncategorized — zet @ 00:31

I worked on that thing some more and it’s getting crazily interesting:


The screenshots are taken after several cave-ins happened. The boulders are toppling down when they fall, falling stuff rips off pieces from the sides… it’s really neat. There’s a game in this. At least one!

February 2, 2012

Mining in unsafe regions

Filed under: Uncategorized — zet @ 23:50

Here’s more. Use the mouse cursor to erase stuff. Basically, only worked on getting stability / unstability into the simulation. Caveins happen when an overhang gets too big. Pretty nice to play with. In the game, the player can build pillars and special material to improve stability. If something breaks, the region around it gets destabilized, which can cause more caveins. I should make a video of that :)

Work in progress: some mining game

Filed under: Uncategorized — zet @ 01:11

I don’t know where this is heading to, but I am heading to bed.


Try the arrow keys. Caveins are regular right now.

January 24, 2012

Android SDK: WebView doesn’t load files from asset directory on Honeycomb systems

Filed under: Android — zet @ 02:13

I ran into a bug or undocumented behavior on Honeycomb on the new tablet I got.  WebView components and the loadDataWithBaseURL method aren’t loading anything from the assets directory within the base URL of ”file:///android_asset/”. It just displays nothing. I looked around a lot and couldn’t find anything useful except “it’s not working” (See http://code.google.com/p/android/issues/detail?id=19293 for some more information, but it’s pretty fuzzy). Well, on my Nexus phone and various other models, everything is fine. Just my new tablet isn’t cooperating. So I looked for a workaround and found one.

(more…)

January 8, 2012

2nd Innogames 48h game jam

Filed under: as3,Box2d,Game Jam,Space Parcel Delivery — zet @ 04:09

PLAY LATEST VERSION

Ok, I am really tired – been participating in a 48 hour game jam of my company. I didn’t have so much time to work on it since I can’t work all weekend on this project. Thus, about 14 hours before the official deadline, I am uploading now my final version for the jam. I hope it’s some fun to play. It was nice to work this thing out and I am a little sad I can’t get another 10 hours to make some levels that are fun to play. But maybe I’ll make an Android game from this…

Err.. the game itself is somewhat similar to the old Space Taxi game – except it involves physics (box2d) and product delivery. Controls are arrows + d/c +space (well, see ingame help).
I concentrated mostly on the physics and how to use them, less on game design or artworks.

Changelist:
- V1.6: crate losing into space will be replaced now, minor changes
- V1.5: Longer rope, 4th level
- V1.4: Minor changes to levels and background
- V1.3: Different control of spaceship – no more direct engine control, instead, you set the altitude
- V1.2: No sound during showing help, engine particles are no longer on top of the helpwindow
- V1.1: Fixed crate bug, adjusted some physics parameters

Play space parcel delivery!

… and this is how it once looked like:

December 29, 2011

Quakatoo!

Filed under: Recombustor — zet @ 12:05

I’ve set up another blog (yay) which is focusing on my android game stuff – check it out if you are interested in that:

http://quakatoo.com/

 

 

September 27, 2011

Android Recombustor development update

Filed under: Recombustor — zet @ 19:48

The Android Recombustor app is progressing really slowly, though mostly because I find not much time. But it’s really getting somewhere I think:

There’s a new feature that is purely visually – the molecules are a bit “gluey” or “blobby” and adjacent balls are connecting. It can form quite long chains (as long as it’s not 3 in a row or more, then it dissolves):

The algorithm to find the borders efficiently was quite painful to develop and it still lacks some minor improvements (that would free a lot of calculation time, desperately wanted on the G1), but on a newer nexus, compiling the blobs takes about 10 milliseconds, which is ok (with optimizations, it could drop down to 2-5msecs). I went once again through quite a pain when dealing with the android API since a couple of things are not working as expected, as an example, here’s an alpha-rgb channel glitch that causes kind of black borders:

This is really nasty when it comes to small details and I only stumbled over it when I tried to use bitmaps to make the blobs work (the current approach is using rasterized floodfills) – the lesson learned was not to use the GLUtils.texImage2D method when the alpha channel is important.

But the performance of the bitmap blob blitting was way worse and the lack of proper alpha channel handling and operators was one of the reasons. I think on more modern devices, one could use shaders and render targets, but I don’t want to go that way as it would leave me without a solution on older hardware. Besides, I think it wouldn’t be much more efficient than the currently used algorithm. Well, maybe ten times faster but then again, I don’t really need high FPS rates, especially not on the more modern devices that have already plenty of CPU power.

 

 

 

 

 

 

July 1, 2011

GLSurfaceView problems

Filed under: Uncategorized — zet @ 16:36

I am looking into the Android Development Kit right now and went straight for OpenGL, rejoicing to see a simple-looking class to paint stuff. But … o-boy how bugged it is!

This is what I am talking about: http://android-developers.blogspot.com/2009/04/introducing-glsurfaceview.html

And here are the painful-pitfalls that I stumbled in and solved so far (not all – of course). It runs smooth and fine as long as you don’t deal with .onResume and .onPause. If you’re doing that, you’re already in the middle of threading without knowing. The GLSurfaceView class is using a thread that takes care about rendering, however, the looping is fragile and it even gives me more headaches when thinking about the potential impact on threadsafety and so on. And I only have begun to look into the ADK. Sigh.

So here are the trouble makers in detail:

Nr.1: http://code.google.com/p/android/issues/detail?id=2828 describes what can happen if you pause / resume an activity (which can happen already when just rotating the device’ screen). The device screen remains black and after some time a dialog offers you to terminate the activity. It seems to be a sort-of deadlock issue when trying to pause the state. It helps to call Thread.sleep after calling GLSurfaceVies.onPause() to give it time to settle down. I assume that the sleeptime should be at least as long as one frame needs to be rendered. This issue arises only if you’re in the RENDERMODE_CONTINUOUSLY mode.

Nr.2: After figuring that out, I decided to switch to RENDERMODE_WHEN_DIRTY because I also want to save battery powers and avoid unnecessary renderings. And guess what: More problems, similar, but yet different: http://www.mailinglistarchive.com/html/android-developers@googlegroups.com/2009-11/msg04528.html . The problem here is, that the dirty mode doesn’t cooperate with onPause cleanly either! So instead, you have to switch to the other buggy mode (RENDERMODE_CONTINUOUSLY) during onPause, WAIT to avoid the OTHER bug and when resuming, switch to the RENDERMODE_WHEN_DIRTY again!

Big fun, and it still doesn’t fit what I am experiencing now, check this out, this is what I am supposed to see:

But I am seeing this:

You could now think: Well, the background texture hasn’t yet loaded yet simply, or something failed, however: It’s one single picture – the symbols and the background share the same texture! So it hasn’t failed (completely). My first thought was that the texture is not being loaded fully when drawing the first screen (the background comes first of course). So I checked the threads and calling order and the problem doesn’t seem to be threading – in short, I have no idea what the cause of this trouble is, but right now, I can only fix it by enforcing a second rendering after the first one. This is really sort of annoying. Though I AM happy that I can use OpenGL for the drawing process.

Maybe the only reason for all this trouble is that I am developing for the G1, a fairly old device by now and so I am using an older API version, but still… couldn’t this issue be fixed and updated? Or maybe someone is afraid to touch this particular code because knowing that there’s stuff our there relying on it. Anyway, if you’re dealing with the GLSurfaceView class, be warned of strange behavior regarding initialization and deinitialization. If you’re in trouble, read the logcat output for any warnings or problems – googling for it in conjunction with the “GLSurfaceView” classname spits out most pointers to issues (except for a page that hints out all the pitfalls of that class).

April 23, 2011

Battleshipgame improvements

Filed under: as3,network,p7 — zet @ 20:44

I worked on a few improvements for the battlegame thing – quite a few actually.

Clientside position inter- and extrapolation and smoothing

One of the most important things was to make the interpolation work to counter lags. This seemed to be a complicated issue but turned out to be solved quite easily when not trying to make it “perfect”. First the facts: The simulation runs at 20 fps on the server, thus I receive one message every 5ms in a perfect network environment. The client runs with a framerate of about 60 frames per second.

However, due to the network traffic and network buffering (which I have not full control on in flash and I don’t know how flash deals with it), the network packages come in in intervals of 0-20ms. AS3 supports only TCP connections. On the upside, this means that it’s quite stable and there’s no packet loss. On the downside, if a packet is lost, the client (or server) tells the other side to resend it – and that costs plenty of time. Meanwhile, many more packets arrive – but I can’t receive them as the OS holds them back until the lost package was received. And then it flushes the whole buffer at once. This behavior is highly undesirable when dealing with fast paced games – which is why I thought a battle ship game with slow controls is better suited for this kind of network technology.

The solution to the lagging when representing the actual scene of received data instantly is to inter- and extrapolate values next to smoothing the final results. What sounds complex is actually really pretty simple: When a ship moves, I calculate the current velocity and angular velocity from the previously received data. I could also include movement speed, but that isn’t really needed since velocities don’t change so quickly. I decided to let the client lag by 5ms compared to the server simulation, so when receiving the state from the server, I don’t move the ships instantly to the “new” positions, but I interpolate the position for the next 5 ms. When the 5ms are over and I haven’t received new data, I extrapolate the position from the known velocity. Both, inter- and extrapolation are however one single term: position + velocity*time_fraction – where time_fraction is a value between 0 and 1 for the 5ms intervals. When no new data is received, I simply let the time_fraction go on to higher values, effectively extrapolating the position of the ship on the server.

If I would do only that, the ship would jump whenever a network delay is corrected since the extrapolation isn’t showing the correct solution. To prevent visual lags from happening, I simply smooth move the ship only for a fraction towards the interpolated values (which can change suddenly when receiving a delayed package). So the actual formula is

screen_position = screen_position*.7 + .3*(position + velocity*time_fraction).

The values .7 and .3 are chosen pretty randomly – for these numbers, sudden movement changes will get smoothed over 3-4 frames until a relatively close screen position is reached (close to the actual position).

So nothing fancy and actually not applicable for faster games, but fine for this one. Oh, and the cannon balls are simulated on the client side from knowing the shot’s origin and the speed at that time.

Extended statistics

I extended the statistics I am gathering. I track now the amount of incoming and outgoing data and also log certain events (coming, going and sinking of ships). This was actually much more work than anticipated – I am using sqlite as database backend and Lua as the server side language. Since I do not use threading on the server, database access would introduce too much delays. So I needed to come up with something more fancy than simple query execution inside the game logic. Oh boy, this took a while…

After having found out that the db access is introducing lags, I thought about using Lua lanes, a multithreading library for Lua. But then again, I didn’t want to add more libraries on top of my requirements. So I decided that I “simply” start a second process using io.popen and communicate with it through stdin and stdout. There were a few shortcomings to that and I finally ended up with one process that listens on a tcp port for sql execution statements. The game process sends data in batched packages to the database socket and doesn’t wait for it’s completion. There’s a fair chance of data loss when something goes wrong, but for this kind of data (statistics), it’s quite unimportant… so it’s sort of acceptable.

Webfrontend

To have a simple way to look up the stats, I wrote a small webservice that presents the current statistics. It’s listening on port 9293, so if you follow the link, you can see the current stats.

So what’s next? I think I want to add a bot that provides a challenge when other players aren’t available.

Older Posts »
Copyright Eike Decker 2009