Line data Source code
1 0 : /* 2 : 3 : OOModelVerifierStage.m 4 : 5 : 6 : Oolite 7 : Copyright (C) 2004-2013 Giles C Williams and contributors 8 : 9 : This program is free software; you can redistribute it and/or 10 : modify it under the terms of the GNU General Public License 11 : as published by the Free Software Foundation; either version 2 12 : of the License, or (at your option) any later version. 13 : 14 : This program is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU General Public License for more details. 18 : 19 : You should have received a copy of the GNU General Public License 20 : along with this program; if not, write to the Free Software 21 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 : MA 02110-1301, USA. 23 : 24 : */ 25 : 26 : #import "OOModelVerifierStage.h" 27 : 28 : #if OO_OXP_VERIFIER_ENABLED 29 : 30 : #import "OOFileScannerVerifierStage.h" 31 : 32 0 : static NSString * const kStageName = @"Testing models"; 33 : 34 0 : static id NSNULL = nil; 35 : 36 : 37 : @interface OOModelVerifierStage (OOPrivate) 38 : 39 0 : - (void)checkModel:(NSString *)name 40 : context:(NSString *)context 41 : materials:(NSDictionary *)materials 42 : shaders:(NSDictionary *)shaders; 43 : 44 : @end 45 : 46 : 47 : @implementation OOModelVerifierStage 48 : 49 0 : - (id)init 50 : { 51 : self = [super init]; 52 : if (self != nil) 53 : { 54 : NSNULL = [[NSNull null] retain]; 55 : _modelsToCheck = [[NSMutableSet alloc] init]; 56 : } 57 : return self; 58 : } 59 : 60 : 61 0 : - (void)dealloc 62 : { 63 : [_modelsToCheck release]; 64 : 65 : [super dealloc]; 66 : } 67 : 68 : 69 : + (NSString *)nameForReverseDependencyForVerifier:(OOOXPVerifier *)verifier 70 : { 71 : OOModelVerifierStage *stage = [verifier stageWithName:kStageName]; 72 : if (stage == nil) 73 : { 74 : stage = [[OOModelVerifierStage alloc] init]; 75 : [verifier registerStage:stage]; 76 : [stage release]; 77 : } 78 : 79 : return kStageName; 80 : } 81 : 82 : 83 0 : - (NSString *)name 84 : { 85 : return kStageName; 86 : } 87 : 88 : 89 0 : - (BOOL)shouldRun 90 : { 91 : return [_modelsToCheck count] != 0; 92 : } 93 : 94 : 95 0 : - (void)run 96 : { 97 : NSEnumerator *nameEnum = nil; 98 : NSDictionary *info = nil; 99 : NSAutoreleasePool *pool = nil; 100 : NSString *name = nil, 101 : *context = nil; 102 : NSDictionary *materials = nil, 103 : *shaders = nil; 104 : 105 : OOLog(@"verifyOXP.models.unimplemented", @"%@", @"TODO: implement model verifier."); 106 : 107 : for (nameEnum = [_modelsToCheck objectEnumerator]; (info = [nameEnum nextObject]); ) 108 : { 109 : pool = [[NSAutoreleasePool alloc] init]; 110 : 111 : name = [info objectForKey:@"name"]; 112 : context = [info objectForKey:@"context"]; 113 : if (context == NSNULL) context = nil; 114 : materials = [info objectForKey:@"materials"]; 115 : if (materials == NSNULL) materials = nil; 116 : shaders = [info objectForKey:@"shaders"]; 117 : if (shaders == NSNULL) shaders = nil; 118 : 119 : [self checkModel:name 120 : context:context 121 : materials:materials 122 : shaders:shaders]; 123 : 124 : [pool release]; 125 : } 126 : [_modelsToCheck release]; 127 : _modelsToCheck = nil; 128 : } 129 : 130 : 131 : - (BOOL) modelNamed:(NSString *)name 132 : usedForEntry:(NSString *)entryName 133 : inFile:(NSString *)fileName 134 : withMaterials:(NSDictionary *)materials 135 : andShaders:(NSDictionary *)shaders 136 : { 137 : OOFileScannerVerifierStage *fileScanner = nil; 138 : NSDictionary *info = nil; 139 : NSString *context = nil; 140 : 141 : if (name == nil) return NO; 142 : 143 : if (entryName != nil) context = [NSString stringWithFormat:@"entry \"%@\" of %@", entryName, fileName]; 144 : else context = fileName; 145 : 146 : fileScanner = [[self verifier] fileScannerStage]; 147 : if (![fileScanner fileExists:name 148 : inFolder:@"Models" 149 : referencedFrom:context 150 : checkBuiltIn:YES]) 151 : { 152 : return NO; 153 : } 154 : 155 : if (context == nil) context = NSNULL; 156 : if (materials == nil) materials = NSNULL; 157 : if (shaders == nil) shaders = NSNULL; 158 : 159 : info = [NSDictionary dictionaryWithObjectsAndKeys: 160 : name, @"name", 161 : context, @"context", 162 : materials, @"materials", 163 : shaders, @"shaders", 164 : nil]; 165 : 166 : [_modelsToCheck addObject:info]; 167 : 168 : return YES; 169 : } 170 : 171 : @end 172 : 173 : 174 : @implementation OOModelVerifierStage (OOPrivate) 175 : 176 : 177 : - (void)checkModel:(NSString *)name 178 : context:(NSString *)context 179 : materials:(NSDictionary *)materials 180 : shaders:(NSDictionary *)shaders 181 : { 182 : OOLog(@"verifyOXP.verbose.model.unimp", @"- Pretending to verify model %@ referenced in %@.", name, context); 183 : // FIXME: this should check DAT files. 184 : } 185 : 186 : @end 187 : 188 : 189 : @implementation OOOXPVerifier(OOModelVerifierStage) 190 : 191 : - (OOModelVerifierStage *)modelVerifierStage 192 : { 193 : return [self stageWithName:kStageName]; 194 : } 195 : 196 : @end 197 : 198 : #endif