gs2d::str_type::string ETHSpriteDensityManager::ChooseSpriteVersion(const gs2d::str_type::string& fullFilePath,
										   const gs2d::VideoPtr& video, ETHSpriteDensityManager::DENSITY_LEVEL& densityLevel)
{
	const Platform::FileManagerPtr fileManager = video->GetFileManager();
	const bool shouldUseFullHdResources = ShouldUseFullHdResources(video);
	if (shouldUseFullHdResources)
	{
		const string fullHdVersionFileName(AssembleResourceName(fullFilePath, FULL_HD_VERSION_PATH_NAME));
		if (fileManager->FileExists(fullHdVersionFileName))
		{
			densityLevel = ETHSpriteDensityManager::FULL_HD;
			return fullHdVersionFileName;
		}
	}

	if (ShouldUseHdResources(video) || shouldUseFullHdResources)
	{
		const string hdVersionFileName(AssembleResourceName(fullFilePath, HD_VERSION_PATH_NAME));
		if (fileManager->FileExists(hdVersionFileName))
		{
			densityLevel = ETHSpriteDensityManager::HD;
			return hdVersionFileName;
		}
	}

	densityLevel = ETHSpriteDensityManager::DEFAULT;
	return fullFilePath;
}
ETHEntityProperties::ETHEntityProperties(const str_type::string& filePath, const Platform::FileManagerPtr& fileManager)
{
	ETHEntityMaterial::Reset();
	Reset();

	TiXmlDocument doc(filePath);
	str_type::string content;
	fileManager->GetUTF16FileString(filePath, content);
	if (!doc.LoadFile(content, TIXML_ENCODING_LEGACY))
	{
		ETH_STREAM_DECL(ss) << GS_L("Couldn't load file: ") << filePath;
		ETHResourceProvider::Log(ss.str(), Platform::Logger::ERROR);
		return;
	}

	TiXmlHandle hDoc(&doc);
	TiXmlHandle hRoot(0);

	TiXmlElement *pElem = hDoc.FirstChildElement().Element();
	if (!pElem)
	{
		ETH_STREAM_DECL(ss) << GS_L("The current file seems to be invalid: ") << filePath;
		ETHResourceProvider::Log(ss.str(), Platform::Logger::ERROR);
		return;
	}

	hRoot = TiXmlHandle(pElem);
	entityName = Platform::GetFileName(filePath);
	if (ReadFromXMLFile(hRoot.FirstChildElement().Element()))
	{
		successfullyLoaded = true;
	}
}
예제 #3
0
ETH_WINDOW_ENML_FILE::ETH_WINDOW_ENML_FILE(const str_type::string& fileName, const Platform::FileManagerPtr& fileManager)
{
    width = 640;
    height = 480;
    windowed = true;
    vsync = true;
    title = GS_L("Ethanon Engine");

    str_type::string out;
    fileManager->GetAnsiFileString(fileName, out);
    enml::File file(out);
    if (file.getError() == enml::enmlevSUCCESS)
    {
        file.getUInt(GS_L("window"), GS_L("width"), &width);
        file.getUInt(GS_L("window"), GS_L("height"), &height);
        windowed = (file.get(GS_L("window"), GS_L("windowed")) == GS_L("false")) ? false : true;
        vsync = (file.get(GS_L("window"), GS_L("vsync")) == GS_L("false")) ? false : true;

        const str_type::string newTitle = file.get(GS_L("window"), GS_L("title"));
        title = newTitle.empty() ? title : newTitle;
    }
    else
    {
#ifdef GS2D_STR_TYPE_WCHAR
        std::wcerr
#else
        std::cerr
#endif
                << file.getErrorString() << std::endl;
    }
}
예제 #4
0
ETH_WINDOW_ENML_FILE::ETH_WINDOW_ENML_FILE(const str_type::string& fileName, const Platform::FileManagerPtr& fileManager) :
	width(640),
	height(480),
	windowed(true),
	vsync(true),
	title(GS_L("Ethanon Engine")),
	richLighting(true)
{
	str_type::string out;
	fileManager->GetAnsiFileString(fileName, out);
	enml::File file(out);
	if (file.getError() == enml::enmlevSUCCESS)
	{
		file.getUInt(GS_L("window"), GS_L("width"), &width);
		file.getUInt(GS_L("window"), GS_L("height"), &height);
		windowed = ETHGlobal::IsTrue(file.get(GS_L("window"), GS_L("windowed")));
		vsync = ETHGlobal::IsTrue(file.get(GS_L("window"), GS_L("vsync")));
		const str_type::string newTitle = file.get(GS_L("window"), GS_L("title"));
		richLighting = ETHGlobal::IsTrue(file.get(GS_L("rendering"), GS_L("richLighting")));
		title = newTitle.empty() ? title : newTitle;

		densityManager.FillParametersFromFile(file);
	}
	else
	{
		#ifdef GS2D_STR_TYPE_WCHAR
		std::wcerr
		#else
		std::cerr
		#endif
		 << file.getErrorString() << std::endl;
	}
}
예제 #5
0
bool ETHScene::LoadFromFile(const str_type::string& fileName)
{
	Platform::FileManagerPtr fileManager = m_provider->GetVideo()->GetFileManager();

	// load the scene from a file
	{
		Platform::FileBuffer file;
		fileManager->GetFileBuffer(fileName, file);
		if (!file)
		{
			ETH_STREAM_DECL(ss) << GS_L("ETHScene::Open: file not found (") << fileName << GS_L(")");
			m_provider->Log(ss.str(), Platform::FileLogger::ERROR);
			return false;
		}
	}
	m_minSceneHeight = 0.0f;
	m_maxSceneHeight = m_provider->GetVideo()->GetScreenSizeF().y;

	// Read the header and check if the file is valid
	TiXmlDocument doc(fileName);
	str_type::string content;
	fileManager->GetUTF16FileString(fileName, content);
	if (!doc.LoadFile(content, TIXML_ENCODING_LEGACY))
	{
		ETH_STREAM_DECL(ss) << GS_L("ETHScene::Open: file found, but parsing failed (") << fileName << GS_L(")");
		m_provider->Log(ss.str(), Platform::FileLogger::ERROR);
		return false;
	}

	TiXmlHandle hDoc(&doc);
	TiXmlHandle hRoot(0);

	TiXmlElement *pElement = hDoc.FirstChildElement().Element();
	if (!pElement)
	{
		ETH_STREAM_DECL(ss) << GS_L("ETHScene::Open: couldn't find root element (") << fileName << GS_L(")");
		m_provider->Log(ss.str(), Platform::FileLogger::ERROR);
		return false;
	}
	return ReadFromXMLFile(pElement);
}
bool ETHEntityProperties::SaveToFile(const str_type::string& filePath, const Platform::FileManagerPtr& fileManager)
{
	GS2D_UNUSED_ARGUMENT(fileManager);
	TiXmlDocument doc;
	TiXmlDeclaration *pDecl = new TiXmlDeclaration(GS_L("1.0"), GS_L(""), GS_L(""));
	doc.LinkEndChild(pDecl);

	TiXmlElement *pElement = new TiXmlElement(GS_L("Ethanon"));
	doc.LinkEndChild(pElement);

	WriteToXMLFile(doc.RootElement());
	doc.SaveFile(filePath);
	#ifdef GS2D_STR_TYPE_ANSI
	  fileManager->ConvertAnsiFileToUTF16LE(filePath);
	#endif
	return true;
}
예제 #7
0
bool ETHParticleSystem::ReadFromFile(const str_type::string& fileName, const Platform::FileManagerPtr& fileManager)
{
	TiXmlDocument doc(fileName);
	str_type::string content;
	fileManager->GetUTFFileString(fileName, content);
	if (!doc.LoadFile(content, TIXML_ENCODING_LEGACY))
		return false;

	TiXmlHandle hDoc(&doc);
	TiXmlHandle hRoot(0);

	TiXmlElement *pElem = hDoc.FirstChildElement().Element();
	if (!pElem)
		return false;

	hRoot = TiXmlHandle(pElem);

	return ReadFromXMLFile(hRoot.FirstChildElement().Element());
}
예제 #8
0
bool AudiereSample::LoadSampleFromFile(AudioWeakPtr audio, const std::wstring& fileName,
									   const Platform::FileManagerPtr& fileManager, const GS_SAMPLE_TYPE type)
{
	Platform::FileBuffer out;
	fileManager->GetFileBuffer(fileName, out);
	bool r = false;

	if (out)
	{
		r = LoadSampleFromFileInMemory(audio, out->GetAddress(), out->GetBufferSize(), type);
	}

	if (!r)
	{
		std::wstringstream ss;
		ss << L"Failed while loading the file: " << fileName;
		ShowMessage(ss);
		return false;
	}
	return r;
}
예제 #9
0
ETHAppEnmlFile::ETHAppEnmlFile(const str_type::string& fileName, const Platform::FileManagerPtr& fileManager,
							   const gs2d::str_type::string& platformName) :
	hdDensityValue(2.0f),
	fullHdDensityValue(4.0f),
	width(640),
	height(480),
	windowed(true),
	vsync(true),
	title(GS_L("Ethanon Engine")),
	richLighting(true),
	minScreenHeightForHdVersion(720),
	minScreenHeightForFullHdVersion(1080)
{
	str_type::string out;
	fileManager->GetAnsiFileString(fileName, out);
	enml::File file(out);
	if (file.GetError() == enml::RV_SUCCESS)
	{
		LoadProperties(ETH_DEFAULT_PROPERTY_APP_ENML_ENTITY, file);

		// also read "window" entity for backwards project compatibility
		LoadProperties(ETH_OLDER_DEFAULT_PROPERTY_APP_ENML_ENTITY, file);

		// now read platform specific properties
		if (platformName != GS_L(""))
			LoadProperties(platformName, file);

		densityManager.FillParametersFromFile(*this);
	}
	else
	{
#		ifdef GS2D_STR_TYPE_WCHAR
			std::wcerr
#		else
			std::cerr
#		endif
			<< file.GetErrorString() << std::endl;
	}
}
예제 #10
0
ETH_STARTUP_RESOURCES_ENML_FILE::ETH_STARTUP_RESOURCES_ENML_FILE(const str_type::string& fileName, const Platform::FileManagerPtr& fileManager)
{
    emtprojFilename = GS_L("");
    escFilename = GS_L("");

    str_type::string out;
    fileManager->GetAnsiFileString(fileName, out);
    enml::File file(out);
    if (file.getError() == enml::enmlevSUCCESS)
    {
        emtprojFilename = file.get(GS_L("startup"), GS_L("project"));
        escFilename = file.get(GS_L("startup"), GS_L("scene"));
    }
    else
    {
#ifdef GS2D_STR_TYPE_WCHAR
        std::wcerr
#else
        std::cerr
#endif
                << file.getErrorString() << std::endl;
    }
}
예제 #11
0
bool ETHParticleManager::CreateParticleSystem(
	const ETHParticleSystem& partSystem,
	const Vector2& v2Pos,
	const Vector3& v3Pos,
	const float angle,
	const float entityVolume,
	const float scale)
{
	GS2D_UNUSED_ARGUMENT(v3Pos);
	if (partSystem.nParticles <= 0)
	{
		ETH_STREAM_DECL(ss) << GS_L("ETHParticleManager::CreateParticleSystem: The number of particles must be greater than 0.");
		m_provider->Log(ss.str(), Platform::FileLogger::ERROR);
		return false;
	}

	m_finished = false;
	m_killed = false;
	m_nActiveParticles = 0;
	m_soundVolume = 1.0f;
	m_isSoundLooping = false;
	m_isSoundStopped = false;
	m_generalVolume = 1.0f;
	m_system = partSystem;
	m_entityVolume = entityVolume;

	m_system.Scale(scale);

	if (m_system.bitmapFile.empty())
	{
		m_system.bitmapFile = ETH_DEFAULT_PARTICLE_BITMAP;
	}

	ETHGraphicResourceManagerPtr graphics = m_provider->GetGraphicResourceManager();
	ETHAudioResourceManagerPtr samples = m_provider->GetAudioResourceManager();
	Platform::FileIOHubPtr fileIOHub = m_provider->GetFileIOHub();
	Platform::FileManagerPtr fileManager = m_provider->GetFileManager();

	// if there's no resource path, search the current module's path
	const str_type::string& resourcePath = fileIOHub->GetResourceDirectory();
	const str_type::string& programPath  = fileIOHub->GetProgramDirectory();
	const str_type::string currentPath = (resourcePath.empty() && !fileManager->IsPacked()) ? programPath : resourcePath;

	m_pBMP = graphics->GetPointer(m_provider->GetVideo(), m_system.bitmapFile, currentPath,
		ETHDirectories::GetParticlesDirectory(), (m_system.alphaMode == Video::AM_ADD));

	// find the particle sound effect
	if (m_system.soundFXFile != GS_L(""))
	{
		m_pSound = samples->GetPointer(m_provider->GetAudio(), m_provider->GetFileIOHub(), m_system.soundFXFile,
			ETHDirectories::GetSoundFXDirectory(), Audio::SOUND_EFFECT);
	}

	if (m_system.allAtOnce)
	{
		m_nActiveParticles = m_system.nParticles;
	}
	else
	{
		m_nActiveParticles = 0;
	}

	m_particles.resize(m_system.nParticles);

	Matrix4x4 rot = RotateZ(DegreeToRadian(angle));
	for (int t = 0; t < m_system.nParticles; t++)
	{
		m_particles[t].id = t;
		m_particles[t].released = false;
		ResetParticle(t, v2Pos, Vector3(v2Pos,0), angle, rot);
	}
	return true;
}
예제 #12
0
bool FileExists(const str_type::string& file, const Platform::FileManagerPtr& fileManager)
{
	return fileManager->FileExists(file);
}