File: features.cpp

package info (click to toggle)
cultivation 9+dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 4,452 kB
  • sloc: cpp: 35,783; ansic: 693; sh: 163; makefile: 122; perl: 67
file content (102 lines) | stat: -rw-r--r-- 2,871 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Modification History
 *
 * 2006-September-27  Jason Rohrer
 * Created.
 */



#include "defs.h"
#include "features.h"

#include "minorGems/io/file/File.h"

#include <stdio.h>


// set defaults
// all default to true unless set to 0 in features.txt
char Features::largeWindow = true;
char Features::drawClouds = true;
char Features::drawSurfaceNoise = true;
char Features::drawNiceCircles = true;
char Features::drawNicePlantLeaves = true;
char Features::drawComplexGardeners = true;
char Features::drawSoil = true;
char Features::drawWater = true;
char Features::drawShadows = true;
char Features::drawComplexPortal = true;



// map from string names to feature variable pointers
// used in the loop below to read from features.txt
int numFeatures = 10;
const char *nameMap[10] = { "largeWindow",
                           "drawClouds",
                           "drawSurfaceNoise",
                           "drawNiceCircles",
                           "drawNicePlantLeaves",
                           "drawComplexGardeners",
                           "drawSoil",
                           "drawWater",
                           "drawShadows",
                           "drawComplexPortal" };

char *variableMap[10] = { &( Features::largeWindow ),
                          &( Features::drawClouds ),
                         &( Features::drawSurfaceNoise ),
                         &( Features::drawNiceCircles ),
                         &( Features::drawNicePlantLeaves ),
                         &( Features::drawComplexGardeners ),
                         &( Features::drawSoil ),
                         &( Features::drawWater ),
                         &( Features::drawShadows ),
                         &( Features::drawComplexPortal ) };



void initializeFeatures() {
    FILE *featuresFile = fopen( DATADIR "/features.txt", "r" );

    char stringBuffer[100];
    int switchValue;
    
    if( featuresFile != NULL ) {

        
        int numRead = 2;

        while( numRead == 2 ) {
            // read more
            // read a string and a number
            numRead = fscanf( featuresFile,
                              " %99s %d ", stringBuffer, &switchValue );

            if( numRead == 2 ) {
                // process these values

                // look for a match in our feature map
                char found = false;
                for( int i=0; i<numFeatures && !found; i++ ) {

                    if( strcmp( nameMap[i], stringBuffer ) == 0 ) {
                        // hit

                        // set our variable
                        *( variableMap[i] ) = switchValue;
                        
                        found = true;
                        }
                    }
                
                }
            }
        
        
        fclose( featuresFile );
        }
    
    }