| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "Hash.h"
- #include "Path.h"
- #include "StringUtils.h"
- #include "Args.h"
- #include "Resource.h"
- using namespace crown;
- const char* resource_in = NULL;
- uint32_t hash_seed = 0;
- void print_help_message(const char* program_name);
- void parse_command_line(int argc, char** argv);
- /// Generates 64bit hash for the specified resource based on a seed
- int main(int argc, char** argv)
- {
- parse_command_line(argc, argv);
- if (resource_in == NULL)
- {
- printf("%s: ERROR: you have to specify the resource name with `--resource-in`\n", argv[0]);
- exit(-1);
- }
- char resource_basename[256];
- char resource_extension[256];
-
- path::filename_without_extension(resource_in, resource_basename, 256);
- path::extension(resource_in, resource_extension, 256);
-
- uint32_t resource_basename_hash = hash::murmur2_32(resource_basename, string::strlen(resource_basename), hash_seed);
- uint32_t resource_extension_hash = hash::murmur2_32(resource_extension, string::strlen(resource_extension), 0);
- if (resource_extension_hash != TEXTURE_TYPE &&
- resource_extension_hash != MESH_TYPE &&
- resource_extension_hash != SCRIPT_TYPE &&
- resource_extension_hash != TEXT_TYPE &&
- resource_extension_hash != MATERIAL_TYPE &&
- resource_extension_hash != VERTEX_SHADER_TYPE &&
- resource_extension_hash != PIXEL_SHADER_TYPE)
- {
- printf("%s: ERROR: cannot generate hash for resource '%s': Unknown type.\n", argv[0], resource_in);
- exit(-1);
- }
- char out_filename[512];
- out_filename[0] = '\0';
- snprintf(out_filename, 256, "%.8X%.8X", resource_basename_hash, resource_extension_hash);
-
- printf("%s\n", out_filename);
- return 0;
- }
- //-----------------------------------------------------------------------------
- void parse_command_line(int argc, char** argv)
- {
- // Parse arguments
- ArgsOption options[] =
- {
- "help", AOA_NO_ARGUMENT, NULL, 'h',
- "resource-in", AOA_REQUIRED_ARGUMENT, NULL, 'i',
- "seed", AOA_REQUIRED_ARGUMENT, NULL, 's',
- NULL, 0, NULL, 0
- };
- Args args(argc, argv, "", options);
- int32_t opt;
- while ((opt = args.getopt()) != -1)
- {
- switch (opt)
- {
- // Resource in
- case 'i':
- {
- resource_in = args.optarg();
- break;
- }
- case 's':
- {
- hash_seed = atoi(args.optarg());
- break;
- }
- case 'h':
- case '?':
- default:
- {
- print_help_message(argv[0]);
- exit(-1);
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- void print_help_message(const char* program_name)
- {
- printf("Usage: %s [options]\n", program_name);
- printf("Options:\n\n");
- printf(" --help Show this help.\n");
- printf(" --resource-in <name> The <name> of the input resource.\n");
- printf(" --seed <value> The unsigned integer <value> of the hash seed.\n");
- }
|