Oolite
Loading...
Searching...
No Matches
OOProbabilisticTextureManager Class Reference

#include <OOProbabilisticTextureManager.h>

Inheritance diagram for OOProbabilisticTextureManager:
Collaboration diagram for OOProbabilisticTextureManager:

Instance Methods

(id) - initWithPListName:options:anisotropy:lodBias:
(id) - initWithPListName:options:anisotropy:lodBias:seed:
(OOTexture *) - selectTexture
(unsigned) - textureCount
(void) - ensureTexturesLoaded
(RANROTSeed) - seed
(void) - setSeed:
(void) - dealloc [implementation]
(NSString *) - description [implementation]

Private Attributes

unsigned _count
OOTexture ** _textures
float * _prob
int * _galaxy
float _probMax
float * _probMaxGal
RANROTSeed _seed

Detailed Description

Definition at line 36 of file OOProbabilisticTextureManager.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 147 of file OOProbabilisticTextureManager.m.

148{
149 unsigned i;
150
151 if (_textures != NULL) {
152 for (i = 0; i != _count; ++i) {
153 [_textures[i] release];
154 }
155 free(_textures);
156 }
157
158 if (_prob != NULL)
159 free(_prob);
160 if (_galaxy != NULL)
161 free(_galaxy);
162 if (_probMaxGal != NULL)
163 free(_probMaxGal);
164
165 [super dealloc];
166}

References _count, _galaxy, _prob, _probMaxGal, _textures, and dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ description

- (NSString *) description
implementation

Definition at line 168 of file OOProbabilisticTextureManager.m.

169{
170 return [NSString stringWithFormat:@"<%@ %p>{%u textures, cumulative probability=%g}", [self class], self, _count, _probMax];
171}

References description.

Referenced by description.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ensureTexturesLoaded

- (void) ensureTexturesLoaded

Definition at line 210 of file OOProbabilisticTextureManager.m.

211{
212 unsigned i;
213
214 for (i = 0; i != _count; ++i) {
215 [_textures[i] ensureFinishedLoading];
216 }
217}

References _count, OOTexture::ensureFinishedLoading, and ensureTexturesLoaded.

Referenced by ensureTexturesLoaded, and OOSkyDrawable(OOPrivate)::ensureTexturesLoaded.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWithPListName:options:anisotropy:lodBias:

- (id) initWithPListName: (NSString*) plistName
options: (uint32_t) options
anisotropy: (GLfloat) anisotropy
lodBias: (GLfloat) lodBias 

Definition at line 36 of file OOProbabilisticTextureManager.m.

36 :(NSString*)plistName
37 options:(uint32_t)options
38 anisotropy:(GLfloat)anisotropy
39 lodBias:(GLfloat)lodBias
40{
41 return [self initWithPListName:plistName
42 options:options
43 anisotropy:anisotropy
44 lodBias:lodBias
45 seed:RANROTGetFullSeed()];
46}

References initWithPListName:options:anisotropy:lodBias:seed:.

Here is the call graph for this function:

◆ initWithPListName:options:anisotropy:lodBias:seed:

- (id) initWithPListName: (NSString*) plistName
options: (uint32_t) options
anisotropy: (GLfloat) anisotropy
lodBias: (GLfloat) lodBias
seed: (RANROTSeed) seed 

Definition at line 48 of file OOProbabilisticTextureManager.m.

48 :(NSString*)plistName
49 options:(uint32_t)options
50 anisotropy:(GLfloat)anisotropy
51 lodBias:(GLfloat)lodBias
53{
54 BOOL OK = YES;
55 NSArray* config = nil;
56 NSUInteger i, count, j;
57 id entry = nil;
58 NSString* name = nil;
59 float probability;
60 OOTexture* texture = nil;
61 int galID = -1;
62 id object = nil;
63
64 self = [super init];
65 if (self == nil)
66 OK = NO;
67
68 if (OK) {
69 config = [ResourceManager arrayFromFilesNamed:plistName inFolder:@"Config" andMerge:YES];
70 if (config == nil)
71 OK = NO;
72 }
73
74 if (OK) {
75 count = [config count];
76
77 _textures = malloc(sizeof *_textures * count);
78 _prob = malloc(sizeof *_prob * count);
79 _galaxy = malloc(sizeof *_galaxy * count);
80 _probMaxGal = malloc(sizeof *_probMaxGal * (kOOMaximumGalaxyID + 1));
81
82 if (_textures == NULL || _prob == NULL || _galaxy == NULL)
83 OK = NO;
84 }
85
86 if (OK) {
87 for (i = 0; i <= kOOMaximumGalaxyID; i++)
88 _probMaxGal[i] = 0;
89
90 // Go through list and load textures.
91 for (i = 0; i != count; ++i) {
92 entry = [config objectAtIndex:i];
93 galID = -1;
94 if ([entry isKindOfClass:[NSDictionary class]]) {
95 name = [(NSDictionary*)entry oo_stringForKey:@"texture"];
96 probability = [entry oo_floatForKey:@"probability" defaultValue:1.0f];
97 object = [entry objectForKey:@"galaxy"];
98 if ([object isKindOfClass:[NSString class]]) {
99 galID = [object intValue];
100 } else if (object != nil) {
101 OOLog(@"textures.load", @"***** ERROR: %@ for texture %@ is not a string.", @"galaxy", name);
102 }
103 } else if ([entry isKindOfClass:[NSString class]]) {
104 name = entry;
105 probability = 1.0f;
106 } else {
107 name = nil;
108 }
109
110 if (name != nil && 0.0f < probability) {
111 texture = [OOTexture textureWithName:name
112 inFolder:@"Textures"
113 options:options
114 anisotropy:anisotropy
115 lodBias:lodBias];
116 if (texture != nil) {
117 _textures[_count] = [texture retain];
118 _prob[_count] = probability + (galID >= 0 ? _probMaxGal[galID] : _probMax);
119 _galaxy[_count] = (galID >= 0 ? galID : -1);
120 if (galID >= 0) {
121 _probMaxGal[galID] += probability;
122 } else {
123 for (j = 0; j <= kOOMaximumGalaxyID; j++)
124 _probMaxGal[j] += probability;
125 _probMax += probability;
126 }
127 ++_count;
128 }
129 }
130 }
131
132 if (_count == 0)
133 OK = NO;
134 }
135
136 if (OK)
137 _seed = seed;
138
139 if (!OK) {
140 [self release];
141 self = nil;
142 }
143
144 return self;
145}
#define OOLog(class, format,...)
Definition OOLogging.h:84
unsigned count
return nil
@ kOOMaximumGalaxyID
Definition OOTypes.h:186
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
Definition OOTexture.m:132
NSArray * arrayFromFilesNamed:inFolder:andMerge:(NSString *fileName,[inFolder] NSString *folderName,[andMerge] BOOL mergeFiles)
struct RANROTSeed RANROTSeed

References _count, _galaxy, _prob, _probMax, _probMaxGal, _seed, _textures, ResourceManager::arrayFromFilesNamed:inFolder:andMerge:, count, kOOMaximumGalaxyID, nil, OOLog, seed, and OOTexture::textureWithName:inFolder:options:anisotropy:lodBias:.

Referenced by initWithPListName:options:anisotropy:lodBias:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ seed

- (RANROTSeed) seed

Definition at line 219 of file OOProbabilisticTextureManager.m.

220{
221 return _seed;
222}

References _seed, and seed.

Referenced by initWithPListName:options:anisotropy:lodBias:seed:, seed, and setSeed:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectTexture

- (OOTexture *) selectTexture

Definition at line 173 of file OOProbabilisticTextureManager.m.

174{
175 float selection;
176 unsigned i;
177 int hold = -1;
178 int galID = (int)[PLAYER currentGalaxyID];
179
180 selection = randfWithSeed(&_seed);
181
182 selection *= _probMaxGal[galID];
183
184 for (i = 0; i != _count; ++i) {
185 if (_galaxy[i] == -1 || _galaxy[i] == galID) {
186 // make a note of the index of the first texture that meets the galaxy list criteria (but only if _galaxy is set)
187 if (hold == -1 && _prob[i] > 0 && _galaxy[i] == galID)
188 hold = i;
189 if (selection <= _prob[i])
190 return _textures[i];
191 }
192 }
193
194 // first catch point if loop above fails to return a texture
195 // return first texture that meets the galaxy list criteria and has a probability > 0
196 if (hold >= 0) {
197 OOLog(@"probabilisticTextureManager.internalWarning", @"%s: overrun! Galaxy List requirements not met. Choosing first texture available for galaxy.", __PRETTY_FUNCTION__);
198 return _textures[hold];
199 }
200
201 OOLog(@"probabilisticTextureManager.internalFailure", @"%s: overrun! Choosing last texture.", __PRETTY_FUNCTION__);
202 return _textures[_count - 1];
203}
#define PLAYER
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
float randfWithSeed(RANROTSeed *ioSeed)

References _count, _galaxy, _prob, _probMaxGal, _seed, _textures, int(), OOLog, PLAYER, randfWithSeed(), and selectTexture.

Referenced by selectTexture, OOSkyDrawable(OOPrivate)::setUpNebulaeWithColor1:color2:clusterFactor:nebulaHueFix:alpha:scale:, and OOSkyDrawable(OOPrivate)::setUpStarsWithColor1:color2:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setSeed:

- (void) setSeed: (RANROTSeed) seed

Definition at line 224 of file OOProbabilisticTextureManager.m.

225{
226 _seed = seed;
227}

References _seed, and seed.

Referenced by OOSkyDrawable(OOPrivate)::loadNebulaTextures, and OOSkyDrawable(OOPrivate)::loadStarTextures.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textureCount

- (unsigned) textureCount

Definition at line 205 of file OOProbabilisticTextureManager.m.

206{
207 return _count;
208}

References _count, and textureCount.

Referenced by textureCount.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _count

◆ _galaxy

- (int*) _galaxy
private

◆ _prob

- (float*) _prob
private

◆ _probMax

- (float) _probMax
private

◆ _probMaxGal

- (float*) _probMaxGal
private

◆ _seed

◆ _textures

- (OOTexture**) _textures
private

The documentation for this class was generated from the following files: