Skip to content

Commit

Permalink
Merge pull request #36 from bruvzg/mac_rename
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jul 21, 2022
2 parents 458ea33 + b1fee0d commit e53076d
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Generate Headers
run: |
./scripts/generate_headers.sh || true
./scripts/generate_headers.sh 3.x || true
- name: Compile Plugins
run: |
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ If you choose this option, you can skip next the step which generates Godot head

- To generate Godot headers, you need to run the compilation command inside the `godot` submodule directory:

### For Godot 3.x:

```bash
scons platform=iphone target=debug
```

### For Godot 4.x:

```bash
scons platform=ios target=debug
```

You don't have to wait for full engine compilation, as header files are generated first.
Once the actual compilation starts, you can stop this command by pressing <kbd>Ctrl + C</kbd>.

Expand Down
25 changes: 16 additions & 9 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ env.Append(CCFLAGS=[
# '-Wextra',
])

env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path])
env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IOS_SDK_PATH", "-stdlib=libc++", '-isysroot', sdk_path])
env.Append(CCFLAGS=['-DPTRCALL_ENABLED'])
env.Prepend(CXXFLAGS=[
'-DNEED_LONG_INT', '-DLIBYUV_DISABLE_NEON',
'-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED'
'-DIOS_ENABLED', '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED'
])
env.Append(LINKFLAGS=["-arch", env['arch'], '-isysroot', sdk_path, '-F' + sdk_path])

Expand Down Expand Up @@ -152,19 +152,26 @@ else:
quit();

# Adding header files
env.Append(CPPPATH=[
'.',
'godot',
'godot/platform/iphone',
])
if env['version'] == '3.x':
env.Append(CPPPATH=[
'.',
'godot',
'godot/platform/iphone',
])
else:
env.Append(CPPPATH=[
'.',
'godot',
'godot/platform/ios',
])

# tweak this if you want to use different folders, or more folders, to store your source code in.
sources = Glob('plugins/' + env['plugin'] + '/*.cpp')
sources.append(Glob('plugins/' + env['plugin'] + '/*.mm'))
sources.append(Glob('plugins/' + env['plugin'] + '/*.m'))

# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "iphone")
# lib<plugin>.<arch>-<simulator|ios>.<release|debug|release_debug>.a
library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "ios")
library_name = env['plugin'] + "." + library_platform + "." + env["target"] + ".a"
library = env.StaticLibrary(target=env['target_path'] + library_name, source=sources)

Expand Down
6 changes: 6 additions & 0 deletions plugins/apn/apn.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
#ifndef godot_apn_implementation_h
#define godot_apn_implementation_h

#include "core/version.h"

#if VERSION_MAJOR == 4
#include "core/object/class_db.h"
#else
#include "core/object.h"
#endif

class APNPlugin : public Object {
GDCLASS(APNPlugin, Object);
Expand Down
5 changes: 5 additions & 0 deletions plugins/apn/apn.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@

#import <Foundation/Foundation.h>

#if VERSION_MAJOR == 4
#include "core/object/class_db.h"
#include "core/config/project_settings.h"
#else
#include "core/class_db.h"
#include "core/project_settings.h"
#endif

#import "godot_apn_delegate.h"

Expand Down
4 changes: 4 additions & 0 deletions plugins/apn/apn_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
#import "apn_plugin.h"
#import "apn.h"

#if VERSION_MAJOR == 4
#import "core/config/engine.h"
#else
#import "core/engine.h"
#endif

APNPlugin *plugin;

Expand Down
5 changes: 5 additions & 0 deletions plugins/apn/godot_apn_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
#include "apn.h"

#import "godot_user_notification_delegate.h"

#if VERSION_MAJOR == 4
#import "platform/ios/godot_app_delegate.h"
#else
#import "platform/iphone/godot_app_delegate.h"
#endif

struct APNSInitializer {

Expand Down
6 changes: 6 additions & 0 deletions plugins/apn/godot_app_delegate_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#include "core/version.h"

#if VERSION_MAJOR == 4
#import "platform/ios/godot_app_delegate.h"
#else
#import "platform/iphone/godot_app_delegate.h"
#endif

@interface GodotApplicalitionDelegate (PushNotifications)

Expand Down
4 changes: 2 additions & 2 deletions plugins/arkit/arkit_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef PoolVector<uint8_t> GodotUInt8Vector;
/**
@author Bastiaan Olij <[email protected]>
ARKit interface between iPhone and Godot
ARKit interface between iOS and Godot
*/

// forward declaration for some needed objects
Expand Down Expand Up @@ -142,7 +142,7 @@ class ARKitInterface : public GodotBaseARInterface {

virtual void process() GODOT_ARKIT_OVERRIDE;

// called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm)
// called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/ios/*.cpp files to .mm)
void _add_or_update_anchor(GodotARAnchor *p_anchor);
void _remove_anchor(GodotARAnchor *p_anchor);

Expand Down
15 changes: 10 additions & 5 deletions plugins/camera/camera_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

///@TODO this is a near duplicate of CameraOSX, we should find a way to combine those to minimize code duplication!!!!
///@TODO this is a near duplicate of CameraMacOS, we should find a way to combine those to minimize code duplication!!!!
// If you fix something here, make sure you fix it there as wel!

#include "camera_ios.h"
Expand Down Expand Up @@ -182,12 +182,12 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
#if VERSION_MAJOR == 4
uint8_t *w = img_data[0].ptrw();
memcpy(w, dataY, new_width * new_height);
img[0].instantiate();
#else
GodotUInt8Vector::Write w = img_data[0].write();
memcpy(w.ptr(), dataY, new_width * new_height);
#endif

img[0].instance();
#endif
img[0]->create(new_width, new_height, 0, Image::FORMAT_R8, img_data[0]);
}

Expand All @@ -205,13 +205,14 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
#if VERSION_MAJOR == 4
uint8_t *w = img_data[1].ptrw();
memcpy(w, dataCbCr, 2 * new_width * new_height);
img[1].instantiate();
#else
GodotUInt8Vector::Write w = img_data[1].write();
memcpy(w.ptr(), dataCbCr, 2 * new_width * new_height);
img[1].instance();
#endif

///TODO GLES2 doesn't support FORMAT_RG8, need to do some form of conversion
img[1].instance();
img[1]->create(new_width, new_height, 0, Image::FORMAT_RG8, img_data[1]);
}

Expand Down Expand Up @@ -358,7 +359,7 @@ - (void)dealloc {
MyDeviceNotifications *device_notifications = nil;

//////////////////////////////////////////////////////////////////////////
// CameraIOS - Subclass for our camera server on iPhone
// CameraIOS - Subclass for our camera server on iOS

void CameraIOS::update_feeds() {
// this way of doing things is deprecated but still works,
Expand Down Expand Up @@ -410,7 +411,11 @@ - (void)dealloc {

if (!found) {
Ref<CameraFeedIOS> newfeed;
#if VERSION_MAJOR == 4
newfeed.instantiate();
#else
newfeed.instance();
#endif
newfeed->set_device(device);
add_feed(newfeed);
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/gamecenter/game_center.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@
#include "game_center.h"

#import "game_center_delegate.h"

#if VERSION_MAJOR == 4
#import "platform/ios/app_delegate.h"
#import "platform/ios/view_controller.h"
#else
#import "platform/iphone/app_delegate.h"
#import "platform/iphone/view_controller.h"
#endif

#import <GameKit/GameKit.h>

Expand Down
4 changes: 4 additions & 0 deletions plugins/icloud/icloud.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@

#include "icloud.h"

#if VERSION_MAJOR == 4
#import "platform/ios/app_delegate.h"
#else
#import "platform/iphone/app_delegate.h"
#endif

#import <Foundation/Foundation.h>

Expand Down
5 changes: 5 additions & 0 deletions plugins/photo_picker/photo_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@

#include "core/version.h"

#if VERSION_MAJOR == 4
#include "core/io/image.h"
#include "core/object/object.h"
#else
#include "core/image.h"
#include "core/object.h"
#endif

#ifdef __OBJC__
@class GodotPhotoPicker;
Expand Down
14 changes: 14 additions & 0 deletions plugins/photo_picker/photo_picker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@
#import <Foundation/Foundation.h>
#import <Photos/Photos.h>

#if VERSION_MAJOR == 4
#import "platform/ios/app_delegate.h"
#import "platform/ios/view_controller.h"
#else
#import "platform/iphone/app_delegate.h"
#import "platform/iphone/view_controller.h"
#endif

PhotoPicker *instance = NULL;

Expand Down Expand Up @@ -183,12 +188,21 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
if (data) {
Ref<Image> img;

#if VERSION_MAJOR == 4
Vector<uint8_t> img_data;
img_data.resize(length);
uint8_t* w = img_data.ptrw();
memcpy(w, data, length);

img.instantiate();
#else
PoolVector<uint8_t> img_data;
img_data.resize(length);
PoolVector<uint8_t>::Write w = img_data.write();
memcpy(w.ptr(), data, length);

img.instance();
#endif
img->create(image.size.width * image.scale, image.size.height * image.scale, 0, Image::FORMAT_RGBA8, img_data);

PhotoPicker::get_singleton()->select_image(img);
Expand Down
7 changes: 7 additions & 0 deletions plugins/photo_picker/photo_picker_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@

#include "photo_picker_module.h"

#include "core/version.h"

#if VERSION_MAJOR == 4
#include "core/config/engine.h"
#else
#include "core/engine.h"
#endif

#include "core/version.h"

#include "photo_picker.h"
Expand Down
10 changes: 8 additions & 2 deletions scripts/generate_headers.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/bin/bash
cd ./godot && \
./../scripts/timeout scons platform=iphone target=release_debug
if [[ "$1" == "3.x" ]];
then
cd ./godot && \
./../scripts/timeout scons platform=iphone target=release_debug
else
cd ./godot && \
./../scripts/timeout scons platform=ios target=release_debug
fi
6 changes: 3 additions & 3 deletions scripts/generate_static_library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ scons target=$2 arch=armv7 plugin=$1 version=$3
scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3

# Creating a fat libraries for device and simulator
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
# lib<plugin>.<arch>-<simulator|ios>.<release|debug|release_debug>.a
lipo -create "./bin/lib$1.x86_64-simulator.$2.a" \
"./bin/lib$1.armv7-iphone.$2.a" \
"./bin/lib$1.arm64-iphone.$2.a" \
"./bin/lib$1.armv7-ios.$2.a" \
"./bin/lib$1.arm64-ios.$2.a" \
-output "./bin/$1.$2.a"
4 changes: 2 additions & 2 deletions scripts/generate_xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ scons target=$2 arch=x86_64 simulator=yes plugin=$1 version=$3
scons target=$2 arch=arm64 simulator=yes plugin=$1 version=$3

# Creating a fat libraries for device and simulator
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
# lib<plugin>.<arch>-<simulator|ios>.<release|debug|release_debug>.a
lipo -create "./bin/lib$1.x86_64-simulator.$2.a" "./bin/lib$1.arm64-simulator.$2.a" -output "./bin/$1-simulator.$2.a"
lipo -create "./bin/lib$1.armv7-iphone.$2.a" "./bin/lib$1.arm64-iphone.$2.a" -output "./bin/$1-device.$2.a"
lipo -create "./bin/lib$1.armv7-ios.$2.a" "./bin/lib$1.arm64-ios.$2.a" -output "./bin/$1-device.$2.a"

# Creating a xcframework
xcodebuild -create-xcframework \
Expand Down

0 comments on commit e53076d

Please sign in to comment.