File: textureGeneratorTestRig.m

package info (click to toggle)
oolite 1.77.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,264 kB
  • ctags: 5,362
  • sloc: objc: 132,090; ansic: 10,457; python: 2,225; sh: 1,325; makefile: 332; perl: 259; xml: 125; php: 5
file content (137 lines) | stat: -rw-r--r-- 3,432 bytes parent folder | download
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#import <Foundation/Foundation.h>
#import "CollectionUtils.h"
#import "OOPlanetTextureGenerator.h"
#import "OOProfilingStopwatch.h"


#define WRITE_RESULTS	1


int main (int argc, const char * argv[])
{
    [[NSAutoreleasePool alloc] init];
	
	// Set up magic numbers for Lave.
	RANROTSeed seed = { 3560527675, 2338263651 };
	NSDictionary *planetInfo =
	$dict(
		  @"economy", $int(5),
		  @"land_color", [OOColor colorWithRed:0.742188 green:0.662143 blue:0.472565],
		  @"sea_color", [OOColor colorWithRed:0.589844 green:0.393997 blue:0.573013],
		  @"polar_land_color", [OOColor colorWithRed:0.925781 green:0.90082 blue:0.841702],
		  @"polar_sea_color", [OOColor colorWithRed:0.941016 green:0.862904 blue:0.934303],
		  @"land_fraction", $float(0.65),
		  @"noise_map_seed", [NSValue valueWithBytes:&seed objCType:@encode(RANROTSeed)]
	);
	
	// Set up generators with mock texture thingies.
	OOTexture *diffuseTex = nil, *normalTex = nil;
	if (![OOPlanetTextureGenerator generatePlanetTexture:&diffuseTex
										secondaryTexture:&normalTex
												withInfo:planetInfo])
	{
		NSLog(@"Well, that's interesting. The texture generator failed to set up.");
		return EXIT_FAILURE;
	}
	
	OOTextureGenerator *diffuseGen = diffuseTex.generator;
	
	// This is the bit that's interesting to profile.
	OOProfilingStopwatch *stopwatch = [OOProfilingStopwatch stopwatch];
	[stopwatch start];
	[diffuseGen render];
	[stopwatch stop];
	
	NSLog(@"Rendering completed in %g seconds.", stopwatch.currentTime);
	
#if WRITE_RESULTS
	OOTextureGenerator *normalGen = normalTex.generator;
	[normalGen render];
	
	NSLog(@"Writing diffuse/lights.");
	[diffuseGen dumpToRGBFile:@"diffuse" andAlphaFile:@"lights"];
	NSLog(@"Writing normal/specular.");
	[normalGen dumpToRGBFile:@"normal" andAlphaFile:@"specular"];
	NSLog(@"Done.");
#endif
	
    return 0;
}


unsigned RanrotWithSeed(RANROTSeed *ioSeed)
{
	assert(ioSeed != NULL);
	
	ioSeed->high = (ioSeed->high << 16) + (ioSeed->high >> 16);
	ioSeed->high += ioSeed->low;
	ioSeed->low += ioSeed->high;
	return ioSeed->high & 0x7FFFFFFF;
}


float randfWithSeed(RANROTSeed *ioSeed)
{
	return (RanrotWithSeed(ioSeed) & 0xffff) * (1.0f / 65536.0f);
}


@implementation OOColor

@synthesize redComponent, blueComponent, greenComponent;

+ (OOColor *) colorWithRed:(float)r green:(float)g blue:(float)b
{
	OOColor *result = [[[OOColor alloc] init] autorelease];
	result.redComponent = r;
	result.greenComponent = g;
	result.blueComponent = b;
	return result;
}

@end


@implementation OOTexture

@synthesize generator = _generator;

+ (id) textureWithGenerator:(OOTextureGenerator *)generator
{
	OOTexture *result = [[[OOTexture alloc] init] autorelease];
	result.generator = generator;
	return result;
}

@end


void OOLog(NSString *msgClass, NSString *format, ...)
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	
	va_list args;
	va_start(args, format);
	NSString *message = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
	va_end(args);
	
	message = [NSString stringWithFormat:@"[%@] %@", msgClass, message];
	puts([message UTF8String]);
	
	DESTROY(pool);
}


void NSLogShim(NSString *format, ...)
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	
	va_list args;
	va_start(args, format);
	NSString *message = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
	va_end(args);
	
	puts([message UTF8String]);
	
	DESTROY(pool);
}