-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathPolyCore.h
More file actions
executable file
·453 lines (362 loc) · 12.5 KB
/
PolyCore.h
File metadata and controls
executable file
·453 lines (362 loc) · 12.5 KB
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*
Copyright (C) 2011 by Ivan Safrin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once
#include "PolyGlobals.h"
#include "PolyString.h"
#include "PolyRectangle.h"
#include "PolyVector2.h"
#include "PolyEventDispatcher.h"
#include "PolyCoreInput.h"
#include "PolyCoreServices.h"
#include "PolyThreaded.h"
long getThreadID();
namespace Polycode {
class Renderer;
class _PolyExport CoreMutex : public PolyBase {
public:
int mutexID;
};
class _PolyExport CoreFileExtension : public PolyBase {
public:
CoreFileExtension() {}
CoreFileExtension(String description, String extension) {
this->extension = extension;
this->description = description;
}
String extension;
String description;
};
class _PolyExport PolycodeViewBase : public PolyBase {
public:
PolycodeViewBase() { windowData = NULL; }
virtual ~PolycodeViewBase(){}
void *windowData;
};
class _PolyExport TimeInfo {
public:
TimeInfo();
int seconds;
int minutes;
int hours;
int month;
int monthDay;
int weekDay;
int year;
int yearDay;
};
/**
* The main core of the framework. The core deals with system-level functions, such as window initialization and OS interaction. Each platform has its own implementation of this base class. NOTE: SOME OF THE FUNCTIONALITY IN THE CORE IS NOT FULLY IMPLEMENTED!!
*/
class _PolyExport Core : public EventDispatcher {
public:
/**
* Constructor.
* @param xRes Inital horizontal resolution of the renderer.
* @param yRes Inital vertical resolution of the renderer.
* @param fullScreen True to launch in fullscreen, false to launch in window.
* @param aaLevel Level of anti-aliasing. Possible values are 2,4 and 6.
* @param frameRate Frame rate that the core will update and render at.
* @param monitorIndex If fullScreen is true, the monitor index to fullscreen to. Pass -1 to use primary monitor.
*/
Core(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex);
virtual ~Core();
bool Update();
virtual void Render() = 0;
bool fixedUpdate();
virtual bool systemUpdate() = 0;
bool updateAndRender();
/**
* Show or hide cursor.
* @param newval True to show mouse, false to hide it.
*/
virtual void enableMouse(bool newval);
/**
* Capture the mouse.
*
* The mouse will be unable to exit the polycode screen.
*
* @param newval True to capture the mouse, false to uncapture it.
*/
virtual void captureMouse(bool newval);
/**
* Sets the cursor the application is using.
* @param cursorType Type of cursor to use. Possible values are CURSOR_ARROW, CURSOR_TEXT, CURSOR_POINTER, CURSOR_CROSSHAIR, CURSOR_RESIZE_LEFT_RIGHT, CURSOR_RESIZE_UP_DOWN
*/
virtual void setCursor(int cursorType) = 0;
/**
* Warps the cursor to a specified point in the window.
* @param x New cursor x position
* @param y New cursor y position
*/
virtual void warpCursor(int x, int y) {}
/**
* Launches a Threaded class into its own thread. See the documentation for Threaded for information on how to crated threaded classes.
* @param target Target threaded class.
* @see Threaded
*/
virtual void createThread(Threaded *target);
/**
* Locks a mutex.
* @param mutex Mutex to lock.
*/
virtual void lockMutex(CoreMutex *mutex) = 0;
/**
* Unlocks a mutex.
* @param mutex Mutex to lock.
*/
virtual void unlockMutex(CoreMutex *mutex) = 0;
/**
* Creates a mutex
* @return Newly created mutex.
*/
virtual CoreMutex *createMutex() = 0;
/**
* Copies the specified string to system clipboard.
* @param str String to copy to clipboard.
*/
virtual void copyStringToClipboard(const String& str) = 0;
/**
* Returns the system clipboard as a string.
* @return String from clipboard.
*/
virtual String getClipboardString() = 0;
/**
* Returns the core services. See CoreServices for a detailed explanation of services.
* @return Core services.
@see CoreServices
*/
CoreServices *getServices();
/**
* Returns the current average frames per second.
* @return Current average frames per second.
*/
Number getFPS();
/**
* Shuts down the core and quits the application.
*/
void Shutdown();
/**
* Checks if core is in fullscreen mode.
* @return True if in full screen, false if otherwise.
*/
bool isFullscreen(){ return fullScreen; }
/**
* Returns the current anti-aliasing level.
* @return Current anti-aliasing level.
*/
int getAALevel() { return aaLevel; }
/**
* Returns the input class. See CoreInput for details in input.
* @return Input class.
* @see CoreInput
*/
CoreInput *getInput();
/**
* Returns current horizontal resolution.
* @return Current horizontal resolution.
*/
Number getXRes();
/**
* Returns current vertical resolution.
* @return Current vertical resolution.
*/
Number getYRes();
/**
* Returns actual current horizontal resolution.
* @return Current actual horizontal resolution.
*/
virtual Number getBackingXRes() { return getXRes(); }
/**
* Returns actual current vertical resolution.
* @return Current actual horizontal resolution.
*/
virtual Number getBackingYRes() { return getYRes(); }
/**
* Provides the current width, height, and refresh rate of the screen.
* @param width If non-NULL, current screen width will be written here (or 0 if unknown).
* @param hight If non-NULL, current screen height will be written here (or 0 if unknown).
* @param hz If non-NULL, current screen refresh rate will be written here (or 0 if unknown).
*/
static void getScreenInfo(int *width, int *height, int *hz);
int getScreenWidth();
int getScreenHeight();
/**
* Creates a folder on disk with the specified path.
* @param folderPath Path to create the folder in.
*/
virtual void createFolder(const String& folderPath) = 0;
/**
* Copies a disk item from one path to another
* @param itemPath Path to the item to copy.
* @param destItemPath Destination path to copy to.
*/
virtual void copyDiskItem(const String& itemPath, const String& destItemPath) = 0;
/**
* Moves a disk item from one path to another
* @param itemPath Path to the item to move.
* @param destItemPath Destination path to move to.
*/
virtual void moveDiskItem(const String& itemPath, const String& destItemPath) = 0;
/**
* Removes a disk item.
* @param itemPath Path to the item to remove.
*/
virtual void removeDiskItem(const String& itemPath) = 0;
/**
* Opens a system folder picker and suspends operation.
* @return The selected path returned from the picker.
*/
virtual String openFolderPicker() = 0;
void setFramerate(int frameRate, int maxFixedCycles = 8);
/**
* Opens a system file picker for the specified extensions.
* @param extensions An STL vector containing the allowed file extensions that can be selected.
* @param allowMultiple If set to true, the picker can select multiple files.
* @return An STL vector of the selected file paths.
*/
virtual std::vector<String> openFilePicker(std::vector<CoreFileExtension> extensions, bool allowMultiple) = 0;
virtual String saveFilePicker(std::vector<CoreFileExtension> extensions) = 0;
/**
* Sets a new video mode.
* @param xRes New horizontal resolution of the renderer.
* @param yRes New vertical resolution of the renderer.
* @param fullScreen True to launch in fullscreen, false to launch in window.
* @param aaLevel Level of anti-aliasing. Possible values are 2,4 and 6.
*/
virtual void setVideoMode(int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, bool retinaSupport=true) = 0;
/**
* Resizes the renderer.
* @param xRes New horizontal resolution of the renderer.
* @param yRes New vertical resolution of the renderer.
*/
virtual void resizeTo(int xRes, int yRes) = 0;
void doSleep();
/**
* Launches the default browser and directs it to specified URL
* @param url URL to launch.
*/
virtual void openURL(String url) = 0;
/**
* Returns the time elapsed since last frame.
* @return Time elapsed since last frame in floating point microseconds.
*/
Number getElapsed();
/**
* Returns the total ticks elapsed since launch.
* @return Time elapsed since launch in milliseconds
*/
virtual unsigned int getTicks() = 0;
/** Returns the target number of milliseconds between frames */
long getRefreshIntervalMs() const {
return refreshInterval;
}
long getTimeSleptMs() const {
return timeSleptMs;
}
Number getFixedTimestep();
/**
* Returns the total ticks elapsed since launch.
* @return Time elapsed since launch in floating point seconds.
*/
double getTicksFloat();
void setUserPointer(void *ptr) { userPointer = ptr; }
void *getUserPointer() { return userPointer; }
static const int EVENTBASE_CORE = 0x200;
static const int EVENT_CORE_RESIZE = EVENTBASE_CORE+0;
static const int EVENT_LOST_FOCUS = EVENTBASE_CORE+1;
static const int EVENT_GAINED_FOCUS = EVENTBASE_CORE+2;
static const int EVENT_UNDO = EVENTBASE_CORE+3;
static const int EVENT_REDO = EVENTBASE_CORE+4;
static const int EVENT_COPY = EVENTBASE_CORE+5;
static const int EVENT_CUT = EVENTBASE_CORE+6;
static const int EVENT_SELECT_ALL = EVENTBASE_CORE+7;
static const int EVENT_PASTE = EVENTBASE_CORE+8;
virtual String executeExternalCommand(String command, String args, String inDirectory) = 0;
/**
* Returns the default working path of the application.
*/
String getDefaultWorkingDirectory();
/**
* Returns the default working path of the application.
*/
String getUserHomeDirectory();
/**
* Brings the application on top (Cocoa only for now).
*/
virtual void makeApplicationMain() {}
CoreMutex *getEventMutex();
CoreMutex *eventMutex;
void removeThread(Threaded *thread);
static const int CURSOR_ARROW = 0;
static const int CURSOR_TEXT = 1;
static const int CURSOR_POINTER = 2;
static const int CURSOR_CROSSHAIR = 3;
static const int CURSOR_RESIZE_LEFT_RIGHT = 4;
static const int CURSOR_RESIZE_UP_DOWN = 5;
static const int CURSOR_OPEN_HAND = 6;
bool paused;
bool pauseOnLoseFocus;
/**
* Default width of the desktop screen
*/
int defaultScreenWidth;
/**
* Default height of the desktop screen
*/
int defaultScreenHeight;
protected:
virtual bool checkSpecialKeyEvents(PolyKEY key) { return false; }
void loseFocus();
void gainFocus();
String userHomeDirectory;
String defaultWorkingDirectory;
void *userPointer;
//used for pausing workaround..
int frameRate;
long refreshInterval;
unsigned int timeSleptMs;
bool fullScreen;
int aaLevel;
std::vector<Vector2> videoModes;
void updateCore();
int numVideoModes;
bool running;
Number fps;
unsigned int frameTicks;
unsigned int lastFrameTicks;
unsigned int lastFPSTicks;
unsigned int elapsed;
double fixedElapsed;
double fixedTimestep;
double timeLeftOver;
double maxFixedElapsed;
bool mouseEnabled;
bool mouseCaptured;
unsigned int lastSleepFrameTicks;
std::vector<Threaded*> threads;
CoreMutex *threadedEventMutex;
int xRes;
int yRes;
int monitorIndex;
int frames;
CoreInput *input;
Renderer *renderer;
CoreServices *services;
};
}