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