OpenStreetMap Forum

The Free Wiki World Map

You are not logged in.

Announcement

The forum software has recently been upgraded. Not all previous modifications have been re-applied yet, see here for more info and problem reporting.

#1 2016-02-09 14:58:13

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Simple OSM game: Find the nearest train station

Hello,

I'm in a process of developing a bigger game using the OSM data, but first I had to start with something simpler smile

So, for now we have this "find the nearest train station". The player is starting in a random city across the world. He can move via the keyboard arrows and have to reach any target.

It is not something big or exciting, but for me it moved me forward in some big directions:
* getting used to the Overpass API - really cryptic syntax for complex queries
* getting used to Mapbox and Leaflet - they are so different from what I know of OpenLayers and Gmap API
* implementing fog of war over tiled map - it is currently not used here here, because it is not really enhancing the gameplay, but at least I found a way of doing it

Some improvements that can be done here:
* add a countdown timer, to make losing a possibility
* add a way to track high-scores, maybe with a timer? - done in Enemies
* interpret ways with railway=station, currently only nodes tagged as stations are used for destinations - done

I'm open for any remarks and ideas smile

Last edited by ivanatora (2016-02-12 15:49:18)

Offline

#2 2016-02-12 07:08:30

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Re: Simple OSM game: Find the nearest train station

Hi again smile

Second iteration of the game project is here. This time we have enemies on the map! They are bad, they are chasing you, and if they got you, it is game over.

They spawn at shops (because shops are evil) and move towards you if you are close enough. Their speed is a bit lower than yours, so they are definitely escapeable.

Some technical remarks:
* not every starting location has a train station nearby. Maybe switch to different type of win target?
* Overpass servers don't allow running two concurrent queries from the same IP. Have to make sure one is complete before launching the other.
* Scoreboard is still in the TODO list - done!
* There is a big thing in the TODO list - make player and enemies move only on roads. Still have no idea how to implement this one, though smile
* Sometimes map is bouncy. If you move too hard in one direction there is some visual jerk happening. Could it be due to map tiles not being completely loaded in that direction?

Last edited by ivanatora (2016-02-12 15:59:01)

Offline

#3 2016-02-16 15:37:59

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Re: Simple OSM game: Find the nearest train station

Third version here smile In Pursuit we have buildings impairing enemy line of sight, and player's movement. We have a proper splash screen and nicer icons.

Also, there is a possibility for starting in a set location, via URL parameters: http://osm-game.ivanatora.info/leaflet/ … /24.750000


Some technical remarks:
* fetching buildings is another Overpass API request, and I might start getting too many requests. I may have to run a local Overpass server to increase response time a little, but I can't host the entire planet dump. If I get to do it that way, I might have to restrict the playing space to only few countries, which would be pity. Also, I don't wish the game to depend on my local Overpass server...
* TODO: optimizing the visibility algorithm - it is almost bruteforcing enemies vs all buildings and it is so slow now...
* TODO: if enemy doesn't have LOS to player, he should lose him as a target, not just slow down
* TODO: nicer popups for Score and Howto
* TODO: major code refactoring as it is getting pretty messy with all the new features

Last edited by ivanatora (2016-02-16 17:33:00)

Offline

#4 2016-02-20 08:25:44

Zverik
Member
From: Москва
Registered: 2010-10-14
Posts: 5,058
Website

Re: Simple OSM game: Find the nearest train station

You've got great ideas :)

Tiles are not showing for me, since I have a retina display, and mapbox.js adds '@2x' to tile addresses. I'd recomment either using leaflet.js, or finding another method for disabling that misfeature. E.g. setting L.Browser.retina = false.


ШТОСМ | josm.ru | osm радио | обо мне | garage hacker from craps.me

Offline

#5 2016-02-21 14:33:22

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Re: Simple OSM game: Find the nearest train station

Thanks for the feedback!

Switched from Mapbox to Leaflet on your suggestion. It is in the new version - Warp. What is new here:
* Enemies don't rush straight to the player if they can't see him. They also can "loose track" of player if not in line of sight.
* The game doesn't finish once you get to the train station, but instead you have the option to warp to another city and continue endlessly. Not very much of use now, but I have ideas for lots of exciting features smile including: player inventory, complex battles, gathering squad of followers and other completely different game modes (i.e. incremental resource gathering, exploring randomly generated building insights, etc).
* TODO: look and feel of popups still feels wrong.

Offline

#6 2016-02-21 17:11:32

Zverik
Member
From: Москва
Registered: 2010-10-14
Posts: 5,058
Website

Re: Simple OSM game: Find the nearest train station

Nice, it works!
On a popup map with all the stations, you can still move a marker with arrow keys.
Also, can you make it move only across roads?


ШТОСМ | josm.ru | osm радио | обо мне | garage hacker from craps.me

Offline

#7 2016-02-22 10:22:35

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Re: Simple OSM game: Find the nearest train station

> Also, can you make it move only across roads?

This is a thing, I've been wanting to do for a long time. I will move it up my queue of things to do smile

Offline

#8 2016-02-26 13:04:49

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Re: Simple OSM game: Find the nearest train station

I'm back with Roadster! smile This time player movement is going on only on highways, instead of just flying above everything. Had lots of concept issues and involved loooots of math here, it is possibly buggy as hell smile The splash screen is also pimped up a little.

I've left the red highway wireframe visible, and there is a ton of debugging going on (hit F12 and watch the theater when you move the player around). This will probably stay for awhile, until I have some more stable codebase.

TODO: My own Overpass server. Really. The number of queries is getting a little too many for the public server. Sadly, this means the game territory will probably be limited only to European cities, as my computer has limited amount of storage... But it will solve many issues. For example currently only small amount of game data is downloaded (roads, enemies, targets) and it is done only at the game startup.
TODO: Make enemies follow roads, too. Should not be too difficult now when I have the code.
TODO: Prettify the latest code. Currently it is looking like a hungry bulldog has rampaged around. There were lots of new concepts for me to deal with, and it is a mess.
TODO: Prettier popups (I'm dragging this across releases, will have to pay attention to it soon)
TODO: Fixing the case when the user is trying to smash his arrow keys.

Last edited by ivanatora (2016-02-26 13:14:53)

Offline

#9 2016-03-06 00:32:55

Geonick
Member
From: Switzerland
Registered: 2009-04-22
Posts: 11
Website

Re: Simple OSM game: Find the nearest train station

Hi Ivanatora

Very nice game Roadster: http://osm-game.ivanatora.info/leaflet/roadster
Following questions and hints:
* After successful reaching of a station, the game presents an overview map: What does this want to show? How can I proceed?
* How can I quit and/or restart the game? I'd expect ESC?
* Sometimes avatar seems stuck/frozen and I can't move anymore (often at a dead end road). What can I do?
* There are scores: What is my user name in the game? Can I set it?
* Pls. don't forget to set credits lower right to "(c) OpenStreetMap contributors | Improve this map" (weblinks to http://www.openstreetmap.org/copyright and http://www.openstreetmap.org/fixthemap)

BTW: You speak about installing own Overpass server. What about simply using this SW stack: osm2pgsql, PostGIS and e.g. http://postgrest.com ?

Offline

#10 2016-03-07 13:42:07

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Re: Simple OSM game: Find the nearest train station

Hi, Geonick and thank you for your feedback!

> * After successful reaching of a station, the game presents an overview map: What does this want to show? How can I proceed?
The overview map is to move to another nearby city after successfully reaching the goal. You simply select any of the city markers (if there are any). This needs better explanation, that is true.

> * How can I quit and/or restart the game? I'd expect ESC?
I can set it on ESC, but since this is a browser game, F5 is good enough.

> * Sometimes avatar seems stuck/frozen and I can't move anymore (often at a dead end road). What can I do?
Maybe you have reached the end of the downloaded road segments. Currently the game downloads only all the roads in a 1km radius of the player's starting point.

> * There are scores: What is my user name in the game? Can I set it?
Scores are left over from a previous version. In that one, when you reach a train station it is a game over and you can enter a high score. I should remove that feature, as there is no fixed "end" in the current version.

> * Pls. don't forget to set credits
With a pleasure. Thank you for reminding me.

That stack looks like a big hassle and too much stuff running on my computer. I've had Overpass server before and it was relatively simple setting it up. The problem now is that the European dump is a gigantic one (~25GB compressed). I've tried to extract only data I need from it with Оsmosis, but it looks like the Оsmosis in the Ubuntu repo is too old and have compliance issues.

Offline

#11 2016-03-07 17:23:25

stephan75
Member
Registered: 2008-05-28
Posts: 2,532

Re: Simple OSM game: Find the nearest train station

ivanatora wrote:

... I've tried to extract only data I need from it with Оsmosis, but it looks like the Оsmosis in the Ubuntu repo is too old and have compliance issues.

A recent Osmosis version is really recommended when dealing with OSM data.

When you are really not able to install a recent version on your own, have you ever tried

http://wiki.openstreetmap.org/wiki/Osmfilter

as an Osmosis replacement?

Offline

#12 2016-03-08 10:14:38

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Re: Simple OSM game: Find the nearest train station

I haven't used it. Looks promising, might try it. I did manage to run the latest Osmosis last night from a precompiled binary. Even got it to filter tags, and then when bzipping the result I found out my hard drive is failing roll
Still don't know if tag filtering would reduce the db size, but at least I'm getting a new drive. Larger drive with proper partitioning and I might even be able to import that whole Europe dump that got me into Osmosis trouble in the first time smile

Offline

#13 2016-03-12 10:16:15

ivanatora
Member
Registered: 2011-04-05
Posts: 56

Re: Simple OSM game: Find the nearest train station

Small update: enemies are now using the same highway grid and not just fly around. They still need proper routing - Dijkstra or something, because their current navigation if very rudimentary based only on line of sight.

Update: Dijkstra done! Enemies now have proper routing smile

I have an issue with installing the Overpass server. I'm trying to feed it the Europe dump, but I'm getting an error:

Reading XML file ...terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
./init_osm3s.sh: line 44:  3818 Broken pipe             bunzip2 < $PLANET_FILE
      3819 Aborted                 (core dumped) | $EXEC_DIR/bin/update_database --db-dir=$DB_DIR/ $META $COMPRESSION

As from I can see from the init script, it goes like this:

bunzip2 <$PLANET_FILE | $EXEC_DIR/bin/update_database --db-dir=$DB_DIR/ $META $COMPRESSION

It seems bunzip2 have issues feeding the db extract trough the pipe? Why it would be so?

I tried even with smaller country-wide dump (~100MB) and it still fails with Broken pipe.

[EDIT]

It seems the problem is not related with bz. I uncompressed my country dump and tried to feed it directly to the update_database script, it failed:

]$ cat ../../bulgaria-latest.osm | ./update_database --db-dir=/mnt/alpha/ivanatora/osm3s_db/
Reading XML file ... finished reading nodes. terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

[EDIT2]

Google suggest it is a insufficient memory thing. I have 4G RAM + 4G swap on this machine... How much does the install script needs? I see it uses about ~40% memory and there is lots of free memory.

[EDIT3]

I found this in the readme:

Try adding --flush-size=1 as a parameter when calling update_database, so in most cases, add the parameter to the last line in the init_osm3s.sh script

The init script is now finally running, and hopefully I will have OSM3S on tonight smile

[EDIT4]

40-something hours later, the script is still going. My DB dir is about 43G and I think it should get at least 300G... It goes way too slow and I might have to kill it at some point today or tomorrow sad

Last edited by ivanatora (2016-03-14 13:37:54)

Offline

Board footer

Powered by FluxBB