blob: 3218624bf7e16d826a7c5194548d11ab9356066f (
plain) (
blame)
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
|
/***************************************************************************
drawgl.m
an odd set of functions that seem misplaced ATM.
presumably this is the glue to the C GPU plugin stuff
but a much better place might be "PluginWindowController.m" as
gluing is what a controller is made for.
PeopsOpenGPU
Created by Gil Pedersen on Sun April 18 2004.
Copyright (c) 2004 Gil Pedersen.
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. See also the license.txt file for *
* additional informations. *
* *
***************************************************************************/
#import "PluginWindowController.h"
#import "PluginGLView.h"
#include "ExtendedKeys.h"
#include "externals.h"
#include "draw.h"
#include "gpu.h"
#include "menu.h"
#include "drawgl.h"
////////////////////////////////////////////////////////////////////////////////////
// misc globals
////////////////////////////////////////////////////////////////////////////////////
#if 0 // globals for OpenGL (vs. SoftGPU) are owned by others... weird
int iResX;
int iResY;
long lLowerpart;
BOOL bIsFirstFrame = TRUE;
BOOL bCheckMask=FALSE;
unsigned short sSetMask=0;
/* unsigned long lSetMask=0; */
uint32_t sSetMassk=0;
int iDesktopCol=16;
int iShowFPS=0;
int iWinSize;
int iUseScanLines=0;
int iUseNoStretchBlt=0;
int iFastFwd=0;
int iDebugMode=0;
int iFVDisplay=0;
PSXPoint_t ptCursorPoint[8];
unsigned short usCursorActive=0;
char * Xpixels;
char * pCaptionText;
#endif
extern BOOL bCheckMask;
extern BOOL bIsFirstFrame;
extern int iShowFPS;
extern unsigned short sSetMask;
extern int iUseScanLines;
extern unsigned short usCursorActive;
int iResX;
int iResY;
long lLowerpart;
uint32_t sSetMassk=0;
int iDesktopCol=16;
int iWinSize;
int iUseNoStretchBlt=0;
int iFastFwd=0;
int iDebugMode=0;
int iFVDisplay=0;
PSXPoint_t ptCursorPoint[8];
char * Xpixels;
char * pCaptionText;
//static PluginWindowController *windowController;
// static is BAD NEWS if user uses other plug ins
PluginGLView *glView;
////////////////////////////////////////////////////////////////////////
void DoBufferSwap(void) // SWAP BUFFERS
{
#if 1
[glView swapBuffer];
#else
static long long lastTickCount = -1;
static int skipCount = 0;
long long microTickCount;
long deltaTime;
Microseconds((struct UnsignedWide *)µTickCount);
deltaTime = (long)(microTickCount - lastTickCount);
if (deltaTime <= (PSXDisplay.PAL ? 1000000/50 : 100000000 / 5994) ||
skipCount >= 3) {
skipCount = 0;
[glView swapBuffer];
} else {
skipCount++;
}
NSLog(@"count: %i", deltaTime);
lastTickCount = microTickCount;
#endif
}
////////////////////////////////////////////////////////////////////////
void DoClearScreenBuffer(void) // CLEAR DX BUFFER
{
// clear the screen, and DON'T flush it
[glView clearBuffer:NO];
}
////////////////////////////////////////////////////////////////////////
void DoClearFrontBuffer(void) // CLEAR DX BUFFER
{
// clear the screen, and flush it
[glView clearBuffer:YES];
}
////////////////////////////////////////////////////////////////////////
unsigned long ulInitDisplay(void) // OPEN GAME WINDOW
{
bUsingTWin = FALSE;
//InitMenu(); // This function does nothing
bIsFirstFrame = FALSE;
if(iShowFPS)
{
//iShowFPS=0;
ulKeybits |= KEY_SHOWFPS;
szDispBuf[0] = 0;
BuildDispMenu(0);
}
__block PluginWindowController *windowController;
// this causes a runtime error if it's done on a thread other than the main thread
RunOnMainThreadSync(^{
windowController = [PluginWindowController openGameView];
glView = [windowController openGLView];
[[windowController window] setTitle:@(pCaptionText)];
});
return (unsigned long)[windowController window];
}
////////////////////////////////////////////////////////////////////////
void CloseDisplay(void)
{
if (gameController) {
[gameController close];
gameController = nil;
gameWindow = nil;
}
}
void BringContextForward(void)
{
[[glView openGLContext] makeCurrentContext];
}
void SendContextBack(void)
{
[NSOpenGLContext clearCurrentContext];
}
void SetVSync(GLint myValue)
{
GLint DoItMyFriend = myValue;
[[glView openGLContext] setValues: &DoItMyFriend forParameter: NSOpenGLCPSwapInterval];
}
////////////////////////////////////////////////////////////////////////
/* taken care of in menu.c
void CreatePic(unsigned char * pMem)
{
}
*/
///////////////////////////////////////////////////////////////////////////////////////
/* taken care of in menu.c
void DestroyPic(void)
{
}
*/
///////////////////////////////////////////////////////////////////////////////////////
/* taken care of in menu.c
void DisplayPic(void)
{
}
*/
///////////////////////////////////////////////////////////////////////////////////////
void ShowGpuPic(void)
{
// this is the default implementation...
}
///////////////////////////////////////////////////////////////////////////////////////
void ShowTextGpuPic(void)
{
// this is the default implementation...
}
void HandleKey(int keycode)
{
switch (keycode) {
case GPU_FRAME_LIMIT:
if(bUseFrameLimit) {
bUseFrameLimit = false;
iFrameLimit = 1;
}
else {
bUseFrameLimit = true;
iFrameLimit = 2;
}
SetAutoFrameCap();
break;
case GPU_FAST_FORWARD:
if(bUseFrameLimit) {
bUseFrameLimit = false;
iFrameLimit = 1;
bUseFrameSkip = true;
iFastFwd = 0;
}
else {
bUseFrameLimit = true;
iFrameLimit = 2;
bUseFrameSkip = false;
iFastFwd = 0;
}
bSkipNextFrame = FALSE;
break;
case GPU_FULLSCREEN_KEY:
[gameController setFullscreen:![gameController fullscreen]];
break;
}
}
|