summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/SCsub1
-rw-r--r--platform/osx/audio_driver_osx.cpp301
-rw-r--r--platform/osx/audio_driver_osx.h85
-rw-r--r--platform/osx/detect.py4
-rw-r--r--platform/osx/export/export.cpp10
-rw-r--r--platform/osx/os_osx.h11
-rw-r--r--platform/osx/os_osx.mm105
7 files changed, 89 insertions, 428 deletions
diff --git a/platform/osx/SCsub b/platform/osx/SCsub
index 27bffbe80e..be3950bc6d 100644
--- a/platform/osx/SCsub
+++ b/platform/osx/SCsub
@@ -10,7 +10,6 @@ files = [
'crash_handler_osx.mm',
'os_osx.mm',
'godot_main_osx.mm',
- 'audio_driver_osx.cpp',
'sem_osx.cpp',
'dir_access_osx.mm',
'joypad_osx.cpp',
diff --git a/platform/osx/audio_driver_osx.cpp b/platform/osx/audio_driver_osx.cpp
deleted file mode 100644
index 3b3ba60507..0000000000
--- a/platform/osx/audio_driver_osx.cpp
+++ /dev/null
@@ -1,301 +0,0 @@
-/*************************************************************************/
-/* audio_driver_osx.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* 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. */
-/*************************************************************************/
-#ifdef OSX_ENABLED
-
-#include "audio_driver_osx.h"
-#include "core/project_settings.h"
-#include "os/os.h"
-
-#define kOutputBus 0
-
-static OSStatus outputDeviceAddressCB(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress *inAddresses, void *__nullable inClientData) {
- AudioDriverOSX *driver = (AudioDriverOSX *)inClientData;
-
- driver->reopen();
-
- return noErr;
-}
-
-Error AudioDriverOSX::initDevice() {
- AudioComponentDescription desc;
- zeromem(&desc, sizeof(desc));
- desc.componentType = kAudioUnitType_Output;
- desc.componentSubType = kAudioUnitSubType_HALOutput;
- desc.componentManufacturer = kAudioUnitManufacturer_Apple;
-
- AudioComponent comp = AudioComponentFindNext(NULL, &desc);
- ERR_FAIL_COND_V(comp == NULL, FAILED);
-
- OSStatus result = AudioComponentInstanceNew(comp, &audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- AudioStreamBasicDescription strdesc;
-
- zeromem(&strdesc, sizeof(strdesc));
- UInt32 size = sizeof(strdesc);
- result = AudioUnitGetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, kOutputBus, &strdesc, &size);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- switch (strdesc.mChannelsPerFrame) {
- case 2: // Stereo
- case 4: // Surround 3.1
- case 6: // Surround 5.1
- case 8: // Surround 7.1
- channels = strdesc.mChannelsPerFrame;
- break;
-
- default:
- // Unknown number of channels, default to stereo
- channels = 2;
- break;
- }
-
- mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE);
-
- zeromem(&strdesc, sizeof(strdesc));
- strdesc.mFormatID = kAudioFormatLinearPCM;
- strdesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
- strdesc.mChannelsPerFrame = channels;
- strdesc.mSampleRate = mix_rate;
- strdesc.mFramesPerPacket = 1;
- strdesc.mBitsPerChannel = 16;
- strdesc.mBytesPerFrame = strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8;
- strdesc.mBytesPerPacket = strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
-
- result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &strdesc, sizeof(strdesc));
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- int latency = GLOBAL_DEF("audio/output_latency", DEFAULT_OUTPUT_LATENCY);
- // Sample rate is independent of channels (ref: https://stackoverflow.com/questions/11048825/audio-sample-frequency-rely-on-channels)
- buffer_frames = closest_power_of_2(latency * mix_rate / 1000);
-
- result = AudioUnitSetProperty(audio_unit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global, kOutputBus, &buffer_frames, sizeof(UInt32));
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- buffer_size = buffer_frames * channels;
- samples_in.resize(buffer_size);
-
- if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("CoreAudio: detected " + itos(channels) + " channels");
- print_line("CoreAudio: audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms");
- }
-
- AURenderCallbackStruct callback;
- zeromem(&callback, sizeof(AURenderCallbackStruct));
- callback.inputProc = &AudioDriverOSX::output_callback;
- callback.inputProcRefCon = this;
- result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback));
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- result = AudioUnitInitialize(audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- return OK;
-}
-
-Error AudioDriverOSX::finishDevice() {
- OSStatus result;
-
- if (active) {
- result = AudioOutputUnitStop(audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- active = false;
- }
-
- result = AudioUnitUninitialize(audio_unit);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- return OK;
-}
-
-Error AudioDriverOSX::init() {
- OSStatus result;
-
- mutex = Mutex::create();
- active = false;
- channels = 2;
-
- outputDeviceAddress.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
- outputDeviceAddress.mScope = kAudioObjectPropertyScopeGlobal;
- outputDeviceAddress.mElement = kAudioObjectPropertyElementMaster;
-
- result = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &outputDeviceAddress, &outputDeviceAddressCB, this);
- ERR_FAIL_COND_V(result != noErr, FAILED);
-
- return initDevice();
-};
-
-Error AudioDriverOSX::reopen() {
- bool restart = false;
-
- lock();
-
- if (active) {
- restart = true;
- }
-
- Error err = finishDevice();
- if (err != OK) {
- ERR_PRINT("finishDevice failed");
- unlock();
- return err;
- }
-
- err = initDevice();
- if (err != OK) {
- ERR_PRINT("initDevice failed");
- unlock();
- return err;
- }
-
- if (restart) {
- start();
- }
-
- unlock();
-
- return OK;
-}
-
-OSStatus AudioDriverOSX::output_callback(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber, UInt32 inNumberFrames,
- AudioBufferList *ioData) {
-
- AudioDriverOSX *ad = (AudioDriverOSX *)inRefCon;
-
- if (!ad->active || !ad->try_lock()) {
- for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) {
- AudioBuffer *abuf = &ioData->mBuffers[i];
- zeromem(abuf->mData, abuf->mDataByteSize);
- };
- return 0;
- };
-
- for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) {
-
- AudioBuffer *abuf = &ioData->mBuffers[i];
- int frames_left = inNumberFrames;
- int16_t *out = (int16_t *)abuf->mData;
-
- while (frames_left) {
-
- int frames = MIN(frames_left, ad->buffer_frames);
- ad->audio_server_process(frames, ad->samples_in.ptr());
-
- for (int j = 0; j < frames * ad->channels; j++) {
-
- out[j] = ad->samples_in[j] >> 16;
- }
-
- frames_left -= frames;
- out += frames * ad->channels;
- };
- };
-
- ad->unlock();
-
- return 0;
-};
-
-void AudioDriverOSX::start() {
- if (!active) {
- OSStatus result = AudioOutputUnitStart(audio_unit);
- if (result != noErr) {
- ERR_PRINT("AudioOutputUnitStart failed");
- } else {
- active = true;
- }
- }
-};
-
-int AudioDriverOSX::get_mix_rate() const {
- return mix_rate;
-};
-
-AudioDriver::SpeakerMode AudioDriverOSX::get_speaker_mode() const {
- return get_speaker_mode_by_total_channels(channels);
-};
-
-void AudioDriverOSX::lock() {
- if (mutex)
- mutex->lock();
-};
-
-void AudioDriverOSX::unlock() {
- if (mutex)
- mutex->unlock();
-};
-
-bool AudioDriverOSX::try_lock() {
- if (mutex)
- return mutex->try_lock() == OK;
- return true;
-}
-
-void AudioDriverOSX::finish() {
- finishDevice();
-
- OSStatus result = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &outputDeviceAddress, &outputDeviceAddressCB, this);
- if (result != noErr) {
- ERR_PRINT("AudioObjectRemovePropertyListener failed");
- }
-
- AURenderCallbackStruct callback;
- zeromem(&callback, sizeof(AURenderCallbackStruct));
- result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, kOutputBus, &callback, sizeof(callback));
- if (result != noErr) {
- ERR_PRINT("AudioUnitSetProperty failed");
- }
-
- if (mutex) {
- memdelete(mutex);
- mutex = NULL;
- }
-};
-
-AudioDriverOSX::AudioDriverOSX() {
- active = false;
- mutex = NULL;
-
- mix_rate = 0;
- channels = 2;
-
- buffer_size = 0;
- buffer_frames = 0;
-
- samples_in.clear();
-};
-
-AudioDriverOSX::~AudioDriverOSX(){};
-
-#endif
diff --git a/platform/osx/audio_driver_osx.h b/platform/osx/audio_driver_osx.h
deleted file mode 100644
index a7e68c8141..0000000000
--- a/platform/osx/audio_driver_osx.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*************************************************************************/
-/* audio_driver_osx.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* 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. */
-/*************************************************************************/
-#ifdef OSX_ENABLED
-
-#ifndef AUDIO_DRIVER_OSX_H
-#define AUDIO_DRIVER_OSX_H
-
-#include "servers/audio_server.h"
-
-#include <AudioUnit/AudioUnit.h>
-#include <CoreAudio/AudioHardware.h>
-
-class AudioDriverOSX : public AudioDriver {
-
- AudioComponentInstance audio_unit;
- AudioObjectPropertyAddress outputDeviceAddress;
- bool active;
- Mutex *mutex;
-
- int mix_rate;
- unsigned int channels;
- unsigned int buffer_frames;
- unsigned int buffer_size;
-
- Vector<int32_t> samples_in;
-
- static OSStatus output_callback(void *inRefCon,
- AudioUnitRenderActionFlags *ioActionFlags,
- const AudioTimeStamp *inTimeStamp,
- UInt32 inBusNumber, UInt32 inNumberFrames,
- AudioBufferList *ioData);
-
- Error initDevice();
- Error finishDevice();
-
-public:
- const char *get_name() const {
- return "AudioUnit";
- };
-
- virtual Error init();
- virtual void start();
- virtual int get_mix_rate() const;
- virtual SpeakerMode get_speaker_mode() const;
- virtual void lock();
- virtual void unlock();
- virtual void finish();
-
- bool try_lock();
- Error reopen();
-
- AudioDriverOSX();
- ~AudioDriverOSX();
-};
-
-#endif
-
-#endif
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index 51da000712..31032659b6 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -62,7 +62,7 @@ def configure(env):
## Compiler configuration
- if (not os.environ.has_key("OSXCROSS_ROOT")): # regular native build
+ if "OSXCROSS_ROOT" not in os.environ: # regular native build
if (env["bits"] == "fat"):
env.Append(CCFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
env.Append(LINKFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
@@ -103,7 +103,7 @@ def configure(env):
## Flags
env.Append(CPPPATH=['#platform/osx'])
- env.Append(CPPFLAGS=['-DOSX_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DAPPLE_STYLE_KEYS'])
+ env.Append(CPPFLAGS=['-DOSX_ENABLED', '-DUNIX_ENABLED', '-DGLES2_ENABLED', '-DAPPLE_STYLE_KEYS', '-DCOREAUDIO_ENABLED'])
env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback'])
env.Append(LIBS=['pthread'])
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index 2ec76fe0dd..0fd21d62ee 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -97,6 +97,16 @@ void EditorExportPlatformOSX::get_preset_features(const Ref<EditorExportPreset>
if (p_preset->get("texture_format/etc2")) {
r_features->push_back("etc2");
}
+
+ int bits = p_preset->get("application/bits_mode");
+
+ if (bits == 0 || bits == 1) {
+ r_features->push_back("64");
+ }
+
+ if (bits == 0 || bits == 2) {
+ r_features->push_back("32");
+ }
}
void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options) {
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 6c81da04f5..eb8c0566b4 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -31,13 +31,11 @@
#define OS_OSX_H
#include "crash_handler_osx.h"
-#include "drivers/alsa/audio_driver_alsa.h"
-#include "drivers/rtaudio/audio_driver_rtaudio.h"
+#include "drivers/coreaudio/audio_driver_coreaudio.h"
#include "drivers/unix/os_unix.h"
#include "joypad_osx.h"
#include "main/input_default.h"
#include "os/input.h"
-#include "platform/osx/audio_driver_osx.h"
#include "power_osx.h"
#include "servers/audio_server.h"
#include "servers/physics_2d/physics_2d_server_sw.h"
@@ -69,7 +67,7 @@ public:
IP_Unix *ip_unix;
- AudioDriverOSX audio_driver_osx;
+ AudioDriverCoreAudio audio_driver;
InputDefault *input;
JoypadOSX *joypad_osx;
@@ -129,6 +127,7 @@ protected:
virtual const char *get_video_driver_name(int p_driver) const;
virtual VideoMode get_default_video_mode() const;
+ virtual void initialize_logger();
virtual void initialize_core();
virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void finalize();
@@ -143,8 +142,6 @@ public:
virtual String get_name();
- virtual void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR);
-
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual void set_cursor_shape(CursorShape p_shape);
@@ -229,6 +226,8 @@ public:
void disable_crash_handler();
bool is_disable_crash_handler() const;
+ virtual Error move_to_trash(const String &p_path);
+
OS_OSX();
};
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 9a26adc155..8323aa84a8 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -1071,7 +1071,7 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
bool use_gl2 = p_video_driver != 1;
- AudioDriverManager::add_driver(&audio_driver_osx);
+ AudioDriverManager::add_driver(&audio_driver);
// only opengl support here...
RasterizerGLES3::register_config();
@@ -1145,43 +1145,67 @@ String OS_OSX::get_name() {
return "OSX";
}
-void OS_OSX::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
-
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
- if (!_print_error_enabled)
- return;
-
- const char *err_details;
- if (p_rationale && p_rationale[0])
- err_details = p_rationale;
- else
- err_details = p_code;
+class OSXTerminalLogger : public StdLogger {
+public:
+ virtual void log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR) {
+ if (!should_log(true)) {
+ return;
+ }
- switch (p_type) {
- case ERR_ERROR:
- os_log_error(OS_LOG_DEFAULT, "ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
- print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- print("\E[0;31m At: %s:%i.\E[0m\n", p_file, p_line);
- break;
- case ERR_WARNING:
- os_log_info(OS_LOG_DEFAULT, "WARNING: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
- print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n", p_function, err_details);
- print("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
- break;
- case ERR_SCRIPT:
- os_log_error(OS_LOG_DEFAULT, "SCRIPT ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
- print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- print("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
- break;
- case ERR_SHADER:
- os_log_error(OS_LOG_DEFAULT, "SHADER ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
- print("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- print("\E[0;36m At: %s:%i.\E[0m\n", p_file, p_line);
- break;
+ const char *err_details;
+ if (p_rationale && p_rationale[0])
+ err_details = p_rationale;
+ else
+ err_details = p_code;
+
+ switch (p_type) {
+ case ERR_WARNING:
+ os_log_info(OS_LOG_DEFAULT,
+ "WARNING: %{public}s: %{public}s\nAt: %{public}s:%i.",
+ p_function, err_details, p_file, p_line);
+ logf_error("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n", p_function,
+ err_details);
+ logf_error("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_SCRIPT:
+ os_log_error(OS_LOG_DEFAULT,
+ "SCRIPT ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
+ p_function, err_details, p_file, p_line);
+ logf_error("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n", p_function,
+ err_details);
+ logf_error("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_SHADER:
+ os_log_error(OS_LOG_DEFAULT,
+ "SHADER ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
+ p_function, err_details, p_file, p_line);
+ logf_error("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n", p_function,
+ err_details);
+ logf_error("\E[0;36m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_ERROR:
+ default:
+ os_log_error(OS_LOG_DEFAULT,
+ "ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
+ p_function, err_details, p_file, p_line);
+ logf_error("\E[1;31mERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ logf_error("\E[0;31m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ }
}
+};
+
#else
- OS_Unix::print_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
+
+typedef UnixTerminalLogger OSXTerminalLogger;
#endif
+
+void OS_OSX::initialize_logger() {
+ Vector<Logger *> loggers;
+ loggers.push_back(memnew(OSXTerminalLogger));
+ loggers.push_back(memnew(RotatedFileLogger("user://logs/log.txt")));
+ _set_logger(memnew(CompositeLogger(loggers)));
}
void OS_OSX::alert(const String &p_alert, const String &p_title) {
@@ -1910,6 +1934,19 @@ int OS_OSX::get_power_percent_left() {
return power_manager->get_power_percent_left();
}
+Error OS_OSX::move_to_trash(const String &p_path) {
+ NSFileManager *fm = [NSFileManager defaultManager];
+ NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
+ NSError *err;
+
+ if (![fm trashItemAtURL:url resultingItemURL:nil error:&err]) {
+ ERR_PRINTS("trashItemAtURL error: " + String(err.localizedDescription.UTF8String));
+ return FAILED;
+ }
+
+ return OK;
+}
+
OS_OSX *OS_OSX::singleton = NULL;
OS_OSX::OS_OSX() {
@@ -2003,6 +2040,8 @@ OS_OSX::OS_OSX() {
window_size = Vector2(1024, 600);
zoomed = false;
display_scale = 1.0;
+
+ _set_logger(memnew(OSXTerminalLogger));
}
bool OS_OSX::_check_internal_feature_support(const String &p_feature) {