home *** CD-ROM | disk | FTP | other *** search
/ Quark 3 / Quark3.iso / KATALOG / ARCHIV / TOOL / T001.ZIP / SOURCE.ZIP / Script.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-19  |  24.6 KB  |  821 lines

  1. /*
  2. Copyright (C) Matthew 'pagan' Baranowski & Sander 'FireStorm' van Rossen
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. */
  18.  
  19.  
  20. /****************/
  21. /* !!WARNING!!  */
  22. /* UNDER HEAVY  */
  23. /* CONSTRUCTION */
  24. /****************/
  25.  
  26. #include "system.h"
  27.  
  28.  
  29. /*
  30. special map names:
  31.     $lightmap
  32.     *white
  33.     $whiteimage
  34.     $fromblack
  35.  
  36. types of waves:
  37.     "wave","sin"            ,float,float,float,float
  38.     "wave","inversesawtooth",float,float,float,float
  39.     "wave","sawtooth"        ,float,float,float,float
  40.     "wave","square"            ,float,float,float,float
  41.     "wave","noise"            ,float,float,float,float
  42.     "wave","triangle"        ,float,float,float,float
  43.  
  44. }
  45. */
  46.  
  47. void    clean( char*& line )
  48. {
  49.     unsigned int i;
  50.     if ( line[ 0 ] != 0 )
  51.     {
  52.         i = 0;while ( ( i < strlen( line ) ) && ( line[ i ] != '/' ) ) i++;
  53.         if ( ( line[ i ] == '/' ) && ( line[ i + 1 ] == '/' )) line[ i ] = 0;
  54.         if ( line[ 0 ] != 0 )
  55.         {
  56.             for ( i = 0 ; i < strlen( line ) ; i++ )
  57.                 if ( line[ i ] ==  9 ) line[ i ] = 32; else
  58.                 if ( line[ i ] == 10 ) line[ i ] = 32;
  59.             
  60.             i = strlen( line ) - 1 ;
  61.             while ( line[ i ] == 32 ) i--;
  62.             line[ i + 1 ] = 0;
  63.  
  64.             if ( line[ 0 ] != 0 )
  65.             {
  66.                 while ( line[ 0 ] == 32 ) line++;
  67.  
  68.                 if ( line[ 0 ] == 0 )
  69.                     line = NULL;
  70.             } else
  71.                 line = NULL;
  72.         } else
  73.             line = NULL;
  74.     } else
  75.         line = NULL;
  76. }
  77.  
  78. char*    getstring( char*& line )
  79. {
  80.     if ( line != NULL )
  81.     {
  82.         unsigned int i;
  83.         char*    retptr = line;
  84.         i = 0;while ( ( line[ i ] != 32 ) && ( line[ i ] != 0 ) ) i++;
  85.         if ( line[ i ] != 0 ) 
  86.         {
  87.             line[ i ] = 0;
  88.             line = &line[ i + 1 ];
  89.             if ( line[ 0 ] == 0 )
  90.                 line = NULL; 
  91.             else while ( line[ 0 ] == 32 ) line++;
  92.         } else
  93.             line = NULL;
  94.         return retptr;
  95.     } else
  96.         return NULL;
  97. }
  98.  
  99. void Error (char *error, ...);
  100. void Debug (char *error, ...);
  101.  
  102. /*START UNFINISHED BIT*/
  103.  
  104. class RenderPass
  105. {
  106. public:
  107.     //tcMod - texcoords
  108.     float        rp_rotate,rp_scalex,rp_scaley,rp_scrollx,rp_scrolly,
  109.                 //i don't know what the values a-d are for.
  110.                 rp_turba,rp_turbb,rp_turbc,rp_turbd,
  111.                 //i don't know what the values a-d are for.
  112.                 rp_stretchsina,rp_stretchsinb,rp_stretchsinc,rp_stretchsind;
  113.     //various gl functions    
  114.     GLenum        blend_sfactor, blend_dfactor,alpha_func,depth_func;
  115.     GLclampf    alpha_ref;
  116.  
  117.     //misc commands
  118.     bool    rp_detail,rp_depthwrite,rp_clamptexcoords;
  119.  
  120.     void    AddParam( char* Type, char* Var );
  121. };
  122.  
  123. class Surface
  124. {
  125. public:
  126.     //surfaceparam
  127.     bool    sp_trans      ,sp_metalsteps,sp_nolightmap,sp_nodraw    ,sp_noimpact,
  128.             sp_nonsolid   ,sp_nomarks   ,sp_nodrop    ,sp_nodamage  ,sp_playerclip,
  129.             sp_structural ,sp_slick     ,sp_origin    ,sp_areaportal,sp_fog,
  130.             sp_lightfilter,sp_water     ,sp_slime     ,sp_sky       ,sp_lava;
  131.     //cull
  132.     enum    {cull_none, cull_disable, cull_twosided, cull_backsided, cull_back} cull;
  133.  
  134.     //misc commands
  135.     bool    sf_portal,sf_fogonly,sf_nomipmaps,sf_polygonOffset,
  136.             sf_lightning,sf_backsided,sf_qer_nocarve;
  137.     float    sf_light,sf_tesssize,sf_sort,sf_qer_trans,sf_q3map_backsplash,
  138.             sf_q3map_surfacelight;
  139.     char    *sf_sky,*sf_q3map_lightimage,*sf_qer_editorimage;
  140.  
  141.  
  142.     void    AddParam( char* Type, char* Var );
  143.     void    AddPass( RenderPass*& Pass );
  144. };
  145.  
  146. Surface*    CreateSurface( char* Name )
  147. {
  148.     return new Surface;
  149. }
  150.  
  151. void    RenderPass::AddParam( char* Type, char* Var )
  152. {
  153.     char*    Token;
  154.     if ( stricmp( Type , "tcMod" ) == 0 )
  155.     {
  156.         if ( Var == NULL )
  157.             Error( "token expected after surfaceparam, but none found");
  158.  
  159.         Token = getstring( Var );
  160.         if ( Var == NULL )
  161.             Error( "unexpected end after token: %s" , Token );
  162.         
  163.         if ( stricmp( Token , "rotate" ) == 0 )
  164.         {
  165.             Token = getstring( Var );
  166.             if ( Var != NULL )
  167.                 Error( "%s followed by unexpected token: %s" , Token, Var );
  168.  
  169.             //TODO: add check if it's really a number
  170.             rp_rotate = (float)atof(Token);
  171.         } else
  172.         if ( stricmp( Token , "scale" ) == 0 )
  173.         {
  174.             Token = getstring( Var );
  175.             if ( Var == NULL )
  176.                 Error( "unexpected end after token: %s" , Token );
  177.  
  178.             //TODO: add check if it's really a number
  179.             rp_scalex = (float)atof(Token);
  180.  
  181.             Token = getstring( Var );
  182.             if ( Var != NULL )
  183.                 Error( "%s followed by unexpected token: %s" , Token, Var );
  184.  
  185.             //TODO: add check if it's really a number
  186.             rp_scaley = (float)atof(Token);
  187.  
  188.         } else
  189.         if ( stricmp( Token , "scroll" ) == 0 )
  190.         {
  191.             Token = getstring( Var );
  192.             if ( Var == NULL )
  193.                 Error( "unexpected end after token: %s" , Token );
  194.  
  195.             //TODO: add check if it's really a number
  196.             rp_scrollx = (float)atof(Token);
  197.  
  198.             Token = getstring( Var );
  199.             //there is this "tcmod scroll" with four!! paramters..
  200.             //i have no idear what the other 2 are for.
  201. //            if ( Var != NULL )
  202. //                Error( "%s followed by unexpected token: %s" , Token, Var );
  203.  
  204.             //TODO: add check if it's really a number
  205.             rp_scrolly = (float)atof(Token);
  206.  
  207.         } else
  208.         if ( stricmp( Token , "turb" ) == 0 )
  209.         {
  210.             Token = getstring( Var );
  211.             if ( Var == NULL )
  212.                 Error( "unexpected end after token: %s" , Token );
  213.  
  214.             //TODO: add check if it's really a number
  215.             rp_turba = (float)atof(Token);
  216.  
  217.             Token = getstring( Var );
  218.             if ( Var == NULL )
  219.                 Error( "unexpected end after token: %s" , Token );
  220.  
  221.             //TODO: add check if it's really a number
  222.             rp_turbb = (float)atof(Token);
  223.  
  224.             Token = getstring( Var );
  225.             if ( Var == NULL )
  226.                 Error( "unexpected end after token: %s" , Token );
  227.  
  228.             //TODO: add check if it's really a number
  229.             rp_turbc = (float)atof(Token);
  230.  
  231.             Token = getstring( Var );
  232.             if ( Var != NULL )
  233.                 Error( "%s followed by unexpected token: %s" , Token, Var );
  234.  
  235.             //TODO: add check if it's really a number
  236.             rp_turbd = (float)atof(Token);
  237.         } else
  238.         if ( stricmp( Token , "stretch" ) == 0 )
  239.         {
  240.             Token = getstring( Var );
  241.             if ( Var == NULL )
  242.                 Error( "unexpected end after token: %s" , Token );
  243.  
  244.             if ( stricmp( Type , "sin" ) != 0 )
  245.                 Error( "unknown tcmod stretch function: %s" , Token );
  246.  
  247.             //TODO: add check if it's really a number
  248.             rp_stretchsina = (float)atof(Token);
  249.  
  250.             Token = getstring( Var );
  251.             if ( Var == NULL )
  252.                 Error( "unexpected end after token: %s" , Token );
  253.  
  254.             //TODO: add check if it's really a number
  255.             rp_stretchsinb = (float)atof(Token);
  256.  
  257.             Token = getstring( Var );
  258.             if ( Var == NULL )
  259.                 Error( "unexpected end after token: %s" , Token );
  260.  
  261.             //TODO: add check if it's really a number
  262.             rp_stretchsinc = (float)atof(Token);
  263.  
  264.             Token = getstring( Var );
  265.             if ( Var != NULL )
  266.                 Error( "%s followed by unexpected token: %s" , Token, Var );
  267.  
  268.             //TODO: add check if it's really a number
  269.             rp_stretchsind = (float)atof(Token);
  270.         } else
  271.             Error("unknown tcmod command found %s:",Token);
  272.     } else
  273.     if ( stricmp( Type , "blendfunc" ) == 0 )
  274.     {
  275.         if ( Var == NULL )
  276.             Error( "token expected after blendfunc, but none found");
  277.  
  278.         Token = getstring( Var );
  279.         if ( Var == NULL )
  280.             Error( "unexpected end after token: %s" , Token );
  281.  
  282.         if ( stricmp( Token , "gl_zero"                    ) == 0 ) blend_sfactor=GL_ZERO;else
  283.         if ( stricmp( Token , "gl_one"                    ) == 0 ) blend_sfactor=GL_ONE;else
  284.         if ( stricmp( Token , "gl_dst_color"            ) == 0 ) blend_sfactor=GL_DST_COLOR;else
  285.         if ( stricmp( Token , "gl_one_minus_dst_color"    ) == 0 ) blend_sfactor=GL_ONE_MINUS_DST_COLOR;else
  286.         if ( stricmp( Token , "gl_src_alpha"            ) == 0 ) blend_sfactor=GL_SRC_ALPHA;else
  287.         if ( stricmp( Token , "gl_one_minus_src_alpha"    ) == 0 ) blend_sfactor=GL_ONE_MINUS_SRC_ALPHA;else
  288.         if ( stricmp( Token , "gl_dst_alpha"            ) == 0 ) blend_sfactor=GL_DST_ALPHA;else
  289.         if ( stricmp( Token , "gl_one_minus_dst_alpha"    ) == 0 ) blend_sfactor=GL_ONE_MINUS_DST_ALPHA;else
  290.         if ( stricmp( Token , "gl_src_alpha_saturate"    ) == 0 ) blend_sfactor=GL_SRC_ALPHA_SATURATE;
  291.         else Error( "unknown blendfunc parameter found: %s ", Token );
  292.  
  293.         Token = getstring( Var );
  294.         if ( Var != NULL )
  295.             Error( "%s followed by unexpected token: %s" , Token, Var );
  296.  
  297.         if ( stricmp( Token , "gl_zero"                    ) == 0 ) blend_dfactor=GL_ZERO;else
  298.         if ( stricmp( Token , "gl_one"                    ) == 0 ) blend_dfactor=GL_ONE;else
  299.         if ( stricmp( Token , "gl_src_color"            ) == 0 ) blend_dfactor=GL_SRC_COLOR;else
  300.         if ( stricmp( Token , "gl_one_minus_dst_color"    ) == 0 ) blend_dfactor=GL_ONE_MINUS_SRC_COLOR;else
  301.         if ( stricmp( Token , "gl_src_alpha"            ) == 0 ) blend_dfactor=GL_SRC_ALPHA;else
  302.         if ( stricmp( Token , "gl_one_minus_src_alpha"    ) == 0 ) blend_dfactor=GL_ONE_MINUS_SRC_ALPHA;else
  303.         if ( stricmp( Token , "gl_dst_alpha"            ) == 0 ) blend_dfactor=GL_DST_ALPHA;else
  304.         if ( stricmp( Token , "gl_one_minus_dst_alpha"    ) == 0 ) blend_dfactor=GL_ONE_MINUS_DST_ALPHA;
  305.         else Error( "unknown blendfunc parameter found: %s ", Token );
  306.     } else
  307.     if ( stricmp( Type , "alphafunc" ) == 0 )
  308.     {
  309.         if ( Var == NULL )
  310.             Error( "token expected after alphafunc, but none found");
  311.  
  312.         Token = getstring( Var );
  313.         if ( Var != NULL )
  314.             Error( "%s followed by unexpected token: %s" , Token, Var );
  315.  
  316.         if ( stricmp( Token , "gt0"     ) == 0 ) {
  317.             alpha_func = GL_GREATER;alpha_ref = 0;
  318.         } else
  319.         if ( stricmp( Token , "lt128") == 0 ) {
  320.             alpha_func = GL_LESS;alpha_ref = 128;
  321.         } else
  322.         if ( stricmp( Token , "ge128") == 0 ) {
  323.             alpha_func = GL_GEQUAL;alpha_ref = 128;
  324.         }
  325.         else Error( "unknown alphafunc parameter found: %s ", Token );
  326.     } else
  327.     if ( stricmp( Type , "depthfunc" ) == 0 )
  328.     {
  329.         if ( Var == NULL )
  330.             Error( "token expected after depthfunc, but none found");
  331.         
  332.         Token = getstring( Var );
  333.         if ( Var != NULL )
  334.             Error( "%s followed by unexpected token: %s" , Token, Var );
  335.  
  336.         if ( stricmp( Token , "equal"     ) == 0 ) { 
  337.             depth_func = GL_EQUAL;
  338.         }
  339.         else Error( "unknown depthfunc parameter found: %s ", Token );
  340.     } else
  341.     if ( stricmp( Type , "detail" ) == 0 )
  342.     {
  343.         if ( Var != NULL )
  344.             Error( "detail followed by unexpected token: %s" , Var );
  345.  
  346.         rp_detail = true;
  347.     } else
  348.     if ( stricmp( Type , "depthwrite" ) == 0 )
  349.     {
  350.         if ( Var != NULL )
  351.             Error( "depthwrite followed by unexpected token: %s" , Var );
  352.  
  353.         rp_depthwrite = true;
  354.     } else
  355.     if ( stricmp( Type , "clamptexcoords" ) == 0 )
  356.     {
  357.         if ( Var != NULL )
  358.             Error( "clamptexcoords followed by unexpected token: %s" , Var );
  359.  
  360.         rp_clamptexcoords = true;
  361.     } else
  362.     if ( stricmp( Type , "tcgen" ) == 0 )
  363.     {
  364.         if ( Var == NULL )
  365.             Error( "token expected after tcgen, but none found");
  366.  
  367.         Token = getstring( Var );
  368.         if ( Var != NULL )
  369.             Error( "%s followed by unexpected token: %s" , Token, Var );
  370.  
  371.         if ( stricmp( Token , "environment" ) != 0 )
  372.             Error( "unknown tcgen command found: %s ", Token );
  373.  
  374.         //TODO: add functionality
  375.         // Create enviroment map
  376.     } else
  377.     if ( stricmp( Type , "map" ) == 0 )
  378.     {
  379.         if ( Var == NULL )
  380.             Error( "token expected after map, but none found");
  381.         
  382.         Token = getstring( Var );
  383.         if ( Var != NULL )
  384.             Error( "%s followed by unexpected token: %s" , Token, Var );
  385.  
  386.         //TODO: add functionality
  387.         // load texture map
  388.     } else
  389.     if ( stricmp( Type , "alphamap" ) == 0 )
  390.     {
  391.         if ( Var == NULL )
  392.             Error( "token expected after alphamap, but none found");
  393.  
  394.         Token = getstring( Var );
  395.         if ( Var != NULL )
  396.             Error( "%s followed by unexpected token: %s" , Token, Var );
  397.  
  398.         //TODO: add functionality
  399.         // load texture alphamap
  400.     } else
  401.     if ( stricmp( Type , "animmap" ) == 0 )
  402.     {
  403.         if ( Var == NULL )
  404.             Error( "token expected after animmap, but none found");
  405.  
  406.         Token = getstring( Var );
  407.         if ( Var == NULL )
  408.             Error( "unexpected end after token: %s" , Token );
  409.  
  410.         // Token == unknown number
  411.  
  412.         while ( ( Token = getstring( Var ) ) != NULL )
  413.         {
  414.             //TODO: add functionality
  415.             // load texture animmap
  416.         }
  417.     } else
  418.     if ( stricmp( Type , "rgbgen" ) == 0 )
  419.     {
  420.         if ( Var == NULL )
  421.             Error( "token expected after rgbgen, but none found");
  422.         /*
  423.             {"rgbGen","wave","sin",float,float,float,float}
  424.             {"rgbGen","wave","inversesawtooth",float,float,float,float}
  425.             {"rgbGen","wave","sawtooth",float,float,float,float}
  426.             {"rgbGen","wave","square",float,float,float,float}
  427.             {"rgbGen","wave","noise",float,float,float,float}
  428.             {"rgbGen","wave","triangle",float,float,float,float}
  429.             {"rgbGen","identity"}
  430.             {"rgbGen","entity"}
  431.             {"rgbGen","exactvertex"}
  432.             {"rgbGen","vertex"}
  433.             {"rgbGen","identitylighting"}
  434.             {"rgbGen","lightingDiffuse"}
  435.             {"rgbGen","lightingSpecular"}
  436.             {"rgbGen","oneminusentity"}
  437.         */
  438.     } else
  439.     if ( stricmp( Type , "alphagen" ) == 0 )
  440.     {
  441.         if ( Var == NULL )
  442.             Error( "token expected after alphagen, but none found");
  443.         /*
  444.             {"colorGen","wave","sin",float,float,float,float}
  445.             {"colorGen","wave","inversesawtooth",float,float,float,float}
  446.             {"colorGen","wave","sawtooth",float,float,float,float}
  447.             {"colorGen","wave","square",float,float,float,float}
  448.             {"colorGen","wave","noise",float,float,float,float}
  449.             {"colorGen","wave","triangle",float,float,float,float}
  450.             {"colorGen","identity"}
  451.             {"colorGen","entity"}
  452.             {"colorGen","exactvertex"}
  453.             {"colorGen","vertex"}
  454.             {"colorGen","identitylighting"}
  455.             {"colorGen","lightingDiffuse"}
  456.             {"colorGen","lightingSpecular"}
  457.             {"colorGen","oneminusentity"}
  458.         */
  459.     } else
  460.     if ( stricmp( Type , "colorgen" ) == 0 )
  461.     {
  462.         if ( Var == NULL )
  463.             Error( "token expected after colorgen, but none found");
  464.         /*
  465.             {"alphaGen","wave","sin",float,float,float,float}
  466.             {"alphaGen","wave","inversesawtooth",float,float,float,float}
  467.             {"alphaGen","wave","sawtooth",float,float,float,float}
  468.             {"alphaGen","wave","square",float,float,float,float}
  469.             {"alphaGen","wave","noise",float,float,float,float}
  470.             {"alphaGen","wave","triangle",float,float,float,float}
  471.             {"alphaGen","identity"}
  472.             {"alphaGen","entity"}
  473.             {"alphaGen","exactvertex"}
  474.             {"alphaGen","vertex"}
  475.             {"alphaGen","identitylighting"}
  476.             {"alphaGen","lightingDiffuse"}
  477.             {"alphaGen","lightingSpecular"}
  478.             {"alphaGen","oneminusentity"}
  479.         */
  480.     } else
  481.         Error("unknown command found: %s", Type );
  482. }
  483.  
  484. void    Surface::AddParam( char* Type, char* Var )
  485. {
  486.     char*    Token;
  487.     if ( stricmp( Type , "surfaceparam" ) == 0 )
  488.     {
  489.         if ( Var == NULL )
  490.             Error( "token expected after surfaceparam, but none found");
  491.  
  492.         Token = getstring( Var );
  493.         if ( Var != NULL )
  494.             Error( "%s followed by unexpected token: %s" , Token, Var );
  495.  
  496.         if ( stricmp( Token , "lightfilter" ) == 0 ) sp_lightfilter = true;else
  497.         if ( stricmp( Token , "playerclip"  ) == 0 ) sp_playerclip  = true;else
  498.         if ( stricmp( Token , "structural"  ) == 0 ) sp_structural  = true;else
  499.         if ( stricmp( Token , "areaportal"  ) == 0 ) sp_areaportal  = true;else
  500.         if ( stricmp( Token , "metalsteps"  ) == 0 ) sp_metalsteps  = true;else
  501.         if ( stricmp( Token , "nolightmap"  ) == 0 ) sp_nolightmap  = true;else
  502.         if ( stricmp( Token , "noimpact"    ) == 0 ) sp_noimpact     = true;else
  503.         if ( stricmp( Token , "nodamage"    ) == 0 ) sp_nodamage    = true;else
  504.         if ( stricmp( Token , "nonsolid"    ) == 0 ) sp_nonsolid    = true;else
  505.         if ( stricmp( Token , "nomarks"     ) == 0 ) sp_nomarks     = true;else
  506.         if ( stricmp( Token , "origin"      ) == 0 ) sp_origin      = true;else
  507.         if ( stricmp( Token , "nodrop"      ) == 0 ) sp_nodrop      = true;else
  508.         if ( stricmp( Token , "nodraw"      ) == 0 ) sp_nodraw      = true;else
  509.         if ( stricmp( Token , "water"       ) == 0 ) sp_water       = true;else
  510.         if ( stricmp( Token , "slime"       ) == 0 ) sp_slime       = true;else
  511.         if ( stricmp( Token , "slick"       ) == 0 ) sp_slick       = true;else
  512.         if ( stricmp( Token , "trans"       ) == 0 ) sp_trans       = true;else
  513.         if ( stricmp( Token , "lava"        ) == 0 ) sp_lava        = true;else
  514.         if ( stricmp( Token , "sky"         ) == 0 ) sp_sky         = true;else
  515.         if ( stricmp( Token , "fog"         ) == 0 ) sp_fog         = true;
  516.         else Error( "unknown surfaceparam variable: %s" , Token );
  517.  
  518.     } else
  519.     if ( stricmp( Type , "cull" ) == 0 )
  520.     {
  521.         if ( Var == NULL )
  522.             Error( "token expected after cull, but none found");
  523.  
  524.         Token = getstring( Var );
  525.         if ( Var != NULL )
  526.             Error( "%s followed by unexpected token: %s" , Token, Var );
  527.  
  528.         if ( stricmp( Token , "none"        ) == 0 ) cull = cull_none     ;else
  529.         if ( stricmp( Token , "disable"        ) == 0 ) cull = cull_disable  ;else
  530.         if ( stricmp( Token , "twosided"    ) == 0 ) cull = cull_twosided ;else
  531.         if ( stricmp( Token , "backsided"   ) == 0 ) cull = cull_backsided;else
  532.         if ( stricmp( Token , "back"        ) == 0 ) cull = cull_back     ;
  533.         else Error( "unknown cull variable: %s" , Token );
  534.         
  535.     } else
  536.     if ( stricmp( Type , "light" ) == 0 )
  537.     {
  538.         if ( Var == NULL )
  539.             Error( "token expected after light, but none found");
  540.  
  541.         Token = getstring( Var );
  542.         if ( Var != NULL )
  543.             Error( "%s followed by unexpected token: %s" , Token, Var );
  544.  
  545.         //TODO: add check if it's really a number
  546.         sf_light = (float)atof(Token);
  547.     } else
  548.     if ( stricmp( Type , "tesssize" ) == 0 )
  549.     {
  550.         if ( Var == NULL )
  551.             Error( "token expected after tesssize, but none found");
  552.  
  553.         Token = getstring( Var );
  554.         if ( Var != NULL )
  555.             Error( "%s followed by unexpected token: %s" , Token, Var );
  556.  
  557.         //TODO: add check if it's really a number
  558.         sf_tesssize = (float)atof(Token);
  559.     } else
  560.     if ( stricmp( Type , "sort" ) == 0 )
  561.     {
  562.         if ( Var == NULL )
  563.             Error( "token expected after sort, but none found");
  564.  
  565.         Token = getstring( Var );
  566.         if ( Var != NULL )
  567.             Error( "%s followed by unexpected token: %s" , Token, Var );
  568.  
  569.         //TODO: add check if it's really a number
  570.         sf_sort = (float)atof(Token);
  571.     } else
  572.     if ( stricmp( Type , "qer_trans" ) == 0 )
  573.     {
  574.         if ( Var == NULL )
  575.             Error( "token expected after qer_trans, but none found");
  576.  
  577.         Token = getstring( Var );
  578.         if ( Var != NULL )
  579.             Error( "%s followed by unexpected token: %s" , Token, Var );
  580.  
  581.         //TODO: add check if it's really a number
  582.         sf_qer_trans = (float)atof(Token);
  583.     } else
  584.     if ( stricmp( Type , "q3map_backsplash" ) == 0 )
  585.     {
  586.         if ( Var == NULL )
  587.             Error( "token expected after q3map_backsplash, but none found");
  588.  
  589.         Token = getstring( Var );
  590.         if ( Var != NULL )
  591.             Error( "%s followed by unexpected token: %s" , Token, Var );
  592.  
  593.         //TODO: add check if it's really a number
  594.         sf_q3map_backsplash = (float)atof(Token);
  595.     } else
  596.     if ( stricmp( Type , "q3map_surfacelight" ) == 0 )
  597.     {
  598.         if ( Var == NULL )
  599.             Error( "token expected after q3map_surfacelight, but none found");
  600.  
  601.         Token = getstring( Var );
  602.         if ( Var != NULL )
  603.             Error( "%s followed by unexpected token: %s" , Token, Var );
  604.  
  605.         //TODO: add check if it's really a number
  606.         sf_q3map_surfacelight = (float)atof(Token);
  607.     } else
  608.     if ( stricmp( Type , "sky" ) == 0 )
  609.     {
  610.         if ( Var == NULL )
  611.             Error( "token expected after sky, but none found");
  612.  
  613.         Token = getstring( Var );
  614.         if ( Var != NULL )
  615.             Error( "%s followed by unexpected token: %s" , Token, Var );
  616.  
  617.         //TODO: add check if it's really a number
  618.         sf_sky = new char[ strlen( Token ) ];
  619.         strcpy( sf_sky , Token );
  620.     } else
  621.     if ( stricmp( Type , "qer_editorimage" ) == 0 )
  622.     {
  623.         if ( Var == NULL )
  624.             Error( "token expected after qer_editorimage, but none found");
  625.  
  626.         Token = getstring( Var );
  627.         if ( Var != NULL )
  628.             Error( "%s followed by unexpected token: %s" , Token, Var );
  629.  
  630.         //TODO: add check if it's really a number
  631.         sf_qer_editorimage = new char[ strlen( Token ) ];
  632.         strcpy( sf_qer_editorimage , Token );
  633.     } else
  634.     if ( stricmp( Type , "q3map_lightimage" ) == 0 )
  635.     {
  636.         if ( Var == NULL )
  637.             Error( "token expected after q3map_lightimage, but none found");
  638.  
  639.         Token = getstring( Var );
  640.         if ( Var != NULL )
  641.             Error( "%s followed by unexpected token: %s" , Token, Var );
  642.  
  643.         //TODO: add check if it's really a number
  644.         sf_q3map_lightimage = new char[ strlen( Token ) ];
  645.         strcpy( sf_q3map_lightimage , Token );
  646.     } else
  647.     if ( stricmp( Type , "cloudparms" ) == 0 )
  648.     {
  649.         //currently ignores cloudparms
  650.         /*    
  651.             {"cloudparms",int,"full"}
  652.             {"cloudparms",int,"half"}
  653.             {"cloudparms",int}
  654.         */
  655.     } else
  656.     if ( stricmp( Type , "skyparms" ) == 0 )
  657.     {
  658.         //currently ignores skyparms
  659.         /*    
  660.             {"skyparms",char*,"-","-"}
  661.             {"skyparms",int,"full","-"}
  662.             {"skyparms",int,"full","-"}
  663.             {"skyparms","-",int,"-"}
  664.             {"skyparms","full",int,"-"}
  665.             {"skyparms","half",int,"-"}
  666.         */
  667.     } else
  668.     if ( stricmp( Type , "deformVertexes" ) == 0 )
  669.     {
  670.         //currently ignores deformVertexes
  671.         /*    
  672.             {"deformVertexes","wave",int,"sin",float,float,float,float}
  673.             {"deformVertexes","autosprite"}
  674.             {"deformVertexes","autosprite2"}
  675.             {"deformVertexes","projectshadow"}
  676.             {"deformVertexes","bulge",float,float,float}
  677.             {"deformVertexes","bulge",float,float,float}
  678.         */
  679.     } else
  680.     if ( stricmp( Type , "fogparms" ) == 0 )
  681.     {
  682.         //currently ignores fogparms
  683.         //{"fogparms",float,float,float,float,float}
  684.     } else
  685.     if ( stricmp( Type , "q3map_sun" ) == 0 )
  686.     {
  687.         //currently ignores q3map_sun
  688.         //{"q3map_sun",float,float,float,int,int,int}
  689.     } else
  690.     if ( stricmp( Type , "fogGen" ) == 0 )
  691.     {
  692.         //currently ignores fogGen
  693.         //{"fogGen","sin",float,float,float,float}
  694.     } else
  695.     if ( stricmp( Type , "blendMap" ) == 0 )
  696.     {
  697.         //currently ignores blendMap
  698.         //{"blendMap",char*,char*}
  699.     } else
  700.     if ( Var == NULL )
  701.     {
  702.         if ( stricmp( Type , "portal"         ) == 0 ) sf_portal            = true;else
  703.         if ( stricmp( Type , "fogonly"         ) == 0 ) sf_fogonly        = true;else
  704.         if ( stricmp( Type , "nomipmaps"     ) == 0 ) sf_nomipmaps        = true;else
  705.         if ( stricmp( Type , "polygonOffset" ) == 0 ) sf_polygonOffset    = true;else
  706.         if ( stricmp( Type , "lightning"     ) == 0 ) sf_lightning        = true;else
  707.         if ( stricmp( Type , "backsided"     ) == 0 ) sf_backsided        = true;
  708.         if ( stricmp( Type , "qer_nocarve"     ) == 0 ) sf_qer_nocarve    = true;
  709.         else Error( "unknown token: %s" , Type );
  710.  
  711.     } else
  712.         Error( "unexpected token found: %s" , Type );
  713. }
  714.  
  715. void    Surface::AddPass( RenderPass*& Pass )
  716. {
  717.  
  718. }
  719.  
  720. /*END UNFINISHED BIT*/
  721.  
  722. char*    getline( FILE*& F )
  723. {
  724.     char    line[4096];
  725.     char*    lineptr = NULL;
  726.     
  727.     while ( ( lineptr == NULL ) && ( !feof( F ) ) )
  728.     {
  729.         fgets( line , sizeof( line ) , F );
  730.         lineptr = line;
  731.         clean( lineptr );
  732.     }
  733.     return lineptr;
  734. }
  735.  
  736. bool    LoadScript( char* filename )
  737. {
  738.     FILE*    F;
  739.     if ( ( F = fopen( filename , "rt" ) ) != NULL ) 
  740.     {
  741.         char*    lineptr;
  742.         while ( !feof( F ) )
  743.         {
  744.             lineptr = getline( F );
  745.             if ( lineptr != NULL )
  746.             {
  747.                 char*    Token = getstring( lineptr );
  748.                 if ( ( stricmp( Token , "{" ) == 0 ) ||
  749.                      ( stricmp( Token , "}" ) == 0 ) )
  750.                 {
  751.                     Debug("surface expected, got: %s",Token);
  752.                     return false;
  753.                 } else
  754.                 {
  755.                     if ( lineptr != NULL ) {
  756.                         Debug("surface name followed by unexpected token: %s",lineptr);
  757.                         return false;
  758.                     }
  759.  
  760.                     Surface*    newSurface;
  761.                     if ( ( newSurface = CreateSurface( Token ) ) != NULL )
  762.                     {
  763.                         lineptr = getline( F );
  764.                         if ( lineptr == NULL ) {
  765.                             Error("unexpected end of file"); return false;
  766.                         }
  767.                         Token = getstring( lineptr );
  768.                         if ( stricmp( Token , "{" ) != 0 ) {
  769.                             Error("unexpected token found: %s", Token); return false;
  770.                         }
  771.                         if ( lineptr != NULL ) {
  772.                             Error("{ followed by unexpected token: %s", lineptr); 
  773.                             return false;
  774.                         }
  775.                         while ( ( ( Token = lineptr = getline( F ) ) != NULL ) &&
  776.                                 ( ( Token = getstring( lineptr ) ) != NULL ) &&
  777.                                 ( stricmp( Token , "}" ) != 0 ) )
  778.                         {
  779.                             if ( stricmp( Token , "{" ) != 0 )
  780.                             {
  781.                                 newSurface->AddParam( Token , lineptr );
  782.                             } else
  783.                             {
  784.                                 if ( lineptr != NULL ) {
  785.                                     Error("{ followed by unexpected token: %s", lineptr); 
  786.                                     return false;
  787.                                 }
  788.                                 RenderPass*    newPass = new RenderPass;
  789.                                 while ( ( ( Token = lineptr = getline( F ) ) != NULL ) &&
  790.                                         ( ( Token = getstring( lineptr ) ) != NULL ) &&
  791.                                         ( stricmp( Token , "}" ) != 0 ) )
  792.                                 {
  793.                                     newPass->AddParam( Token , lineptr );
  794.                                 }
  795.                                 if ( Token == NULL ) {
  796.                                     Error("unexpected end of file"); return false;
  797.                                 }
  798.                                 if ( lineptr != NULL ) {
  799.                                     Error("} followed by unexpected token: %s ", lineptr); 
  800.                                     return false;
  801.                                 }
  802.                                 newSurface->AddPass( newPass );
  803.                             }
  804.                         }
  805.                         if ( Token == NULL ) {
  806.                             Error("unexpected end of file"); return false;
  807.                         }
  808.                         if ( lineptr != NULL ) {
  809.                             Error("} followed by unexpected token: %s ", lineptr); 
  810.                             return false;
  811.                         }
  812.                     } else
  813.                         Error("failed to make surface");
  814.                 }
  815.             }
  816.         }
  817.         fclose(F);
  818.         return true;
  819.     } else
  820.         return false;
  821. }