The International Simutrans Forum

 

Author Topic: A tool to convert maps into minimap graphics  (Read 3095 times)

0 Members and 1 Guest are viewing this topic.

Offline Ashley

  • Coder/Patcher
  • Devotee
  • *
  • Posts: 1288
    • entropy.me.uk
A tool to convert maps into minimap graphics
« on: May 18, 2011, 05:38:42 PM »
Hello all,

I'd like some guidance... I have an idea to write a tool which can load a Simutrans save game file and then write out a .png image containing essentially a screenshot of the minimap as it would be displayed in-game. The easiest way to do this would be to write a tool which makes use of the functions built into Simutrans of course (similar to the nettool tool does for network-related admin).

What I'd like to know is roughly how difficult this would be, and maybe some pointers to the right bits of the code to look at. Would I need to completely load the map and initialise the game engine etc. to do this, or could I just make use of the minimap generation bits to work directly on the save game data? At the moment all I have is an idea, and no idea where to start on making it into a reality...

(Such a tool would be of great usefulness to generate minimap screenshots of a map which you could then use to provide an overview of how the game developed through time. I'd like to, say, save a minimap image every hour for a network game so you could see the progression of a network being built. This would also let me save a start/end image of the map automatically for archival purposes).

Thanks!

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 9566
  • Languages: De,EN,JP
Re: A tool to convert maps into minimap graphics
« Reply #1 on: May 18, 2011, 09:44:50 PM »
All those, as written countless time, is much easier achieved within simutrans. It would be no problem to make simutrans generate such a snapshot.

Offline Ashley

  • Coder/Patcher
  • Devotee
  • *
  • Posts: 1288
    • entropy.me.uk
Re: A tool to convert maps into minimap graphics
« Reply #2 on: May 18, 2011, 09:51:54 PM »
That's what I want to do, but as a command line tool which can be used as part of an automated process.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4601
  • Languages: EN, DE, AT
Re: A tool to convert maps into minimap graphics
« Reply #3 on: May 19, 2011, 05:23:36 AM »
Why not writing the tool as part of simutrans, and then adding functionality to the nettool to trigger saving of minimaps?

In order to compute the minimap, you need to load everything and initialize the game engine.

Offline Ashley

  • Coder/Patcher
  • Devotee
  • *
  • Posts: 1288
    • entropy.me.uk
Re: A tool to convert maps into minimap graphics
« Reply #4 on: May 19, 2011, 07:46:09 AM »
Just to be clear, I want to include this functionality in Simutrans, not write a complete new tool entirely from scratch. Adding it to the nettool seems like a reasonable idea.

Which bits of the code are responsible for minimap creation? Also what image formats can Simutrans write out to (can it write png directly?)

Offline VS

  • Senior Plumber (Devotee)
  • Devotee
  • *
  • Posts: 4855
  • Vladimír Slávik
    • VS's Simutrans site
  • Languages: CS,EN
Re: A tool to convert maps into minimap graphics
« Reply #5 on: May 19, 2011, 09:39:12 AM »
Just out of curiosity, are you [currently] planning to save the minimap on server, or from nettool?

Offline Ashley

  • Coder/Patcher
  • Devotee
  • *
  • Posts: 1288
    • entropy.me.uk
Re: A tool to convert maps into minimap graphics
« Reply #6 on: May 19, 2011, 10:08:17 AM »
My plan is to modify nettool so that it has another command (say, getmap map-detail) which asks the server to send it a full-size representation of the current map in binary format, nettool will then print this to stdout in hex format. That hex format dump can be processed using some other tool into a .png image of the map.

From looking at the code this shouldn't be too hard to do. It won't be able to do things like city names on the map since it looks like these are drawn onto the map using the graphics engine after the map is generated graphically. Thus I might also have the getmap method send back a list of cities/coordinates so I can just draw these onto the map myself. The output format will be as simple as possible, literally a newline-separated hex dump. I already have a Python script which converts this form of data (along with the Simutrans .pal file) into a .png image.


Edit: I have I think a patch which does this (attached). I haven't been able to test compile it yet though. Am I going about this the right way? I've added an option to nettools.cc, a case to network_cmd_ingame.cc (in the nwc_service_t::execute method), a case to network_cmd.cc (in the nwc_service_t::rdwr method) and I'm using some additional values defined in the nwc_service_t definition in the network_cmd.h header file.

No idea if this even compiles properly yet, but I wanted to check that this is the correct way to go about making these changes...
« Last Edit: May 19, 2011, 04:01:33 PM by Timothy »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4601
  • Languages: EN, DE, AT
Re: A tool to convert maps into minimap graphics
« Reply #7 on: May 19, 2011, 08:38:50 PM »
Looks good so far!

Offline IgorEliezer br

  • Devotee
  • Administrator
  • *
  • Posts: 4087
  • Cake recipes are cool... REALLY!
    • Igor Eliezer Architect and Urban Planner/Arquiteto e Urbanista
  • Languages: PT, EN, AutoLISP, Python
Re: A tool to convert maps into minimap graphics
« Reply #8 on: May 19, 2011, 11:14:44 PM »
Just saying: I like the tool. :D

Offline Ashley

  • Coder/Patcher
  • Devotee
  • *
  • Posts: 1288
    • entropy.me.uk
Re: A tool to convert maps into minimap graphics
« Reply #9 on: May 20, 2011, 08:25:27 AM »
Is there an upper limit to the size of a network packet? I mean, obviously "on the wire" there is which would typically be 1500 bytes, but I am finding if I try and just create a nwc_service_t and add 512*512 bytes to it, and then send it that it fails, but doing the same thing with say 10*10 bytes works fine. I am guessing that the sending routine isn't splitting the data up into multiple packets to send over the network and expects the data to be less than some upper limit within the game? (Edit: Yes there is a limit, this is probably why big things like the savegame file are transferred as files after being written to disk...)

I also notice that the gameinfo_t object gets written out to file and then transferred using network_send_data in 1024 byte chunks. I guess this is to take advantage of the compression routine as well as to buffer the amount of data needing to be kept in memory? Given that the gameinfo_t object has to exist in-memory before being written out actually maybe it's just for the compression.


Edit: Ok I have a working implementation of this now, up to a point. I have a command I can send to the server which makes the server write the map information out to a file. I don't know how much utility there would be in transferring that file back to the nettool since I really envisage running nettool on the same machine as the server. Some kind of filter for nettool connections to limit them to a specified range of IPs would be useful (e.g. only allow administrative commands from localhost). I'll see if I can implement that next.

I also spotted a couple of potential bugs which I will make patches for. One is that the temporary file written out during send of gameinfo is called the same thing for all servers, so if you had multiple instances running in the same directory the potential is there for them to clobber each other's files. This should be a simple fix by renaming the files to include the server's port (much like the network save files).

The nettool case/switch statement also is missing some break statements, so for example sending an admin message causes the server to shut down.
« Last Edit: May 20, 2011, 05:01:45 PM by Timothy »

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4601
  • Languages: EN, DE, AT
Re: A tool to convert maps into minimap graphics
« Reply #10 on: May 22, 2011, 07:07:49 PM »
Quote
The nettool case/switch statement also is missing some break statements, so for example sending an admin message causes the server to shut down.
This is now fixed.

Offline Ashley

  • Coder/Patcher
  • Devotee
  • *
  • Posts: 1288
    • entropy.me.uk
Re: A tool to convert maps into minimap graphics
« Reply #11 on: May 22, 2011, 11:23:05 PM »
http://forum.simutrans.com/index.php?topic=7355.0

Just posted a preliminary patch for nettool (not related to the map graphic command directly) and I'd appreciate some feedback on that too :)

Thanks for fixing the case statement issue too :)