Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Sat Mar 30, 2024 4:27 am

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Thu Jul 26, 2007 3:38 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Another proposal.
The goal of this function is to avoid the declaration of recurrent code in the main. Usually the next lines are always in the main, which minor changes:
Code:
raydium_window_create(640,480,RAYDIUM_RENDERING_WINDOW,"Primer aplicacion de Vicente");
/*raydium_window_create(640,480,RAYDIUM_RENDERING_FULLSCREEN,"My app");*/

raydium_texture_filter_change(RAYDIUM_TEXTURE_FILTER_BILINEAR);
raydium_window_view_perspective(60,0.01,2500); // fov 60 + near and far planes

raydium_fog_disable();   
raydium_light_enable();
raydium_light_on(0);

raydium_light_conf_7f(0,50,150,200,1000000,1,0.9,0.7); // id, pos, intensity and color (RGB)
raydium_background_color_change(1,0.9,0.7,1);

raydium_sky_box_cache();


This function load a config text file with the variable data and do the rest by itself.:

This is an config text file:
Code:
width=800                              #window width (default:  800)
height=600                              #window height (default:  600)
windowtype=window                     #window style: window or fullscreen (default: window )
title=Titulo de pantalla               #title of the window,application (default:  Raydium application 0.1)
filter=aniso                        #texture filter: none, bilinear, trilinear, aniso (default:  trilinear)
fov=60                                 #view angle, ie fov (default:  60)
near=0.001                              #distance to the nearets object(plane) draw   (default:  0.001)
far=2500                              #distance to the further   object(plane) draw (default:  2500)
fog=on                                 #fog: on/enable or off/disable (default:  off)
lighting=on                           #lighting: on/enable or off/disable (default: on )
light0=0,50,150,200,1000000,1,0.9,0.7         #light 0 parameters (default:  0,50,150,200,1000000,1,0.9,0.7)
background=1,0.9,0.7,1                     #background color (default:  1,0.9,0.7,1)


So, using the prvious proposal and this one, an skel.c file could ends like this:
Code:
/*
    Raydium - CQFD Corp.
    http://raydium.org/
    License: GPL - GNU General Public License, see "gpl.txt" file.
*/

// This file is a default skeleton. Replace all [ ... ] sections with yours.
// Have fun !

#include "raydium/index.c"


void display(void)
{
raydium_camera_first_person_free_allinone();
if(raydium_key_last==1027)
    exit(0);
/* [ draw here ] */ raydium_ode_draw_all(0);
raydium_rendering_finish();
}


int main(int argc, char **argv)
{
raydium_init_args(argc,argv);
raydium_init_load_from_file("ejemplo.config");
/* [ place base scene here ] */ raydium_ode_ground_set_name("cocorobix.tri");

raydium_callback(&display);
return(0);
}

// EOF


And here is a preliminar version of the function (with spanish comments):
Code:
void raydium_init_load_from_file(char *filename)
{   
    FILE *fp;
    int ret;
    char var[255];
    char val_s[255];
    GLfloat val_f[255];
    int size;
    int tmp_width,tmp_height,tmp_windowtype,tmp_filter,tmp_fog,tmp_lighting;
    double tmp_fov,tmp_far,tmp_near;
    float tmp_light0[8],tmp_background[4];
    char tmp_title[255],tmp_string[255];
    int flag_width,flag_height,flag_title,flag_windowtype,flag_filter,flag_fov,flag_near,flag_far,flag_fog,flag_lighting,flag_light0,flag_background;
       
    fp=raydium_file_fopen(filename,"rt");
    flag_width=flag_height=flag_title=flag_windowtype=flag_filter=flag_fov=flag_near=flag_far=flag_fog=flag_lighting=flag_light0=flag_background=0;
     
    while( (ret=raydium_parser_read(var,val_s,val_f,&size,fp))!=RAYDIUM_PARSER_TYPE_EOF)
    {
        if(!strcasecmp(var,"foobar_variable"))
        {
            if(ret!=RAYDIUM_PARSER_TYPE_FLOAT || size!=2)
            {
                raydium_log("error: foobar_variable is not float array");
                continue;
            }
           
        }
        raydium_log("*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***");
        raydium_log("La variable %s, tiene el valor %s",var,val_s);
        if(strcmp(var,"width")==0)
            {
                tmp_width=atoi(val_s);
                raydium_log("Hemos configurado la anchura con el valor %d",tmp_width);
                flag_width=1;
            }
        if(strcmp(var,"height")==0)
            {
                tmp_height=atoi(val_s);
                raydium_log("Hemos configurado la altura con el valor %d",tmp_height);
                flag_height=1;
            }
        if(strcmp(var,"windowtype")==0)
        {
            //ulgy way to clean the string. Is there a better way?
            strncpy(tmp_string,val_s,strcspn(val_s,"\t "));
            tmp_string[strcspn(val_s,"\t ")]=NULL;
            if(strcmp(tmp_string,"fullscreen")==0) tmp_windowtype=RAYDIUM_RENDERING_FULLSCREEN;
                else tmp_windowtype=RAYDIUM_RENDERING_WINDOW;
            raydium_log("Hemos configurado el tipo de ventana como %s",(tmp_windowtype)?"RAYDIUM_RENDERING_FULLSCREEN":"RAYDIUM_RENDERING_WINDOW");
            flag_windowtype=1;
        }
        if(strcmp(var,"title")==0)
        {
            //ulgy way to clean the string. Is there a better way?
            strncpy(tmp_string,val_s,strcspn(val_s,"\t#"));
            tmp_string[strcspn(val_s,"\t#")]=NULL;
            strcpy(tmp_title,tmp_string);
            raydium_log("Hemos configurado el titulo de ventana como: %s",tmp_title);
            flag_title=1;
        }
        if(strcmp(var,"filter")==0)
        {
            //ulgy way to clean the string. Is there a better way?
            strncpy(tmp_string,val_s,strcspn(val_s,"\t "));
            tmp_string[strcspn(val_s,"\t ")]=NULL;
            if(strcmp(tmp_string,"trilinear")==0)tmp_filter=2;
            if(strcmp(tmp_string,"bilinear")==0)tmp_filter=1;
            if(strcmp(tmp_string,"none")==0)tmp_filter=0;
            if(strcmp(tmp_string,"aniso")==0)tmp_filter=3;
            flag_filter=1;           
        }
        if(strcmp(var,"fov")==0)
        {
            tmp_fov=atof(val_s);
            raydium_log("Hemos configurado el angulo de visión como: %f",tmp_fov);         
            flag_fov=1;           
        }
        if(strcmp(var,"near")==0)
        {
            tmp_near=atof(val_s);
            raydium_log("Hemos configurado el limite cercano a: %f",tmp_near);         
            flag_near=1;           
        }
        if(strcmp(var,"far")==0)
        {           
            tmp_far=atof(val_s);
            raydium_log("Hemos configurado el limite lejano a: %f",tmp_far);         
            flag_far=1;           
        }
        if(strcmp(var,"fog")==0)
        {
           //ulgy way to clean the string. Is there a better way?
           strncpy(tmp_string,val_s,strcspn(val_s,"\t "));
            tmp_string[strcspn(val_s,"\t ")]=NULL;
            tmp_fog=((strcmp(tmp_string,"on")==0) || (strcmp(tmp_string,"enable")==0))?1:0;
            raydium_log("Hemos configurado la niebla como: %f",tmp_fog);         
            flag_fog=1;           
        }
        if(strcmp(var,"lighting")==0)
        {
           //ulgy way to clean the string. Is there a better way?
           strncpy(tmp_string,val_s,strcspn(val_s,"\t "));
            tmp_string[strcspn(val_s,"\t ")]=NULL;
            tmp_lighting=((strcmp(tmp_string,"on")==0) || (strcmp(tmp_string,"enable")==0))?1:0;
            raydium_log("Hemos configurado la iluminación como: %f",tmp_lighting);         
            flag_lighting=1;           
        }
        if(strcmp(var,"light0")==0)
        {
           //ulgy way to clean the string. Is there a better way?
           strncpy(tmp_string,val_s,strcspn(val_s,"\t "));
            tmp_string[strcspn(val_s,"\t ")]=NULL;
            sscanf( tmp_string, "%f,%f,%f,%f,%f,%f,%f,%f", &tmp_light0[0], &tmp_light0[1],&tmp_light0[2],&tmp_light0[3],&tmp_light0[4],&tmp_light0[5],&tmp_light0[6],&tmp_light0[7]);
            raydium_log("Hemos configurado la luz 0 con los valores: %f,%f,%f,%f,%f,%f,%f,%f",tmp_light0[0],tmp_light0[1],tmp_light0[2],tmp_light0[3],tmp_light0[4],tmp_light0[5],tmp_light0[6],tmp_light0[7]);         
            flag_light0=1;           
        }
         if(strcmp(var,"background")==0)
        {
           //ulgy way to clean the string. Is there a better way?
           strncpy(tmp_string,val_s,strcspn(val_s,"\t "));
            tmp_string[strcspn(val_s,"\t ")]=NULL;
            sscanf( tmp_string, "%f,%f,%f,%f", &tmp_background[0], &tmp_background[1],&tmp_background[2],&tmp_background[3]);
            raydium_log("Hemos configurado la luz 0 con los valores: %f,%f,%f,%f,%f,%f,%f,%f",tmp_background[0], tmp_background[1],tmp_background[2],tmp_background[3]);         
            flag_background=1;           
        }
    }
   
   
    //Here, we process all the data achieved and make the raydium calls
   
   
    if(flag_width && flag_height && flag_windowtype && flag_title)
        {
            raydium_log("vamos a crear la ventana con esta funcion: raydium_window_create(%d,%d,%d,\"%s\"); ",tmp_width,tmp_height,tmp_windowtype,tmp_title);
            raydium_window_create(tmp_width,tmp_height,tmp_windowtype,tmp_title);
        }
    if(flag_filter)
        {
            raydium_log("configurando filtrado de textura en modo %d",tmp_filter);
            raydium_texture_filter_change(tmp_filter);
        }
   if (flag_fov && flag_near && flag_far)
    {
       raydium_log("configurando el fov a %d, y los planos de recorte en %f y %f.",tmp_fov,tmp_near,tmp_far);
       raydium_window_view_perspective(tmp_fov,tmp_near,tmp_far); // fov 60 + near and far planes
    } 
   
    if(flag_fog)
    {
       raydium_log("configurando la niebla como %d",tmp_fog);
       if(tmp_fog)raydium_fog_enable(); else raydium_fog_disable();
    }
    if(flag_lighting)
    {
       raydium_log("configurando la iluminación como %d",tmp_lighting);
       if(tmp_fog)raydium_light_enable(); else raydium_light_disable();
    }
    if(flag_light0 && flag_lighting && tmp_lighting)
    {
       raydium_log("configurando la luz 0 con los valores : %f,%f,%f,%f,%f,%f,%f,%f",tmp_light0[0],tmp_light0[1],tmp_light0[2],tmp_light0[3],tmp_light0[4],tmp_light0[5],tmp_light0[6],tmp_light0[7]);
       raydium_light_on(0);
      raydium_light_conf_7f(tmp_light0[0],tmp_light0[1],tmp_light0[2],tmp_light0[3],tmp_light0[4],tmp_light0[5],tmp_light0[6],tmp_light0[7]); // id, pos, intensity and color (RGB)
       
    }
    if(flag_background)
    {
       raydium_log("configurando el color de fondo con los valores : %f,%f,%f,%f",tmp_background[0], tmp_background[1],tmp_background[2],tmp_background[3]);
       raydium_background_color_change(tmp_background[0], tmp_background[1],tmp_background[2],tmp_background[3]);
       
    }
   
    //This should be configurable???
    raydium_sky_box_cache();
   
}


Comments?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 11:31 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
BUG: I have notice problems when there are spaces after the values. In the next version i'll add a trim function when reading.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 11:43 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
The idea is nice : It's easy to use, easy to , easy to understand, easy to maintain: I love that !

The code of the function could be a bit more compact, perhaps ? I haven't think about it, but is it necessary to use flags for example ?

Let's make the name of the function simple, don't you think ? Something like raydium_init_auto(filename) ? No ?

About the bug and data parsing: do not put comments (// not #) after your values, but on another line just before your value, for example (see below). We may update the parser so it can support comments-on-the-line, I think.

Code:
// window width (default:  800)
width=800;


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 9:35 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Xfennec wrote:
The code of the function could be a bit more compact, perhaps ? I haven't think about it, but is it necessary to use flags for example ?
Well, i have to recheck the code but i remember i saw a good reason to use that.... But i can not remember which.

Quote:
Let's make the name of the function simple, don't you think ? Something like raydium_init_auto(filename) ? No ?

Ok, but i think the word "load", "from" or "external" should appear in the name, to show clearly that it's related to a thing out of the current code. Maybe raydium_init_load(filename).

Quote:
About the bug and data parsing: do not put comments (// not #) after your values, but on another line just before your value, for example (see below). We may update the parser so it can support comments-on-the-line, I think.

As you prefer. No problem in changing that. However i think adding support for inline comments could be a nice update.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 2:25 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
About the code length, you've free card, do your best, as usual ;)

Quote:
raydium_init_load(filename)

Not bad. OK for me.

Quote:
However i think adding support for inline comments could be a nice update.

Yep, and It's probably quiet easy to do, I'll look at that very soon.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 4:48 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Inline comments for string values is now ok (rev 551).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 5:11 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
As productive as ever :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2007 5:00 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Commit done.

The function is now called raydium_init_load.
As asked, the code has been reduced a bit. Flags are used to indicate if a certain feature has to be processed, cause some features are not mandatory to be part of the configuration file. So i think i can not remove them.
In fact you can delete the line about Light0 and still the application will work.

I have added a template configuration file, called exampleconfig.txt, and a "demo" of usage, called configload.c.
Should this demo be quitted?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2007 5:02 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
If the demo is removed, i go to paste here the example code of usage(it also make use of raydium_camera_freemove):

Code:
#include "raydium/index.c"

void display(void)
{
    if(raydium_key_last==1027)
        exit(0);           
    raydium_camera_freemove();
    raydium_clear_frame();
    /* [ draw here ] */ raydium_ode_draw_all(0);
    raydium_rendering_finish();
}

int main(int argc, char **argv)
{
    raydium_init_args(argc,argv);
    raydium_init_load("exampleconfig.txt");
    /* [ place base scene here ] */ raydium_ode_ground_set_name("cocorobix.tri");
    raydium_callback(&display);
   
    return(0);
}


I think it doesn't need explanations, right?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 17, 2007 5:41 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
As for freemove, we should use this feature in our demos, I think. We can perhaps share some config files over

A few points:
- We must do data type checks (example: strcmp(var,"width")==0 && ret==RAYDIUM_PARSER_TYPE_FLOAT && size==1) and use this types (tmp_width=val_f)
- Too much log (needed for debug only IMHO)
- Should use constants (tmp_filter=RAYDIUM_TEXTURE_FILTER_BILINEAR)
- As stated above and in the doc, comments in parsed files should be "//" and not "#" (se we're consistent for all parsed files)
- What "sky" is ?
- Raydoc comments in "headers" directory should not execeed 80 characters, to be easily readable in the .h file.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 18, 2007 5:48 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Ok, i'll do a cleanup soon


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 18, 2007 11:35 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Xfennec wrote:
- We must do data type checks (example: strcmp(var,"width")==0 && ret==RAYDIUM_PARSER_TYPE_FLOAT && size==1) and use this types (tmp_width=val_f)

Hmmm... too tired to understand this now. Tomorrow i'll try again :)
Quote:
- Too much log (needed for debug only IMHO)

Removing almost the whole log
Quote:
- Should use constants (tmp_filter=RAYDIUM_TEXTURE_FILTER_BILINEAR)

Hmmm, they are hard... but ok.
Quote:
- As stated above and in the doc, comments in parsed files should be "//" and not "#" (se we're consistent for all parsed files)

Ok
Quote:
- What "sky" is ?

The sky type. None means no sky, normal is the usual sky and sphere is the "skysphere" testing sky i did some time ago. However since it'a quite beta, i should remove this right now.
Quote:
- Raydoc comments in "headers" directory should not execeed 80 characters, to be easily readable in the .h file.
Hmm right, i forgot.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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:  
cron
Powered by phpBB® Forum Software © phpBB Group