Пример #1
0
void Grafkit::SceneLoader::SceneLoaderHelper::PersistEntities(Archive &ar, IResourceManager * const & resman)
{
	UINT entityCount = 0;
	if (ar.IsStoring())
		entityCount = m_entities.size();

	PERSIST_FIELD(ar, entityCount);
	for (UINT i = 0; i < entityCount; ++i) {
		Entity3D* entity = nullptr;
		if (ar.IsStoring())
			entity = m_entities[i];

		PERSIST_OBJECT(ar, entity);

		if (!ar.IsStoring()) {
			m_entities.push_back(entity);
		}
	}
}
Пример #2
0
void Grafkit::SceneLoader::SceneLoaderHelper::PersistAnimations(Archive &ar, IResourceManager * const & resman)
{
	UINT animationCount = 0;
	if (ar.IsStoring())
		animationCount = m_Animations.size();

	PERSIST_FIELD(ar, animationCount);

	for (UINT i = 0; i < animationCount; ++i) {
		Animation* animation = nullptr;

		if (ar.IsStoring())
			animation = m_Animations[i];

		PERSIST_OBJECT(ar, animation);

		if (!ar.IsStoring())
			m_Animations.push_back(animation);
	}
}
Пример #3
0
void Grafkit::SceneLoader::SceneLoaderHelper::PersistActors(Archive &ar, IResourceManager * const & resman)
{
	UINT actorCount = 0;
	if (ar.IsStoring())
		actorCount = m_actors.size();

	PERSIST_FIELD(ar, actorCount);

	for (UINT i = 0; i < actorCount; ++i) {
		Actor* actor = nullptr;

		if (ar.IsStoring())
			actor = m_actors[i];

		PERSIST_OBJECT(ar, actor);

		if (!ar.IsStoring())
			m_actors.push_back(actor);
	}
}
Пример #4
0
void Grafkit::SceneLoader::SceneLoaderHelper::PersistKeymap(Archive & ar, std::vector<assoc_t>& keymap)
{
	UINT size = 0;
	assoc_t pair;

	if (ar.IsStoring())
		size = keymap.size();
	else
		keymap.clear();

	PERSIST_FIELD(ar, size);

	for (size_t i = 0; i < size; ++i) {

		if (ar.IsStoring())
			pair = keymap[i];

		PERSIST_FIELD(ar, pair.first);
		PERSIST_FIELD(ar, pair.second);

		if (!ar.IsStoring())
			keymap.push_back(pair);
	}
}
Пример #5
0
void Grafkit::SceneLoader::SceneLoaderHelper::PersistMaterials(Archive &ar, IResourceManager * const & resman)
{
	UINT materialCount = 0;
	if (ar.IsStoring())
		materialCount = m_materials.size();

	PERSIST_FIELD(ar, materialCount);
	for (UINT i = 0; i < materialCount; ++i) {

		Material *material = nullptr;
		if (ar.IsStoring())
			material = m_materials[i];

		PERSIST_OBJECT(ar, material);

		if (!ar.IsStoring())
			m_materials.push_back(material);

		// materials_to_textures
		std::vector<texture_bind_t> tx_bind;
		UINT textureCount = 0;

		if (ar.IsStoring()) {
			tx_bind = m_textures_to_materials[i];
			textureCount = tx_bind.size();
		}

		PERSIST_FIELD(ar, textureCount);

		for (UINT j = 0; j < textureCount; ++j) {
			texture_bind_t tx;
			if (ar.IsStoring())
				tx = tx_bind[j];

			PERSIST_STRING(ar, tx.first);
			PERSIST_STRING(ar, tx.second);

			if (!ar.IsStoring()) {
				TextureResRef texture = resman->Get<Texture2DRes>(tx.first);
				material->AddTexture(texture, tx.second);
			}
		}
	}
}
Пример #6
0
void Grafkit::SceneLoader::SceneLoaderHelper::Persist(Archive & ar, IResourceManager * const & resman)
{
	try {
		// --- persist scene 
		PERSIST_REFOBJECT(ar, m_scene);

		if (!ar.IsStoring() && m_scene.Invalid())
			throw new EX(SceneLoadException);

		PersistMaterials(ar, resman);
		PersistEntities(ar, resman);
		PersistActors(ar, resman);
		PersistAnimations(ar, resman);

		PersistKeymap(ar, m_materials_to_meshes);
		PersistKeymap(ar, m_entities_to_actors);
		PersistKeymap(ar, m_actor_to_actor);
		PersistKeymap(ar, m_animation_to_actor);
		PersistKeymap(ar, m_animation_to_entity);
	}
	catch (int i) {
		return;
	}
}
Пример #7
0
Grafkit::SceneLoader::SceneLoaderHelper::SceneLoaderHelper(Archive &ar, SceneRef & scene) : m_scene(scene)
{
	if (ar.IsStoring()) {
		BuildObjectMaps();
	}
}