Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Thu May 23, 2013 1:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Article - support for switch in scripts
PostPosted: Sun Feb 20, 2005 1:45 am 
Offline
picked up 100 armour

Joined: Thu Feb 03, 2005 2:22 am
Posts: 126
Location: London
I've posted an article showing how you can get support for switches in the scripts. This was a bit more complex than the previous article i wrote where i showed how to make an inequality operator for boolean types.

Here's the link: http://www.gamedev.no/doom3_switch.jsp

Comments and/or suggestions for other things you would like imlpemented in the scripts is welcome.

* Adding support for arrays would be cool, but not sure if i'm going to have an attempt at it.

This is what you can do after adding support for switches:
Code:
void player::testScript() {
   float test;
   test = 9999;

   switch ( test ) {
      case 9999 :
         sys.print("This works 1\n");
         break;
      case 99 :
         sys.print("This works 2\n");
         break;
      case 1 :
         sys.print("This works 3\n");
         break;
      default:
         sys.print"Default works?\n");
   }
}



Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 20, 2005 4:19 am 
Offline
a gun & a nice word
User avatar

Joined: Sat Jan 11, 2003 9:30 pm
Posts: 8713
Location: Orlando, FL
Very nice.

_________________
Image Staff
Learn something today? Why not write an article about it on modwiki.net?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 20, 2005 9:36 am 
Offline
fired 300 rounds

Joined: Sat Aug 21, 2004 11:00 pm
Posts: 393
Location: New Zealand
Outstanding.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 2:19 pm 
Offline
found a secret
User avatar

Joined: Sun Nov 10, 2002 1:21 pm
Posts: 578
Location: UK
Very nice.

Arrays would be very good.

_________________
Intel Core 2 Duo 3.00GHz 4MB Cache 1333MHz FSB / 4GB DR3
Asus 8800GT 512MB GDDR3 DVI PCI-E / 2x500GB SATA2 7200RPM 16MB Cache / Samsung Pebble SM2232BW 22" TFT 1680x1050 DVI


Top
 Profile E-mail  
 
 Post subject: Re: Article - support for switch in scripts
PostPosted: Mon Feb 21, 2005 3:32 pm 
Offline
found a secret

Joined: Wed Sep 08, 2004 8:48 am
Posts: 562
AO wrote:
This is what you can do after adding support for switches:


Apart form the obvious better structuring in teh script code, how well does this perofm in relation to a series of if statements? Is there a benefit for this, or is this more a cosmetically change? Still it is great to know that we can change the scripting language as well (I was not so sure on this). :)

In that case something I would like to request is alos can the scripting version be queried somehow? Otherwise there might be problems with script not working anymore because this or that feature is not supported. In case of more additions to the langauge there should be some method to determine this.


Top
 Profile E-mail  
 
 Post subject: Re: Article - support for switch in scripts
PostPosted: Wed Jun 17, 2009 7:43 pm 
Offline
fired 300 rounds

Joined: Thu Jun 16, 2005 4:01 pm
Posts: 311
I know bringing up an old thread is a no-no, I couldn't help but inquire as to how to implement a few more tokens into the script engine. specifically ArcSine, ArcCosine, and Atan2. support for those functions is included in Math.h for the idMath class:

Code:
   static float            ASin( float a );         // arc sine with 32 bits precision, input is clamped to [-1, 1] to avoid a silent NaN
   static float            ASin16( float a );         // arc sine with 16 bits precision, maximum absolute error is 6.7626e-05
   static double            ASin64( float a );         // arc sine with 64 bits precision

   static float            ACos( float a );         // arc cosine with 32 bits precision, input is clamped to [-1, 1] to avoid a silent NaN
   static float            ACos16( float a );         // arc cosine with 16 bits precision, maximum absolute error is 6.7626e-05
   static double            ACos64( float a );         // arc cosine with 64 bits precision

   static float            ATan( float a );         // arc tangent with 32 bits precision
   static float            ATan16( float a );         // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
   static double            ATan64( float a );         // arc tangent with 64 bits precision

   static float            ATan( float y, float x );   // arc tangent with 32 bits precision
   static float            ATan16( float y, float x );   // arc tangent with 16 bits precision, maximum absolute error is 1.3593e-08
   static double            ATan64( float y, float x );   // arc tangent with 64 bits precision



here's how cos goes from script to the engine in the game:

Code:
##doom_events.script:343
scriptEvent   float   cos( float degrees );

becomes:
Code:
##Script_Thread.cpp:45
const idEventDef EV_Thread_Cosine( "cos", "f", 'f' );

becomes:
Code:
##Script_Thread.cpp:124
EVENT( EV_Thread_Cosine,            idThread::Event_GetCosine )

becomes:
Code:
##Script_Thread.h:117
void   Event_GetCosine( float angle );

becomes:
Code:
##Script_Thread.cpp:1259
/*
================
idThread::Event_GetCosine
================
*/
void idThread::Event_GetCosine( float angle ) {
   ReturnFloat( idMath::Cos( DEG2RAD( angle ) ) );
}


It seems as though including those extra script arguments should be fairly easy to implement, no?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group