b3view/main.cpp

80 lines
1.8 KiB
C++
Raw Permalink Normal View History

2010-04-22 05:16:15 -07:00
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
2010-04-22 05:16:15 -07:00
2010-04-21 07:48:36 -07:00
#include "Engine.h"
using std::wstring;
using namespace irr;
using namespace irr::core;
wchar_t* getWideCharString(char* str);
2010-04-22 05:16:15 -07:00
2010-04-22 01:44:10 -07:00
#ifdef WIN32
#include <Windows.h>
2019-04-19 14:13:58 -07:00
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
2010-04-22 01:44:10 -07:00
#else
int main(int argc, char** argv)
2010-04-22 01:44:10 -07:00
#endif
2010-04-21 07:48:36 -07:00
{
2019-03-07 10:23:54 -08:00
// Parse commandline to check if a filename argument has been passed
2010-04-22 05:16:15 -07:00
#ifdef WIN32
2019-03-07 10:23:54 -08:00
int argc;
char** argv;
2010-04-22 05:16:15 -07:00
LPWSTR* args;
args = CommandLineToArgvW(GetCommandLineW(), &argc);
2010-04-22 05:16:15 -07:00
argv = (char**)malloc(sizeof(char*) * argc);
for (int index = 0; index < argc; index++) {
int argumentBufferLength = wcslen(args[index]) + 1;
argv[index] = (char*)malloc(sizeof(char) * argumentBufferLength);
sprintf_s(argv[index], argumentBufferLength, "%ws", args[index]);
2019-03-07 10:23:54 -08:00
}
2010-04-22 05:16:15 -07:00
LocalFree(args);
2010-04-22 05:16:15 -07:00
#endif
Engine* engine = new Engine();
if (argc >= 2) {
2021-03-28 03:08:53 -07:00
for (int i = 1; i < argc; i++) {
wchar_t* optionCS = getWideCharString(argv[i]);
if ((strlen(argv[i]) >=2 ) && (argv[i][0] == '-') && (argv[i][1] == '-')) {
2021-03-28 03:08:53 -07:00
engine->pushOption(wstring(optionCS));
}
else {
engine->loadMesh(wstring(optionCS), false);
2021-03-28 03:08:53 -07:00
}
free(optionCS);
}
2019-03-07 10:23:54 -08:00
}
//else
// engine->loadMesh(L"test.b3d");
2010-04-22 05:16:15 -07:00
2010-04-21 07:48:36 -07:00
engine->run();
delete engine;
2010-04-22 05:16:15 -07:00
#ifdef WIN32
for (int index = 0; index < argc; index++)
free(argv[index]);
free(argv);
2010-04-22 05:16:15 -07:00
#endif
}
wchar_t* getWideCharString(char* str)
2010-04-22 05:16:15 -07:00
{
2019-04-19 14:13:58 -07:00
wchar_t* dest = static_cast<wchar_t*>(
malloc(sizeof(wchar_t) * (strlen(str) + 1))
);
size_t resultSize = mbstowcs(nullptr, str, strlen(str));
mbstowcs(dest, str, strlen(str));
dest[resultSize] = '\0';
2010-04-22 05:16:15 -07:00
2019-03-07 10:23:54 -08:00
return dest;
2010-04-21 07:48:36 -07:00
}