예제 #1
0
	virtual bool deserialize(UniverseContext& ctx,
							 InputBlob& serializer) override
	{
		SerializedEngineHeader header;
		serializer.read(header);
		if (header.m_magic != SERIALIZED_ENGINE_MAGIC)
		{
			g_log_error.log("engine") << "Wrong or corrupted file";
			return false;
		}
		if (header.m_version > SerializedEngineVersion::LATEST)
		{
			g_log_error.log("engine") << "Unsupported version";
			return false;
		}
		if (!hasSerializedPlugins(serializer))
		{
			return false;
		}
		g_path_manager.deserialize(serializer);
		ctx.m_universe->deserialize(serializer);
		ctx.m_hierarchy->deserialize(serializer);
		m_plugin_manager->deserialize(serializer);
		int32_t scene_count;
		serializer.read(scene_count);
		for (int i = 0; i < scene_count; ++i)
		{
			char tmp[32];
			serializer.readString(tmp, sizeof(tmp));
			IScene* scene = ctx.getScene(crc32(tmp));
			scene->deserialize(serializer);
		}
		g_path_manager.clear();
		return true;
	}
예제 #2
0
void ParticleEmitter::SizeModule::deserialize(InputBlob& blob)
{
	int size;
	blob.read(size);
	m_values.resize(size);
	blob.read(&m_values[0], sizeof(m_values[0]) * m_values.size());
	sample();
}
예제 #3
0
void ParticleEmitter::PlaneModule::deserialize(InputBlob& blob, int)
{
	blob.read(m_bounce);
	blob.read(m_count);
	for (int i = 0; i < m_count; ++i)
	{
		blob.read(m_entities[i]);
	}
}
예제 #4
0
void ParticleEmitter::AttractorModule::deserialize(InputBlob& blob)
{
	blob.read(m_force);
	blob.read(m_count);
	for(int i = 0; i < m_count; ++i)
	{
		blob.read(m_entities[i]);
	}
}
예제 #5
0
void ParticleEmitter::SizeModule::deserialize(InputBlob& blob, int version)
{
	if (version <= (int)ParticleEmitterVersion::SIZE_ALPHA_SAVE) return;

	int size;
	blob.read(size);
	m_values.resize(size);
	blob.read(&m_values[0], sizeof(m_values[0]) * m_values.size());
	sample();
}
예제 #6
0
void ParticleEmitter::deserialize(InputBlob& blob, ResourceManager& manager)
{
	blob.read(m_spawn_count);
	blob.read(m_spawn_period);
	blob.read(m_initial_life);
	blob.read(m_initial_size);
	blob.read(m_entity);
	blob.read(m_autoemit);
	blob.read(m_local_space);
	char path[MAX_PATH_LENGTH];
	blob.readString(path, lengthOf(path));
	auto material_manager = manager.get(MATERIAL_TYPE);
	auto material = static_cast<Material*>(material_manager->load(Path(path)));
	setMaterial(material);

	int size;
	blob.read(size);
	for (auto* module : m_modules)
	{
		LUMIX_DELETE(m_allocator, module);
	}
	m_modules.clear();
	for (int i = 0; i < size; ++i)
	{
		ParticleEmitter::ModuleBase* module = nullptr;
		u32 hash;
		blob.read(hash);
		ComponentType type = PropertyRegister::getComponentTypeFromHash(hash);
		module = createModule(type, *this);
		if (module)
		{
			m_modules.push(module);
		}
	}
}
예제 #7
0
void ParticleEmitter::deserialize(InputBlob& blob, ResourceManager& manager, bool has_version)
{
	int version = (int)ParticleEmitterVersion::INVALID;
	if (has_version)
	{
		blob.read(version);
		if (version > (int)ParticleEmitterVersion::SPAWN_COUNT) blob.read(m_spawn_count);
	}
	blob.read(m_spawn_period);
	blob.read(m_initial_life);
	blob.read(m_initial_size);
	blob.read(m_entity);
	char path[MAX_PATH_LENGTH];
	blob.readString(path, lengthOf(path));
	auto material_manager = manager.get(ResourceManager::MATERIAL);
	auto material = static_cast<Material*>(material_manager->load(Lumix::Path(path)));
	setMaterial(material);

	int size;
	blob.read(size);
	for (auto* module : m_modules)
	{
		LUMIX_DELETE(m_allocator, module);
	}
	m_modules.clear();
	for (int i = 0; i < size; ++i)
	{
		uint32 type;
		blob.read(type);
		auto* module = createModule(type, *this);
		m_modules.push(module);
		module->deserialize(blob, version);
	}
}
예제 #8
0
void Universe::deserialize(InputBlob& serializer)
{
	int32 count;
	serializer.read(count);
	m_transformations.resize(count);

	serializer.read(&m_transformations[0], sizeof(m_transformations[0]) * m_transformations.size());

	serializer.read(count);
	m_id_to_name_map.clear();
	m_name_to_id_map.clear();
	for (int i = 0; i < count; ++i)
	{
		uint32 key;
		char name[50];
		serializer.read(key);
		serializer.readString(name, sizeof(name));
		m_id_to_name_map.insert(key, string(name, m_allocator));
		m_name_to_id_map.insert(crc32(name), key);
	}

	serializer.read(m_first_free_slot);
	serializer.read(count);
	m_id_map.resize(count);
	if (!m_id_map.empty())
	{
		serializer.read(&m_id_map[0], sizeof(m_id_map[0]) * count);
	}
}
예제 #9
0
	void PathManager::deserialize(InputBlob& serializer)
	{
		MT::SpinLock lock(m_mutex);
		int32 size;
		serializer.read(size);
		for (int i = 0; i < size; ++i)
		{
			char path[MAX_PATH_LENGTH];
			serializer.readString(path, sizeof(path));
			uint32 hash = crc32(path);
			PathInternal* internal = getPathMultithreadUnsafe(hash, path);
			--internal->m_ref_count;
		}
	}
예제 #10
0
	bool deserialize(UniverseContext& ctx, InputBlob& serializer) override
	{
		SerializedEngineHeader header;
		serializer.read(header);
		if (header.m_magic != SERIALIZED_ENGINE_MAGIC)
		{
			g_log_error.log("engine") << "Wrong or corrupted file";
			return false;
		}
		if (header.m_version > SerializedEngineVersion::LATEST)
		{
			g_log_error.log("engine") << "Unsupported version";
			return false;
		}
		if (!hasSerializedPlugins(serializer))
		{
			return false;
		}
		if (header.m_version > SerializedEngineVersion::SCENE_VERSION_CHECK &&
			!hasSupportedSceneVersions(serializer, ctx))
		{
			return false;
		}

		m_path_manager.deserialize(serializer);
		ctx.m_universe->deserialize(serializer);

		if (header.m_version <= SerializedEngineVersion::HIERARCHY_COMPONENT)
		{
			ctx.getScene(HIERARCHY_HASH)->deserialize(serializer, 0);
		}

		m_plugin_manager->deserialize(serializer);
		int32 scene_count;
		serializer.read(scene_count);
		for (int i = 0; i < scene_count; ++i)
		{
			char tmp[32];
			serializer.readString(tmp, sizeof(tmp));
			IScene* scene = ctx.getScene(crc32(tmp));
			int scene_version = -1;
			if (header.m_version > SerializedEngineVersion::SCENE_VERSION)
			{
				serializer.read(scene_version);
			}
			scene->deserialize(serializer, scene_version);
		}
		m_path_manager.clear();
		return true;
	}
예제 #11
0
	bool hasSerializedPlugins(InputBlob& serializer)
	{
		int32 count;
		serializer.read(count);
		for (int i = 0; i < count; ++i)
		{
			char tmp[32];
			serializer.readString(tmp, sizeof(tmp));
			if (!m_plugin_manager->getPlugin(tmp))
			{
				g_log_error.log("engine") << "Missing plugin " << tmp;
				return false;
			}
		}
		return true;
	}
예제 #12
0
	void deserialize(InputBlob& serializer) override
	{
		int count;
		serializer.read(count);
		m_prefabs.resize(count);
		if (count > 0)
			serializer.read(&m_prefabs[0], m_prefabs.size() * sizeof(m_prefabs[0]));
		serializer.read(count);
		for (int i = 0; i < count; ++i)
		{
			u64 key;
			Entity value;
			serializer.read(key);
			serializer.read(value);
			m_instances.insert(key, value);
		}
		serializer.read(count);
		auto* resource_manager = m_editor.getEngine().getResourceManager().get(PrefabResource::TYPE);
		for (int i = 0; i < count; ++i)
		{
			char tmp[MAX_PATH_LENGTH];
			serializer.readString(tmp, lengthOf(tmp));
			auto* res = (PrefabResource*)resource_manager->load(Path(tmp));
			m_resources.insert(res->getPath().getHash(), res);
		}
	}
예제 #13
0
	bool hasSupportedSceneVersions(InputBlob& serializer, UniverseContext& ctx)
	{
		int32 count;
		serializer.read(count);
		for (int i = 0; i < count; ++i)
		{
			uint32 hash;
			serializer.read(hash);
			auto* scene = ctx.getScene(hash);
			int version;
			serializer.read(version);
			if (version > scene->getVersion())
			{
				g_log_error.log("engine") << "Plugin " << scene->getPlugin().getName() << " is too old";
				return false;
			}
		}
		return true;
	}
예제 #14
0
			void deserialize(InputBlob& serializer) override
			{
				int32_t count;
				serializer.read(count);
				m_script_entities.resize(count);
				m_paths.clear();
				m_paths.reserve(count);
				for (int i = 0; i < m_script_entities.size(); ++i)
				{
					serializer.read(m_script_entities[i]);
					char path[LUMIX_MAX_PATH];
					serializer.readString(path, sizeof(path));
					m_paths.push(Path(path));
					Entity entity(&m_universe, m_script_entities[i]);
					if(m_script_entities[i] != -1)
					{
						m_universe.addComponent(entity, SCRIPT_HASH, this, i);
					}
				}
			}
	void deserialize(InputBlob& serializer) override
	{
		m_template_names.clear();
		m_instances.clear();
		int32 count;
		serializer.read(count);
		for (int i = 0; i < count; ++i)
		{
			const int MAX_NAME_LENGTH = 50;
			char name[MAX_NAME_LENGTH];
			serializer.readString(name, MAX_NAME_LENGTH);
			m_template_names.push(string(name, m_editor.getAllocator()));
		}
		serializer.read(count);
		for (int i = 0; i < count; ++i)
		{
			uint32 hash;
			serializer.read(hash);
			int32 instances_per_template;
			serializer.read(instances_per_template);
			m_instances.insert(hash, Array<Entity>(m_editor.getAllocator()));
			Array<Entity>& entities = m_instances.get(hash);
			for (int j = 0; j < instances_per_template; ++j)
			{
				int32 entity_index;
				serializer.read(entity_index);
				entities.push(Entity(entity_index));
			}
		}
		m_updated.invoke();
	}
예제 #16
0
		void set(ComponentUID cmp, int index, InputBlob& stream) const override
		{
			int value;
			stream.read(&value, sizeof(value));
			if (index == -1)
			{
				(static_cast<PhysicsScene*>(cmp.scene)->*m_single.setter)(cmp.handle, value);
			}
			else
			{
				(static_cast<PhysicsScene*>(cmp.scene)->*m_array.setter)(cmp.handle, index, value);
			}
		};
예제 #17
0
	void deserialize(InputBlob& serializer, int) override
	{
		int32 count;
		serializer.read(count);
		m_animables.resize(count);
		for (int i = 0; i < count; ++i)
		{
			serializer.read(m_animables[i].m_entity);
			ComponentIndex renderable =
				m_render_scene->getRenderableComponent(m_animables[i].m_entity);
			if (renderable >= 0)
			{
				m_animables[i].m_renderable = renderable;
			}
			serializer.read(m_animables[i].m_time);
			serializer.read(m_animables[i].m_is_free);
			char path[MAX_PATH_LENGTH];
			serializer.readString(path, sizeof(path));
			m_animables[i].m_animation = path[0] == '\0' ? nullptr : loadAnimation(path);
			m_universe.addComponent(m_animables[i].m_entity, ANIMABLE_HASH, this, i);
		}
	}
예제 #18
0
	OutputBlob::OutputBlob(const InputBlob& blob, IAllocator& allocator)
		: m_allocator(&allocator)
		, m_pos(blob.getSize())
	{
		if (blob.getSize() > 0)
		{
			m_data = allocator.allocate(blob.getSize());
			copyMemory(m_data, blob.getData(), blob.getSize());
			m_size = blob.getSize();
		}
		else
		{
			m_data = nullptr;
			m_size = 0;
		}
	}
예제 #19
0
	void deserialize(InputBlob& serializer, int version) override
	{
		int32 count;
		serializer.read(count);
		m_animables.reserve(count);
		for (int i = 0; i < count; ++i)
		{
			Animable animable;
			serializer.read(animable.entity);
			bool free = false;
			if (version <= (int)AnimationSceneVersion::FIRST)
			{
				serializer.read(animable.time);
				serializer.read(free);
				animable.time_scale = 1;
				animable.start_time = 0;
			}
			else
			{
				uint32 flags = 0;
				if(version <= (int)AnimationSceneVersion::REFACTOR) serializer.read(flags);
				free = flags != 0;
				serializer.read(animable.time_scale);
				serializer.read(animable.start_time);
				animable.time = animable.start_time;
			}

			char path[MAX_PATH_LENGTH];
			serializer.readString(path, sizeof(path));
			animable.animation = path[0] == '\0' ? nullptr : loadAnimation(Path(path));
			if (!free)
			{
				m_animables.insert(animable.entity, animable);
				ComponentHandle cmp = {animable.entity.index};
				m_universe.addComponent(animable.entity, ANIMABLE_TYPE, this, cmp);
			}
		}
	}
예제 #20
0
void ParticleEmitter::LinearMovementModule::deserialize(InputBlob& blob, int)
{
	blob.read(m_x);
	blob.read(m_y);
	blob.read(m_z);
}
예제 #21
0
void ParticleEmitter::SubimageModule::deserialize(InputBlob& blob)
{
	blob.read(rows);
	blob.read(cols);
}
예제 #22
0
void ParticleEmitter::SpawnShapeModule::deserialize(InputBlob& blob, int)
{
	blob.read(m_shape);
	blob.read(m_radius);
}
예제 #23
0
void ParticleEmitter::ForceModule::deserialize(InputBlob& blob, int)
{
	blob.read(m_acceleration);
}