:: Home :: Get Hosted :: PPM FAQ :: Forum FAQ :: Privacy Policy :: Search :: Memberlist :: Usergroups :: Register :: Profile :: Log in to check your private messages :: Log in ::
Do you want to advertise at Project Perfect Mod. Find out how to do it HERE.

The time now is Fri Apr 03, 2020 1:23 am
All times are UTC + 0
 Forum index » Modding Central » Tiberian Sun Editing Forum
TSMapPreviewToolIran
Moderators: Global Moderators, Tiberian Sun Moderators
Post new topic   Reply to topic Page 1 of 1 [9 Posts] View previous topic :: View next topic
Author Message
Iran
Pyro Sniper


Joined: 23 Mar 2011

PostPosted: Sat Jan 04, 2020 9:31 pm    Post subject:  TSMapPreviewToolIran Reply with quote

This is my map preview tool. It uses the in-game renderer and a command-line tool. Run TSMapPreviewToolIran.exe.

Uses cnc-ddraw GDI renderer with 14000x6500 resolution. A modified ts-spawner is used to spawn into the game and automatically grab a screenshot and then exit the game. The command-line tools opens the screenshots, gets map size from map INI and crops out map size roughly.

Spawner loads spawnmap.ini. Spawn.ini has two new options:
DoScreenshotOnceThenExit=Yes/No
DoScreenshotOnceThenExitFrame=0 (on which frame do we screenshot and then exit?)

The command line tool has two arguments. First argument is ShowSpawnIndicators/DontShowSpawnIndicator.s This will copy spawn_indicator.ini in the folder into spawnmap.ini. The idea is that you modify the MCV to show a spawn indicator and place this mod inside spawn_indicator.ini (you need to do this yourself).

Second argument is the map file to make a screenshot of, if this arg is missing then spawnmap.ini is used.

Note: this should also work with savegames, you might need to set DoScreenshotOnceThenExitFrame=-1 then though.


https://www.dropbox.com/s/vf7s6xmbbu0lv8n/mapPreview_iran_files.zip?dl=0

C# code:

Code:
using ImageMagick;
using IniParser;
using IniParser.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TSMapPreviewToolIran
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0 && args[0] == "ShowSpawnIndicators")
            {
                string[] Lines = File.ReadAllLines("spawn_indicators.ini");
                File.AppendAllLines("spawnmap.ini", Lines);
            }

            if (args.Length > 1)
            {
                string mapfile = args[1];
                File.Copy(mapfile, "spawnmap.ini", true);
            }

            File.Delete("SCRN0000.pcx");

            var parser = new FileIniDataParser();
            IniData data = parser.ReadFile("spawnmap.ini");

            //string MapSize = data["Map"]["Size"];

            //Left,Top,Width,Height
            string LocalSize = data["Map"]["LocalSize"];
            string[] split = LocalSize.Split(',');
            int left = int.Parse(split[0]);
            int top = int.Parse(split[1]);
            int width = int.Parse(split[2]);
            int height = int.Parse(split[3]);

            int previewWidth = (width - left) * 48;
            int previewHeight = (height - top) * 24;

            var process = Process.Start("mappreview.exe", "-SPAWN");
            process.WaitForExit();

            var image = new MagickImage("SCRN0000.pcx");
            image.Crop(new MagickGeometry(0, 20, previewWidth, previewHeight));
            image.ToBitmap().Save("out.png");
        }
    }
}


Custom ts-patches for this will be posted on github.com/cncnet/ts-patches when I do a pull request.

Last edited by Iran on Tue Feb 04, 2020 10:13 pm; edited 1 time in total

Back to top
View user's profile Send private message
E1 Elite
Commander


Joined: 28 May 2013

PostPosted: Sun Jan 05, 2020 3:17 am    Post subject: Reply with quote

Nice, it works.

As the map sizes are a variable, so should be the resolution in sun.ini or ddraw parameter. Theoretical max map size is 511x1 or 1x511. With a cell size in TS being 48x24, max width needed is 24528 and can round it off for sidebar to 25000. Max height needed is 511*24 = 12264, rounding it to 12300. But we can't have a resolution of 25000x12300 as the game crashes at about 95275000 area value (w*h) at the extreme. So, the resolution could use the map size multiplied by 48x24 and with some buffer for the sidebar and topbar.

Back to top
View user's profile Send private message
Iran
Pyro Sniper


Joined: 23 Mar 2011

PostPosted: Sun Jan 05, 2020 11:21 am    Post subject: Reply with quote

That's of course not an issue to program, takes a few lines. Do you have an example map?

Back to top
View user's profile Send private message
E1 Elite
Commander


Joined: 28 May 2013

PostPosted: Sun Jan 05, 2020 3:02 pm    Post subject: Reply with quote

1 cell width maps are not practical and have problems with the game. Attaching 492x20 and 20x492 sized maps. You can create such maps yourself with patched FinalSun for TSClient.

Game limit is W+H <= 512. FinalSun crashes at about W*H more than 43500. Included a map of size 256x256 that crashes FinalSun. If you get time can you check the problem with larger area maps in FinalSun. Can make blank maps and its [Map] Size can be changed in a text editor to get different sized maps also.


492x20_20x492_256x256.7z
 Description:

Download
 Filename:  492x20_20x492_256x256.7z
 Filesize:  74.7 KB
 Downloaded:  0 Time(s)


Back to top
View user's profile Send private message
Iran
Pyro Sniper


Joined: 23 Mar 2011

PostPosted: Tue Feb 04, 2020 10:12 pm    Post subject: Reply with quote

The patches for this have now been merged with github.com/cncnet/ts-patches .

This will enable

Spawner loads spawnmap.ini. Spawn.ini has two new options:
DoScreenshotOnceThenExit=Yes/No
DoScreenshotOnceThenExitFrame=0 (on which frame do we screenshot and then exit?)


Use it in combination with the C# code from my first post.

Back to top
View user's profile Send private message
E1 Elite
Commander


Joined: 28 May 2013

PostPosted: Wed Feb 05, 2020 2:57 am    Post subject: Reply with quote

Is resolution fixed still or varies with map size? May be the client would have to check renderer(s) or sun.ini, change the resolution and restore current resolution after screenshot.

Back to top
View user's profile Send private message
Iran
Pyro Sniper


Joined: 23 Mar 2011

PostPosted: Wed Feb 05, 2020 3:44 am    Post subject: Reply with quote

still fixed but it isnt hard to change that, the C# code in the OP already does pixel width and height calculations.

Bittah has shown interest in using this so and was asking about renderers so I'll have him test a bit.

Back to top
View user's profile Send private message
E1 Elite
Commander


Joined: 28 May 2013

PostPosted: Wed Feb 05, 2020 4:18 am    Post subject: Reply with quote

Users might be using cnc-ddraw or ts-ddraw or may be using resolution from sun.ini. Those renderers currently use ddraw.ini with or without resolution override. Wouldn't it be better in this case to feed the needed resolution directly to the game.exe so that none of the INI files need to be altered?

Back to top
View user's profile Send private message
Iran
Pyro Sniper


Joined: 23 Mar 2011

PostPosted: Wed Feb 05, 2020 4:52 am    Post subject: Reply with quote

Maybe, once people give feedback we'll know.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [9 Posts] View previous topic :: View next topic
 Forum index » Modding Central » Tiberian Sun Editing Forum
Jump to:  
Share on TwitterShare on FacebookShare on Google+Share on DiggShare on RedditShare on PInterestShare on Del.icio.usShare on Stumble Upon
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © phpBB Group

[ Time: 0.1302s ][ Queries: 12 (0.0059s) ][ Debug on ]