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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
#import "PluginConfigController.h"
#include "gpu.h"
#include "cfg.h"
#include "menu.h"
#include "externals.h"
#import "SGPUPreferences.h"
#import "ARCBridge.h"
#import "PluginGLView.h"
#ifdef ENABLE_NLS
#include <libintl.h>
#include <locale.h>
#define _(x) gettext(x)
#define N_(x) (x)
//If running under Mac OS X, use the Localizable.strings file instead.
#elif defined(_MACOSX)
#ifdef PCSXRCORE
__private_extern__ char* Pcsxr_locale_text(char* toloc);
#define _(String) Pcsxr_locale_text(String)
#define N_(String) String
#else
#ifndef PCSXRPLUG
#warning please define the plug being built to use Mac OS X localization!
#define _(msgid) msgid
#define N_(msgid) msgid
#else
//Kludge to get the preprocessor to accept PCSXRPLUG as a variable.
#define PLUGLOC_x(x,y) x ## y
#define PLUGLOC_y(x,y) PLUGLOC_x(x,y)
#define PLUGLOC PLUGLOC_y(PCSXRPLUG,_locale_text)
__private_extern__ char* PLUGLOC(char* toloc);
#define _(String) PLUGLOC(String)
#define N_(String) String
#endif
#endif
#else
#define _(x) (x)
#define N_(x) (x)
#endif
#define APP_ID @"net.sf.peops.SoftGpuGLPlugin"
#define PrefsKey APP_ID @" Settings"
static PluginConfigController *windowController = nil;
void AboutDlgProc()
{
// Get parent application instance
NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID];
// Get Credits.rtf
NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"];
NSAttributedString *credits;
if (path) {
credits = [[NSAttributedString alloc] initWithPath: path
documentAttributes:NULL];
AUTORELEASEOBJNORETURN(credits);
} else {
credits = AUTORELEASEOBJ([[NSAttributedString alloc] initWithString:@""]);
}
// Get Application Icon
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]];
NSSize size = NSMakeSize(64, 64);
[icon setSize:size];
NSDictionary *infoPaneDict =
[[NSDictionary alloc] initWithObjectsAndKeys:
[bundle objectForInfoDictionaryKey:@"CFBundleName"], @"ApplicationName",
icon, @"ApplicationIcon",
[bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"ApplicationVersion",
[bundle objectForInfoDictionaryKey:@"CFBundleVersion"], @"Version",
[bundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"], @"Copyright",
credits, @"Credits",
nil];
dispatch_async(dispatch_get_main_queue(), ^{
[NSApp orderFrontStandardAboutPanelWithOptions:infoPaneDict];
});
RELEASEOBJ(infoPaneDict);
}
void SoftDlgProc()
{
RunOnMainThreadSync(^{
NSWindow *window;
if (windowController == nil) {
windowController = [[PluginConfigController alloc] initWithWindowNibName:@"NetSfPeopsSoftGPUConfig"];
}
window = [windowController window];
/* load values */
[windowController loadValues];
[window center];
[window makeKeyAndOrderFront:nil];
});
}
BOOL isShaderEnabled()
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *keyValues = [defaults dictionaryForKey:PrefsKey];
return [[keyValues objectForKey:@"UseShader"] boolValue];
}
NSURL *PSXVertexShader()
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *keyValues = [defaults dictionaryForKey:PrefsKey];
return [NSURL URLByResolvingBookmarkData:[keyValues objectForKey:@"VertexShader"] options:NSURLBookmarkResolutionWithoutUI relativeToURL:nil bookmarkDataIsStale:NULL error:nil];
}
NSURL *PSXFragmentShader()
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *keyValues = [defaults dictionaryForKey:PrefsKey];
return [NSURL URLByResolvingBookmarkData:[keyValues objectForKey:@"FragmentShader"] options:NSURLBookmarkResolutionWithoutUI relativeToURL:nil bookmarkDataIsStale:NULL error:nil];
}
float PSXShaderQuality()
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSDictionary *keyValues = [defaults dictionaryForKey:PrefsKey];
return (float)[[keyValues objectForKey:@"ShaderQuality"] intValue];
}
void ReadConfig(void)
{
NSDictionary *keyValues;
NSBundle *selfBundle = [NSBundle bundleWithIdentifier:APP_ID];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
[NSDictionary dictionaryWithObjectsAndKeys:
@NO, @"FPS Counter",
@NO, @"Auto Full Screen",
@NO, @"Frame Skipping",
@YES, @"Frame Limit",
@NO, @"VSync",
@NO, @"Enable Hacks",
@1, @"Dither Mode",
@((unsigned int)0), @"Hacks",
[[selfBundle URLForResource:@"gpuPeteOGL2" withExtension:@"slv"] bookmarkDataWithOptions:NSURLBookmarkCreationPreferFileIDResolution includingResourceValuesForKeys:nil relativeToURL:nil error:nil], @"VertexShader",
[[selfBundle URLForResource:@"gpuPeteOGL2" withExtension:@"slf"] bookmarkDataWithOptions:NSURLBookmarkCreationPreferFileIDResolution includingResourceValuesForKeys:nil relativeToURL:nil error:nil], @"FragmentShader",
@NO, @"UseShader",
@4, @"ShaderQuality",
nil], PrefsKey,
nil]];
keyValues = [defaults dictionaryForKey:PrefsKey];
iShowFPS = [[keyValues objectForKey:@"FPS Counter"] boolValue];
iWindowMode = [[keyValues objectForKey:@"Auto Full Screen"] boolValue] ? 0 : 1;
UseFrameSkip = [[keyValues objectForKey:@"Frame Skipping"] boolValue];
UseFrameLimit = [[keyValues objectForKey:@"Frame Limit"] boolValue];
//??? = [[keyValues objectForKey:@"VSync"] boolValue];
iUseFixes = [[keyValues objectForKey:@"Enable Hacks"] boolValue];
iUseDither = [[keyValues objectForKey:@"Dither Mode"] intValue];
dwCfgFixes = [[keyValues objectForKey:@"Hacks"] unsignedIntValue];
iResX = 640;
iResY = 480;
iUseNoStretchBlt = 1;
fFrameRate = 60;
iFrameLimit = 2;
if (iShowFPS)
ulKeybits |= KEY_SHOWFPS;
else
ulKeybits &= ~KEY_SHOWFPS;
// additional checks
if(!iColDepth) iColDepth = 32;
if(iUseFixes) {
dwActFixes = dwCfgFixes;
} else {
dwActFixes = 0;
}
SetFixes();
if(iFrameLimit == 2) SetAutoFrameCap();
bSkipNextFrame = FALSE;
szDispBuf[0] = 0;
BuildDispMenu(0);
}
@implementation NetSfPeopsSoftGPUPluginConfigController
@synthesize fragmentPath;
@synthesize vertexPath;
- (IBAction)cancel:(id)sender
{
[self close];
}
- (IBAction)ok:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *writeDic = [NSMutableDictionary dictionaryWithDictionary:keyValues];
[writeDic setObject:([fpsCounter intValue] ? @YES : @NO) forKey:@"FPS Counter"];
[writeDic setObject:([autoFullScreen intValue] ? @YES : @NO) forKey:@"Auto Full Screen"];
[writeDic setObject:([frameSkipping intValue] ? @YES : @NO) forKey:@"Frame Skipping"];
//[writeDic setObject:@([frameLimit intValue]) forKey:@"Frame Limit"];
[writeDic setObject:([vSync intValue] ? @YES : @NO) forKey:@"VSync"];
[writeDic setObject:([hackEnable intValue] ? @YES : @NO) forKey:@"Enable Hacks"];
[writeDic setObject:([shaders intValue] ? @YES : @NO) forKey:@"UseShader"];
[writeDic setObject:@([shaderQualitySelector indexOfSelectedItem] + 1) forKey:@"ShaderQuality"];
[writeDic setObject:@([ditherMode indexOfSelectedItem]) forKey:@"Dither Mode"];
unsigned int hackValues = 0;
for (NSCell *control in [hacksMatrix cells]) {
hackValues |= [control intValue] << ([control tag] - 1);
}
[writeDic setObject:@(hackValues) forKey:@"Hacks"];
[writeDic setObject:[vertexPath bookmarkDataWithOptions:NSURLBookmarkCreationPreferFileIDResolution includingResourceValuesForKeys:nil relativeToURL:nil error:nil] forKey:@"VertexShader"];
[writeDic setObject:[fragmentPath bookmarkDataWithOptions:NSURLBookmarkCreationPreferFileIDResolution includingResourceValuesForKeys:nil relativeToURL:nil error:nil] forKey:@"FragmentShader"];
// write to defaults
[defaults setObject:writeDic forKey:PrefsKey];
[defaults synchronize];
// and set global values accordingly
ReadConfig();
[self close];
}
- (IBAction)reset:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:PrefsKey];
[self loadValues];
}
- (IBAction)hackToggle:(id)sender
{
BOOL enable = [sender intValue] ? YES : NO;
NSArray *views = [[[hacksView subviews] objectAtIndex:0] subviews];
for (NSView *control in views) {
if ([control isKindOfClass:[NSControl class]]) {
if ([control isKindOfClass:[NSTextField class]]) {
[(NSTextField*)control setTextColor:enable ? [NSColor controlTextColor] : [NSColor disabledControlTextColor] ];
}
[(NSControl *)control setEnabled:enable];
}
}
}
- (IBAction)toggleShader:(id)sender {
BOOL enable = [sender intValue] ? YES : NO;
NSArray *views = [[[shadersView subviews] objectAtIndex:0] subviews];
for (NSView *control in views) {
if ([control isKindOfClass:[NSControl class]]) {
if ([control isKindOfClass:[NSTextField class]]) {
[(NSTextField*)control setTextColor:enable ? [NSColor controlTextColor] : [NSColor disabledControlTextColor] ];
}
[(NSControl *)control setEnabled:enable];
}
}
}
- (void)setFragmentPathInfo:(NSURL *)_fragmentPath
{
self.fragmentPath = _fragmentPath;
if (_fragmentPath) {
[fragmentShaderViewablePath setTitleWithMnemonic:[fragmentPath lastPathComponent]];
[fragmentShaderViewablePath setToolTip:[fragmentPath path]];
}
}
- (void)setVertexPathInfo:(NSURL *)_vertexPath
{
self.vertexPath = _vertexPath;
if (_vertexPath) {
[vertexShaderViewablePath setTitleWithMnemonic:[vertexPath lastPathComponent]];
[vertexShaderViewablePath setToolTip:[vertexPath path]];
}
}
- (IBAction)selectShader:(id)sender {
NSOpenPanel *openPanel = RETAINOBJ([NSOpenPanel openPanel]);
[openPanel setAllowsMultipleSelection:NO];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanChooseFiles:YES];
if ([openPanel runModal] == NSFileHandlingPanelOKButton)
{
if ([sender tag] == 1) {
[self setVertexPathInfo:[openPanel URL]];
} else {
[self setFragmentPathInfo:[openPanel URL]];
}
}
RELEASEOBJ(openPanel);
}
- (void)loadValues
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
ReadConfig();
/* load from preferences */
RELEASEOBJ(keyValues);
keyValues = [[defaults dictionaryForKey:PrefsKey] mutableCopy];
{
BOOL resetPrefs = NO;
[self setVertexPathInfo:[NSURL URLByResolvingBookmarkData:[keyValues objectForKey:@"VertexShader"] options:NSURLBookmarkResolutionWithoutUI relativeToURL:nil bookmarkDataIsStale:NULL error:nil]];
if (!vertexPath) {
resetPrefs = YES;
}
[self setFragmentPathInfo:[NSURL URLByResolvingBookmarkData:[keyValues objectForKey:@"FragmentShader"] options:NSURLBookmarkResolutionWithoutUI relativeToURL:nil bookmarkDataIsStale:NULL error:nil]];
if (!fragmentPath) {
resetPrefs = YES;
}
if (resetPrefs) {
NSBundle *selfBundle = [NSBundle bundleForClass:[self class]];
[self setVertexPathInfo:[selfBundle URLForResource:@"gpuPeteOGL2" withExtension:@"slv"]];
[self setFragmentPathInfo:[selfBundle URLForResource:@"gpuPeteOGL2" withExtension:@"slf"]];
}
}
[fpsCounter setIntValue:[[keyValues objectForKey:@"FPS Counter"] intValue]];
[autoFullScreen setIntValue:[[keyValues objectForKey:@"Auto Full Screen"] intValue]];
[frameSkipping setIntValue:[[keyValues objectForKey:@"Frame Skipping"] intValue]];
[vSync setIntValue:[[keyValues objectForKey:@"VSync"] intValue]];
[hackEnable setIntValue:[[keyValues objectForKey:@"Enable Hacks"] intValue]];
[shaders setIntValue:[[keyValues objectForKey:@"UseShader"] intValue]];
[ditherMode selectItemAtIndex:[[keyValues objectForKey:@"Dither Mode"] intValue]];
[shaderQualitySelector selectItemAtIndex:[[keyValues objectForKey:@"ShaderQuality"] intValue] - 1];
unsigned int hackValues = [[keyValues objectForKey:@"Hacks"] unsignedIntValue];
for (NSCell *control in [hacksMatrix cells]) {
[control setIntValue:(hackValues >> ([control tag] - 1)) & 1];
}
[self hackToggle:hackEnable];
[self toggleShader:shaders];
}
#if !__has_feature(objc_arc)
- (void)dealloc
{
[vertexPath release];
[fragmentPath release];
[keyValues release];
[super dealloc];
}
#endif
@end
#import "OSXPlugLocalization.h"
PLUGLOCIMP([PluginConfigController class]);
|