This commit is contained in:
Riley Labrecque
2014-01-29 13:10:49 +02:00
parent 1e6cca4e93
commit 6e588c2100
86 changed files with 3310 additions and 870 deletions
+23
View File
@@ -11,6 +11,29 @@ website at: http://partner.steamgames.com
Revision History:
----------------------------------------------------------------
v1.11 23rd August 2010
----------------------------------------------------------------
Networking
* added virtual ports to the P2P networking API to help with routing messages to different systems
* added ISteamUser::BIsBehindNAT() to detect when a user is behind a NAT
Friends / Matchmaking
* added support for retrieving large (184x184) avatars
* added ISteamUser::AdvertiseGame() which can be used send join game info to friends without using the game server APIs
64-bit support
* 64-bit windows binaries are included in the sdk/redistributable_bin/ folder
* VAC and CEG are not yet supported
Authentication
* added ticket based remote authentication library
Other
* added ISteamUser::CheckFileSignature which can be used in conjunction with the signing tab on the partner site to verify that an executable has not been modified
----------------------------------------------------------------
v1.10 20th July 2010
----------------------------------------------------------------
+16 -13
View File
@@ -29,7 +29,7 @@ public:
typedef std::pair<std::string, T> MenuItem_t;
// Constructor
CBaseMenu( CGameEngine *pGameEngine )
CBaseMenu( IGameEngine *pGameEngine )
{
m_pGameEngine = pGameEngine;
@@ -45,6 +45,9 @@ public:
}
// Destructor
virtual ~CBaseMenu() { }
// Sets a heading for the menu
void SetHeading( const char *pchHeading )
{
@@ -103,10 +106,10 @@ public:
if ( m_pGameEngine->BIsKeyDown( VK_RETURN ) )
{
uint64 ulCurrentTickCount = m_pGameEngine->GetGameTickCount();
if ( ulCurrentTickCount - 150 > g_ulLastReturnKeyTick )
if ( ulCurrentTickCount - 220 > g_ulLastReturnKeyTick )
{
g_ulLastReturnKeyTick = ulCurrentTickCount;
if ( m_uSelectedItem >= 0 && m_uSelectedItem < m_VecMenuItems.size() )
if ( m_uSelectedItem < m_VecMenuItems.size() )
{
SpaceWarClient()->OnMenuSelection( m_VecMenuItems[m_uSelectedItem].second );
return;
@@ -117,7 +120,7 @@ public:
else if ( m_pGameEngine->BIsKeyDown( VK_DOWN ) )
{
uint64 ulCurrentTickCount = m_pGameEngine->GetGameTickCount();
if ( ulCurrentTickCount - 150 > g_ulLastKeyDownTick )
if ( ulCurrentTickCount - 140 > g_ulLastKeyDownTick )
{
g_ulLastKeyDownTick = ulCurrentTickCount;
if ( m_uSelectedItem < m_VecMenuItems.size() - 1 )
@@ -127,7 +130,7 @@ public:
else if ( m_pGameEngine->BIsKeyDown( VK_UP ) )
{
uint64 ulCurrentTickCount = m_pGameEngine->GetGameTickCount();
if ( ulCurrentTickCount - 250 > g_ulLastKeyUpTick )
if ( ulCurrentTickCount - 140 > g_ulLastKeyUpTick )
{
g_ulLastKeyUpTick = ulCurrentTickCount;
if ( m_uSelectedItem > 0 )
@@ -143,7 +146,7 @@ public:
{
const int32 iMaxMenuItems = 13;
int32 iNumItems = (int32)m_VecMenuItems.size();
uint32 uBoxHeight = min( iNumItems, iMaxMenuItems ) * ( MENU_FONT_HEIGHT + MENU_ITEM_PADDING );
uint32 uBoxHeight = MIN( iNumItems, iMaxMenuItems ) * ( MENU_FONT_HEIGHT + MENU_ITEM_PADDING );
uint32 yPos = m_pGameEngine->GetViewportHeight()/2 - uBoxHeight/2;
RECT rect;
@@ -161,22 +164,22 @@ public:
rect.bottom = rect.top + MENU_FONT_HEIGHT + ( MENU_ITEM_PADDING * 2 );
rect.left = 0;
rect.right = m_pGameEngine->GetViewportWidth();
m_pGameEngine->BDrawString( g_hMenuFont, rect, dwColor, DT_CENTER|DT_VCENTER, m_sHeading.c_str() );
m_pGameEngine->BDrawString( g_hMenuFont, rect, dwColor, TEXTPOS_CENTER|TEXTPOS_VCENTER, m_sHeading.c_str() );
}
int32 iStartItem = 0;
int32 iEndItem = iNumItems;
if ( iNumItems > iMaxMenuItems )
{
iStartItem = max( (int32)m_uSelectedItem - iMaxMenuItems/2, 0 );
iEndItem = min( iStartItem + iMaxMenuItems, iNumItems );
iStartItem = MAX( (int32)m_uSelectedItem - iMaxMenuItems/2, 0 );
iEndItem = MIN( iStartItem + iMaxMenuItems, iNumItems );
}
if ( iStartItem > 0 )
{
// Draw ... Scroll Up ...
DWORD dwColor = D3DCOLOR_ARGB( 255, 255, 255, 255 );
m_pGameEngine->BDrawString( g_hMenuFont, rect, dwColor, DT_CENTER|DT_VCENTER, "... Scroll Up ..." );
m_pGameEngine->BDrawString( g_hMenuFont, rect, dwColor, TEXTPOS_CENTER|TEXTPOS_VCENTER, "... Scroll Up ..." );
rect.top = rect.bottom;
rect.bottom += MENU_FONT_HEIGHT + MENU_ITEM_PADDING;
@@ -198,7 +201,7 @@ public:
dwColor = D3DCOLOR_ARGB( 255, 255, 255, 255 );
_snprintf( rgchBuffer, sizeof( rgchBuffer), "%s", m_VecMenuItems[i].first.c_str() );
}
m_pGameEngine->BDrawString( g_hMenuFont, rect, dwColor, DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( g_hMenuFont, rect, dwColor, TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
}
rect.top = rect.bottom;
@@ -209,7 +212,7 @@ public:
{
// Draw ... Scroll Down ...
DWORD dwColor = D3DCOLOR_ARGB( 255, 255, 255, 255 );
m_pGameEngine->BDrawString( g_hMenuFont, rect, dwColor, DT_CENTER|DT_VCENTER, "... Scroll Down ..." );
m_pGameEngine->BDrawString( g_hMenuFont, rect, dwColor, TEXTPOS_CENTER|TEXTPOS_VCENTER, "... Scroll Down ..." );
rect.top = rect.bottom;
rect.bottom += MENU_FONT_HEIGHT + MENU_ITEM_PADDING;
@@ -218,7 +221,7 @@ public:
private:
// Game engine instance
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Heading
std::string m_sHeading;
+49 -268
View File
@@ -11,62 +11,6 @@
#include <set>
#include <map>
// How big is the vertex buffer for batching lines in total?
// NOTE: This must be a multiple of the batch size below!!! (crashes will occur if it isn't)
#define LINE_BUFFER_TOTAL_SIZE 1000
// How many lines do we put in the buffer in between flushes?
//
// This should be enough smaller than the total size so that draw calls
// can finish using the data before we wrap around and discard it.
#define LINE_BUFFER_BATCH_SIZE 250
// How big is the vertex buffer for batching points in total?
// NOTE: This must be a multiple of the batch size below!!! (crashes will occur if it isn't)
#define POINT_BUFFER_TOTAL_SIZE 1800
// How many points do we put in the buffer in between flushes?
//
// This should be enough smaller than the total size so that draw calls
// can finish using the data before we wrap around and discard it.
#define POINT_BUFFER_BATCH_SIZE 600
// How big is the vertex buffer for batching quads in total?
// NOTE: This must be a multiple of the batch size below!!! (crashes will occur if it isn't)
#define QUAD_BUFFER_TOTAL_SIZE 1000
// How many quads do we put in the buffer in between flushes?
//
// This should be enough smaller than the total size so that draw calls
// can finish using the data before we wrap around and discard it.
#define QUAD_BUFFER_BATCH_SIZE 250
// Vertex struct for line batches
struct LineVertex_t
{
float x, y, z, rhw;
DWORD color;
};
// Vertex struct for point batches
struct PointVertex_t
{
float x, y, z, rhw;
DWORD color;
};
// Vertex struct for textured quads
struct TexturedQuadVertex_t
{
float x, y, z, rhw;
DWORD color;
float u, v; // texture coordinates
};
// WndProc declaration
LRESULT CALLBACK GameWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
// Typedef for font handles
typedef int HGAMEFONT;
@@ -76,269 +20,106 @@ typedef int HGAMEVERTBUF;
// Typedef for texture handles
typedef int HGAMETEXTURE;
class CGameEngine
// BDrawText position flags
#define TEXTPOS_TOP 0x00000000
#define TEXTPOS_LEFT 0x00000000
#define TEXTPOS_CENTER 0x00000001
#define TEXTPOS_RIGHT 0x00000002
#define TEXTPOS_VCENTER 0x00000004
#define TEXTPOS_BOTTOM 0x00000008
//
// Interface that needs to be implemented for game engines on all platforms
//
class IGameEngine
{
public:
// Static methods for tracing mapping of game engine class instances to hwnds
static CGameEngine * FindEngineInstanceForHWND( HWND hWnd );
static void AddInstanceToHWNDMap( CGameEngine* pInstance, HWND hWnd );
static void RemoveInstanceFromHWNDMap( HWND hWnd );
// Constructor
CGameEngine( HINSTANCE hInstance, int nShowCommand, int32 nWindowWidth, int32 nWindowHeight );
// Destructor
~CGameEngine() { Shutdown(); }
// Just here to stop warnings on non-virtual destructor in PS3 build
virtual ~IGameEngine() {};
// Check if the game engine is initialized ok and ready for use
bool BReadyForUse() { return m_bEngineReadyForUse; }
virtual bool BReadyForUse() = 0;
// Check if the engine is shutting down
bool BShuttingDown() { return m_bShuttingDown; }
virtual bool BShuttingDown() = 0;
// Set the background color
void SetBackgroundColor( short a, short r, short g, short b );
virtual void SetBackgroundColor( short a, short r, short g, short b ) = 0;
// Start a frame, clear(), beginscene(), etc
bool StartFrame();
virtual bool StartFrame() = 0;
// Finish a frame, endscene(), present(), etc.
void EndFrame();
virtual void EndFrame() = 0;
// Shutdown the game engine
void Shutdown();
virtual void Shutdown() = 0;
// Pump messages from the OS
void MessagePump();
virtual void MessagePump() = 0;
// Accessors for game screen size
int32 GetViewportWidth() { return m_nViewportWidth; }
int32 GetViewportHeight() { return m_nViewportHeight; }
virtual int32 GetViewportWidth() = 0;
virtual int32 GetViewportHeight() = 0;
// Function for drawing text to the screen, dwFormat is a combination of flags like DT_LEFT, DT_VCENTER etc...
bool BDrawString( HGAMEFONT hFont, RECT rect, DWORD dwColor, DWORD dwFormat, const char *pchText );
// Function for drawing text to the screen, dwFormat is a combination of flags like DT_LEFT, TEXTPOS_VCENTER etc...
virtual bool BDrawString( HGAMEFONT hFont, RECT rect, DWORD dwColor, DWORD dwFormat, const char *pchText ) = 0;
// Create a new font returning our internal handle value for it (0 means failure)
HGAMEFONT HCreateFont( int nHeight, int nFontWeight, bool bItalic, char * pchFont );
virtual HGAMEFONT HCreateFont( int nHeight, int nFontWeight, bool bItalic, char * pchFont ) = 0;
// Create a new texture returning our internal handle value for it (0 means failure)
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight );
virtual HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight ) = 0;
// 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 );
virtual bool BDrawLine( float xPos0, float yPos0, DWORD dwColor0, float xPos1, float yPos1, DWORD dwColor1 ) = 0;
// Flush the line buffer
bool BFlushLineBuffer();
virtual bool BFlushLineBuffer() = 0;
// Draw a point, the engine itself will manage batching these (although you can explicitly flush if you need to)
bool BDrawPoint( float xPos, float yPos, DWORD dwColor );
virtual bool BDrawPoint( float xPos, float yPos, DWORD dwColor ) = 0;
// Flush the point buffer
bool BFlushPointBuffer();
virtual bool BFlushPointBuffer() = 0;
// Draw a filled quad
bool BDrawFilledQuad( float xPos0, float yPos0, float xPos1, float yPos1, DWORD dwColor );
virtual bool BDrawFilledQuad( float xPos0, float yPos0, float xPos1, float yPos1, DWORD dwColor ) = 0;
// Draw a textured rectangle
bool BDrawTexturedQuad( float xPos0, float yPos0, float xPos1, float yPos1,
float u0, float v0, float u1, float v1, DWORD dwColor, HGAMETEXTURE hTexture );
virtual bool BDrawTexturedQuad( float xPos0, float yPos0, float xPos1, float yPos1,
float u0, float v0, float u1, float v1, DWORD dwColor, HGAMETEXTURE hTexture ) = 0;
// Flush any still cached quad buffers
bool BFlushQuadBuffer();
// Track the state of keyboard input
void RecordKeyDown( DWORD dwVK );
void RecordKeyUp( DWORD dwVK );
virtual bool BFlushQuadBuffer() = 0;
// Get the current state of a key
bool BIsKeyDown( DWORD dwVK );
virtual bool BIsKeyDown( DWORD dwVK ) = 0;
// Get the first (in some arbitrary order) key down, if any
bool BGetFirstKeyDown( DWORD *pdwVK );
virtual bool BGetFirstKeyDown( DWORD *pdwVK ) = 0;
// Get current tick count for the game engine
uint64 GetGameTickCount() { return m_ulGameTickCount; }
virtual uint64 GetGameTickCount() = 0;
// Tell the game engine to update current tick count
virtual void UpdateGameTickCount() = 0;
// Tell the game engine to sleep for a bit if needed to limit frame rate. Returns
// true if you need to keep calling it to sleep more to reach your limit, returns
// false when you should proceed to the next frame.
virtual bool BSleepForFrameRateLimit( uint32 ulMaxFrameRate ) = 0;
// Get the tick count elapsed since the previous frame
// bugbug - We use this time to compute things like thrust and acceleration in the game,
// so it's important in doesn't jump ahead by large increments... Need a better
// way to handle that.
uint64 GetGameTicksFrameDelta() { return m_ulGameTickCount - m_ulPreviousGameTickCount; }
void SetGameTickCount( uint64 ulGameTickCount ) { m_ulPreviousGameTickCount = m_ulGameTickCount; m_ulGameTickCount = ulGameTickCount; }
// Get the game engines hwnd
HWND GetGameHWND() { return m_hWnd; }
virtual uint64 GetGameTicksFrameDelta() = 0;
// Check if the game engine hwnd currently has focus (and a working d3d device)
bool BGameEngineHasFocus() { return ::GetForegroundWindow() == m_hWnd && !m_bDeviceLost; }
// Set the max FPS for the engine to run at (will sleep in EndFrame() to limit the rate)
void SetMaxFPS( float flMaxFPS ) { m_flMaxFPS = flMaxFPS; }
private:
// Creates the hwnd for the game
bool BCreateGameWindow( int nShowCommand );
// Initializes D3D for the game
bool BInitializeD3D9();
// Resets all the render, texture, and sampler states to our defaults
void ResetRenderStates();
// Create a new vertex buffer returning our internal handle for it (0 means failure)
HGAMEVERTBUF HCreateVertexBuffer( uint32 nSizeInBytes, DWORD dwUsage, DWORD dwFVF );
// Lock an entire vertex buffer with the specified flags
bool BLockEntireVertexBuffer( HGAMEVERTBUF hVertBuf, void **ppVoid, DWORD dwFlags );
// Unlock a vertex buffer
bool BUnlockVertexBuffer( HGAMEVERTBUF hVertBuf );
// Release a vertex buffer and free its resources
bool BReleaseVertexBuffer( HGAMEVERTBUF hVertBuf );
// Set steam source
bool BSetStreamSource( HGAMEVERTBUF hVertBuf, uint32 uOffset, uint32 uStride );
// Render primitives out of the current stream source
bool BRenderPrimitive( D3DPRIMITIVETYPE primType, uint32 uStartVertex, uint32 uCount );
// Set vertex format
bool BSetFVF( DWORD dwFormat );
// Handle losing the d3d device (ie, release resources)
bool BHandleLostDevice();
// Handle reseting the d3d device (ie, acquire resources again)
bool BHandleResetDevice();
private:
// Tracks whether the engine is ready for use
bool m_bEngineReadyForUse;
// Tracks if we are shutting down
bool m_bShuttingDown;
// Color we clear the background of the window to each frame
DWORD m_dwBackgroundColor;
// HInstance for the application running the engine
HINSTANCE m_hInstance;
// HWND for the engine instance
HWND m_hWnd;
// IDirect3D9 interface
IDirect3D9 *m_pD3D9Interface;
// IDirect3DDevice9 interface
IDirect3DDevice9 *m_pD3D9Device;
// Size of the window to display the game in
int32 m_nWindowWidth;
int32 m_nWindowHeight;
// Size of actual d3d viewport (window size minus borders, title, etc)
int32 m_nViewportWidth;
int32 m_nViewportHeight;
// Next font handle value to give out
HGAMEFONT m_nNextFontHandle;
// Map of font handles to font objects
std::map<HGAMEFONT, ID3DXFont *> m_MapFontInstances;
// Next vertex buffer handle value to give out
HGAMEVERTBUF m_nNextVertBufferHandle;
// Map of handles to vertex buffer objects
struct VertBufData_t
{
bool m_bIsLocked;
IDirect3DVertexBuffer9 * m_pBuffer;
};
std::map<HGAMEVERTBUF, VertBufData_t> m_MapVertexBuffers;
HGAMETEXTURE m_nNextTextureHandle;
// Map of handles to texture objects
struct TextureData_t
{
byte *m_pRGBAData; // We keep a copy of the raw data so we can rebuild textures after a device is lost
uint32 m_uWidth;
uint32 m_uHeight;
LPDIRECT3DTEXTURE9 m_pTexture;
};
std::map<HGAMETEXTURE, TextureData_t> m_MapTextures;
// Vertex buffer for textured quads
HGAMEVERTBUF m_hQuadBuffer;
// Last texture used in drawing a batched quad
HGAMETEXTURE m_hLastTexture;
// Pointer to quad vertex data
TexturedQuadVertex_t *m_pQuadVertexes;
// How many quads are awaiting flushing
DWORD m_dwQuadsToFlush;
// Where does the current batch begin
DWORD m_dwQuadBufferBatchPos;
// White texture used when drawing filled quads
HGAMETEXTURE m_hTextureWhite;
// Currently set FVF format
DWORD m_dwCurrentFVF;
// Map of key state
std::set<DWORD> m_SetKeysDown;
// Current game time in milliseconds
uint64 m_ulGameTickCount;
// Game time at the start of the previous frame
uint64 m_ulPreviousGameTickCount;
// Maximum FPS to run the engine at
float m_flMaxFPS;
// Map of engine instances by HWND, used in wndproc to find engine instance for messages
static std::map<HWND, CGameEngine *> m_MapEngineInstances;
// Internal vertex buffer for batching line drawing
HGAMEVERTBUF m_hLineBuffer;
// Pointer to actual line buffer memory (valid only while locked)
LineVertex_t *m_pLineVertexes;
// Track how many lines are awaiting flushing in our line buffer
DWORD m_dwLinesToFlush;
// Track where the current batch starts in the vert buffer
DWORD m_dwLineBufferBatchPos;
// Internal vertex buffer for batching point drawing
HGAMEVERTBUF m_hPointBuffer;
// Pointer to actual point buffer memory (valid only while locked)
PointVertex_t *m_pPointVertexes;
// Track how many points are awaiting flushing in our line buffer
DWORD m_dwPointsToFlush;
// Track where the current batch starts in the vert buffer
DWORD m_dwPointBufferBatchPos;
// Track if we have lost the d3d device
bool m_bDeviceLost;
// Presentation parameters, saved in case of lost device needing reset
D3DPRESENT_PARAMETERS m_d3dpp;
virtual bool BGameEngineHasFocus() = 0;
};
+6 -7
View File
@@ -7,7 +7,6 @@
#include "stdafx.h"
#include "leaderboards.h"
#include <math.h>
#include "steam/isteamuserstats.h"
//-----------------------------------------------------------------------------
// Purpose: Menu that shows a leaderboard
@@ -30,7 +29,7 @@ public:
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CLeaderboardMenu( CGameEngine *pGameEngine ) : CBaseMenu<LeaderboardMenuItem_t>( pGameEngine )
CLeaderboardMenu( IGameEngine *pGameEngine ) : CBaseMenu<LeaderboardMenuItem_t>( pGameEngine )
{
m_hSteamLeaderboard = 0;
m_nLeaderboardEntries = 0;
@@ -69,9 +68,9 @@ public:
PushSelectedItem();
ClearMenuItems();
LeaderboardMenuItem_t menuItemEmpty = { 0 };
LeaderboardMenuItem_t menuItemBack = { true, false };
LeaderboardMenuItem_t menuItemNextLeaderboard = { false, true };
LeaderboardMenuItem_t menuItemEmpty = { 0 };
if ( m_hSteamLeaderboard )
{
@@ -147,7 +146,7 @@ public:
m_bIOFailure = bIOFailure;
// leaderboard entries handle will be invalid once we return from this function. Copy all data now.
m_nLeaderboardEntries = min( pLeaderboardScoresDownloaded->m_cEntryCount, k_nMaxLeaderboardEntries );
m_nLeaderboardEntries = MIN( pLeaderboardScoresDownloaded->m_cEntryCount, k_nMaxLeaderboardEntries );
for ( int index = 0; index < m_nLeaderboardEntries; index++ )
{
SteamUserStats()->GetDownloadedLeaderboardEntry( pLeaderboardScoresDownloaded->m_hSteamLeaderboardEntries,
@@ -165,14 +164,14 @@ public:
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CLeaderboards::CLeaderboards( CGameEngine *pGameEngine ) : m_pGameEngine( pGameEngine )
CLeaderboards::CLeaderboards( IGameEngine *pGameEngine ) : m_pGameEngine( pGameEngine )
{
m_hQuickestWinLeaderboard = 0;
m_hFeetTraveledLeaderboard = 0;
m_nCurrentLeaderboard = 0;
m_pLeaderboardMenu = new CLeaderboardMenu( pGameEngine );
m_bLoading = false;
m_pLeaderboardMenu = new CLeaderboardMenu( pGameEngine );
FindLeaderboards();
}
@@ -318,4 +317,4 @@ void CLeaderboards::OnUploadScore( LeaderboardScoreUploaded_t *pScoreUploadedRes
{
// could display new rank
}
}
}
+3 -3
View File
@@ -9,7 +9,6 @@
#include "SpaceWar.h"
#include "GameEngine.h"
#include "steam/isteamuserstats.h"
#include "StatsAndAchievements.h"
#include "SpaceWarClient.h"
@@ -22,7 +21,7 @@ class CLeaderboards
{
public:
// Constructor
CLeaderboards( CGameEngine *pGameEngine );
CLeaderboards( IGameEngine *pGameEngine );
// Run a frame
void RunFrame();
@@ -40,7 +39,7 @@ private:
void FindLeaderboards();
// Engine
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Called when SteamUserStats()->FindOrCreateLeaderboard() returns asynchronously
void OnFindLeaderboard( LeaderboardFindResult_t *pFindLearderboardResult, bool bIOFailure );
@@ -53,6 +52,7 @@ private:
// handles to our leaderboards
SteamLeaderboard_t m_hQuickestWinLeaderboard;
SteamLeaderboard_t m_hFeetTraveledLeaderboard;
int m_bLoading; // true if we looking up a leaderboard handle
+27 -11
View File
@@ -18,7 +18,7 @@ class CLobbyMenu : public CBaseMenu<LobbyMenuItem_t>
{
public:
// Constructor
CLobbyMenu( CGameEngine *pGameEngine ) : CBaseMenu<LobbyMenuItem_t>( pGameEngine ) {}
CLobbyMenu( IGameEngine *pGameEngine ) : CBaseMenu<LobbyMenuItem_t>( pGameEngine ) {}
void Rebuild( const CSteamID &steamIDLobby )
{
@@ -44,7 +44,8 @@ public:
// a PersonaStateUpdate_t callback when they do, and we'll rebuild the list then
if ( pchName && *pchName )
{
bool bReady = ( 1 == atoi( SteamMatchmaking()->GetLobbyMemberData( steamIDLobby, steamIDLobbyMember, "ready" ) ) );
const char *pchReady = SteamMatchmaking()->GetLobbyMemberData( steamIDLobby, steamIDLobbyMember, "ready" );
bool bReady = ( pchReady && atoi( pchReady ) == 1);
LobbyMenuItem_t menuItem = { steamIDLobbyMember, LobbyMenuItem_t::k_ELobbyMenuItemUser };
char rgchMenuText[256];
@@ -56,7 +57,8 @@ public:
// ready/not ready toggle
{
bool bReady = ( 1 == atoi( SteamMatchmaking()->GetLobbyMemberData( steamIDLobby, SteamUser()->GetSteamID(), "ready" ) ) );
const char *pchReady = SteamMatchmaking()->GetLobbyMemberData( steamIDLobby, SteamUser()->GetSteamID(), "ready" );
bool bReady = ( pchReady && atoi( pchReady ) == 1 );
LobbyMenuItem_t menuItem = { CSteamID(), LobbyMenuItem_t::k_ELobbyMenuItemToggleReadState };
if ( bReady )
AddMenuItem( CLobbyMenu::MenuItem_t( "Set myself as Not Ready", menuItem ) );
@@ -100,8 +102,8 @@ public:
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CLobby::CLobby( CGameEngine *pGameEngine ) :
m_pGameEngine( pGameEngine ),
CLobby::CLobby( IGameEngine *pGameEngine ) :
m_pGameEngine( pGameEngine ),
m_CallbackPersonaStateChange( this, &CLobby::OnPersonaStateChange ),
m_CallbackLobbyDataUpdate( this, &CLobby::OnLobbyDataUpdate ),
m_CallbackChatDataUpdate( this, &CLobby::OnLobbyChatUpdate )
@@ -204,7 +206,22 @@ class CLobbyBrowserMenu : public CBaseMenu<LobbyBrowserMenuItem_t>
{
public:
// Constructor
CLobbyBrowserMenu( CGameEngine *pGameEngine ) : CBaseMenu<LobbyBrowserMenuItem_t>( pGameEngine ) {}
CLobbyBrowserMenu( IGameEngine *pGameEngine ) : CBaseMenu<LobbyBrowserMenuItem_t>( pGameEngine ) {}
void ShowSearching()
{
PushSelectedItem();
ClearMenuItems();
LobbyBrowserMenuItem_t data;
data.m_eStateToTransitionTo = k_EClientGameMenu;
AddMenuItem( CLobbyBrowserMenu::MenuItem_t( "Searching...", data ) );
data.m_eStateToTransitionTo = k_EClientGameMenu;
AddMenuItem( CLobbyBrowserMenu::MenuItem_t( "Return to main menu", data ) );
PopSelectedItem();
}
void Rebuild( std::list<Lobby_t> &listLobbies )
{
@@ -237,16 +254,14 @@ public:
// Purpose: Constructor
// just initializes base data
//-----------------------------------------------------------------------------
CLobbyBrowser::CLobbyBrowser( CGameEngine *pGameEngine ) :
m_CallbackLobbyDataUpdated( this, &CLobbyBrowser::OnLobbyDataUpdatedCallback )
CLobbyBrowser::CLobbyBrowser( IGameEngine *pGameEngine )
: m_CallbackLobbyDataUpdated( this, &CLobbyBrowser::OnLobbyDataUpdatedCallback )
{
m_pGameEngine = pGameEngine;
m_pMenu = new CLobbyBrowserMenu( pGameEngine );
m_pMenu->Rebuild( m_ListLobbies );
m_pMenu->SetHeading( "Lobby browser" );
m_bRequestingLobbies = false;
Refresh();
}
@@ -280,6 +295,7 @@ void CLobbyBrowser::Refresh()
SteamAPICall_t hSteamAPICall = SteamMatchmaking()->RequestLobbyList();
// set the function to call when this API call has completed
m_SteamCallResultLobbyMatchList.Set( hSteamAPICall, this, &CLobbyBrowser::OnLobbyMatchListCallback );
m_pMenu->ShowSearching();
}
}
@@ -351,4 +367,4 @@ void CLobbyBrowser::OnLobbyDataUpdatedCallback( LobbyDataUpdate_t *pCallback )
return;
}
}
}
}
+4 -5
View File
@@ -10,7 +10,6 @@
#include "SpaceWar.h"
#include "GameEngine.h"
#include "steam/isteammatchmaking.h"
#include "BaseMenu.h"
#include <list>
@@ -25,7 +24,7 @@ class CLobbyMenu;
class CLobby
{
public:
CLobby( CGameEngine *pGameEngine );
CLobby( IGameEngine *pGameEngine );
~CLobby();
// sets which lobby to display
@@ -38,7 +37,7 @@ private:
CSteamID m_steamIDLobby;
// Pointer to engine instance (so we can draw stuff)
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Menu object
CLobbyMenu *m_pMenu;
@@ -66,7 +65,7 @@ struct Lobby_t
class CLobbyBrowser
{
public:
CLobbyBrowser( CGameEngine *pGameEngine );
CLobbyBrowser( IGameEngine *pGameEngine );
~CLobbyBrowser();
// rebuild the list
@@ -77,7 +76,7 @@ public:
private:
// Pointer to engine instance (so we can draw stuff)
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Track whether we are in the middle of a refresh or not
bool m_bRequestingLobbies;
+235 -112
View File
@@ -5,15 +5,21 @@
//=============================================================================
#include "stdafx.h"
#include "GameEngine.h"
#ifdef WIN32
#include "gameenginewin32.h"
#elif _PS3
#include "gameengineps3.h"
#endif
#include "SpaceWarClient.h"
#include "steam/steam_api.h"
//-----------------------------------------------------------------------------
// Purpose: Wrapper around SteamAPI_WriteMiniDump which can be used directly
// as a se translator
//-----------------------------------------------------------------------------
#ifndef _PS3
void MiniDumpFunction( unsigned int nExceptionCode, EXCEPTION_POINTERS *pException )
{
// You can build and set an arbitrary comment to embed in the minidump here,
@@ -24,6 +30,7 @@ void MiniDumpFunction( unsigned int nExceptionCode, EXCEPTION_POINTERS *pExcepti
// The 0 here is a build ID, we don't set it
SteamAPI_WriteMiniDump( nExceptionCode, pException, 0 );
}
#endif
//-----------------------------------------------------------------------------
@@ -39,16 +46,93 @@ extern "C" void __cdecl SteamAPIDebugTextHook( int nSeverity, const char *pchDeb
{
// place to set a breakpoint for catching API errors
int x = 3;
x;
x = x;
}
}
//-----------------------------------------------------------------------------
// Purpose: Main loop code shared between all platforms
//-----------------------------------------------------------------------------
void RunGameLoop( IGameEngine *pGameEngine, char *pchServerAddress, char *pchLobbyID )
{
// Make sure it initialized ok
if ( pGameEngine->BReadyForUse() )
{
// Initialize the game
CSpaceWarClient *pGameClient = new CSpaceWarClient( pGameEngine, SteamUser()->GetSteamID() );
// Black background
pGameEngine->SetBackgroundColor( 0, 0, 0, 0 );
// If +connect was used to specify a server address, connect now
if ( pchServerAddress )
{
int32 octet0 = 0, octet1 = 0, octet2 = 0, octet3 = 0;
int32 uPort = 0;
int nConverted = sscanf( pchServerAddress, "%d.%d.%d.%d:%d", &octet0, &octet1, &octet2, &octet3, &uPort );
if ( nConverted == 5 )
{
char rgchIPAddress[128];
_snprintf( rgchIPAddress, ARRAYSIZE( rgchIPAddress ), "%d.%d.%d.%d", octet0, octet1, octet2, octet3 );
uint32 unIPAddress = ( octet3 ) + ( octet2 << 8 ) + ( octet1 << 16 ) + ( octet0 << 24 );
pGameClient->InitiateServerConnection( unIPAddress, uPort );
}
}
// if +connect_lobby was used to specify a lobby to join, connect now
if ( pchLobbyID )
{
#ifndef _PS3
CSteamID steamIDLobby( (uint64)_atoi64( pchLobbyID ) );
#else
CSteamID steamIDLobby( (uint64)atoll( pchLobbyID ) );
#endif
if ( steamIDLobby.IsValid() )
{
// act just like we had selected it from the menu
LobbyBrowserMenuItem_t menuItem = { steamIDLobby, k_EClientJoiningLobby };
pGameClient->OnMenuSelection( menuItem );
}
}
// test a user specific secret before entering main loop
#ifndef _PS3
Steamworks_TestSecret();
#endif
pGameClient->RetrieveEncryptedAppTicket();
while( !pGameEngine->BShuttingDown() )
{
if ( pGameEngine->StartFrame() )
{
pGameEngine->UpdateGameTickCount();
// Run a game frame
pGameClient->RunFrame();
pGameEngine->EndFrame();
// Sleep to limit frame rate
while( pGameEngine->BSleepForFrameRateLimit( MAX_CLIENT_AND_SERVER_FPS ) )
{
// Keep running the network on the client at a faster rate than the FPS limit
pGameClient->ReceiveNetworkData();
}
}
}
delete pGameClient;
}
// Cleanup the game engine
delete pGameEngine;
}
//-----------------------------------------------------------------------------
// Purpose: Real main entry point for the program
//-----------------------------------------------------------------------------
#ifdef WIN32
int APIENTRY RealMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
@@ -128,114 +212,10 @@ int APIENTRY RealMain(HINSTANCE hInstance,
// Construct a new instance of the game engine
// bugbug jmccaskey - make screen resolution dynamic, maybe take it on command line?
CGameEngine *pGameEngine = new CGameEngine( hInstance, nCmdShow, 1024, 768 );
CGameEngineWin32 *pGameEngine = new CGameEngineWin32( hInstance, nCmdShow, 1024, 768 );
// Make sure it initialized ok
if ( pGameEngine->BReadyForUse() )
{
// Initialize the game
CSpaceWarClient *pGameClient = new CSpaceWarClient( pGameEngine, SteamUser()->GetSteamID() );
// Black background
pGameEngine->SetBackgroundColor( 0, 0, 0, 0 );
// Set max FPS
pGameEngine->SetMaxFPS( MAX_CLIENT_AND_SERVER_FPS );
// If +connect was used to specify a server address, connect now
if ( pchServerAddress )
{
int32 octet0 = 0, octet1 = 0, octet2 = 0, octet3 = 0;
int32 uPort = 0;
int nConverted = sscanf( pchServerAddress, "%d.%d.%d.%d:%d", &octet0, &octet1, &octet2, &octet3, &uPort );
if ( nConverted == 5 )
{
char rgchIPAddress[128];
_snprintf( rgchIPAddress, ARRAYSIZE( rgchIPAddress ), "%d.%d.%d.%d", octet0, octet1, octet2, octet3 );
uint32 unIPAddress = ( octet3 ) + ( octet2 << 8 ) + ( octet1 << 16 ) + ( octet0 << 24 );
pGameClient->InitiateServerConnection( unIPAddress, uPort );
}
}
// if +connect_lobby was used to specify a lobby to join, connect now
if ( pchLobbyID )
{
CSteamID steamIDLobby( (uint64)_atoi64( pchLobbyID ) );
if ( steamIDLobby.IsValid() )
{
// act just like we had selected it from the menu
LobbyBrowserMenuItem_t menuItem = { steamIDLobby, k_EClientJoiningLobby };
pGameClient->OnMenuSelection( menuItem );
}
}
// test a user specific secret before entering main loop
Steamworks_TestSecret();
static const int m_flMaxFPS = 120;
// restrict this main game thread to the first processor, so queryperformance counter won't jump on crappy AMD cpus
DWORD dwThreadAffinityMask = 0x01;
::SetThreadAffinityMask( ::GetCurrentThread(), dwThreadAffinityMask );
uint64 ulPerfCounterToMillisecondsDivisor;
LARGE_INTEGER l;
::QueryPerformanceFrequency( &l );
ulPerfCounterToMillisecondsDivisor = l.QuadPart/1000;
::QueryPerformanceCounter( &l );
uint64 ulFirstQueryPerformanceCounterValue = l.QuadPart;
uint64 ulGameTickCount = 0;
while( !pGameEngine->BShuttingDown() )
{
if ( pGameEngine->StartFrame() )
{
// update timers
::QueryPerformanceCounter( &l );
ulGameTickCount = (l.QuadPart - ulFirstQueryPerformanceCounterValue) / ulPerfCounterToMillisecondsDivisor;
pGameEngine->SetGameTickCount( ulGameTickCount );
// Run a game frame
pGameClient->RunFrame();
pGameEngine->EndFrame();
// Frame rate limiting
float flDesiredFrameMilliseconds = 1000.0f/m_flMaxFPS;
while( 1 )
{
::QueryPerformanceCounter( &l );
ulGameTickCount = (l.QuadPart - ulFirstQueryPerformanceCounterValue) / ulPerfCounterToMillisecondsDivisor;
float flMillisecondsElapsed = (float)(ulGameTickCount - pGameEngine->GetGameTickCount());
if ( flMillisecondsElapsed < flDesiredFrameMilliseconds )
{
// run networking each frame first
pGameClient->ReceiveNetworkData();
// If enough time is left sleep, otherwise just keep spinning so we don't go over the limit...
if ( flDesiredFrameMilliseconds - flMillisecondsElapsed > 2.0f )
{
Sleep( 2 );
}
else
{
continue;
}
}
else
break;
}
}
}
delete pGameClient;
}
// Cleanup the game engine
delete pGameEngine;
// This call will block and run until the game exits
RunGameLoop( pGameEngine, pchServerAddress, pchLobbyID );
// Shutdown the SteamAPI
SteamAPI_Shutdown();
@@ -246,11 +226,12 @@ int APIENTRY RealMain(HINSTANCE hInstance,
// exit
return EXIT_SUCCESS;
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Main entry point for the program
// Purpose: Main entry point for the program -- win32
//-----------------------------------------------------------------------------
#ifdef WIN32
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
@@ -280,3 +261,145 @@ int APIENTRY WinMain(HINSTANCE hInstance,
return -1;
}
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Main entry point for the program -- ps3
//-----------------------------------------------------------------------------
#ifdef _PS3
//-----------------------------------------------------------------------------
// Purpose: Loads the Steam PS3 module
//-----------------------------------------------------------------------------
sys_prx_id_t g_sys_prx_id_steam = -1;
static bool LoadSteamPS3Module()
{
g_sys_prx_id_steam = sys_prx_load_module( SYS_APP_HOME "/steam_api_ps3.sprx", 0, NULL );
if ( g_sys_prx_id_steam < CELL_OK )
{
OutputDebugString( "LoadSteamModule() - failed to load steam_api_ps3\n" );
return false;
}
int modres;
int res = sys_prx_start_module( g_sys_prx_id_steam, 0, NULL, &modres, 0, NULL);
if ( res < CELL_OK )
{
OutputDebugString( "LoadSteamModule() - failed to start steam_api_ps3\n" );
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Unloads the Steam PS3 module
//-----------------------------------------------------------------------------
static bool UnloadSteamPS3Module()
{
// check if loaded
if ( g_sys_prx_id_steam < CELL_OK )
return false;
int modres;
int res = sys_prx_stop_module( g_sys_prx_id_steam, 0, NULL, &modres, 0, NULL);
if ( res < CELL_OK )
{
OutputDebugString( "LoadSteamModule() - failed to stop steam_api_ps3\n" );
return false;
}
res = sys_prx_unload_module( g_sys_prx_id_steam, 0, NULL );
if ( res < CELL_OK )
{
OutputDebugString( "LoadSteamModule() - failed to unload steam_api_ps3\n" );
return false;
}
g_sys_prx_id_steam = -1;
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Initializes Steam PS3 params for our application
//-----------------------------------------------------------------------------
bool SetSteamPS3Params( SteamPS3Params_t *pParams )
{
// Steam needs the system cache path
CellSysCacheParam sysCacheParams;
memset( &sysCacheParams, 0, sizeof( CellSysCacheParam ) );
if ( cellSysCacheMount( &sysCacheParams ) < 0 )
return false;
// configure the Steamworks PS3 parameters. All params need to be set
strncpy( pParams->m_rgchInstallationPath, SYS_APP_HOME, STEAM_PS3_PATH_MAX );
strncpy( pParams->m_rgchSystemCache, sysCacheParams.getCachePath, STEAM_PS3_PATH_MAX );
return true;
}
// Global for PS3 params
SteamPS3Params_t g_SteamPS3Params;
//-----------------------------------------------------------------------------
// Purpose: Main entry point for the program -- ps3
//-----------------------------------------------------------------------------
int main( int argc, char *argv[] )
{
printf( "PS3 main\n" );
// Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL
sys_spu_initialize(6, 1);
// Load Steam
if ( !LoadSteamPS3Module() )
return EXIT_FAILURE;
// No restart app if necessary, or CEG initialization on PS3
// Initialize SteamAPI, if this fails we bail out since we depend on Steam for lots of stuff.
// You don't necessarily have to though if you write your code to check whether all the Steam
// interfaces are NULL before using them and provide alternate paths when they are unavailable.
if ( !SetSteamPS3Params( &g_SteamPS3Params ) )
{
OutputDebugString( "SetSteamPS3Params() failed\n" );
return EXIT_FAILURE;
}
if ( !SteamAPI_Init( &g_SteamPS3Params ) )
{
OutputDebugString( "SteamAPI_Init() failed\n" );
return EXIT_FAILURE;
}
// set our debug handler
SteamClient()->SetWarningMessageHook( &SteamAPIDebugTextHook );
// bugbug ps3
SteamUser()->LogOn( "jmccaskeybeta", "test123" );
// No overlay notification position setting on PS3
// No +connect support on PS3 since Steam isn't launching us
// Construct a new instance of the game engine
// bugbug jmccaskey - make screen resolution dynamic, maybe take it on command line?
CGameEnginePS3 *pGameEngine = new CGameEnginePS3();
// This call will block and run until the game exits
RunGameLoop( pGameEngine, NULL, NULL );
// Shutdown the SteamAPI
SteamAPI_Shutdown();
// Unload Steam
UnloadSteamPS3Module();
// exit
return 0;
}
#endif
+1 -1
View File
@@ -13,7 +13,7 @@
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CMainMenu::CMainMenu( CGameEngine *pGameEngine ) : CBaseMenu<EClientGameState>( pGameEngine )
CMainMenu::CMainMenu( IGameEngine *pGameEngine ) : CBaseMenu<EClientGameState>( pGameEngine )
{
AddMenuItem( MenuItem_t( "Start New Server", k_EClientGameStartServer ) );
AddMenuItem( MenuItem_t( "Find LAN Servers", k_EClientFindLANServers ) );
+1 -1
View File
@@ -19,7 +19,7 @@ class CMainMenu : public CBaseMenu<EClientGameState>
{
public:
// Constructor
CMainMenu( CGameEngine *pGameEngine );
CMainMenu( IGameEngine *pGameEngine );
};
#endif // MAINMENU_H
+82 -19
View File
@@ -10,8 +10,7 @@
#include <map>
// Would normally set this to 1 byte, however we use 8 byte to support older clients that didn't specify packing
#pragma pack( push, 8 )
#pragma pack( push, 1 )
// Network message types
enum EMessage
@@ -47,9 +46,20 @@ enum EMessage
// and tells the client what SteamID the game server is using as well as whether the server is secure
struct MsgServerSendInfo_t
{
MsgServerSendInfo_t() : m_dwMessageType( k_EMsgServerSendInfo ) {}
const DWORD m_dwMessageType;
MsgServerSendInfo_t() : m_dwMessageType( LittleDWord( k_EMsgServerSendInfo ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
void SetSteamIDServer( uint64 SteamID ) { m_ulSteamIDServer = LittleQWord( SteamID ); }
uint64 GetSteamIDServer() { return LittleQWord( m_ulSteamIDServer ); }
void SetSecure( bool bSecure ) { m_bIsVACSecure = bSecure; }
bool GetSecure() { return m_bIsVACSecure; }
void SetServerName( const char *pchName ) { strncpy( m_rgchServerName, pchName, sizeof( m_rgchServerName ) ); }
const char *GetServerName() { return m_rgchServerName; }
private:
const DWORD m_dwMessageType;
uint64 m_ulSteamIDServer;
bool m_bIsVACSecure;
char m_rgchServerName[128];
@@ -58,66 +68,102 @@ struct MsgServerSendInfo_t
// Msg from the server to the client when refusing a connection
struct MsgServerFailAuthentication_t
{
MsgServerFailAuthentication_t() : m_dwMessageType( k_EMsgServerFailAuthentication ) {}
MsgServerFailAuthentication_t() : m_dwMessageType( LittleDWord( k_EMsgServerFailAuthentication ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
private:
const DWORD m_dwMessageType;
};
// Msg from the server to client when accepting a pending connection
struct MsgServerPassAuthentication_t
{
MsgServerPassAuthentication_t() : m_dwMessageType( k_EMsgServerPassAuthentication ) {}
const DWORD m_dwMessageType;
MsgServerPassAuthentication_t() : m_dwMessageType( LittleDWord( k_EMsgServerPassAuthentication ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
void SetPlayerPosition ( uint32 pos ) { m_uPlayerPosition = LittleDWord( pos ); }
uint32 GetPlayerPosition() { return LittleDWord( m_uPlayerPosition ); }
private:
const DWORD m_dwMessageType;
uint32 m_uPlayerPosition;
};
// Msg from the server to clients when updating the world state
struct MsgServerUpdateWorld_t
{
MsgServerUpdateWorld_t() : m_dwMessageType( k_EMsgServerUpdateWorld ) {}
const DWORD m_dwMessageType;
MsgServerUpdateWorld_t() : m_dwMessageType( LittleDWord( k_EMsgServerUpdateWorld ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
ServerSpaceWarUpdateData_t *AccessUpdateData() { return &m_ServerUpdateData; }
private:
const DWORD m_dwMessageType;
ServerSpaceWarUpdateData_t m_ServerUpdateData;
};
// Msg from server to clients when it is exiting
struct MsgServerExiting_t
{
MsgServerExiting_t() : m_dwMessageType( k_EMsgServerExiting ) {}
MsgServerExiting_t() : m_dwMessageType( LittleDWord( k_EMsgServerExiting ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
private:
const DWORD m_dwMessageType;
};
// Msg from server to clients when it is exiting
struct MsgServerPingResponse_t
{
MsgServerPingResponse_t() : m_dwMessageType( k_EMsgServerPingResponse ) {}
MsgServerPingResponse_t() : m_dwMessageType( LittleDWord( k_EMsgServerPingResponse ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
private:
const DWORD m_dwMessageType;
};
// Msg from client to server when trying to connect
struct MsgClientInitiateConnection_t
{
MsgClientInitiateConnection_t() : m_dwMessageType( k_EMsgClientInitiateConnection ) {}
MsgClientInitiateConnection_t() : m_dwMessageType( LittleDWord( k_EMsgClientInitiateConnection ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
private:
const DWORD m_dwMessageType;
};
// Msg from client to server when initiating authentication
struct MsgClientBeginAuthentication_t
{
MsgClientBeginAuthentication_t() : m_dwMessageType( k_EMsgClientBeginAuthentication ) {}
MsgClientBeginAuthentication_t() : m_dwMessageType( LittleDWord( k_EMsgClientBeginAuthentication ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
void SetToken( const char *pchToken, uint32 unLen ) { m_uTokenLen = LittleDWord( unLen ); memcpy( m_rgchToken, pchToken, MIN( unLen, sizeof( m_rgchToken ) ) ); }
uint32 GetTokenLen() { return LittleDWord( m_uTokenLen ); }
const char *GetTokenPtr() { return m_rgchToken; }
void SetSteamID( uint64 ulSteamID ) { m_ulSteamID = LittleQWord( ulSteamID ); }
uint64 GetSteamID() { return LittleQWord( m_ulSteamID ); }
private:
const DWORD m_dwMessageType;
uint32 m_uTokenLen;
#ifdef USE_GS_AUTH_API
char m_rgchToken[1024];
#endif
CSteamID m_SteamID;
uint64 m_ulSteamID;
};
// Msg from client to server when sending state update
struct MsgClientSendLocalUpdate_t
{
MsgClientSendLocalUpdate_t() : m_dwMessageType( k_EMsgClientSendLocalUpdate ) {}
MsgClientSendLocalUpdate_t() : m_dwMessageType( LittleDWord( k_EMsgClientSendLocalUpdate ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
void SetShipPosition( uint32 uPos ) { m_uShipPosition = LittleDWord( uPos ); }
ClientSpaceWarUpdateData_t *AccessUpdateData() { return &m_ClientUpdateData; }
private:
const DWORD m_dwMessageType;
uint32 m_uShipPosition;
@@ -127,25 +173,42 @@ struct MsgClientSendLocalUpdate_t
// Msg from the client telling the server it is about to leave
struct MsgClientLeavingServer_t
{
MsgClientLeavingServer_t() : m_dwMessageType( k_EMsgClientLeavingServer ) {}
MsgClientLeavingServer_t() : m_dwMessageType( LittleDWord( k_EMsgClientLeavingServer ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
private:
const DWORD m_dwMessageType;
};
// server ping
struct MsgClientPing_t
{
MsgClientPing_t() : m_dwMessageType( k_EMsgClientPing ) {}
MsgClientPing_t() : m_dwMessageType( LittleDWord( k_EMsgClientPing ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
private:
const DWORD m_dwMessageType;
};
// Msg from client to server when trying to connect
struct MsgP2PSendingTicket_t
{
MsgP2PSendingTicket_t() : m_dwMessageType( k_EMsgP2PSendingTicket ) {}
MsgP2PSendingTicket_t() : m_dwMessageType( LittleDWord( k_EMsgP2PSendingTicket ) ) {}
DWORD GetMessageType() { return LittleDWord( m_dwMessageType ); }
void SetToken( const char *pchToken, uint32 unLen ) { m_uTokenLen = LittleDWord( unLen ); memcpy( m_rgchToken, pchToken, MIN( unLen, sizeof( m_rgchToken ) ) ); }
uint32 GetTokenLen() { return LittleDWord( m_uTokenLen ); }
const char *GetTokenPtr() { return m_rgchToken; }
void SetSteamID( uint64 ulSteamID ) { m_ulSteamID = LittleQWord( ulSteamID ); }
uint64 GetSteamID() { return LittleQWord( m_ulSteamID ); }
private:
const DWORD m_dwMessageType;
uint32 m_uTokenLen;
char m_rgchToken[1024];
CSteamID m_SteamID;
uint64 m_ulSteamID;
};
#pragma pack( pop )
+5 -5
View File
@@ -12,7 +12,7 @@
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CPhotonBeam::CPhotonBeam( CGameEngine *pGameEngine, float xPos, float yPos, DWORD dwBeamColor, float flInitialRotation, float flInitialXVelocity, float flInitialYVelocity )
CPhotonBeam::CPhotonBeam( IGameEngine *pGameEngine, float xPos, float yPos, DWORD dwBeamColor, float flInitialRotation, float flInitialXVelocity, float flInitialYVelocity )
: CSpaceWarEntity( pGameEngine, 3, true )
{
// Beams only have a lifetime of 1 second
@@ -32,9 +32,9 @@ CPhotonBeam::CPhotonBeam( CGameEngine *pGameEngine, float xPos, float yPos, DWOR
//-----------------------------------------------------------------------------
// Purpose: Update with data from server
//-----------------------------------------------------------------------------
void CPhotonBeam::OnReceiveServerUpdate( ServerPhotonBeamUpdateData_t UpdateData )
void CPhotonBeam::OnReceiveServerUpdate( ServerPhotonBeamUpdateData_t *pUpdateData )
{
SetPosition( UpdateData.m_flXPosition, UpdateData.m_flYPosition );
SetVelocity( UpdateData.m_flXVelocity, UpdateData.m_flYVelocity );
SetAccumulatedRotation( UpdateData.m_flCurrentRotation );
SetPosition( pUpdateData->GetXPosition()*m_pGameEngine->GetViewportWidth(), pUpdateData->GetYPosition()*m_pGameEngine->GetViewportHeight() );
SetVelocity( pUpdateData->GetXVelocity(), pUpdateData->GetYVelocity() );
SetAccumulatedRotation( pUpdateData->GetRotation() );
}
+2 -2
View File
@@ -16,13 +16,13 @@ class CPhotonBeam : public CSpaceWarEntity
{
public:
// Constructor
CPhotonBeam( CGameEngine *pGameEngine, float xPos, float yPos, DWORD dwBeamColor, float flInitialRotation, float flInitialXVelocity, float flInitialYVelocity );
CPhotonBeam( IGameEngine *pGameEngine, float xPos, float yPos, DWORD dwBeamColor, float flInitialRotation, float flInitialXVelocity, float flInitialYVelocity );
// Check if the photon beam needs to die
bool BIsBeamExpired() { return m_pGameEngine->GetGameTickCount() > m_ulTickCountToDieAt; }
// Update with new data from server
void OnReceiveServerUpdate( ServerPhotonBeamUpdateData_t UpdateData );
void OnReceiveServerUpdate( ServerPhotonBeamUpdateData_t *pUpdateData );
private:
uint64 m_ulTickCountToDieAt;
+1 -1
View File
@@ -13,7 +13,7 @@
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CQuitMenu::CQuitMenu( CGameEngine *pGameEngine ) : CBaseMenu<EClientGameState>( pGameEngine )
CQuitMenu::CQuitMenu( IGameEngine *pGameEngine ) : CBaseMenu<EClientGameState>( pGameEngine )
{
AddMenuItem( MenuItem_t( "Resume Game", k_EClientGameActive ) );
AddMenuItem( MenuItem_t( "Exit To Menu", k_EClientGameMenu ) );
+1 -1
View File
@@ -19,7 +19,7 @@ class CQuitMenu : public CBaseMenu<EClientGameState>
{
public:
// Constructor
CQuitMenu( CGameEngine *pGameEngine );
CQuitMenu( IGameEngine *pGameEngine );
};
#endif // QUITMENU_H
+9 -14
View File
@@ -33,7 +33,7 @@
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CRemoteStorage::CRemoteStorage( CGameEngine *pGameEngine )
CRemoteStorage::CRemoteStorage( IGameEngine *pGameEngine )
: m_pGameEngine( pGameEngine )
{
m_rgchGreeting[0] = 0;
@@ -85,7 +85,6 @@ void CRemoteStorage::GetFileStats()
//-----------------------------------------------------------------------------
void CRemoteStorage::Render()
{
static uint64 m_ulLastEnterKeyTick = 0;
uint64 ulCurrentTickCount = m_pGameEngine->GetGameTickCount();
m_bFinished = false;
@@ -100,10 +99,6 @@ void CRemoteStorage::Render()
while ( m_pGameEngine->BGetFirstKeyDown( &dwVKDown ) )
{
// Clear this key
m_pGameEngine->RecordKeyUp( dwVKDown );
if ( VK_ESCAPE == dwVKDown )
{
// cancel
@@ -181,7 +176,7 @@ void CRemoteStorage::Render()
char rgchBuffer[256];
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Num Files In Cloud: %d", m_nNumFilesInCloud );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
rect.top = pxVertOffset;
rect.bottom = rect.top + CLOUDDISP_TEXT_HEIGHT;
@@ -190,7 +185,7 @@ void CRemoteStorage::Render()
pxVertOffset = rect.bottom + CLOUDDISP_TEXT_HEIGHT + CLOUDDISP_VERT_SPACING;
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Quota: %d bytes, %d bytes remaining", m_nBytesQuota, m_nAvailableBytes );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
rect.top = pxVertOffset;
rect.bottom = rect.top + CLOUDDISP_TEXT_HEIGHT;
@@ -199,7 +194,7 @@ void CRemoteStorage::Render()
pxVertOffset = rect.bottom + CLOUDDISP_VERT_SPACING;
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Current Message:" );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
rect.top = pxVertOffset;
rect.bottom = rect.top + CLOUDDISP_TEXT_HEIGHT;
@@ -207,7 +202,7 @@ void CRemoteStorage::Render()
rect.right = rect.left + CLOUDDISP_COLUMN_WIDTH;
pxVertOffset = rect.bottom + CLOUDDISP_TEXT_HEIGHT + CLOUDDISP_VERT_SPACING;
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, m_rgchGreeting );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, m_rgchGreeting );
rect.top = pxVertOffset;
rect.bottom = rect.top + CLOUDDISP_TEXT_HEIGHT;
@@ -216,7 +211,7 @@ void CRemoteStorage::Render()
pxVertOffset = rect.bottom + CLOUDDISP_VERT_SPACING;
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Type in a new message below:" );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
rect.top = pxVertOffset;
rect.bottom = rect.top + CLOUDDISP_TEXT_HEIGHT;
@@ -224,7 +219,7 @@ void CRemoteStorage::Render()
rect.right = rect.left + CLOUDDISP_COLUMN_WIDTH;
pxVertOffset = rect.bottom + CLOUDDISP_TEXT_HEIGHT + CLOUDDISP_VERT_SPACING;
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, m_rgchGreetingNext );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, m_rgchGreetingNext );
rect.top = pxVertOffset;
rect.bottom = rect.top + CLOUDDISP_TEXT_HEIGHT;
@@ -233,7 +228,7 @@ void CRemoteStorage::Render()
pxVertOffset = rect.bottom + CLOUDDISP_TEXT_HEIGHT + CLOUDDISP_VERT_SPACING;
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Hit <ENTER> to save, <ESC> to cancel" );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
if ( bQuotaExceeded )
{
@@ -244,7 +239,7 @@ void CRemoteStorage::Render()
pxVertOffset = rect.bottom + CLOUDDISP_TEXT_HEIGHT + CLOUDDISP_VERT_SPACING;
_snprintf( rgchBuffer, sizeof( rgchBuffer), "!! QUOTA EXCEEDED !!" );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
}
}
+2 -3
View File
@@ -10,7 +10,6 @@
#include "SpaceWar.h"
#include "GameEngine.h"
#include "steam/isteamremotestorage.h"
class ISteamUser;
class CSpaceWarClient;
@@ -20,7 +19,7 @@ class CRemoteStorage
public:
// Constructor
CRemoteStorage( CGameEngine *pGameEngine );
CRemoteStorage( IGameEngine *pGameEngine );
// Display the remote storage screen
void Render();
@@ -34,7 +33,7 @@ private:
void GetFileStats();
// Engine
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Display font
HGAMEFONT m_hDisplayFont;
+5 -3
View File
@@ -10,7 +10,6 @@
#include "ServerBrowser.h"
#include "ServerBrowserMenu.h"
//-----------------------------------------------------------------------------
// Purpose: Constructor -- initialize from steam gameserveritem_t
//-----------------------------------------------------------------------------
@@ -36,7 +35,7 @@ CGameServer::CGameServer( gameserveritem_t *pGameServerItem )
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CServerBrowser::CServerBrowser( CGameEngine *pGameEngine )
CServerBrowser::CServerBrowser( IGameEngine *pGameEngine )
{
m_pMenu = new CServerBrowserMenu( pGameEngine );
m_pGameEngine = pGameEngine;
@@ -90,7 +89,9 @@ void CServerBrowser::RefreshInternetServers()
m_pMenu->Rebuild( m_ListGameServers, m_bRequestingServers );
#ifndef _PS3
Steamworks_TestSecret();
#endif
// Allocate some filters, there are some common pre-defined values that can be used:
//
@@ -199,4 +200,5 @@ void CServerBrowser::RefreshComplete( HServerListRequest hReq, EMatchMakingServe
void CServerBrowser::RunFrame()
{
m_pMenu->RunFrame();
}
}
+3 -3
View File
@@ -11,13 +11,13 @@
#include "SpaceWar.h"
#include "GameEngine.h"
#include "steam/isteammatchmaking.h"
#include "BaseMenu.h"
#include <list>
class CSpaceWarClient;
class CServerBrowserMenu;
// Class to encapsulate game server data
class CGameServer
{
@@ -53,7 +53,7 @@ private:
class CServerBrowser : public ISteamMatchmakingServerListResponse
{
public:
CServerBrowser( CGameEngine *pGameEngine );
CServerBrowser( IGameEngine *pGameEngine );
~CServerBrowser();
// Initiate a refresh of internet servers
@@ -73,7 +73,7 @@ public:
private:
// Pointer to engine instance (so we can draw stuff)
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Track the number of servers we know about
int m_nServers;
+2 -4
View File
@@ -10,12 +10,11 @@
#include "BaseMenu.h"
#include "ServerBrowser.h"
class CServerBrowserMenu : public CBaseMenu<ServerBrowserMenuData_t>
{
public:
// Constructor
CServerBrowserMenu( CGameEngine *pGameEngine ) : CBaseMenu<ServerBrowserMenuData_t>( pGameEngine ) {}
CServerBrowserMenu( IGameEngine *pGameEngine ) : CBaseMenu<ServerBrowserMenuData_t>( pGameEngine ) {}
void Rebuild( std::list<CGameServer> &List, bool bIsRefreshing )
{
@@ -36,5 +35,4 @@ public:
}
};
#endif SERVERBROWSERMENU_H
#endif // SERVERBROWSERMENU_H
+66 -64
View File
@@ -10,11 +10,13 @@
#include "stdlib.h"
#include "SpaceWarServer.h"
#include "StatsAndAchievements.h"
#include <math.h>
#include <string.h>
//-----------------------------------------------------------------------------
// Purpose: Constructor for thrusters
//-----------------------------------------------------------------------------
CForwardThrusters::CForwardThrusters( CGameEngine *pGameEngine, CShip *pShip ) : CVectorEntity( pGameEngine, 0 )
CForwardThrusters::CForwardThrusters( IGameEngine *pGameEngine, CShip *pShip ) : CVectorEntity( pGameEngine, 0 )
{
DWORD dwColor = D3DCOLOR_ARGB( 255, 255, 255, 102 );
@@ -44,7 +46,7 @@ void CForwardThrusters::RunFrame()
//-----------------------------------------------------------------------------
// Purpose: Constructor for reverse thrusters
//-----------------------------------------------------------------------------
CReverseThrusters::CReverseThrusters( CGameEngine *pGameEngine, CShip *pShip ) : CVectorEntity( pGameEngine, 0 )
CReverseThrusters::CReverseThrusters( IGameEngine *pGameEngine, CShip *pShip ) : CVectorEntity( pGameEngine, 0 )
{
DWORD dwColor = D3DCOLOR_ARGB( 255, 255, 255, 102 );
@@ -76,7 +78,7 @@ void CReverseThrusters::RunFrame()
//-----------------------------------------------------------------------------
// Purpose: Constructor for ship debris after explosion
//-----------------------------------------------------------------------------
CShipDebris::CShipDebris( CGameEngine *pGameEngine, float xPos, float yPos, DWORD dwDebrisColor ) : CSpaceWarEntity( pGameEngine, 0, true )
CShipDebris::CShipDebris( IGameEngine *pGameEngine, float xPos, float yPos, DWORD dwDebrisColor ) : CSpaceWarEntity( pGameEngine, 0, true )
{
AddLine( 0.0f, 0.0f, 16.0f, 0.0f, dwDebrisColor );
@@ -112,7 +114,7 @@ CShipDebris::CShipDebris( CGameEngine *pGameEngine, float xPos, float yPos, DWOR
//-----------------------------------------------------------------------------
void CShipDebris::RunFrame()
{
SetRotationDeltaNextFrame( m_flRotationPerInterval * min( m_pGameEngine->GetGameTicksFrameDelta(), 400.0f )/400.0f );
SetRotationDeltaNextFrame( m_flRotationPerInterval * MIN( m_pGameEngine->GetGameTicksFrameDelta(), 400.0f )/400.0f );
CSpaceWarEntity::RunFrame();
}
@@ -124,7 +126,7 @@ void CShipDebris::RunFrame()
// warning C4355: 'this' : used in base member initializer list
// This is OK because the thruster classes won't use the ship object in their constructors (where it may still be only partly constructed)
#pragma warning( disable : 4355 )
CShip::CShip( CGameEngine *pGameEngine, bool bIsServerInstance, float xPos, float yPos, DWORD dwShipColor ) :
CShip::CShip( IGameEngine *pGameEngine, bool bIsServerInstance, float xPos, float yPos, DWORD dwShipColor ) :
CSpaceWarEntity( pGameEngine, 11, true ), m_ForwardThrusters( pGameEngine, this ), m_ReverseThrusters( pGameEngine, this )
{
m_bDisabled = false;
@@ -140,7 +142,6 @@ CShip::CShip( CGameEngine *pGameEngine, bool bIsServerInstance, float xPos, floa
m_bForwardThrustersActive = false;
m_bReverseThrustersActive = false;
m_bIsLocalPlayer = false;
m_bFirePhotonBeamNextFrame = false;
m_ulLastClientUpdateTick = 0;
m_bIsServerInstance = bIsServerInstance;
@@ -188,7 +189,7 @@ CShip::~CShip()
//-----------------------------------------------------------------------------
// Purpose: Update entity with updated data from the server
//-----------------------------------------------------------------------------
void CShip::OnReceiveServerUpdate( ServerShipUpdateData_t UpdateData )
void CShip::OnReceiveServerUpdate( ServerShipUpdateData_t *pUpdateData )
{
if ( m_bIsServerInstance )
{
@@ -196,33 +197,34 @@ void CShip::OnReceiveServerUpdate( ServerShipUpdateData_t UpdateData )
return;
}
SetDisabled( UpdateData.m_bDisabled );
SetDisabled( pUpdateData->GetDisabled() );
SetExploding( UpdateData.m_bExploding );
SetExploding( pUpdateData->GetExploding() );
SetPosition( UpdateData.m_flXPosition, UpdateData.m_flYPosition );
SetVelocity( UpdateData.m_flXVelocity, UpdateData.m_flYVelocity );
SetAccumulatedRotation( UpdateData.m_flCurrentRotation );
SetPosition( pUpdateData->GetXPosition()*m_pGameEngine->GetViewportWidth(), pUpdateData->GetYPosition()*m_pGameEngine->GetViewportHeight() );
SetVelocity( pUpdateData->GetXVelocity(), pUpdateData->GetYVelocity() );
SetAccumulatedRotation( pUpdateData->GetRotation() );
m_bForwardThrustersActive = UpdateData.m_bForwardThrustersActive;
m_bReverseThrustersActive = UpdateData.m_bReverseThrustersActive;
m_bForwardThrustersActive = pUpdateData->GetForwardThrustersActive();
m_bReverseThrustersActive = pUpdateData->GetReverseThrustersActive();
// Update the photon beams
for ( int i=0; i < MAX_PHOTON_BEAMS_PER_SHIP; ++i )
{
if ( UpdateData.m_PhotonBeamData[i].m_bIsActive )
ServerPhotonBeamUpdateData_t *pPhotonUpdate = pUpdateData->AccessPhotonBeamData( i );
if ( pPhotonUpdate->GetActive() )
{
if ( !m_rgPhotonBeams[i] )
{
m_rgPhotonBeams[i] = new CPhotonBeam( m_pGameEngine,
UpdateData.m_PhotonBeamData[i].m_flXPosition, UpdateData.m_PhotonBeamData[i].m_flYPosition,
m_dwShipColor, UpdateData.m_PhotonBeamData[i].m_flCurrentRotation,
UpdateData.m_PhotonBeamData[i].m_flXVelocity, UpdateData.m_PhotonBeamData[i].m_flYVelocity );
pPhotonUpdate->GetXPosition(), pPhotonUpdate->GetYPosition(),
m_dwShipColor, pPhotonUpdate->GetRotation(),
pPhotonUpdate->GetXVelocity(), pPhotonUpdate->GetYVelocity() );
}
else
{
m_rgPhotonBeams[i]->OnReceiveServerUpdate( UpdateData.m_PhotonBeamData[i] );
m_rgPhotonBeams[i]->OnReceiveServerUpdate( pPhotonUpdate );
}
}
else
@@ -240,14 +242,14 @@ void CShip::OnReceiveServerUpdate( ServerShipUpdateData_t UpdateData )
//-----------------------------------------------------------------------------
// Purpose: Update entity with updated data from the client
//-----------------------------------------------------------------------------
void CShip::OnReceiveClientUpdate( ClientSpaceWarUpdateData_t UpdateData )
void CShip::OnReceiveClientUpdate( ClientSpaceWarUpdateData_t *pUpdateData )
{
if ( !m_bIsServerInstance )
{
OutputDebugString( "Should not be receiving client updates on non-server instances\n" );
return;
}
memcpy( &m_SpaceWarClientUpdateData, &UpdateData, sizeof( ClientSpaceWarUpdateData_t ) );
memcpy( &m_SpaceWarClientUpdateData, pUpdateData, sizeof( ClientSpaceWarUpdateData_t ) );
}
@@ -264,7 +266,9 @@ bool CShip::BGetClientUpdateData( ClientSpaceWarUpdateData_t *pUpdateData )
// Update playername before sending
if ( m_bIsLocalPlayer )
strncpy( m_SpaceWarClientUpdateData.m_rgchPlayerName, SteamFriends()->GetFriendPersonaName( SteamUser()->GetSteamID() ), ARRAYSIZE( m_SpaceWarClientUpdateData.m_rgchPlayerName ) );
{
m_SpaceWarClientUpdateData.SetPlayerName( SteamFriends()->GetFriendPersonaName( SteamUser()->GetSteamID() ) );
}
memcpy( pUpdateData, &m_SpaceWarClientUpdateData, sizeof( ClientSpaceWarUpdateData_t ) );
memset( &m_SpaceWarClientUpdateData, 0, sizeof( m_SpaceWarClientUpdateData ) );
@@ -277,7 +281,7 @@ bool CShip::BGetClientUpdateData( ClientSpaceWarUpdateData_t *pUpdateData )
//-----------------------------------------------------------------------------
const char* CShip::GetPlayerName()
{
return m_SpaceWarClientUpdateData.m_rgchPlayerName;
return m_SpaceWarClientUpdateData.GetPlayerName();
}
@@ -324,29 +328,29 @@ void CShip::RunFrame()
if ( m_bIsLocalPlayer )
{
m_SpaceWarClientUpdateData.m_bTurnLeftPressed = false;
m_SpaceWarClientUpdateData.m_bTurnRightPressed = false;
m_SpaceWarClientUpdateData.SetTurnLeftPressed( false );
m_SpaceWarClientUpdateData.SetTurnRightPressed( false );
if ( m_pGameEngine->BIsKeyDown( m_dwVKLeft ) )
{
m_SpaceWarClientUpdateData.m_bTurnLeftPressed = true;
m_SpaceWarClientUpdateData.SetTurnLeftPressed( true );
}
if ( m_pGameEngine->BIsKeyDown( m_dwVKRight ) )
{
m_SpaceWarClientUpdateData.m_bTurnRightPressed = true;
m_SpaceWarClientUpdateData.SetTurnRightPressed( true );
}
}
else if ( m_bIsServerInstance )
{
// Server side
float flRotationDelta = 0.0f;
if ( m_SpaceWarClientUpdateData.m_bTurnLeftPressed )
if ( m_SpaceWarClientUpdateData.GetTurnLeftPressed() )
{
flRotationDelta += (PI_VALUE/2.0f) * -1.0f * (float)m_pGameEngine->GetGameTicksFrameDelta()/400.0f;
}
if ( m_SpaceWarClientUpdateData.m_bTurnRightPressed )
if ( m_SpaceWarClientUpdateData.GetTurnRightPressed() )
{
flRotationDelta += (PI_VALUE/2.0f) * (float)m_pGameEngine->GetGameTicksFrameDelta()/400.0f;
}
@@ -357,17 +361,17 @@ void CShip::RunFrame()
if ( m_bIsLocalPlayer )
{
// client side
m_SpaceWarClientUpdateData.m_bReverseThrustersPressed = false;
m_SpaceWarClientUpdateData.m_bForwardThrustersPressed = false;
m_SpaceWarClientUpdateData.SetReverseThrustersPressed( false );
m_SpaceWarClientUpdateData.SetForwardThrustersPressed( false );
if ( m_pGameEngine->BIsKeyDown( m_dwVKForwardThrusters ) || m_pGameEngine->BIsKeyDown( m_dwVKReverseThrusters ) )
{
if ( m_pGameEngine->BIsKeyDown( m_dwVKReverseThrusters ) )
{
m_SpaceWarClientUpdateData.m_bReverseThrustersPressed = true;
m_SpaceWarClientUpdateData.SetReverseThrustersPressed( true );
}
else
{
m_SpaceWarClientUpdateData.m_bForwardThrustersPressed = true;
m_SpaceWarClientUpdateData.SetForwardThrustersPressed( true );
}
}
}
@@ -378,10 +382,10 @@ void CShip::RunFrame()
float yThrust = 0;
m_bReverseThrustersActive = false;
m_bForwardThrustersActive = false;
if ( m_SpaceWarClientUpdateData.m_bReverseThrustersPressed || m_SpaceWarClientUpdateData.m_bForwardThrustersPressed )
if ( m_SpaceWarClientUpdateData.GetReverseThrustersPressed() || m_SpaceWarClientUpdateData.GetForwardThrustersPressed() )
{
float flSign = 1.0f;
if ( m_SpaceWarClientUpdateData.m_bReverseThrustersPressed )
if ( m_SpaceWarClientUpdateData.GetReverseThrustersPressed() )
{
m_bReverseThrustersActive = true;
flSign = -1.0f;
@@ -395,7 +399,7 @@ void CShip::RunFrame()
m_ulLastThrustStartedTickCount = ulCurrentTickCount;
// You have to hold the key for a second to reach maximum thrust
float factor = min( ((float)(ulCurrentTickCount - m_ulLastThrustStartedTickCount) / 500.0f) + 0.2f, 1.0f );
float factor = MIN( ((float)(ulCurrentTickCount - m_ulLastThrustStartedTickCount) / 500.0f) + 0.2f, 1.0f );
xThrust = flSign * (float)(MAXIMUM_SHIP_THRUST * factor * sin( GetAccumulatedRotation() ) );
yThrust = flSign * -1.0f * (float)(MAXIMUM_SHIP_THRUST * factor * cos( GetAccumulatedRotation() ) );
@@ -414,22 +418,18 @@ void CShip::RunFrame()
float sinvalue = (float)sin( GetAccumulatedRotation() );
float cosvalue = (float)cos( GetAccumulatedRotation() );
// See if we need to fire a photon beam
bool bFirePhotonBeam = m_bFirePhotonBeamNextFrame;
m_bFirePhotonBeamNextFrame = false;
if ( m_bIsLocalPlayer )
{
// client side
if ( m_pGameEngine->BIsKeyDown( m_dwVKFire ) )
{
m_SpaceWarClientUpdateData.m_bFirePressed = true;
m_SpaceWarClientUpdateData.SetFirePressed( true );
}
}
else if ( m_bIsServerInstance )
{
// server side
if ( nNextAvailablePhotonBeamSlot != -1 && !m_bExploding && m_SpaceWarClientUpdateData.m_bFirePressed && ulCurrentTickCount - PHOTON_BEAM_FIRE_INTERVAL_TICKS > m_ulLastPhotonTickCount )
if ( nNextAvailablePhotonBeamSlot != -1 && !m_bExploding && m_SpaceWarClientUpdateData.GetFirePressed() && ulCurrentTickCount - PHOTON_BEAM_FIRE_INTERVAL_TICKS > m_ulLastPhotonTickCount )
{
m_ulLastPhotonTickCount = ulCurrentTickCount;
@@ -502,7 +502,9 @@ void CShip::SetExploding( bool bExploding )
if ( m_bExploding == bExploding )
return;
#ifndef _PS3
Steamworks_TestSecret();
#endif
// Track that we are exploding, and disable collision detection
m_bExploding = bExploding;
@@ -572,43 +574,43 @@ bool CShip::BCheckForPhotonsCollidingWith( CVectorEntity *pTarget )
//-----------------------------------------------------------------------------
void CShip::BuildServerUpdate( ServerShipUpdateData_t *pUpdateData )
{
pUpdateData->m_bDisabled = BIsDisabled();
pUpdateData->m_bExploding = BIsExploding();
pUpdateData->m_flXAcceleration = GetXAccelerationLastFrame();
pUpdateData->m_flYAcceleration = GetYAccelerationLastFrame();
pUpdateData->m_flXPosition = GetXPos();
pUpdateData->m_flYPosition = GetYPos();
pUpdateData->m_flXVelocity = GetXVelocity();
pUpdateData->m_flYVelocity = GetYVelocity();
pUpdateData->m_flCurrentRotation = GetAccumulatedRotation();
pUpdateData->m_flRotationDeltaLastFrame = GetRotationDeltaLastFrame();
pUpdateData->m_bForwardThrustersActive = m_bForwardThrustersActive;
pUpdateData->m_bReverseThrustersActive = m_bReverseThrustersActive;
pUpdateData->SetDisabled( BIsDisabled() );
pUpdateData->SetExploding( BIsExploding() );
pUpdateData->SetXAcceleration( GetXAccelerationLastFrame() );
pUpdateData->SetYAcceleration( GetYAccelerationLastFrame() );
pUpdateData->SetXPosition( GetXPos()/(float)m_pGameEngine->GetViewportWidth() );
pUpdateData->SetYPosition( GetYPos()/(float)m_pGameEngine->GetViewportHeight() );
pUpdateData->SetXVelocity( GetXVelocity() );
pUpdateData->SetYVelocity( GetYVelocity() );
pUpdateData->SetRotation( GetAccumulatedRotation() );
pUpdateData->SetRotationDeltaLastFrame( GetRotationDeltaLastFrame() );
pUpdateData->SetForwardThrustersActive( m_bForwardThrustersActive );
pUpdateData->SetReverseThrustersActive( m_bReverseThrustersActive );
BuildServerPhotonBeamUpdate( pUpdateData->m_PhotonBeamData );
BuildServerPhotonBeamUpdate( pUpdateData );
}
//-----------------------------------------------------------------------------
// Purpose: Build the photon beam update data to send from the server to clients
//-----------------------------------------------------------------------------
void CShip::BuildServerPhotonBeamUpdate( ServerPhotonBeamUpdateData_t *pUpdateData )
void CShip::BuildServerPhotonBeamUpdate( ServerShipUpdateData_t *pUpdateData )
{
for( int i = 0; i < MAX_PHOTON_BEAMS_PER_SHIP; ++i )
{
ServerPhotonBeamUpdateData_t *pPhotonUpdate = pUpdateData->AccessPhotonBeamData( i );
if ( m_rgPhotonBeams[i] )
{
pUpdateData[i].m_bIsActive = true;
pUpdateData[i].m_flXPosition = m_rgPhotonBeams[i]->GetXPos();
pUpdateData[i].m_flYPosition = m_rgPhotonBeams[i]->GetYPos();
pUpdateData[i].m_flXVelocity = m_rgPhotonBeams[i]->GetXVelocity();
pUpdateData[i].m_flYVelocity = m_rgPhotonBeams[i]->GetYVelocity();
pUpdateData[i].m_flCurrentRotation = m_rgPhotonBeams[i]->GetAccumulatedRotation();
pPhotonUpdate->SetActive( true );
pPhotonUpdate->SetXPosition( m_rgPhotonBeams[i]->GetXPos()/(float)m_pGameEngine->GetViewportWidth() );
pPhotonUpdate->SetYPosition( m_rgPhotonBeams[i]->GetYPos()/(float)m_pGameEngine->GetViewportHeight() );
pPhotonUpdate->SetXVelocity( m_rgPhotonBeams[i]->GetXVelocity() );
pPhotonUpdate->SetYVelocity( m_rgPhotonBeams[i]->GetYVelocity() );
pPhotonUpdate->SetRotation( m_rgPhotonBeams[i]->GetAccumulatedRotation() );
}
else
{
pUpdateData[i].m_bIsActive = false;
pPhotonUpdate->SetActive( false );
}
}
}
+7 -10
View File
@@ -27,7 +27,7 @@ class CStatsAndAchievements;
class CForwardThrusters : public CVectorEntity
{
public:
CForwardThrusters( CGameEngine *pGameEngine, CShip *pShip );
CForwardThrusters( IGameEngine *pGameEngine, CShip *pShip );
// Run Frame
void RunFrame();
@@ -40,7 +40,7 @@ private:
class CReverseThrusters : public CVectorEntity
{
public:
CReverseThrusters( CGameEngine *pGameEngine, CShip *pShip );
CReverseThrusters( IGameEngine *pGameEngine, CShip *pShip );
// Run Frame
void RunFrame();
@@ -53,7 +53,7 @@ private:
class CShipDebris : public CSpaceWarEntity
{
public:
CShipDebris( CGameEngine *pGameEngine, float xPos, float yPos, DWORD dwDebrisColor );
CShipDebris( IGameEngine *pGameEngine, float xPos, float yPos, DWORD dwDebrisColor );
// Run Frame
void RunFrame();
@@ -67,7 +67,7 @@ class CShip : public CSpaceWarEntity
{
public:
// Constructor
CShip( CGameEngine *pGameEngine, bool bIsServerInstance, float xPos, float yPos, DWORD dwShipColor );
CShip( IGameEngine *pGameEngine, bool bIsServerInstance, float xPos, float yPos, DWORD dwShipColor );
// Destructor
~CShip();
@@ -79,10 +79,10 @@ public:
void Render();
// Update ship with data from server
void OnReceiveServerUpdate( ServerShipUpdateData_t UpdateData );
void OnReceiveServerUpdate( ServerShipUpdateData_t *pUpdateData );
// Update the ship with data from a client
void OnReceiveClientUpdate( ClientSpaceWarUpdateData_t UpdateData );
void OnReceiveClientUpdate( ClientSpaceWarUpdateData_t *pUpdateData );
// Get the update data for this ship client side (copying into memory passed in)
bool BGetClientUpdateData( ClientSpaceWarUpdateData_t *pUpdatedata );
@@ -91,7 +91,7 @@ public:
void BuildServerUpdate( ServerShipUpdateData_t *pUpdateData );
// Build update data for photon beams to send to clients
void BuildServerPhotonBeamUpdate( ServerPhotonBeamUpdateData_t *pUpdateData );
void BuildServerPhotonBeamUpdate( ServerShipUpdateData_t *pUpdateData );
// Reset vertex data for our object
void ResetVertexData();
@@ -158,9 +158,6 @@ private:
// is the ship disabled for now?
bool m_bDisabled;
// Do we need to fire a photon beam next frame?
bool m_bFirePhotonBeamNextFrame;
// vector of beams we have fired (in order of firing time)
CPhotonBeam * m_rgPhotonBeams[MAX_PHOTON_BEAMS_PER_SHIP];
+162 -1
View File
@@ -77,6 +77,68 @@
#define MAX_CLIENT_AND_SERVER_FPS 86
template <typename T>
inline T WordSwap( T w )
{
uint16 temp;
temp = ((*((uint16 *)&w) & 0xff00) >> 8);
temp |= ((*((uint16 *)&w) & 0x00ff) << 8);
return *((T*)&temp);
}
template <typename T>
inline T DWordSwap( T dw )
{
uint32 temp;
temp = *((uint32 *)&dw) >> 24;
temp |= ((*((uint32 *)&dw) & 0x00FF0000) >> 8);
temp |= ((*((uint32 *)&dw) & 0x0000FF00) << 8);
temp |= ((*((uint32 *)&dw) & 0x000000FF) << 24);
return *((T*)&temp);
}
template <typename T>
inline T QWordSwap( T dw )
{
uint64 temp;
temp = *((uint64 *)&dw) >> 56;
temp |= ((*((uint64 *)&dw) & 0x00FF000000000000ull) >> 40);
temp |= ((*((uint64 *)&dw) & 0x0000FF0000000000ull) >> 24);
temp |= ((*((uint64 *)&dw) & 0x000000FF00000000ull) >> 8);
temp |= ((*((uint64 *)&dw) & 0x00000000FF000000ull) << 8);
temp |= ((*((uint64 *)&dw) & 0x0000000000FF0000ull) << 24);
temp |= ((*((uint64 *)&dw) & 0x000000000000FF00ull) << 40);
temp |= ((*((uint64 *)&dw) & 0x00000000000000FFull) << 56);
return *((T*)&temp);
}
#ifndef _PS3
#define LittleShort( val ) ( val )
#define LittleWord( val ) ( val )
#define LittleLong( val ) ( val )
#define LittleDWord( val ) ( val )
#define LittleQWord( val ) ( val )
#define LittleFloat( val ) ( val )
#else
#define LittleShort( val ) WordSwap( val )
#define LittleWord( val ) WordSwap( val )
#define LittleLong( val ) DWordSwap( val )
#define LittleDWord( val ) DWordSwap( val )
#define LittleQWord( val ) QWordSwap( val )
#define LittleFloat( val ) DWordSwap( val )
#endif
// Leaderboard names
#define LEADERBOARD_QUICKEST_WIN "Quickest Win"
#define LEADERBOARD_FEET_TRAVELED "Feet Traveled"
@@ -129,10 +191,31 @@ enum EServerGameState
k_EServerExiting,
};
#pragma pack( push, 1 )
// Data sent per photon beam from the server to update clients photon beam positions
struct ServerPhotonBeamUpdateData_t
{
void SetActive( bool bIsActive ) { m_bIsActive = bIsActive; }
bool GetActive() { return m_bIsActive; }
void SetRotation( float flRotation ) { m_flCurrentRotation = LittleFloat( flRotation ); }
float GetRotation() { return LittleFloat( m_flCurrentRotation ); }
void SetXVelocity( float flVelocity ) { m_flXVelocity = LittleFloat( flVelocity ); }
float GetXVelocity() { return LittleFloat( m_flXVelocity ); }
void SetYVelocity( float flVelocity ) { m_flYVelocity = LittleFloat( flVelocity ); }
float GetYVelocity() { return LittleFloat( m_flYVelocity ); }
void SetXPosition( float flPosition ) { m_flXPosition = LittleFloat( flPosition ); }
float GetXPosition() { return LittleFloat( m_flXPosition ); }
void SetYPosition( float flPosition ) { m_flYPosition = LittleFloat( flPosition ); }
float GetYPosition() { return LittleFloat( m_flYPosition ); }
private:
// Does the photon beam exist right now?
bool m_bIsActive;
@@ -152,6 +235,45 @@ struct ServerPhotonBeamUpdateData_t
// This is the data that gets sent per ship in each update, see below for the full update data
struct ServerShipUpdateData_t
{
void SetRotation( float flRotation ) { m_flCurrentRotation = LittleFloat( flRotation ); }
float GetRotation() { return LittleFloat( m_flCurrentRotation ); }
void SetRotationDeltaLastFrame( float flDelta ) { m_flRotationDeltaLastFrame = LittleFloat( flDelta ); }
float GetRotationDeltaLastFrame() { return LittleFloat( m_flRotationDeltaLastFrame ); }
void SetXAcceleration( float flAcceleration ) { m_flXAcceleration = LittleFloat( flAcceleration ); }
float GetXAcceleration() { return LittleFloat( m_flXAcceleration ); }
void SetYAcceleration( float flAcceleration ) { m_flYAcceleration = LittleFloat( flAcceleration ); }
float GetYAcceleration() { return LittleFloat( m_flYAcceleration ); }
void SetXVelocity( float flVelocity ) { m_flXVelocity = LittleFloat( flVelocity ); }
float GetXVelocity() { return LittleFloat( m_flXVelocity ); }
void SetYVelocity( float flVelocity ) { m_flYVelocity = LittleFloat( flVelocity ); }
float GetYVelocity() { return LittleFloat( m_flYVelocity ); }
void SetXPosition( float flPosition ) { m_flXPosition = LittleFloat( flPosition ); }
float GetXPosition() { return LittleFloat( m_flXPosition ); }
void SetYPosition( float flPosition ) { m_flYPosition = LittleFloat( flPosition ); }
float GetYPosition() { return LittleFloat( m_flYPosition ); }
void SetExploding( bool bIsExploding ) { m_bExploding = bIsExploding; }
bool GetExploding() { return m_bExploding; }
void SetDisabled( bool bIsDisabled ) { m_bDisabled = bIsDisabled; }
bool GetDisabled() { return m_bDisabled; }
void SetForwardThrustersActive( bool bActive ) { m_bForwardThrustersActive = bActive; }
bool GetForwardThrustersActive() { return m_bForwardThrustersActive; }
void SetReverseThrustersActive( bool bActive ) { m_bReverseThrustersActive = bActive; }
bool GetReverseThrustersActive() { return m_bReverseThrustersActive; }
ServerPhotonBeamUpdateData_t *AccessPhotonBeamData( int iIndex ) { return &m_PhotonBeamData[iIndex]; }
private:
// The current rotation of the ship
float m_flCurrentRotation;
@@ -188,8 +310,26 @@ struct ServerShipUpdateData_t
// This is the data that gets sent from the server to each client for each update
struct ServerSpaceWarUpdateData_t
{
void SetServerGameState( EServerGameState eState ) { m_eCurrentGameState = LittleDWord( (uint32)eState ); }
EServerGameState GetServerGameState() { return (EServerGameState)LittleDWord( m_eCurrentGameState ); }
void SetPlayerWhoWon( uint32 iIndex ) { m_uPlayerWhoWonGame = LittleDWord( iIndex ); }
uint32 GetPlayerWhoWon() { return LittleDWord( m_uPlayerWhoWonGame ); }
void SetPlayerActive( uint32 iIndex, bool bIsActive ) { m_rgPlayersActive[iIndex] = bIsActive; }
bool GetPlayerActive( uint32 iIndex ) { return m_rgPlayersActive[iIndex]; }
void SetPlayerScore( uint32 iIndex, uint32 unScore ) { m_rgPlayerScores[iIndex] = LittleDWord(unScore); }
uint32 GetPlayerScore( uint32 iIndex ) { return LittleDWord(m_rgPlayerScores[iIndex]); }
void SetPlayerSteamID( uint32 iIndex, uint64 ulSteamID ) { m_rgPlayerSteamIDs[iIndex] = LittleQWord(ulSteamID); }
uint64 GetPlayerSteamID( uint32 iIndex ) { return LittleQWord(m_rgPlayerSteamIDs[iIndex]); }
ServerShipUpdateData_t *AccessShipUpdateData( uint32 iIndex ) { return &m_rgShipData[iIndex];}
private:
// What state the game is in
EServerGameState m_eCurrentGameState;
uint32 m_eCurrentGameState;
// Who just won the game? -- only valid when m_eCurrentGameState == k_EGameWinner
uint32 m_uPlayerWhoWonGame;
@@ -211,6 +351,25 @@ struct ServerSpaceWarUpdateData_t
// This is the data that gets sent from each client to the server for each update
struct ClientSpaceWarUpdateData_t
{
void SetPlayerName( const char *pchName ) { strncpy( m_rgchPlayerName, pchName, sizeof( m_rgchPlayerName ) ); }
const char *GetPlayerName() { return m_rgchPlayerName; }
void SetFirePressed( bool bIsPressed ) { m_bFirePressed = bIsPressed; }
bool GetFirePressed() { return m_bFirePressed; }
void SetTurnLeftPressed( bool bIsPressed ) { m_bTurnLeftPressed = bIsPressed; }
bool GetTurnLeftPressed() { return m_bTurnLeftPressed; }
void SetTurnRightPressed( bool bIsPressed ) { m_bTurnRightPressed = bIsPressed; }
bool GetTurnRightPressed() { return m_bTurnRightPressed; }
void SetForwardThrustersPressed( bool bIsPressed ) { m_bForwardThrustersPressed = bIsPressed; }
bool GetForwardThrustersPressed() { return m_bForwardThrustersPressed; }
void SetReverseThrustersPressed( bool bIsPressed ) { m_bReverseThrustersPressed = bIsPressed; }
bool GetReverseThrustersPressed() { return m_bReverseThrustersPressed; }
private:
// Key's which are done
bool m_bFirePressed;
bool m_bTurnLeftPressed;
@@ -223,4 +382,6 @@ struct ClientSpaceWarUpdateData_t
char m_rgchPlayerName[64];
};
#pragma pack( pop )
#endif // SPACEWAR_H
+189 -78
View File
@@ -16,6 +16,7 @@
#include "Leaderboards.h"
#include "Lobby.h"
#include "p2pauth.h"
#include "steam/steamencryptedappticket.h"
CSpaceWarClient *g_pSpaceWarClient = NULL;
CSpaceWarClient* SpaceWarClient() { return g_pSpaceWarClient; }
@@ -23,12 +24,23 @@ CSpaceWarClient* SpaceWarClient() { return g_pSpaceWarClient; }
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CSpaceWarClient::CSpaceWarClient( CGameEngine *pGameEngine, CSteamID steamIDUser ) :
CSpaceWarClient::CSpaceWarClient( IGameEngine *pGameEngine, CSteamID steamIDUser ) :
m_CallbackP2PSessionConnectFail( this, &CSpaceWarClient::OnP2PSessionConnectFail ),
m_LobbyGameCreated( this, &CSpaceWarClient::OnLobbyGameCreated ),
m_AvatarImageLoadedCreated( this, &CSpaceWarClient::OnAvatarImageLoaded ),
m_IPCFailureCallback( this, &CSpaceWarClient::OnIPCFailure ),
m_SteamShutdownCallback( this, &CSpaceWarClient::OnSteamShutdown )
{
m_SteamIDLocalUser = steamIDUser;
Init( pGameEngine );
}
//-----------------------------------------------------------------------------
// Purpose: Shared initialization for both constructors
//-----------------------------------------------------------------------------
void CSpaceWarClient::Init( IGameEngine *pGameEngine )
{
g_pSpaceWarClient = this;
m_pGameEngine = pGameEngine;
@@ -38,7 +50,6 @@ CSpaceWarClient::CSpaceWarClient( CGameEngine *pGameEngine, CSteamID steamIDUser
m_ulLastNetworkDataReceivedTime = 0;
m_pServer = NULL;
m_uPlayerShipIndex = 0;
m_SteamIDLocalUser = steamIDUser;
m_eConnectedStatus = k_EClientNotConnected;
m_bTransitionedGameState = false;
m_rgchErrorText[0] = 0;
@@ -186,17 +197,21 @@ void CSpaceWarClient::OnReceiveServerInfo( CSteamID steamIDGameServer, bool bVAC
MsgClientBeginAuthentication_t msg;
#ifdef USE_GS_AUTH_API
msg.m_uTokenLen = SteamUser()->InitiateGameConnection( (void*)&msg.m_rgchToken, ARRAYSIZE( msg.m_rgchToken ), steamIDGameServer, m_unServerIP, m_usServerPort, bVACSecure );
char rgchToken[1024];
uint32 unTokenLen = SteamUser()->InitiateGameConnection( (void*)&rgchToken, ARRAYSIZE( rgchToken ), steamIDGameServer, m_unServerIP, m_usServerPort, bVACSecure );
msg.SetToken( rgchToken, unTokenLen );
#else
// When you aren't using Steam auth you still call InitiateGameConnection() so you can communicate presence data to the friends
// system. Make sure to pass k_steamIDNonSteamGS so Steam won't try to authenticate your user.
msg.m_uTokenLen = SteamUser()->InitiateGameConnection( NULL, 0, k_steamIDNonSteamGS, m_unServerIP, m_usServerPort, false );
msg.m_SteamID = SteamUser()->GetSteamID();
uint32 unTokenLen = SteamUser()->InitiateGameConnection( NULL, 0, k_steamIDNonSteamGS, m_unServerIP, m_usServerPort, false );
msg.SetSteamID( SteamUser()->GetSteamID().ConvertToUint64() );
#endif
#ifndef _PS3
Steamworks_TestSecret();
#endif
if ( msg.m_uTokenLen < 1 )
if ( msg.GetTokenLen() < 1 )
OutputDebugString( "Warning: Looks like InitiateGameConnection didn't give us a good token\n" );
BSendServerData( &msg, sizeof(msg) );
@@ -234,11 +249,11 @@ void CSpaceWarClient::OnReceiveServerAuthenticationResponse( bool bSuccess, uint
//-----------------------------------------------------------------------------
// Purpose: Handles receiving a state update from the game server
//-----------------------------------------------------------------------------
void CSpaceWarClient::OnReceiveServerUpdate( ServerSpaceWarUpdateData_t UpdateData )
void CSpaceWarClient::OnReceiveServerUpdate( ServerSpaceWarUpdateData_t *pUpdateData )
{
// Update our client state based on what the server tells us
switch( UpdateData.m_eCurrentGameState )
switch( pUpdateData->GetServerGameState() )
{
case k_EServerWaitingForPlayers:
if ( m_eGameState == k_EClientGameQuitMenu )
@@ -289,10 +304,13 @@ void CSpaceWarClient::OnReceiveServerUpdate( ServerSpaceWarUpdateData_t UpdateDa
}
// Update scores
memcpy( m_rguPlayerScores, UpdateData.m_rgPlayerScores, sizeof( m_rguPlayerScores ) );
for( int i=0; i < MAX_PLAYERS_PER_SERVER; ++i )
{
m_rguPlayerScores[i] = pUpdateData->GetPlayerScore(i);
}
// Update who won last
m_uPlayerWhoWonGame = UpdateData.m_uPlayerWhoWonGame;
m_uPlayerWhoWonGame = pUpdateData->GetPlayerWhoWon();
if ( m_pP2PAuthedGame )
{
@@ -303,10 +321,10 @@ void CSpaceWarClient::OnReceiveServerUpdate( ServerSpaceWarUpdateData_t UpdateDa
// assume i am in slot 0, so start at slot 1
for( uint32 i=1; i < MAX_PLAYERS_PER_SERVER; ++i )
{
CSteamID steamIDNew( UpdateData.m_rgPlayerSteamIDs[i] );
CSteamID steamIDNew( pUpdateData->GetPlayerSteamID(i) );
if ( steamIDNew == SteamUser()->GetSteamID() )
{
OutputDebugStringA( "Server player slot 0 is not server owner.\n" );
OutputDebugString( "Server player slot 0 is not server owner.\n" );
}
else if ( steamIDNew != m_rgSteamIDPlayers[i] )
{
@@ -324,16 +342,16 @@ void CSpaceWarClient::OnReceiveServerUpdate( ServerSpaceWarUpdateData_t UpdateDa
else
{
// i am just a client, i need to auth the game owner ( slot 0 )
CSteamID steamIDNew( UpdateData.m_rgPlayerSteamIDs[0] );
CSteamID steamIDNew( pUpdateData->GetPlayerSteamID( 0 ) );
if ( steamIDNew == SteamUser()->GetSteamID() )
{
OutputDebugStringA( "Server player slot 0 is not server owner.\n" );
OutputDebugString( "Server player slot 0 is not server owner.\n" );
}
else if ( steamIDNew != m_rgSteamIDPlayers[0] )
{
if ( m_rgSteamIDPlayers[0].IsValid() )
{
OutputDebugStringA( "Server player slot 0 has disconnected - but thats the server owner.\n" );
OutputDebugString( "Server player slot 0 has disconnected - but thats the server owner.\n" );
m_pP2PAuthedGame->PlayerDisconnect( 0 );
}
if ( steamIDNew.IsValid() )
@@ -348,14 +366,15 @@ void CSpaceWarClient::OnReceiveServerUpdate( ServerSpaceWarUpdateData_t UpdateDa
for( uint32 i=0; i < MAX_PLAYERS_PER_SERVER; ++i )
{
// Update steamid array with data from server
m_rgSteamIDPlayers[i].SetFromUint64( UpdateData.m_rgPlayerSteamIDs[i] );
m_rgSteamIDPlayers[i].SetFromUint64( pUpdateData->GetPlayerSteamID( i ) );
if ( UpdateData.m_rgPlayersActive[i] )
if ( pUpdateData->GetPlayerActive( i ) )
{
// Check if we have a ship created locally for this player slot, if not create it
if ( !m_rgpShips[i] )
{
m_rgpShips[i] = new CShip( m_pGameEngine, false, UpdateData.m_rgShipData[i].m_flXPosition, UpdateData.m_rgShipData[i].m_flYPosition, g_rgPlayerColors[i] );
ServerShipUpdateData_t *pShipData = pUpdateData->AccessShipUpdateData( i );
m_rgpShips[i] = new CShip( m_pGameEngine, false, pShipData->GetXPosition(), pShipData->GetYPosition(), g_rgPlayerColors[i] );
if ( i == m_uPlayerShipIndex )
{
// If this is our local ship, then setup key bindings appropriately
@@ -372,7 +391,7 @@ void CSpaceWarClient::OnReceiveServerUpdate( ServerSpaceWarUpdateData_t UpdateDa
else
m_rgpShips[i]->SetIsLocalPlayer( false );
m_rgpShips[i]->OnReceiveServerUpdate( UpdateData.m_rgShipData[i] );
m_rgpShips[i]->OnReceiveServerUpdate( pUpdateData->AccessShipUpdateData( i ) );
}
else
{
@@ -423,7 +442,6 @@ bool CSpaceWarClient::BSendServerData( const void *pData, uint32 nSizeOfData )
OutputDebugString( "Failed sending data to server\n" );
return false;
}
return true;
}
@@ -483,7 +501,7 @@ void CSpaceWarClient::OnP2PSessionConnectFail( P2PSessionConnectFail_t *pCallbac
if ( pCallback->m_steamIDRemote == m_steamIDGameServer )
{
// failed, error out
OutputDebugString( "Failed to make P2P connection, quiting server" );
OutputDebugString( "Failed to make P2P connection, quiting server\n" );
OnReceiveServerExiting();
}
}
@@ -494,7 +512,7 @@ void CSpaceWarClient::OnP2PSessionConnectFail( P2PSessionConnectFail_t *pCallbac
//-----------------------------------------------------------------------------
void CSpaceWarClient::ReceiveNetworkData()
{
char rgchRecvBuf[MAX_SPACEWAR_PACKET_SIZE];
char rgchRecvBuf[1024];
char *pchRecvBuf = rgchRecvBuf;
uint32 cubMsgSize;
for (;;)
@@ -529,13 +547,13 @@ void CSpaceWarClient::ReceiveNetworkData()
if ( m_eConnectedStatus == k_EClientNotConnected && m_eGameState != k_EClientGameConnecting )
continue;
if ( cubMsgSize < sizeof( EMessage ) )
if ( cubMsgSize < sizeof( DWORD ) )
{
OutputDebugString( "Got garbage on client socket, too short\n" );
}
EMessage *pEMsg = (EMessage*)pchRecvBuf;
switch ( *pEMsg )
EMessage eMsg = (EMessage)LittleDWord( *(DWORD*)pchRecvBuf );
switch ( eMsg )
{
case k_EMsgServerSendInfo:
{
@@ -547,7 +565,7 @@ void CSpaceWarClient::ReceiveNetworkData()
MsgServerSendInfo_t *pMsg = (MsgServerSendInfo_t*)pchRecvBuf;
// pull the IP address of the user from the socket
OnReceiveServerInfo( CSteamID( pMsg->m_ulSteamIDServer ), pMsg->m_bIsVACSecure, pMsg->m_rgchServerName );
OnReceiveServerInfo( CSteamID( pMsg->GetSteamIDServer() ), pMsg->GetSecure(), pMsg->GetServerName() );
}
break;
case k_EMsgServerPassAuthentication:
@@ -561,7 +579,7 @@ void CSpaceWarClient::ReceiveNetworkData()
// Our game client doesn't really care about whether the server is secure, or what its
// steamID is, but if it did we would pass them in here as they are part of the accept message
OnReceiveServerAuthenticationResponse( true, pMsg->m_uPlayerPosition );
OnReceiveServerAuthenticationResponse( true, pMsg->GetPlayerPosition() );
}
break;
case k_EMsgServerFailAuthentication:
@@ -578,7 +596,7 @@ void CSpaceWarClient::ReceiveNetworkData()
}
MsgServerUpdateWorld_t *pMsg = (MsgServerUpdateWorld_t*)pchRecvBuf;
OnReceiveServerUpdate( pMsg->m_ServerUpdateData );
OnReceiveServerUpdate( pMsg->AccessUpdateData() );
}
break;
case k_EMsgServerExiting:
@@ -606,8 +624,8 @@ void CSpaceWarClient::ReceiveNetworkData()
}
else
{
EMessage *pEMsg = (EMessage*)pchRecvBuf;
m_pP2PAuthedGame->HandleMessage( *pEMsg, pchRecvBuf );
EMessage eMsg = (EMessage)LittleDWord( *(DWORD*)pchRecvBuf );
m_pP2PAuthedGame->HandleMessage( eMsg, pchRecvBuf );
}
}
@@ -630,7 +648,9 @@ void CSpaceWarClient::OnReceiveServerExiting()
return;
if ( m_eConnectedStatus == k_EClientConnectedAndAuthenticated )
{
SteamUser()->TerminateGameConnection( m_unServerIP, m_usServerPort );
}
m_eConnectedStatus = k_EClientNotConnected;
@@ -670,7 +690,6 @@ void CSpaceWarClient::OnLobbyCreated( LobbyCreated_t *pCallback, bool bIOFailure
}
}
//-----------------------------------------------------------------------------
// Purpose: Finishes up entering a lobby
//-----------------------------------------------------------------------------
@@ -679,26 +698,21 @@ void CSpaceWarClient::OnLobbyEntered( LobbyEnter_t *pCallback, bool bIOFailure )
if ( m_eGameState != k_EClientJoiningLobby )
return;
if ( pCallback->m_EChatRoomEnterResponse != k_EChatRoomEnterResponseSuccess )
{
// failed, show error
SetConnectionFailureText( "Failed to enter lobby" );
SetGameState( k_EClientGameConnectionFailure );
return;
}
// success
// move forward the state
SetGameState( k_EClientInLobby );
m_steamIDLobby = pCallback->m_ulSteamIDLobby;
m_pLobby->SetLobbySteamID( m_steamIDLobby );
}
void CSpaceWarClient::OnLobbyDataChange( LobbyDataUpdate_t *pCallback, bool bIOFailure )
{
OutputDebugStringA( "OnLobbyDataChange ");
CSteamID steamIDLobbyMember( pCallback->m_ulSteamIDMember );
}
void CSpaceWarClient::OnLobbyChatUpdate( LobbyChatUpdate_t *pCallback, bool bIOFailure )
{
CSteamID steamIDLobbyMember( pCallback->m_ulSteamIDUserChanged );
CSteamID steamIDLobbyMember2( pCallback->m_ulSteamIDMakingChange );
OutputDebugStringA( "OnLobbyChatUpdate ");
}
//-----------------------------------------------------------------------------
// Purpose: Joins a game from a lobby
@@ -716,6 +730,14 @@ void CSpaceWarClient::OnLobbyGameCreated( LobbyGameCreated_t *pCallback )
}
//-----------------------------------------------------------------------------
// Purpose: a large avatar image has been loaded for us
//-----------------------------------------------------------------------------
void CSpaceWarClient::OnAvatarImageLoaded( AvatarImageLoaded_t *pCallback )
{
}
//-----------------------------------------------------------------------------
// Purpose: Handles menu actions in a lobby
//-----------------------------------------------------------------------------
@@ -746,6 +768,7 @@ void CSpaceWarClient::OnMenuSelection( LobbyMenuItem_t selection )
// broadcast to everyone in the lobby that the game is starting
SteamMatchmaking()->SetLobbyData( m_steamIDLobby, "game_starting", "1" );
// start a local game server
m_pServer = new CSpaceWarServer( m_pGameEngine );
// we'll have to wait until the game server connects to the Steam server back-end
@@ -831,10 +854,12 @@ void CSpaceWarClient::OnGameStateChanged( EClientGameState eGameStateNew )
void CSpaceWarClient::OnIPCFailure( IPCFailure_t *failure )
{
static bool bExiting = false;
if ( ! bExiting )
if ( !bExiting )
{
OutputDebugString( "Steam IPC Failure, shutting down\n" );
#if defined( WIN32 )
::MessageBoxA( NULL, "Connection to Steam Lost, Exiting", "Steam Connection Error", MB_OK );
#endif
m_pGameEngine->Shutdown();
bExiting = true;
}
@@ -972,8 +997,9 @@ void CSpaceWarClient::RunFrame()
if ( m_pP2PAuthedGame )
m_pP2PAuthedGame->EndGame();
if ( m_eConnectedStatus == k_EClientConnectedAndAuthenticated )
{
SteamUser()->TerminateGameConnection( m_unServerIP, m_usServerPort );
}
m_GameServerPing.CancelPing();
SetConnectionFailureText( "Timed out connecting to game server" );
SetGameState( k_EClientGameConnectionFailure );
@@ -1025,10 +1051,11 @@ void CSpaceWarClient::RunFrame()
break;
case k_EClientMinidump:
#ifndef _PS3
RaiseException( EXCEPTION_NONCONTINUABLE_EXCEPTION,
EXCEPTION_NONCONTINUABLE,
0, NULL );
#endif
SetGameState( k_EClientGameMenu );
break;
@@ -1095,10 +1122,10 @@ void CSpaceWarClient::RunFrame()
if ( m_eConnectedStatus == k_EClientConnectedAndAuthenticated && m_rgpShips[ m_uPlayerShipIndex ] )
{
MsgClientSendLocalUpdate_t msg;
msg.m_uShipPosition = m_uPlayerShipIndex;
msg.SetShipPosition( m_uPlayerShipIndex );
// If this fails, it probably just means its not time to send an update yet
if ( m_rgpShips[ m_uPlayerShipIndex ]->BGetClientUpdateData( &msg.m_ClientUpdateData ) )
if ( m_rgpShips[ m_uPlayerShipIndex ]->BGetClientUpdateData( msg.AccessUpdateData() ) )
BSendServerData( &msg, sizeof( msg ) );
}
@@ -1172,7 +1199,16 @@ void CSpaceWarClient::RunFrame()
void CSpaceWarClient::DrawHUDText()
{
// Padding from the edge of the screen for hud elements
const int32 nHudPadding = 15;
#ifdef _PS3
// Larger padding on PS3, since many of our test HDTVs truncate
// edges of the screen and can't be calibrated properly.
const int32 nHudPaddingVertical = 20;
const int32 nHudPaddingHorizontal = 35;
#else
const int32 nHudPaddingVertical = 15;
const int32 nHudPaddingHorizontal = 15;
#endif
const int32 width = m_pGameEngine->GetViewportWidth();
const int32 height = m_pGameEngine->GetViewportHeight();
@@ -1182,7 +1218,7 @@ void CSpaceWarClient::DrawHUDText()
const int32 nSpaceBetweenAvatarAndScore = 6;
LONG scorewidth = LONG((m_pGameEngine->GetViewportWidth() - nHudPadding*2.0f)/4.0f);
LONG scorewidth = LONG((m_pGameEngine->GetViewportWidth() - nHudPaddingHorizontal*2.0f)/4.0f);
char rgchBuffer[256];
for( uint32 i=0; i<MAX_PLAYERS_PER_SERVER; ++i )
@@ -1207,18 +1243,20 @@ void CSpaceWarClient::DrawHUDText()
}
// We also want to use the Steam Avatar image inside the HUD if it is available.
// We look it up via GetFriendAvatar, which returns an image index we use
// We look it up via GetMediumFriendAvatar, which returns an image index we use
// to look up the actual RGBA data below.
int iImage = SteamFriends()->GetFriendAvatar( m_rgSteamIDPlayers[i], k_EAvatarSize64x64 );
HGAMETEXTURE hTexture = GetSteamImageAsTexture( iImage );
int iImage = SteamFriends()->GetMediumFriendAvatar( m_rgSteamIDPlayers[i] );
HGAMETEXTURE hTexture = NULL;
if ( iImage != -1 )
hTexture = GetSteamImageAsTexture( iImage );
RECT rect;
switch( i )
{
case 0:
rect.top = nHudPadding;
rect.top = nHudPaddingVertical;
rect.bottom = rect.top+nAvatarHeight;
rect.left = nHudPadding;
rect.left = nHudPaddingHorizontal;
rect.right = rect.left + scorewidth;
if ( hTexture )
@@ -1230,14 +1268,14 @@ void CSpaceWarClient::DrawHUDText()
}
_snprintf( rgchBuffer, sizeof( rgchBuffer), "%s\nScore: %2u", rgchPlayerName, m_rguPlayerScores[i] );
m_pGameEngine->BDrawString( m_hHUDFont, rect, g_rgPlayerColors[i], DT_LEFT|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hHUDFont, rect, g_rgPlayerColors[i], TEXTPOS_LEFT|TEXTPOS_VCENTER, rgchBuffer );
break;
case 1:
rect.top = nHudPadding;
rect.top = nHudPaddingVertical;
rect.bottom = rect.top+nAvatarHeight;
rect.left = width-nHudPadding-scorewidth;
rect.right = width-nHudPadding;
rect.left = width-nHudPaddingHorizontal-scorewidth;
rect.right = width-nHudPaddingHorizontal;
if ( hTexture )
{
@@ -1248,12 +1286,12 @@ void CSpaceWarClient::DrawHUDText()
}
_snprintf( rgchBuffer, sizeof( rgchBuffer), "%s\nScore: %2u", rgchPlayerName, m_rguPlayerScores[i] );
m_pGameEngine->BDrawString( m_hHUDFont, rect, g_rgPlayerColors[i], DT_RIGHT|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hHUDFont, rect, g_rgPlayerColors[i], TEXTPOS_RIGHT|TEXTPOS_VCENTER, rgchBuffer );
break;
case 2:
rect.top = height-nHudPadding-nAvatarHeight;
rect.top = height-nHudPaddingVertical-nAvatarHeight;
rect.bottom = rect.top+nAvatarHeight;
rect.left = nHudPadding;
rect.left = nHudPaddingHorizontal;
rect.right = rect.left + scorewidth;
if ( hTexture )
@@ -1265,13 +1303,13 @@ void CSpaceWarClient::DrawHUDText()
}
_snprintf( rgchBuffer, sizeof( rgchBuffer), "%s\nScore: %2u", rgchPlayerName, m_rguPlayerScores[i] );
m_pGameEngine->BDrawString( m_hHUDFont, rect, g_rgPlayerColors[i], DT_LEFT|DT_BOTTOM, rgchBuffer );
m_pGameEngine->BDrawString( m_hHUDFont, rect, g_rgPlayerColors[i], TEXTPOS_LEFT|TEXTPOS_BOTTOM, rgchBuffer );
break;
case 3:
rect.top = height-nHudPadding-nAvatarHeight;
rect.top = height-nHudPaddingVertical-nAvatarHeight;
rect.bottom = rect.top+nAvatarHeight;
rect.left = width-nHudPadding-scorewidth;
rect.right = width-nHudPadding;
rect.left = width-nHudPaddingHorizontal-scorewidth;
rect.right = width-nHudPaddingHorizontal;
if ( hTexture )
{
@@ -1282,7 +1320,7 @@ void CSpaceWarClient::DrawHUDText()
}
_snprintf( rgchBuffer, sizeof( rgchBuffer), "%s\nScore: %2u", rgchPlayerName, m_rguPlayerScores[i] );
m_pGameEngine->BDrawString( m_hHUDFont, rect, g_rgPlayerColors[i], DT_RIGHT|DT_BOTTOM, rgchBuffer );
m_pGameEngine->BDrawString( m_hHUDFont, rect, g_rgPlayerColors[i], TEXTPOS_RIGHT|TEXTPOS_BOTTOM, rgchBuffer );
break;
default:
OutputDebugString( "DrawHUDText() needs updating for more players\n" );
@@ -1306,8 +1344,13 @@ void CSpaceWarClient::DrawInstructions()
rect.right = width;
char rgchBuffer[256];
#ifdef _PS3
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Turn Ship Left: 'Left'\nTurn Ship Right: 'Right'\nForward Thrusters: 'R2'\nReverse Thrusters: 'L2'\nFire Photon Beams: 'Cross'" );
#else
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Turn Ship Left: 'A'\nTurn Ship Right: 'D'\nForward Thrusters: 'W'\nReverse Thrusters: 'S'\nFire Photon Beams: 'Space'" );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
#endif
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
rect.left = 0;
@@ -1316,7 +1359,7 @@ void CSpaceWarClient::DrawInstructions()
rect.bottom = m_pGameEngine->GetViewportHeight();
_snprintf( rgchBuffer, sizeof( rgchBuffer ), "Press ESC to return to the Main Menu" );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_TOP, rgchBuffer );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_TOP, rgchBuffer );
}
@@ -1349,7 +1392,7 @@ void CSpaceWarClient::DrawConnectionAttemptText()
else
_snprintf( rgchBuffer, sizeof( rgchBuffer ), "Connecting to server%s", rgchTimeoutString );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
}
@@ -1368,7 +1411,7 @@ void CSpaceWarClient::DrawConnectionFailureText()
char rgchBuffer[256];
_snprintf( rgchBuffer, sizeof( rgchBuffer), "%s\n", m_rgchErrorText );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
rect.left = 0;
rect.right = width;
@@ -1376,7 +1419,7 @@ void CSpaceWarClient::DrawConnectionFailureText()
rect.bottom = m_pGameEngine->GetViewportHeight();
_snprintf( rgchBuffer, sizeof( rgchBuffer ), "Press ESC to return to the Main Menu" );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_TOP, rgchBuffer );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_TOP, rgchBuffer );
}
@@ -1397,16 +1440,16 @@ void CSpaceWarClient::DrawWinnerDrawOrWaitingText()
if ( m_eGameState == k_EClientGameWaitingForPlayers )
{
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Server is waiting for players.\n\nStarting in %d seconds...", nSecondsToRestart );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
}
else if ( m_eGameState == k_EClientGameDraw )
{
_snprintf( rgchBuffer, sizeof( rgchBuffer), "The round is a draw!\n\nStarting again in %d seconds...", nSecondsToRestart );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
}
else if ( m_eGameState == k_EClientGameWinner )
{
if ( m_uPlayerWhoWonGame < 0 || m_uPlayerWhoWonGame >= MAX_PLAYERS_PER_SERVER )
if ( m_uPlayerWhoWonGame >= MAX_PLAYERS_PER_SERVER )
{
OutputDebugString( "Invalid winner value\n" );
return;
@@ -1424,7 +1467,7 @@ void CSpaceWarClient::DrawWinnerDrawOrWaitingText()
_snprintf( rgchBuffer, sizeof( rgchBuffer), "%s wins!\n\nStarting again in %d seconds...", rgchPlayerName, nSecondsToRestart );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hInstructionsFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
}
}
@@ -1436,7 +1479,7 @@ bool CSpaceWarClient::BLocalPlayerWonLastGame()
{
if ( m_eGameState == k_EClientGameWinner )
{
if ( m_uPlayerWhoWonGame < 0 || m_uPlayerWhoWonGame >= MAX_PLAYERS_PER_SERVER )
if ( m_uPlayerWhoWonGame >= MAX_PLAYERS_PER_SERVER )
{
// ur
return false;
@@ -1511,3 +1554,71 @@ HGAMETEXTURE CSpaceWarClient::GetSteamImageAsTexture( int iImage )
return hTexture;
}
//-----------------------------------------------------------------------------
// Purpose: Request an encrypted app ticket
//-----------------------------------------------------------------------------
uint32 k_unSecretData = 0x5444;
void CSpaceWarClient::RetrieveEncryptedAppTicket()
{
SteamAPICall_t hSteamAPICall = SteamUser()->RequestEncryptedAppTicket( &k_unSecretData, sizeof( k_unSecretData ) );
m_SteamCallResultEncryptedAppTicket.Set( hSteamAPICall, this, &CSpaceWarClient::OnRequestEncryptedAppTicket );
}
//-----------------------------------------------------------------------------
// Purpose: Called when requested app ticket asynchronously completes
//-----------------------------------------------------------------------------
void CSpaceWarClient::OnRequestEncryptedAppTicket( EncryptedAppTicketResponse_t *pEncryptedAppTicketResponse, bool bIOFailure )
{
if ( bIOFailure )
return;
if ( pEncryptedAppTicketResponse->m_eResult == k_EResultOK )
{
uint8 rgubTicket[1024];
uint32 cubTicket;
SteamUser()->GetEncryptedAppTicket( rgubTicket, sizeof( rgubTicket), &cubTicket );
// normally at this point you transmit the encrypted ticket to the service that knows the decryption key
// this code is just to demonstrate the ticket cracking library
// included is the "secret" key for spacewar. normally this is secret
const uint8 rgubKey[k_nSteamEncryptedAppTicketSymmetricKeyLen] = { 0xed, 0x93, 0x86, 0x07, 0x36, 0x47, 0xce, 0xa5, 0x8b, 0x77, 0x21, 0x49, 0x0d, 0x59, 0xed, 0x44, 0x57, 0x23, 0xf0, 0xf6, 0x6e, 0x74, 0x14, 0xe1, 0x53, 0x3b, 0xa3, 0x3c, 0xd8, 0x03, 0xbd, 0xbd };
uint8 rgubDecrypted[1024];
uint32 cubDecrypted = sizeof( rgubDecrypted );
if ( !SteamEncryptedAppTicket_BDecryptTicket( rgubTicket, cubTicket, rgubDecrypted, &cubDecrypted, rgubKey, sizeof( rgubKey ) ) )
{
OutputDebugString( "Ticket failed to decrypt\n" );
return;
}
if ( !SteamEncryptedAppTicket_BIsTicketForApp( rgubDecrypted, cubDecrypted, SteamUtils()->GetAppID() ) )
OutputDebugString( "Ticket for wrong app id\n" );
CSteamID steamIDFromTicket;
SteamEncryptedAppTicket_GetTicketSteamID( rgubDecrypted, cubDecrypted, &steamIDFromTicket );
if ( steamIDFromTicket != SteamUser()->GetSteamID() )
OutputDebugString( "Ticket for wrong user\n" );
uint32 cubData;
uint32 *punSecretData = (uint32 *)SteamEncryptedAppTicket_GetUserVariableData( rgubDecrypted, cubDecrypted, &cubData );
if ( cubData != sizeof( uint32 ) || *punSecretData != k_unSecretData )
OutputDebugString( "Failed to retrieve secret data\n" );
}
else if ( pEncryptedAppTicketResponse->m_eResult == k_EResultLimitExceeded )
{
OutputDebugString( "Calling RequestEncryptedAppTicket more than once per minute returns this error\n" );
}
else if ( pEncryptedAppTicketResponse->m_eResult == k_EResultDuplicateRequest )
{
OutputDebugString( "Calling RequestEncryptedAppTicket while there is already a pending request results in this error\n" );
}
else if ( pEncryptedAppTicketResponse->m_eResult == k_EResultNoConnection )
{
OutputDebugString( "Calling RequestEncryptedAppTicket while not connected to steam results in this error\n" );
}
}
+23 -13
View File
@@ -15,9 +15,14 @@
#include "StarField.h"
#include "Sun.h"
#include "Ship.h"
#include "steam\steam_api.h"
#include "StatsAndAchievements.h"
#include "RemoteStorage.h"
// Must define this stuff before BaseMenu.h as it depends on calling back into us through these accessors
class CSpaceWarClient;
extern CSpaceWarClient *g_pSpaceWarClient;
CSpaceWarClient *SpaceWarClient();
#include "BaseMenu.h"
// Forward class declaration
@@ -89,7 +94,10 @@ class CSpaceWarClient
{
public:
//Constructor
CSpaceWarClient( CGameEngine *pEngine, CSteamID steamIDUser );
CSpaceWarClient( IGameEngine *pEngine, CSteamID steamIDUser );
// Shared init for all constructors
void Init( IGameEngine *pGameEngine );
// Destructor
~CSpaceWarClient();
@@ -153,7 +161,10 @@ public:
CSteamID GetLocalSteamID() { return m_SteamIDLocalUser; }
// Get the local players name
const char* GetLocalPlayerName() { return SteamFriends()->GetFriendPersonaName( m_SteamIDLocalUser ); }
const char* GetLocalPlayerName()
{
return SteamFriends()->GetFriendPersonaName( m_SteamIDLocalUser );
}
// Scale screen size to "real" size
float PixelsToFeet( float flPixels );
@@ -161,6 +172,8 @@ public:
// Get a Steam-supplied image
HGAMETEXTURE GetSteamImageAsTexture( int iImage );
void RetrieveEncryptedAppTicket();
private:
// Receive a response from the server for a connection attempt
@@ -170,7 +183,7 @@ private:
void OnReceiveServerAuthenticationResponse( bool bSuccess, uint32 uPlayerPosition );
// Receive a state update from the server
void OnReceiveServerUpdate( ServerSpaceWarUpdateData_t UpdateData );
void OnReceiveServerUpdate( ServerSpaceWarUpdateData_t *pUpdateData );
// Handle the server exiting
void OnReceiveServerExiting();
@@ -313,7 +326,7 @@ private:
CQuitMenu *m_pQuitMenu;
// pointer to game engine instance we are running under
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// track which steam image indexes we have textures for, and what handle that texture has
std::map<int, HGAMETEXTURE> m_MapSteamImagesToTextures;
@@ -336,13 +349,9 @@ private:
void OnLobbyEntered( LobbyEnter_t *pCallback, bool bIOFailure );
CCallResult<CSpaceWarClient, LobbyEnter_t> m_SteamCallResultLobbyEntered;
void OnLobbyDataChange( LobbyDataUpdate_t *pCallback, bool bIOFailure );
CCallResult<CSpaceWarClient, LobbyDataUpdate_t> m_SteamCallResultLobbyDataChange;
void OnLobbyChatUpdate( LobbyChatUpdate_t *pCallback, bool bIOFailure );
CCallResult<CSpaceWarClient, LobbyChatUpdate_t> m_SteamCallResultLobbyChatUpdate;
// callback for when the lobby game server has started
STEAM_CALLBACK( CSpaceWarClient, OnLobbyGameCreated, LobbyGameCreated_t, m_LobbyGameCreated );
STEAM_CALLBACK( CSpaceWarClient, OnAvatarImageLoaded, AvatarImageLoaded_t, m_AvatarImageLoadedCreated );
// lobby browser menu
CLobbyBrowser *m_pLobbyBrowser;
@@ -360,9 +369,10 @@ private:
// Steam wants to shut down, Game for Windows applications should shutdown too
STEAM_CALLBACK( CSpaceWarClient, OnSteamShutdown, SteamShutdown_t, m_SteamShutdownCallback );
// Called when SteamUser()->RequestEncryptedAppTicket() returns asynchronously
void OnRequestEncryptedAppTicket( EncryptedAppTicketResponse_t *pEncryptedAppTicketResponse, bool bIOFailure );
CCallResult< CSpaceWarClient, EncryptedAppTicketResponse_t > m_SteamCallResultEncryptedAppTicket;
};
extern CSpaceWarClient *g_pSpaceWarClient;
CSpaceWarClient *SpaceWarClient();
#endif // SPACEWARCLIENT_H
+2 -2
View File
@@ -14,7 +14,7 @@
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CSpaceWarEntity::CSpaceWarEntity( CGameEngine *pGameEngine, uint32 uCollisionRadius, bool bAffectedByGravity )
CSpaceWarEntity::CSpaceWarEntity( IGameEngine *pGameEngine, uint32 uCollisionRadius, bool bAffectedByGravity )
: CVectorEntity( pGameEngine, uCollisionRadius )
{
m_bAffectedByGravity = bAffectedByGravity;
@@ -37,7 +37,7 @@ void CSpaceWarEntity::RunFrame()
float distanceToSun = (float)sqrt( pow( xPosSun - GetXPos(), 2 ) + pow( yPosSun - GetYPos(), 2 ) );
float distancePower = (float)pow( distanceToSun, 2.0f ); // gravity power falls off exponentially
float factor = min( 5200000.0f / distancePower, 150.0f ); // arbitrary value for power of gravity
float factor = MIN( 5200000.0f / distancePower, 150.0f ); // arbitrary value for power of gravity
float xDirection = (GetXPos() - xPosSun)/distanceToSun;
float yDirection = (GetYPos() - yPosSun)/distanceToSun;
+1 -1
View File
@@ -16,7 +16,7 @@ class CSpaceWarEntity : public CVectorEntity
{
public:
// Constructor
CSpaceWarEntity( CGameEngine *pGameEngine, uint32 uCollisionRadius, bool bAffectedByGravity );
CSpaceWarEntity( IGameEngine *pGameEngine, uint32 uCollisionRadius, bool bAffectedByGravity );
// Destructor
virtual ~CSpaceWarEntity() { return; }
+68 -48
View File
@@ -10,11 +10,18 @@
#include "SpaceWarClient.h"
#include "stdlib.h"
#include "time.h"
#include <math.h>
#ifdef _PS3
// From main.cpp
extern SteamPS3Params_t g_SteamPS3Params;
#endif
//-----------------------------------------------------------------------------
// Purpose: Constructor -- note the syntax for setting up Steam API callback handlers
//-----------------------------------------------------------------------------
CSpaceWarServer::CSpaceWarServer( CGameEngine *pGameEngine ) :
CSpaceWarServer::CSpaceWarServer( IGameEngine *pGameEngine )
:
m_CallbackSteamServersConnected( this, &CSpaceWarServer::OnSteamServersConnected ),
m_CallbackSteamServersDisconnected( this, &CSpaceWarServer::OnSteamServersDisconnected ),
m_CallbackSteamServersConnectFailure( this, &CSpaceWarServer::OnSteamServersConnectFailure ),
@@ -27,6 +34,7 @@ CSpaceWarServer::CSpaceWarServer( CGameEngine *pGameEngine ) :
{
m_bConnectedToSteam = false;
char *pchGameDir = "spacewar";
uint32 unIP = INADDR_ANY;
uint16 usSpectatorPort = 0; // We don't support specators in our game
@@ -41,7 +49,11 @@ CSpaceWarServer::CSpaceWarServer( CGameEngine *pGameEngine ) :
// Initialize the SteamGameServer interface, we tell it some info about us, and we request support
// for both Authentication (making sure users own games) and secure mode, VAC running in our game
// and kicking users who are VAC banned
#ifdef _PS3
if ( !SteamGameServer_Init( &g_SteamPS3Params, unIP, SPACEWAR_AUTHENTICATION_PORT, SPACEWAR_SERVER_PORT, usSpectatorPort, usMasterServerUpdaterPort, eMode, pchGameDir, SPACEWAR_SERVER_VERSION ) )
#else
if ( !SteamGameServer_Init( unIP, SPACEWAR_AUTHENTICATION_PORT, SPACEWAR_SERVER_PORT, usSpectatorPort, usMasterServerUpdaterPort, eMode, pchGameDir, SPACEWAR_SERVER_VERSION ) )
#endif
{
OutputDebugString( "SteamGameServer_Init call failed\n" );
}
@@ -180,7 +192,6 @@ bool CSpaceWarServer::BSendDataToClient( uint32 uShipIndex, char *pData, uint32
OutputDebugString( "Failed sending data to a client\n" );
return false;
}
return true;
}
@@ -199,7 +210,6 @@ bool CSpaceWarServer::BSendDataToPendingClient( uint32 uShipIndex, char *pData,
OutputDebugString( "Failed sending data to a pending client\n" );
return false;
}
return true;
}
@@ -209,7 +219,7 @@ bool CSpaceWarServer::BSendDataToPendingClient( uint32 uShipIndex, char *pData,
//-----------------------------------------------------------------------------
void CSpaceWarServer::OnClientBeginAuthentication( CSteamID steamIDClient, void *pToken, uint32 uTokenLen )
{
// First, check this isn't a duplicate and we already have a user logged on from the same ip/port combo
// First, check this isn't a duplicate and we already have a user logged on from the same steamid
for( uint32 i = 0; i < MAX_PLAYERS_PER_SERVER; ++i )
{
if ( m_rgClientData[i].m_SteamIDUser == steamIDClient )
@@ -243,7 +253,6 @@ void CSpaceWarServer::OnClientBeginAuthentication( CSteamID steamIDClient, void
if ( !m_rgPendingClientData[i].m_bActive )
{
m_rgPendingClientData[i].m_ulTickCountLastData = m_pGameEngine->GetGameTickCount();
#ifdef USE_GS_AUTH_API
// authenticate the user with the Steam back-end servers
@@ -311,7 +320,7 @@ void CSpaceWarServer::OnAuthCompleted( bool bAuthSuccessful, uint32 iPendingAuth
m_rgpShips[i]->SetDisabled( true );
MsgServerPassAuthentication_t msg;
msg.m_uPlayerPosition = i;
msg.SetPlayerPosition( i );
BSendDataToClient( i, (char*)&msg, sizeof( msg ) );
bAddedOk = true;
@@ -500,26 +509,26 @@ void CSpaceWarServer::ReceiveNetworkData()
if ( !SteamGameServerNetworking()->ReadP2PPacket( pchRecvBuf, cubMsgSize, &cubMsgSize, &steamIDRemote ) )
break;
if ( cubMsgSize < sizeof( EMessage ) )
if ( cubMsgSize < sizeof( DWORD ) )
{
OutputDebugString( "Got garbage on server socket, too short\n" );
continue;
}
EMessage *pEMsg = (EMessage*)pchRecvBuf;
switch ( *pEMsg )
EMessage eMsg = (EMessage)LittleDWord( *(DWORD*)pchRecvBuf );
switch ( eMsg )
{
case k_EMsgClientInitiateConnection:
{
// We always let clients do this without even checking for room on the server since we reserve that for
// the authentication phase of the connection which comes next
MsgServerSendInfo_t msg;
msg.m_ulSteamIDServer = SteamGameServer()->GetSteamID().ConvertToUint64();
msg.SetSteamIDServer( SteamGameServer()->GetSteamID().ConvertToUint64() );
#ifdef USE_GS_AUTH_API
// You can only make use of VAC when using the Steam authentication system
msg.m_bIsVACSecure = SteamGameServer()->BSecure();
msg.SetSecure( SteamGameServer()->BSecure() );
#endif
_snprintf( msg.m_rgchServerName, sizeof( msg.m_rgchServerName ), "%s", m_sServerName.c_str() );
msg.SetServerName( m_sServerName.c_str() );
SteamGameServerNetworking()->SendP2PPacket( steamIDRemote, &msg, sizeof( MsgServerSendInfo_t ), k_EP2PSendReliable );
}
break;
@@ -532,7 +541,7 @@ void CSpaceWarServer::ReceiveNetworkData()
}
MsgClientBeginAuthentication_t *pMsg = (MsgClientBeginAuthentication_t*)pchRecvBuf;
#ifdef USE_GS_AUTH_API
OnClientBeginAuthentication( steamIDRemote, &pMsg->m_rgchToken, pMsg->m_uTokenLen );
OnClientBeginAuthentication( steamIDRemote, (void*)pMsg->GetTokenPtr(), pMsg->GetTokenLen() );
#else
OnClientBeginAuthentication( steamIDRemote, 0 );
#endif
@@ -554,7 +563,7 @@ void CSpaceWarServer::ReceiveNetworkData()
{
bFound = true;
MsgClientSendLocalUpdate_t *pMsg = (MsgClientSendLocalUpdate_t*)pchRecvBuf;
OnReceiveClientUpdateData( i, pMsg->m_ClientUpdateData );
OnReceiveClientUpdateData( i, pMsg->AccessUpdateData() );
break;
}
}
@@ -570,36 +579,42 @@ void CSpaceWarServer::ReceiveNetworkData()
}
break;
case k_EMsgClientLeavingServer:
if ( cubMsgSize != sizeof( MsgClientLeavingServer_t ) )
{
OutputDebugString( "Bad leaving server msg\n" );
continue;
}
// Find the connection that should exist for this users address
bool bFound = false;
for( uint32 i=0; i<MAX_PLAYERS_PER_SERVER; ++i )
{
if ( m_rgClientData[i].m_SteamIDUser == steamIDRemote )
if ( cubMsgSize != sizeof( MsgClientLeavingServer_t ) )
{
bFound = true;
RemovePlayerFromServer( i );
break;
OutputDebugString( "Bad leaving server msg\n" );
continue;
}
// Find the connection that should exist for this users address
bool bFound = false;
for( uint32 i=0; i<MAX_PLAYERS_PER_SERVER; ++i )
{
if ( m_rgClientData[i].m_SteamIDUser == steamIDRemote )
{
bFound = true;
RemovePlayerFromServer( i );
break;
}
// Also check for pending connections that may match
if ( m_rgPendingClientData[i].m_SteamIDUser == steamIDRemote )
{
#ifdef USE_GS_AUTH_API
// Tell the GS the user is leaving the server
SteamGameServer()->SendUserDisconnect( m_rgPendingClientData[i].m_SteamIDUser );
#endif
// Clear our data on the user
memset( &m_rgPendingClientData[i], 0 , sizeof( ClientConnectionData_t ) );
break;
// Also check for pending connections that may match
if ( m_rgPendingClientData[i].m_SteamIDUser == steamIDRemote )
{
#ifdef USE_GS_AUTH_API
// Tell the GS the user is leaving the server
SteamGameServer()->SendUserDisconnect( m_rgPendingClientData[i].m_SteamIDUser );
#endif
// Clear our data on the user
memset( &m_rgPendingClientData[i], 0 , sizeof( ClientConnectionData_t ) );
break;
}
}
if ( !bFound )
OutputDebugString( "Got a client leaving server msg, but couldn't find a matching client\n" );
}
if ( !bFound )
OutputDebugString( "Got a client leaving server msg, but couldn't find a matching client\n" );
default:
char rgch[128];
_snprintf( rgch, 128, "Invalid message %x\n", eMsg );
OutputDebugString( rgch );
}
}
@@ -714,20 +729,20 @@ void CSpaceWarServer::SendUpdateDataToAllClients()
MsgServerUpdateWorld_t msg;
msg.m_ServerUpdateData.m_eCurrentGameState = m_eGameState;
msg.AccessUpdateData()->SetServerGameState( m_eGameState );
for( int i=0; i<MAX_PLAYERS_PER_SERVER; ++i )
{
msg.m_ServerUpdateData.m_rgPlayersActive[i] = m_rgClientData[i].m_bActive;
msg.m_ServerUpdateData.m_rgPlayerScores[i] = m_rguPlayerScores[i];
msg.m_ServerUpdateData.m_rgPlayerSteamIDs[i] = m_rgClientData[i].m_SteamIDUser.ConvertToUint64();
msg.AccessUpdateData()->SetPlayerActive( i, m_rgClientData[i].m_bActive );
msg.AccessUpdateData()->SetPlayerScore( i, m_rguPlayerScores[i] );
msg.AccessUpdateData()->SetPlayerSteamID( i, m_rgClientData[i].m_SteamIDUser.ConvertToUint64() );
if ( m_rgpShips[i] )
{
m_rgpShips[i]->BuildServerUpdate( &msg.m_ServerUpdateData.m_rgShipData[i] );
m_rgpShips[i]->BuildServerUpdate( msg.AccessUpdateData()->AccessShipUpdateData( i ) );
}
}
msg.m_ServerUpdateData.m_uPlayerWhoWonGame = m_uPlayerWhoWonGame;
msg.AccessUpdateData()->SetPlayerWhoWon( m_uPlayerWhoWonGame );
for( int i=0; i<MAX_PLAYERS_PER_SERVER; ++i )
{
@@ -742,12 +757,12 @@ void CSpaceWarServer::SendUpdateDataToAllClients()
//-----------------------------------------------------------------------------
// Purpose: Receives update data from clients
//-----------------------------------------------------------------------------
void CSpaceWarServer::OnReceiveClientUpdateData( uint32 uShipIndex, ClientSpaceWarUpdateData_t UpdateData )
void CSpaceWarServer::OnReceiveClientUpdateData( uint32 uShipIndex, ClientSpaceWarUpdateData_t *pUpdateData )
{
if ( m_rgClientData[uShipIndex].m_bActive && m_rgpShips[uShipIndex] )
{
m_rgClientData[uShipIndex].m_ulTickCountLastData = m_pGameEngine->GetGameTickCount();
m_rgpShips[uShipIndex]->OnReceiveClientUpdate( UpdateData );
m_rgpShips[uShipIndex]->OnReceiveClientUpdate( pUpdateData );
}
}
@@ -863,6 +878,9 @@ void CSpaceWarServer::OnPolicyResponse( GSPolicyResponse_t *pPolicyResponse )
{
OutputDebugString( "SpaceWarServer is not VAC Secure!\n" );
}
char rgch[128];
_snprintf( rgch, 128, "Game server SteamID: %llu\n", SteamGameServer()->GetSteamID().ConvertToUint64() );
OutputDebugString( rgch );
#endif
}
@@ -892,7 +910,6 @@ void CSpaceWarServer::OnSteamServersConnectFailure( SteamServerConnectFailure_t
//-----------------------------------------------------------------------------
void CSpaceWarServer::SendUpdatedServerDetailsToSteam()
{
char *pchGameDir = "spacewar";
#ifdef USE_GS_AUTH_API
// Tell the Steam Master Server about our game
@@ -1030,6 +1047,10 @@ CSteamID CSpaceWarServer::GetSteamID()
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Kicks a player off the server
//-----------------------------------------------------------------------------
void CSpaceWarServer::KickPlayerOffServer( CSteamID steamID )
{
uint32 uPlayerCount = 0;
@@ -1053,5 +1074,4 @@ void CSpaceWarServer::KickPlayerOffServer( CSteamID steamID )
}
}
m_uPlayerCount = uPlayerCount;
}
+5 -7
View File
@@ -13,10 +13,6 @@
#include "Ship.h"
#include "Sun.h"
// Game server API code from Steam, lets us do authentication via Steam for who to allow to play,
// also lets us get ourselves listed in the Steam master server so the server browser can find us
#include "steam/steam_gameserver.h"
// Forward declaration
class CSpaceWarClient;
@@ -31,7 +27,7 @@ class CSpaceWarServer
{
public:
//Constructor
CSpaceWarServer( CGameEngine *pEngine );
CSpaceWarServer( IGameEngine *pEngine );
// Destructor
~CSpaceWarServer();
@@ -54,6 +50,7 @@ public:
// Checks various game objects for collisions and updates state appropriately if they have occurred
void CheckForCollisions();
// Kicks a given player off the server
void KickPlayerOffServer( CSteamID steamID );
// data accessors
@@ -66,6 +63,7 @@ private:
// connection to the Steam servers for authentication purposes.
//
// Tells us when we have successfully connected to Steam
STEAM_GAMESERVER_CALLBACK( CSpaceWarServer, OnSteamServersConnected, SteamServersConnected_t, m_CallbackSteamServersConnected );
@@ -101,7 +99,7 @@ private:
void SendUpdatedServerDetailsToSteam();
// Receive updates from client
void OnReceiveClientUpdateData( uint32 uShipIndex, ClientSpaceWarUpdateData_t UpdateData );
void OnReceiveClientUpdateData( uint32 uShipIndex, ClientSpaceWarUpdateData_t *pUpdateData );
// Send data to a client at the given ship index
bool BSendDataToClient( uint32 uShipIndex, char *pData, uint32 nSizeOfData );
@@ -156,7 +154,7 @@ private:
CSun *m_pSun;
// pointer to game engine instance we are running under
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Vector to keep track of client connections
ClientConnectionData_t m_rgClientData[MAX_PLAYERS_PER_SERVER];
+1 -1
View File
@@ -12,7 +12,7 @@
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CStarField::CStarField( CGameEngine *pGameEngine )
CStarField::CStarField( IGameEngine *pGameEngine )
{
m_pGameEngine = pGameEngine;
+2 -2
View File
@@ -23,7 +23,7 @@ class CStarField
{
public:
// Constructor
CStarField( CGameEngine *pGameEngine );
CStarField( IGameEngine *pGameEngine );
// Render the star field
void Render();
@@ -31,7 +31,7 @@ public:
private:
// Game engine instance we are running under
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Vector for starfield data
std::vector<StarVertex_t> m_VecStars;
+7 -8
View File
@@ -8,7 +8,6 @@
#include "stdafx.h"
#include "StatsAndAchievements.h"
#include <math.h>
#include "steam/isteamuserstats.h"
#include "SpaceWarClient.h"
#define ACHDISP_FONT_HEIGHT 20
@@ -36,9 +35,9 @@ Achievement_t g_rgAchievements[] =
// warning C4355: 'this' : used in base member initializer list
// This is OK because it's warning on setting up the Steam callbacks, they won't use this until after construction is done
#pragma warning( disable : 4355 )
CStatsAndAchievements::CStatsAndAchievements( CGameEngine *pGameEngine )
CStatsAndAchievements::CStatsAndAchievements( IGameEngine *pGameEngine )
:
m_pGameEngine( pGameEngine ),
m_pGameEngine( pGameEngine ),
m_pSteamUser( NULL ),
m_pSteamUserStats( NULL ),
m_GameID( SteamUtils()->GetAppID() ),
@@ -386,7 +385,7 @@ void CStatsAndAchievements::Render()
char rgchBuffer[256];
_snprintf( rgchBuffer, sizeof( rgchBuffer), "Unable to retrieve data from Steam\n" );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_VCENTER, rgchBuffer );
rect.left = 0;
@@ -395,7 +394,7 @@ void CStatsAndAchievements::Render()
rect.bottom = m_pGameEngine->GetViewportHeight();
_snprintf( rgchBuffer, sizeof( rgchBuffer ), "Press ESC to return to the Main Menu" );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_TOP, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_TOP, rgchBuffer );
}
else
@@ -485,7 +484,7 @@ void CStatsAndAchievements::Render()
char rgchBuffer[256];
_snprintf( rgchBuffer, sizeof( rgchBuffer ), "Press ESC to return to the Main Menu" );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_CENTER|DT_TOP, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_CENTER|TEXTPOS_TOP, rgchBuffer );
}
}
@@ -518,7 +517,7 @@ void CStatsAndAchievements::DrawAchievementInfo( RECT &rect, Achievement_t &ach
ach.m_bAchieved ? "Unlocked" : "Locked",
ach.m_rgchDescription );
m_pGameEngine->BDrawString( m_hDisplayFont, rect2, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_LEFT|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect2, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_LEFT|TEXTPOS_VCENTER, rgchBuffer );
}
void CStatsAndAchievements::DrawStatInfo( RECT &rect, const char *pchName, float flValue )
@@ -526,5 +525,5 @@ void CStatsAndAchievements::DrawStatInfo( RECT &rect, const char *pchName, float
// todo: divide up so can draw image
char rgchBuffer[256];
_snprintf( rgchBuffer, sizeof( rgchBuffer), "%s: %.1f", pchName, flValue );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), DT_LEFT|DT_VCENTER, rgchBuffer );
m_pGameEngine->BDrawString( m_hDisplayFont, rect, D3DCOLOR_ARGB( 255, 25, 200, 25 ), TEXTPOS_LEFT|TEXTPOS_VCENTER, rgchBuffer );
}
+2 -3
View File
@@ -10,7 +10,6 @@
#include "SpaceWar.h"
#include "GameEngine.h"
#include "steam/isteamuserstats.h"
enum EAchievements
{
@@ -38,7 +37,7 @@ class CStatsAndAchievements
{
public:
// Constructor
CStatsAndAchievements( CGameEngine *pGameEngine );
CStatsAndAchievements( IGameEngine *pGameEngine );
// Run a frame
void RunFrame();
@@ -77,7 +76,7 @@ private:
CGameID m_GameID;
// Engine
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
// Steam User interface
ISteamUser *m_pSteamUser;
+6
View File
@@ -6,13 +6,19 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F9B80FD0-A31F-443F-9FFF-85813D209141}.Debug|Win32.ActiveCfg = Debug|Win32
{F9B80FD0-A31F-443F-9FFF-85813D209141}.Debug|Win32.Build.0 = Debug|Win32
{F9B80FD0-A31F-443F-9FFF-85813D209141}.Debug|x64.ActiveCfg = Debug|x64
{F9B80FD0-A31F-443F-9FFF-85813D209141}.Debug|x64.Build.0 = Debug|x64
{F9B80FD0-A31F-443F-9FFF-85813D209141}.Release|Win32.ActiveCfg = Release|Win32
{F9B80FD0-A31F-443F-9FFF-85813D209141}.Release|Win32.Build.0 = Release|Win32
{F9B80FD0-A31F-443F-9FFF-85813D209141}.Release|x64.ActiveCfg = Release|x64
{F9B80FD0-A31F-443F-9FFF-85813D209141}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+185 -6
View File
@@ -5,13 +5,15 @@
Name="SteamworksExample"
ProjectGUID="{F9B80FD0-A31F-443F-9FFF-85813D209141}"
RootNamespace="SteamWorksExample"
SccProvider="MSSCCI:Perforce SCM"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
@@ -65,9 +67,9 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="steam_api.lib"
AdditionalDependencies="steam_api.lib sdkencryptedappticket.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="..\redistributable_bin;"
AdditionalLibraryDirectories="..\redistributable_bin;..\public\steam\lib\win32"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
@@ -95,6 +97,91 @@
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="copy ..\redistributable_bin\steam_api.dll $(OutDir)&#x0D;&#x0A;copy ..\public\steam\lib\win32\sdkencryptedappticket.dll $(OutDir)"
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="win64\$(ConfigurationName)"
IntermediateDirectory="win64\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
CommandLine=""
Outputs=""
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\public;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
ExceptionHandling="2"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="steam_api64.lib sdkencryptedappticket64.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="..\redistributable_bin\win64;..\public\steam\lib\win64"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="copy ..\redistributable_bin\win64\steam_api64.dll $(OutDir)&#x0D;&#x0A;copy ..\public\steam\lib\win64\sdkencryptedappticket64.dll $(OutDir)"
/>
</Configuration>
<Configuration
@@ -144,9 +231,9 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="steam_api.lib"
AdditionalDependencies="steam_api.lib sdkencryptedappticket.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="..\redistributable_bin;"
AdditionalLibraryDirectories="..\redistributable_bin;..\public\steam\lib\win32"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
@@ -176,6 +263,90 @@
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="copy ..\redistributable_bin\steam_api.dll $(OutDir)&#x0D;&#x0A;copy ..\public\steam\lib\win32\sdkencryptedappticket.dll $(OutDir)"
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="win64\$(ConfigurationName)"
IntermediateDirectory="win64\$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
CommandLine=""
Outputs=""
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\public;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS"
ExceptionHandling="2"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="steam_api64.lib sdkencryptedappticket64.lib"
LinkIncremental="1"
AdditionalLibraryDirectories="..\redistributable_bin\win64;..\public\steam\lib\win64"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine="copy ..\redistributable_bin\win64\steam_api64.dll $(OutDir)&#x0D;&#x0A;copy ..\public\steam\lib\win64\sdkencryptedappticket64.dll $(OutDir)"
/>
</Configuration>
</Configurations>
@@ -199,7 +370,7 @@
Name="Engine"
>
<File
RelativePath=".\GameEngine.cpp"
RelativePath=".\gameenginewin32.cpp"
>
</File>
<File
@@ -292,6 +463,10 @@
RelativePath=".\GameEngine.h"
>
</File>
<File
RelativePath=".\gameenginewin32.h"
>
</File>
<File
RelativePath=".\VectorEntity.h"
>
@@ -332,6 +507,10 @@
RelativePath=".\QuitMenu.h"
>
</File>
<File
RelativePath=".\RemoteStorage.h"
>
</File>
<File
RelativePath=".\ServerBrowser.h"
>
+1 -1
View File
@@ -13,7 +13,7 @@
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CSun::CSun( CGameEngine *pGameEngine ) : CSpaceWarEntity( pGameEngine, 2*SUN_VECTOR_SCALE_FACTOR, false )
CSun::CSun( IGameEngine *pGameEngine ) : CSpaceWarEntity( pGameEngine, 2*SUN_VECTOR_SCALE_FACTOR, false )
{
float xcenter = (float)pGameEngine->GetViewportWidth()/2;
float ycenter = (float)pGameEngine->GetViewportHeight()/2;
+1 -1
View File
@@ -17,7 +17,7 @@ class CSun : public CSpaceWarEntity
{
public:
// Constructor
CSun( CGameEngine *pGameEngine );
CSun( IGameEngine *pGameEngine );
// Run a frame
void RunFrame();
+2 -2
View File
@@ -15,7 +15,7 @@
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CVectorEntity::CVectorEntity( CGameEngine *pGameEngine, uint32 uCollisionRadius )
CVectorEntity::CVectorEntity( IGameEngine *pGameEngine, uint32 uCollisionRadius )
{
m_uCollisionRadius = uCollisionRadius;
m_pGameEngine = pGameEngine;
@@ -125,7 +125,7 @@ void CVectorEntity::RunFrame()
// Update our acceleration, velocity, and finally position
// Note: The min here is so we don't get massive acceleration if frames for some reason don't run for a bit
float ulElapsedSeconds = min( (float)m_pGameEngine->GetGameTicksFrameDelta() / 1000.0f, 2 );
float ulElapsedSeconds = MIN( (float)m_pGameEngine->GetGameTicksFrameDelta() / 1000.0f, 2 );
m_flXVelocity += m_flXAccel * ulElapsedSeconds;
m_flYVelocity += m_flYAccel * ulElapsedSeconds;
+2 -2
View File
@@ -26,7 +26,7 @@ class CVectorEntity
{
public:
// Constructor
CVectorEntity( CGameEngine *pGameEngine, uint32 uCollisionRadius );
CVectorEntity( IGameEngine *pGameEngine, uint32 uCollisionRadius );
// Destructor
virtual ~CVectorEntity();
@@ -105,7 +105,7 @@ protected:
protected:
// Game engine instance we are running under
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
private:
// Vector of points (always built 2 at a time so it's actually lines)
+23 -21
View File
@@ -13,7 +13,8 @@
//-----------------------------------------------------------------------------
// Purpose: constructor
//-----------------------------------------------------------------------------
CNetworkTransport::CNetworkTransport() :
CNetworkTransport::CNetworkTransport()
:
m_CallbackP2PSessionRequest( this, &CNetworkTransport::OnP2PSessionRequest ),
m_CallbackP2PSessionConnectFail( this, &CNetworkTransport::OnP2PSessionConnectFail )
{
@@ -26,9 +27,8 @@ CNetworkTransport::CNetworkTransport() :
bool CNetworkTransport::SendTicket( CSteamID steamIDFrom, CSteamID steamIDTo, uint32 cubTicket, uint8 *pubTicket )
{
MsgP2PSendingTicket_t msg;
msg.m_uTokenLen = cubTicket;
memcpy( msg.m_rgchToken, pubTicket, cubTicket );
msg.m_SteamID = steamIDFrom;
msg.SetToken( (char *)pubTicket, cubTicket );
msg.SetSteamID( steamIDFrom.ConvertToUint64() );
return SendNetMessage( steamIDTo, (void*)&msg, sizeof( msg ) );
}
@@ -75,7 +75,8 @@ void CNetworkTransport::OnP2PSessionConnectFail( P2PSessionConnectFail_t *pP2PSe
//-----------------------------------------------------------------------------
// Purpose: constructor
//-----------------------------------------------------------------------------
CP2PAuthPlayer::CP2PAuthPlayer( CGameEngine *pGameEngine, CNetworkTransport *pNetworkTransport ):m_CallbackBeginAuthResponse( this, &CP2PAuthPlayer::OnBeginAuthResponse )
CP2PAuthPlayer::CP2PAuthPlayer( IGameEngine *pGameEngine, CNetworkTransport *pNetworkTransport )
: m_CallbackBeginAuthResponse( this, &CP2PAuthPlayer::OnBeginAuthResponse )
{
m_pGameEngine = pGameEngine;
m_pNetworkTransport = pNetworkTransport;
@@ -108,7 +109,7 @@ void CP2PAuthPlayer::OnBeginAuthResponse( ValidateAuthTicketResponse_t *pCallbac
{
char rgch[128];
sprintf( rgch, "P2P:: Received steam response for account=%d\n", m_steamID.GetAccountID() );
OutputDebugStringA( rgch );
OutputDebugString( rgch );
m_ulAnswerTime = GetGameTimeInSeconds();
m_bHaveAnswer = true;
m_eAuthSessionResponse = pCallback->m_eAuthSessionResponse;
@@ -158,7 +159,7 @@ bool CP2PAuthPlayer::BIsAuthOk()
{
char rgch[128];
sprintf( rgch, "P2P:: Nothing received for account=%d\n", m_steamID.GetAccountID() );
OutputDebugStringA( rgch );
OutputDebugString( rgch );
return false;
}
}
@@ -167,7 +168,7 @@ bool CP2PAuthPlayer::BIsAuthOk()
{
char rgch[128];
sprintf( rgch, "P2P:: Ticket from account=%d was bad\n", m_steamID.GetAccountID() );
OutputDebugStringA( rgch );
OutputDebugString( rgch );
return false;
}
// second ticket check: if the steam backend replied, was that good?
@@ -175,7 +176,7 @@ bool CP2PAuthPlayer::BIsAuthOk()
{
char rgch[128];
sprintf( rgch, "P2P:: Steam response for account=%d was bad\n", m_steamID.GetAccountID() );
OutputDebugStringA( rgch );
OutputDebugString( rgch );
return false;
}
// last: if i sent him a ticket and he has not reciprocated, time out after 30 sec
@@ -185,7 +186,7 @@ bool CP2PAuthPlayer::BIsAuthOk()
{
char rgch[128];
sprintf( rgch, "P2P:: No ticket received for account=%d\n", m_steamID.GetAccountID() );
OutputDebugStringA( rgch );
OutputDebugString( rgch );
return false;
}
}
@@ -226,22 +227,23 @@ bool CP2PAuthPlayer::HandleMessage( EMessage eMsg, void *pMessage )
{
MsgP2PSendingTicket_t *pMsg = (MsgP2PSendingTicket_t*)pMessage;
// is this message for me?
if ( pMsg->m_SteamID != m_steamID )
if ( pMsg->GetSteamID() != m_steamID.ConvertToUint64() )
return false;
m_cubTicketHeGaveMe = pMsg->m_uTokenLen;
memcpy( m_rgubTicketHeGaveMe, pMsg->m_rgchToken, m_cubTicketHeGaveMe );
m_cubTicketHeGaveMe = pMsg->GetTokenLen();
memcpy( m_rgubTicketHeGaveMe, pMsg->GetTokenPtr(), m_cubTicketHeGaveMe );
m_eBeginAuthSessionResult = SteamUser()->BeginAuthSession( m_rgubTicketHeGaveMe, m_cubTicketHeGaveMe, m_steamID );
m_bSubmittedHisTicket = true;
char rgch[128];
sprintf( rgch, "P2P:: ReceivedTicket from account=%d \n", m_steamID.GetAccountID() );
OutputDebugStringA( rgch );
OutputDebugString( rgch );
if ( !m_bSentTicket )
StartAuthPlayer();
return true;
}
default:
{
OutputDebugStringA( "P2P:: Received unknown message on our listen socket\n" );
OutputDebugString( "P2P:: Received unknown message on our listen socket\n" );
break;
}
}
@@ -261,7 +263,7 @@ CSteamID CP2PAuthPlayer::GetSteamID()
//-----------------------------------------------------------------------------
// Purpose: constructor
//-----------------------------------------------------------------------------
CP2PAuthedGame::CP2PAuthedGame( CGameEngine *pGameEngine )
CP2PAuthedGame::CP2PAuthedGame( IGameEngine *pGameEngine )
{
m_pNetworkTransport = new CNetworkTransport;
m_pGameEngine = pGameEngine;
@@ -316,7 +318,7 @@ void CP2PAuthedGame::InternalInitPlayer( int iSlot, CSteamID steamID, bool bStar
{
char rgch[128];
sprintf( rgch, "P2P:: StartAuthPlayer slot=%d account=%d \n", iSlot, steamID.GetAccountID() );
OutputDebugStringA( rgch );
OutputDebugString( rgch );
m_rgpP2PAuthPlayer[iSlot] = new CP2PAuthPlayer( m_pGameEngine, m_pNetworkTransport );
m_rgpP2PAuthPlayer[iSlot]->InitPlayer( steamID );
if ( bStartAuthProcess )
@@ -329,7 +331,7 @@ void CP2PAuthedGame::InternalInitPlayer( int iSlot, CSteamID steamID, bool bStar
{
if ( m_rgpP2PAuthPlayer[i]->HandleMessage( k_EMsgP2PSendingTicket, m_rgpQueuedMessage[i] ) )
{
OutputDebugStringA( "P2P:: Consumed queued message \n" );
OutputDebugString( "P2P:: Consumed queued message \n" );
free( m_rgpQueuedMessage[i] );
m_rgpQueuedMessage[i] = NULL;
}
@@ -383,7 +385,7 @@ bool CP2PAuthedGame::HandleMessage( EMessage eMsg, void *pMessage )
}
}
// if we dont have the player in our list yet, lets queue the message and assume he will show up soon
OutputDebugStringA( "P2P:: HandleMessage queueing message \n" );
OutputDebugString( "P2P:: HandleMessage queueing message \n" );
for ( int i = 0; i < MAX_PLAYERS_PER_SERVER; i++ )
{
if ( m_rgpQueuedMessage[i] == NULL )
@@ -396,7 +398,7 @@ bool CP2PAuthedGame::HandleMessage( EMessage eMsg, void *pMessage )
}
default:
{
OutputDebugStringA( "Received unknown message on our listen socket\n" );
OutputDebugString( "Received unknown message on our listen socket\n" );
break;
}
}
@@ -410,4 +412,4 @@ bool CP2PAuthedGame::HandleMessage( EMessage eMsg, void *pMessage )
CSteamID CP2PAuthedGame::GetSteamID()
{
return SteamUser()->GetSteamID();
}
}
+9 -9
View File
@@ -18,14 +18,15 @@ class CNetworkTransport;
class CP2PAuthPlayer
{
public:
CP2PAuthPlayer( CGameEngine *pGameEngine, CNetworkTransport *pNetworkTransport );
CP2PAuthPlayer( IGameEngine *pGameEngine, CNetworkTransport *pNetworkTransport );
~CP2PAuthPlayer();
void EndGame();
void InitPlayer( CSteamID steamID );
void StartAuthPlayer();
bool BIsAuthOk();
virtual bool HandleMessage( EMessage eMsg, void *pMessage );
virtual CSteamID GetSteamID();
bool HandleMessage( EMessage eMsg, void *pMessage );
CSteamID GetSteamID();
STEAM_CALLBACK( CP2PAuthPlayer, OnBeginAuthResponse, ValidateAuthTicketResponse_t, m_CallbackBeginAuthResponse );
@@ -50,7 +51,7 @@ private:
EAuthSessionResponse m_eAuthSessionResponse;
CNetworkTransport *m_pNetworkTransport;
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
};
//-----------------------------------------------------------------------------
@@ -59,18 +60,18 @@ private:
class CP2PAuthedGame
{
public:
CP2PAuthedGame( CGameEngine *pGameEngine );
CP2PAuthedGame( IGameEngine *pGameEngine );
void PlayerDisconnect( int iSlot );
void EndGame();
void StartAuthPlayer( int iSlot, CSteamID steamID );
void RegisterPlayer( int iSlot, CSteamID steamID );
virtual bool HandleMessage( EMessage eMsg, void *pMessage );
virtual CSteamID GetSteamID();
bool HandleMessage( EMessage eMsg, void *pMessage );
CSteamID GetSteamID();
void InternalInitPlayer( int iSlot, CSteamID steamID, bool bStartAuthProcess );
CP2PAuthPlayer *m_rgpP2PAuthPlayer[MAX_PLAYERS_PER_SERVER];
MsgP2PSendingTicket_t *m_rgpQueuedMessage[MAX_PLAYERS_PER_SERVER];
CGameEngine *m_pGameEngine;
IGameEngine *m_pGameEngine;
CNetworkTransport *m_pNetworkTransport;
};
@@ -82,7 +83,6 @@ class CNetworkTransport
{
public:
CNetworkTransport();
bool SendTicket( CSteamID steamIDFrom, CSteamID steamIDTo, uint32 cubTicket, uint8 *pubTicket );
void CloseConnection( CSteamID steamID );
+3 -1
View File
@@ -10,9 +10,11 @@
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#include <varargs.h>
#include <stdio.h>
#ifdef WIN32
#include <varargs.h>
#include <tchar.h>
#endif
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
+122 -3
View File
@@ -13,6 +13,12 @@
#pragma once
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#ifdef WIN32
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 2k or later.
@@ -33,8 +39,6 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#pragma comment( lib, "d3d9.lib" )
#pragma comment( lib, "d3dx9.lib" )
#pragma comment( lib, "dxguid.lib" )
@@ -58,8 +62,11 @@ typedef unsigned __int32 uint32;
typedef __int64 int64;
typedef unsigned __int64 uint64;
// steam api header file
#include "steam/steam_api.h"
#include "steam/isteamuserstats.h"
#include "steam/isteamremotestorage.h"
#include "steam/isteammatchmaking.h"
#include "steam/steam_gameserver.h"
#ifdef STEAM_CEG
// Steam DRM header file
@@ -71,3 +78,115 @@ typedef unsigned __int64 uint64;
#define Steamworks_SelfCheck() (true)
#endif
#elif _PS3
#include <stdio.h>
#include <stddef.h>
#include <cell/error.h>
#include <sys/process.h>
#include <sys/paths.h>
#include <sys/prx.h>
#include <sys/spu_initialize.h>
#include <sys/memory.h>
#include <PSGL/psgl.h>
#include <PSGL/psglu.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <cell/fios/fios_common.h>
#include <cell/fios/fios_memory.h>
#include <cell/fios/fios_configuration.h>
#include <cell/fios/fios_time.h>
#include <cell/dbgfont.h>
#include <cell/pad/libpad.h>
#include <sysutil/sysutil_syscache.h>
#include <string.h>
// Need to define some types on POSIX
typedef short int16;
typedef unsigned short uint16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
typedef uint32 DWORD;
typedef DWORD HWND;
typedef short SHORT;
typedef long LONG;
typedef unsigned char byte;
typedef unsigned char uint8;
/* Font Weights */
#define FW_DONTCARE 0
#define FW_THIN 100
#define FW_EXTRALIGHT 200
#define FW_LIGHT 300
#define FW_NORMAL 400
#define FW_MEDIUM 500
#define FW_SEMIBOLD 600
#define FW_BOLD 700
#define FW_EXTRABOLD 800
#define FW_HEAVY 900
/* Some VK_ defines from windows, we'll map these to PS3 controls */
#define VK_BACK 0x08
#define VK_TAB 0x09
#define VK_RETURN 0x0D
#define VK_SHIFT 0x10
#define VK_CONTROL 0x11
#define VK_ESCAPE 0x1B
#define VK_SPACE 0x20
#define VK_UP 0x26
#define VK_DOWN 0x28
#define VK_SELECT 0x29
typedef struct tagRECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
#define D3DCOLOR_ARGB(a,r,g,b) \
((DWORD)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
// Macros for converting ARGB DWORD color representation into opengl formats...
#define COLOR_RED( color ) \
(GLubyte)(((color)>>16)&0xff)
#define COLOR_GREEN( color ) \
(GLubyte)(((color)>>8)&0xff)
#define COLOR_BLUE( color ) \
(GLubyte)((color)&0xff)
#define COLOR_ALPHA( color ) \
(GLubyte)(((color)>>24)&0xff)
#define DWARGB_TO_DWRGBA(color) \
((DWORD)(( (((((color)>>16)&0xff))<<24)|(((((color)>>8)&0xff))<<16)|((color&0xff)<<8)|((color)>>24)&0xff)))
#define DWARGB_TO_DWABGR(color) \
((DWORD)(( (((((color)>>24)&0xff))<<24)|(((((color))&0xff))<<16)|(((color>>8)&0xff)<<8)|((color)>>16)&0xff)))
// steam api header file
#include "steam/steam_api.h"
#include "steam/isteamuserstats.h"
#include "steam/isteamremotestorage.h"
#include "steam/isteammatchmaking.h"
#include "steam/steam_gameserver.h"
extern CellDbgFontConsoleId g_DbgFontConsoleID;
static void OutputDebugString( const char *pchMsg )
{
printf( "%s", pchMsg );
cellDbgFontConsolePrintf( g_DbgFontConsoleID, "%s", pchMsg );
}
// No _snprintf on PS3, use sprintf
#define _snprintf snprintf
#define ARRAYSIZE(a) sizeof(a)/sizeof(a[0])
#endif // _PS3
+4
View File
@@ -24,6 +24,10 @@ typedef int32 HSteamUser;
#endif
extern "C" typedef void (__cdecl *SteamAPIWarningMessageHook_t)(int, const char *);
#if defined( __SNC__ )
#pragma diag_suppress=1700 // warning 1700: class "%s" has virtual functions but non-virtual destructor
#endif
// interface predec
class ISteamUser;
class ISteamGameServer;
+25 -13
View File
@@ -64,16 +64,6 @@ enum EFriendFlags
};
//-----------------------------------------------------------------------------
// Purpose: avatar sizes, used in ISteamFriends::GetFriendAvatar()
//-----------------------------------------------------------------------------
enum EAvatarSize
{
k_EAvatarSize32x32 = 0,
k_EAvatarSize64x64 = 1,
};
// friend game played information
#pragma pack( push, 8 )
struct FriendGameInfo_t
@@ -143,8 +133,6 @@ public:
//
virtual const char *GetFriendPersonaName( CSteamID steamIDFriend ) = 0;
// gets the avatar of the current user, which is a handle to be used in IClientUtils::GetImageRGBA(), or 0 if none set
virtual int GetFriendAvatar( CSteamID steamIDFriend, int eAvatarSize ) = 0;
// returns true if the friend is actually in a game, and fills in pFriendGameInfo with an extra details
virtual bool GetFriendGamePlayed( CSteamID steamIDFriend, FriendGameInfo_t *pFriendGameInfo ) = 0;
// accesses old friends names - returns an empty string when their are no more items in the history
@@ -198,9 +186,19 @@ public:
// activates game overlay to open the invite dialog. Invitations will be sent for the provided lobby.
// You can also use ActivateGameOverlay( "LobbyInvite" ) to allow the user to create invitations for their current public lobby.
virtual void ActivateGameOverlayInviteDialog( CSteamID steamIDLobby ) = 0;
// gets the small (32x32) avatar of the current user, which is a handle to be used in IClientUtils::GetImageRGBA(), or 0 if none set
virtual int GetSmallFriendAvatar( CSteamID steamIDFriend ) = 0;
// gets the medium (64x64) avatar of the current user, which is a handle to be used in IClientUtils::GetImageRGBA(), or 0 if none set
virtual int GetMediumFriendAvatar( CSteamID steamIDFriend ) = 0;
// gets the large (184x184) avatar of the current user, which is a handle to be used in IClientUtils::GetImageRGBA(), or 0 if none set
// returns -1 if this image has yet to be loaded, in this case wait for a AvatarImageLoaded_t callback and then call this again
virtual int GetLargeFriendAvatar( CSteamID steamIDFriend ) = 0;
};
#define STEAMFRIENDS_INTERFACE_VERSION "SteamFriends006"
#define STEAMFRIENDS_INTERFACE_VERSION "SteamFriends007"
// callbacks
#pragma pack( push, 8 )
@@ -269,6 +267,20 @@ struct GameLobbyJoinRequested_t
CSteamID m_steamIDFriend; // the friend they did the join via (will be invalid if not directly via a friend)
};
//-----------------------------------------------------------------------------
// Purpose: called when an avatar is loaded in from a previous GetLargeFriendAvatar() call
// if the image wasn't already available
//-----------------------------------------------------------------------------
struct AvatarImageLoaded_t
{
enum { k_iCallback = k_iSteamFriendsCallbacks + 34 };
CSteamID m_steamID; // steamid the avatar has been loaded for
int m_iImage; // the image index of the now loaded image
int m_iWide; // width of the loaded image
int m_iTall; // height of the loaded image
};
#pragma pack( pop )
#endif // ISTEAMFRIENDS_H
+8 -5
View File
@@ -25,7 +25,7 @@ enum EP2PSessionError
k_EP2PSessionErrorTimeout = 4, // target isn't responding, perhaps not calling AcceptP2PSessionWithUser()
// corporate firewalls can also block this (NAT traversal is not firewall traversal)
// make sure that UDP ports 3478, 4379, and 4380 are open in an outbound direction
k_EP2PSessionErrorMax = 5
};
// SendP2PPacket() send types
@@ -129,16 +129,19 @@ public:
// the first packet send may be delayed as the NAT-traversal code runs
// if we can't get through to the user, an error will be posted via the callback P2PSessionConnectFail_t
// see EP2PSend enum above for the descriptions of the different ways of sending packets
virtual bool SendP2PPacket( CSteamID steamIDRemote, const void *pubData, uint32 cubData, EP2PSend eP2PSendType ) = 0;
// nVirtualPort is a routing number you can use to help route message to different systems - you'll have to call ReadP2PPacket()
// with the same nVirtualPort number in order to retrieve the data on the other end
// using different virtual ports to talk to the same user will still use the same underlying p2p connection, saving on resources
virtual bool SendP2PPacket( CSteamID steamIDRemote, const void *pubData, uint32 cubData, EP2PSend eP2PSendType, int nVirtualPort = 0 ) = 0;
// returns true if any data is available for read, and the amount of data that will need to be read
virtual bool IsP2PPacketAvailable( uint32 *pcubMsgSize ) = 0;
virtual bool IsP2PPacketAvailable( uint32 *pcubMsgSize, int nVirtualPort = 0 ) = 0;
// reads in a packet that has been sent from another user via SendP2PPacket()
// returns the size of the message and the steamID of the user who sent it in the last two parameters
// if the buffer passed in is too small, the message will be truncated
// this call is not blocking, and will return false if no data is available
virtual bool ReadP2PPacket( void *pubDest, uint32 cubDest, uint32 *pcubMsgSize, CSteamID *psteamIDRemote ) = 0;
virtual bool ReadP2PPacket( void *pubDest, uint32 cubDest, uint32 *pcubMsgSize, CSteamID *psteamIDRemote, int nVirtualPort = 0 ) = 0;
// AcceptP2PSessionWithUser() should only be called in response to a P2PSessionRequest_t callback
// P2PSessionRequest_t will be posted if another user tries to send you a packet that you haven't talked to yet
@@ -237,7 +240,7 @@ public:
// max packet size, in bytes
virtual int GetMaxPacketSize( SNetSocket_t hSocket ) = 0;
};
#define STEAMNETWORKING_INTERFACE_VERSION "SteamNetworking003"
#define STEAMNETWORKING_INTERFACE_VERSION "SteamNetworking004"
// callbacks
#pragma pack( push, 8 )
+36 -2
View File
@@ -1,4 +1,4 @@
//====== Copyright © 1996-2008, Valve Corporation, All rights reserved. =======
//====== Copyright (c) 1996-2008, Valve Corporation, All rights reserved. =======
//
// Purpose: interface to user account information in Steam
//
@@ -127,9 +127,32 @@ public:
// After receiving a user's authentication data, and passing it to BeginAuthSession, use this function
// to determine if the user owns downloadable content specified by the provided AppID.
virtual EUserHasLicenseForAppResult UserHasLicenseForApp( CSteamID steamID, AppId_t appID ) = 0;
// returns true if this users looks like they are behind a NAT device. Only valid once the user has connected to steam
// (i.e a SteamServersConnected_t has been issued) and may not catch all forms of NAT.
virtual bool BIsBehindNAT() = 0;
#ifdef _PS3
// Logs a user into Steam by using his login name and password
virtual void LogOn( const char *pchUserName, const char *pchPassword ) = 0;
#endif
// set data to be replicated to friends so that they can join your game
// CSteamID steamIDGameServer - the steamID of the game server, received from the game server by the client
// uint32 unIPServer, uint16 usPortServer - the IP address of the game server
virtual void AdvertiseGame( CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPortServer ) = 0;
// Requests a ticket encrypted with an app specific shared key
// pDataToInclude, cbDataToInclude will be encrypted into the ticket
// ( This is asynchronous, you must wait for the ticket to be completed by the server )
virtual SteamAPICall_t RequestEncryptedAppTicket( void *pDataToInclude, int cbDataToInclude ) = 0;
// retrieve a finished ticket
virtual bool GetEncryptedAppTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ) = 0;
};
#define STEAMUSER_INTERFACE_VERSION "SteamUser013"
#define STEAMUSER_INTERFACE_VERSION "SteamUser014"
// callbacks
@@ -228,6 +251,17 @@ struct MicroTxnAuthorizationResponse_t
uint8 m_bAuthorized; // if user authorized transaction
};
//-----------------------------------------------------------------------------
// Purpose: Result from RequestEncryptedAppTicket
//-----------------------------------------------------------------------------
struct EncryptedAppTicketResponse_t
{
enum { k_iCallback = k_iSteamUserCallbacks + 54 };
EResult m_eResult;
};
#pragma pack( pop )
#endif // ISTEAMUSER_H
+8 -1
View File
@@ -109,7 +109,14 @@ public:
// refresh the screen with Present or SwapBuffers to allow the overlay to do it's work.
virtual bool BOverlayNeedsPresent() = 0;
// Asynchronous call to check if file is signed, result is returned in CheckFileSignature_t
// Asynchronous call to check if an executable file has been signed using the public key set on the signing tab
// of the partner site, for example to refuse to load modified executable files.
// The result is returned in CheckFileSignature_t.
// k_ECheckFileSignatureNoSignaturesFoundForThisApp - This app has not been configured on the signing tab of the partner site to enable this function.
// k_ECheckFileSignatureNoSignaturesFoundForThisFile - This file is not listed on the signing tab for the partner site.
// k_ECheckFileSignatureFileNotFound - The file does not exist on disk.
// k_ECheckFileSignatureInvalidSignature - The file exists, and the signing tab has been set for this file, but the file is either not signed or the signature does not match.
// k_ECheckFileSignatureValidSignature - The file is signed and the signature is valid.
virtual SteamAPICall_t CheckFileSignature( const char *szFileName ) = 0;
};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+17 -1
View File
@@ -80,11 +80,22 @@ S_API void SteamAPI_SetMiniDumpComment( const char *pchMsg );
// pvContext-- can be NULL, will be the void * context passed into m_pfnPreMinidumpCallback
// PFNPreMinidumpCallback m_pfnPreMinidumpCallback -- optional callback which occurs just before a .dmp file is written during a crash. Applications can hook this to allow adding additional information into the .dmp comment stream.
S_API void SteamAPI_UseBreakpadCrashHandler( char const *pchVersion, char const *pchDate, char const *pchTime, bool bFullMemoryDumps, void *pvContext, PFNPreMinidumpCallback m_pfnPreMinidumpCallback );
S_API void SteamAPI_SetBreakpadAppID( uint32 unAppID );
// interface pointers, configured by SteamAPI_Init()
S_API ISteamClient *SteamClient();
//----------------------------------------------------------------------------------------------------------------------------------------------------------//
// PlayStation 3 initialization parameters
//
// The following structure must be passed to when loading steam_api_ps3.prx
//----------------------------------------------------------------------------------------------------------------------------------------------------------//
#define STEAM_PS3_PATH_MAX 1055
struct SteamPS3Params_t
{
char m_rgchInstallationPath[ STEAM_PS3_PATH_MAX ];
char m_rgchSystemCache[ STEAM_PS3_PATH_MAX ];
};
//
// VERSION_SAFE_STEAM_API_INTERFACES is usually not necessary, but it provides safety against releasing
@@ -99,7 +110,12 @@ S_API ISteamClient *SteamClient();
#ifdef VERSION_SAFE_STEAM_API_INTERFACES
S_API bool SteamAPI_InitSafe();
#else
#if defined(_PS3)
S_API bool SteamAPI_Init( SteamPS3Params_t *pParams );
#else
S_API bool SteamAPI_Init();
#endif
S_API ISteamUser *SteamUser();
S_API ISteamFriends *SteamFriends();
+14
View File
@@ -29,11 +29,25 @@ enum EServerMode
//
// Pass 0 for usGamePort or usSpectatorPort if you're not using that. Then, the master server updater will report
// what's running based on that.
#ifndef _PS3
#ifdef VERSION_SAFE_STEAM_API_INTERFACES
S_API bool SteamGameServer_InitSafe( uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usSpectatorPort, uint16 usQueryPort, EServerMode eServerMode, const char *pchGameDir, const char *pchVersionString );
#else
S_API bool SteamGameServer_Init( uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usSpectatorPort, uint16 usQueryPort, EServerMode eServerMode, const char *pchGameDir, const char *pchVersionString );
#endif
#else
#ifdef VERSION_SAFE_STEAM_API_INTERFACES
S_API bool SteamGameServer_InitSafe( const SteamPS3Params_t *ps3Params, uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usSpectatorPort, uint16 usQueryPort, EServerMode eServerMode, const char *pchGameDir, const char *pchVersionString );
#else
S_API bool SteamGameServer_Init( const SteamPS3Params_t *ps3Params, uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usSpectatorPort, uint16 usQueryPort, EServerMode eServerMode, const char *pchGameDir, const char *pchVersionString );
#endif
#endif
#ifndef VERSION_SAFE_STEAM_API_INTERFACES
S_API ISteamGameServer *SteamGameServer();
S_API ISteamUtils *SteamGameServerUtils();
S_API ISteamMasterServerUpdater *SteamMasterServerUpdater();
+27 -8
View File
@@ -80,6 +80,7 @@ enum EResult
k_EResultDataCorruption = 53, // Operation canceled because data is ill formed or unrecoverable
k_EResultDiskFull = 54, // Operation canceled - not enough disk space.
k_EResultRemoteCallFailed = 55, // an remote call or IPC call failed
k_EResultPasswordUnset = 56, // Password could not be verified as it's unset server side
};
// Error codes for use with the voice functions
@@ -236,10 +237,10 @@ enum EChatRoomEnterResponse
//-----------------------------------------------------------------------------
enum EStatusDepotVersion
{
k_EStatusDepotVersionInvalid = 0,
k_EStatusDepotVersionCompleteDisabled = 1,
k_EStatusDepotVersionCompleteEnabledBeta = 2,
k_EStatusDepotVersionCompleteEnabledPublic = 3,
k_EStatusDepotVersionInvalid = 0,
k_EStatusDepotVersionDisabled = 1, // version was disabled, no manifest & content available
k_EStatusDepotVersionAvailable = 2, // manifest & content is available, but not current
k_EStatusDepotVersionCurrent = 3, // current depot version. The can be multiple, one for public and one for each beta key
};
@@ -605,10 +606,17 @@ private:
{
struct SteamIDComponent_t
{
#ifdef VALVE_BIG_ENDIAN
EUniverse m_EUniverse : 8; // universe this account belongs to
unsigned int m_EAccountType : 4; // type of account - can't show as EAccountType, due to signed / unsigned difference
unsigned int m_unAccountInstance : 20; // dynamic instance ID (used for multiseat type accounts only)
uint32 m_unAccountID : 32; // unique account identifier
#else
uint32 m_unAccountID : 32; // unique account identifier
unsigned int m_unAccountInstance : 20; // dynamic instance ID (used for multiseat type accounts only)
unsigned int m_EAccountType : 4; // type of account - can't show as EAccountType, due to signed / unsigned difference
EUniverse m_EUniverse : 8; // universe this account belongs to
#endif
} m_comp;
uint64 m_unAll64Bits;
@@ -787,6 +795,11 @@ public:
return &m_ulGameID;
}
void Set( uint64 ulGameID )
{
m_ulGameID = ulGameID;
}
bool IsMod() const
{
return ( m_gameID.m_nType == k_EGameIDTypeGameMod );
@@ -839,16 +852,16 @@ public:
{
case k_EGameIDTypeApp:
return m_gameID.m_nAppID != k_uAppIdInvalid;
break;
case k_EGameIDTypeGameMod:
return m_gameID.m_nAppID != k_uAppIdInvalid && m_gameID.m_nModID & 0x80000000;
break;
case k_EGameIDTypeShortcut:
return (m_gameID.m_nModID & 0x80000000) != 0;
break;
case k_EGameIDTypeP2P:
return m_gameID.m_nAppID == k_uAppIdInvalid && m_gameID.m_nModID & 0x80000000;
break;
default:
#if defined(Assert)
Assert(false);
@@ -877,9 +890,15 @@ private:
struct GameID_t
{
#ifdef VALVE_BIG_ENDIAN
unsigned int m_nModID : 32;
unsigned int m_nType : 8;
unsigned int m_nAppID : 24;
#else
unsigned int m_nAppID : 24;
unsigned int m_nType : 8;
unsigned int m_nModID : 32;
#endif
};
union
+32
View File
@@ -0,0 +1,32 @@
//========= Copyright © 1996-2010, Valve LLC, All rights reserved. ============
//
// Purpose: utilities to decode/decrypt a ticket from the
// ISteamUser::RequestEncryptedAppTicket, ISteamUser::GetEncryptedAppTicket API
//
// To use: declare CSteamEncryptedAppTicket, then call BDecryptTicket
// if BDecryptTicket returns true, other accessors are valid
//
//=============================================================================
#include "steam_api.h"
static const int k_nSteamEncryptedAppTicketSymmetricKeyLen = 32;
S_API bool SteamEncryptedAppTicket_BDecryptTicket( const uint8 *rgubTicketEncrypted, uint32 cubTicketEncrypted,
uint8 *rgubTicketDecrypted, uint32 *pcubTicketDecrypted,
const uint8 rgubKey[k_nSteamEncryptedAppTicketSymmetricKeyLen], int cubKey );
S_API bool SteamEncryptedAppTicket_BIsTicketForApp( uint8 *rgubTicketDecrypted, uint32 cubTicketDecrypted, AppId_t nAppID );
S_API RTime32 SteamEncryptedAppTicket_GetTicketIssueTime( uint8 *rgubTicketDecrypted, uint32 cubTicketDecrypted );
S_API void SteamEncryptedAppTicket_GetTicketSteamID( uint8 *rgubTicketDecrypted, uint32 cubTicketDecrypted, CSteamID *psteamID );
S_API AppId_t SteamEncryptedAppTicket_GetTicketAppID( uint8 *rgubTicketDecrypted, uint32 cubTicketDecrypted );
S_API bool SteamEncryptedAppTicket_BUserOwnsAppInTicket( uint8 *rgubTicketDecrypted, uint32 cubTicketDecrypted, AppId_t nAppID );
S_API bool SteamEncryptedAppTicket_BUserIsVacBanned( uint8 *rgubTicketDecrypted, uint32 cubTicketDecrypted );
S_API const uint8 *SteamEncryptedAppTicket_GetUserVariableData( uint8 *rgubTicketDecrypted, uint32 cubTicketDecrypted, uint32 *pcubUserData );
+5
View File
@@ -26,6 +26,11 @@ typedef unsigned char uint8;
#define X64BITS
#endif
// Make sure VALVE_BIG_ENDIAN gets set on PS3, may already be set previously in Valve internal code.
#if !defined(VALVE_BIG_ENDIAN) && defined(_PS3)
#define VALVE_BIG_ENDIAN
#endif
typedef unsigned char uint8;
typedef signed char int8;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large Load Diff
+205
View File
@@ -0,0 +1,205 @@
//========= Copyright © 1996-2008, Valve LLC, All rights reserved. ============
//
// Purpose: Main class for the game engine -- ps3 implementation
//
// $NoKeywords: $
//=============================================================================
#ifndef GAMEENGINEPS3_H
#define GAMEENGINEPS3_H
#include "GameEngine.h"
#include <set>
#include <map>
// Font info for PS3 dbg font output
struct PS3DbgFont_t
{
float m_nScale;
};
class CGameEnginePS3 : public IGameEngine
{
public:
// Static methods for tracing mapping of game engine class instances to hwnds
static CGameEnginePS3 * FindEngineInstanceForPtr( void *ptr );
static void AddInstanceToPtrMap( CGameEnginePS3* pInstance );
static void RemoveInstanceFromPtrMap( void *ptr );
// Constructor
CGameEnginePS3();
// Destructor
~CGameEnginePS3() { Shutdown(); }
// Check if the game engine is initialized ok and ready for use
bool BReadyForUse() { return m_bEngineReadyForUse; }
// Check if the engine is shutting down
bool BShuttingDown() { return m_bShuttingDown; }
// Set the background color
void SetBackgroundColor( short a, short r, short g, short b );
// Start a frame, clear(), beginscene(), etc
bool StartFrame();
// Finish a frame, endscene(), present(), etc.
void EndFrame();
// Shutdown the game engine
void Shutdown();
// Pump messages from the OS
void MessagePump();
// Accessors for game screen size
int32 GetViewportWidth() { return m_nWindowWidth; }
int32 GetViewportHeight() { return m_nWindowHeight; }
// Function for drawing text to the screen, dwFormat is a combination of flags like DT_LEFT, TEXTPOS_VCENTER etc...
bool BDrawString( HGAMEFONT hFont, RECT rect, DWORD dwColor, DWORD dwFormat, const char *pchText );
// Create a new font returning our internal handle value for it (0 means failure)
HGAMEFONT HCreateFont( int nHeight, int nFontWeight, bool bItalic, char * pchFont );
// Create a new texture returning our internal handle value for it (0 means failure)
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight );
// 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 );
// Flush the line buffer
bool BFlushLineBuffer();
// Draw a point, the engine itself will manage batching these (although you can explicitly flush if you need to)
bool BDrawPoint( float xPos, float yPos, DWORD dwColor );
// Flush the point buffer
bool BFlushPointBuffer();
// Draw a filled quad
bool BDrawFilledQuad( float xPos0, float yPos0, float xPos1, float yPos1, DWORD dwColor );
// Draw a textured rectangle
bool BDrawTexturedQuad( float xPos0, float yPos0, float xPos1, float yPos1,
float u0, float v0, float u1, float v1, DWORD dwColor, HGAMETEXTURE hTexture );
// Flush any still cached quad buffers
bool BFlushQuadBuffer();
// Get the current state of a key
bool BIsKeyDown( DWORD dwVK );
// Get the first (in some arbitrary order) key down, if any
bool BGetFirstKeyDown( DWORD *pdwVK );
// Get current tick count for the game engine
uint64 GetGameTickCount() { return m_ulGameTickCount; }
// Get the tick count elapsed since the previous frame
// bugbug - We use this time to compute things like thrust and acceleration in the game,
// so it's important in doesn't jump ahead by large increments... Need a better
// way to handle that.
uint64 GetGameTicksFrameDelta() { return m_ulGameTickCount - m_ulPreviousGameTickCount; }
// Tell the game engine to update current tick count
void UpdateGameTickCount();
// Tell the game engine to sleep for a bit if needed to limit frame rate
bool BSleepForFrameRateLimit( uint32 ulMaxFrameRate );
// Check if the game engine hwnd currently has focus (and a working d3d device)
bool BGameEngineHasFocus() { return true; }
private:
// Initialize the PSGL rendering interfaces and default state
bool BInitializePSGL();
// Initialize the debug font library
bool BInitializeCellDbgFont();
// Initialize libpad for controller input
bool BInitializeLibPad();
private:
// Tracks whether the engine is ready for use
bool m_bEngineReadyForUse;
// Tracks if we are shutting down
bool m_bShuttingDown;
// Size of the window to display the game in
int32 m_nWindowWidth;
int32 m_nWindowHeight;
// Current game time in milliseconds
uint64 m_ulGameTickCount;
// Game time at the start of the previous frame
uint64 m_ulPreviousGameTickCount;
// White texture used when drawing filled quads
HGAMETEXTURE m_hTextureWhite;
// PSGL and CellDbgFont objects
PSGLcontext * m_pPSGLContext;
PSGLdevice * m_pPSGLDevice;
CellDbgFontConsoleId m_DbgFontConsoleID;
// Pointer to actual data for points
GLfloat *m_rgflPointsData;
GLubyte *m_rgflPointsColorData;
// How many points are outstanding needing flush
DWORD m_dwPointsToFlush;
// Pointer to actual data for lines
GLfloat *m_rgflLinesData;
GLubyte *m_rgflLinesColorData;
// How many lines are outstanding needing flush
DWORD m_dwLinesToFlush;
// Pointer to actual data for quads
GLfloat *m_rgflQuadsData;
GLubyte *m_rgflQuadsColorData;
GLfloat *m_rgflQuadsTextureData;
// How many lines are outstanding needing flush
DWORD m_dwQuadsToFlush;
// Currently active PS3 pad index to use for input
int m_iCurrentPadIndex;
// Map of engine instances by ptr, used in ps3 sys callbacks to find engine instance to handle callback
static std::map<void *, CGameEnginePS3 *> m_MapEngineInstances;
// Map of font handles we have given out
HGAMEFONT m_nNextFontHandle;
std::map< HGAMEFONT, PS3DbgFont_t > m_MapGameFonts;
// Map of handles to texture objects
struct TextureData_t
{
uint32 m_uWidth;
uint32 m_uHeight;
GLuint m_uTextureID;
};
std::map<HGAMETEXTURE, TextureData_t> m_MapTextures;
HGAMETEXTURE m_nNextTextureHandle;
// Last bound texture, used to know when we must flush
HGAMETEXTURE m_hLastTexture;
// Map of button state, translated to VK for win32.
std::set< DWORD > m_SetKeysDown;
};
#endif // GAMEENGINEPS3_H
@@ -1,15 +1,16 @@
//========= Copyright © 1996-2008, Valve LLC, All rights reserved. ============
//
// Purpose: Main class for the game engine
// Purpose: Main class for the game engine -- win32 implementation
//
// $NoKeywords: $
//=============================================================================
#include "stdafx.h"
#include "GameEngine.h"
#include "GameEngineWin32.h"
#include <map>
// Allocate static member
std::map<HWND, CGameEngine* > CGameEngine::m_MapEngineInstances;
std::map<HWND, CGameEngineWin32* > CGameEngineWin32::m_MapEngineInstances;
//-----------------------------------------------------------------------------
// Purpose: WndProc
@@ -18,11 +19,11 @@ LRESULT CALLBACK GameWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam
{
switch ( msg )
{
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT:
{
CGameEngine *pGameEngine = CGameEngine::FindEngineInstanceForHWND( hWnd );
CGameEngineWin32 *pGameEngine = CGameEngineWin32::FindEngineInstanceForHWND( hWnd );
if ( pGameEngine )
pGameEngine->Shutdown();
else
@@ -31,40 +32,40 @@ LRESULT CALLBACK GameWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam
PostQuitMessage( 0 );
return(0);
} break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
{
CGameEngineWin32 *pGameEngine = CGameEngineWin32::FindEngineInstanceForHWND( hWnd );
if ( pGameEngine )
{
CGameEngine *pGameEngine = CGameEngine::FindEngineInstanceForHWND( hWnd );
if ( pGameEngine )
{
pGameEngine->RecordKeyDown( (DWORD) wParam );
return 0;
}
else
{
OutputDebugString( "Failed to find game engine for hwnd, key down event lost\n" );
}
pGameEngine->RecordKeyDown( (DWORD) wParam );
return 0;
}
break;
case WM_KEYUP:
case WM_SYSKEYUP:
else
{
CGameEngine *pGameEngine = CGameEngine::FindEngineInstanceForHWND( hWnd );
if ( pGameEngine )
{
pGameEngine->RecordKeyUp( (DWORD) wParam );
return 0;
}
else
{
OutputDebugString( "Failed to find game engine for hwnd, key up event lost\n" );
}
OutputDebugString( "Failed to find game engine for hwnd, key down event lost\n" );
}
break;
}
break;
case WM_KEYUP:
case WM_SYSKEYUP:
{
CGameEngineWin32 *pGameEngine = CGameEngineWin32::FindEngineInstanceForHWND( hWnd );
if ( pGameEngine )
{
pGameEngine->RecordKeyUp( (DWORD) wParam );
return 0;
}
else
{
OutputDebugString( "Failed to find game engine for hwnd, key up event lost\n" );
}
}
break;
// Add additional handlers for things like input here...
default:
break;
default:
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
@@ -74,7 +75,7 @@ LRESULT CALLBACK GameWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam
//-----------------------------------------------------------------------------
// Purpose: Constructor for game engine instance
//-----------------------------------------------------------------------------
CGameEngine::CGameEngine( HINSTANCE hInstance, int nShowCommand, int32 nWindowWidth, int32 nWindowHeight )
CGameEngineWin32::CGameEngineWin32( HINSTANCE hInstance, int nShowCommand, int32 nWindowWidth, int32 nWindowHeight )
{
m_bEngineReadyForUse = false;
m_bShuttingDown = false;
@@ -106,13 +107,26 @@ CGameEngine::CGameEngine( HINSTANCE hInstance, int nShowCommand, int32 nWindowWi
m_ulGameTickCount = 0;
m_dwBackgroundColor = D3DCOLOR_ARGB(0, 255, 255, 255 );
// restrict this main game thread to the first processor, so query performance counter won't jump on crappy AMD cpus
DWORD dwThreadAffinityMask = 0x01;
::SetThreadAffinityMask( ::GetCurrentThread(), dwThreadAffinityMask );
// Setup timing data
LARGE_INTEGER l;
::QueryPerformanceFrequency( &l );
m_ulPerfCounterToMillisecondsDivisor = l.QuadPart/1000;
::QueryPerformanceCounter( &l );
m_ulFirstQueryPerformanceCounterValue = l.QuadPart;
if ( !BCreateGameWindow( nShowCommand ) || !m_hWnd )
{
OutputDebugString( "Failed creating game window\n" );
return;
}
CGameEngine::AddInstanceToHWNDMap( this, m_hWnd );
CGameEngineWin32::AddInstanceToHWNDMap( this, m_hWnd );
if ( !BInitializeD3D9() )
{
@@ -133,7 +147,7 @@ CGameEngine::CGameEngine( HINSTANCE hInstance, int nShowCommand, int32 nWindowWi
//-----------------------------------------------------------------------------
// Purpose: Shutdown the game engine
//-----------------------------------------------------------------------------
void CGameEngine::Shutdown()
void CGameEngineWin32::Shutdown()
{
// Flag that we are shutting down so the frame loop will stop running
m_bShuttingDown = true;
@@ -212,7 +226,7 @@ void CGameEngine::Shutdown()
}
}
CGameEngine::RemoveInstanceFromHWNDMap( m_hWnd );
CGameEngineWin32::RemoveInstanceFromHWNDMap( m_hWnd );
m_hWnd = NULL;
}
@@ -231,7 +245,7 @@ void CGameEngine::Shutdown()
//-----------------------------------------------------------------------------
// Purpose: Handle losing the d3d device (ie, release resources)
//-----------------------------------------------------------------------------
bool CGameEngine::BHandleLostDevice()
bool CGameEngineWin32::BHandleLostDevice()
{
bool bFullySuccessful = true;
@@ -302,7 +316,7 @@ bool CGameEngine::BHandleLostDevice()
//-----------------------------------------------------------------------------
// Purpose: Handle device reset after losing it
//-----------------------------------------------------------------------------
bool CGameEngine::BHandleResetDevice()
bool CGameEngineWin32::BHandleResetDevice()
{
bool bFullySuccessful = true;
@@ -328,10 +342,61 @@ bool CGameEngine::BHandleResetDevice()
}
//-----------------------------------------------------------------------------
// Purpose: Updates current tick count for the game engine
//-----------------------------------------------------------------------------
void CGameEngineWin32::UpdateGameTickCount()
{
LARGE_INTEGER l;
::QueryPerformanceCounter( &l );
m_ulPreviousGameTickCount = m_ulGameTickCount;
m_ulGameTickCount = (l.QuadPart - m_ulFirstQueryPerformanceCounterValue) / m_ulPerfCounterToMillisecondsDivisor;
}
//-----------------------------------------------------------------------------
// Purpose: Tell the game engine to sleep for a bit if needed to limit frame rate. You must keep
// calling this repeatedly until it returns false. If it returns true it's slept a little, but more
// time may be needed.
//-----------------------------------------------------------------------------
bool CGameEngineWin32::BSleepForFrameRateLimit( uint32 ulMaxFrameRate )
{
// Frame rate limiting
float flDesiredFrameMilliseconds = 1000.0f/ulMaxFrameRate;
LARGE_INTEGER l;
::QueryPerformanceCounter( &l );
uint64 ulGameTickCount = (l.QuadPart - m_ulFirstQueryPerformanceCounterValue) / m_ulPerfCounterToMillisecondsDivisor;
float flMillisecondsElapsed = (float)(ulGameTickCount - m_ulGameTickCount);
if ( flMillisecondsElapsed < flDesiredFrameMilliseconds )
{
// If enough time is left sleep, otherwise just keep spinning so we don't go over the limit...
if ( flDesiredFrameMilliseconds - flMillisecondsElapsed > 3.0f )
{
Sleep( 2 );
}
else
{
// Just return right away so we busy loop, don't want to sleep too long and go over
}
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
// Purpose: Resets all the render, texture, and sampler states to our defaults
//-----------------------------------------------------------------------------
void CGameEngine::ResetRenderStates()
void CGameEngineWin32::ResetRenderStates()
{
// Since we are just a really basic rendering engine we'll setup our initial
// render states here and we can just assume that they don't change later
@@ -358,7 +423,7 @@ void CGameEngine::ResetRenderStates()
//-----------------------------------------------------------------------------
// Purpose: Creates the window for the game to use
//-----------------------------------------------------------------------------
bool CGameEngine::BCreateGameWindow( int nShowCommand )
bool CGameEngineWin32::BCreateGameWindow( int nShowCommand )
{
WNDCLASS wc;
DWORD style;
@@ -411,7 +476,7 @@ bool CGameEngine::BCreateGameWindow( int nShowCommand )
return true;
}
bool CGameEngine::BInitializeD3D9()
bool CGameEngineWin32::BInitializeD3D9()
{
if ( !m_pD3D9Interface )
{
@@ -491,7 +556,7 @@ bool CGameEngine::BInitializeD3D9()
//-----------------------------------------------------------------------------
// Purpose: Set the background color to clear to
//-----------------------------------------------------------------------------
void CGameEngine::SetBackgroundColor( short a, short r, short g, short b )
void CGameEngineWin32::SetBackgroundColor( short a, short r, short g, short b )
{
m_dwBackgroundColor = D3DCOLOR_ARGB( a, r, g, b );
}
@@ -499,7 +564,7 @@ void CGameEngine::SetBackgroundColor( short a, short r, short g, short b )
//-----------------------------------------------------------------------------
// Purpose: Start a new frame
//-----------------------------------------------------------------------------
bool CGameEngine::StartFrame()
bool CGameEngineWin32::StartFrame()
{
// Before doing anything else pump messages
MessagePump();
@@ -539,7 +604,7 @@ bool CGameEngine::StartFrame()
else if ( hRes == D3DERR_DEVICENOTRESET )
{
OutputDebugString( "Getting ready to reset device\n" );
// Reset the device
hRes = m_pD3D9Device->Reset( &m_d3dpp );
if ( !FAILED( hRes ) )
@@ -558,7 +623,7 @@ bool CGameEngine::StartFrame()
Shutdown();
}
}
// Return true even though we can't render, frames can still run otherwise
// and the game should continue its simulation or choose to pause on its own
if ( m_bDeviceLost )
@@ -580,7 +645,7 @@ bool CGameEngine::StartFrame()
//-----------------------------------------------------------------------------
// Purpose: End the current frame
//-----------------------------------------------------------------------------
void CGameEngine::EndFrame()
void CGameEngineWin32::EndFrame()
{
if ( BShuttingDown() )
return;
@@ -626,7 +691,7 @@ void CGameEngine::EndFrame()
//-----------------------------------------------------------------------------
// Purpose: Creates a new vertex buffer
//-----------------------------------------------------------------------------
HGAMEVERTBUF CGameEngine::HCreateVertexBuffer( uint32 nSizeInBytes, DWORD dwUsage, DWORD dwFVF )
HGAMEVERTBUF CGameEngineWin32::HCreateVertexBuffer( uint32 nSizeInBytes, DWORD dwUsage, DWORD dwFVF )
{
if ( !m_pD3D9Device )
return false;
@@ -656,7 +721,7 @@ HGAMEVERTBUF CGameEngine::HCreateVertexBuffer( uint32 nSizeInBytes, DWORD dwUsag
//-----------------------------------------------------------------------------
// Purpose: Locks an entire vertex buffer with the specified flags into memory
//-----------------------------------------------------------------------------
bool CGameEngine::BLockEntireVertexBuffer( HGAMEVERTBUF hVertBuf, void **ppVoid, DWORD dwFlags )
bool CGameEngineWin32::BLockEntireVertexBuffer( HGAMEVERTBUF hVertBuf, void **ppVoid, DWORD dwFlags )
{
if ( !m_pD3D9Device )
return false;
@@ -711,7 +776,7 @@ bool CGameEngine::BLockEntireVertexBuffer( HGAMEVERTBUF hVertBuf, void **ppVoid,
//-----------------------------------------------------------------------------
// Purpose: Unlocks a vertex buffer
//-----------------------------------------------------------------------------
bool CGameEngine::BUnlockVertexBuffer( HGAMEVERTBUF hVertBuf )
bool CGameEngineWin32::BUnlockVertexBuffer( HGAMEVERTBUF hVertBuf )
{
if ( !m_pD3D9Device )
return false;
@@ -765,7 +830,7 @@ bool CGameEngine::BUnlockVertexBuffer( HGAMEVERTBUF hVertBuf )
//-----------------------------------------------------------------------------
// Purpose: Release a vertex buffer and free its resources
//-----------------------------------------------------------------------------
bool CGameEngine::BReleaseVertexBuffer( HGAMEVERTBUF hVertBuf )
bool CGameEngineWin32::BReleaseVertexBuffer( HGAMEVERTBUF hVertBuf )
{
if ( !m_pD3D9Device )
return false;
@@ -812,7 +877,7 @@ bool CGameEngine::BReleaseVertexBuffer( HGAMEVERTBUF hVertBuf )
//-----------------------------------------------------------------------------
// Purpose: Set the FVF
//-----------------------------------------------------------------------------
bool CGameEngine::BSetFVF( DWORD dwFormat )
bool CGameEngineWin32::BSetFVF( DWORD dwFormat )
{
if ( !m_pD3D9Device )
return false;
@@ -830,7 +895,7 @@ bool CGameEngine::BSetFVF( DWORD dwFormat )
OutputDebugString( "SetFVF() call failed\n" );
return false;
}
m_dwCurrentFVF = dwFormat;
return true;
@@ -840,7 +905,7 @@ bool CGameEngine::BSetFVF( DWORD dwFormat )
//-----------------------------------------------------------------------------
// Purpose: Draw a line, the engine internally manages a vertex buffer for batching these
//-----------------------------------------------------------------------------
bool CGameEngine::BDrawLine( float xPos0, float yPos0, DWORD dwColor0, float xPos1, float yPos1, DWORD dwColor1 )
bool CGameEngineWin32::BDrawLine( float xPos0, float yPos0, DWORD dwColor0, float xPos1, float yPos1, DWORD dwColor1 )
{
if ( !m_pD3D9Device )
return false;
@@ -903,7 +968,7 @@ bool CGameEngine::BDrawLine( float xPos0, float yPos0, DWORD dwColor0, float xPo
//-----------------------------------------------------------------------------
// Purpose: Flush batched lines to the screen
//-----------------------------------------------------------------------------
bool CGameEngine::BFlushLineBuffer()
bool CGameEngineWin32::BFlushLineBuffer()
{
// If the vert buffer isn't already locked into memory, then there is nothing to flush
if ( m_pLineVertexes == NULL )
@@ -957,7 +1022,7 @@ bool CGameEngine::BFlushLineBuffer()
//-----------------------------------------------------------------------------
// Purpose: Draw a point, the engine internally manages a vertex buffer for batching these
//-----------------------------------------------------------------------------
bool CGameEngine::BDrawPoint( float xPos, float yPos, DWORD dwColor )
bool CGameEngineWin32::BDrawPoint( float xPos, float yPos, DWORD dwColor )
{
if ( !m_pD3D9Device )
return false;
@@ -1014,7 +1079,7 @@ bool CGameEngine::BDrawPoint( float xPos, float yPos, DWORD dwColor )
//-----------------------------------------------------------------------------
// Purpose: Flush batched points to the screen
//-----------------------------------------------------------------------------
bool CGameEngine::BFlushPointBuffer()
bool CGameEngineWin32::BFlushPointBuffer()
{
// If the vert buffer isn't already locked into memory, then there is nothing to flush
if ( m_pPointVertexes == NULL )
@@ -1068,7 +1133,7 @@ bool CGameEngine::BFlushPointBuffer()
//-----------------------------------------------------------------------------
// Purpose: Draw a filled quad
//-----------------------------------------------------------------------------
bool CGameEngine::BDrawFilledQuad( float xPos0, float yPos0, float xPos1, float yPos1, DWORD dwColor )
bool CGameEngineWin32::BDrawFilledQuad( float xPos0, float yPos0, float xPos1, float yPos1, DWORD dwColor )
{
if ( !m_hTextureWhite )
{
@@ -1085,7 +1150,7 @@ bool CGameEngine::BDrawFilledQuad( float xPos0, float yPos0, float xPos1, float
//-----------------------------------------------------------------------------
// Purpose: Draw a textured quad
//-----------------------------------------------------------------------------
bool CGameEngine::BDrawTexturedQuad( float xPos0, float yPos0, float xPos1, float yPos1, float u0, float v0, float u1, float v1, DWORD dwColor, HGAMETEXTURE hTexture )
bool CGameEngineWin32::BDrawTexturedQuad( float xPos0, float yPos0, float xPos1, float yPos1, float u0, float v0, float u1, float v1, DWORD dwColor, HGAMETEXTURE hTexture )
{
if ( !m_pD3D9Device )
return false;
@@ -1189,7 +1254,7 @@ bool CGameEngine::BDrawTexturedQuad( float xPos0, float yPos0, float xPos1, floa
//-----------------------------------------------------------------------------
// Purpose: Flush buffered quads
//-----------------------------------------------------------------------------
bool CGameEngine::BFlushQuadBuffer()
bool CGameEngineWin32::BFlushQuadBuffer()
{
// If the vert buffer isn't already locked into memory, then there is nothing to flush
if ( m_pQuadVertexes == NULL )
@@ -1319,13 +1384,13 @@ bool CGameEngine::BFlushQuadBuffer()
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Set the current stream source (this always set stream 0, we don't support more than 1 stream presently)
//-----------------------------------------------------------------------------
bool CGameEngine::BSetStreamSource( HGAMEVERTBUF hVertBuf, uint32 uOffset, uint32 uStride )
bool CGameEngineWin32::BSetStreamSource( HGAMEVERTBUF hVertBuf, uint32 uOffset, uint32 uStride )
{
if ( !m_pD3D9Device )
return false;
@@ -1368,7 +1433,7 @@ bool CGameEngine::BSetStreamSource( HGAMEVERTBUF hVertBuf, uint32 uOffset, uint3
//-----------------------------------------------------------------------------
// Purpose: Renders primitives using the current stream source
//-----------------------------------------------------------------------------
bool CGameEngine::BRenderPrimitive( D3DPRIMITIVETYPE primType, uint32 uStartVertex, uint32 uCount )
bool CGameEngineWin32::BRenderPrimitive( D3DPRIMITIVETYPE primType, uint32 uStartVertex, uint32 uCount )
{
if ( !m_pD3D9Device )
return false;
@@ -1389,7 +1454,7 @@ bool CGameEngine::BRenderPrimitive( D3DPRIMITIVETYPE primType, uint32 uStartVert
//-----------------------------------------------------------------------------
// Purpose: Creates a new texture
//-----------------------------------------------------------------------------
HGAMETEXTURE CGameEngine::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight )
HGAMETEXTURE CGameEngineWin32::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight )
{
if ( !m_pD3D9Device )
return 0;
@@ -1412,7 +1477,7 @@ HGAMETEXTURE CGameEngine::HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32
//-----------------------------------------------------------------------------
// Purpose: Creates a new font
//-----------------------------------------------------------------------------
HGAMEFONT CGameEngine::HCreateFont( int nHeight, int nFontWeight, bool bItalic, char * pchFont )
HGAMEFONT CGameEngineWin32::HCreateFont( int nHeight, int nFontWeight, bool bItalic, char * pchFont )
{
if ( !m_pD3D9Device )
return 0;
@@ -1437,7 +1502,7 @@ HGAMEFONT CGameEngine::HCreateFont( int nHeight, int nFontWeight, bool bItalic,
//-----------------------------------------------------------------------------
// Purpose: Draws text to the screen inside the given rectangular region, using the given font
//-----------------------------------------------------------------------------
bool CGameEngine::BDrawString( HGAMEFONT hFont, RECT rect, DWORD dwColor, DWORD dwFormat, const char *pchText )
bool CGameEngineWin32::BDrawString( HGAMEFONT hFont, RECT rect, DWORD dwColor, DWORD dwFormat, const char *pchText )
{
if ( !m_pD3D9Device )
return false;
@@ -1474,7 +1539,7 @@ bool CGameEngine::BDrawString( HGAMEFONT hFont, RECT rect, DWORD dwColor, DWORD
//-----------------------------------------------------------------------------
// Purpose: Message pump for OS messages
//-----------------------------------------------------------------------------
void CGameEngine::MessagePump()
void CGameEngineWin32::MessagePump()
{
MSG msg;
BOOL bRet;
@@ -1493,7 +1558,7 @@ void CGameEngine::MessagePump()
//-----------------------------------------------------------------------------
// Purpose: Track keys which are down
//-----------------------------------------------------------------------------
void CGameEngine::RecordKeyDown( DWORD dwVK )
void CGameEngineWin32::RecordKeyDown( DWORD dwVK )
{
m_SetKeysDown.insert( dwVK );
}
@@ -1502,7 +1567,7 @@ void CGameEngine::RecordKeyDown( DWORD dwVK )
//-----------------------------------------------------------------------------
// Purpose: Track keys which are up
//-----------------------------------------------------------------------------
void CGameEngine::RecordKeyUp( DWORD dwVK )
void CGameEngineWin32::RecordKeyUp( DWORD dwVK )
{
std::set<DWORD>::iterator iter;
iter = m_SetKeysDown.find( dwVK );
@@ -1514,7 +1579,7 @@ void CGameEngine::RecordKeyUp( DWORD dwVK )
//-----------------------------------------------------------------------------
// Purpose: Find out if a key is currently down
//-----------------------------------------------------------------------------
bool CGameEngine::BIsKeyDown( DWORD dwVK )
bool CGameEngineWin32::BIsKeyDown( DWORD dwVK )
{
std::set<DWORD>::iterator iter;
iter = m_SetKeysDown.find( dwVK );
@@ -1527,13 +1592,14 @@ bool CGameEngine::BIsKeyDown( DWORD dwVK )
//-----------------------------------------------------------------------------
// Purpose: Get a down key value
//-----------------------------------------------------------------------------
bool CGameEngine::BGetFirstKeyDown( DWORD *pdwVK )
bool CGameEngineWin32::BGetFirstKeyDown( DWORD *pdwVK )
{
std::set<DWORD>::iterator iter;
iter = m_SetKeysDown.begin();
if ( iter != m_SetKeysDown.end() )
{
*pdwVK = *iter;
m_SetKeysDown.erase( iter );
return true;
}
else
@@ -1546,9 +1612,9 @@ bool CGameEngine::BGetFirstKeyDown( DWORD *pdwVK )
//-----------------------------------------------------------------------------
// Purpose: Find the engine instance tied to a given hwnd
//-----------------------------------------------------------------------------
CGameEngine * CGameEngine::FindEngineInstanceForHWND( HWND hWnd )
CGameEngineWin32 * CGameEngineWin32::FindEngineInstanceForHWND( HWND hWnd )
{
std::map<HWND, CGameEngine *>::iterator iter;
std::map<HWND, CGameEngineWin32 *>::iterator iter;
iter = m_MapEngineInstances.find( hWnd );
if ( iter == m_MapEngineInstances.end() )
return NULL;
@@ -1560,7 +1626,7 @@ CGameEngine * CGameEngine::FindEngineInstanceForHWND( HWND hWnd )
//-----------------------------------------------------------------------------
// Purpose: Add the engine instance tied to a given hwnd to our static map
//-----------------------------------------------------------------------------
void CGameEngine::AddInstanceToHWNDMap( CGameEngine* pInstance, HWND hWnd )
void CGameEngineWin32::AddInstanceToHWNDMap( CGameEngineWin32* pInstance, HWND hWnd )
{
m_MapEngineInstances[hWnd] = pInstance;
}
@@ -1569,13 +1635,11 @@ void CGameEngine::AddInstanceToHWNDMap( CGameEngine* pInstance, HWND hWnd )
//-----------------------------------------------------------------------------
// Purpose: Removes the instance associated with a given HWND from the map
//-----------------------------------------------------------------------------
void CGameEngine::RemoveInstanceFromHWNDMap( HWND hWnd )
void CGameEngineWin32::RemoveInstanceFromHWNDMap( HWND hWnd )
{
std::map<HWND, CGameEngine *>::iterator iter;
std::map<HWND, CGameEngineWin32 *>::iterator iter;
iter = m_MapEngineInstances.find( hWnd );
if ( iter != m_MapEngineInstances.end() )
m_MapEngineInstances.erase( iter );
}
+341
View File
@@ -0,0 +1,341 @@
//========= Copyright © 1996-2008, Valve LLC, All rights reserved. ============
//
// Purpose: Main class for the game engine -- win32 implementation
//
// $NoKeywords: $
//=============================================================================
#ifndef GAMEENGINEWIN32_H
#define GAMEENGINEWIN32_H
#include "GameEngine.h"
#include <set>
#include <map>
// How big is the vertex buffer for batching lines in total?
// NOTE: This must be a multiple of the batch size below!!! (crashes will occur if it isn't)
#define LINE_BUFFER_TOTAL_SIZE 1000
// How many lines do we put in the buffer in between flushes?
//
// This should be enough smaller than the total size so that draw calls
// can finish using the data before we wrap around and discard it.
#define LINE_BUFFER_BATCH_SIZE 250
// How big is the vertex buffer for batching points in total?
// NOTE: This must be a multiple of the batch size below!!! (crashes will occur if it isn't)
#define POINT_BUFFER_TOTAL_SIZE 1800
// How many points do we put in the buffer in between flushes?
//
// This should be enough smaller than the total size so that draw calls
// can finish using the data before we wrap around and discard it.
#define POINT_BUFFER_BATCH_SIZE 600
// How big is the vertex buffer for batching quads in total?
// NOTE: This must be a multiple of the batch size below!!! (crashes will occur if it isn't)
#define QUAD_BUFFER_TOTAL_SIZE 1000
// How many quads do we put in the buffer in between flushes?
//
// This should be enough smaller than the total size so that draw calls
// can finish using the data before we wrap around and discard it.
#define QUAD_BUFFER_BATCH_SIZE 250
// Vertex struct for line batches
struct LineVertex_t
{
float x, y, z, rhw;
DWORD color;
};
// Vertex struct for point batches
struct PointVertex_t
{
float x, y, z, rhw;
DWORD color;
};
// Vertex struct for textured quads
struct TexturedQuadVertex_t
{
float x, y, z, rhw;
DWORD color;
float u, v; // texture coordinates
};
// WndProc declaration
LRESULT CALLBACK GameWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
class CGameEngineWin32 : public IGameEngine
{
public:
// Static methods for tracing mapping of game engine class instances to hwnds
static CGameEngineWin32 * FindEngineInstanceForHWND( HWND hWnd );
static void AddInstanceToHWNDMap( CGameEngineWin32* pInstance, HWND hWnd );
static void RemoveInstanceFromHWNDMap( HWND hWnd );
// Constructor
CGameEngineWin32( HINSTANCE hInstance, int nShowCommand, int32 nWindowWidth, int32 nWindowHeight );
// Destructor
~CGameEngineWin32() { Shutdown(); }
// Check if the game engine is initialized ok and ready for use
bool BReadyForUse() { return m_bEngineReadyForUse; }
// Check if the engine is shutting down
bool BShuttingDown() { return m_bShuttingDown; }
// Set the background color
void SetBackgroundColor( short a, short r, short g, short b );
// Start a frame, clear(), beginscene(), etc
bool StartFrame();
// Finish a frame, endscene(), present(), etc.
void EndFrame();
// Shutdown the game engine
void Shutdown();
// Pump messages from the OS
void MessagePump();
// Accessors for game screen size
int32 GetViewportWidth() { return m_nViewportWidth; }
int32 GetViewportHeight() { return m_nViewportHeight; }
// Function for drawing text to the screen, dwFormat is a combination of flags like DT_LEFT, DT_VCENTER etc...
bool BDrawString( HGAMEFONT hFont, RECT rect, DWORD dwColor, DWORD dwFormat, const char *pchText );
// Create a new font returning our internal handle value for it (0 means failure)
HGAMEFONT HCreateFont( int nHeight, int nFontWeight, bool bItalic, char * pchFont );
// Create a new texture returning our internal handle value for it (0 means failure)
HGAMETEXTURE HCreateTexture( byte *pRGBAData, uint32 uWidth, uint32 uHeight );
// 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 );
// Flush the line buffer
bool BFlushLineBuffer();
// Draw a point, the engine itself will manage batching these (although you can explicitly flush if you need to)
bool BDrawPoint( float xPos, float yPos, DWORD dwColor );
// Flush the point buffer
bool BFlushPointBuffer();
// Draw a filled quad
bool BDrawFilledQuad( float xPos0, float yPos0, float xPos1, float yPos1, DWORD dwColor );
// Draw a textured rectangle
bool BDrawTexturedQuad( float xPos0, float yPos0, float xPos1, float yPos1,
float u0, float v0, float u1, float v1, DWORD dwColor, HGAMETEXTURE hTexture );
// Flush any still cached quad buffers
bool BFlushQuadBuffer();
// Get the current state of a key
bool BIsKeyDown( DWORD dwVK );
// Get the first (in some arbitrary order) key down, if any
bool BGetFirstKeyDown( DWORD *pdwVK );
// Get current tick count for the game engine
uint64 GetGameTickCount() { return m_ulGameTickCount; }
// Get the tick count elapsed since the previous frame
// bugbug - We use this time to compute things like thrust and acceleration in the game,
// so it's important in doesn't jump ahead by large increments... Need a better
// way to handle that.
uint64 GetGameTicksFrameDelta() { return m_ulGameTickCount - m_ulPreviousGameTickCount; }
// Tell the game engine to update current tick count
void UpdateGameTickCount();
// Tell the game engine to sleep for a bit if needed to limit frame rate
bool BSleepForFrameRateLimit( uint32 ulMaxFrameRate );
// Check if the game engine hwnd currently has focus (and a working d3d device)
bool BGameEngineHasFocus() { return ::GetForegroundWindow() == m_hWnd && !m_bDeviceLost; }
// Track the state of keyboard input (these are public, but not part of the public interface)
void RecordKeyDown( DWORD dwVK );
void RecordKeyUp( DWORD dwVK );
private:
// Creates the hwnd for the game
bool BCreateGameWindow( int nShowCommand );
// Initializes D3D for the game
bool BInitializeD3D9();
// Resets all the render, texture, and sampler states to our defaults
void ResetRenderStates();
// Create a new vertex buffer returning our internal handle for it (0 means failure)
HGAMEVERTBUF HCreateVertexBuffer( uint32 nSizeInBytes, DWORD dwUsage, DWORD dwFVF );
// Lock an entire vertex buffer with the specified flags
bool BLockEntireVertexBuffer( HGAMEVERTBUF hVertBuf, void **ppVoid, DWORD dwFlags );
// Unlock a vertex buffer
bool BUnlockVertexBuffer( HGAMEVERTBUF hVertBuf );
// Release a vertex buffer and free its resources
bool BReleaseVertexBuffer( HGAMEVERTBUF hVertBuf );
// Set steam source
bool BSetStreamSource( HGAMEVERTBUF hVertBuf, uint32 uOffset, uint32 uStride );
// Render primitives out of the current stream source
bool BRenderPrimitive( D3DPRIMITIVETYPE primType, uint32 uStartVertex, uint32 uCount );
// Set vertex format
bool BSetFVF( DWORD dwFormat );
// Handle losing the d3d device (ie, release resources)
bool BHandleLostDevice();
// Handle reseting the d3d device (ie, acquire resources again)
bool BHandleResetDevice();
private:
// Tracks whether the engine is ready for use
bool m_bEngineReadyForUse;
// Tracks if we are shutting down
bool m_bShuttingDown;
// Color we clear the background of the window to each frame
DWORD m_dwBackgroundColor;
// HInstance for the application running the engine
HINSTANCE m_hInstance;
// HWND for the engine instance
HWND m_hWnd;
// IDirect3D9 interface
IDirect3D9 *m_pD3D9Interface;
// IDirect3DDevice9 interface
IDirect3DDevice9 *m_pD3D9Device;
// Size of the window to display the game in
int32 m_nWindowWidth;
int32 m_nWindowHeight;
// Size of actual d3d viewport (window size minus borders, title, etc)
int32 m_nViewportWidth;
int32 m_nViewportHeight;
// Next font handle value to give out
HGAMEFONT m_nNextFontHandle;
// Map of font handles to font objects
std::map<HGAMEFONT, ID3DXFont *> m_MapFontInstances;
// Next vertex buffer handle value to give out
HGAMEVERTBUF m_nNextVertBufferHandle;
// Map of handles to vertex buffer objects
struct VertBufData_t
{
bool m_bIsLocked;
IDirect3DVertexBuffer9 * m_pBuffer;
};
std::map<HGAMEVERTBUF, VertBufData_t> m_MapVertexBuffers;
HGAMETEXTURE m_nNextTextureHandle;
// Map of handles to texture objects
struct TextureData_t
{
byte *m_pRGBAData; // We keep a copy of the raw data so we can rebuild textures after a device is lost
uint32 m_uWidth;
uint32 m_uHeight;
LPDIRECT3DTEXTURE9 m_pTexture;
};
std::map<HGAMETEXTURE, TextureData_t> m_MapTextures;
// Vertex buffer for textured quads
HGAMEVERTBUF m_hQuadBuffer;
// Last texture used in drawing a batched quad
HGAMETEXTURE m_hLastTexture;
// Pointer to quad vertex data
TexturedQuadVertex_t *m_pQuadVertexes;
// How many quads are awaiting flushing
DWORD m_dwQuadsToFlush;
// Where does the current batch begin
DWORD m_dwQuadBufferBatchPos;
// White texture used when drawing filled quads
HGAMETEXTURE m_hTextureWhite;
// Currently set FVF format
DWORD m_dwCurrentFVF;
// Map of key state
std::set<DWORD> m_SetKeysDown;
// Current game time in milliseconds
uint64 m_ulGameTickCount;
// Game time at the start of the previous frame
uint64 m_ulPreviousGameTickCount;
// Divisor for turning QPC values to milliseconds
uint64 m_ulPerfCounterToMillisecondsDivisor;
// First value for QPC when we started the process
uint64 m_ulFirstQueryPerformanceCounterValue;
// Map of engine instances by HWND, used in wndproc to find engine instance for messages
static std::map<HWND, CGameEngineWin32 *> m_MapEngineInstances;
// Internal vertex buffer for batching line drawing
HGAMEVERTBUF m_hLineBuffer;
// Pointer to actual line buffer memory (valid only while locked)
LineVertex_t *m_pLineVertexes;
// Track how many lines are awaiting flushing in our line buffer
DWORD m_dwLinesToFlush;
// Track where the current batch starts in the vert buffer
DWORD m_dwLineBufferBatchPos;
// Internal vertex buffer for batching point drawing
HGAMEVERTBUF m_hPointBuffer;
// Pointer to actual point buffer memory (valid only while locked)
PointVertex_t *m_pPointVertexes;
// Track how many points are awaiting flushing in our line buffer
DWORD m_dwPointsToFlush;
// Track where the current batch starts in the vert buffer
DWORD m_dwPointBufferBatchPos;
// Track if we have lost the d3d device
bool m_bDeviceLost;
// Presentation parameters, saved in case of lost device needing reset
D3DPRESENT_PARAMETERS m_d3dpp;
};
#endif // GAMEENGINEWIN32_H
@@ -0,0 +1 @@
480
@@ -0,0 +1 @@
480
Binary file not shown.
Binary file not shown.
Binary file not shown.