From eb37622b15f34c3b53fa1ea8916812ae4d08d3e1 Mon Sep 17 00:00:00 2001 From: XProger Date: Thu, 3 Nov 2016 22:11:03 +0300 Subject: [PATCH] #15 tabs & includes fix --- src/core.h | 1 + src/platform/osx/main.cpp | 118 +++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 59 deletions(-) diff --git a/src/core.h b/src/core.h index 0683b31f..da74f6ae 100644 --- a/src/core.h +++ b/src/core.h @@ -13,6 +13,7 @@ #include #elif __APPLE__ #include + #include #include #include #include diff --git a/src/platform/osx/main.cpp b/src/platform/osx/main.cpp index 337b3b45..eb6bd330 100644 --- a/src/platform/osx/main.cpp +++ b/src/platform/osx/main.cpp @@ -1,12 +1,10 @@ #include "game.h" -#include -#include bool isQuit = false; WindowRef window; AGLContext context; -#define SND_SIZE 8192 // можно и 4096, что в 2 раза сократит latency, но в симуляторе будут слышны щелчки +#define SND_SIZE 8192 static AudioQueueRef audioQueue; @@ -16,19 +14,20 @@ void soundFill(void* inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffe Sound::fill((Sound::Frame*)frames, count); inBuffer->mAudioDataByteSize = count * 4; AudioQueueEnqueueBuffer(audioQueue, inBuffer, 0, NULL); + // TODO: mutex } void soundInit() { AudioStreamBasicDescription deviceFormat; - deviceFormat.mSampleRate = 44100; - deviceFormat.mFormatID = kAudioFormatLinearPCM; - deviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger; - deviceFormat.mBytesPerPacket = 4; - deviceFormat.mFramesPerPacket = 1; - deviceFormat.mBytesPerFrame = 4; - deviceFormat.mChannelsPerFrame = 2; - deviceFormat.mBitsPerChannel = 16; - deviceFormat.mReserved = 0; + deviceFormat.mSampleRate = 44100; + deviceFormat.mFormatID = kAudioFormatLinearPCM; + deviceFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger; + deviceFormat.mBytesPerPacket = 4; + deviceFormat.mFramesPerPacket = 1; + deviceFormat.mBytesPerFrame = 4; + deviceFormat.mChannelsPerFrame = 2; + deviceFormat.mBitsPerChannel = 16; + deviceFormat.mReserved = 0; AudioQueueNewOutput(&deviceFormat, soundFill, NULL, NULL, NULL, 0, &audioQueue); @@ -65,11 +64,11 @@ InputKey mouseToInputKey(int btn) { } OSStatus eventHandler(EventHandlerCallRef handler, EventRef event, void* userData) { - OSType eventClass = GetEventClass(event); - UInt32 eventKind = GetEventKind(event); + OSType eventClass = GetEventClass(event); + UInt32 eventKind = GetEventKind(event); - switch (eventClass) { - case kEventClassWindow : + switch (eventClass) { + case kEventClassWindow : switch (eventKind) { case kEventWindowClosed : isQuit = true; @@ -84,35 +83,35 @@ OSStatus eventHandler(EventHandlerCallRef handler, EventRef event, void* userDat } } break; - + case kEventClassMouse : { - EventMouseButton mouseButton; - CGPoint mousePos; - Rect wndRect; - - GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(mousePos), NULL, &mousePos); - GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(mouseButton), nil, &mouseButton); - - GetWindowBounds(window, kWindowContentRgn, &wndRect); - mousePos.x -= wndRect.left; - mousePos.y -= wndRect.top; + EventMouseButton mouseButton; + CGPoint mousePos; + Rect wndRect; + + GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(mousePos), NULL, &mousePos); + GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL, sizeof(mouseButton), nil, &mouseButton); + + GetWindowBounds(window, kWindowContentRgn, &wndRect); + mousePos.x -= wndRect.left; + mousePos.y -= wndRect.top; vec2 pos(mousePos.x, mousePos.y); - switch (eventKind) { - case kEventMouseDown : - case kEventMouseUp : { + switch (eventKind) { + case kEventMouseDown : + case kEventMouseUp : { InputKey key = mouseToInputKey(mouseButton); Input::setPos(key, pos); Input::setDown(key, eventKind == kEventMouseDown); - break; + break; } - case kEventMouseDragged : - Input::setPos(ikMouseL, pos); - break; - } - break; + case kEventMouseDragged : + Input::setPos(ikMouseL, pos); + break; + } + break; } - + case kEventClassKeyboard : { switch (eventKind) { case kEventRawKeyDown : @@ -134,22 +133,22 @@ OSStatus eventHandler(EventHandlerCallRef handler, EventRef event, void* userDat } break; } - } - - return CallNextEventHandler(handler, event); + } + + return CallNextEventHandler(handler, event); } int getTime() { - UInt64 t; - Microseconds((UnsignedWide*)&t); - return int(t / 1000); + UInt64 t; + Microseconds((UnsignedWide*)&t); + return int(t / 1000); } char *contentPath; int main() { // init window - Rect rect = {0, 0, 720, 1280}; + Rect rect = {0, 0, 720, 1280}; CreateNewWindow(kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowFullZoomAttribute | kWindowResizableAttribute | kWindowStandardHandlerAttribute, &rect, &window); SetWTitle(window, "\pOpenLara"); @@ -157,9 +156,9 @@ int main() { GLint attribs[] = { AGL_RGBA, AGL_DOUBLEBUFFER, - AGL_BUFFER_SIZE, 32, - AGL_DEPTH_SIZE, 24, - AGL_STENCIL_SIZE, 8, + AGL_BUFFER_SIZE, 32, + AGL_DEPTH_SIZE, 24, + AGL_STENCIL_SIZE, 8, AGL_NONE }; AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, (GLint*)&attribs); @@ -170,12 +169,12 @@ int main() { aglSetCurrentContext(context); // get path to game content - CFBundleRef bundle = CFBundleGetMainBundle(); - CFURLRef bundleURL = CFBundleCopyBundleURL(bundle); - CFStringRef pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); + CFBundleRef bundle = CFBundleGetMainBundle(); + CFURLRef bundleURL = CFBundleCopyBundleURL(bundle); + CFStringRef pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); contentPath = new char[1024]; - CFStringGetFileSystemRepresentation(pathStr, contentPath, 1024); - strcat(contentPath, "/Contents/Resources/"); + CFStringGetFileSystemRepresentation(pathStr, contentPath, 1024); + strcat(contentPath, "/Contents/Resources/"); soundInit(); Game::init(); @@ -198,8 +197,8 @@ int main() { int lastTime = getTime(), fpsTime = lastTime + 1000, fps = 0; - EventRecord event; - while (!isQuit) + EventRecord event; + while (!isQuit) if (!GetNextEvent(0xffff, &event)) { int time = getTime(); if (time <= lastTime) @@ -225,12 +224,13 @@ int main() { } else fps++; } - - Game::free(); + + Game::free(); delete[] contentPath; + // TODO: sndFree aglSetCurrentContext(NULL); - ReleaseWindow(window); - - return 0; + ReleaseWindow(window); + + return 0; }