|
|
@@ -69,16 +69,6 @@ namespace crown
|
|
|
//-----------------------------------------------------------------------------
|
|
|
Device::Device() :
|
|
|
m_allocator(default_allocator(), MAX_SUBSYSTEMS_HEAP),
|
|
|
-
|
|
|
- m_preferred_window_width(1000),
|
|
|
- m_preferred_window_height(625),
|
|
|
- m_preferred_window_fullscreen(0),
|
|
|
- m_parent_window_handle(0),
|
|
|
- m_compile(0),
|
|
|
- m_continue(0),
|
|
|
-
|
|
|
- m_quit_after_init(0),
|
|
|
-
|
|
|
m_is_init(false),
|
|
|
m_is_running(false),
|
|
|
m_is_paused(false),
|
|
|
@@ -113,41 +103,6 @@ Device::~Device()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-bool Device::init(int argc, char** argv)
|
|
|
-{
|
|
|
- CE_ASSERT(!is_init(), "Engine already initialized");
|
|
|
-
|
|
|
- parse_command_line(argc, argv);
|
|
|
- check_preferred_settings();
|
|
|
-
|
|
|
- // Resource compilation only in debug or development mode and only on linux or windows builds
|
|
|
- #if (defined(LINUX) || defined(WINDOWS)) && (defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT))
|
|
|
- if (m_compile == 1)
|
|
|
- {
|
|
|
- m_bundle_compiler = CE_NEW(m_allocator, BundleCompiler);
|
|
|
- if (!m_bundle_compiler->compile(m_bundle_dir, m_source_dir))
|
|
|
- {
|
|
|
- CE_DELETE(m_allocator, m_bundle_compiler);
|
|
|
- m_allocator.clear();
|
|
|
- Log::e("Exiting.");
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
-
|
|
|
- if (!m_continue)
|
|
|
- {
|
|
|
- CE_DELETE(m_allocator, m_bundle_compiler);
|
|
|
- m_allocator.clear();
|
|
|
- exit(EXIT_SUCCESS);
|
|
|
- }
|
|
|
- }
|
|
|
- #endif
|
|
|
-
|
|
|
- init();
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void Device::init()
|
|
|
{
|
|
|
@@ -210,12 +165,6 @@ void Device::init()
|
|
|
}
|
|
|
|
|
|
Log::d("Total allocated size: %llu", m_allocator.allocated_size());
|
|
|
-
|
|
|
- if (m_quit_after_init == 1)
|
|
|
- {
|
|
|
- stop();
|
|
|
- shutdown();
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
@@ -269,16 +218,7 @@ void Device::shutdown()
|
|
|
CE_DELETE(m_allocator, m_filesystem);
|
|
|
}
|
|
|
|
|
|
- #if (defined(LINUX) || defined(WINDOWS)) && (defined(CROWN_DEBUG) || defined(CROWN_DEVELOPMENT))
|
|
|
- Log::i("Releasing BundleCompiler...");
|
|
|
- if (m_bundle_compiler)
|
|
|
- {
|
|
|
- CE_DELETE(m_allocator, m_bundle_compiler);
|
|
|
- }
|
|
|
- #endif
|
|
|
-
|
|
|
m_allocator.clear();
|
|
|
-
|
|
|
m_is_init = false;
|
|
|
}
|
|
|
|
|
|
@@ -464,182 +404,53 @@ void Device::reload(ResourceId name)
|
|
|
(void)name;
|
|
|
}
|
|
|
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-void Device::parse_command_line(int argc, char** argv)
|
|
|
-{
|
|
|
- static ArgsOption options[] =
|
|
|
- {
|
|
|
- { "help", AOA_NO_ARGUMENT, NULL, 'i' },
|
|
|
- { "source-dir", AOA_REQUIRED_ARGUMENT, NULL, 's' },
|
|
|
- { "bundle-dir", AOA_REQUIRED_ARGUMENT, NULL, 'b' },
|
|
|
- { "compile", AOA_NO_ARGUMENT, &m_compile, 1 },
|
|
|
- { "continue", AOA_NO_ARGUMENT, &m_continue, 1 },
|
|
|
- { "width", AOA_REQUIRED_ARGUMENT, NULL, 'w' },
|
|
|
- { "height", AOA_REQUIRED_ARGUMENT, NULL, 'h' },
|
|
|
- { "fullscreen", AOA_NO_ARGUMENT, &m_preferred_window_fullscreen, 1 },
|
|
|
- { "parent-window", AOA_REQUIRED_ARGUMENT, NULL, 'p' },
|
|
|
- { "quit-after-init", AOA_NO_ARGUMENT, &m_quit_after_init, 1 },
|
|
|
- { NULL, 0, NULL, 0 }
|
|
|
- };
|
|
|
-
|
|
|
- Args args(argc, argv, "", options);
|
|
|
-
|
|
|
- int32_t opt;
|
|
|
-
|
|
|
- while ((opt = args.getopt()) != -1)
|
|
|
- {
|
|
|
- switch (opt)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- break;
|
|
|
- }
|
|
|
- // Source directory
|
|
|
- case 's':
|
|
|
- {
|
|
|
- string::strncpy(m_source_dir, args.optarg(), MAX_PATH_LENGTH);
|
|
|
- break;
|
|
|
- }
|
|
|
- // Bundle directory
|
|
|
- case 'b':
|
|
|
- {
|
|
|
- string::strncpy(m_bundle_dir, args.optarg(), MAX_PATH_LENGTH);
|
|
|
- break;
|
|
|
- }
|
|
|
- // Window width
|
|
|
- case 'w':
|
|
|
- {
|
|
|
- m_preferred_window_width = atoi(args.optarg());
|
|
|
- break;
|
|
|
- }
|
|
|
- // Window height
|
|
|
- case 'h':
|
|
|
- {
|
|
|
- m_preferred_window_height = atoi(args.optarg());
|
|
|
- break;
|
|
|
- }
|
|
|
- // Parent window
|
|
|
- case 'p':
|
|
|
- {
|
|
|
- m_parent_window_handle = string::parse_uint(args.optarg());
|
|
|
- break;
|
|
|
- }
|
|
|
- case 'i':
|
|
|
- case '?':
|
|
|
- default:
|
|
|
- {
|
|
|
- print_help_message();
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-void Device::check_preferred_settings()
|
|
|
-{
|
|
|
- if (m_compile == 1)
|
|
|
- {
|
|
|
- if (string::strcmp(m_source_dir, "") == 0)
|
|
|
- {
|
|
|
- Log::e("You have to specify the source directory when running in compile mode.");
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
-
|
|
|
- if (!os::is_absolute_path(m_source_dir))
|
|
|
- {
|
|
|
- Log::e("The source directory must be absolute.");
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!os::is_absolute_path(m_bundle_dir))
|
|
|
- {
|
|
|
- Log::e("The bundle directory must be absolute.");
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
-
|
|
|
- if (m_preferred_window_width == 0 || m_preferred_window_height == 0)
|
|
|
- {
|
|
|
- Log::e("Window width and height must be greater than zero.");
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void Device::read_engine_settings()
|
|
|
{
|
|
|
- // Check crown.config existance
|
|
|
- CE_ASSERT(m_filesystem->is_file("crown.config"), "Unable to open crown.config");
|
|
|
+ // // Check crown.config existance
|
|
|
+ // CE_ASSERT(m_filesystem->is_file("crown.config"), "Unable to open crown.config");
|
|
|
|
|
|
- // Copy crown config in a buffer
|
|
|
- TempAllocator4096 allocator;
|
|
|
+ // // Copy crown config in a buffer
|
|
|
+ // TempAllocator4096 allocator;
|
|
|
|
|
|
- File* config_file = m_filesystem->open("crown.config", FOM_READ);
|
|
|
+ // File* config_file = m_filesystem->open("crown.config", FOM_READ);
|
|
|
|
|
|
- char* json_string = (char*)allocator.allocate(config_file->size());
|
|
|
+ // char* json_string = (char*)allocator.allocate(config_file->size());
|
|
|
|
|
|
- config_file->read(json_string, config_file->size());
|
|
|
+ // config_file->read(json_string, config_file->size());
|
|
|
|
|
|
- m_filesystem->close(config_file);
|
|
|
+ // m_filesystem->close(config_file);
|
|
|
|
|
|
- // Parse crown.config
|
|
|
- JSONParser parser(json_string);
|
|
|
+ // // Parse crown.config
|
|
|
+ // JSONParser parser(json_string);
|
|
|
|
|
|
- JSONElement root = parser.root();
|
|
|
+ // JSONElement root = parser.root();
|
|
|
|
|
|
- // Boot
|
|
|
- if (root.has_key("boot"))
|
|
|
- {
|
|
|
- const char* boot = root.key("boot").string_value();
|
|
|
- const size_t boot_length = string::strlen(boot) + 1;
|
|
|
+ // // Boot
|
|
|
+ // if (root.has_key("boot"))
|
|
|
+ // {
|
|
|
+ // const char* boot = root.key("boot").string_value();
|
|
|
+ // const size_t boot_length = string::strlen(boot) + 1;
|
|
|
|
|
|
- string::strncpy(m_boot_file, boot, boot_length);
|
|
|
- }
|
|
|
- // Window width
|
|
|
- if (root.has_key("window_width"))
|
|
|
- {
|
|
|
- m_preferred_window_width = root.key("window_width").int_value();
|
|
|
- }
|
|
|
- // Window height
|
|
|
- if (root.has_key("window_height"))
|
|
|
- {
|
|
|
- m_preferred_window_height = root.key("window_height").int_value();
|
|
|
- }
|
|
|
+ // string::strncpy(m_boot_file, boot, boot_length);
|
|
|
+ // }
|
|
|
+ // // Window width
|
|
|
+ // if (root.has_key("window_width"))
|
|
|
+ // {
|
|
|
+ // m_preferred_window_width = root.key("window_width").int_value();
|
|
|
+ // }
|
|
|
+ // // Window height
|
|
|
+ // if (root.has_key("window_height"))
|
|
|
+ // {
|
|
|
+ // m_preferred_window_height = root.key("window_height").int_value();
|
|
|
+ // }
|
|
|
|
|
|
- allocator.deallocate(json_string);
|
|
|
+ // allocator.deallocate(json_string);
|
|
|
|
|
|
- Log::i("Configuration set");
|
|
|
-}
|
|
|
-
|
|
|
-//-----------------------------------------------------------------------------
|
|
|
-void Device::print_help_message()
|
|
|
-{
|
|
|
- os::printf(
|
|
|
- "Usage: crown [options]\n"
|
|
|
- "Options:\n\n"
|
|
|
-
|
|
|
- "All of the following options take precedence over\n"
|
|
|
- "environment variables and configuration files.\n\n"
|
|
|
-
|
|
|
- " --help Show this help.\n"
|
|
|
- " --bundle-dir <path> Use <path> as the source directory for compiled resources.\n"
|
|
|
- " --width <width> Set the <width> of the main window.\n"
|
|
|
- " --height <width> Set the <height> of the main window.\n"
|
|
|
- " --fullscreen Start in fullscreen.\n"
|
|
|
- " --parent-window <handle> Set the parent window <handle> of the main window.\n"
|
|
|
- " Used only by tools.\n"
|
|
|
-
|
|
|
- "\nAvailable only in debug and development builds:\n\n"
|
|
|
-
|
|
|
- " --source-dir <path> Use <path> as the source directory for resource compilation.\n"
|
|
|
- " --compile Run the engine as resource compiler.\n"
|
|
|
- " --continue Do a full compile of the resources and continue the execution.\n"
|
|
|
- " --quit-after-init Quit the engine immediately after the initialization.\n");
|
|
|
+ // Log::i("Configuration set");
|
|
|
}
|
|
|
|
|
|
static Device* g_device;
|
|
|
-
|
|
|
void set_device(Device* device)
|
|
|
{
|
|
|
g_device = device;
|