News:

Simutrans Sites
Know our official sites. Find tools and resources for Simutrans.

A tool to convert maps into minimap graphics

Started by Ashley, May 18, 2011, 05:38:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ashley

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!
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

prissi

All those, as written countless time, is much easier achieved within simutrans. It would be no problem to make simutrans generate such a snapshot.

Ashley

That's what I want to do, but as a command line tool which can be used as part of an automated process.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Dwachs

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.
Parsley, sage, rosemary, and maggikraut.

Ashley

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?)
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

VS

Just out of curiosity, are you [currently] planning to save the minimap on server, or from nettool?

My projects... Tools for messing with Simutrans graphics. Graphic archive - templates and some other stuff for painters. Development logs for most recent information on what is going on. And of course pak128!

Ashley

#6
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...
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Dwachs

Parsley, sage, rosemary, and maggikraut.


Ashley

#9
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.
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.

Dwachs

QuoteThe 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.
Parsley, sage, rosemary, and maggikraut.

Ashley

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 :)
Use Firefox? Interested in IPv6? Try SixOrNot the IPv6 status indicator for Firefox.
Why not try playing Simutrans online? See the Game Servers board for details.