VBOOL VApplication::SetCurrentFile(	VSTRING_CONST	pszFileName,
										VBOOL			bDefault)
	{
		/* If pszFileName IS the current filename pointer, do nothing.*/
		if ( pszFileName && pszFileName == m_strCurrentFile.String() )
			return VTRUE;

		/* Save current filename string.*/
		m_strCurrentFile = pszFileName;

		/* Build display string.*/
		VString s(VGetAppTitle());

		VSTRING_CONST pszTitle =
			(pszFileName) ? pszFileName : (bDefault) ? VTEXT("Untitled") : NULL;

		if ( s.IsNotEmpty() && pszTitle )
		{
			s += VTEXT(" - ");
			s += pszTitle;
		}

		#ifdef VWCL_CONSOLE_APP
			if ( !SetConsoleTitle(s) )
				return VFALSE;
		#else
			#ifndef VWCL_NO_VWINDOW
				VWindow::MainWindow().SetText(s);
			#endif
		#endif

		return VTRUE;
	}
Example #2
0
	const GLchar* GLShader::ReadShader(const UString& path)
	{
		FILE* file;
#if defined VIX_SYS_WINDOWS && defined UNICODE
		_wfopen_s(&file, path.c_str(), VTEXT("rb"));
#else
		file = fopen(path.c_str(), VTEXT("rb"));
#endif
		if (!file) {
			DebugPrintF(VTEXT("Unabled to read shader: %s\n"),
				    ErrCodeString(ErrCode::ERR_FAILURE).c_str());
			return NULL;
		}

		/*seek end of file*/
		fseek(file, 0, SEEK_END);
		/*cache length*/
		size_t len = ftell(file);
		/*seek beg of file*/
		fseek(file, 0, SEEK_SET);

		/*buffer source*/
		GLchar* src = new GLchar[len + 1];

		/*read file contents into buffer*/
		fread(src, 1, len, file);
		/*close file after read*/
		fclose(file);
		/*null terminate*/
		src[len] = 0;

		return src;
	}
	bool SDLGameWindow::VInit()
	{
		/* Initialize SDL
		*/
		if (SDL_Init(SDL_INIT_TIMER) != 0) {
			DebugPrintF(VTEXT("SDL Failed to Initialize"));
            return false;
		}

		/*Create the SDL_Window handle*/
#ifdef UNICODE
		UConverter convert;
		std::string title = convert.to_bytes(m_params.title);
#else
		std::string title = m_params.title;
#endif
		m_windowHandle = SDL_CreateWindow(title.c_str(),
											m_params.x <= 0 ? SDL_WINDOWPOS_CENTERED : m_params.x,
											m_params.y <= 0 ? SDL_WINDOWPOS_CENTERED : m_params.y,
											m_params.width,
											m_params.height,
											SDL_WINDOW_OPENGL);
		if (!m_windowHandle) {
			SDL_Quit();
			DebugPrintF(VTEXT("Failed to created SDL_Window handle"));
            return false;
		}

#ifdef VIX_SYS_WINDOWS
        SDL_SysWMinfo info;
        SDL_VERSION(&info.version);
        if (SDL_GetWindowWMInfo(m_windowHandle, &info))
        {
            m_nativeHandle = info.info.win.window;
            if (m_renderer)
                m_renderer->VAttachNativeHandle(m_nativeHandle);
        }
#endif

#ifdef VIX_SYS_LINUX //for now
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
		/*create OpenGL context*/
		m_context = SDL_GL_CreateContext(m_windowHandle);
		if (!m_context) {
			SDL_Quit();
			DebugPrintF(VTEXT("Failed to create SDL_GL_Context handle"));
            return false;
		}
#endif

		if (m_renderer && !m_renderer->VInitialize()) {
		  DebugPrintF(VTEXT("Renderer failed to initialize"));
			return false;
		}

		return true;
	}
	bool SDLGameWindow::VInit()
	{
		/* Initialize SDL
		*/
		if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
			DebugPrintF(VTEXT("SDL Failed to Initialize"));
            return false;
		}

		/*Create the SDL_Window handle*/
#ifdef UNICODE
		UConverter convert;
		std::string title = convert.to_bytes(m_params.title);
#else
		std::string title = m_params.title;
#endif
		m_windowHandle = SDL_CreateWindow(title.c_str(),
											m_params.x <= 0 ? SDL_WINDOWPOS_CENTERED : m_params.x,
											m_params.y <= 0 ? SDL_WINDOWPOS_CENTERED : m_params.y,
											m_params.width,
											m_params.height,
											SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN);
		if (!m_windowHandle) {
			SDL_Quit();
			DebugPrintF(VTEXT("Failed to created SDL_Window handle"));
            return false;
		}

#ifdef VIX_SYS_WINDOWS
        SDL_SysWMinfo info;
        SDL_VERSION(&info.version);
        if (SDL_GetWindowWMInfo(m_windowHandle, &info))
        {
            m_nativeHandle = info.info.win.window;
        }
#endif

#ifdef VIX_SYS_LINUX //for now
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
		/*create OpenGL context*/
		m_context = SDL_GL_CreateContext(m_windowHandle);
		if (!m_context) {
			SDL_Quit();
			DebugPrintF(VTEXT("Failed to create SDL_GL_Context handle"));
            return false;
		}
#endif
        m_mouseState = new SDLMouseState;
        m_keyboardState = new SDLKeyboardState;
		m_controllerState = new SDLControllerState;
        m_running = true;

		return true;
	}
	void ResourceManager::PrintLoaded()
	{
		ResourceManager& _RM = ResourceManager::instance();

		for (auto& asset : _RM.m_assetMap)
		{
			Asset* _asset = asset.second;
			if (_asset) {
				DebugPrintF(VTEXT("File: %s\n"), _asset->FileName().c_str());
				DebugPrintF(VTEXT("RefCount: %d\n"), _asset->RefCount());
			}
		}
	}
	FREE_IMAGE_FORMAT
	FREEIMAGE_FormatFromExtension(const UString& ext)
	{
		if (ext.empty())
			return FIF_UNKNOWN;
		if (ext == VTEXT("png"))
			return FIF_PNG;
		if (ext == VTEXT("jpg"))
			return FIF_JPEG;
		if (ext == VTEXT("bmp"))
			return FIF_BMP;
		if (ext == VTEXT("tga"))
			return FIF_TARGA;
	}
	UString os_dir(const UString& path, bool wt)
	{
		UString dir = VTEXT("");
		if (path.empty())
			return dir;

		//remove trailing slash for now
		dir = path.substr(0, path.size() - 1);

		size_t back_slash = 0;
		UChar   c_slash;
#ifdef VIX_SYS_WINDOWS
		c_slash = WIN_PATH_DELIM[0];
		back_slash = dir.find_last_of(c_slash);
#else
		c_slash = UNIX_PATH_DELIM[0];
		back_slash = dir.find_last_of(c_slash);
#endif
		if (back_slash != UString::npos)
			dir = dir.substr(0, back_slash);
		if (wt)
			dir += c_slash;

		return dir;

	}
    Font* ResourceManager::OpenFont(UString filePath)
    {
        UString assetPath = PathManager::AssetPath() + VTEXT("Fonts/");

        assetPath += filePath;
        assetPath = os_path(assetPath);

		Font* _font = NULL;

        File* file = FileManager::OpenFile(assetPath, FileMode::ReadBinary);
        if (file)
        {
            //Create Renderer Specific model type
            ResourceManager& _RM = ResourceManager::instance();

            if (_RM.m_resourceLoader)
            {
				_font = (Font*)ResourceManager::AccessAsset(file->FileName());

				if (!_font)
				{
					//Need to load a font object into memory
					_font = _RM.m_resourceLoader->LoadFont(file);
				
					ResourceManager::MapAsset(file->FileName(), _font);
				}

                FileManager::CloseFile(file);
            }
        }

        return _font;
    }
Example #9
0
	bool GLShader::ValidateCompile(GLuint shader)
	{
		GLint compiled;
		glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
		if (!compiled) {
			GLsizei length;
			glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);

			/*output shader log info*/
			GLchar* log = new GLchar[length + 1];
			glGetShaderInfoLog(shader, length, &length, log);
#ifdef UNICODE
			std::string log_text(log);
			UConverter converter;
			UString log_string = converter.from_bytes(log_text);
			DebugPrintF(log_string.c_str());
			std::cout << log << std::endl;
#else
			DebugPrintF(VTEXT("Shader Log: %s\n"),
				    log);
#endif
			delete[] log;

			return false;
		}


		return true;
	}
    Texture* ResourceManager::OpenTexture(UString filePath)
    {
        UString assetPath = PathManager::AssetPath() + VTEXT("Textures/");

        assetPath += filePath;
        assetPath = os_path(assetPath);

		Texture* _texture = NULL;

        File* file = FileManager::OpenFile(assetPath, FileMode::ReadBinary);
        if (file)
        {
            //Create Renderer Specific texture type
            ResourceManager& _RM = ResourceManager::instance();

			if (_RM.m_resourceLoader)
			{
				_texture = (Texture*)ResourceManager::AccessAsset(file->FileName());

				if (!_texture)
				{
					_texture = _RM.m_resourceLoader->LoadTexture(file);

					ResourceManager::MapAsset(file->FileName(), (Asset*)_texture);

				}
				
				FileManager::CloseFile(file);
			}
               
            
        }

		return _texture;
    }
  BMFont* ContentManager::LoadFont(const UString& path)
  {
    	if (path.empty()) {
	  DebugPrintF(VTEXT("Error Loading [BMFont]"));
			return NULL;
		}

		UString _path = os_path(FONT_FOLDER_PATH + path);
		UString _texPath = os_path(FONT_FOLDER_PATH + TEX_FOLDER_PATH);

		ContentMap::iterator it = m_fonts.find(_path);
		if (it != m_fonts.end()) {
			return (BMFont*)it->second;
		}
		else {

			/*create new font*/
			BMFont* font = new BMFont(_path);
			/*load textures for font*/
			for (auto& page : font->FontFile().pages) {
				Texture* tex = LoadTexture(_texPath + page.file);
				if (tex)
					font->AddPageTexture(tex);
			}
			m_fonts[_path] = (IContent*)font;
			return font;
		}

		return NULL;
  }
Example #12
0
	bool GLShader::VInitFromFile(const UString& path)
	{
		/*grab source from file*/
		const GLchar* source = ReadShader(path);
		if (!source) {
			DebugPrintF(VTEXT("Failed to parse shader source\n"));
			return false;
		}

		if (!LoadShader(source)) {
			DebugPrintF(VTEXT("Failed to init shader from file\n"));
			return false;
		}

		return true;
	}
	void ContentManager::DumpTextures()
	{
		for (auto& tex : m_textures)
		{
			Texture* _tex = (Texture*)tex.second;
			DebugPrintF(VTEXT("Texture [%s]\n"), _tex->name().c_str());
		}
	}
Example #14
0
	ErrCode LuaEngine::VExecuteFile(const UString& path)
	{
		ErrCode error = ErrCode::ERR_SUCCESS;

		if (path.empty()) {
			DebugPrintF(VTEXT("Failed to execute script file: NULL PATH"));
			return ErrCode::ERR_NULL_PATH;
		}

		/*try and execute script file*/
        std::string _path = UStringToStd(path);
		int state = luaL_dofile(m_L, _path.c_str());
		error = ReportScriptErrors(state);
		if (CheckError(error)) {
                        DebugPrintF(VTEXT("Failed to execute script file"));
		}
		return error;
	}
Example #15
0
	ErrCode LuaEngine::VExecuteExpression(const UString& expression)
	{
		ErrCode error = ErrCode::ERR_SUCCESS;

		if (expression.empty()) {
			DebugPrintF(VTEXT("SCRIPT EMPTY"));
			return ErrCode::ERR_NULL_PATH;
		}

        std::string _exp = UStringToStd(expression);
		int state = luaL_dostring(m_L, _exp.c_str());
		error = ReportScriptErrors(state);
		if (CheckError(error)) {
                        DebugPrintF(VTEXT("Failed to execute script expression"));
		}

		return error;
	}
Example #16
0
    bool LuaEngine::ExecuteExpression(UString expression)
    {
        LuaEngine& _engine = LuaEngine::instance();

        if (expression.empty()) {
            DebugPrintF(VTEXT("SCRIPT EMPTY"));
            return false;
        }

        std::string _exp = UStringToStd(expression);
        int state = luaL_dostring(_engine.m_L, _exp.c_str());
        if (!ReportScriptErrors(state)) {
            DebugPrintF(VTEXT("Failed to execute script expression"));
            return false;
        }

        return true;
    }
Example #17
0
    bool LuaEngine::ExecuteFile(UString filePath)
    {
        LuaEngine& _engine = LuaEngine::instance();

        if (filePath.empty()) {
            DebugPrintF(VTEXT("Failed to execute script file: NULL PATH"));
            return false;
        }

        /*try and execute script file*/
        std::string _path = UStringToStd(filePath);
        int state = luaL_dofile(_engine.m_L, _path.c_str());
        if (!LuaEngine::ReportScriptErrors(state)) {
            DebugPrintF(VTEXT("Failed to execute script file"));
            return false;
        }

        return true;
    }
Example #18
0
	void SDLGameWindow::OutputDisplayModes()
	{
		int numModes = SDL_GetNumDisplayModes(0);
		for (int i = 0; i < numModes; i++)
		{
			SDL_DisplayMode mode;
			SDL_GetDisplayMode(0, i, &mode);
			DebugPrintF(VTEXT("DisplayMode[%i]: <W: %i, H: %i>\n"), i, mode.w, mode.h);
		}
	}
	/** Constructor must be initialized with name of file to create the
	mutex for.*/
	VFileNameMutex(VSTRING_CONST pszFileName)
	{
		/* Initialize members.*/
		m_strFileName = pszFileName;
		m_bLocked =		VFALSE;

		VASSERT(m_strFileName.IsNotEmpty())

		/* Mutex's don't allow backslashes. Convert to _ instead.*/
		m_strFileName.ReplaceCharacters(VTEXT('\\'), VTEXT('_'));

		/* Since mutex naming is case sensitive, always force lowercase.*/
		m_strFileName.LowerCase();

		/* Create the mutex, or open an existing one, but don't
		acquire it right now.*/
		m_Mutex.Set(CreateMutex(NULL, VFALSE, m_strFileName));
		VASSERT(m_Mutex.GetHandle())
	}
	GLTexture::GLTexture(const UString& filePath, GLenum target /* = GL_TEXTURE_2D */)
	{
		m_width = 0;
		m_height = 0;
		m_target = target;

		ErrCode error = InitFromFile(filePath);
		if (CheckError(error)) {
			DebugPrintF(VTEXT("Texture failed to initialize"));
		}
	}
	/** Given a string, return VTRUE if it is considered true. The strings
	True, Yes, On and 1 are considered VTRUE, while everything else is
	considered VFALSE, as is NULL.*/
	static VBOOL		IsStringTrue(VSTRING_CONST pszString)
	{
		if ( pszString )
		{
			VSTRING_CONST TRUE_STRINGS[] =
				{
					VTEXT("TRUE"),
					VTEXT("YES"),
					VTEXT("ON"),
					VTEXT("1")
				};

			for ( VUINT i = 0; i < VARRAY_SIZE(TRUE_STRINGS); i++ )
			{
				if ( VSTRCMP_NOCASE(pszString, TRUE_STRINGS[i]) == 0 )
					return VTRUE;
			}
		}

		return VFALSE;
	}
Example #22
0
	ErrCode LuaEngine::ReportScriptErrors(int state)
	{
		if (state != 0) {
            const char* err = lua_tostring(m_L, state);

			DebugPrintF(VTEXT("Lua Script Error: %s"),
                UStringFromCharArray(err).c_str());
			lua_pop(m_L, 1); //remove error
			return ErrCode::ERR_FAILURE;
		}

		return ErrCode::ERR_SUCCESS;
	}
Example #23
0
	ErrCode AudioManager::VShutDown()
	{
		ErrCode error = ErrCode::ERR_SUCCESS;

		DebugPrintF(VTEXT("AudioManager shutting down..."));

		/*close sound system*/
		error = FMOD_CheckError(m_system->close());
		/*release sound system*/
		error = FMOD_CheckError(m_system->release());

		return error;
	}
	void PrimitiveTube::init_shader_program()
	{
		/*vertex shader info*/
		ShaderInfo vshader_info;
		vshader_info.filePath = VTEXT("Basic.vs");
		vshader_info.raw = VTEXT("");
		vshader_info.type = ShaderType::VERTEX_SHADER;

		/*fragment shader info*/
		ShaderInfo fshader_info;
		fshader_info.filePath = VTEXT("Basic.fs");
		fshader_info.raw = VTEXT("");
		fshader_info.type = ShaderType::FRAGMENT_SHADER;

		/*populate shader args*/
		ShaderArgs args;
		args[0] = vshader_info;
		args[1] = fshader_info;

		/*create shader program*/
		m_program = new GLShaderProgram(args);
	}
Example #25
0
	GLShader::GLShader(const ShaderInfo& info)
	{
		m_info = info;

		if (m_info.filePath.empty() && m_info.raw.empty()) {
			/*no file or raw contents avaliable for loading*/
			DebugPrintF(VTEXT("Shader creation failed: %s\n"),
				        VTEXT("No shader path or raw contents avaliable"));
		}

		/*determine if shader should load from file or raw contents*/
		bool success;
		if (!m_info.filePath.empty()) {
			success = VInitFromFile(m_info.filePath);
		}
		else {
			success = VInitFromString(m_info.raw);
		}

		if (!success) {
			DebugPrintF(VTEXT("Shader creation failed\n"));
		}
	}
	/** This function helps with determining what a service application
	should do at startup. Early in the execution of the application, a call
	should be made to this function to test for command line parameters. If
	this function determines that the service should start, it will return
	VTRUE. Otherwise, it means the user wanted to only install or un-install
	the service, or show text mode help. Command line parameters that this
	function understands are as follows:

	-I = Install the Service. Calls the Install(VTRUE) virtual function.

	-U = Uninstall the Service. Calls the Install(VFALSE) virtual function.

	-? = Calls the OnHelp() virtual function to show text mode help.

	If any other parameters are specified, this function will call
	the virtual function OnCommandLineParameter().*/
	VBOOL					ProcessCommandLine()
	{
		VBOOL bServiceShouldStart = VTRUE;

		/* See if at least 1 command line param is present.*/
		if ( VGetARGC() > 0 )
		{
			VApplication& theApp = VGetApp();

			if ( theApp.IsCommandLineOption(VTEXT("I")) )
			{
				Install(VTRUE);
				bServiceShouldStart = VFALSE;
			}
			else if ( theApp.IsCommandLineOption(VTEXT("U")) )
			{
				Install(VFALSE);
				bServiceShouldStart = VFALSE;
			}
			else if ( theApp.IsCommandLineOption(VTEXT("?")) )
			{
				OnHelp();
				bServiceShouldStart = VFALSE;
			}

			if ( bServiceShouldStart )
			{
				for ( VUINT i = 1; i < VGetARGC(); i++ )
				{
					if ( !OnCommandLineParameter(VGetARGV(i)) )
						bServiceShouldStart = VFALSE;
				}
			}
		}

		return bServiceShouldStart;
	}
Example #27
0
    bool LuaEngine::ReportScriptErrors(int state)
    {
        LuaEngine& _engine = LuaEngine::instance();

        if (state != 0) {
            const char* err = lua_tostring(_engine.m_L, state);

			if (err) {
				DebugPrintF(VTEXT("Lua Script Error: %s"),
					UStringFromCharArray(err).c_str());
				lua_pop(_engine.m_L, 1); //remove error
			}
            return false;
        }

        return true;
    }
Example #28
0
	ErrCode AudioManager::VStartUp()
	{
		ErrCode error = ErrCode::ERR_SUCCESS;

		DebugPrintF(VTEXT("AudioManager starting up..."));

		/*create fmod sound system*/
		error = FMOD_CheckError(FMOD::System_Create(&m_system));
		if (CheckError(error))
			return error;

		/*initialize fmod sound system*/
		error = FMOD_CheckError(m_system->init(MAX_CHANNELS, FMOD_INIT_NORMAL, NULL));
		if (CheckError(error))
			return error;

		return error;
	}
Example #29
0
	bool GLShader::VInitFromString(const UString& path)
	{

#if defined UNICODE && defined VIX_SYS_WINDOWS
		UConverter cv;
		std::string _source = cv.to_bytes(m_info.raw.c_str());
		const GLchar* source = _source.c_str();
#else
		const GLchar* source = (const GLchar*)m_info.raw.c_str();
#endif
		if (!LoadShader(source)) {
			if (CheckError(error)) {
				DebugPrintF(VTEXT("Failed to init shader from source\n"));
				return true;
			}
		}

		return false;
	}
Example #30
0
	bool GLShader::LoadShader(const GLchar* source)
	{
		GLenum type = GLShaderType(m_info.type);
		if (type == GL_NONE) {
			DebugPrintF(VTEXT("Failed to Load Shader due to invalid type\n"));
			return false;
		}

		/*create shader object*/
		m_shader = glCreateShader(type);

		/*put shader source into memory*/
		glShaderSource(m_shader, 1, &source, NULL);
		/*cleanup allocated source*/

		/*compile shader*/
		glCompileShader(m_shader);

		return ValidateCompile(m_shader);
	}