Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental iOS Support #8407

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ android/.gradle
# Automatically created Android assets
android/app/src/main/assets/files/

# Xcode per user files
xcuserdata

# Mac magic folders
.DS_Store
2 changes: 1 addition & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [**fheroes2**](README.md) installation guide
shell# [**fheroes2**](README.md) installation guide

## Requirements

Expand Down
11 changes: 11 additions & 0 deletions ios/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions ios/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
17 changes: 17 additions & 0 deletions ios/Assets.xcassets/ColorMap.textureset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"origin" : "bottom-left",
"interpretation" : "non-premultiplied-colors"
},
"textures" : [
{
"idiom" : "universal",
"filename" : "Universal.mipmapset"
}
]
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"levels" : [
{
"filename" : "ColorMap.png",
"mipmap-level" : "base"
}
]
}
6 changes: 6 additions & 0 deletions ios/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
25 changes: 25 additions & 0 deletions ios/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
24 changes: 24 additions & 0 deletions ios/SDL_uikit_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
SDL_uikit_main.c, placed in the public domain by Sam Lantinga 3/18/2019
*/

/* Include the SDL main definition header */
#include "SDL_main.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ clang-diagnostic-error ⚠️
SDL_main.h file not found


#if defined(__IPHONEOS__) || defined(__TVOS__)

#ifndef SDL_MAIN_HANDLED
#ifdef main
#undef main
#endif

int
main(int argc, char *argv[])
{
return SDL_UIKitRunApp(argc, argv, SDL_main);
}
#endif /* !SDL_MAIN_HANDLED */

#endif /* __IPHONEOS__ || __TVOS__ */

/* vi: set ts=4 sw=4 expandtab: */
49 changes: 49 additions & 0 deletions ios/ShaderTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// ShaderTypes.h
// fheroes2
//
// Created by Drew Bratcher on 4/29/23.
//

//
// Header containing types and enum constants shared between Metal shaders and Swift/ObjC source
//
#ifndef ShaderTypes_h
#define ShaderTypes_h

#ifdef __METAL_VERSION__
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
typedef metal::int32_t EnumBackingType;
#else
#import <Foundation/Foundation.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ clang-diagnostic-import-preprocessor-directive-pedantic ⚠️
#import is a language extension

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ clang-diagnostic-error ⚠️
Foundation/Foundation.h file not found

typedef NSInteger EnumBackingType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ modernize-use-using ⚠️
use using instead of typedef

Suggested change
typedef NSInteger EnumBackingType;
using EnumBackingType = int;

#endif

#include <simd/simd.h>

typedef NS_ENUM(EnumBackingType, BufferIndex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-named-parameter ⚠️
all parameters should be named in a function

Suggested change
typedef NS_ENUM(EnumBackingType, BufferIndex)
typedef NS_ENUM(EnumBackingType /*unused*/, BufferIndex /*unused*/)

{
BufferIndexMeshPositions = 0,
BufferIndexMeshGenerics = 1,
BufferIndexUniforms = 2
};

typedef NS_ENUM(EnumBackingType, VertexAttribute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-named-parameter ⚠️
all parameters should be named in a function

Suggested change
typedef NS_ENUM(EnumBackingType, VertexAttribute)
typedef NS_ENUM(EnumBackingType /*unused*/, VertexAttribute /*unused*/)

{
VertexAttributePosition = 0,
VertexAttributeTexcoord = 1,
};

typedef NS_ENUM(EnumBackingType, TextureIndex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ readability-named-parameter ⚠️
all parameters should be named in a function

Suggested change
typedef NS_ENUM(EnumBackingType, TextureIndex)
typedef NS_ENUM(EnumBackingType /*unused*/, TextureIndex /*unused*/)

{
TextureIndexColor = 0,
};

typedef struct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ modernize-use-using ⚠️
use using instead of typedef

Suggested change
typedef struct
using Uniforms = struct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ cppcoreguidelines-pro-type-member-init ⚠️
constructor does not initialize these fields: projectionMatrix, modelViewMatrix

{
matrix_float4x4 projectionMatrix;
matrix_float4x4 modelViewMatrix;
} Uniforms;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ modernize-use-using ⚠️
use using instead of typedef

Suggested change
} Uniforms;
};


#endif /* ShaderTypes_h */

53 changes: 53 additions & 0 deletions ios/Shaders.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Shaders.metal
// fheroes2
//
// Created by Drew Bratcher on 4/29/23.
//

// File for Metal kernel and shader functions

#include <metal_stdlib>
#include <simd/simd.h>

// Including header shared between this Metal shader code and Swift/C code executing Metal API commands
#import "ShaderTypes.h"

using namespace metal;

typedef struct
{
float3 position [[attribute(VertexAttributePosition)]];
float2 texCoord [[attribute(VertexAttributeTexcoord)]];
} Vertex;

typedef struct
{
float4 position [[position]];
float2 texCoord;
} ColorInOut;

vertex ColorInOut vertexShader(Vertex in [[stage_in]],
constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]])
{
ColorInOut out;

float4 position = float4(in.position, 1.0);
out.position = uniforms.projectionMatrix * uniforms.modelViewMatrix * position;
out.texCoord = in.texCoord;

return out;
}

fragment float4 fragmentShader(ColorInOut in [[stage_in]],
constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]],
texture2d<half> colorMap [[ texture(TextureIndexColor) ]])
{
constexpr sampler colorSampler(mip_filter::linear,
mag_filter::linear,
min_filter::linear);

half4 colorSample = colorMap.sample(colorSampler, in.texCoord.xy);

return float4(colorSample);
}
Loading
Loading