Skip to content

Level texture support

dgengin edited this page Mar 7, 2019 · 3 revisions

Level texture support

DGEngine as of v0.2.0 supports using level/player/etc textures from newer formats such as png images.

This image is part of town.cel and is saved as an indexed image.

Indexed images store the palette index in the red channel, so you can use different palettes with png images as well.

Note you don't need to use indexed images. You can load the final images directly and not use palettes.

11.png

Loading maps with png textures

This is how DGEngine loads the town map right now using cel files:

{
  "level": {
    "id": "level",
    "name": "Town Center",
    "palette": "town",
    "file": "Nlevels/TownData/Town.CEL",
    "mapSize": [96, 96],
    "map": [
      { "file": "levels/towndata/sector1s.dun", "position": [46, 46] },
      { "file": "levels/towndata/sector2s.dun", "position": [46, 0] },
      { "file": "levels/towndata/sector3s.dun", "position": [0, 46] },
      { "file": "levels/towndata/sector4s.dun", "position": [0, 0] }
    ],
    "til": "Nlevels/TownData/Town.TIL",
    "min": "Nlevels/TownData/Town.MIN",
    "minBlocks": 16,
    "sol": "Nlevels/TownData/Town.SOL"
  },
  "load": "level/town/levelObjects.json",
  "load": "level/town/items.json"
}

Textures are loaded from the cel and min files.

This is how you would load the same level using textures saved as png spritesheets:

Note we no longer need the min file.

{
  "texturePack": [
    {
      "id": "levelBack",
      "texture": [
        { "file": "levels/towndata/back/1.png", "frames": [16, 32], "direction": "horizontal" },
        { "file": "levels/towndata/back/2.png", "frames": [16, 32], "direction": "horizontal" },
        { "file": "levels/towndata/back/3.png", "frames": [16, 32], "direction": "horizontal" }
      ],
      "palette": "town",
      "indexed": true
    },
    {
      "id": "levelFront",
      "texture": [
        { "file": "levels/towndata/front/1.png", "frames": [16, 4], "direction": "horizontal" },
        { "file": "levels/towndata/front/2.png", "frames": [16, 4], "direction": "horizontal" },
        { "file": "levels/towndata/front/3.png", "frames": [16, 4], "direction": "horizontal" },
        { "file": "levels/towndata/front/4.png", "frames": [16, 4], "direction": "horizontal" },
        { "file": "levels/towndata/front/5.png", "frames": [16, 4], "direction": "horizontal" },
        { "file": "levels/towndata/front/6.png", "frames": [16, 4], "direction": "horizontal" }
      ],
      "textureIndexes": [
        104, 105, 108, 111, 114, 116, 127, 128, 129, 155, 156, 157, 159, 161, 167, 168,
        169, 179, 180, 181, 211, 212, 213, 215, 216, 220, 221, 222, 223, 224, 226, 228,
        230, 231, 232, 257, 258, 259, 357, 358, 359, 361, 362, 363, 381, 382, 385, 386,
        405, 407, 409, 411, 413, 415, 417, 418, 421, 422, 423, 425, 427, 429, 430, 431,
        433, 434, 435, 437, 438, 439, 468, 469, 472, 473, 476, 477, 478, 480, 482, 484,
        486, 508, 509, 512, 520, 521, 522, 524, 525, 528, 530, 532, 534, 536, 538, 539,
        540, 550, 552, 553, 556, 558, 626, 627, 628, 630, 631, 634, 636, 638, 640, 714,
        715, 718, 719, 720, 722, 723, 724, 726, 727, 730, 731, 784, 786, 788, 790, 792,
        794, 796, 798, 800, 804, 805, 806, 808, 809, 810, 812, 813, 815, 816, 817, 819,
        821, 823, 825, 827, 829, 831, 832, 833, 835, 836, 838, 839, 840, 842, 843, 844,
        846, 847, 849, 851, 853, 855, 861, 863, 865, 866, 869, 870, 909, 910, 917, 918,
        919, 925, 926, 927, 929, 930, 931, 937, 939, 941, 943, 945, 946, 949, 950, 953,
        954, 955, 957, 958, 962, 965, 969, 970, 973, 974, 977, 981, 982, 986, 989, 993,
        994, 998, 1001, 1006, 1009, 1013, 1014, 1017, 1025, 1026, 1029, 1030, 1033, 1037, 1042, 1045,
        1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1064, 1065,
        1066, 1067, 1068, 1069, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1081, 1082, 1083,
        1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1094, 1095, 1096, 1097, 1098, 1099, 1100,
        1102, 1103, 1104, 1105, 1106, 1108, 1110, 1112, 1114, 1116, 1131, 1132, 1133, 1134, 1136, 1138,
        1140, 1166, 1170, 1172, 1174, 1176, 1178, 1180, 1182, 1184, 1200, 1202, 1203, 1205, 1206, 1207,
        1209, 1210, 1213, 1214, 1215, 1216, 1217, 1224, 1232, 1256, 1257, 1272, 1302, 1322, 1323, 1330,
        1331, 1346, 1349, 1355, 1360, 1361, 1362, 1376, 1377
      ],
      "palette": "town",
      "indexed": true
    }
  ],
  "level": {
    "id": "level",
    "name": "Town Center",
    "palette": "town",
    "texturePackBottom": "levelBack",
    "texturePackTop": "levelFront",
    "mapSize": [96, 96],
    "map": [
      { "file": "levels/towndata/sector1s.dun", "position": [46, 46] },
      { "file": "levels/towndata/sector2s.dun", "position": [46, 0] },
      { "file": "levels/towndata/sector3s.dun", "position": [0, 46] },
      { "file": "levels/towndata/sector4s.dun", "position": [0, 0] }
    ],
    "til": "levels/towndata/town.til",
    "sol": "levels/towndata/town.sol"
  }
}

Internally, DGEngine constructs TexturePacks from the cel file.

The background texture pack loads 3 png images (1024 x 1024 pixels) with 16 x 32 = 512 textures each.

The background texture pack loads 6 png images (1024 x 1024 pixels) with 16 x 4 = 64 textures each. Because not all background textures have a front texture (pillar such as door, tree), we skip blanks and use textureIndexes to map to the correct indexes. This way we save memory by not loading/drawing blank pillars.

Creating spritesheets from cel files

To convert cel files to spritesheets, you can use the function defined in LevelHelper.h

	// bottomTopOrBoth : -1 for both, 0 for bottom, 1 for top
	void saveTilesetSprite(const std::string& path,
		CachedImagePack& imgPack, Min& min, int bottomTopOrBoth, bool skipBlankTiles);

I recommend calling this function in ParseTexturePack.cpp right before the LevelHelper::loadTilesetSprite function.

Since version 0.3.4, you can export tilesets using the following commands:

DGEngine --export <archive_files> <file_in_archive> <output_file_or_path>

DGEngine --export-tileset:<min_size> <archive_files> <tileset_cel_file> <output_path>
DGEngine --export-tileset:<min_size> <archive_files> <tileset_cel_file> <palette_file> <output_path>

DGEngine --export-tileset-bottom
DGEngine --export-tileset-top

examples:

DGEngine --export-tileset:16 DIABDAT levels/towndata/town.cel Z:\
DGEngine --export-tileset DIABDAT levels/l1data/l1.cel Z:\
DGEngine --export-tileset DIABDAT levels/l2data/l2.cel Z:\
DGEngine --export-tileset DIABDAT levels/l3data/l3.cel Z:\
DGEngine --export-tileset:16 DIABDAT levels/l4data/l4.cel levels/l4data/l4_1.pal Z:\

DGEngine --export-tileset:16 "DIABDAT|hellfire" NLevels/TownData/TOWN.CEL levels/towndata/town.pal Z:\
DGEngine --export-tileset "DIABDAT|hellfire" NLevels/L5Data/L5.CEL NLevels/L5Data/L5Base.PAL Z:\
DGEngine --export-tileset "DIABDAT|hellfire" NLevels/L6Data/L6.CEL NLevels/L6Data/l6base.pal Z:\