Last active
March 25, 2016 07:34
-
-
Save kkabdol/f452d14619c0bd86522e to your computer and use it in GitHub Desktop.
HumanView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef std::list< shared_ptr< IScreenElement > > ScreenElementList; | |
class HumanView : public IGameView | |
{ | |
protected: | |
GameViewI m_ViewId; | |
optional< ActorId > m_ActorId; | |
// this CProcessManager is for things like button animations, etc. | |
CProcessManager * m_pProcessManager; | |
DWORD m_currTick; // time right now | |
DWORD m_lastDraw; // last time the game rendered | |
bool m_runFullSpeed; // set to true if you want to run full speed | |
ID3DXFont * m_pFont; | |
ID3DXSprite * m_pTextSprite; | |
virtual void VRenderText( CDXUTTextHelper &txtHelper ) {}; | |
public: | |
// Implement the IGameView interface | |
virtual HRESULT VOnRestore(); | |
virtual void VOnRender( double fTime, float fElapsedTime ); | |
virtual void VOnLostDevice(); | |
virtual GameViewType VGetType() { return GameView_Human; } | |
virtual GameViewIdVGetId() const { return m_ViewId; } | |
virtual void VOnAttach( GameViewId vid, optional< ActorId > aid ) | |
{ | |
m_ViewId = vid; | |
m_ActorId = aid; | |
} | |
virtual LRESULT CALLBACK VOnMsgProc( AppMsg Msg ); | |
virtual void VOnUpdate( int deltaMilliseconds ); | |
// Virtual methods to control the layering of interface elements. | |
virtual void VPushElement( shared_ptr< IScreenElement > pScreen ); | |
virtual void VPopElement(); | |
~HumanView(); | |
HumanView(); | |
ScreenElementList m_ScreenElements; | |
// Interface sensitive objects | |
shared_ptr< IMouseHandler > m_MouseHandler; | |
shared_ptr< IKeyboardHandler > m_KeyboardHandler; | |
// Audio | |
bool InitAudio(); | |
}; | |
void HumanView::VOnRender( double fTime, float fElapsedTime ) | |
{ | |
m_currTick = timeGetTime(); | |
// early out - we've already drawn in this tick | |
if ( m_currTick == m_lastDraw ) | |
return; | |
HRESULT hr; | |
// It is time to draw ? | |
if( m_runFullSpeed || | |
( ( m_currTick - m_lastDraw ) > SCREEN_REFRESH_RATE) ) | |
{ | |
// Clear the render target and the zbuffer | |
V( DXUTGetD3D9Device()->Clear( ( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) ); | |
// Render the scene | |
if( SUCCEEDED( DXUTGetD3D9Device()->BeginScene() ) ) | |
{ | |
CDXUTTextHelper txtHelper( m_pFont, m_pTextSprite, 15 ); | |
VRenderText( txtHelper ); | |
m_ScreenElements.sort( SortBy_SharedPtr_Content< IScreenElement >() ); | |
for( ScreenElementList::iterator i = m_ScreenElements.begin(); i != m_ScreenElements.end(); ++i ) | |
{ | |
if( ( *i )->VIsVisible() ) | |
{ | |
( *i )->VOnRender( fTime, fElapsedTime ); | |
} | |
} | |
// record the last successful paint | |
m_lastDraw = m_currTick; | |
} | |
V( DXUTGetD3D9Device()->EndScene() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment