mirror of
https://github.com/rlabrecque/SteamworksSDK.git
synced 2026-10-10 09:33:04 +08:00
v1.31
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#Visit http://visualgdb.com/makefiles for more details
|
||||
|
||||
#VisualGDB: AutoSourceFiles #<--- remove this line to disable auto-updating of SOURCEFILES and EXTERNAL_LIBS
|
||||
SOURCEFILES := BaseMenu.cpp clanchatroom.cpp connectingmenu.cpp gameenginesdl.cpp glew.c Leaderboards.cpp Lobby.cpp Main.cpp MainMenu.cpp musicplayer.cpp p2pauth.cpp PhotonBeam.cpp QuitMenu.cpp RemoteStorage.cpp remotestoragesync.cpp ServerBrowser.cpp Ship.cpp SpaceWarClient.cpp SpaceWarEntity.cpp SpaceWarServer.cpp StarField.cpp StatsAndAchievements.cpp stdafx.cpp steamvrglhelper.cpp Sun.cpp VectorEntity.cpp voicechat.cpp
|
||||
SOURCEFILES := BaseMenu.cpp clanchatroom.cpp connectingmenu.cpp gameenginesdl.cpp glew.c htmlsurface.cpp Leaderboards.cpp Lobby.cpp Main.cpp MainMenu.cpp musicplayer.cpp p2pauth.cpp PhotonBeam.cpp QuitMenu.cpp RemoteStorage.cpp remotestoragesync.cpp ServerBrowser.cpp Ship.cpp SpaceWarClient.cpp SpaceWarEntity.cpp SpaceWarServer.cpp StarField.cpp StatsAndAchievements.cpp stdafx.cpp steamvrglhelper.cpp Sun.cpp VectorEntity.cpp voicechat.cpp
|
||||
|
||||
TARGETNAME := SteamworksExampleLinux
|
||||
#TARGETTYPE can be APP, STATIC or SHARED
|
||||
|
||||
@@ -0,0 +1,465 @@
|
||||
//====== Copyright 1996-2014, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: Simple C++ protobuf manipulation routines. For a more advanced,
|
||||
// fully-featured library, see https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
#include "SimpleProtobuf.h"
|
||||
|
||||
|
||||
//
|
||||
// NOTE:
|
||||
// You should probably be using the official protobuf library instead if you
|
||||
// have any concerns about how this code works, or are planning to modify it.
|
||||
//
|
||||
|
||||
#define CHECK_OVERRUN( ptr, end, len ) ( end < ptr || (size_t)( end - ptr ) < len )
|
||||
|
||||
static void ProtobufEncodeVarInt( std::string& strProtobuf, uint64 ulVarInt )
|
||||
{
|
||||
for ( ; ulVarInt >= 128; ulVarInt >>= 7 )
|
||||
strProtobuf.append( 1, ((char)ulVarInt & (char)127) | (char)128 );
|
||||
strProtobuf.append( 1, (char)ulVarInt );
|
||||
}
|
||||
|
||||
void ProtobufWriteField_Integer( std::string& strProtobuf, uint32 uFieldNumber, uint64 ulVarIntData )
|
||||
{
|
||||
ProtobufEncodeVarInt( strProtobuf, PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ) );
|
||||
ProtobufEncodeVarInt( strProtobuf, ulVarIntData );
|
||||
}
|
||||
|
||||
void ProtobufWriteField_SInteger( std::string& strProtobuf, uint32 uFieldNumber, int64 ulSwizzleVarIntData )
|
||||
{
|
||||
ProtobufEncodeVarInt( strProtobuf, PROTOBUF_FIELDTAG_SINTEGER( uFieldNumber ) );
|
||||
ProtobufEncodeVarInt( strProtobuf, (ulSwizzleVarIntData << 1) ^ (ulSwizzleVarIntData >> 63) );
|
||||
}
|
||||
|
||||
void ProtobufWriteField_Fixed64( std::string& strProtobuf, uint32 uFieldNumber, uint64 ulFixed64Data )
|
||||
{
|
||||
ProtobufEncodeVarInt( strProtobuf, PROTOBUF_FIELDTAG_FIXED64( uFieldNumber ) );
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
ulFixed64Data = QWordSwap( ulFixed64Data );
|
||||
#endif
|
||||
strProtobuf.append( reinterpret_cast<char*>(&ulFixed64Data), 8 );
|
||||
}
|
||||
|
||||
void ProtobufWriteField_Fixed64( std::string& strProtobuf, uint32 uFieldNumber, double flFixed64Data )
|
||||
{
|
||||
ProtobufEncodeVarInt( strProtobuf, PROTOBUF_FIELDTAG_FIXED64( uFieldNumber ) );
|
||||
const char *pData = reinterpret_cast<const char*>(&flFixed64Data);
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
strProtobuf.append( std::const_reverse_iterator<const char*>( pData + 8 ), std::const_reverse_iterator<const char*>( pData ) );
|
||||
#else
|
||||
strProtobuf.append( pData, 8 );
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProtobufWriteField_String( std::string& strProtobuf, uint32 uFieldNumber, const char *pchData, size_t cchData )
|
||||
{
|
||||
ProtobufEncodeVarInt( strProtobuf, PROTOBUF_FIELDTAG_STRING( uFieldNumber ) );
|
||||
ProtobufEncodeVarInt( strProtobuf, cchData );
|
||||
strProtobuf.append( pchData, cchData );
|
||||
}
|
||||
|
||||
void ProtobufWriteField_String( std::string& strProtobuf, uint32 uFieldNumber, const std::string &strData )
|
||||
{
|
||||
ProtobufWriteField_String( strProtobuf, uFieldNumber, strData.data(), strData.size() );
|
||||
}
|
||||
|
||||
void ProtobufWriteField_String( std::string& strProtobuf, uint32 uFieldNumber, const char *pchData )
|
||||
{
|
||||
ProtobufWriteField_String( strProtobuf, uFieldNumber, pchData, strlen( pchData ) );
|
||||
}
|
||||
|
||||
void ProtobufWriteField_Fixed32( std::string& strProtobuf, uint32 uFieldNumber, uint32 ulFixed32Data )
|
||||
{
|
||||
ProtobufEncodeVarInt( strProtobuf, PROTOBUF_FIELDTAG_FIXED32( uFieldNumber ) );
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
ulFixed32Data = DWordSwap( ulFixed32Data );
|
||||
#endif
|
||||
strProtobuf.append( reinterpret_cast<char*>(&ulFixed32Data), 4 );
|
||||
}
|
||||
|
||||
void ProtobufWriteField_Fixed32( std::string& strProtobuf, uint32 uFieldNumber, float flFixed32Data )
|
||||
{
|
||||
ProtobufEncodeVarInt( strProtobuf, PROTOBUF_FIELDTAG_FIXED32( uFieldNumber ) );
|
||||
const char *pData = reinterpret_cast<const char*>(&flFixed32Data);
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
strProtobuf.append( std::const_reverse_iterator<const char*>( pData + 4 ), std::const_reverse_iterator<const char*>( pData ) );
|
||||
#else
|
||||
strProtobuf.append( pData, 4 );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static bool ProtobufDecodeVarInt( const char * &pParsePosition, const char *pParseEnd, uint64 &ulVarInt )
|
||||
{
|
||||
const char * pStart = pParsePosition;
|
||||
while ( pParsePosition < pParseEnd && (*pParsePosition & 128) )
|
||||
++pParsePosition;
|
||||
if ( pParsePosition >= pParseEnd )
|
||||
return false;
|
||||
uint64 v = 0;
|
||||
for ( const char *p = pParsePosition++; p >= pStart; --p )
|
||||
v = (v << 7) + (*p & 127);
|
||||
ulVarInt = v;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadFieldTag( const char * &pParsePosition, const char *pParseEnd, uint32 &uFieldTag )
|
||||
{
|
||||
uint64 v;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, v ) || v == 0 || (v >> 32) != 0 )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
uFieldTag = (uint32)v;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufSkipFieldValue( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag )
|
||||
{
|
||||
switch ( uFieldTag & 7 )
|
||||
{
|
||||
case 0: // VARINT
|
||||
while ( pParsePosition < pParseEnd )
|
||||
{
|
||||
char c = *pParsePosition++;
|
||||
if ( !( c & 128 ) )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
case 1: // FIXED64
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, 8 ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
pParsePosition += 8;
|
||||
return true;
|
||||
|
||||
case 2: // LENGTH DELIM (string, etc)
|
||||
{
|
||||
uint64 ulLength = 0;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, ulLength ) )
|
||||
return false;
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, ulLength ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
pParsePosition += ulLength;
|
||||
return true;
|
||||
}
|
||||
|
||||
case 5: // FIXED32
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, 4 ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
pParsePosition += 4;
|
||||
return true;
|
||||
|
||||
default: // UNKNOWN
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProtobufReadFixed32( const char * &pParsePosition, const char *pParseEnd, int32 &nValue )
|
||||
{
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, 4 ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
memcpy( &nValue, pParsePosition, 4 );
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
nValue = DWordSwap( nValue );
|
||||
#endif
|
||||
pParsePosition += 4;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadFixed32( const char * &pParsePosition, const char *pParseEnd, uint32 &uValue )
|
||||
{
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, 4 ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
memcpy( &uValue, pParsePosition, 4 );
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
uValue = DWordSwap( uValue );
|
||||
#endif
|
||||
pParsePosition += 4;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadFixed32( const char * &pParsePosition, const char *pParseEnd, float &flValue )
|
||||
{
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, 4 ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
std::copy( std::const_reverse_iterator( pParsePosition + 4 ), std::const_reverse_iterator( pParsePosition ), reinterpret_cast<char *>(&flValue) );
|
||||
#else
|
||||
memcpy( &flValue, pParsePosition, 4 );
|
||||
#endif
|
||||
pParsePosition += 4;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadFixed64( const char * &pParsePosition, const char *pParseEnd, int64 &lValue )
|
||||
{
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, 8 ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
memcpy( &lValue, pParsePosition, 8 );
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
lValue = QWordSwap( lValue );
|
||||
#endif
|
||||
pParsePosition += 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadFixed64( const char * &pParsePosition, const char *pParseEnd, uint64 &ulValue )
|
||||
{
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, 8 ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
memcpy( &ulValue, pParsePosition, 8 );
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
ulValue = QWordSwap( ulValue );
|
||||
#endif
|
||||
pParsePosition += 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadFixed64( const char * &pParsePosition, const char *pParseEnd, double &flValue )
|
||||
{
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, 8 ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
#ifdef VALVE_BIG_ENDIAN
|
||||
std::copy( std::const_reverse_iterator( pParsePosition + 8 ), std::const_reverse_iterator( pParsePosition ), reinterpret_cast<char *>(&flValue) );
|
||||
#else
|
||||
memcpy( &flValue, pParsePosition, 8 );
|
||||
#endif
|
||||
pParsePosition += 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, uint64 &ulVarInt )
|
||||
{
|
||||
return ProtobufDecodeVarInt( pParsePosition, pParseEnd, ulVarInt );
|
||||
}
|
||||
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, int64 &lVarInt )
|
||||
{
|
||||
return ProtobufDecodeVarInt( pParsePosition, pParseEnd, reinterpret_cast<uint64&>(lVarInt) );
|
||||
}
|
||||
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, uint32 &uVarInt )
|
||||
{
|
||||
uint64 ulVarInt;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, ulVarInt ) )
|
||||
return false;
|
||||
uVarInt = (uint32)ulVarInt;
|
||||
return (uint64)uVarInt == ulVarInt;
|
||||
}
|
||||
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, int32 &nVarInt )
|
||||
{
|
||||
uint64 ulVarInt;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, ulVarInt ) )
|
||||
return false;
|
||||
nVarInt = (int32)ulVarInt;
|
||||
return (uint64)(int64)nVarInt == ulVarInt;
|
||||
}
|
||||
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, bool &bVarInt )
|
||||
{
|
||||
uint64 ulVarInt;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, ulVarInt ) )
|
||||
return false;
|
||||
bVarInt = ( ulVarInt != 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadSInteger( const char * &pParsePosition, const char *pParseEnd, int64 &lVarInt )
|
||||
{
|
||||
uint64 v;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, v ) )
|
||||
return false;
|
||||
lVarInt = (int64)(v >> 1) ^ -(int64)(v & 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadSInteger( const char * &pParsePosition, const char *pParseEnd, int32 &nVarInt )
|
||||
{
|
||||
uint64 v;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, v ) )
|
||||
return false;
|
||||
int64 lVarInt = (int64)(v >> 1) ^ -(int64)(v & 1);
|
||||
nVarInt = (int32)lVarInt;
|
||||
return (int64)nVarInt == lVarInt;
|
||||
}
|
||||
|
||||
bool ProtobufReadString( const char * &pParsePosition, const char *pParseEnd, std::string &strValue )
|
||||
{
|
||||
uint64 ulLength;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, ulLength ) )
|
||||
return false;
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, ulLength ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
strValue.assign( pParsePosition, (size_t)ulLength );
|
||||
pParsePosition += ulLength;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadStringAlias( const char * &pParsePosition, const char *pParseEnd, const char * &pStringDataStart, const char * &pStringDataEnd )
|
||||
{
|
||||
uint64 ulLength;
|
||||
if ( !ProtobufDecodeVarInt( pParsePosition, pParseEnd, ulLength ) )
|
||||
return false;
|
||||
if ( CHECK_OVERRUN( pParsePosition, pParseEnd, ulLength ) )
|
||||
{
|
||||
pParsePosition = pParseEnd;
|
||||
return false;
|
||||
}
|
||||
pStringDataStart = pParsePosition;
|
||||
pParsePosition += ulLength;
|
||||
pStringDataEnd = pParsePosition;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template < typename T >
|
||||
static bool ProtobufReadRepeated_T( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector< T > &vecData, bool( *pfnRead )(const char * &, const char *, T &) )
|
||||
{
|
||||
if ( (uFieldTag & 7) == 2 )
|
||||
{
|
||||
const char *pStart = NULL, *pEnd = NULL;
|
||||
if ( !ProtobufReadStringAlias( pParsePosition, pParseEnd, pStart, pEnd ) )
|
||||
return false;
|
||||
|
||||
while ( pStart != pEnd )
|
||||
{
|
||||
T v;
|
||||
if ( !pfnRead( pStart, pEnd, v ) )
|
||||
return false;
|
||||
vecData.push_back( v );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
T v;
|
||||
if ( !pfnRead( pParsePosition, pParseEnd, v ) )
|
||||
return false;
|
||||
vecData.push_back( v );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<uint64> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadInteger ); }
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int64> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadInteger ); }
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<uint32> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadInteger ); }
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int32> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadInteger ); }
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<bool> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadInteger ); }
|
||||
bool ProtobufReadRepeatedSInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int64> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadSInteger ); }
|
||||
bool ProtobufReadRepeatedSInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int32> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadSInteger ); }
|
||||
bool ProtobufReadRepeatedFixed32( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int32> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadFixed32 ); }
|
||||
bool ProtobufReadRepeatedFixed32( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<uint32> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadFixed32 ); }
|
||||
bool ProtobufReadRepeatedFixed32( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<float> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadFixed32 ); }
|
||||
bool ProtobufReadRepeatedFixed64( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int64> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadFixed64 ); }
|
||||
bool ProtobufReadRepeatedFixed64( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<uint64> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadFixed64 ); }
|
||||
bool ProtobufReadRepeatedFixed64( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<double> &vec ) { return ProtobufReadRepeated_T( pParsePosition, pParseEnd, uFieldTag, vec, &ProtobufReadFixed64 ); }
|
||||
|
||||
bool ProtobufReadRepeatedString( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<std::string> &vec )
|
||||
{
|
||||
vec.push_back( std::string() );
|
||||
if ( !ProtobufReadString( pParsePosition, pParseEnd, vec.back() ) )
|
||||
{
|
||||
vec.pop_back();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template < typename T >
|
||||
static bool ProtobufExtractField_T( const char *pParsePosition, const char *pParseEnd, uint32 uFieldTag, T &value, bool( *pfnRead )(const char * &, const char *, T &) )
|
||||
{
|
||||
uint32 uCurrentTag = 0;
|
||||
bool bOK = false;
|
||||
while ( ProtobufReadFieldTag( pParsePosition, pParseEnd, uCurrentTag ) )
|
||||
{
|
||||
if ( uCurrentTag == uFieldTag )
|
||||
bOK = pfnRead( pParsePosition, pParseEnd, value );
|
||||
else
|
||||
ProtobufSkipFieldValue( pParsePosition, pParseEnd, uCurrentTag );
|
||||
}
|
||||
return bOK;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
static bool ProtobufExtractField_T( const char *pParsePosition, const char *pParseEnd, uint32 uFieldTag, T &value, bool( *pfnRead )(const char * &, const char *, uint32, T &) )
|
||||
{
|
||||
uint32 uCurrentTag = 0;
|
||||
bool bOK = false;
|
||||
while ( ProtobufReadFieldTag( pParsePosition, pParseEnd, uCurrentTag ) )
|
||||
{
|
||||
if ( uCurrentTag == uFieldTag || uCurrentTag == PROTOBUF_FIELDTAG_STRING( uFieldTag >> 3 ) )
|
||||
bOK = pfnRead( pParsePosition, pParseEnd, uCurrentTag, value );
|
||||
else
|
||||
ProtobufSkipFieldValue( pParsePosition, pParseEnd, uCurrentTag );
|
||||
}
|
||||
return bOK;
|
||||
}
|
||||
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, uint64 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), value, &ProtobufReadInteger ); }
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, int64 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), value, &ProtobufReadInteger ); }
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, uint32 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), value, &ProtobufReadInteger ); }
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, int32 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), value, &ProtobufReadInteger ); }
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, bool &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), value, &ProtobufReadInteger ); }
|
||||
bool ProtobufExtractField_SInteger( const std::string &strProtobuf, uint32 uFieldNumber, int64 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_SINTEGER( uFieldNumber ), value, &ProtobufReadSInteger ); }
|
||||
bool ProtobufExtractField_SInteger( const std::string &strProtobuf, uint32 uFieldNumber, int32 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_SINTEGER( uFieldNumber ), value, &ProtobufReadSInteger ); }
|
||||
bool ProtobufExtractField_Fixed64( const std::string &strProtobuf, uint32 uFieldNumber, int64 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED64( uFieldNumber ), value, &ProtobufReadFixed64 ); }
|
||||
bool ProtobufExtractField_Fixed64( const std::string &strProtobuf, uint32 uFieldNumber, uint64 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED64( uFieldNumber ), value, &ProtobufReadFixed64 ); }
|
||||
bool ProtobufExtractField_Fixed64( const std::string &strProtobuf, uint32 uFieldNumber, double &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED64( uFieldNumber ), value, &ProtobufReadFixed64 ); }
|
||||
bool ProtobufExtractField_Fixed32( const std::string &strProtobuf, uint32 uFieldNumber, int32 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED32( uFieldNumber ), value, &ProtobufReadFixed32 ); }
|
||||
bool ProtobufExtractField_Fixed32( const std::string &strProtobuf, uint32 uFieldNumber, uint32 &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED32( uFieldNumber ), value, &ProtobufReadFixed32 ); }
|
||||
bool ProtobufExtractField_Fixed32( const std::string &strProtobuf, uint32 uFieldNumber, float &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED32( uFieldNumber ), value, &ProtobufReadFixed32 ); }
|
||||
bool ProtobufExtractField_String( const std::string &strProtobuf, uint32 uFieldNumber, std::string &value ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_STRING( uFieldNumber ), value, &ProtobufReadString ); }
|
||||
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<uint64> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), vec, &ProtobufReadRepeatedInteger ); }
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<int64> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), vec, &ProtobufReadRepeatedInteger ); }
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<uint32> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), vec, &ProtobufReadRepeatedInteger ); }
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<int32> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), vec, &ProtobufReadRepeatedInteger ); }
|
||||
bool ProtobufExtractField_Integer( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<bool> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_INTEGER( uFieldNumber ), vec, &ProtobufReadRepeatedInteger ); }
|
||||
bool ProtobufExtractField_SInteger( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<int64> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_SINTEGER( uFieldNumber ), vec, &ProtobufReadRepeatedSInteger ); }
|
||||
bool ProtobufExtractField_SInteger( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<int32> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_SINTEGER( uFieldNumber ), vec, &ProtobufReadRepeatedSInteger ); }
|
||||
bool ProtobufExtractField_Fixed64( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<int64> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED64( uFieldNumber ), vec, &ProtobufReadRepeatedFixed64 ); }
|
||||
bool ProtobufExtractField_Fixed64( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<uint64> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED64( uFieldNumber ), vec, &ProtobufReadRepeatedFixed64 ); }
|
||||
bool ProtobufExtractField_Fixed64( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<double> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED64( uFieldNumber ), vec, &ProtobufReadRepeatedFixed64 ); }
|
||||
bool ProtobufExtractField_Fixed32( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<int32> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED32( uFieldNumber ), vec, &ProtobufReadRepeatedFixed32 ); }
|
||||
bool ProtobufExtractField_Fixed32( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<uint32> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED32( uFieldNumber ), vec, &ProtobufReadRepeatedFixed32 ); }
|
||||
bool ProtobufExtractField_Fixed32( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<float> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_FIXED32( uFieldNumber ), vec, &ProtobufReadRepeatedFixed32 ); }
|
||||
bool ProtobufExtractField_String( const std::string &strProtobuf, uint32 uFieldNumber, std::vector<std::string> &vec ) { return ProtobufExtractField_T( strProtobuf.data(), strProtobuf.data() + strProtobuf.size(), PROTOBUF_FIELDTAG_STRING( uFieldNumber ), vec, &ProtobufReadRepeatedString ); }
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
//====== Copyright 1996-2014, Valve Corporation, All rights reserved. =======
|
||||
//
|
||||
// Purpose: Simple C++ protobuf manipulation routines. For a more advanced,
|
||||
// fully-featured library, see https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
#ifndef SIMPLEPROTOBUF_H
|
||||
#define SIMPLEPROTOBUF_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "steam/steamtypes.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
//
|
||||
// This file contains some quick-and-dirty helpers that can encode and
|
||||
// decode the protocol-buffer ("protobuf") serialization format. It's
|
||||
// a reasonable way to communicate with simple protobuf-based services.
|
||||
//
|
||||
// However, if you are doing serious work with protobufs, you should
|
||||
// take the time to understand and use the official C++ library. It
|
||||
// provides a tool which copmiles protobuf descriptions directly into
|
||||
// working C++ classes, which will save you time and effort, and help
|
||||
// with parsing complicated message types.
|
||||
//
|
||||
// https://developers.google.com/protocol-buffers/
|
||||
//
|
||||
|
||||
//
|
||||
// The protobuf serialization format is a simple field-based encoding;
|
||||
// a complete protobuf is the unordered concatenation of all its fields.
|
||||
// Unknown or incorrectly-typed fields are ignored by protobuf parsers.
|
||||
//
|
||||
// Details: https://developers.google.com/protocol-buffers/docs/encoding
|
||||
//
|
||||
// All protobuf value types use one of these five encodings:
|
||||
// Integer: bool, enum, int32, uint32, int64, uint64
|
||||
// SInteger: sint32, sint64
|
||||
// Fixed32: fixed32, float
|
||||
// Fixed64: fixed64, double
|
||||
// String: string, bytes, nested message types
|
||||
//
|
||||
// Nested protobufs are built up independently, then encoded as string
|
||||
// fields in the parent protobuf.
|
||||
//
|
||||
// Arrays ("repeated" field types) have two possible encodings: simple
|
||||
// and packed. This utility file can parse both encodings, but only
|
||||
// emits simple repeated fields (via multiple ProtobufWriteField calls
|
||||
// with the same field number, one for every array element).
|
||||
//
|
||||
|
||||
//
|
||||
// Example usage
|
||||
//
|
||||
// If this is the protobuf definition of a message...
|
||||
//
|
||||
// message TestMessage {
|
||||
// optional uint32 index = 1;
|
||||
// optional string text = 2;
|
||||
// repeated double number = 3;
|
||||
// optional bool flag = 4;
|
||||
// }
|
||||
//
|
||||
// ...then this is how to compose it:
|
||||
//
|
||||
// std::string msg;
|
||||
// ProtobufWriteField_Integer( msg, 1, iIndex );
|
||||
// ProtobufWriteField_Integer( msg, 4, true );
|
||||
// ProtobufWriteField_Fixed64( msg, 3, 1.0 );
|
||||
// ProtobufWriteField_Fixed64( msg, 3, 2.0 );
|
||||
// ProtobufWriteField_Fixed64( msg, 3, 3.0 );
|
||||
// ProtobufWriteField_String( msg, 2, "text field" );
|
||||
//
|
||||
// ...and this is how to extract individual fields:
|
||||
//
|
||||
// std::string strText;
|
||||
// ProtobufExtractField_String( msg, 2, strText );
|
||||
//
|
||||
// ...and this is how to parse it with optimized low-level operations:
|
||||
//
|
||||
// bool bFlag = false;
|
||||
// uint32 uIndex = 0;
|
||||
// std::string strText;
|
||||
// std::vector< double > vecNumbers;
|
||||
//
|
||||
// const char *pParse = msg.data(), *pEnd = msg.data() + msg.size();
|
||||
// for ( uint32 uFieldTag = 0; ProtobufReadFieldTag( pParse, pEnd, uFieldTag ); ) {
|
||||
// switch ( uFieldTag ) {
|
||||
// case PROTOBUF_FIELDTAG_INTEGER( 1 ): ProtobufReadInteger( pParse, pEnd, iIndex ); break;
|
||||
// case PROTOBUF_FIELDTAG_STRING( 2 ): ProtobufReadString( pParse, pEnd, strText ); break;
|
||||
// case PROTOBUF_FIELDTAG_FIXED64( 3 ): case PROTOBUF_FIELDTAG_REPEATED_FIXED64( 3 ):
|
||||
// ProtobufReadRepeatedFixed64( pParse, pEnd, uFieldTag, vecNumbers ); break;
|
||||
// case PROTOBUF_FIELDTAG_STRING( 4 ): ProtobufReadInteger( pParse, pEnd, bFlag ); break;
|
||||
// default: ProtobufSkipFieldValue( pParse, pEnd, uFieldTag ); break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// NOTE: it is important to handle both REPEATED and non-REPEATED cases when
|
||||
// parsing repeated fields, for all types other than strings! There are two
|
||||
// different possible encodings for repeated non-string fields, and failing
|
||||
// to handle both cases can lead to invalid parse results.
|
||||
//
|
||||
|
||||
|
||||
// Encoding functions
|
||||
//
|
||||
// Note: C++ type promotion rules will automatically handle smaller integer types
|
||||
|
||||
void ProtobufWriteField_Integer( std::string& strProtobuf, uint32 uFieldNumber, uint64 ulVarIntData );
|
||||
void ProtobufWriteField_SInteger( std::string& strProtobuf, uint32 uFieldNumber, int64 lSwizzleVarIntData );
|
||||
void ProtobufWriteField_Fixed64( std::string& strProtobuf, uint32 uFieldNumber, uint64 ulFixed64Data );
|
||||
void ProtobufWriteField_Fixed64( std::string& strProtobuf, uint32 uFieldNumber, double flFixed64Data );
|
||||
void ProtobufWriteField_Fixed32( std::string& strProtobuf, uint32 uFieldNumber, uint32 ulFixed32Data );
|
||||
void ProtobufWriteField_Fixed32( std::string& strProtobuf, uint32 uFieldNumber, float flFixed32Data );
|
||||
void ProtobufWriteField_String( std::string& strProtobuf, uint32 uFieldNumber, const char *pchData, size_t cchData );
|
||||
void ProtobufWriteField_String( std::string& strProtobuf, uint32 uFieldNumber, const char *pchData );
|
||||
void ProtobufWriteField_String( std::string& strProtobuf, uint32 uFieldNumber, const std::string &strData );
|
||||
|
||||
// Decoding functions, high-level (not optimized for speed)
|
||||
//
|
||||
|
||||
bool ProtobufExtractField_Integer( const std::string & strProtobuf, uint32 uFieldNumber, uint64 &ulData );
|
||||
bool ProtobufExtractField_Integer( const std::string & strProtobuf, uint32 uFieldNumber, int64 &lData );
|
||||
bool ProtobufExtractField_Integer( const std::string & strProtobuf, uint32 uFieldNumber, uint32 &uData );
|
||||
bool ProtobufExtractField_Integer( const std::string & strProtobuf, uint32 uFieldNumber, int32 &iData );
|
||||
bool ProtobufExtractField_Integer( const std::string & strProtobuf, uint32 uFieldNumber, bool &bData );
|
||||
bool ProtobufExtractField_SInteger( const std::string & strProtobuf, uint32 uFieldNumber, int64 &lData );
|
||||
bool ProtobufExtractField_SInteger( const std::string & strProtobuf, uint32 uFieldNumber, int32 &lData );
|
||||
bool ProtobufExtractField_Fixed64( const std::string & strProtobuf, uint32 uFieldNumber, uint64 &ulData );
|
||||
bool ProtobufExtractField_Fixed64( const std::string & strProtobuf, uint32 uFieldNumber, int64 &lData );
|
||||
bool ProtobufExtractField_Fixed64( const std::string & strProtobuf, uint32 uFieldNumber, double &flData );
|
||||
bool ProtobufExtractField_Fixed32( const std::string & strProtobuf, uint32 uFieldNumber, uint32 &uData );
|
||||
bool ProtobufExtractField_Fixed32( const std::string & strProtobuf, uint32 uFieldNumber, int32 &iData );
|
||||
bool ProtobufExtractField_Fixed32( const std::string & strProtobuf, uint32 uFieldNumber, float &flData );
|
||||
bool ProtobufExtractField_String( const std::string & strProtobuf, uint32 uFieldNumber, std::string &strData );
|
||||
|
||||
// Decoding functions, low-level (see example usage and important NOTE in comments above)
|
||||
//
|
||||
|
||||
bool ProtobufReadFieldTag( const char * &pParsePosition, const char *pParseEnd, uint32 &uFieldTag );
|
||||
bool ProtobufSkipFieldValue( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag );
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, uint64 &ulVarInt );
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, int64 &lVarInt );
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, uint32 &uVarInt );
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, int32 &nVarInt );
|
||||
bool ProtobufReadInteger( const char * &pParsePosition, const char *pParseEnd, bool &bVarInt );
|
||||
bool ProtobufReadSInteger( const char * &pParsePosition, const char *pParseEnd, int64 &lVarInt );
|
||||
bool ProtobufReadSInteger( const char * &pParsePosition, const char *pParseEnd, int32 &nVarInt );
|
||||
bool ProtobufReadFixed64( const char * &pParsePosition, const char *pParseEnd, int64 &lValue );
|
||||
bool ProtobufReadFixed64( const char * &pParsePosition, const char *pParseEnd, uint64 &ulValue );
|
||||
bool ProtobufReadFixed64( const char * &pParsePosition, const char *pParseEnd, double &flValue );
|
||||
bool ProtobufReadFixed32( const char * &pParsePosition, const char *pParseEnd, int32 &nValue );
|
||||
bool ProtobufReadFixed32( const char * &pParsePosition, const char *pParseEnd, uint32 &uValue );
|
||||
bool ProtobufReadFixed32( const char * &pParsePosition, const char *pParseEnd, float &flValue );
|
||||
bool ProtobufReadString( const char * &pParsePosition, const char *pParseEnd, std::string &strValue );
|
||||
bool ProtobufReadStringAlias( const char * &pParsePosition, const char *pParseEnd, const char * &pStringDataStart, const char * &pStringDataEnd );
|
||||
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<uint64> &vec );
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int64> &vec );
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<uint32> &vec );
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int32> &vec );
|
||||
bool ProtobufReadRepeatedInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<bool> &vec );
|
||||
bool ProtobufReadRepeatedSInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int64> &vec );
|
||||
bool ProtobufReadRepeatedSInteger( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int32> &vec );
|
||||
bool ProtobufReadRepeatedFixed64( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int64> &vec );
|
||||
bool ProtobufReadRepeatedFixed64( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<uint64> &vec );
|
||||
bool ProtobufReadRepeatedFixed64( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<double> &vec );
|
||||
bool ProtobufReadRepeatedFixed32( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<int32> &vec );
|
||||
bool ProtobufReadRepeatedFixed32( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<uint32> &vec );
|
||||
bool ProtobufReadRepeatedFixed32( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<float> &vec );
|
||||
bool ProtobufReadRepeatedString( const char * &pParsePosition, const char *pParseEnd, uint32 uFieldTag, std::vector<std::string> &vec );
|
||||
|
||||
#define PROTOBUF_FIELDTAG_INTEGER( Field ) ( (uint64)( Field ) << 3 )
|
||||
#define PROTOBUF_FIELDTAG_SINTEGER( Field ) ( (uint64)( Field ) << 3 )
|
||||
#define PROTOBUF_FIELDTAG_FIXED64( Field ) ( (uint64)( Field ) << 3 | (uint64)1 )
|
||||
#define PROTOBUF_FIELDTAG_STRING( Field ) ( (uint64)( Field ) << 3 | (uint64)2 )
|
||||
#define PROTOBUF_FIELDTAG_FIXED32( Field ) ( (uint64)( Field ) << 3 | (uint64)5 )
|
||||
|
||||
#define PROTOBUF_FIELDTAG_REPEATED_INTEGER PROTOBUF_FIELDTAG_STRING
|
||||
#define PROTOBUF_FIELDTAG_REPEATED_SINTEGER PROTOBUF_FIELDTAG_STRING
|
||||
#define PROTOBUF_FIELDTAG_REPEATED_FIXED32 PROTOBUF_FIELDTAG_STRING
|
||||
#define PROTOBUF_FIELDTAG_REPEATED_FIXED64 PROTOBUF_FIELDTAG_STRING
|
||||
|
||||
|
||||
#endif
|
||||
@@ -144,7 +144,10 @@ public:
|
||||
HGAMEFONT HCreateFont( int nHeight, int nFontWeight, bool bItalic, const char * pchFont );
|
||||
|
||||
// Create a new texture returning our internal handle value for it (0 means failure)
|
||||
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight );
|
||||
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat = eTextureFormat_RGBA );
|
||||
|
||||
// update an existing texture
|
||||
bool UpdateTexture( HGAMETEXTURE texture, byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat );
|
||||
|
||||
// Draw a line, the engine itself will manage batching these (although you can explicitly flush if you need to)
|
||||
bool BDrawLine( float xPos0, float yPos0, DWORD dwColor0, float xPos1, float yPos1, DWORD dwColor1 );
|
||||
|
||||
@@ -1693,7 +1693,7 @@ bool CGameEngineGL::BFlushQuadBuffer()
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Creates a new texture
|
||||
//-----------------------------------------------------------------------------
|
||||
HGAMETEXTURE CGameEngineGL::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight )
|
||||
HGAMETEXTURE CGameEngineGL::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat )
|
||||
{
|
||||
#if DX9MODE
|
||||
if ( !m_pD3D9Device )
|
||||
@@ -1732,7 +1732,7 @@ HGAMETEXTURE CGameEngineGL::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint
|
||||
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
|
||||
// build our texture mipmaps
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, uWidth, uHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (void *)pRGBAData );
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, uWidth, uHeight, 0, eTextureFormat == eTextureFormat_RGBA ? GL_RGBA : GL_BGRA, GL_UNSIGNED_BYTE, (void *)pRGBAData );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
int nHandle = m_nNextTextureHandle;
|
||||
@@ -1744,6 +1744,39 @@ HGAMETEXTURE CGameEngineGL::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: update an exiting textue
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGameEngineGL::UpdateTexture( HGAMETEXTURE texture, byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat )
|
||||
{
|
||||
#if DX9MODE
|
||||
|
||||
return false;
|
||||
#else
|
||||
if ( m_bShuttingDown )
|
||||
return false;
|
||||
|
||||
std::map<HGAMETEXTURE, TextureData_t>::iterator iter;
|
||||
iter = m_MapTextures.find( texture );
|
||||
if ( iter == m_MapTextures.end() )
|
||||
{
|
||||
OutputDebugString( "BDrawTexturedQuad called with invalid hTexture value\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
glBindTexture( GL_TEXTURE_2D, iter->second.m_uTextureID );
|
||||
|
||||
// build our texture mipmaps
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, uWidth, uHeight, 0, eTextureFormat == eTextureFormat_RGBA ? GL_RGBA : GL_BGRA, GL_UNSIGNED_BYTE, (void *)pRGBAData );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
return true;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Creates a new font
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -837,7 +837,7 @@ bool CGameEngineGL::BFlushQuadBuffer()
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Creates a new texture
|
||||
//-----------------------------------------------------------------------------
|
||||
HGAMETEXTURE CGameEngineGL::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight )
|
||||
HGAMETEXTURE CGameEngineGL::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat )
|
||||
{
|
||||
if ( m_bShuttingDown )
|
||||
return 0;
|
||||
@@ -859,7 +859,7 @@ HGAMETEXTURE CGameEngineGL::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint
|
||||
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
|
||||
|
||||
// build our texture mipmaps
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, uWidth, uHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, (void *)pRGBAData );
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, uWidth, uHeight, 0, eTextureFormat == eTextureFormat_RGBA ? GL_RGBA : GL_BGRA, GL_UNSIGNED_BYTE, (void *)pRGBAData );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
int nHandle = m_nNextTextureHandle;
|
||||
@@ -870,6 +870,33 @@ HGAMETEXTURE CGameEngineGL::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: update an exiting textue
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGameEngineGL::UpdateTexture( HGAMETEXTURE texture, byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat )
|
||||
{
|
||||
if ( m_bShuttingDown )
|
||||
return false;
|
||||
|
||||
std::map<HGAMETEXTURE, TextureData_t>::iterator iter;
|
||||
iter = m_MapTextures.find( texture );
|
||||
if ( iter == m_MapTextures.end() )
|
||||
{
|
||||
OutputDebugString( "BDrawTexturedQuad called with invalid hTexture value\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
glBindTexture( GL_TEXTURE_2D, iter->second.m_uTextureID );
|
||||
|
||||
// build our texture mipmaps
|
||||
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, uWidth, uHeight, 0, eTextureFormat == eTextureFormat_RGBA ? GL_RGBA : GL_BGRA, GL_UNSIGNED_BYTE, (void *)pRGBAData );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Creates a new font
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -104,7 +104,10 @@ public:
|
||||
HGAMEFONT HCreateFont( int nHeight, int nFontWeight, bool bItalic, const char * pchFont );
|
||||
|
||||
// Create a new texture returning our internal handle value for it (0 means failure)
|
||||
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight );
|
||||
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat = eTextureFormat_RGBA );
|
||||
|
||||
// update an existing texture
|
||||
bool UpdateTexture( HGAMETEXTURE texture, byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat );
|
||||
|
||||
// Draw a line, the engine itself will manage batching these (although you can explicitly flush if you need to)
|
||||
bool BDrawLine( float xPos0, float yPos0, DWORD dwColor0, float xPos1, float yPos1, DWORD dwColor1 );
|
||||
|
||||
@@ -1846,29 +1846,34 @@ bool CGameEngineWin32::BRenderPrimitive( D3DPRIMITIVETYPE primType, uint32 uStar
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Creates a new texture
|
||||
//-----------------------------------------------------------------------------
|
||||
HGAMETEXTURE CGameEngineWin32::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight )
|
||||
{
|
||||
return HCreateTextureInternal( pRGBAData, uWidth, uHeight, D3DFMT_A8R8G8B8 );
|
||||
}
|
||||
|
||||
|
||||
// Create a new texture returning our internal handle value for it (0 means failure)
|
||||
HGAMETEXTURE CGameEngineWin32::HCreateTextureInternal( byte *pRGBAData, uint32 uWidth, uint32 uHeight, D3DFORMAT eFormat )
|
||||
HGAMETEXTURE CGameEngineWin32::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat )
|
||||
{
|
||||
if ( !m_pD3D9Device )
|
||||
return 0;
|
||||
|
||||
D3DFORMAT eD3DDeviceFormat = D3DFMT_A8R8G8B8;
|
||||
|
||||
switch ( eTextureFormat )
|
||||
{
|
||||
case eTextureFormat_RGBA:
|
||||
case eTextureFormat_BGRA:
|
||||
eD3DDeviceFormat = D3DFMT_A8R8G8B8;
|
||||
break;
|
||||
case eTextureFormat_BGRA16:
|
||||
eD3DDeviceFormat = D3DFMT_A16B16G16R16;
|
||||
}
|
||||
|
||||
TextureData_t TexData;
|
||||
TexData.m_uWidth = uWidth;
|
||||
TexData.m_uHeight = uHeight;
|
||||
if ( pRGBAData )
|
||||
{
|
||||
size_t dataSize = 0;
|
||||
if ( eFormat == D3DFMT_A8B8G8R8 )
|
||||
if ( eD3DDeviceFormat == D3DFMT_A8R8G8B8 )
|
||||
{
|
||||
dataSize = uWidth*uHeight * 4;
|
||||
}
|
||||
else if ( eFormat == D3DFMT_A16B16G16R16 )
|
||||
else if ( eD3DDeviceFormat == D3DFMT_A16B16G16R16 )
|
||||
{
|
||||
dataSize = sizeof(uint16)* 4 * uWidth * uHeight;
|
||||
}
|
||||
@@ -1881,7 +1886,8 @@ HGAMETEXTURE CGameEngineWin32::HCreateTextureInternal( byte *pRGBAData, uint32 u
|
||||
}
|
||||
TexData.m_pTexture = NULL;
|
||||
TexData.m_pDepthSurface = NULL;
|
||||
TexData.m_eFormat = eFormat;
|
||||
TexData.m_eFormat = eD3DDeviceFormat;
|
||||
TexData.m_eTextureFormat = eTextureFormat;
|
||||
|
||||
int nHandle = m_nNextTextureHandle;
|
||||
++m_nNextTextureHandle;
|
||||
@@ -2162,6 +2168,78 @@ bool CGameEngineWin32::AddVoiceData( HGAMEVOICECHANNEL hChannel, const uint8 *pV
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: update an existing texture
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CGameEngineWin32::UpdateTexture( HGAMETEXTURE hTexture, byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat )
|
||||
{
|
||||
std::map<HGAMETEXTURE, TextureData_t>::iterator iter;
|
||||
iter = m_MapTextures.find( hTexture );
|
||||
if (iter == m_MapTextures.end())
|
||||
{
|
||||
OutputDebugString( "BFlushQuadBuffer failed with invalid m_hLastTexture value\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Put the data into the texture
|
||||
D3DLOCKED_RECT rect;
|
||||
HRESULT hRes = iter->second.m_pTexture->LockRect( 0, &rect, NULL, 0 );
|
||||
if (FAILED( hRes ))
|
||||
{
|
||||
OutputDebugString( "LockRect call failed\n" );
|
||||
iter->second.m_pTexture->Release();
|
||||
iter->second.m_pTexture = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (iter->second.m_eFormat == D3DFMT_A8R8G8B8)
|
||||
{
|
||||
DWORD *pARGB = (DWORD *)rect.pBits;
|
||||
byte *pRGBA = (byte *)pRGBAData;
|
||||
|
||||
byte r, g, b, a;
|
||||
for (uint32 y = 0; y < uHeight; ++y)
|
||||
{
|
||||
for (uint32 x = 0; x < uWidth; ++x)
|
||||
{
|
||||
// swap position of alpha value from back to front to be in correct format for d3d...
|
||||
r = *pRGBA++;
|
||||
g = *pRGBA++;
|
||||
b = *pRGBA++;
|
||||
a = *pRGBA++;
|
||||
|
||||
if ( eTextureFormat == eTextureFormat_RGBA )
|
||||
*pARGB++ = D3DCOLOR_ARGB( a, r, g, b );
|
||||
else if ( eTextureFormat == eTextureFormat_BGRA)
|
||||
*pARGB++ = D3DCOLOR_ARGB( a, b, g, r );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (iter->second.m_eFormat == D3DFMT_A16B16G16R16)
|
||||
{
|
||||
uint16 *pDest = (uint16 *)rect.pBits;
|
||||
uint16 *pSrc = (uint16 *)pRGBAData;
|
||||
|
||||
if ( eTextureFormat != eTextureFormat_BGRA16 )
|
||||
OutputDebugString( "Unsupported texture format for BGRA16 texture \n" );
|
||||
|
||||
memcpy( pDest, pSrc, sizeof( uint16 )* uWidth * uHeight * 4 );
|
||||
}
|
||||
|
||||
hRes = iter->second.m_pTexture->UnlockRect( 0 );
|
||||
if (FAILED( hRes ))
|
||||
{
|
||||
OutputDebugString( "UnlockRect call failed\n" );
|
||||
iter->second.m_pTexture->Release();
|
||||
iter->second.m_pTexture = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CGameEngineWin32::BReadyTexture( HGAMETEXTURE hTexture )
|
||||
{
|
||||
std::map<HGAMETEXTURE, TextureData_t>::iterator iter;
|
||||
@@ -2215,7 +2293,7 @@ bool CGameEngineWin32::BReadyTexture( HGAMETEXTURE hTexture )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( iter->second.m_eFormat == D3DFMT_A8B8G8R8 )
|
||||
if ( iter->second.m_eFormat == D3DFMT_A8R8G8B8 )
|
||||
{
|
||||
DWORD *pARGB = (DWORD *)rect.pBits;
|
||||
byte *pRGBA = (byte *)iter->second.m_pRGBAData;
|
||||
@@ -2231,7 +2309,10 @@ bool CGameEngineWin32::BReadyTexture( HGAMETEXTURE hTexture )
|
||||
b = *pRGBA++;
|
||||
a = *pRGBA++;
|
||||
|
||||
*pARGB++ = D3DCOLOR_ARGB( a, r, g, b );
|
||||
if ( iter->second.m_eTextureFormat == eTextureFormat_RGBA )
|
||||
*pARGB++ = D3DCOLOR_ARGB( a, r, g, b );
|
||||
else
|
||||
*pARGB++ = D3DCOLOR_ARGB( a, b, g, r );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2239,6 +2320,9 @@ bool CGameEngineWin32::BReadyTexture( HGAMETEXTURE hTexture )
|
||||
{
|
||||
uint16 *pDest = (uint16 *)rect.pBits;
|
||||
uint16 *pSrc = (uint16 *)iter->second.m_pRGBAData;
|
||||
|
||||
if ( iter->second.m_eTextureFormat != eTextureFormat_BGRA16 )
|
||||
OutputDebugString( "Unsupported texture format for BGRA16 texture \n" );
|
||||
|
||||
memcpy( pDest, pSrc, sizeof(uint16)* iter->second.m_uWidth * iter->second.m_uHeight * 4 );
|
||||
}
|
||||
@@ -2515,7 +2599,7 @@ bool CGameEngineWin32::BInitializeVRShader()
|
||||
}
|
||||
}
|
||||
|
||||
m_hVRDistortionMap[i] = HCreateTextureInternal( (byte *)pData, nDistSize, nDistSize, D3DFMT_A16B16G16R16 );
|
||||
m_hVRDistortionMap[i] = HCreateTexture( (byte *)pData, nDistSize, nDistSize, eTextureFormat_BGRA16 );
|
||||
free( pData );
|
||||
if ( !m_hVRDistortionMap[i] )
|
||||
{
|
||||
|
||||
@@ -127,7 +127,10 @@ public:
|
||||
HGAMEFONT HCreateFont( int nHeight, int nFontWeight, bool bItalic, const char * pchFont );
|
||||
|
||||
// Create a new texture returning our internal handle value for it (0 means failure)
|
||||
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight );
|
||||
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat = eTextureFormat_RGBA );
|
||||
|
||||
// update an existing texture
|
||||
bool UpdateTexture( HGAMETEXTURE texture, byte *pRGBAData, uint32 uWidth, uint32 uHeight, ETEXTUREFORMAT eTextureFormat );
|
||||
|
||||
// Draw a line, the engine itself will manage batching these (although you can explicitly flush if you need to)
|
||||
bool BDrawLine( float xPos0, float yPos0, DWORD dwColor0, float xPos1, float yPos1, DWORD dwColor1 );
|
||||
@@ -203,9 +206,6 @@ public:
|
||||
void RecordKeyUp( DWORD dwVK );
|
||||
|
||||
private:
|
||||
// Create a new texture returning our internal handle value for it (0 means failure)
|
||||
HGAMETEXTURE HCreateTextureInternal( byte *pRGBAData, uint32 uWidth, uint32 uHeight, D3DFORMAT eFormat );
|
||||
|
||||
|
||||
// Creates the hwnd for the game
|
||||
bool BCreateGameWindow( int nShowCommand );
|
||||
@@ -309,7 +309,8 @@ private:
|
||||
uint32 m_uHeight;
|
||||
LPDIRECT3DTEXTURE9 m_pTexture;
|
||||
LPDIRECT3DSURFACE9 m_pDepthSurface; // render targets only
|
||||
D3DFORMAT m_eFormat;
|
||||
D3DFORMAT m_eFormat; // format for the texture on the card itself
|
||||
ETEXTUREFORMAT m_eTextureFormat; // format of the data you provide
|
||||
};
|
||||
std::map<HGAMETEXTURE, TextureData_t> m_MapTextures;
|
||||
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
//========= Copyright © 1996-2008, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose: Class to render a HTML page on the screen
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "htmlsurface.h"
|
||||
#include "SpaceWarClient.h"
|
||||
|
||||
#define HTML_TEXT_HEIGHT 20
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Constructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CHTMLSurface::CHTMLSurface( IGameEngine *pGameEngine ) :
|
||||
m_CloseBrowser( this, &CHTMLSurface::OnCloseBrowser ),
|
||||
m_NeedsPaint( this, &CHTMLSurface::OnNeedsPaint ),
|
||||
m_StartRequest( this, &CHTMLSurface::OnStartRequest ),
|
||||
m_FinishedRequest( this, &CHTMLSurface::OnFinishedRequest )
|
||||
{
|
||||
m_pGameEngine = pGameEngine;
|
||||
m_unBrowserHandle = INVALID_HTTMLBROWSER;
|
||||
m_hHTMLTexture = -1;
|
||||
|
||||
m_unHTMLWide = m_pGameEngine->GetViewportWidth() - 100;
|
||||
m_unHTMLTall = m_pGameEngine->GetViewportHeight() - 100;
|
||||
|
||||
SteamHTMLSurface()->Init();
|
||||
SteamHTMLSurface()->SetSize( m_unBrowserHandle, m_unHTMLWide, m_unHTMLTall );
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Destructor
|
||||
//-----------------------------------------------------------------------------
|
||||
CHTMLSurface::~CHTMLSurface()
|
||||
{
|
||||
if ( m_unBrowserHandle )
|
||||
SteamHTMLSurface()->RemoveBrowser( m_unBrowserHandle );
|
||||
m_unBrowserHandle = INVALID_HTTMLBROWSER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: RunFrame
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLSurface::RunFrame()
|
||||
{
|
||||
if ( m_pGameEngine->BIsKeyDown( VK_ESCAPE ) )
|
||||
{
|
||||
SpaceWarClient()->SetGameState( k_EClientGameMenu );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: draw the page
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLSurface::Render()
|
||||
{
|
||||
if (m_hHTMLTexture >= 0)
|
||||
{
|
||||
RECT rect;
|
||||
rect.left = 50;
|
||||
rect.top = 50;
|
||||
rect.right = m_unHTMLWide + rect.left;
|
||||
rect.bottom = m_unHTMLTall + rect.top;
|
||||
|
||||
m_pGameEngine->BDrawTexturedQuad( (float)rect.left, (float)rect.top, (float)rect.right, (float)rect.bottom,
|
||||
0.0f, 0.0f, 1.0, 1.0, D3DCOLOR_ARGB( 255, 255, 255, 255 ), m_hHTMLTexture );
|
||||
}
|
||||
|
||||
RECT rect;
|
||||
rect.top = m_unHTMLTall + 70;
|
||||
rect.bottom = rect.top + HTML_TEXT_HEIGHT;
|
||||
rect.left = m_unHTMLWide/2 - 200;
|
||||
rect.right = rect.left + 400;
|
||||
|
||||
char rgchBuffer[256];
|
||||
sprintf_safe( rgchBuffer, "Hit ESC to return to main menu" );
|
||||
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER | TEXTPOS_VCENTER, rgchBuffer );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLSurface::Show()
|
||||
{
|
||||
m_hDisplayFont = m_pGameEngine->HCreateFont(HTML_TEXT_HEIGHT, FW_MEDIUM, false, "Arial");
|
||||
if (!m_hDisplayFont)
|
||||
OutputDebugString("RemoteStorage font was not created properly, text won't draw\n");
|
||||
|
||||
SteamAPICall_t hSteamAPICall = SteamHTMLSurface()->CreateBrowser( "SpaceWars Test", NULL );
|
||||
m_SteamCallResultBrowserReady.Set( hSteamAPICall, this, &CHTMLSurface::OnBrowserReady );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: the page asked to be closed
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLSurface::OnCloseBrowser( HTML_CloseBrowser_t *pParam )
|
||||
{
|
||||
m_unBrowserHandle = INVALID_HTTMLBROWSER;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: the browser is ready to load pages and start sending us textures to render
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLSurface::OnBrowserReady( HTML_BrowserReady_t *pBrowserReady, bool bIOFailure )
|
||||
{
|
||||
if (bIOFailure)
|
||||
return;
|
||||
|
||||
m_unBrowserHandle = pBrowserReady->unBrowserHandle;
|
||||
SteamHTMLSurface()->SetSize( m_unBrowserHandle, m_unHTMLWide, m_unHTMLWide );
|
||||
SteamHTMLSurface()->LoadURL( m_unBrowserHandle, "http://steamcommunity.com/", NULL );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: we have a new texture to present
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLSurface::OnNeedsPaint( HTML_NeedsPaint_t *pParam )
|
||||
{
|
||||
if ( m_hHTMLTexture < 0 )
|
||||
m_hHTMLTexture = m_pGameEngine->HCreateTexture( (byte *)pParam->pBGRA, pParam->unWide, pParam->unTall, eTextureFormat_BGRA );
|
||||
else
|
||||
m_pGameEngine->UpdateTexture( m_hHTMLTexture, (byte *)pParam->pBGRA, pParam->unWide, pParam->unTall, eTextureFormat_BGRA );
|
||||
|
||||
if (pParam->unWide != m_unHTMLWide)
|
||||
OutputDebugString( "bad texture width for html\n" );
|
||||
if (pParam->unTall != m_unHTMLTall)
|
||||
OutputDebugString( "bad texture height for html\n" );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: the page requested that a URL be loaded, should we allow it?
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLSurface::OnStartRequest( HTML_StartRequest_t *pParam )
|
||||
{
|
||||
SteamHTMLSurface()->AllowStartRequest( m_unBrowserHandle, true );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: the page is now fully loaded
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHTMLSurface::OnFinishedRequest( HTML_FinishedRequest_t *pParam )
|
||||
{
|
||||
// Uncomment this if you want to scale a pages contents when you display it
|
||||
//SteamHTMLSurface()->SetPageScaleFactor( m_unBrowserHandle, 2.0, 0, 0 );
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//========= Copyright © 1996-2008, Valve LLC, All rights reserved. ============
|
||||
//
|
||||
// Purpose: Class for handling finding servers, getting their details, and displaying
|
||||
// them inside the game
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================
|
||||
|
||||
#ifndef HTMLSURFACE_H
|
||||
#define HTMLSURFACE_H
|
||||
|
||||
#include "SpaceWar.h"
|
||||
#include "GameEngine.h"
|
||||
#include "steam/steam_api.h"
|
||||
#include "steam/isteamhtmlsurface.h"
|
||||
|
||||
|
||||
class CHTMLSurface
|
||||
{
|
||||
public:
|
||||
CHTMLSurface( IGameEngine *pGameEngine );
|
||||
~CHTMLSurface();
|
||||
|
||||
// Run a frame (to handle kb input and such as well as render)
|
||||
void RunFrame();
|
||||
|
||||
void Render();
|
||||
|
||||
void Show();
|
||||
|
||||
private:
|
||||
STEAM_CALLBACK( CHTMLSurface, OnCloseBrowser, HTML_CloseBrowser_t, m_CloseBrowser );
|
||||
STEAM_CALLBACK( CHTMLSurface, OnNeedsPaint, HTML_NeedsPaint_t, m_NeedsPaint );
|
||||
STEAM_CALLBACK( CHTMLSurface, OnStartRequest, HTML_StartRequest_t, m_StartRequest );
|
||||
STEAM_CALLBACK( CHTMLSurface, OnFinishedRequest, HTML_FinishedRequest_t, m_FinishedRequest );
|
||||
|
||||
void OnBrowserReady( HTML_BrowserReady_t *pBrowserReady, bool bIOFailure );
|
||||
CCallResult< CHTMLSurface, HTML_BrowserReady_t > m_SteamCallResultBrowserReady;
|
||||
|
||||
|
||||
// Pointer to engine instance (so we can draw stuff)
|
||||
IGameEngine *m_pGameEngine;
|
||||
|
||||
HGAMEFONT m_hDisplayFont;
|
||||
|
||||
HHTMLBrowser m_unBrowserHandle; // handle to the html surface object
|
||||
HGAMETEXTURE m_hHTMLTexture; // the texture data for the page
|
||||
|
||||
uint32 m_unHTMLWide; // the size of the html page we want to show
|
||||
uint32 m_unHTMLTall;
|
||||
|
||||
};
|
||||
|
||||
#endif //HTMLSURFACE_H
|
||||
@@ -193,6 +193,8 @@ bool CSteamVRGLHelper::BInitPredistortRenderTarget()
|
||||
// Set the list of draw buffers.
|
||||
GLenum rDrawBuffers[1] = { GL_COLOR_ATTACHMENT0 };
|
||||
glDrawBuffers(ARRAYSIZE( rDrawBuffers ), rDrawBuffers);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
50E77DF51362190C000FC072 /* glmgrext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50E77DE61362190C000FC072 /* glmgrext.cpp */; };
|
||||
50E77DF61362190C000FC072 /* mathlite.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 50E77DE91362190C000FC072 /* mathlite.cpp */; };
|
||||
50E77DF813621991000FC072 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50E77DF713621991000FC072 /* IOKit.framework */; };
|
||||
840B387019BB91C50084B9F1 /* htmlsurface.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 840B386E19BB91C50084B9F1 /* htmlsurface.cpp */; };
|
||||
F803305119087F9200344590 /* musicplayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F803305019087F9200344590 /* musicplayer.cpp */; };
|
||||
F80330831908872600344590 /* controller.vdf in Resources */ = {isa = PBXBuildFile; fileRef = F80330821908872600344590 /* controller.vdf */; };
|
||||
/* End PBXBuildFile section */
|
||||
@@ -155,6 +156,8 @@
|
||||
50E77DE91362190C000FC072 /* mathlite.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = mathlite.cpp; path = ../glmgr/mathlite.cpp; sourceTree = "<group>"; };
|
||||
50E77DEA1362190C000FC072 /* mathlite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mathlite.h; path = ../glmgr/mathlite.h; sourceTree = "<group>"; };
|
||||
50E77DF713621991000FC072 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
|
||||
840B386E19BB91C50084B9F1 /* htmlsurface.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = htmlsurface.cpp; sourceTree = "<group>"; };
|
||||
840B386F19BB91C50084B9F1 /* htmlsurface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = htmlsurface.h; sourceTree = "<group>"; };
|
||||
F803304F19087DA600344590 /* musicplayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = musicplayer.h; sourceTree = "<group>"; };
|
||||
F803305019087F9200344590 /* musicplayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = musicplayer.cpp; sourceTree = "<group>"; };
|
||||
F80330821908872600344590 /* controller.vdf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = controller.vdf; sourceTree = "<group>"; };
|
||||
@@ -191,6 +194,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
50E77DCF136218F5000FC072 /* glmgr */,
|
||||
840B386E19BB91C50084B9F1 /* htmlsurface.cpp */,
|
||||
503C6CED1268F49F00B66E3B /* p2pauth.cpp */,
|
||||
503C6CEF1268F49F00B66E3B /* PhotonBeam.cpp */,
|
||||
503C6CF11268F49F00B66E3B /* QuitMenu.cpp */,
|
||||
@@ -253,6 +257,7 @@
|
||||
503C6D291268F4EE00B66E3B /* Headers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
840B386F19BB91C50084B9F1 /* htmlsurface.h */,
|
||||
50D642861461EF3200A5739B /* clanchatroom.h */,
|
||||
503C6CEE1268F49F00B66E3B /* p2pauth.h */,
|
||||
503C6CF01268F49F00B66E3B /* PhotonBeam.h */,
|
||||
@@ -380,6 +385,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
840B387019BB91C50084B9F1 /* htmlsurface.cpp in Sources */,
|
||||
503C6D0F1268F49F00B66E3B /* BaseMenu.cpp in Sources */,
|
||||
503C6D101268F49F00B66E3B /* connectingmenu.cpp in Sources */,
|
||||
F803305119087F9200344590 /* musicplayer.cpp in Sources */,
|
||||
|
||||
Reference in New Issue
Block a user