void Device::init() { // Initialize CE_LOGI("Initializing Crown Engine %s...", version()); // Create resource manager CE_LOGD("Creating resource manager..."); _resource_manager = CE_NEW(_allocator, ResourceManager)(_fs); CE_LOGD("Creating material manager..."); material_manager::init(); debug_line::init(); _lua_environment = CE_NEW(_allocator, LuaEnvironment)(); _lua_environment->load_libs(); CE_LOGD("Crown Engine initialized."); CE_LOGD("Initializing Game..."); _is_init = true; _is_running = true; _last_time = os::clocktime(); _boot_package = create_resource_package(_boot_package_id); _boot_package->load(); _boot_package->flush(); _lua_environment->execute((LuaResource*)_resource_manager->get(SCRIPT_TYPE, _boot_script_id)); _lua_environment->call_global("init", 0); }
//----------------------------------------------------------------------------- DiskFile* Filesystem::open(const char* relative_path, FileOpenMode mode) { CE_ASSERT(exists(relative_path), "File does not exist: %s", relative_path); CE_ASSERT(is_file(relative_path), "File is not a regular file: %s", relative_path); return CE_NEW(m_allocator, DiskFile)(mode, os_path(relative_path)); }
File* DiskFilesystem::open(const char* path, FileOpenMode mode) { CE_ASSERT_NOT_NULL(path); TempAllocator256 alloc; DynamicString abs_path(alloc); get_absolute_path(path, abs_path); return CE_NEW(default_allocator(), DiskFile)(mode, abs_path.c_str()); }
//----------------------------------------------------------------------------- void Device::init() { // Initialize CE_LOGI("Initializing Crown Engine %s...", version()); _resource_bundle = Bundle::create(_allocator, _fs); // Create resource manager CE_LOGD("Creating resource manager..."); _resource_manager = CE_NEW(_allocator, ResourceManager)(*_resource_bundle); // Create world manager CE_LOGD("Creating world manager..."); _world_manager = CE_NEW(_allocator, WorldManager)(); CE_LOGD("Creating material manager..."); material_manager::init(); CE_LOGD("Creating lua system..."); lua_system::init(); _lua_environment = CE_NEW(_allocator, LuaEnvironment)(lua_system::state()); CE_LOGD("Crown Engine initialized."); CE_LOGD("Initializing Game..."); _is_init = true; _is_running = true; _last_time = os::clocktime(); _boot_package = create_resource_package(_boot_package_id); _boot_package->load(); _boot_package->flush(); ResourceId bootid; bootid.type = LUA_TYPE; bootid.name = _boot_script_id; _lua_environment->execute((LuaResource*) _resource_manager->get(bootid)); _lua_environment->call_global("init", 0); }
void* load(File& file, Allocator& a) { BinaryReader br(file); u32 version; br.read(version); CE_ASSERT(version == RESOURCE_VERSION_PACKAGE, "Wrong version"); u32 num_resources; br.read(num_resources); PackageResource* pr = CE_NEW(a, PackageResource)(a); array::resize(pr->resources, num_resources); br.read(array::begin(pr->resources), sizeof(PackageResource::Resource)*num_resources); return pr; }
void* ShaderManager::load(File& file, Allocator& a) { BinaryReader br(file); u32 version; br.read(version); CE_ASSERT(version == RESOURCE_VERSION_SHADER, "Wrong version"); u32 num; br.read(num); ShaderResource* sr = CE_NEW(a, ShaderResource)(a); array::resize(sr->_data, num); for (u32 i = 0; i < num; ++i) { u32 shader_name; br.read(shader_name); u64 render_state; br.read(render_state); u32 vs_code_size; br.read(vs_code_size); const bgfx::Memory* vsmem = bgfx::alloc(vs_code_size); br.read(vsmem->data, vs_code_size); u32 fs_code_size; br.read(fs_code_size); const bgfx::Memory* fsmem = bgfx::alloc(fs_code_size); br.read(fsmem->data, fs_code_size); sr->_data[i].name._id = shader_name; sr->_data[i].state = render_state; sr->_data[i].vsmem = vsmem; sr->_data[i].fsmem = fsmem; } return sr; }
void init() { _keyboard = CE_NEW(default_allocator(), Keyboard); _mouse = CE_NEW(default_allocator(), Mouse); _touch = CE_NEW(default_allocator(), Touch); }
void init(Filesystem& fs, StringId64 boot_package, StringId64 boot_script) { CE_ASSERT(_device == NULL, "Crown already initialized"); _device = CE_NEW(default_allocator(), Device)(fs, boot_package, boot_script); }
//----------------------------------------------------------------------------- ResourcePackage* Device::create_resource_package(StringId64 id) { return CE_NEW(default_allocator(), ResourcePackage)(id, *_resource_manager); }
File* NetworkFilesystem::open(const char* path, FileOpenMode mode) { return CE_NEW(default_allocator(), NetworkFile)(_address, _port, path); }
SoundWorld* SoundWorld::create(Allocator& a) { return CE_NEW(a, NullSoundWorld)(); }
World* Device::create_world() { World* w = CE_NEW(default_allocator(), World)(*_resource_manager, *_lua_environment); array::push_back(_worlds, w); return w; }
SpriteAnimation* SpriteAnimationPlayer::create_sprite_animation(const SpriteAnimationResource* sar) { SpriteAnimation* anim = CE_NEW(default_allocator(), SpriteAnimation)(sar); array::push_back(m_animations, anim); return anim; }
void init() { _console = CE_NEW(default_allocator(), ConsoleServer); }