Format most source files

This commit is contained in:
smallmodel committed 2025-07-19 23:30:20 +02:00
1 parent 57abfa297b
commit a3f520de8c
217 files changed
+20330 -25450

No files matched your search

+108 -119
View File
@@ -27,20 +27,20 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "level.h"
#if defined(GAME_DLL)
#include "archive.h"
# include "archive.h"
#endif
Event EV_ScriptTimer_Think
(
"scripttimer_think",
EV_CODEONLY,
NULL,
NULL,
"Internal event",
EV_NORMAL
"scripttimer_think",
EV_CODEONLY,
NULL,
NULL,
"Internal event",
EV_NORMAL
);
Container< ScriptTimer * > m_scriptTimers;
Container<ScriptTimer *> m_scriptTimers;
/*void ScriptTimer::HandleTimer( float frametime )
{
@@ -56,121 +56,114 @@ Container< ScriptTimer * > m_scriptTimers;
}
}*/
ScriptTimer::ScriptTimer( timertype_e type )
ScriptTimer::ScriptTimer(timertype_e type)
{
Reset();
bEnabled = false;
Reset();
bEnabled = false;
setType( type );
setType(type);
m_scriptTimers.AddObject( this );
m_scriptTimers.AddObject(this);
}
ScriptTimer::~ScriptTimer()
{
Disable();
Disable();
if( m_scriptTimers.IndexOfObject( this ) )
{
m_scriptTimers.RemoveObject( this );
}
if (m_scriptTimers.IndexOfObject(this)) {
m_scriptTimers.RemoveObject(this);
}
}
void ScriptTimer::Archive( Archiver &arc )
void ScriptTimer::Archive(Archiver& arc)
{
Listener::Archive( arc );
Listener::Archive(arc);
#ifdef CGAME_DLL
arc.ArchiveFloat( &targetTime );
arc.ArchiveFloat( &currentTime );
arc.ArchiveFloat( &realTime );
arc.ArchiveFloat(&targetTime);
arc.ArchiveFloat(&currentTime);
arc.ArchiveFloat(&realTime);
arc.ArchiveFloat( &glideRatio );
arc.ArchiveFloat(&glideRatio);
arc.ArchiveInteger( ( int * )&timerType );
arc.ArchiveInteger((int *)&timerType);
arc.ArchiveBool( &bEnabled );
arc.ArchiveBool(&bEnabled);
if( arc.Loading() && bEnabled ) {
Enable();
}
if (arc.Loading() && bEnabled) {
Enable();
}
#endif
}
void ScriptTimer::GlideRefresh()
{
if( timerType != TIMER_GLIDE ) {
return;
}
if (timerType != TIMER_GLIDE) {
return;
}
if( targetTime <= 0.0f ){
return;
}
if (targetTime <= 0.0f) {
return;
}
float r = realTime / ( targetTime * 0.5f );
float r = realTime / (targetTime * 0.5f);
if( r > 1.0f )
{
glideRatio = 2.0f - 2.0f * ( r - 1.0f );
if (r > 1.0f) {
glideRatio = 2.0f - 2.0f * (r - 1.0f);
if( glideRatio < 0.0f ) {
glideRatio = 0.0f;
}
}
else
{
glideRatio = 2.0f * r;
if (glideRatio < 0.0f) {
glideRatio = 0.0f;
}
} else {
glideRatio = 2.0f * r;
if( glideRatio > 2.0f ) {
glideRatio = 2.0f;
}
}
if (glideRatio > 2.0f) {
glideRatio = 2.0f;
}
}
}
void ScriptTimer::Think( Event *ev )
void ScriptTimer::Think(Event *ev)
{
if( !bEnabled ) {
return;
}
if (!bEnabled) {
return;
}
#ifdef CGAME_DLL
float frametime = ( float )cg->frametime;
float frametime = (float)cg->frametime;
#else
float frametime = level.frametime;
float frametime = level.frametime;
#endif
GlideRefresh();
GlideRefresh();
if( currentTime < targetTime )
{
realTime += frametime;
if (currentTime < targetTime) {
realTime += frametime;
if( timerType == TIMER_GLIDE ) {
currentTime += frametime * glideRatio;
} else {
currentTime += frametime;
}
}
else
{
currentTime = targetTime;
realTime = targetTime;
if (timerType == TIMER_GLIDE) {
currentTime += frametime * glideRatio;
} else {
currentTime += frametime;
}
} else {
currentTime = targetTime;
realTime = targetTime;
bEnabled = false;
CancelEventsOfType( &EV_ScriptTimer_Think );
bEnabled = false;
CancelEventsOfType(&EV_ScriptTimer_Think);
return;
}
return;
}
CancelEventsOfType( &EV_ScriptTimer_Think );
PostEvent( EV_ScriptTimer_Think, level.frametime );
CancelEventsOfType(&EV_ScriptTimer_Think);
PostEvent(EV_ScriptTimer_Think, level.frametime);
}
void ScriptTimer::Disable()
{
bEnabled = false;
bEnabled = false;
CancelEventsOfType( &EV_ScriptTimer_Think );
CancelEventsOfType(&EV_ScriptTimer_Think);
}
void ScriptTimer::Enable()
@@ -183,93 +176,89 @@ void ScriptTimer::Enable()
qboolean ScriptTimer::Done()
{
return ( currentTime >= targetTime );
return (currentTime >= targetTime);
}
float ScriptTimer::GetCurrentTime()
{
return realTime;
return realTime;
}
float ScriptTimer::GetRatio()
{
float ratio;
float ratio;
if( targetTime <= 0.0f ) {
return 1.0f;
}
if (targetTime <= 0.0f) {
return 1.0f;
}
ratio = ( currentTime / targetTime );
ratio = (currentTime / targetTime);
// ratio must not go below 0.0 and above 1.0
// ratio must not go below 0.0 and above 1.0
return ( ratio < 0.0f ? 0.0f : ratio > 1.0f ? 1.0f : ratio );
return (ratio < 0.0f ? 0.0f : ratio > 1.0f ? 1.0f : ratio);
}
float ScriptTimer::GetTime()
{
return targetTime;
return targetTime;
}
float ScriptTimer::LerpValue( float start, float end )
float ScriptTimer::LerpValue(float start, float end)
{
return start + ( end - start ) * GetRatio();
return start + (end - start) * GetRatio();
}
Vector ScriptTimer::LerpValue( Vector start, Vector end )
Vector ScriptTimer::LerpValue(Vector start, Vector end)
{
return start + ( end - start ) * GetRatio();
return start + (end - start) * GetRatio();
}
void ScriptTimer::Reset()
{
currentTime = 0.f;
realTime = 0.f;
currentTime = 0.f;
realTime = 0.f;
glideRatio = 0.f;
glideRatio = 0.f;
}
void ScriptTimer::SetCurrentTime( float time )
void ScriptTimer::SetCurrentTime(float time)
{
realTime = time * 1000.0f;
realTime = time * 1000.0f;
if( timerType == TIMER_GLIDE )
{
GlideRefresh();
currentTime = time * 1000.0f * glideRatio;
}
else
{
currentTime = time * 1000.0f;
}
if (timerType == TIMER_GLIDE) {
GlideRefresh();
currentTime = time * 1000.0f * glideRatio;
} else {
currentTime = time * 1000.0f;
}
}
void ScriptTimer::SetPhase( float phase )
void ScriptTimer::SetPhase(float phase)
{
float t = targetTime * ( phase / 2.0f ) / 1000.0f;
float t = targetTime * (phase / 2.0f) / 1000.0f;
SetCurrentTime( t );
SetCurrentTime(t);
}
void ScriptTimer::SetTime( float time )
void ScriptTimer::SetTime(float time)
{
Reset();
Reset();
targetTime = time * 1000.0f;
targetTime = time * 1000.0f;
}
bool ScriptTimer::isEnabled()
{
return bEnabled;
return bEnabled;
}
void ScriptTimer::setType( timertype_e type )
void ScriptTimer::setType(timertype_e type)
{
timerType = type;
timerType = type;
}
CLASS_DECLARATION( Listener, ScriptTimer, NULL )
{
{ &EV_ScriptTimer_Think, &ScriptTimer::Think },
{ NULL, NULL }
CLASS_DECLARATION(Listener, ScriptTimer, NULL) {
{&EV_ScriptTimer_Think, &ScriptTimer::Think},
{NULL, NULL }
};