mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-12 08:04:09 +02:00
#15 osx cocoa PR preparation
This commit is contained in:
@@ -8,16 +8,18 @@
|
|||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
99713CC9204CAD9900006FAC /* tinflate.c in Sources */ = {isa = PBXBuildFile; fileRef = 99713CC8204CAD9900006FAC /* tinflate.c */; };
|
99713CC9204CAD9900006FAC /* tinflate.c in Sources */ = {isa = PBXBuildFile; fileRef = 99713CC8204CAD9900006FAC /* tinflate.c */; };
|
||||||
99BFB6A21DCA7F5300E2E997 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 99BFB6A11DCA7F5300E2E997 /* main.cpp */; };
|
523F97E41DDF7AA5006FE2FC /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 523F97E31DDF7AA5006FE2FC /* Cocoa.framework */; };
|
||||||
|
523F97E61DDF926E006FE2FC /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 523F97E51DDF926E006FE2FC /* QuartzCore.framework */; };
|
||||||
|
99BFB6A21DCA7F5300E2E997 /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = 99BFB6A11DCA7F5300E2E997 /* main.mm */; };
|
||||||
99BFB6A91DCA87BF00E2E997 /* stb_vorbis.c in Sources */ = {isa = PBXBuildFile; fileRef = 99BFB6A81DCA87BF00E2E997 /* stb_vorbis.c */; };
|
99BFB6A91DCA87BF00E2E997 /* stb_vorbis.c in Sources */ = {isa = PBXBuildFile; fileRef = 99BFB6A81DCA87BF00E2E997 /* stb_vorbis.c */; };
|
||||||
99BFB6AB1DCA87C500E2E997 /* minimp3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 99BFB6AA1DCA87C500E2E997 /* minimp3.cpp */; };
|
99BFB6AB1DCA87C500E2E997 /* minimp3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 99BFB6AA1DCA87C500E2E997 /* minimp3.cpp */; };
|
||||||
99C4C0B71796AB730032DE85 /* AGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99C4C0951796A9730032DE85 /* AGL.framework */; };
|
|
||||||
99C4C0B91796AB7B0032DE85 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99C4C0B81796AB7B0032DE85 /* Carbon.framework */; };
|
|
||||||
99C4C0BA1796AB810032DE85 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99C4C0931796A96F0032DE85 /* OpenGL.framework */; };
|
99C4C0BA1796AB810032DE85 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99C4C0931796A96F0032DE85 /* OpenGL.framework */; };
|
||||||
99DF7BC41DCBA30B00C40D0A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99DF7BC31DCBA30B00C40D0A /* AudioToolbox.framework */; };
|
99DF7BC41DCBA30B00C40D0A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99DF7BC31DCBA30B00C40D0A /* AudioToolbox.framework */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
523F97E31DDF7AA5006FE2FC /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
|
||||||
|
523F97E51DDF926E006FE2FC /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
|
||||||
995C97EF1E91A857003825B2 /* shaders */ = {isa = PBXFileReference; lastKnownFileType = folder; name = shaders; path = ../../shaders; sourceTree = "<group>"; };
|
995C97EF1E91A857003825B2 /* shaders */ = {isa = PBXFileReference; lastKnownFileType = folder; name = shaders; path = ../../shaders; sourceTree = "<group>"; };
|
||||||
99713CAE204CA3DA00006FAC /* animation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = animation.h; path = ../../animation.h; sourceTree = "<group>"; };
|
99713CAE204CA3DA00006FAC /* animation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = animation.h; path = ../../animation.h; sourceTree = "<group>"; };
|
||||||
99713CAF204CA3DA00006FAC /* cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cache.h; path = ../../cache.h; sourceTree = "<group>"; };
|
99713CAF204CA3DA00006FAC /* cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cache.h; path = ../../cache.h; sourceTree = "<group>"; };
|
||||||
@@ -64,10 +66,10 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
523F97E61DDF926E006FE2FC /* QuartzCore.framework in Frameworks */,
|
||||||
|
523F97E41DDF7AA5006FE2FC /* Cocoa.framework in Frameworks */,
|
||||||
99DF7BC41DCBA30B00C40D0A /* AudioToolbox.framework in Frameworks */,
|
99DF7BC41DCBA30B00C40D0A /* AudioToolbox.framework in Frameworks */,
|
||||||
99C4C0BA1796AB810032DE85 /* OpenGL.framework in Frameworks */,
|
99C4C0BA1796AB810032DE85 /* OpenGL.framework in Frameworks */,
|
||||||
99C4C0B91796AB7B0032DE85 /* Carbon.framework in Frameworks */,
|
|
||||||
99C4C0B71796AB730032DE85 /* AGL.framework in Frameworks */,
|
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -107,7 +109,25 @@
|
|||||||
99BFB6AA1DCA87C500E2E997 /* minimp3.cpp */,
|
99BFB6AA1DCA87C500E2E997 /* minimp3.cpp */,
|
||||||
99BFB6A81DCA87BF00E2E997 /* stb_vorbis.c */,
|
99BFB6A81DCA87BF00E2E997 /* stb_vorbis.c */,
|
||||||
99713CC8204CAD9900006FAC /* tinflate.c */,
|
99713CC8204CAD9900006FAC /* tinflate.c */,
|
||||||
99BFB6A11DCA7F5300E2E997 /* main.cpp */,
|
99BFB69E1DCA7F1700E2E997 /* libs */,
|
||||||
|
99BFB6A11DCA7F5300E2E997 /* main.mm */,
|
||||||
|
99BFB68D1DCA7F1700E2E997 /* lara.h */,
|
||||||
|
99BFB68E1DCA7F1700E2E997 /* format.h */,
|
||||||
|
99BFB68F1DCA7F1700E2E997 /* level.h */,
|
||||||
|
99BFB6901DCA7F1700E2E997 /* mesh.h */,
|
||||||
|
99BFB6911DCA7F1700E2E997 /* debug.h */,
|
||||||
|
99BFB6921DCA7F1700E2E997 /* controller.h */,
|
||||||
|
99BFB6931DCA7F1700E2E997 /* utils.h */,
|
||||||
|
99BFB6941DCA7F1700E2E997 /* sound.h */,
|
||||||
|
99BFB6951DCA7F1700E2E997 /* camera.h */,
|
||||||
|
99BFB6961DCA7F1700E2E997 /* core.h */,
|
||||||
|
99BFB6971DCA7F1700E2E997 /* trigger.h */,
|
||||||
|
99BFB6981DCA7F1700E2E997 /* shader.h */,
|
||||||
|
99BFB6991DCA7F1700E2E997 /* shader.glsl */,
|
||||||
|
99BFB69A1DCA7F1700E2E997 /* input.h */,
|
||||||
|
99BFB69B1DCA7F1700E2E997 /* enemy.h */,
|
||||||
|
99BFB69C1DCA7F1700E2E997 /* game.h */,
|
||||||
|
99BFB69D1DCA7F1700E2E997 /* texture.h */,
|
||||||
99C4C0A31796AACF0032DE85 /* Supporting Files */,
|
99C4C0A31796AACF0032DE85 /* Supporting Files */,
|
||||||
99C4C0821796A8230032DE85 /* Frameworks */,
|
99C4C0821796A8230032DE85 /* Frameworks */,
|
||||||
99C4C0811796A8230032DE85 /* Products */,
|
99C4C0811796A8230032DE85 /* Products */,
|
||||||
@@ -125,6 +145,8 @@
|
|||||||
99C4C0821796A8230032DE85 /* Frameworks */ = {
|
99C4C0821796A8230032DE85 /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
523F97E51DDF926E006FE2FC /* QuartzCore.framework */,
|
||||||
|
523F97E31DDF7AA5006FE2FC /* Cocoa.framework */,
|
||||||
99DF7BC31DCBA30B00C40D0A /* AudioToolbox.framework */,
|
99DF7BC31DCBA30B00C40D0A /* AudioToolbox.framework */,
|
||||||
99DF7BC11DCBA2D100C40D0A /* CoreAudioKit.framework */,
|
99DF7BC11DCBA2D100C40D0A /* CoreAudioKit.framework */,
|
||||||
99DF7BBF1DCBA2BF00C40D0A /* CoreAudio.framework */,
|
99DF7BBF1DCBA2BF00C40D0A /* CoreAudio.framework */,
|
||||||
@@ -207,7 +229,7 @@
|
|||||||
files = (
|
files = (
|
||||||
99713CC9204CAD9900006FAC /* tinflate.c in Sources */,
|
99713CC9204CAD9900006FAC /* tinflate.c in Sources */,
|
||||||
99BFB6AB1DCA87C500E2E997 /* minimp3.cpp in Sources */,
|
99BFB6AB1DCA87C500E2E997 /* minimp3.cpp in Sources */,
|
||||||
99BFB6A21DCA7F5300E2E997 /* main.cpp in Sources */,
|
99BFB6A21DCA7F5300E2E997 /* main.mm in Sources */,
|
||||||
99BFB6A91DCA87BF00E2E997 /* stb_vorbis.c in Sources */,
|
99BFB6A91DCA87BF00E2E997 /* stb_vorbis.c in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
@@ -1,220 +0,0 @@
|
|||||||
#include <pthread.h>
|
|
||||||
#include "game.h"
|
|
||||||
|
|
||||||
WindowRef window;
|
|
||||||
AGLContext context;
|
|
||||||
|
|
||||||
// sound
|
|
||||||
#define SND_SIZE 8192
|
|
||||||
|
|
||||||
static AudioQueueRef audioQueue;
|
|
||||||
|
|
||||||
void soundFill(void* inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) {
|
|
||||||
void* frames = inBuffer->mAudioData;
|
|
||||||
UInt32 count = inBuffer->mAudioDataBytesCapacity / 4;
|
|
||||||
Sound::fill((Sound::Frame*)frames, count);
|
|
||||||
inBuffer->mAudioDataByteSize = count * 4;
|
|
||||||
AudioQueueEnqueueBuffer(audioQueue, inBuffer, 0, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
AudioQueueNewOutput(&deviceFormat, soundFill, NULL, NULL, NULL, 0, &audioQueue);
|
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
AudioQueueBufferRef mBuffer;
|
|
||||||
AudioQueueAllocateBuffer(audioQueue, SND_SIZE, &mBuffer);
|
|
||||||
soundFill(NULL, audioQueue, mBuffer);
|
|
||||||
}
|
|
||||||
AudioQueueStart(audioQueue, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// common input functions
|
|
||||||
InputKey keyToInputKey(int code) {
|
|
||||||
static const int codes[] = {
|
|
||||||
0x7B, 0x7C, 0x7E, 0x7D, 0x31, 0x30, 0x24, 0x35, 0x38, 0x3B, 0x3A,
|
|
||||||
0x1D, 0x12, 0x13, 0x14, 0x15, 0x17, 0x16, 0x1A, 0x1C, 0x19, // 0..9
|
|
||||||
0x00, 0x0B, 0x08, 0x02, 0x0E, 0x03, 0x05, 0x04, 0x22, 0x26, 0x28, 0x25, 0x2E, // A..M
|
|
||||||
0x2D, 0x1F, 0x23, 0x0C, 0x0F, 0x01, 0x11, 0x20, 0x09, 0x0D, 0x07, 0x10, 0x06, // N..Z
|
|
||||||
};
|
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(codes) / sizeof(codes[0]); i++)
|
|
||||||
if (codes[i] == code)
|
|
||||||
return (InputKey)(ikLeft + i);
|
|
||||||
return ikNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
InputKey mouseToInputKey(int btn) {
|
|
||||||
switch (btn) {
|
|
||||||
case 1 : return ikMouseL;
|
|
||||||
case 2 : return ikMouseR;
|
|
||||||
case 3 : return ikMouseM;
|
|
||||||
}
|
|
||||||
return ikNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool osJoyReady(int index) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void osJoyVibrate(int index, float L, float R) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
OSStatus eventHandler(EventHandlerCallRef handler, EventRef event, void* userData) {
|
|
||||||
OSType eventClass = GetEventClass(event);
|
|
||||||
UInt32 eventKind = GetEventKind(event);
|
|
||||||
|
|
||||||
switch (eventClass) {
|
|
||||||
case kEventClassWindow :
|
|
||||||
switch (eventKind) {
|
|
||||||
case kEventWindowClosed :
|
|
||||||
Core::quit();
|
|
||||||
break;
|
|
||||||
case kEventWindowBoundsChanged : {
|
|
||||||
aglUpdateContext(context);
|
|
||||||
Rect rect;
|
|
||||||
GetWindowPortBounds(window, &rect);
|
|
||||||
Core::width = rect.right - rect.left;
|
|
||||||
Core::height = rect.bottom - rect.top;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
vec2 pos(mousePos.x, mousePos.y);
|
|
||||||
|
|
||||||
switch (eventKind) {
|
|
||||||
case kEventMouseDown :
|
|
||||||
case kEventMouseUp : {
|
|
||||||
InputKey key = mouseToInputKey(mouseButton);
|
|
||||||
Input::setPos(key, pos);
|
|
||||||
Input::setDown(key, eventKind == kEventMouseDown);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kEventMouseDragged :
|
|
||||||
Input::setPos(ikMouseL, pos);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case kEventClassKeyboard : {
|
|
||||||
switch (eventKind) {
|
|
||||||
case kEventRawKeyDown :
|
|
||||||
case kEventRawKeyUp : {
|
|
||||||
uint32 keyCode;
|
|
||||||
if (GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(keyCode), NULL, &keyCode) == noErr)
|
|
||||||
Input::setDown(keyToInputKey(keyCode), eventKind != kEventRawKeyUp);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case kEventRawKeyModifiersChanged : {
|
|
||||||
uint32 modifiers;
|
|
||||||
if (GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(modifiers), NULL, &modifiers) == noErr) {
|
|
||||||
Input::setDown(ikShift, modifiers & shiftKey);
|
|
||||||
Input::setDown(ikCtrl, modifiers & controlKey);
|
|
||||||
Input::setDown(ikAlt, modifiers & optionKey);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return CallNextEventHandler(handler, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
// timing
|
|
||||||
int osGetTime() {
|
|
||||||
UInt64 t;
|
|
||||||
Microseconds((UnsignedWide*)&t);
|
|
||||||
return int(t / 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
cacheDir[0] = saveDir[0] = contentDir[0] = 0;
|
|
||||||
|
|
||||||
// get path to game content
|
|
||||||
CFBundleRef bundle = CFBundleGetMainBundle();
|
|
||||||
CFURLRef bundleURL = CFBundleCopyBundleURL(bundle);
|
|
||||||
CFStringRef pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
|
|
||||||
CFStringGetFileSystemRepresentation(pathStr, contentDir, 230);
|
|
||||||
strcat(contentDir, "/Contents/Resources/");
|
|
||||||
|
|
||||||
// init window
|
|
||||||
Rect rect = {0, 0, 720, 1280};
|
|
||||||
CreateNewWindow(kDocumentWindowClass, kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute | kWindowFullZoomAttribute | kWindowResizableAttribute | kWindowStandardHandlerAttribute, &rect, &window);
|
|
||||||
SetWTitle(window, "\pOpenLara");
|
|
||||||
|
|
||||||
// init OpenGL context
|
|
||||||
GLint attribs[] = {
|
|
||||||
AGL_RGBA,
|
|
||||||
AGL_DOUBLEBUFFER,
|
|
||||||
AGL_BUFFER_SIZE, 32,
|
|
||||||
AGL_DEPTH_SIZE, 24,
|
|
||||||
AGL_STENCIL_SIZE, 8,
|
|
||||||
AGL_NONE
|
|
||||||
};
|
|
||||||
AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, (GLint*)&attribs);
|
|
||||||
context = aglCreateContext(format, NULL);
|
|
||||||
aglDestroyPixelFormat(format);
|
|
||||||
|
|
||||||
aglSetDrawable(context, GetWindowPort(window));
|
|
||||||
aglSetCurrentContext(context);
|
|
||||||
|
|
||||||
soundInit();
|
|
||||||
Game::init();
|
|
||||||
|
|
||||||
// show window
|
|
||||||
const int events[][2] = {
|
|
||||||
{ kEventClassWindow, kEventWindowClosed },
|
|
||||||
{ kEventClassWindow, kEventWindowBoundsChanged },
|
|
||||||
{ kEventClassKeyboard, kEventRawKeyDown },
|
|
||||||
{ kEventClassKeyboard, kEventRawKeyUp },
|
|
||||||
{ kEventClassKeyboard, kEventRawKeyModifiersChanged },
|
|
||||||
{ kEventClassMouse, kEventMouseDown },
|
|
||||||
{ kEventClassMouse, kEventMouseUp },
|
|
||||||
{ kEventClassMouse, kEventMouseDragged },
|
|
||||||
};
|
|
||||||
|
|
||||||
InstallEventHandler(GetApplicationEventTarget(), (EventHandlerUPP)eventHandler, sizeof(events) / sizeof(events[0]), (EventTypeSpec*)&events, NULL, NULL);
|
|
||||||
SelectWindow(window);
|
|
||||||
ShowWindow(window);
|
|
||||||
|
|
||||||
EventRecord event;
|
|
||||||
while (!Core::isQuit)
|
|
||||||
if (!GetNextEvent(0xffff, &event) && Game::update()) {
|
|
||||||
Game::render();
|
|
||||||
aglSwapBuffers(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
Game::deinit();
|
|
||||||
// TODO: sndFree
|
|
||||||
|
|
||||||
aglSetCurrentContext(NULL);
|
|
||||||
ReleaseWindow(window);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Reference in New Issue
Block a user