Exemple #1
0
	void universeFileLoaded(Lumix::FS::IFile& file,
							bool success,
							Lumix::FS::FileSystem& fs)
	{
		ASSERT(success);
		if (success)
		{
			ASSERT(file.getBuffer());
			Lumix::InputBlob blob(file.getBuffer(), file.size());
			uint32_t hash = 0;
			blob.read(hash);
			uint32_t engine_hash = 0;
			blob.read(engine_hash);
			if (Lumix::crc32((const uint8_t*)blob.getData() + sizeof(hash),
							 blob.getSize() - sizeof(hash)) != hash)
			{
				ASSERT(false);
				return;
			}
			bool deserialize_succeeded =
				m_engine->deserialize(*m_universe_context, blob);
			m_is_test_universe_loaded = true;
			ASSERT(deserialize_succeeded);
		}

		fs.close(file);
	}
	void universeFileLoaded(Lumix::FS::IFile& file, bool success)
	{
		ASSERT(success);
		if (!success) return;

		ASSERT(file.getBuffer());
		Lumix::InputBlob blob(file.getBuffer(), (int)file.size());
		#pragma pack(1)
			struct Header
			{
				Lumix::uint32 magic;
				int version;
				Lumix::uint32 hash;
				Lumix::uint32 engine_hash;
			};
		#pragma pack()
		Header header;
		blob.read(header);
		if (Lumix::crc32((const uint8_t*)blob.getData() + sizeof(header), blob.getSize() - sizeof(header)) !=
			header.hash)
		{
			Lumix::g_log_error.log("App") << "Universe corrupted";
			return;
		}
		m_universe->resetScenes();
		bool deserialize_succeeded = m_engine->deserialize(*m_universe, blob);
		if (!deserialize_succeeded)
		{
			Lumix::g_log_error.log("App") << "Failed to deserialize universe";
		}
	}
static void
executeEditorCommand(lua_State* L, const char* name, const char* data)
{
	if (lua_getglobal(L, "API_plugin_loader") == LUA_TLIGHTUSERDATA)
	{
		auto loader = (EditorPluginLoader*)lua_touserdata(L, -1);
		auto& editor = loader->getMainWindow().getWorldEditor();
		auto& engine = editor.getEngine();
		auto* command = editor.createEditorCommand(Lumix::crc32(name));
		if (command)
		{
			Lumix::FS::IFile* file = engine.getFileSystem().open(
				engine.getFileSystem().getMemoryDevice(),
				"",
				Lumix::FS::Mode::WRITE);
			ASSERT(file);
			file->write(data, strlen(data));
			file->seek(Lumix::FS::SeekMode::BEGIN, 0);
			Lumix::JsonSerializer serializer(
				*file, Lumix::JsonSerializer::READ, "", engine.getAllocator());
			command->deserialize(serializer);
			editor.executeCommand(command);
			engine.getFileSystem().close(*file);
		}
	}
	lua_pop(L, 1);
}
	void startupScriptLoaded(Lumix::FS::IFile& file, bool success)
	{
		if (!success)
		{
			Lumix::g_log_error.log("App") << "Could not open " << m_startup_script_path;
			return;
		}

		m_engine->runScript((const char*)file.getBuffer(), (int)file.size(), m_startup_script_path);
	}