Esempio n. 1
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;
    }
}
Esempio n. 2
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;
	}
}
Esempio n. 3
0
bool StdFileManager::GetUTF16FileString(const str_type::string &fileName, str_type::string &out)
{
	FILE* file = 0;
	errno_t err = _wfopen_s(&file, fileName.c_str(), L"rb");
	if (err || !file)
	{
		return false;
	}

	long length = 0;

	// const std::size_t wcharSize = sizeof(wchar_t);
	const std::size_t BOMsize = 2;

	fseek(file, 0, SEEK_END);
	length = ftell(file);
	fseek(file, 0, SEEK_SET);

	if (length <= 0)
	{
		return false;
	}

	out.resize(length);
	unsigned short usOrder;
	fread(&usOrder, BOMsize, 1, file);
	if (fread(&out[0], length - BOMsize, 1, file) != 1)
	{
		fclose(file);
		return false;
	}
	fclose(file);
	return true;
}
Esempio n. 4
0
void ETHAppEnmlFile::LoadProperties(const str_type::string& platformName, const gs2d::enml::File& file)
{
	if (!file.Exists(platformName))
		return;

	file.GetUInt(platformName, GS_L("width"), &width);
	file.GetUInt(platformName, GS_L("height"), &height);

	GetBoolean(file, platformName, GS_L("windowed"), windowed);
	GetBoolean(file, platformName, GS_L("vsync"), vsync);
	GetBoolean(file, platformName, GS_L("richLighting"), richLighting);

	GetString(file, platformName, GS_L("fixedWidth"), fixedWidth);
	GetString(file, platformName, GS_L("fixedHeight"), fixedHeight);

	file.GetFloat(platformName, GS_L("hdDensityValue"), &hdDensityValue);
	file.GetFloat(platformName, GS_L("fullHdDensityValue"), &fullHdDensityValue);
	file.GetUInt(platformName, GS_L("minScreenHeightForHdVersion"), &minScreenHeightForHdVersion);
	file.GetUInt(platformName, GS_L("minScreenHeightForFullHdVersion"), &minScreenHeightForFullHdVersion);

	const str_type::string newTitle = file.Get(platformName, GS_L("title"));
	if (!newTitle.empty())
		title = newTitle;

	std::vector<gs2d::str_type::string> words = ETHGlobal::SplitString(file.Get(platformName, GS_L("definedWords")), GS_L(","));
	definedWords.insert(definedWords.end(), words.begin(), words.end());
	std::sort(definedWords.begin(), definedWords.end());

	std::vector<gs2d::str_type::string>::iterator it = std::unique(definedWords.begin(), definedWords.end());
	definedWords.resize(it - definedWords.begin());
}
Esempio n. 5
0
std::vector<str_type::string> SplitString(str_type::string str, const str_type::string& c)
{
	std::vector<str_type::string> v; // I know...
	std::size_t pos;
	while ((pos = str.find(c)) != str_type::string::npos)
	{
		v.push_back(str.substr(0, pos));
		str = str.substr(pos + c.length(), str_type::string::npos);
	}
	v.push_back(str);
	return v;
}
Esempio n. 6
0
int ETHScene::AddEntity(ETHRenderEntity* pEntity, const str_type::string& alternativeName)
{
	// sets an alternative name if there is any
	if (!alternativeName.empty())
	{
		pEntity->ChangeEntityName(alternativeName);
	}

	// generate an unique id
	if (pEntity->GetID() < 0)
	{
		pEntity->SetID(++m_idCounter);
	}

	m_buckets.Add(pEntity, (pEntity->GetType() == ETH_HORIZONTAL) ? ETHBucketManager::FRONT : ETHBucketManager::BACK);

	m_maxSceneHeight = Max(m_maxSceneHeight, pEntity->GetMaxHeight());
	m_minSceneHeight = Min(m_minSceneHeight, pEntity->GetMinHeight());

	// find a callback function for this one
	if (m_pContext && m_pModule)
	{
		AssignCallbackScript(pEntity);
	}

	// if it has a callback and is dynamic, or if it's temporary, add it to the "callback constant run list"
	m_tempEntities.AddEntityWhenEligible(pEntity);

	// restart all sound effects for this one
	// It's useful in case of explosion sfx's for example. It'll start all over again
	pEntity->StartSFX();

	return pEntity->GetID();
}
Esempio n. 7
0
str_type::string FindResourceDir(const int argc, gs2d::str_type::char_t* argv[])
{
	for (int t = 0; t < argc; t++)
	{
		const str_type::string argStr = (argv[t]);
		if (argStr.substr(0, 4) == GS_L("dir="))
		{
			const std::vector<str_type::string> pieces = Platform::SplitString(argStr, GS_L("="));
			if (pieces.size() >= 2)
			{
				str_type::string dir = Platform::AddLastSlash(pieces[1]);
				return Platform::FixSlashes(dir);
			}
		}
	}
	return GS_L("");
}
bool ETHScriptWrapper::FileExists(const str_type::string& fileName)
{
	str_type::ifstream ifs(fileName.c_str());
	if (ifs.is_open())
	{
		ifs.close();
		return true;
	}
	else
	{
		return false;
	}
}
Esempio n. 9
0
bool StdFileManager::GetFileBuffer(const str_type::string &fileName, FileBuffer &out)
{
	#if _MSC_VER >= 1500
		FILE *f = 0;
		_wfopen_s(&f, fileName.c_str(), GS_L("rb"));
	#else
		FILE *f = _wfopen(fileName.c_str(), GS_L("rb"));
	#endif

	if (!f)
	{
		return false;
	}
	
	fseek(f, 0, SEEK_END);
	const std::size_t len = ftell(f);
	fseek(f, 0, SEEK_SET);

	out = FileBuffer(new _FileBuffer<unsigned char>(len));
	fread(out->GetAddress(), len, 1, f);
	fclose(f);
	return true;
}
Esempio n. 10
0
inline int GLES2UniformParameter::GetLocation(const GLuint program, const str_type::string& name, const Platform::FileLogger& logger)
{
	LocationMap& locations = *m_locations.get();
	std::map<GLuint, int>::iterator iter = locations.find(program);
	if (iter != locations.end())
	{
		return iter->second;
	}
	else
	{
		const int location = glGetUniformLocation(program, name.c_str());
		GLES2Video::CheckGLError(name + ": uniform parameter not found with glGetUniformLocation", logger);
		str_type::stringstream ss;
		ss << "Location obtained successfully [" << name << "] " << counter++ << ": " << location;
		logger.Log(ss.str(), Platform::FileLogger::INFO);
		locations[program] = location;
		return location;
	}
}
bool ETHScriptWrapper::LoadScene(const str_type::string &escFile, const Vector2& bucketSize)
{
	if (!IsPersistentResources())
	{
		if (escFile != m_sceneFileName)
		{
			ReleaseResources();
		}
	}

	str_type::string fileName = m_provider->GetResourcePath();
	fileName += escFile;

	// if the name is set to _ETH_EMPTY_SCENE_STRING, don't load anything
	if (escFile != _ETH_EMPTY_SCENE_STRING && escFile.size() > 0)
	{
		m_pScene = ETHScenePtr(new ETHScene(fileName, m_provider, m_richLighting, ETHSceneProperties(), m_pASModule,
			m_pScriptContext, false, bucketSize));
	}
	else
	{
		m_pScene = ETHScenePtr(new ETHScene(m_provider, m_richLighting, ETHSceneProperties(), m_pASModule,
			m_pScriptContext, false, bucketSize));
	}

	m_pScene->ScaleEntities(m_provider->GetGlobalScaleManager()->GetScale(), true);
	m_pScene->ResolveJoints();
	m_primitiveList.clear();
	m_sceneFileName = escFile;
	m_pScene->EnableLightmaps(m_useLightmaps);
	GenerateLightmaps();
	m_provider->GetVideo()->SetCameraPos(Vector2(0,0));
	LoadSceneScripts();
	m_timer.CalcLastFrame();
	return true;
}
Esempio n. 12
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;
}
Esempio n. 13
0
 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;
}
Esempio n. 14
0
bool ETHEngine::BuildModule(const std::vector<gs2d::str_type::string>& definedWords)
{
	const str_type::string resourcePath = m_provider->GetFileIOHub()->GetResourceDirectory();
	const str_type::string mainScript = resourcePath + ETH_DEFAULT_MAIN_SCRIPT_FILE;
	const str_type::string byteCodeWriteFile = m_provider->GetByteCodeSaveDirectory() + ETH_DEFAULT_MAIN_BYTECODE_FILE;
	const str_type::string byteCodeReadFile  = resourcePath + ETH_DEFAULT_MAIN_BYTECODE_FILE;

	// if there's a main script file, load the source from text code and compile it
	if (ETHGlobal::FileExists(mainScript, m_provider->GetFileManager()))
	{
		ETH_STREAM_DECL(ssi) << GS_L("Loading game script from source-code: ") << ETH_DEFAULT_MAIN_SCRIPT_FILE;
		m_provider->Log(ssi.str(), Platform::Logger::INFO);

		// Load the main script
		CScriptBuilder builder(m_provider);

		RegisterDefinedWords(definedWords, builder, m_testing);

		int r;
		r = builder.StartNewModule(m_pASEngine, ETH_SCRIPT_MODULE.c_str());
		if (!CheckAngelScriptError(r, GS_L("Failed while starting the new module.")))
			return false;

		r = builder.AddSectionFromFile(mainScript.c_str());
		str_type::stringstream ss;
		ss << GS_L("Failed while loading the main script. Verify the ") << mainScript << GS_L(" file");
		if (!CheckAngelScriptError(r, ss.str()))
			return false;

		// builds the module
		const VideoPtr& video = m_provider->GetVideo();
		const unsigned long buildTime = video->GetElapsedTime();
		r = builder.BuildModule();
		str_type::stringstream timeStringStream; timeStringStream << GS_L("Compile time: ") << video->GetElapsedTime() - buildTime << GS_L(" milliseconds");
		m_provider->Log(timeStringStream.str(), Platform::Logger::INFO);
		if (!CheckAngelScriptError(r, GS_L("Failed while building module.")))
			return false;

		// Gets the recently built module
		m_pASModule = CScriptBuilder::GetModule(m_pASEngine, ETH_SCRIPT_MODULE);

		// Writes the compiled byte code to file
		ETHBinaryStream stream(m_provider->GetFileManager());
		if (stream.OpenW(byteCodeWriteFile))
		{
			m_pASModule->SaveByteCode(&stream);
			stream.CloseW();
		}
		else
		{
			ETH_STREAM_DECL(ss) << GS_L("Failed while writing the byte code file ") << byteCodeWriteFile;
			m_provider->Log(ss.str(), Platform::Logger::ERROR);
			// return false;
		}
	}
	else // otherwiser, try to load the bytecode
	{
		ETH_STREAM_DECL(ss) << GS_L("Loading game script from pre-compiled byte code: ") << ETH_DEFAULT_MAIN_BYTECODE_FILE;
		m_provider->Log(ss.str(), Platform::Logger::INFO);
	
		m_pASModule = CScriptBuilder::GetModule(m_pASEngine, ETH_SCRIPT_MODULE, asGM_ALWAYS_CREATE);
		ETHBinaryStream stream(m_provider->GetFileManager());
		if (stream.OpenR(byteCodeReadFile))
		{
			if (m_pASModule->LoadByteCode(&stream) < 0)
			{
				ETH_STREAM_DECL(ss) << GS_L("Couldn't load game script from pre-compiled byte code: ") << ETH_DEFAULT_MAIN_BYTECODE_FILE;
				m_provider->Log(ss.str(), Platform::Logger::ERROR);
				stream.CloseR();
				return false;
			}
			stream.CloseR();
		}
		else
		{
			ETH_STREAM_DECL(ss) << GS_L("Failed while reading the byte code file ") << byteCodeReadFile;
			m_provider->Log(ss.str(), Platform::Logger::ERROR);
			Abort();
			return false;
		}
	}

	return true;
}
Esempio n. 15
0
unsigned int ParseUIntStd(const str_type::string& str)
{
	return ParseUInt(str.c_str());
}
Esempio n. 16
0
float ParseFloatStd(const str_type::string& str)
{
	return ParseFloat(str.c_str());
}