new unitsync APIs, for reading heightmap/metalmap etc.

new unitsync APIs, for reading heightmap/metalmap etc.

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

new unitsync APIs, for reading heightmap/metalmap etc.

Post by Tobi »

I added the following two new APIs to unitsync:

Code: Select all

/**
 * @brief Retrieves dimensions of infomap for a map.
 * @param filename The name of the map, including extension.
 * @param name     Of which infomap to retrieve the dimensions.
 * @param width    This is set to the width of the infomap, or 0 on error.
 * @param height   This is set to the height of the infomap, or 0 on error.
 * @return 1 when the infomap was found with a nonzero size, 0 on error.
 * @see GetInfoMap
 */
DLL_EXPORT int __stdcall GetInfoMapSize(const char* filename, const char* name, int* width, int* height);

Code: Select all

/**
 * @brief Retrieves infomap data of a map.
 * @param filename The name of the map, including extension.
 * @param name     Which infomap to extract from the file.
 * @param data     Pointer to memory location with enough room to hold the infomap data.
 * @param typeHint One of bm_grayscale_8 (or 1) and bm_grayscale_16 (or 2).
 * @return 1 if the infomap was succesfully extracted (and optionally converted),
 * or 0 on error (map wasn't found, infomap wasn't found, or typeHint could not
 * be honoured.)
 *
 * This function extracts an infomap from a map. This can currently be one of:
 * "height", "metal", "grass", "type". The heightmap is natively in 16 bits per
 * pixel, the others are in 8 bits pixel. Using typeHint one can give a hint to
 * this function to convert from one format to another. Currently only the
 * conversion from 16 bpp to 8 bpp is implemented.
 */
DLL_EXPORT int __stdcall GetInfoMap(const char* filename, const char* name, void* data, int typeHint);
This allows lobby clients to fetch and display e.g. the metalmap or heightmap of a map.

The usage should be clear from the documentation, if not then you still have this thread :-)

Happy coding :-P

EDIT:

oh, and here is some crappy example code (from tools/unitsync/test/test.cpp) which dumps the infomaps to raw data files:

Code: Select all

    char* infomaps[] = { "height", "grass", "metal", "type", NULL };
    int width, height;
    for (int i = 0; infomaps[i]; ++i) {
      if (GetInfoMapSize(mapName.c_str(), infomaps[i], &width, &height)) {
        printf("    %smap: %i x %i\n", infomaps[i], width, height);
        void* data = malloc(width*height);
        GetInfoMap(mapName.c_str(), infomaps[i], data, 1);
        FILE* f = fopen(infomaps[i], "w");
        if (f == NULL) {
          perror(infomaps[i]);
        } else {
          fwrite(data, 1, width*height, f);
          fclose(f);
        }
        free(data);
      }
    }
Satirik
Lobby Developer
Posts: 1688
Joined: 16 Mar 2007, 18:27

Re: new unitsync APIs, for reading heightmap/metalmap etc.

Post by Satirik »

i'll update my mapInfoExtractor to use them good work :) JJ's gonna be happy, and i will add this to the lobby later
Post Reply

Return to “Engine”