2020-07-21 11:34:39 +00:00
|
|
|
#include "state.hpp"
|
|
|
|
|
2020-08-09 07:14:33 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#include "windows.h"
|
2020-08-11 03:08:49 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2020-08-09 07:14:33 +00:00
|
|
|
|
|
|
|
int WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) {
|
2020-08-11 03:08:49 +00:00
|
|
|
int argvCapacity = 16;
|
|
|
|
int argc = 0;
|
|
|
|
char **argv = (char**)calloc(argvCapacity, sizeof(char*));
|
|
|
|
int argLength = std::strlen(lpCmdLine);
|
|
|
|
int tempCapacity = 128;
|
|
|
|
int tempSize = 0;
|
|
|
|
char *temp = (char*)malloc(sizeof(char) * tempCapacity);
|
|
|
|
for (int i = 0; i < argLength; ++i) {
|
|
|
|
if (lpCmdLine[i] == ' ') {
|
|
|
|
if (tempSize > 0) {
|
|
|
|
if (argc >= argvCapacity) {
|
|
|
|
char **newArgv = (char**)calloc(argvCapacity * 2, sizeof(char*));
|
|
|
|
std::memcpy(newArgv, argv, sizeof(char*) * argvCapacity);
|
|
|
|
free(argv);
|
|
|
|
argv = newArgv;
|
|
|
|
argvCapacity *= 2;
|
|
|
|
}
|
|
|
|
argv[argc] = (char*)malloc(sizeof(char) * (tempSize + 1));
|
|
|
|
std::memcpy(argv[argc], temp, sizeof(char) * tempSize);
|
|
|
|
argv[argc][tempSize] = 0;
|
|
|
|
++argc;
|
|
|
|
tempSize = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tempSize >= tempCapacity) {
|
|
|
|
char *newTemp = (char*)malloc(sizeof(char) * tempCapacity * 2);
|
|
|
|
std::memcpy(newTemp, temp, sizeof(char) * tempSize);
|
|
|
|
free(temp);
|
|
|
|
temp = newTemp;
|
|
|
|
tempCapacity *= 2;
|
|
|
|
}
|
|
|
|
temp[tempSize++] = lpCmdLine[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tempSize > 0) {
|
|
|
|
if (argc >= argvCapacity) {
|
|
|
|
char **newArgv = (char**)calloc(argvCapacity * 2, sizeof(char*));
|
|
|
|
std::memcpy(newArgv, argv, sizeof(char*) * argvCapacity);
|
|
|
|
free(argv);
|
|
|
|
argv = newArgv;
|
|
|
|
argvCapacity *= 2;
|
|
|
|
}
|
|
|
|
argv[argc] = (char*)malloc(sizeof(char) * (tempSize + 1));
|
|
|
|
std::memcpy(argv[argc], temp, sizeof(char) * tempSize);
|
|
|
|
argv[argc][tempSize] = 0;
|
|
|
|
++argc;
|
|
|
|
tempSize = 0;
|
|
|
|
}
|
|
|
|
free(temp);
|
|
|
|
|
2020-08-09 07:14:33 +00:00
|
|
|
// init
|
2020-08-11 03:08:49 +00:00
|
|
|
Tri::State state(argc, argv);
|
2020-08-09 07:14:33 +00:00
|
|
|
|
|
|
|
// main loop
|
|
|
|
while(state.get_flags().test(1)) {
|
|
|
|
state.handle_events();
|
|
|
|
state.update();
|
|
|
|
state.draw();
|
|
|
|
}
|
2020-08-11 03:08:49 +00:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
free(argv[i]);
|
|
|
|
}
|
|
|
|
free(argv);
|
|
|
|
|
2020-08-09 07:14:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
2020-07-21 11:03:22 +00:00
|
|
|
int main(int argc, char **argv) {
|
2020-07-21 11:15:10 +00:00
|
|
|
// init
|
2020-07-22 06:19:37 +00:00
|
|
|
Tri::State state(argc, argv);
|
2020-07-21 11:34:39 +00:00
|
|
|
|
2020-07-21 11:15:10 +00:00
|
|
|
// main loop
|
2020-07-22 06:19:37 +00:00
|
|
|
while(state.get_flags().test(1)) {
|
2020-07-22 06:11:10 +00:00
|
|
|
state.handle_events();
|
2020-07-21 11:34:39 +00:00
|
|
|
state.update();
|
|
|
|
state.draw();
|
2020-07-21 11:15:10 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 11:03:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-08-09 07:14:33 +00:00
|
|
|
#endif
|