Exemplo n.º 1
0
	void ExecuteConsoleFunction( long appPtr, char const * commandStr ) const
	{
		DROIDLOG( "OvrConsole", "Received console command \"%s\"", commandStr );
	
		char cmdName[128];
		char const * parms = "";
		int cmdLen = (int)strlen( commandStr );
		char const * spacePtr = strstr( commandStr, " " );
		if ( spacePtr != NULL && spacePtr - commandStr < cmdLen )
		{
			parms = spacePtr + 1;
			OVR_strncpy( cmdName, sizeof( cmdName ), commandStr, spacePtr - commandStr );
		} 
		else
		{
			OVR_strcpy( cmdName, sizeof( cmdName ), commandStr );
		}

		LOG( "ExecuteConsoleFunction( %s, %s )", cmdName, parms );
		for ( int i = 0 ; i < ConsoleFunctions.GetSizeI(); ++i )
		{
			LOG( "Checking console function '%s'", ConsoleFunctions[i].GetName() );
			if ( OVR_stricmp( ConsoleFunctions[i].GetName(), cmdName ) == 0 )
			{
				LOG( "Executing console function '%s'", cmdName );
				ConsoleFunctions[i].Execute( reinterpret_cast< void* >( appPtr ), parms );
				return;
			}
		}

		DROIDLOG( "OvrConsole", "ERROR: unknown console command '%s'", cmdName );
	}
Exemplo n.º 2
0
//==============================
// ovrFileSysLocal::FindSchemeIndexForName
int ovrFileSysLocal::FindSchemeIndexForName( char const * schemeName ) const
{
	for ( int i = 0; i < Schemes.GetSizeI(); ++i )
	{
		if ( OVR_stricmp( Schemes[i]->GetSchemeName(), schemeName ) == 0 )
		{
			return i;
		}
	}
	return -1;
}
Exemplo n.º 3
0
const SetupGraphicsDeviceSet* SetupGraphicsDeviceSet::PickSetupDevice(const char* typeArg) const
{
    // Search for graphics creation object that matches type arg.
    if (typeArg)
    {
        for (const SetupGraphicsDeviceSet* p = this; p != 0; p = p->pNext)
        {
            if (!OVR_stricmp(p->pTypeArg, typeArg))
                return p;
        }
    }
    return this;
}
Exemplo n.º 4
0
static bool ExtensionMatches( char const * fileName, char const * ext )
{
	if ( fileName == NULL || ext == NULL )
	{
		return false;
	}
	size_t extLen = OVR_strlen( ext );
	size_t fileNameLen = OVR_strlen( fileName );
	if ( extLen > fileNameLen )
	{
		return false;
	}
	return OVR_stricmp( fileName + fileNameLen - extLen, ext ) == 0;
}
Exemplo n.º 5
0
	void RegisterConsoleFunction( const char * name, consoleFn_t function )
	{
		//LOG( "Registering console function '%s'", name );
		for ( int i = 0 ; i < ConsoleFunctions.GetSizeI(); ++i )
		{
			if ( OVR_stricmp( ConsoleFunctions[i].GetName(), name ) == 0 )
			{
				LOG( "OvrConsole", "Console function '%s' is already registered!!", name );
				OVR_ASSERT( false );	// why are you registering the same function twice??
				return;
			}
		}
		LOG( "Registered console function '%s'", name );
		ConsoleFunctions.PushBack( OvrConsoleFunction( name, function ) );
	}
int String::CompareNoCase(const char* a, const char* b)
{
    return OVR_stricmp(a, b);
}
Exemplo n.º 7
0
//==============================
// FontInfoType::LoadFromBuffer
bool FontInfoType::LoadFromBuffer( void const * buffer, size_t const bufferSize ) 
{
	char const * errorMsg = NULL;
	OVR::JSON * jsonRoot = OVR::JSON::Parse( reinterpret_cast< char const * >( buffer ), &errorMsg );
	if ( jsonRoot == NULL )
	{
		LOG( "JSON Error: %s", ( errorMsg != NULL ) ? errorMsg : "<NULL>" );
		return false;
	}

	int32_t maxCharCode = -1;
	// currently we're only supporting the first unicode plane up to 65k. If we were to support other planes
	// we could conceivably end up with a very sparse 1,114,111 byte type for mapping character codes to
	// glyphs and if that's the case we may just want to use a hash, or use a combination of tables for
	// the first 65K and hashes for the other, less-frequently-used characters.
	static const int MAX_GLYPHS = 0xffff;	

	// load the glyphs
	const JsonReader jsonGlyphs( jsonRoot );
	if ( !jsonGlyphs.IsObject() )
	{
		jsonRoot->Release();
		return false;
	}

	int Version = jsonGlyphs.GetChildFloatByName( "Version" );
	if ( Version != FNT_FILE_VERSION )
	{
		jsonRoot->Release();
		return false;
	}

	FontName = jsonGlyphs.GetChildStringByName( "FontName" );
	CommandLine = jsonGlyphs.GetChildStringByName( "CommandLine" );
	ImageFileName = jsonGlyphs.GetChildStringByName( "ImageFileName" );
	const int numGlyphs = jsonGlyphs.GetChildInt32ByName( "NumGlyphs" );
	if ( numGlyphs < 0 || numGlyphs > MAX_GLYPHS )
	{
		OVR_ASSERT( numGlyphs > 0 && numGlyphs <= MAX_GLYPHS );
		jsonRoot->Release();
		return false;
	}

	NaturalWidth = jsonGlyphs.GetChildFloatByName( "NaturalWidth" );
	NaturalHeight = jsonGlyphs.GetChildFloatByName( "NaturalHeight" );

	// we scale everything after loading integer values from the JSON file because the OVR JSON writer loses precision on floats
	double nwScale = 1.0f / NaturalWidth;
	double nhScale = 1.0f / NaturalHeight;

	HorizontalPad = jsonGlyphs.GetChildFloatByName( "HorizontalPad" ) * nwScale;
	VerticalPad = jsonGlyphs.GetChildFloatByName( "VerticalPad" ) * nhScale;
	FontHeight = jsonGlyphs.GetChildFloatByName( "FontHeight" ) * nhScale;
	CenterOffset = jsonGlyphs.GetChildFloatByName( "CenterOffset" );
	TweakScale = jsonGlyphs.GetChildFloatByName( "TweakScale", 1.0f );

	LOG( "FontName = %s", FontName.ToCStr() );
	LOG( "CommandLine = %s", CommandLine.ToCStr() );
	LOG( "HorizontalPad = %.4f", HorizontalPad );
	LOG( "VerticalPad = %.4f", VerticalPad );
	LOG( "FontHeight = %.4f", FontHeight );
	LOG( "CenterOffset = %.4f", CenterOffset );
	LOG( "TweakScale = %.4f", TweakScale );
	LOG( "ImageFileName = %s", ImageFileName.ToCStr() );
	LOG( "Loading %i glyphs.", numGlyphs );

/// HACK: this is hard-coded until we do not have a dependcy on reading the font from Home
	if ( OVR_stricmp( FontName.ToCStr(), "korean.fnt" ) == 0 )
	{
		TweakScale = 1.4f;
		CenterOffset = -0.02f;
	}
/// HACK: end hack

	Glyphs.Resize( numGlyphs );

	const JsonReader jsonGlyphArray( jsonGlyphs.GetChildByName( "Glyphs" ) );
	double totalWidth = 0.0;
	if ( jsonGlyphArray.IsArray() )
	{
		for ( int i = 0; i < Glyphs.GetSizeI() && !jsonGlyphArray.IsEndOfArray(); i++ )
		{
			const JsonReader jsonGlyph( jsonGlyphArray.GetNextArrayElement() );
			if ( jsonGlyph.IsObject() )
			{
				FontGlyphType & g = Glyphs[i];
				g.CharCode	= jsonGlyph.GetChildInt32ByName( "CharCode" );
				g.X			= jsonGlyph.GetChildFloatByName( "X" );
				g.Y			= jsonGlyph.GetChildFloatByName( "Y" );
				g.Width		= jsonGlyph.GetChildFloatByName( "Width" );
				g.Height	= jsonGlyph.GetChildFloatByName( "Height" );
				g.AdvanceX	= jsonGlyph.GetChildFloatByName( "AdvanceX" );
				g.AdvanceY	= jsonGlyph.GetChildFloatByName( "AdvanceY" );
				g.BearingX	= jsonGlyph.GetChildFloatByName( "BearingX" );
				g.BearingY	= jsonGlyph.GetChildFloatByName( "BearingY" );

				g.X *= nwScale;
				g.Y *= nhScale;
				g.Width *= nwScale;
				g.Height *= nhScale;
				g.AdvanceX *= nwScale;
				g.AdvanceY *= nhScale;
				g.BearingX *= nwScale;
				g.BearingY *= nhScale;

				totalWidth += g.Width;

				maxCharCode = Alg::Max( maxCharCode, g.CharCode );
			}
		}
	}

	double averageGlyphWidth = totalWidth / numGlyphs;

	// this is the average width in uv space of characters in the ClearSans font. This is used to 
	// compute a scaling factor for other fonts.
	double const DEFAULT_GLYPH_UV_WIDTH = 0.047458650262793022;	
	float const DEFAULT_TEXT_SCALE = 0.0025f;

	float const widthScaleFactor = static_cast< float >( DEFAULT_GLYPH_UV_WIDTH / averageGlyphWidth );
	ScaleFactor = DEFAULT_SCALE_FACTOR * DEFAULT_TEXT_SCALE * widthScaleFactor * TweakScale;

	// This is not intended for wide or ucf character sets -- depending on the size range of
	// character codes lookups may need to be changed to use a hash.
	if ( maxCharCode >= MAX_GLYPHS )
	{
		OVR_ASSERT( maxCharCode <= MAX_GLYPHS );
		maxCharCode = MAX_GLYPHS;
	}
	
	// resize the array to the maximum glyph value
	CharCodeMap.Resize( maxCharCode + 1 );
	for ( int i = 0; i < Glyphs.GetSizeI(); ++i )
	{
		FontGlyphType const & g = Glyphs[i];
		CharCodeMap[g.CharCode] = i;
	}

	jsonRoot->Release();

	return true;
}