Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOTextureVerifierStage.m
Go to the documentation of this file.
1/*
2
3OOTextureVerifierStage.m
4
5
6Oolite
7Copyright (C) 2004-2013 Giles C Williams and contributors
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22MA 02110-1301, USA.
23
24*/
25
27
28#if OO_OXP_VERIFIER_ENABLED
29
30#import "OOTextureLoader.h"
32#import "OOMaths.h"
33
34static NSString * const kStageName = @"Testing textures and images";
35
36
37@interface OOTextureVerifierStage (OOPrivate)
38
39- (void)checkTextureNamed:(NSString *)name inFolder:(NSString *)folder;
40
41@end
42
43
44@implementation OOTextureVerifierStage
45
46- (id)init
47{
48 self = [super init];
49 if (self != nil)
50 {
51 _usedTextures = [[NSMutableSet alloc] init];
52 }
53 return self;
54}
55
56
57- (void)dealloc
58{
59 [_usedTextures release];
60
61 [super dealloc];
62}
63
64
65+ (NSString *)nameForReverseDependencyForVerifier:(OOOXPVerifier *)verifier
66{
67 return kStageName;
68}
69
70
71- (NSString *)name
72{
73 return kStageName;
74}
75
76
77- (BOOL)shouldRun
78{
79 return [_usedTextures count] != 0 || [[[self verifier] fileScannerStage] filesInFolder:@"Images"] != nil;
80}
81
82
83- (void)run
84{
85 NSEnumerator *nameEnum = nil;
86 NSString *name = nil;
87 NSAutoreleasePool *pool = nil;
88
89 for (nameEnum = [_usedTextures objectEnumerator]; (name = [nameEnum nextObject]); )
90 {
91 pool = [[NSAutoreleasePool alloc] init];
92 [self checkTextureNamed:name inFolder:@"Textures"];
93 [pool release];
94 }
95 [_usedTextures release];
96 _usedTextures = nil;
97
98 // All "images" are considered used, since we don't have a reasonable way to look for images referenced in JavaScript scripts.
99 nameEnum = [[[[self verifier] fileScannerStage] filesInFolder:@"Images"] objectEnumerator];
100 while ((name = [nameEnum nextObject]))
101 {
102 [self checkTextureNamed:name inFolder:@"Images"];
103 }
104}
105
106
107- (void) textureNamed:(NSString *)name usedInContext:(NSString *)context
108{
109 OOFileScannerVerifierStage *fileScanner = nil;
110
111 if (name == nil) return;
112 if ([_usedTextures containsObject:name]) return;
113 [_usedTextures addObject:name];
114
115 fileScanner = [[self verifier] fileScannerStage];
116 if (![fileScanner fileExists:name
117 inFolder:@"Textures"
118 referencedFrom:context
119 checkBuiltIn:YES])
120 {
121 OOLog(@"verifyOXP.texture.notFound", @"----- WARNING: texture \"%@\" referenced in %@ could not be found in %@ or in Oolite.", name, context, [[self verifier] oxpDisplayName]);
122 }
123}
124
125@end
126
127
128@implementation OOTextureVerifierStage (OOPrivate)
129
130- (void)checkTextureNamed:(NSString *)name inFolder:(NSString *)folder
131{
132 OOTextureLoader *loader = nil;
133 NSString *path = nil;
134 OOFileScannerVerifierStage *fileScanner = nil;
135 NSString *displayName = nil;
136 OOPixMapDimension rWidth, rHeight;
137 BOOL success;
138 OOPixMap pixmap;
139 OOTextureDataFormat format;
140
141 fileScanner = [[self verifier] fileScannerStage];
142 path = [fileScanner pathForFile:name
143 inFolder:folder
145 checkBuiltIn:NO];
146
147 if (path == nil) return;
148
149 loader = [OOTextureLoader loaderWithPath:path
150 options:kOOTextureMinFilterNearest |
151 kOOTextureMinFilterNearest |
152 kOOTextureNoShrink |
153 kOOTextureNoFNFMessage |
154 kOOTextureNeverScale];
155
156 displayName = [fileScanner displayNameForFile:name andFolder:folder];
157 if (loader == nil)
158 {
159 OOLog(@"verifyOXP.texture.failed", @"***** ERROR: image %@ could not be read.", displayName);
160 }
161 else
162 {
163 success = [loader getResult:&pixmap format:&format originalWidth:NULL originalHeight:NULL];
164
165 if (success)
166 {
167 rWidth = OORoundUpToPowerOf2_PixMap((2 * pixmap.width) / 3);
168 rHeight = OORoundUpToPowerOf2_PixMap((2 * pixmap.height) / 3);
169 if (pixmap.width != rWidth || pixmap.height != rHeight)
170 {
171 OOLog(@"verifyOXP.texture.notPOT", @"----- WARNING: image %@ has non-power-of-two dimensions; it will have to be rescaled (from %ux%u pixels to %ux%u pixels) at runtime.", displayName, pixmap.width, pixmap.height, rWidth, rHeight);
172 }
173 else
174 {
175 OOLog(@"verifyOXP.verbose.texture.OK", @"- %@ (%ux%u px) OK.", displayName, pixmap.width, pixmap.height);
176 }
177
178 OOFreePixMap(&pixmap);
179 }
180 else
181 {
182 OOLog(@"verifyOXP.texture.failed", @"***** ERROR: texture loader failed to load %@.", displayName);
183 }
184 }
185}
186
187@end
188
189
190@implementation OOTextureHandlingStage
191
192- (NSSet *)dependents
193{
194 NSMutableSet *result = [[super dependents] mutableCopy];
195 [result addObject:[OOTextureVerifierStage nameForReverseDependencyForVerifier:[self verifier]]];
196 return [result autorelease];
197}
198
199@end
200
201
203
204- (OOTextureVerifierStage *)textureVerifierStage
205{
206 return [self stageWithName:kStageName];
207}
208
209@end
210
211#endif
static NSString *const kStageName
#define OOLog(class, format,...)
Definition OOLogging.h:88
uint_fast32_t OOPixMapDimension
Definition OOPixMap.h:33
void OOFreePixMap(OOPixMap *ioPixMap)
Definition OOPixMap.m:86
OOPixMapFormat
Definition OOPixMap.h:39
#define OORoundUpToPowerOf2_PixMap
Definition OOPixMap.h:35
return nil
static NSString *const kStageName
id displayNameForFile:andFolder:(NSString *file,[andFolder] NSString *folder)
NSString * pathForFile:inFolder:referencedFrom:checkBuiltIn:(NSString *file,[inFolder] NSString *folder,[referencedFrom] NSString *context,[checkBuiltIn] BOOL checkBuiltIn)
id loaderWithPath:options:(NSString *path,[options] uint32_t options)
BOOL getResult:format:originalWidth:originalHeight:(OOPixMap *result,[format] OOTextureDataFormat *outFormat,[originalWidth] uint32_t *outWidth,[originalHeight] uint32_t *outHeight)
NSString * nameForReverseDependencyForVerifier:(OOOXPVerifier *verifier)
OOPixMapDimension height
Definition OOPixMap.h:50
OOPixMapDimension width
Definition OOPixMap.h:50