Oolite 1.91.0.7646-241128-10e222e
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 37 of file OOProbabilisticTextureManager.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 1 of file OOProbabilisticTextureManager.m.

161{
162 unsigned i;
163
164 if (_textures != NULL)
165 {
166 for (i = 0; i != _count; ++i)
167 {
168 [_textures[i] release];
169 }
170 free(_textures);
171 }
172
173 if (_prob != NULL) free(_prob);
174 if (_galaxy != NULL) free(_galaxy);
175 if (_probMaxGal != NULL) free(_probMaxGal);
176
177 [super dealloc];
178}

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

+ Here is the call graph for this function:

◆ description

- (NSString *) description
implementation

Definition at line 1 of file OOProbabilisticTextureManager.m.

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

◆ ensureTexturesLoaded

- (void) ensureTexturesLoaded

Definition at line 1 of file OOProbabilisticTextureManager.m.

228{
229 unsigned i;
230
231 for (i = 0; i != _count; ++i)
232 {
233 [_textures[i] ensureFinishedLoading];
234 }
235}

◆ initWithPListName:options:anisotropy:lodBias:

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

Definition at line 1 of file OOProbabilisticTextureManager.m.

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

◆ 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 1 of file OOProbabilisticTextureManager.m.

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

Referenced by dealloc.

+ Here is the caller graph for this function:

◆ seed

- (RANROTSeed) seed

Definition at line 1 of file OOProbabilisticTextureManager.m.

239{
240 return _seed;
241}

◆ selectTexture

- (OOTexture *) selectTexture

Definition at line 1 of file OOProbabilisticTextureManager.m.

188{
189 float selection;
190 unsigned i;
191 int hold = -1;
192 int galID = (int)[PLAYER currentGalaxyID];
193
194 selection = randfWithSeed(&_seed);
195
196 selection *= _probMaxGal[galID];
197
198 for (i = 0; i != _count; ++i)
199 {
200 if (_galaxy[i] == -1 || _galaxy[i] == galID)
201 {
202 // make a note of the index of the first texture that meets the galaxy list criteria (but only if _galaxy is set)
203 if (hold == -1 && _prob[i] > 0 && _galaxy[i] == galID) hold = i;
204 if (selection <= _prob[i]) return _textures[i];
205 }
206 }
207
208 // first catch point if loop above fails to return a texture
209 // return first texture that meets the galaxy list criteria and has a probability > 0
210 if (hold >= 0)
211 {
212 OOLog(@"probabilisticTextureManager.internalWarning", @"%s: overrun! Galaxy List requirements not met. Choosing first texture available for galaxy.", __PRETTY_FUNCTION__);
213 return _textures[hold];
214 }
215
216 OOLog(@"probabilisticTextureManager.internalFailure", @"%s: overrun! Choosing last texture.", __PRETTY_FUNCTION__);
217 return _textures[_count - 1];
218}
#define PLAYER
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
float randfWithSeed(RANROTSeed *ioSeed)

◆ setSeed:

- (void) setSeed: (RANROTSeed) seed

Definition at line 1 of file OOProbabilisticTextureManager.m.

245{
246 _seed = seed;
247}
struct RANROTSeed RANROTSeed

◆ textureCount

- (unsigned) textureCount

Definition at line 1 of file OOProbabilisticTextureManager.m.

222{
223 return _count;
224}

Member Data Documentation

◆ _count

- (unsigned) _count
private

Definition at line 40 of file OOProbabilisticTextureManager.h.

◆ _galaxy

- (int*) _galaxy
private

Definition at line 43 of file OOProbabilisticTextureManager.h.

◆ _prob

- (float*) _prob
private

Definition at line 42 of file OOProbabilisticTextureManager.h.

◆ _probMax

- (float) _probMax
private

Definition at line 44 of file OOProbabilisticTextureManager.h.

◆ _probMaxGal

- (float*) _probMaxGal
private

Definition at line 45 of file OOProbabilisticTextureManager.h.

◆ _seed

- (RANROTSeed) _seed
private

Definition at line 46 of file OOProbabilisticTextureManager.h.

◆ _textures

- (OOTexture**) _textures
private

Definition at line 41 of file OOProbabilisticTextureManager.h.


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