2019-07-20 13:55:16 -07:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "kraken.h"
|
|
|
|
|
|
|
|
|
|
using namespace kraken;
|
|
|
|
|
|
2020-08-06 18:15:58 -07:00
|
|
|
enum ResourceMapping {
|
|
|
|
|
output_bundle = 0,
|
|
|
|
|
loaded_resource = 1,
|
|
|
|
|
shader_compile_log = 2,
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-20 13:55:16 -07:00
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
|
{
|
2020-08-06 18:15:58 -07:00
|
|
|
bool failed = false;
|
2019-07-20 13:55:16 -07:00
|
|
|
printf("Kraken Convert\n");
|
|
|
|
|
printf("Initializing Kraken...\n");
|
2020-08-07 01:40:03 -07:00
|
|
|
printf("%i arguments:\n", argc);
|
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
|
printf("argv[%i]: %s\n", i, argv[i]);
|
|
|
|
|
}
|
2019-07-20 13:55:16 -07:00
|
|
|
KrInitializeInfo init_info = {};
|
|
|
|
|
init_info.sType = KR_STRUCTURE_TYPE_INITIALIZE;
|
2019-07-28 16:46:46 -07:00
|
|
|
init_info.resourceMapSize = 1024;
|
2019-07-20 13:55:16 -07:00
|
|
|
KrResult res = KrInitialize(&init_info);
|
|
|
|
|
if (res != KR_SUCCESS) {
|
|
|
|
|
printf("Failed to initialize Kraken!\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 16:46:46 -07:00
|
|
|
KrCreateBundleInfo create_bundle_info = {};
|
|
|
|
|
create_bundle_info.sType = KR_STRUCTURE_TYPE_CREATE_BUNDLE;
|
2020-08-06 18:15:58 -07:00
|
|
|
create_bundle_info.resourceHandle = ResourceMapping::output_bundle;
|
2019-07-28 16:46:46 -07:00
|
|
|
create_bundle_info.pBundleName = "output";
|
|
|
|
|
res = KrCreateBundle(&create_bundle_info);
|
|
|
|
|
if (res != KR_SUCCESS) {
|
|
|
|
|
printf("Failed to create bundle.\n");
|
|
|
|
|
KrShutdown();
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-20 13:55:16 -07:00
|
|
|
KrLoadResourceInfo load_resource_info = {};
|
2019-07-28 16:46:46 -07:00
|
|
|
load_resource_info.sType = KR_STRUCTURE_TYPE_LOAD_RESOURCE;
|
2020-08-06 18:15:58 -07:00
|
|
|
load_resource_info.resourceHandle = ResourceMapping::loaded_resource;
|
2019-07-28 16:46:46 -07:00
|
|
|
|
|
|
|
|
KrMoveToBundleInfo move_to_bundle_info = {};
|
|
|
|
|
move_to_bundle_info.sType = KR_STRUCTURE_TYPE_MOVE_TO_BUNDLE;
|
2020-08-06 18:15:58 -07:00
|
|
|
move_to_bundle_info.bundleHandle = ResourceMapping::output_bundle;
|
2019-07-20 13:55:16 -07:00
|
|
|
|
2019-11-30 17:57:45 -08:00
|
|
|
char* output_bundle = nullptr;
|
2020-08-06 18:15:58 -07:00
|
|
|
bool compile_shaders = false;
|
2019-11-30 17:57:45 -08:00
|
|
|
|
2020-08-06 18:52:06 -07:00
|
|
|
char command = '\0';
|
2020-08-06 18:15:58 -07:00
|
|
|
for (int i = 1; i < argc && !failed; i++) {
|
2019-07-20 13:55:16 -07:00
|
|
|
char *arg = argv[i];
|
2020-08-06 18:52:06 -07:00
|
|
|
if (arg[0] == '-') {
|
|
|
|
|
if (command != '\0') {
|
|
|
|
|
// The last command is expecting a parameter, not another command.
|
|
|
|
|
printf("Invalid syntax. '%s' not expected after '-%c'\n", arg, command);
|
|
|
|
|
failed = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (arg[1] == '\0') {
|
|
|
|
|
// We received a lonely '-'
|
|
|
|
|
printf("Invalid syntax. '-' must be followed by a command.\n");
|
|
|
|
|
failed = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (arg[2] != '\0') {
|
|
|
|
|
// All commands are currently one character long
|
|
|
|
|
printf("Unknown command: '%s'\n", arg);
|
|
|
|
|
failed = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
command = arg[1];
|
2019-11-30 17:57:45 -08:00
|
|
|
switch (command) {
|
2020-08-06 18:15:58 -07:00
|
|
|
case 'c':
|
|
|
|
|
compile_shaders = true;
|
2020-08-06 18:52:06 -07:00
|
|
|
command = '\0';
|
2020-08-06 18:15:58 -07:00
|
|
|
break;
|
2020-08-06 18:52:06 -07:00
|
|
|
case 'o':
|
|
|
|
|
// Next arg will be the output path
|
2019-11-30 17:57:45 -08:00
|
|
|
break;
|
2020-08-06 18:52:06 -07:00
|
|
|
default:
|
|
|
|
|
printf("Unknown command: '%s'\n", arg);
|
|
|
|
|
failed = true;
|
|
|
|
|
continue;
|
2019-11-30 17:57:45 -08:00
|
|
|
}
|
|
|
|
|
continue;
|
2020-08-06 18:52:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process commands that receive arguments
|
|
|
|
|
switch (command) {
|
|
|
|
|
case 'o':
|
|
|
|
|
output_bundle = arg;
|
|
|
|
|
command = '\0';
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-11-30 17:57:45 -08:00
|
|
|
|
|
|
|
|
load_resource_info.pResourcePath = arg;
|
|
|
|
|
printf("loading %s... ", arg);
|
2019-07-20 13:55:16 -07:00
|
|
|
res = KrLoadResource(&load_resource_info);
|
|
|
|
|
if (res != KR_SUCCESS) {
|
2019-11-30 17:57:45 -08:00
|
|
|
printf("[FAIL] (KrLoadResource)\n");
|
2020-08-06 18:15:58 -07:00
|
|
|
failed = true;
|
2020-08-06 18:52:06 -07:00
|
|
|
continue;
|
2019-07-20 13:55:16 -07:00
|
|
|
}
|
2020-08-06 18:15:58 -07:00
|
|
|
move_to_bundle_info.resourceHandle = ResourceMapping::loaded_resource;
|
2019-07-28 16:46:46 -07:00
|
|
|
res = KrMoveToBundle(&move_to_bundle_info);
|
|
|
|
|
if (res != KR_SUCCESS) {
|
2019-11-30 17:57:45 -08:00
|
|
|
printf("[FAIL] (KrMoveToBundle)\n");
|
2020-08-06 18:15:58 -07:00
|
|
|
failed = true;
|
2020-08-06 18:52:06 -07:00
|
|
|
continue;
|
2019-07-20 13:55:16 -07:00
|
|
|
}
|
2019-11-30 17:57:45 -08:00
|
|
|
printf("[GOOD]\n");
|
2019-07-20 13:55:16 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-06 18:15:58 -07:00
|
|
|
if (compile_shaders && !failed) {
|
2020-08-06 18:52:06 -07:00
|
|
|
printf("Compiling Shaders... ");
|
2020-08-06 18:15:58 -07:00
|
|
|
KrCompileAllShadersInfo compile_all_shaders_info = {};
|
|
|
|
|
compile_all_shaders_info.sType = KR_STRUCTURE_TYPE_COMPILE_ALL_SHADERS;
|
|
|
|
|
compile_all_shaders_info.logHandle = ResourceMapping::shader_compile_log;
|
|
|
|
|
res = KrCompileAllShaders(&compile_all_shaders_info);
|
|
|
|
|
if (res != KR_SUCCESS) {
|
|
|
|
|
printf("[FAIL] (Error %i)\n", res);
|
|
|
|
|
failed = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("[GOOD]\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (output_bundle && !failed) {
|
2019-11-30 17:57:45 -08:00
|
|
|
printf("Bundling %s... ", output_bundle);
|
|
|
|
|
KrSaveResourceInfo save_resource_info = {};
|
|
|
|
|
save_resource_info.sType = KR_STRUCTURE_TYPE_SAVE_RESOURCE;
|
2020-08-06 18:15:58 -07:00
|
|
|
save_resource_info.resourceHandle = ResourceMapping::output_bundle;
|
2019-11-30 17:57:45 -08:00
|
|
|
save_resource_info.pResourcePath = output_bundle;
|
|
|
|
|
res = KrSaveResource(&save_resource_info);
|
|
|
|
|
if (res != KR_SUCCESS) {
|
|
|
|
|
printf("[FAIL] (Error %i)\n", res);
|
2020-08-06 18:15:58 -07:00
|
|
|
failed = true;
|
2019-11-30 17:57:45 -08:00
|
|
|
} else {
|
|
|
|
|
printf("[GOOD]\n");
|
|
|
|
|
}
|
2019-07-28 16:46:46 -07:00
|
|
|
}
|
|
|
|
|
|
2019-07-20 13:55:16 -07:00
|
|
|
KrShutdown();
|
2020-08-07 01:40:03 -07:00
|
|
|
printf("--- after shutdown ----\n");
|
|
|
|
|
printf("%i arguments:\n", argc);
|
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
|
printf("argv[%i]: %s\n", i, argv[i]);
|
|
|
|
|
}
|
2020-08-06 18:15:58 -07:00
|
|
|
return failed ? 1 : 0;
|
2019-07-20 13:55:16 -07:00
|
|
|
}
|