The International Simutrans Forum

 

Author Topic: Shortening dat files with image-templates  (Read 5300 times)

0 Members and 1 Guest are viewing this topic.

Offline Leartin

  • Heir-Benevolent-Dictator-Apparent
  • Devotee
  • *
  • Posts: 1469
  • PAK-DEV P192C
  • Languages: DE, EN
Shortening dat files with image-templates
« on: January 09, 2016, 02:31:48 PM »
The following code is the image definition of one citybuilding:

Code: [Select]
BackImage[7][0][0][1][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.0
BackImage[7][0][0][0][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.0
BackImage[6][0][0][1][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.1
BackImage[6][0][0][0][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.1
BackImage[5][0][0][1][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.2
BackImage[5][0][0][0][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.2

BackImage[0][0][0][1][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.0
BackImage[0][0][0][0][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.0
BackImage[2][0][0][1][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.0
BackImage[2][0][0][0][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.0
BackImage[4][0][0][1][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.1
BackImage[4][0][0][0][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.1
BackImage[1][0][0][1][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.2
BackImage[1][0][0][0][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.2
BackImage[3][0][0][1][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.2
BackImage[3][0][0][0][0][0]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.2

BackImage[7][0][0][1][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.0
BackImage[7][0][0][0][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.0
BackImage[6][0][0][1][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.1
BackImage[6][0][0][0][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.1
BackImage[5][0][0][1][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.2
BackImage[5][0][0][0][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.2

BackImage[0][0][0][1][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.0
BackImage[0][0][0][0][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.0
BackImage[2][0][0][1][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.0
BackImage[2][0][0][0][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.0
BackImage[4][0][0][1][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.1
BackImage[4][0][0][0][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.1
BackImage[1][0][0][1][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.2
BackImage[1][0][0][0][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.2
BackImage[3][0][0][1][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.2
BackImage[3][0][0][0][0][1]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.2

BackImage[7][0][0][1][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.0
BackImage[7][0][0][0][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.0
BackImage[6][0][0][1][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.1
BackImage[6][0][0][0][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.1
BackImage[5][0][0][1][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.2
BackImage[5][0][0][0][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.2

BackImage[0][0][0][1][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.0
BackImage[0][0][0][0][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.0
BackImage[2][0][0][1][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.0
BackImage[2][0][0][0][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.0
BackImage[4][0][0][1][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.1
BackImage[4][0][0][0][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.1
BackImage[1][0][0][1][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.2
BackImage[1][0][0][0][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.2
BackImage[3][0][0][1][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.2
BackImage[3][0][0][0][0][2]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.2

BackImage[7][0][0][1][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.0
BackImage[7][0][0][0][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.0
BackImage[6][0][0][1][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.1
BackImage[6][0][0][0][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.1
BackImage[5][0][0][1][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.2
BackImage[5][0][0][0][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.2

BackImage[0][0][0][1][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.0
BackImage[0][0][0][0][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.0
BackImage[2][0][0][1][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.0
BackImage[2][0][0][0][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.0
BackImage[4][0][0][1][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.1
BackImage[4][0][0][0][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.1
BackImage[1][0][0][1][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.2
BackImage[1][0][0][0][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.2
BackImage[3][0][0][1][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.2
BackImage[3][0][0][0][0][3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.2


BackImage[7][0][0][1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.3
BackImage[7][0][0][0][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.3
BackImage[6][0][0][1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.4
BackImage[6][0][0][0][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.4
BackImage[5][0][0][1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.0.5
BackImage[5][0][0][0][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1.5

BackImage[0][0][0][1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.3
BackImage[0][0][0][0][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.3
BackImage[2][0][0][1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.3
BackImage[2][0][0][0][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.3
BackImage[4][0][0][1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.4
BackImage[4][0][0][0][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.4
BackImage[1][0][0][1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.5
BackImage[1][0][0][0][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.5
BackImage[3][0][0][1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2.5
BackImage[3][0][0][0][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3.5


Frontimage[7][0][0][0][0][0]=images/Stadtgruen_1.0.0
Frontimage[6][0][0][0][0][0]=images/Stadtgruen_1.0.1
Frontimage[5][0][0][0][0][0]=images/Stadtgruen_1.0.2
Frontimage[0][0][0][0][0][0]=images/Stadtgruen_1.0.3
Frontimage[2][0][0][0][0][0]=images/Stadtgruen_1.0.3
Frontimage[4][0][0][0][0][0]=images/Stadtgruen_1.0.4
Frontimage[1][0][0][0][0][0]=images/Stadtgruen_1.0.5
Frontimage[3][0][0][0][0][0]=images/Stadtgruen_1.0.5

Frontimage[7][0][0][0][0][1]=images/Stadtgruen_1.3.0
Frontimage[6][0][0][0][0][1]=images/Stadtgruen_1.3.1
Frontimage[5][0][0][0][0][1]=images/Stadtgruen_1.3.2
Frontimage[0][0][0][0][0][1]=images/Stadtgruen_1.3.3
Frontimage[2][0][0][0][0][1]=images/Stadtgruen_1.3.3
Frontimage[4][0][0][0][0][1]=images/Stadtgruen_1.3.4
Frontimage[1][0][0][0][0][1]=images/Stadtgruen_1.3.5
Frontimage[3][0][0][0][0][1]=images/Stadtgruen_1.3.5

Frontimage[7][0][0][0][0][2]=images/Stadtgruen_1.4.0
Frontimage[6][0][0][0][0][2]=images/Stadtgruen_1.4.1
Frontimage[5][0][0][0][0][2]=images/Stadtgruen_1.4.2
Frontimage[0][0][0][0][0][2]=images/Stadtgruen_1.4.3
Frontimage[2][0][0][0][0][2]=images/Stadtgruen_1.4.3
Frontimage[4][0][0][0][0][2]=images/Stadtgruen_1.4.4
Frontimage[1][0][0][0][0][2]=images/Stadtgruen_1.4.5
Frontimage[3][0][0][0][0][2]=images/Stadtgruen_1.4.5

Frontimage[7][0][0][0][0][3]=images/Stadtgruen_1.2.0
Frontimage[6][0][0][0][0][3]=images/Stadtgruen_1.2.1
Frontimage[5][0][0][0][0][3]=images/Stadtgruen_1.2.2
Frontimage[0][0][0][0][0][3]=images/Stadtgruen_1.2.3
Frontimage[2][0][0][0][0][3]=images/Stadtgruen_1.2.3
Frontimage[4][0][0][0][0][3]=images/Stadtgruen_1.2.4
Frontimage[1][0][0][0][0][3]=images/Stadtgruen_1.2.5
Frontimage[3][0][0][0][0][3]=images/Stadtgruen_1.2.5

Frontimage[7][0][0][0][0][4]=images/smoke_l.0.0,-2,-30
Frontimage[7][0][0][0][1][4]=images/smoke_l.0.1,-2,-30
Frontimage[7][0][0][0][2][4]=images/smoke_l.0.2,-2,-30
Frontimage[6][0][0][0][0][4]=images/smoke_l.0.0,-2,-30
Frontimage[6][0][0][0][1][4]=images/smoke_l.0.1,-2,-30
Frontimage[6][0][0][0][2][4]=images/smoke_l.0.2,-2,-30
Frontimage[5][0][0][0][0][4]=images/smoke_l.0.0,-2,-30
Frontimage[5][0][0][0][1][4]=images/smoke_l.0.1,-2,-30
Frontimage[5][0][0][0][2][4]=images/smoke_l.0.2,-2,-30
Frontimage[0][0][0][0][0][4]=images/smoke_l.0.0,-2,-30
Frontimage[0][0][0][0][1][4]=images/smoke_l.0.1,-2,-30
Frontimage[0][0][0][0][2][4]=images/smoke_l.0.2,-2,-30
Frontimage[2][0][0][0][0][4]=images/smoke_l.0.0,-2,-30
Frontimage[2][0][0][0][1][4]=images/smoke_l.0.1,-2,-30
Frontimage[2][0][0][0][2][4]=images/smoke_l.0.2,-2,-30
Frontimage[4][0][0][0][0][4]=images/smoke_l.0.0,-2,-30
Frontimage[4][0][0][0][1][4]=images/smoke_l.0.1,-2,-30
Frontimage[4][0][0][0][2][4]=images/smoke_l.0.2,-2,-30
Frontimage[1][0][0][0][0][4]=images/smoke_l.0.0,-2,-30
Frontimage[1][0][0][0][1][4]=images/smoke_l.0.1,-2,-30
Frontimage[1][0][0][0][2][4]=images/smoke_l.0.2,-2,-30
Frontimage[3][0][0][0][0][4]=images/smoke_l.0.0,-2,-30
Frontimage[3][0][0][0][1][4]=images/smoke_l.0.1,-2,-30
Frontimage[3][0][0][0][2][4]=images/smoke_l.0.2,-2,-30

It is a 1x1 citybuilding that supports 8 directions and 5 seasons.
Since the building itself does not change throughout the year, while the greenery in front does, AND the greenery is shared by other similar buildings, it is seperated in backimage (building, same image in 4 seasons) and frontimage (greenery, different images in 4 seasons but same in other buildings)
Snow is included in the backimage, but the snowy phase still uses frontimage for a smoke animation raising from the chimney. Smoke images are the same for every building, just repositioned via offset.

Such an amount of code just for one citybuilding is probably unique in that it does not happen in other paksets, but it happens quite often in pak192.comic, and will appear even more often in the future. Writing such a giant dat is easy, since you'd just replace the image names via search&replace, but if you want to change anything about the buildings parameters manually, you have to scroll through all of this, multiple times. It's just tiring.


So what I would like to be able to do is having templates for the image definitions. I'd like to write the image definitions just like above, but with placeholders, and give it a template name. The actual building would then reference said template and tell it which variables to use instead of the placeholders.
Let's imagine the long code above, but you replace "images/res/northsea/C3/1920_Backsteinexpressionismus_1" with the placeholder [[building]], "images/Stadtgruen_1" with [[greenery]], and ",-2,-30" with [[offset]]. you save it as "template1.dat"

In the actual buildings definition, you'd write
Code: [Select]
[[template1.dat; building=images/res/northsea/C3/1920_Backsteinexpressionismus_1; greenery=images/Stadtgruen_1; offset=,-2,-30]]
Upon packing, makeobj would replace this short snippet with the long one in template1.dat, and fills out the placeholder before actually packing.


My example here is especially long, but even for smaller objects it can be useful. Even a simple building that makes use of 5 seasons requires 5 images, and for that alone it could be advantagous to replace five lines with only one.
If it could be stacked, you'd be able to use [[imagepath.dat]] inside the outsourced image-definition. Thus, you could move or rename the whole image folder with ease by just replacing path written in imagepath.dat.



I understand that one could do this with a seperate program that just runs right before you pak, possibly not even a program but a script for an advanced editor. But still, with the evergrowing possibilities of image definitions, and since string manipulation should not be too hard to do, I'd really like to see it in makeobj.



PS: These citybuildings are enourmous in file size! I know the game is optimized to not load duplicate images, but could it be that makeobj is not and paks the same image several times?

Offline Vladki

  • Devotee
  • *
  • Posts: 3458
    • My addons, mostly roadsigns, pak128.cs
  • Languages: EN, CS
Re: Shortening dat files with image-templates
« Reply #1 on: January 09, 2016, 04:09:28 PM »
Hmm, what about a template more like this:

Code: [Select]
BackImage[A][0][0][B][0][C]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2*C+B.A

This would force the png to have all rotations in one line, first line the first level, second line second level, third line again first level in next season, and so on.

However max values for A,B,C would have to be defined like:
dims=1,1,8
seasons=5
height=2

« Last Edit: January 09, 2016, 04:47:04 PM by Vladki »

Offline Leartin

  • Heir-Benevolent-Dictator-Apparent
  • Devotee
  • *
  • Posts: 1469
  • PAK-DEV P192C
  • Languages: DE, EN
Re: Shortening dat files with image-templates
« Reply #2 on: January 09, 2016, 04:16:42 PM »
If something like that is easier to program, I suppose it would already help a lot, but it's way less flexible.
For the example building, it would be very bad: Although 8 rotations need to be defined, there are only 6 different rotation graphics (north and south as well as east and west are the same), plus there are no changes between seasons on the building itself. Not counting height, there are currently 12 images on the actual graphics sheet for the building, with your proposal there would need to be 40.

Offline Dwachs

  • DevTeam, Coder/patcher
  • Administrator
  • *
  • Posts: 4761
  • Languages: EN, DE, AT
Re: Shortening dat files with image-templates
« Reply #3 on: January 09, 2016, 04:46:11 PM »
PS: These citybuildings are enourmous in file size! I know the game is optimized to not load duplicate images, but could it be that makeobj is not and paks the same image several times?
Makeobj does not recognize duplicate images. Compressing the pak files afterwards should reduce filesize again.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10245
  • Languages: De,EN,JP
Re: Shortening dat files with image-templates
« Reply #4 on: January 09, 2016, 09:54:02 PM »
Simutrans recognise identical images after loading and merges them. So if you reuse the same graphics, they will be saved on the harddisk; but if the pak has the same image images, those will not consume memory nor image pointers.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5672
  • Languages: EN, NO
Re: Shortening dat files with image-templates
« Reply #5 on: January 09, 2016, 10:05:24 PM »
Simutrans recognise identical images after loading and merges them. So if you reuse the same graphics, they will be saved on the harddisk; but if the pak has the same image images, those will not consume memory nor image pointers.

Leartin wrote that he knew this. What he wanted was apparently to not save the duplicate images on the harddisk and/or that the duplicate images are only transmitted once when downloading pak files from the Internet.

Offline Leartin

  • Heir-Benevolent-Dictator-Apparent
  • Devotee
  • *
  • Posts: 1469
  • PAK-DEV P192C
  • Languages: DE, EN
Re: Shortening dat files with image-templates
« Reply #6 on: January 09, 2016, 10:24:55 PM »
It was a side question about makeobj since the main question was about makeobj. Yes, it would be nice not to use up 2MB of space due to using the same image 4 or even 8 times, but at the same time it is just storage, nothing else. I'm sorry the topic was derailed by that careless comment, it really is mostly about how images get defined.

Maybe requested in a quicker way: Most often the same image parts defined for similar objects, so why not design a template so you only have to write the name of an accordingly aligned image file, rather then defining each image part seperately.

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 10245
  • Languages: De,EN,JP
Re: Shortening dat files with image-templates
« Reply #7 on: January 10, 2016, 12:10:50 AM »
Since each object is stored seperately it has to be stored completely. Otherwise what would happen if people decide to mix manually objects (as many people did before)?

But the topic derailed. Due to the internal working of makobj I would prefere something like

Code: [Select]
BackImage[A][0][0][B][0][C]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2*C+B.A

or

Code: [Select]
BackImage[0-8][0][0][0-1][0][0-5]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.2*C+B.A+2

The latter is probably more flexible and even easier to implement.

Offline Leartin

  • Heir-Benevolent-Dictator-Apparent
  • Devotee
  • *
  • Posts: 1469
  • PAK-DEV P192C
  • Languages: DE, EN
Re: Shortening dat files with image-templates
« Reply #8 on: January 11, 2016, 01:09:32 PM »
Obviously shared ressources like the smoke would need to be in every pak, I was more concerned about duplicates of the same image inside one object, like the shown object which uses .2.2 8 times due to seperation of building and greenery in 5 seasons.

I really like the second idea, since it seems you could use it multiple times in the same image definition to be more precise.
For example, the original long dat could be shortened to seven lines given that the images are arranged accordingly:
Code: [Select]
BackImage[0-1][0][0][0-1][0][0-3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1-B.A
BackImage[0-1][0][0][0-1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3-B.A
BackImage[2-7][0][0][0-1][0][0-3]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.1-B.A-2
BackImage[2-7][0][0][0-1][0][4]=images/res/northsea/C3/1920_Backsteinexpressionismus_1.3-B.A-2
Frontimage[0-7][0][0][0][0][0-3]=images/Stadtgruen_1.B.A
Frontimage[0-7][0][0][0][0][0-3]=images/Stadtgruen_1.B.A
Frontimage[0-7][0][0][0][0-2][4]=images/smoke_l.0.B,-2,-30
Let me say, this is huge!

Explaination: Rotation 0 and 1 have the same graphic as rotation 2 and 3. thus repeating the first two lines with A-2. 1-B instead of simply B is just so you can have the roof on top of the building in the graphic, not the other way around.


Two minor things though:
I'd think the Variables should be A-F, not based on which parameter is variable, just for consistency. The variable you use for the season should not change based on whether there is a second floor or not, that could be confusing.

There ought to be a similar system for other objects which use non-number parameters, eg. vehicles which use directions.
Something like this:

Code: [Select]
EmptyImage[S;E;N;W;SW;NE;SE;NW]=image.0.A

Offline Vladki

  • Devotee
  • *
  • Posts: 3458
    • My addons, mostly roadsigns, pak128.cs
  • Languages: EN, CS
Re: Shortening dat files with image-templates
« Reply #9 on: January 11, 2016, 07:21:24 PM »
Perhaps those variables could have more descriptive names (rotation, season, x, y, z,...)

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Shortening dat files with image-templates
« Reply #10 on: February 27, 2016, 10:18:09 PM »
Very much a proof of concept patch. Code probably messy and certainly lacking a few comments...

Syntax:
within square brackets as well as having one number you can now have ranges or several number - eg [0,1,2] or [0-2] or [0,2-4,8] etc. Only limit is that at most 255 numbers can be referenced this way for each set of square brackets.
note that more than one set of square brackets can use this, so Image[0-15][0-4] is also valid

to use these on the right hand side of the = enclose expansions in <>. Then use $0 to refer to the leftmost [] containing a range, $1 for the next and so on. For example <$0-15> or <4-$1>. Note only + and - operators are supported at this point, no brackets!

for example
Code: [Select]
Image[8-15][0][0][0-4] = image/test.<$0-8>.<$1>
A more realistic example, marker from pak128.Britain recoded to use this

Code: [Select]
#
# Ground marker for pak128
#
Obj=ground
Name=Marker
copyright=Timothy Baldock
# the front part (obtained by hang%27) for signle slopes
Image[0-8][0]=images/marker.3.<$0>
Image[9-17][0]=images/marker.4.<$0-9>
Image[18-26][0]=images/marker.5.<$0-18>

# backpart (obtained by (hang%3) + ((hang-(hang%9))/3)
Image[27-29][0]=images/marker.0.<$0-27>
Image[30-32][0]=images/marker.1.<$0-30>
Image[33-35][0]=images/marker.2.<$0-33>
Image[36-38][0]=images/marker.0.<$0-36+3>
Image[39-41][0]=images/marker.1.<$0-39+3>
Image[42-44][0]=images/marker.2.<$0-42+3>
Image[45-47][0]=images/marker.0.<$0-45+6>
Image[48-50][0]=images/marker.1.<$0-48+6>
Image[51-53][0]=images/marker.2.<$0-51+6>
--------------------

So, thoughts? Is a more complete set of operators needed?
--
Edit forgot to say limit of up to 10 expansions and 10 square brackets containing ranges on each line. Though this and 255 limit for numbers within ranges is easily extended. Also while in these examples have used expansions in coordinates section of image, nothing stopping being used in filename bit too.
--
Another edit:

What are peoples thoughts about possible boolean comparisons - e.g. instead of:
Code: [Select]
BackImage[0][0][0][0][0][0]=brick-platform-narrow.1.0
BackImage[0][0][0][0][0][1]=brick-platform-narrow-snow.1.0
having
Code: [Select]
BackImage[0][0][0][0][0][0-1]=brick-platform-narrow<$0=0?:-snow>.1.0
? Is this going a step too far in obfuscation? Does saving a few lines in a dat file mean that much?
« Last Edit: February 27, 2016, 10:43:49 PM by kierongreen »

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Shortening dat files with image-templates
« Reply #11 on: February 28, 2016, 01:02:53 AM »
Tidied version (no additional functionality)... (edit, more tidying)
« Last Edit: February 28, 2016, 01:40:17 AM by kierongreen »

Offline Leartin

  • Heir-Benevolent-Dictator-Apparent
  • Devotee
  • *
  • Posts: 1469
  • PAK-DEV P192C
  • Languages: DE, EN
Re: Shortening dat files with image-templates
« Reply #12 on: February 28, 2016, 09:04:15 AM »
What are peoples thoughts about possible boolean comparisons - e.g. instead of:
Code: [Select]
BackImage[0][0][0][0][0][0]=brick-platform-narrow.1.0
BackImage[0][0][0][0][0][1]=brick-platform-narrow-snow.1.0
having
Code: [Select]
BackImage[0][0][0][0][0][0-1]=brick-platform-narrow<$0=0?:-snow>.1.0
? Is this going a step too far in obfuscation? Does saving a few lines in a dat file mean that much?

I think it would be better to add multiplication functionality. If you had multiplications, you could combine the snow graphic with the non-snow graphic and add "+$?*x" to the position, where x is the width or height of the original graphic sheet, depending on whether you added snow below or to the right.
Multiplication to adress different clusters could be useful whenever three or more variables are used. Say you have a 4*4 building with 4 rotations and 5 seasons. You could simply write:
Code: [Select]
Backimage[0-3][0-3][0-3][0][0][0-4] = image/thisbuilding.<$0*4+$1>.<$2+$3*4>Thus having a pattern of the 4*4 graphics as one cluster, with four rows of clusters for different rotation and four columns for different seasons.


Sorry, I can't test the patch since I have no idea how :(

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Shortening dat files with image-templates
« Reply #13 on: February 28, 2016, 10:32:21 AM »
Working on multiplication but it does involve adding brackets which complicates matters... (though once adding in multiplication might as well add in division and modulus).

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Shortening dat files with image-templates
« Reply #14 on: February 28, 2016, 04:32:01 PM »
Ok, add, subtract, divide, multiple, modulo with correct precedence (and brackets) all supported.

Example below (compare with original in pak128.Britain which had 54 lines for these images...):
Code: [Select]
#
# Ground marker for pak128
#
Obj=ground
Name=Marker
copyright=Timothy Baldock
# the front part (obtained by hang%27) for signle slopes
Image[0-26][0]=images/marker.<$0/9+3>.<$0%9>

# backpart (obtained by (hang%3) + ((hang-(hang%9))/3)
Image[27-53][0]=images/marker.<($0%9)/3>.<$0%3+(($0-27)/9)*3>
--------------------

--

Edit: This doesn't seem controversial so after some more testing and tidying submitted in 7774. Though noticed there's not a nightly build for makeobj and I haven't managed to get my windows compile working again so will rely on people compiling from source themselves.
« Last Edit: February 28, 2016, 06:52:48 PM by kierongreen »

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2920
  • D'oh
    • by An_dz
  • Languages: pt, en, it, (de)
Re: Shortening dat files with image-templates
« Reply #15 on: February 28, 2016, 06:56:31 PM »
Rather than using angle brackets <> I would suggest using brackets {}

To me angle brackets mean tags and not code. And brackets to me mean repetition.

Not using angle brackets could allow comparators or binary operators, I'm not requesting them, but just in case one day we find any use for them. And also for the sake of using the same de facto standard.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Shortening dat files with image-templates
« Reply #16 on: February 28, 2016, 07:11:04 PM »
One reason for using angled brackets is that these are forbidden characters in Windows filenames.

Offline Ters

  • Coder/patcher
  • Devotee
  • *
  • Posts: 5672
  • Languages: EN, NO
Re: Shortening dat files with image-templates
« Reply #17 on: February 28, 2016, 07:35:16 PM »
While not strictly forbidden in file name on other platforms, the fact that angle brackets are used for redirecting streams on the command line of every system I have ever encountered, makes them unlikely to be part of any filename anywhere. Ironically, that might also be why they are rarely used for embedded expressions.

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Shortening dat files with image-templates
« Reply #18 on: February 29, 2016, 12:58:27 AM »
Fixed a problem with the loading of tabfiles that caused menuconf.tab to not load correctly (thanks to the auto reporting of errors for picking up on this!)

Offline Leartin

  • Heir-Benevolent-Dictator-Apparent
  • Devotee
  • *
  • Posts: 1469
  • PAK-DEV P192C
  • Languages: DE, EN
Re: Shortening dat files with image-templates
« Reply #19 on: February 29, 2016, 10:09:41 AM »
I assume the logic only cares about what is written in the same line of code, so this would be something different, but I throw it out anyways:

Especially with citybuildings, I often have some alternate versions of the same building, which all use the same code, except for different object names and a different row in the image definition. So I wonder if it would be possible to define other ranges within the objects name, and use them not only in the image definition, but for other parameters as well.
For example, say you have one design for a building that spans over several levels. A good example would be a townhall I made for pak192.comic, which has 5 different stages. There names are "tow_copper[01-05]", they use the image "kupferdach<$$0>" and there level is <$$0*10>. (for now, they need 319 lines of code, the patch as it is would reduce this to 65 lines, and with this addition it would be 13 lines)

Offline kierongreen

  • Dev Team, Coder/patcher
  • Devotee
  • *
  • Posts: 2346
Re: Shortening dat files with image-templates
« Reply #20 on: February 29, 2016, 09:20:09 PM »
Anything which is read as a tabfile will be covered. Not just images but basically any line which has one or more [ ] followed by an = on the same line.

To address your point though I don't think it would work as the parameters would be on the right and as you say would extend beyond one line of code. So no, and your suggestion would be much more difficult to implement I think.