123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- size_t idDeclFX::Size( void ) const {
- return sizeof( idDeclFX );
- }
- void idDeclFX::Print( void ) const {
- const idDeclFX *list = this;
- common->Printf("%d events\n", list->events.Num() );
- for( int i = 0; i < list->events.Num(); i++ ) {
- switch( list->events[i].type ) {
- case FX_LIGHT:
- common->Printf("FX_LIGHT %s\n", list->events[i].data.c_str());
- break;
- case FX_PARTICLE:
- common->Printf("FX_PARTICLE %s\n", list->events[i].data.c_str());
- break;
- case FX_MODEL:
- common->Printf("FX_MODEL %s\n", list->events[i].data.c_str());
- break;
- case FX_SOUND:
- common->Printf("FX_SOUND %s\n", list->events[i].data.c_str());
- break;
- case FX_DECAL:
- common->Printf("FX_DECAL %s\n", list->events[i].data.c_str());
- break;
- case FX_SHAKE:
- common->Printf("FX_SHAKE %s\n", list->events[i].data.c_str());
- break;
- case FX_ATTACHLIGHT:
- common->Printf("FX_ATTACHLIGHT %s\n", list->events[i].data.c_str());
- break;
- case FX_ATTACHENTITY:
- common->Printf("FX_ATTACHENTITY %s\n", list->events[i].data.c_str());
- break;
- case FX_LAUNCH:
- common->Printf("FX_LAUNCH %s\n", list->events[i].data.c_str());
- break;
- case FX_SHOCKWAVE:
- common->Printf("FX_SHOCKWAVE %s\n", list->events[i].data.c_str());
- break;
- }
- }
- }
- void idDeclFX::List( void ) const {
- common->Printf("%s, %d stages\n", GetName(), events.Num() );
- }
- void idDeclFX::ParseSingleFXAction( idLexer &src, idFXSingleAction& FXAction ) {
- idToken token;
- FXAction.type = -1;
- FXAction.sibling = -1;
- FXAction.data = "<none>";
- FXAction.name = "<none>";
- FXAction.fire = "<none>";
- FXAction.delay = 0.0f;
- FXAction.duration = 0.0f;
- FXAction.restart = 0.0f;
- FXAction.size = 0.0f;
- FXAction.fadeInTime = 0.0f;
- FXAction.fadeOutTime = 0.0f;
- FXAction.shakeTime = 0.0f;
- FXAction.shakeAmplitude = 0.0f;
- FXAction.shakeDistance = 0.0f;
- FXAction.shakeFalloff = false;
- FXAction.shakeImpulse = 0.0f;
- FXAction.shakeIgnoreMaster = false;
- FXAction.lightRadius = 0.0f;
- FXAction.rotate = 0.0f;
- FXAction.random1 = 0.0f;
- FXAction.random2 = 0.0f;
- FXAction.lightColor = vec3_origin;
- FXAction.offset = vec3_origin;
- FXAction.axis = mat3_identity;
- FXAction.bindParticles = false;
- FXAction.explicitAxis = false;
- FXAction.noshadows = false;
- FXAction.particleTrackVelocity = false;
- FXAction.trackOrigin = false;
- FXAction.soundStarted = false;
- while (1) {
- if ( !src.ReadToken( &token ) ) {
- break;
- }
- if ( !token.Icmp( "}" ) ) {
- break;
- }
- if ( !token.Icmp( "shake" ) ) {
- FXAction.type = FX_SHAKE;
- FXAction.shakeTime = src.ParseFloat();
- src.ExpectTokenString(",");
- FXAction.shakeAmplitude = src.ParseFloat();
- src.ExpectTokenString(",");
- FXAction.shakeDistance = src.ParseFloat();
- src.ExpectTokenString(",");
- FXAction.shakeFalloff = src.ParseBool();
- src.ExpectTokenString(",");
- FXAction.shakeImpulse = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "noshadows" ) ) {
- FXAction.noshadows = true;
- continue;
- }
- if ( !token.Icmp( "name" ) ) {
- src.ReadToken( &token );
- FXAction.name = token;
- continue;
- }
- if ( !token.Icmp( "fire") ) {
- src.ReadToken( &token );
- FXAction.fire = token;
- continue;
- }
- if ( !token.Icmp( "random" ) ) {
- FXAction.random1 = src.ParseFloat();
- src.ExpectTokenString( "," );
- FXAction.random2 = src.ParseFloat();
- FXAction.delay = 0.0f;
- continue;
- }
- if ( !token.Icmp( "delay" ) ) {
- FXAction.delay = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "rotate" ) ) {
- FXAction.rotate = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "duration" ) ) {
- FXAction.duration = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "trackorigin" ) ) {
- FXAction.trackOrigin = src.ParseBool();
- continue;
- }
- if (!token.Icmp("restart")) {
- FXAction.restart = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "fadeIn" ) ) {
- FXAction.fadeInTime = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "fadeOut" ) ) {
- FXAction.fadeOutTime = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "size" ) ) {
- FXAction.size = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "offset" ) ) {
- FXAction.offset.x = src.ParseFloat();
- src.ExpectTokenString( "," );
- FXAction.offset.y = src.ParseFloat();
- src.ExpectTokenString( "," );
- FXAction.offset.z = src.ParseFloat();
- continue;
- }
- if ( !token.Icmp( "axis" ) ) {
- idVec3 v;
- v.x = src.ParseFloat();
- src.ExpectTokenString( "," );
- v.y = src.ParseFloat();
- src.ExpectTokenString( "," );
- v.z = src.ParseFloat();
- v.Normalize();
- FXAction.axis = v.ToMat3();
- FXAction.explicitAxis = true;
- continue;
- }
- if ( !token.Icmp( "angle" ) ) {
- idAngles a;
- a[0] = src.ParseFloat();
- src.ExpectTokenString( "," );
- a[1] = src.ParseFloat();
- src.ExpectTokenString( "," );
- a[2] = src.ParseFloat();
- FXAction.axis = a.ToMat3();
- FXAction.explicitAxis = true;
- continue;
- }
- if ( !token.Icmp( "uselight" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- for( int i = 0; i < events.Num(); i++ ) {
- if ( events[i].name.Icmp( FXAction.data ) == 0 ) {
- FXAction.sibling = i;
- FXAction.lightColor = events[i].lightColor;
- FXAction.lightRadius = events[i].lightRadius;
- }
- }
- FXAction.type = FX_LIGHT;
-
- declManager->FindMaterial( FXAction.data );
- continue;
- }
- if ( !token.Icmp( "attachlight" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- FXAction.type = FX_ATTACHLIGHT;
-
- declManager->FindMaterial( FXAction.data );
- continue;
- }
- if ( !token.Icmp( "attachentity" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- FXAction.type = FX_ATTACHENTITY;
-
- renderModelManager->FindModel( FXAction.data );
- continue;
- }
- if ( !token.Icmp( "launch" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- FXAction.type = FX_LAUNCH;
-
- declManager->FindType( DECL_ENTITYDEF, FXAction.data );
- continue;
- }
- if ( !token.Icmp( "useModel" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- for( int i = 0; i < events.Num(); i++ ) {
- if ( events[i].name.Icmp( FXAction.data ) == 0 ) {
- FXAction.sibling = i;
- }
- }
- FXAction.type = FX_MODEL;
-
- renderModelManager->FindModel( FXAction.data );
- continue;
- }
- if ( !token.Icmp( "light" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- src.ExpectTokenString( "," );
- FXAction.lightColor[0] = src.ParseFloat();
- src.ExpectTokenString( "," );
- FXAction.lightColor[1] = src.ParseFloat();
- src.ExpectTokenString( "," );
- FXAction.lightColor[2] = src.ParseFloat();
- src.ExpectTokenString( "," );
- FXAction.lightRadius = src.ParseFloat();
- FXAction.type = FX_LIGHT;
-
- declManager->FindMaterial( FXAction.data );
- continue;
- }
-
- if ( !token.Icmp( "model" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- FXAction.type = FX_MODEL;
-
- renderModelManager->FindModel( FXAction.data );
- continue;
- }
- if ( !token.Icmp( "particle" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- FXAction.type = FX_PARTICLE;
-
- renderModelManager->FindModel( FXAction.data );
- continue;
- }
- if ( !token.Icmp( "decal" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- FXAction.type = FX_DECAL;
-
- declManager->FindMaterial( FXAction.data );
- continue;
- }
- if ( !token.Icmp( "particleTrackVelocity" ) ) {
- FXAction.particleTrackVelocity = true;
- continue;
- }
- if ( !token.Icmp( "sound" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- FXAction.type = FX_SOUND;
-
- declManager->FindSound( FXAction.data );
- continue;
- }
- if ( !token.Icmp( "ignoreMaster" ) ) {
- FXAction.shakeIgnoreMaster = true;
- continue;
- }
- if ( !token.Icmp( "shockwave" ) ) {
- src.ReadToken( &token );
- FXAction.data = token;
- FXAction.type = FX_SHOCKWAVE;
-
- declManager->FindType( DECL_ENTITYDEF, FXAction.data );
- continue;
- }
- src.Warning( "FX File: bad token" );
- continue;
- }
- }
- bool idDeclFX::Parse( const char *text, const int textLength ) {
- idLexer src;
- idToken token;
- src.LoadMemory( text, textLength, GetFileName(), GetLineNum() );
- src.SetFlags( DECL_LEXER_FLAGS );
- src.SkipUntilString( "{" );
-
- while( 1 ) {
-
- if ( !src.ReadToken( &token ) ) {
- break;
- }
- if ( token == "}" ) {
- break;
- }
- if ( !token.Icmp( "bindto" ) ) {
- src.ReadToken( &token );
- joint = token;
- continue;
- }
- if ( !token.Icmp( "{" ) ) {
- idFXSingleAction action;
- ParseSingleFXAction( src, action );
- events.Append( action );
- continue;
- }
- }
- if ( src.HadError() ) {
- src.Warning( "FX decl '%s' had a parse error", GetName() );
- return false;
- }
- return true;
- }
- const char *idDeclFX::DefaultDefinition( void ) const {
- return
- "{\n"
- "\t" "{\n"
- "\t\t" "duration\t5\n"
- "\t\t" "model\t\t_default\n"
- "\t" "}\n"
- "}";
- }
- void idDeclFX::FreeData( void ) {
- events.Clear();
- }
|