Update of /cvsroot/playerstage/code/stage/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15329/src
Modified Files:
model_laser.c stage.c stg_time.cc stg_time.h
Log Message:
added a few places to look for rgb.txt and a hash table for faster color
lookup, plus fixed a laser visualization bug
Index: stage.c
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/stage.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -C2 -d -r1.90 -r1.91
*** stage.c 21 Nov 2006 01:30:47 -0000 1.90
--- stage.c 14 Jan 2008 20:23:01 -0000 1.91
***************
*** 143,149 ****
stg_color_t stg_lookup_color(const char *name)
{
- FILE *file;
- const char *filename;
-
if( name == NULL ) // no string?
return 0; // black
--- 143,146 ----
***************
*** 151,199 ****
if( strcmp( name, "" ) == 0 ) // empty string?
return 0; // black
! filename = COLOR_DATABASE;
! file = fopen(filename, "r");
! if (!file)
! {
! PRINT_ERR2("unable to open color database %s : %s",
! filename, strerror(errno));
! fclose(file);
! return 0xFFFFFF;
! }
! while (TRUE)
! {
! char line[1024];
! if (!fgets(line, sizeof(line), file))
! break;
! // it's a macro or comment line - ignore the line
! if (line[0] == '!' || line[0] == '#' || line[0] == '%')
! continue;
! // Trim the trailing space
! while (strchr(" \t\n", line[strlen(line)-1]))
! line[strlen(line)-1] = 0;
! // Read the color
! int r, g, b;
! int chars_matched = 0;
! sscanf( line, "%d %d %d %n", &r, &g, &b, &chars_matched );
!
! // Read the name
! char* nname = line + chars_matched;
- // If the name matches
- if (strcmp(nname, name) == 0)
- {
fclose(file);
- return ((r << 16) | (g << 8) | b);
}
- }
- PRINT_WARN1("unable to find color [%s]; using default (red)", name);
- fclose(file);
- return 0xFF0000;
- }
--- 148,225 ----
if( strcmp( name, "" ) == 0 ) // empty string?
return 0; // black
+
+ static FILE *file = NULL;
+ static GHashTable* table = NULL;
! if( table == NULL )
! table = g_hash_table_new( g_str_hash, g_str_equal );
! if( file == NULL )
! {
! char* searchfiles[] = {
! "./rgb.txt",
! #ifdef RGBFILE
! RGBFILE,
! #endif
! "../rgb.txt",
! NULL };
!
! for( int i=0;
! searchfiles[i];
! i++ )
! {
! char* filename = searchfiles[i];
! PRINT_DEBUG1( "Attempting to open \"%s\"", filename );
! if( (file = fopen( filename, "r")) )
! break; // opened a file ok - jump out of for loop
! }
!
! if( file == NULL )
! {
!
! PRINT_ERR1("unable to open color database: %s",
! strerror(errno));
! fclose(file);
! exit(0);
! }
!
! PRINT_DEBUG( "Success!" );
! // load the file into the hash table
! while (TRUE)
! {
! char line[1024];
! if (!fgets(line, sizeof(line), file))
! break;
!
! // it's a macro or comment line - ignore the line
! if (line[0] == '!' || line[0] == '#' || line[0] == '%')
! continue;
! // Trim the trailing space
! while (strchr(" \t\n", line[strlen(line)-1]))
! line[strlen(line)-1] = 0;
!
! // Read the color
! int r, g, b;
! int chars_matched = 0;
! sscanf( line, "%d %d %d %n", &r, &g, &b, &chars_matched );
!
! stg_color_t col = ( 0xFF000000 | (r << 16) | (g << 8) | b);
! // Read the name
! char* colorname = strdup( line + chars_matched );
!
! // map the name to the color in the table
! g_hash_table_insert( table, (gpointer)colorname, (gpointer)col );
!
! }
fclose(file);
}
+ // look up the colorname in the database
+ return (stg_color_t)g_hash_table_lookup( table, name );
+ }
Index: model_laser.c
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/model_laser.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -C2 -d -r1.90 -r1.91
*** model_laser.c 21 Nov 2006 01:48:47 -0000 1.90
--- model_laser.c 14 Jan 2008 20:23:01 -0000 1.91
***************
*** 376,379 ****
--- 376,382 ----
stg_rtk_fig_color_rgb32( fg, bright_color );
+ points[0].x = 0.0;
+ points[0].y = 0.0;
+
int s;
for( s=0; s<sample_count; s++ )
Index: stg_time.h
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/stg_time.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** stg_time.h 25 Aug 2005 18:11:45 -0000 1.5
--- stg_time.h 14 Jan 2008 20:23:01 -0000 1.6
***************
*** 31,36 ****
#include <libplayercore/playercore.h>
- //#include "stage.h"
- //#include "p_driver.h"
class StgDriver;
--- 31,34 ----
Index: stg_time.cc
===================================================================
RCS file: /cvsroot/playerstage/code/stage/src/stg_time.cc,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** stg_time.cc 20 Sep 2005 00:36:24 -0000 1.11
--- stg_time.cc 14 Jan 2008 20:23:01 -0000 1.12
***************
*** 27,32 ****
///////////////////////////////////////////////////////////////////////////
-
- #include "stage_internal.h"
#include "stg_time.h"
#include "math.h"
--- 27,30 ----
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit