示例#1
0
bool ETHScriptWrapper::LoadSoundEffect(const str_type::string &file)
{
	if (WarnIfRunsInMainFunction(GS_L("LoadSoundEffect")))
		return false;

	str_type::stringstream ss;
	Platform::FileIOHubPtr fileIOHub = m_provider->GetFileIOHub();
	ss << fileIOHub->GetResourceDirectory() << file;
	if (!m_provider->GetAudioResourceManager()->AddFile(m_provider->GetAudio(), fileIOHub, ss.str(), GSST_SOUND_EFFECT))
	{
		ShowMessage(GS_L("Could not load the file: ") + file, ETH_ERROR, false);
		return false;
	}
	return true;
}
示例#2
0
AudioSamplePtr ETHAudioResourceManager::AddFile(
	AudioPtr audio,
	const Platform::FileIOHubPtr& fileIOHub,
	const str_type::string& path,
	const Audio::SAMPLE_TYPE type)
{
	if (!m_resource.empty())
	{
		str_type::string fileName = Platform::GetFileName(path);
		std::map<str_type::string, AudioSamplePtr>::iterator iter = m_resource.find(fileName);
		if (iter != m_resource.end())
			return iter->second;
	}

	AudioSamplePtr pSample;
	str_type::string fixedName(path);
	Platform::FixSlashes(fixedName);
	if (!(pSample = audio->LoadSampleFromFile(fixedName, fileIOHub->GetFileManager(), type)))
	{
		pSample.reset();
		ETH_STREAM_DECL(ss) << GS_L("(Not loaded) \"") << fixedName << GS_L("\"");
		ETHResourceProvider::Log(ss.str(), Platform::Logger::ERROR);
		return AudioSamplePtr();
	}
	//#if defined(_DEBUG) || defined(DEBUG)
	str_type::string fileName = Platform::GetFileName(path);
	ETH_STREAM_DECL(ss) << GS_L("(Loaded) ") << fileName;
	ETHResourceProvider::Log(ss.str(), Platform::Logger::INFO);
	//#endif
	m_resource[fileName] = pSample;
	return pSample;
}
示例#3
0
AudioSamplePtr ETHAudioResourceManager::GetPointer(
	AudioPtr audio,
	const Platform::FileIOHubPtr& fileIOHub,
	const str_type::string &fileRelativePath,
	const str_type::string &searchPath,
	const Audio::SAMPLE_TYPE type)
{
	if (fileRelativePath == GS_L(""))
		return AudioSamplePtr();

	if (!m_resource.empty())
	{
		str_type::string fileName = Platform::GetFileName(fileRelativePath);
		std::map<str_type::string, AudioSamplePtr>::iterator iter = m_resource.find(fileName);
		if (iter != m_resource.end())
			return iter->second;
	}

	// we can set a search path to search the file in case
	// it hasn't been loaded yet
	if (searchPath != GS_L(""))
	{
		str_type::string fileName = Platform::GetFileName(fileRelativePath);

		str_type::string path = fileIOHub->GetResourceDirectory();
		path += searchPath;
		path += fileName;
		AddFile(audio, fileIOHub, path, type);
		return GetPointer(audio, fileIOHub, fileName, GS_L(""), type);
	}
	return AudioSamplePtr();
}
示例#4
0
void ETHEngine::Start(VideoPtr video, InputPtr input, AudioPtr audio)
{
	Platform::FileIOHubPtr fileIOHub = video->GetFileIOHub();

	ETHAppEnmlFile file(fileIOHub->GetResourceDirectory() + ETH_APP_PROPERTIES_FILE, fileIOHub->GetFileManager(), video->GetPlatformName());
	m_richLighting = file.IsRichLightingEnabled();

	m_provider = ETHResourceProviderPtr(new ETHResourceProvider(
		ETHGraphicResourceManagerPtr(new ETHGraphicResourceManager(file.GetDensityManager())),
		ETHAudioResourceManagerPtr(new ETHAudioResourceManager()),
		ETHShaderManagerPtr(new ETHShaderManager(video, fileIOHub->GetStartResourceDirectory() + ETHDirectories::GetShaderDirectory(), m_richLighting)),
		video, audio, input, fileIOHub, false));

	m_ethInput.SetProvider(m_provider);

	CreateDynamicBackBuffer(file);

	if (!m_pASEngine)
	{
		video->SetBGColor(gs2d::constant::BLACK);

		if (!PrepareScriptingEngine(file.GetDefinedWords()))
		{
			Abort();
			return;
		}

		if (m_compileAndRun)
		{
			if (!RunMainFunction(GetMainFunctionId()))
			{
				Abort();
				return;
			}
			video->EnableQuitShortcuts(true);
			m_v2LastCamPos = video->GetCameraPos();
		}
	}
	else
	{
		video->SetBGColor(m_lastBGColor);
		m_pScene->RecoverResources();
	}
}
示例#5
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;
}
示例#6
0
 int main(int argc, char** argv)
#endif
{
	// convert args to multibyte char
	#ifdef WIN32
		GS2D_UNUSED_ARGUMENT(hInstance);
		GS2D_UNUSED_ARGUMENT(nCmdShow);
		int argc = 0;
		LPWSTR* wargv = CommandLineToArgvW(lpCmdLine, &argc);

		LPSTR* argv = new LPSTR [argc];

		for (int t = 0; t < argc; t++)
		{
			std::size_t convertCount = 0;
			const std::size_t bufferSize = 4096;
			argv[t] = new CHAR [bufferSize];
			wcstombs_s(&convertCount, argv[t], bufferSize, wargv[t], wcslen(wargv[t]) + 1);
		}
	#endif

	// start engine runtime
	bool compileAndRun, testing, wait;
	ProcParams(argc, argv, compileAndRun, testing, wait);
	ETHScriptWrapper::SetArgc(argc);
	ETHScriptWrapper::SetArgv(argv);

	Platform::FileManagerPtr fileManager(new Platform::StdFileManager());

	Platform::FileIOHubPtr fileIOHub = Platform::CreateFileIOHub(fileManager, ETHDirectories::GetBitmapFontDirectory());
	{
		const str_type::string resourceDirectory = FindResourceDir(argc, argv);
		if (!resourceDirectory.empty())
			fileIOHub->SetResourceDirectory(resourceDirectory);
	}
	const str_type::string resourceDirectory = fileIOHub->GetResourceDirectory(); 

	const ETHAppEnmlFile app(resourceDirectory + ETH_APP_PROPERTIES_FILE, Platform::FileManagerPtr(new Platform::StdFileManager), Application::GetPlatformName());
	const str_type::string bitmapFontPath = resourceDirectory + ETHDirectories::GetBitmapFontDirectory();

	bool aborted;
	{
		ETHEnginePtr application = ETHEnginePtr(new ETHEngine(testing, compileAndRun));
		application->SetHighEndDevice(true);

		VideoPtr video;
		if ((video = CreateVideo(
			app.GetWidth(),
			app.GetHeight(),
			app.GetTitle(),
			app.IsWindowed(),
			app.IsVsyncEnabled(),
			fileIOHub,
			Texture::PF_UNKNOWN,
			false)))
		{
			InputPtr input = CreateInput(0, false);
			AudioPtr audio = CreateAudio(0);

			application->Start(video, input, audio);

			if (compileAndRun)
			{
				Video::APP_STATUS status;
				while ((status = video->HandleEvents()) != Video::APP_QUIT)
				{
					if (status == Video::APP_SKIP)
						continue;

					input->Update();
					if (application->Update(Min(1000.0f, ComputeElapsedTimeF(video))) == Application::APP_QUIT)
					{
						break;
					}
					application->RenderFrame();
				}
			}
		}
		application->Destroy();	
		aborted = application->Aborted();
	}

	if (aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("The program executed an ilegal operation and was aborted");
		GS2D_CERR << ss.str() << std::endl;
	}

	if (!compileAndRun && !aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("Compilation successful: 0 errors");
		GS2D_CERR << ss.str() << std::endl;
	}

	if (aborted && wait)
	{
		GS2D_COUT << GS_L("Press any key to continue...") << GS_L("\n");
		std::cin.get();
	}

	#if defined(_DEBUG) || defined(DEBUG)
	 #ifdef WIN32
	  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	  LocalFree(wargv);
	  for (int t = 0; t < argc; t++)
	  {
		  delete [] argv[t];
	  }
	  delete [] argv;
	  #endif
	#endif
	return 0;
}
示例#7
0
文件: main.cpp 项目: skaflux/ethanon
 int ETH_MACHINE_MAIN_FUNC(int argc, gs2d::str_type::char_t** argv)
#endif
{
	bool compileAndRun, testing, wait;
	ProcParams(argc, argv, compileAndRun, testing, wait);
	ETHScriptWrapper::SetArgc(argc);
	ETHScriptWrapper::SetArgv(argv);

	Platform::FileManagerPtr fileManager(new Platform::StdFileManager());

	Platform::FileIOHubPtr fileIOHub = Platform::CreateFileIOHub(fileManager, ETHDirectories::GetBitmapFontDirectory());
	{
		const str_type::string resourceDirectory = FindResourceDir(argc, argv);
		if (!resourceDirectory.empty())
			fileIOHub->SetResourceDirectory(resourceDirectory);
	}
	const str_type::string resourceDirectory = fileIOHub->GetResourceDirectory(); 

	const ETHAppEnmlFile app(resourceDirectory + ETH_APP_PROPERTIES_FILE, Platform::FileManagerPtr(new Platform::StdFileManager), Application::GetPlatformName());
	const str_type::string bitmapFontPath = resourceDirectory + ETHDirectories::GetBitmapFontDirectory();

	bool aborted;
	{
		ETHEnginePtr application = ETHEnginePtr(new ETHEngine(testing, compileAndRun));
		application->SetHighEndDevice(true);

		VideoPtr video;
		if ((video = CreateVideo(
			app.GetWidth(),
			app.GetHeight(),
			app.GetTitle(),
			app.IsWindowed(),
			app.IsVsyncEnabled(),
			fileIOHub,
			Texture::PF_UNKNOWN,
			false)))
		{
			InputPtr input = CreateInput(0, false);
			AudioPtr audio = CreateAudio(0);

			application->Start(video, input, audio);

			if (compileAndRun)
			{
				Video::APP_STATUS status;
				while ((status = video->HandleEvents()) != Video::APP_QUIT)
				{
					if (status == Video::APP_SKIP)
						continue;

					input->Update();
					if (application->Update(Min(static_cast<unsigned long>(1000), ComputeElapsedTime(video))) == Application::APP_QUIT)
					{
						break;
					}
					application->RenderFrame();
				}
			}
		}
		application->Destroy();	
		aborted = application->Aborted();
	}

	if (aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("The program executed an ilegal operation and was aborted");
		GS2D_CERR << ss.str() << std::endl;
	}

	if (!compileAndRun && !aborted)
	{
		ETH_STREAM_DECL(ss) << std::endl << GS_L("Compilation successful: 0 errors");
		GS2D_CERR << ss.str() << std::endl;
	}

	if (aborted && wait)
	{
		GS2D_COUT << GS_L("Press any key to continue...") << GS_L("\n");
		std::cin.get();
	}

	#if defined(_DEBUG) || defined(DEBUG)
	 #ifdef WIN32
	  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
	  #endif
	#endif
	return 0;
}