Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New I/O/KV for movie entities #362

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions sp/src/game/client/c_movie_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,67 @@ IMPLEMENT_CLIENTCLASS_DT( C_MovieDisplay, DT_MovieDisplay, CMovieDisplay )
RecvPropBool( RECVINFO( m_bMuted ) ),
RecvPropString( RECVINFO( m_szMovieFilename ) ),
RecvPropString( RECVINFO( m_szGroupName ) ),
#ifdef MAPBASE
RecvPropBool( RECVINFO( m_bPaused ) ),
RecvPropFloat( RECVINFO( m_flTargetTime ) ),
RecvPropInt( RECVINFO( m_nTargetFrame ) ),
#endif
END_RECV_TABLE()

#ifdef MAPBASE
BEGIN_DATADESC( C_MovieDisplay )

DEFINE_FIELD( m_nVideoFrame, FIELD_INTEGER ),

END_DATADESC()
#endif

C_MovieDisplay::C_MovieDisplay()
{
}

C_MovieDisplay::~C_MovieDisplay()
{
}

#ifdef MAPBASE
void C_MovieDisplay::OnDataChanged( DataUpdateType_t type )
{
BaseClass::OnDataChanged( type );

OnRestore();

if (type == DATA_UPDATE_DATATABLE_CHANGED)
{
if (m_flTargetTime != m_flOldTargetTime)
{
m_bNewTargetTime = true;
m_flOldTargetTime = m_flTargetTime;
}
if (m_nTargetFrame != m_nOldTargetFrame)
{
m_bNewTargetFrame = true;
m_nOldTargetFrame = m_nTargetFrame;
}
}
}

//-----------------------------------------------------------------------------
// handler to do stuff before you are saved
//-----------------------------------------------------------------------------
void C_MovieDisplay::OnSave()
{
BaseClass::OnSave();
}

//-----------------------------------------------------------------------------
// handler to do stuff after you are restored
//-----------------------------------------------------------------------------
void C_MovieDisplay::OnRestore()
{
BaseClass::OnRestore();

m_bNewTargetFrame = true;
m_nOldTargetFrame = m_nTargetFrame = m_nVideoFrame;
}
#endif
39 changes: 39 additions & 0 deletions sp/src/game/client/c_movie_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,38 @@ class C_MovieDisplay : public C_BaseEntity
public:
DECLARE_CLASS( C_MovieDisplay, C_BaseEntity );
DECLARE_CLIENTCLASS();
#ifdef MAPBASE
DECLARE_DATADESC();
#endif

C_MovieDisplay();
~C_MovieDisplay();

#ifdef MAPBASE
void OnDataChanged( DataUpdateType_t type );

void UpdateVideoFrame( int nFrame ) { m_nVideoFrame = nFrame; }

void OnSave();
void OnRestore();
#endif

bool IsEnabled( void ) const { return m_bEnabled; }
bool IsLooping( void ) const { return m_bLooping; }
bool IsMuted(void) const { return m_bMuted; }

#ifdef MAPBASE
bool IsPaused(void) const { return m_bPaused; }

float GetTargetTime(void) const { return m_flTargetTime; }
bool HasNewTargetTime() const { return m_bNewTargetTime; }
void ResetTargetTime() { m_bNewTargetTime = false; m_flOldTargetTime = -1.0f; }

float GetTargetFrame( void ) const { return m_nTargetFrame; }
bool HasNewTargetFrame() const { return m_bNewTargetFrame; }
void ResetTargetFrame() { m_bNewTargetFrame = false; m_nTargetFrame = -1; }
#endif

const char *GetMovieFilename( void ) const { return m_szMovieFilename; }
const char *GetGroupName( void ) const { return m_szGroupName; }

Expand All @@ -31,6 +55,21 @@ class C_MovieDisplay : public C_BaseEntity
bool m_bMuted;
char m_szMovieFilename[128];
char m_szGroupName[128];

#ifdef MAPBASE
bool m_bPaused = false;

bool m_bNewTargetTime = false;
float m_flTargetTime = 0.0f;
float m_flOldTargetTime = 0.0f;

bool m_bNewTargetFrame = false;
int m_nTargetFrame = 0;
int m_nOldTargetFrame = 0;

// Updated by screen, restored to screen after save load
int m_nVideoFrame;
#endif
};

#endif //C_MOVIE_DISPLAY_H
22 changes: 22 additions & 0 deletions sp/src/game/client/vgui_movie_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ void CMovieDisplayScreen::UpdateMovie( void )
bScreenActive = false;
}

#ifdef MAPBASE
if ( bScreenActive && m_hScreenEntity->IsPaused() )
{
bScreenActive = false;
}
#endif

// See if we've changed our activity state
if ( bScreenActive != m_bLastActiveState )
{
Expand All @@ -286,6 +293,21 @@ void CMovieDisplayScreen::UpdateMovie( void )
// Update the frame if we're currently enabled
if ( bScreenActive )
{
#ifdef MAPBASE
if ( m_hScreenEntity->HasNewTargetTime() )
{
m_VideoMaterial->SetTime( m_hScreenEntity->GetTargetTime() );
m_hScreenEntity->ResetTargetTime();
}
else if ( m_hScreenEntity->HasNewTargetFrame() )
{
m_VideoMaterial->SetFrame( m_hScreenEntity->GetTargetFrame() );
m_hScreenEntity->ResetTargetFrame();
}

m_hScreenEntity->UpdateVideoFrame( m_VideoMaterial->GetCurrentFrame() );
#endif

// Update our frame
if ( m_VideoMaterial->Update() == false )
{
Expand Down
79 changes: 79 additions & 0 deletions sp/src/game/server/movie_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ class CMovieDisplay : public CBaseEntity

void InputSetDisplayText( inputdata_t &inputdata );

#ifdef MAPBASE
void InputPause( inputdata_t &inputdata );
void InputUnpause( inputdata_t &inputdata );

void InputSetTime( inputdata_t &inputdata );
void InputSetFrame( inputdata_t &inputdata );
#endif

private:

// Control panel
Expand All @@ -57,6 +65,12 @@ class CMovieDisplay : public CBaseEntity
CNetworkVar( bool, m_bLooping );
CNetworkVar( bool, m_bMuted);

#ifdef MAPBASE
CNetworkVar( bool, m_bPaused );
CNetworkVar( float, m_flTargetTime );
CNetworkVar( int, m_nTargetFrame );
#endif

CNetworkString( m_szDisplayText, 128 );

// Filename of the movie to play
Expand Down Expand Up @@ -98,6 +112,12 @@ BEGIN_DATADESC( CMovieDisplay )
DEFINE_KEYFIELD( m_bLooping, FIELD_BOOLEAN, "looping" ),
DEFINE_KEYFIELD( m_bMuted, FIELD_BOOLEAN, "muted"),

#ifdef MAPBASE
DEFINE_KEYFIELD( m_bPaused, FIELD_BOOLEAN, "paused" ),
DEFINE_KEYFIELD( m_flTargetTime, FIELD_FLOAT, "starttime" ),
DEFINE_KEYFIELD( m_nTargetFrame, FIELD_INTEGER, "startframe" ),
#endif

DEFINE_FIELD( m_bDoFullTransmit, FIELD_BOOLEAN ),

DEFINE_FIELD( m_hScreen, FIELD_EHANDLE ),
Expand All @@ -107,6 +127,14 @@ BEGIN_DATADESC( CMovieDisplay )

DEFINE_INPUTFUNC( FIELD_STRING, "SetDisplayText", InputSetDisplayText ),

#ifdef MAPBASE
DEFINE_INPUTFUNC( FIELD_VOID, "Pause", InputPause ),
DEFINE_INPUTFUNC( FIELD_VOID, "Unpause", InputUnpause ),

DEFINE_INPUTFUNC( FIELD_FLOAT, "SetTime", InputSetTime ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "SetFrame", InputSetFrame ),
#endif

END_DATADESC()

IMPLEMENT_SERVERCLASS_ST( CMovieDisplay, DT_MovieDisplay )
Expand All @@ -115,6 +143,11 @@ IMPLEMENT_SERVERCLASS_ST( CMovieDisplay, DT_MovieDisplay )
SendPropBool( SENDINFO( m_bMuted ) ),
SendPropString( SENDINFO( m_szMovieFilename ) ),
SendPropString( SENDINFO( m_szGroupName ) ),
#ifdef MAPBASE
SendPropBool( SENDINFO( m_bPaused ) ),
SendPropFloat( SENDINFO( m_flTargetTime ) ),
SendPropInt( SENDINFO( m_nTargetFrame ) ),
#endif
END_SEND_TABLE()

CMovieDisplay::~CMovieDisplay()
Expand Down Expand Up @@ -293,6 +326,52 @@ void CMovieDisplay::InputSetDisplayText( inputdata_t &inputdata )
Q_strcpy( m_szDisplayText.GetForModify(), inputdata.value.String() );
}

#ifdef MAPBASE
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CMovieDisplay::InputPause( inputdata_t &inputdata )
{
if (!m_bPaused)
{
m_bPaused = true;
DispatchUpdateTransmitState();
}
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CMovieDisplay::InputUnpause( inputdata_t &inputdata )
{
if (m_bPaused)
{
m_bPaused = false;
DispatchUpdateTransmitState();
}
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CMovieDisplay::InputSetTime( inputdata_t &inputdata )
{
float flTime = MAX( inputdata.value.Float(), 0 );
m_flTargetTime = flTime;
DispatchUpdateTransmitState();
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CMovieDisplay::InputSetFrame( inputdata_t &inputdata )
{
int nFrame = MAX( inputdata.value.Int(), 0 );
m_nTargetFrame = nFrame;
DispatchUpdateTransmitState();
}
#endif

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
Expand Down
Loading