|
|
@@ -4,7 +4,7 @@
|
|
|
#include "Platform.h"
|
|
|
#include "FileSystem.h"
|
|
|
#include "Game.h"
|
|
|
-
|
|
|
+#include "Form.h"
|
|
|
#include <unistd.h>
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
@@ -15,10 +15,10 @@
|
|
|
using namespace std;
|
|
|
using namespace gameplay;
|
|
|
|
|
|
-// Default to 720p
|
|
|
-#define WINDOW_WIDTH 1280
|
|
|
-#define WINDOW_HEIGHT 720
|
|
|
-
|
|
|
+// Default to 720p
|
|
|
+#define WINDOW_WIDTH 1280
|
|
|
+#define WINDOW_HEIGHT 720
|
|
|
+
|
|
|
static const float ACCELEROMETER_X_FACTOR = 90.0f / WINDOW_WIDTH;
|
|
|
static const float ACCELEROMETER_Y_FACTOR = 90.0f / WINDOW_HEIGHT;
|
|
|
|
|
|
@@ -32,7 +32,7 @@ static int __ly;
|
|
|
static bool __hasMouse = false;
|
|
|
static bool __leftMouseDown = false;
|
|
|
static bool __rightMouseDown = false;
|
|
|
-static bool __otherMouseDown = false;
|
|
|
+static bool __otherMouseDown = false;
|
|
|
static bool __shiftDown = false;
|
|
|
|
|
|
long getMachTimeInMilliseconds()
|
|
|
@@ -109,7 +109,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
|
|
|
- (id) initWithFrame: (NSRect) frame
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
NSOpenGLPixelFormatAttribute attrs[] =
|
|
|
{
|
|
|
NSOpenGLPFAAccelerated,
|
|
|
@@ -125,12 +125,12 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
if (!pf)
|
|
|
NSLog(@"OpenGL pixel format not supported.");
|
|
|
|
|
|
- if((self = [super initWithFrame:frame pixelFormat:[pf autorelease]]))
|
|
|
- {
|
|
|
- lock = [[NSRecursiveLock alloc] init];
|
|
|
- _game = Game::getInstance();
|
|
|
- __timeStart = getMachTimeInMilliseconds();
|
|
|
- }
|
|
|
+ if((self = [super initWithFrame:frame pixelFormat:[pf autorelease]]))
|
|
|
+ {
|
|
|
+ lock = [[NSRecursiveLock alloc] init];
|
|
|
+ _game = Game::getInstance();
|
|
|
+ __timeStart = getMachTimeInMilliseconds();
|
|
|
+ }
|
|
|
|
|
|
return self;
|
|
|
}
|
|
|
@@ -183,16 +183,16 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
[super dealloc];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-- (void) mouse: (Mouse::MouseEvent) mouseEvent orTouchEvent: (Touch::TouchEvent) touchEvent atX: (int) x y: (int) y s: (int) s
|
|
|
-{
|
|
|
- if (!Game::getInstance()->mouseEvent(mouseEvent, x, y, s))
|
|
|
- {
|
|
|
- Game::getInstance()->touchEvent(touchEvent, x, y, 0);
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
+
|
|
|
+- (void) mouse: (Mouse::MouseEvent) mouseEvent orTouchEvent: (Touch::TouchEvent) touchEvent atX: (int) x y: (int) y s: (int) s
|
|
|
+{
|
|
|
+ if (!Game::getInstance()->mouseEvent(mouseEvent, x, y, s))
|
|
|
+ {
|
|
|
+ Game::getInstance()->touchEvent(touchEvent, x, y, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
- (void) mouseDown: (NSEvent*) event
|
|
|
{
|
|
|
NSPoint point = [event locationInWindow];
|
|
|
@@ -220,12 +220,12 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
[self mouse: Mouse::MOUSE_RELEASE_LEFT_BUTTON orTouchEvent: Touch::TOUCH_RELEASE atX: point.x y: WINDOW_HEIGHT - point.y s: 0];
|
|
|
}
|
|
|
|
|
|
-- (void)mouseMoved:(NSEvent *) event
|
|
|
-{
|
|
|
- NSPoint point = [event locationInWindow];
|
|
|
- Game::getInstance()->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
-}
|
|
|
-
|
|
|
+- (void)mouseMoved:(NSEvent *) event
|
|
|
+{
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+}
|
|
|
+
|
|
|
- (void) mouseDragged: (NSEvent*) event
|
|
|
{
|
|
|
NSPoint point = [event locationInWindow];
|
|
|
@@ -240,15 +240,15 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
__rightMouseDown = true;
|
|
|
NSPoint point = [event locationInWindow];
|
|
|
__lx = point.x;
|
|
|
- __ly = WINDOW_HEIGHT - point.y;
|
|
|
- _game->mouseEvent(Mouse::MOUSE_PRESS_RIGHT_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+ __ly = WINDOW_HEIGHT - point.y;
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_PRESS_RIGHT_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
}
|
|
|
|
|
|
- (void) rightMouseUp: (NSEvent*) event
|
|
|
{
|
|
|
__rightMouseDown = false;
|
|
|
- NSPoint point = [event locationInWindow];
|
|
|
- _game->mouseEvent(Mouse::MOUSE_RELEASE_RIGHT_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_RELEASE_RIGHT_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
}
|
|
|
|
|
|
- (void) rightMouseDragged: (NSEvent*) event
|
|
|
@@ -268,48 +268,48 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
|
|
__lx = point.x;
|
|
|
__ly = (WINDOW_HEIGHT - point.y);
|
|
|
}
|
|
|
-
|
|
|
- // In right-mouse case, whether __rightMouseDown is true or false
|
|
|
- // this should not matter, mouse move is still occuring
|
|
|
- _game->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
-}
|
|
|
-
|
|
|
-- (void)otherMouseDown: (NSEvent *) event
|
|
|
-{
|
|
|
- __otherMouseDown = true;
|
|
|
- NSPoint point = [event locationInWindow];
|
|
|
- _game->mouseEvent(Mouse::MOUSE_PRESS_MIDDLE_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
-}
|
|
|
-
|
|
|
-- (void)otherMouseUp: (NSEvent *) event
|
|
|
-{
|
|
|
- __otherMouseDown = false;
|
|
|
- NSPoint point = [event locationInWindow];
|
|
|
- _game->mouseEvent(Mouse::MOUSE_RELEASE_MIDDLE_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
-}
|
|
|
-
|
|
|
-- (void)otherMouseDragged: (NSEvent *) event
|
|
|
-{
|
|
|
- NSPoint point = [event locationInWindow];
|
|
|
- _game->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
-}
|
|
|
-
|
|
|
+
|
|
|
+ // In right-mouse case, whether __rightMouseDown is true or false
|
|
|
+ // this should not matter, mouse move is still occuring
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+}
|
|
|
+
|
|
|
+- (void)otherMouseDown: (NSEvent *) event
|
|
|
+{
|
|
|
+ __otherMouseDown = true;
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_PRESS_MIDDLE_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+}
|
|
|
+
|
|
|
+- (void)otherMouseUp: (NSEvent *) event
|
|
|
+{
|
|
|
+ __otherMouseDown = false;
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_RELEASE_MIDDLE_BUTTON, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+}
|
|
|
+
|
|
|
+- (void)otherMouseDragged: (NSEvent *) event
|
|
|
+{
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ _game->mouseEvent(Mouse::MOUSE_MOVE, point.x, WINDOW_HEIGHT - point.y, 0);
|
|
|
+}
|
|
|
+
|
|
|
- (void) mouseEntered: (NSEvent*)event
|
|
|
{
|
|
|
__hasMouse = true;
|
|
|
}
|
|
|
|
|
|
-- (void)scrollWheel: (NSEvent *) event
|
|
|
-{
|
|
|
- NSPoint point = [event locationInWindow];
|
|
|
- Game::getInstance()->mouseEvent(Mouse::MOUSE_WHEEL, point.x, WINDOW_HEIGHT - point.y, (int)([event deltaY] * 10.0f));
|
|
|
-}
|
|
|
-
|
|
|
+- (void)scrollWheel: (NSEvent *) event
|
|
|
+{
|
|
|
+ NSPoint point = [event locationInWindow];
|
|
|
+ Game::getInstance()->mouseEvent(Mouse::MOUSE_WHEEL, point.x, WINDOW_HEIGHT - point.y, (int)([event deltaY] * 10.0f));
|
|
|
+}
|
|
|
+
|
|
|
- (void) mouseExited: (NSEvent*)event
|
|
|
{
|
|
|
__leftMouseDown = false;
|
|
|
__rightMouseDown = false;
|
|
|
- __otherMouseDown = false;
|
|
|
+ __otherMouseDown = false;
|
|
|
__hasMouse = false;
|
|
|
}
|
|
|
|
|
|
@@ -525,28 +525,28 @@ int getKey(unsigned short keyCode, unsigned int modifierFlags)
|
|
|
_game->keyEvent((flags & NSAlphaShiftKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_CAPS_LOCK);
|
|
|
break;
|
|
|
case 0x38:
|
|
|
- _game->keyEvent((flags & NSShiftKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_SHIFT);
|
|
|
+ _game->keyEvent((flags & NSShiftKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_SHIFT);
|
|
|
break;
|
|
|
case 0x3C:
|
|
|
- _game->keyEvent((flags & NSShiftKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_SHIFT);
|
|
|
+ _game->keyEvent((flags & NSShiftKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_SHIFT);
|
|
|
break;
|
|
|
case 0x3A:
|
|
|
- _game->keyEvent((flags & NSAlternateKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_ALT);
|
|
|
+ _game->keyEvent((flags & NSAlternateKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_ALT);
|
|
|
break;
|
|
|
case 0x3D:
|
|
|
- _game->keyEvent((flags & NSAlternateKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_ALT);
|
|
|
+ _game->keyEvent((flags & NSAlternateKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_ALT);
|
|
|
break;
|
|
|
case 0x3B:
|
|
|
- _game->keyEvent((flags & NSControlKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_CTRL);
|
|
|
+ _game->keyEvent((flags & NSControlKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_CTRL);
|
|
|
break;
|
|
|
case 0x3E:
|
|
|
- _game->keyEvent((flags & NSControlKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_CTRL);
|
|
|
+ _game->keyEvent((flags & NSControlKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_CTRL);
|
|
|
break;
|
|
|
case 0x37:
|
|
|
- _game->keyEvent((flags & NSCommandKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_HYPER);
|
|
|
+ _game->keyEvent((flags & NSCommandKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_HYPER);
|
|
|
break;
|
|
|
case 0x36:
|
|
|
- _game->keyEvent((flags & NSCommandKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_HYPER);
|
|
|
+ _game->keyEvent((flags & NSCommandKeyMask) ? Keyboard::KEY_PRESS : Keyboard::KEY_RELEASE, Keyboard::KEY_HYPER);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -600,7 +600,7 @@ Platform* Platform::create(Game* game)
|
|
|
int Platform::enterMessagePump()
|
|
|
{
|
|
|
NSAutoreleasePool* pool = [NSAutoreleasePool new];
|
|
|
- NSApplication* app = [NSApplication sharedApplication];
|
|
|
+ NSApplication* app = [NSApplication sharedApplication];
|
|
|
NSRect screenBounds = [[NSScreen mainScreen] frame];
|
|
|
NSRect viewBounds = NSMakeRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
|
|
|
|
|
@@ -617,27 +617,27 @@ int Platform::enterMessagePump()
|
|
|
backing:NSBackingStoreBuffered
|
|
|
defer:NO];
|
|
|
|
|
|
- [window setAcceptsMouseMovedEvents:YES];
|
|
|
+ [window setAcceptsMouseMovedEvents:YES];
|
|
|
[window setContentView:__view];
|
|
|
[window setDelegate:__view];
|
|
|
[__view release];
|
|
|
|
|
|
- [app run];
|
|
|
+ [app run];
|
|
|
|
|
|
[pool release];
|
|
|
return EXIT_SUCCESS;
|
|
|
}
|
|
|
-
|
|
|
-unsigned int Platform::getDisplayWidth()
|
|
|
-{
|
|
|
- return WINDOW_WIDTH;
|
|
|
-}
|
|
|
-
|
|
|
-unsigned int Platform::getDisplayHeight()
|
|
|
-{
|
|
|
- return WINDOW_HEIGHT;
|
|
|
-}
|
|
|
-
|
|
|
+
|
|
|
+unsigned int Platform::getDisplayWidth()
|
|
|
+{
|
|
|
+ return WINDOW_WIDTH;
|
|
|
+}
|
|
|
+
|
|
|
+unsigned int Platform::getDisplayHeight()
|
|
|
+{
|
|
|
+ return WINDOW_HEIGHT;
|
|
|
+}
|
|
|
+
|
|
|
long Platform::getAbsoluteTime()
|
|
|
{
|
|
|
__timeAbsolute = getMachTimeInMilliseconds();
|
|
|
@@ -680,18 +680,18 @@ void Platform::displayKeyboard(bool display)
|
|
|
{
|
|
|
// Do nothing.
|
|
|
}
|
|
|
-
|
|
|
-void Platform::touchEventInternal(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
|
|
|
-{
|
|
|
- if (!Form::touchEventInternal(evt, x, y, contactIndex))
|
|
|
- {
|
|
|
- Game::getInstance()->touchEvent(evt, x, y, contactIndex);
|
|
|
- }
|
|
|
+
|
|
|
+void Platform::touchEventInternal(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
|
|
|
+{
|
|
|
+ if (!Form::touchEventInternal(evt, x, y, contactIndex))
|
|
|
+ {
|
|
|
+ Game::getInstance()->touchEvent(evt, x, y, contactIndex);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-void Platform::sleep(long ms)
|
|
|
-{
|
|
|
- usleep(ms * 1000);
|
|
|
+void Platform::sleep(long ms)
|
|
|
+{
|
|
|
+ usleep(ms * 1000);
|
|
|
}
|
|
|
|
|
|
}
|