diff --git a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt
index 2493d87a1c0..73334fc14b1 100644
--- a/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt
+++ b/Interop/Indexer/src/main/kotlin/org/jetbrains/kotlin/native/interop/indexer/Indexer.kt
@@ -91,7 +91,7 @@ internal class NativeIndexImpl(val language: Language) : NativeIndex() {
}
}
- assert (underlying is ConstArrayType)
+ if (underlying !is ConstArrayType) return underlying
// So the result must feel like array:
return ConstArrayType(RecordType(structDeclaration), 1)
}
diff --git a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt
index 73e79770c1a..aa384819bcc 100644
--- a/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt
+++ b/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/jvm/main.kt
@@ -148,7 +148,7 @@ private fun Properties.defaultCompilerOpts(target: String, dependencies: String)
"-miphoneos-version-min=5.0.0")
"osx-ios-sim" ->
return listOf(
- "-arch", "amd64",
+ "-arch", "x86_64",
"-isystem", isystem,
"-B$sysRoot/usr/bin",
"--sysroot=$targetSysRoot",
diff --git a/backend.native/konan.properties b/backend.native/konan.properties
index fca614ad62d..d9e6c3796e1 100644
--- a/backend.native/konan.properties
+++ b/backend.native/konan.properties
@@ -15,7 +15,7 @@ osVersionMin.osx = -macosx_version_min 10.10.0
// iphone
arch.osx-ios = arm64
sysRoot.osx-ios = target-sysroot-1-darwin-macos
-targetSysRoot.osx-ios = target-sysroot-1-darwin-ios
+targetSysRoot.osx-ios = target-sysroot-2-darwin-ios
llvmHome.osx-ios = clang+llvm-3.9.0-darwin-macos
llvmLtoFlags.osx-ios = -O3 -function-sections -exported-symbol=_main
llvmLlcFlags.osx-ios = -mtriple=arm64-apple-ios5.0.0 --disable-fp-elim
diff --git a/dependencies/build.gradle b/dependencies/build.gradle
index d0f3953244b..5dd8eb13433 100644
--- a/dependencies/build.gradle
+++ b/dependencies/build.gradle
@@ -87,7 +87,7 @@ if (isLinux()) {
baseName = "target-sysroot-1-$host"
}
task iphoneSysroot(type: TgzNativeDep) {
- baseName = "target-sysroot-1-darwin-ios"
+ baseName = "target-sysroot-2-darwin-ios"
}
// TODO: re-enable when we known how to bring the simulator
// sysroot to dependencies.
diff --git a/samples/tetris/Info.plist b/samples/tetris/Info.plist
new file mode 100644
index 00000000000..da637bfe644
--- /dev/null
+++ b/samples/tetris/Info.plist
@@ -0,0 +1,77 @@
+
+
+
+
+ BuildMachineOSBuild
+ 15G1212
+ CFBundleDevelopmentRegion
+ en
+ CFBundleExecutable
+ tetris.kexe
+ CFBundleIdentifier
+ tetris.kexe
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ tetris.kexe
+ CFBundlePackageType
+ APPL
+ CFBundleShortVersionString
+ 1.0
+ CFBundleSupportedPlatforms
+
+ iPhoneOS
+
+ CFBundleVersion
+ 1
+ DTCompiler
+ com.apple.compilers.llvm.clang.1_0
+ DTPlatformBuild
+ 14C89
+ DTPlatformName
+ iphoneos
+ DTPlatformVersion
+ 10.2
+ DTSDKBuild
+ 14C89
+ DTSDKName
+ iphoneos10.2
+ DTXcode
+ 0821
+ DTXcodeBuild
+ 8C1002
+ LSRequiresIPhoneOS
+
+ MinimumOSVersion
+ 10.2
+ UIDeviceFamily
+
+ 1
+
+ UILaunchStoryboardName
+ LaunchScreen
+ UIRequiredDeviceCapabilities
+
+ arm64
+
+ UIStatusBarHidden
+
+ UISupportedInterfaceOrientations
+
+ UIInterfaceOrientationPortrait
+ UIInterfaceOrientationLandscapeLeft
+ UIInterfaceOrientationLandscapeRight
+
+ CFBundleIcons
+
+ CFBundlePrimaryIcon
+
+ CFBundleIconFiles
+
+ Icon-60x2
+ Icon-60
+
+
+
+
+
diff --git a/samples/tetris/build b/samples/tetris/build
index 7ced5eb42f9..ae9ecde461c 100755
--- a/samples/tetris/build
+++ b/samples/tetris/build
@@ -2,25 +2,31 @@
DIR=.
DIST=../../dist
-OSX_CFLAGS=-I/Library/Frameworks/SDL2.framework/Headers
-OSX_LINKER_ARGS="-F /Library/Frameworks -framework SDL2"
-#OSX_CFLAGS=-I/opt/local/include/SDL2
-#OSX_LINKER_ARGS="-L/opt/local/lib -lSDL2"
-LINUX_CFLAGS=-I/usr/include/SDL2
-LINUX_LINKER_ARGS="-L/usr/lib/x86_64-linux-gnu -lSDL2"
+DEPS=../../dependencies/all
+CFLAGS_macbook=-I/Library/Frameworks/SDL2.framework/Headers
+LINKER_ARGS_macbook="-F /Library/Frameworks -framework SDL2"
+#CFLAGS_macbook=-I/opt/local/include/SDL2
+#LINKER_ARGS_macbook="-L/opt/local/lib -lSDL2"
+CFLAGS_linux=-I/usr/include/SDL2
+LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lSDL2"
+CFLAGS_iphone=-I$DEPS/target-sysroot-2-darwin-ios/System/Library/Frameworks/SDL2.framework/Headers
+LINKER_ARGS_iphone="-framework SDL2 \
+-framework AVFoundation -framework CoreGraphics -framework CoreMotion -framework Foundation -framework GameController \
+-framework AudioToolbox -framework OpenGLES -framework QuartzCore -framework UIKit"
+if [ x$TARGET == x ]; then
case "$OSTYPE" in
- darwin*) OS=OSX ;;
- linux*) OS=LINUX ;;
+ darwin*) TARGET=macbook ;;
+ linux*) TARGET=linux ;;
*) echo "unknown: $OSTYPE" && exit 1;;
esac
+fi
-var=${OS}_CFLAGS
+var=CFLAGS_${TARGET}
CFLAGS=${!var}
-var=${OS}_LINKER_ARGS
+var=LINKER_ARGS_${TARGET}
LINKER_ARGS=${!var}
-$DIST/bin/interop -def:$DIR/sdl.def -copt:$CFLAGS || exit 1
-$DIST/bin/konanc -opt $DIR/tetris.kt sdl -nativelibrary sdlstubs.bc -linkerArgs "$LINKER_ARGS" -o tetris.kexe || exit 1
-strip tetris.kexe
-
+$DIST/bin/interop -def:$DIR/sdl.def -copt:"$CFLAGS" -target:$TARGET || exit 1
+$DIST/bin/konanc -target $TARGET sdl $DIR/tetris.kt -nativelibrary sdlstubs.bc -linkerArgs "$LINKER_ARGS" -o tetris.kexe || exit 1
+#strip tetris.kexe
diff --git a/samples/tetris/sdl.def b/samples/tetris/sdl.def
index 65774b895ac..482efc9c2bd 100644
--- a/samples/tetris/sdl.def
+++ b/samples/tetris/sdl.def
@@ -1,7 +1,9 @@
headers = SDL.h stdio.h string.h unistd.h stdlib.h time.h
excludedFunctions = _IO_flockfile _IO_funlockfile _IO_ftrylockfile \
_IO_cleanup_region_start _IO_cleanup_region_end \
- mkstemp_dprotected_np
+ mkstemp_dprotected_np add_profil profil unwhiteout zopen \
+ SDL_PointInRect SDL_RectEmpty SDL_RectEquals \
+ __darwin_fd_isset __sputc matherr _mm_stream_si32 _mm_stream_si64
entryPoint = SDL_main
compilerOpts.osx = -D_POSIX_SOURCE -mxsave -mavx -mf16c
diff --git a/samples/tetris/tetris.kt b/samples/tetris/tetris.kt
index bef4d3e5cf6..e2447ae643c 100644
--- a/samples/tetris/tetris.kt
+++ b/samples/tetris/tetris.kt
@@ -507,9 +507,12 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
private val LEVEL_LABEL_WIDTH = 103
private val NEXT_LABEL_WIDTH = 85
private val TETRISES_LABEL_WIDTH = 162
- private val GAMEPAD_HEIGHT = 100
- inner class GamePadButtons(val width: Int, val height: Int) {
+ private val ratio: Float
+
+ private fun stretch(value: Int) = (value.toFloat() * ratio + 0.5).toInt()
+
+ inner class GamePadButtons(width: Int, height: Int, gamePadHeight: Int) {
val arena = Arena()
val leftRect: SDL_Rect
val rightRect: SDL_Rect
@@ -518,40 +521,40 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
val rotateRect: SDL_Rect
init {
- val s = 30
- val m = 15
- val x = (width - 3 * s - 2 * m - 3 * s) / 2
- val y1 = (GAMEPAD_HEIGHT - s) / 2
- val y2 = (GAMEPAD_HEIGHT - 2 * s - m) / 2
+ val s1 = 50
+ val s2 = 80
+ val m = 25
+ val x = (width - 3 * s1 - 2 * m - m - s2) / 2 - s1
+ val y2 = (gamePadHeight - 2 * s1 - m) / 2
leftRect = arena.alloc()
- leftRect.w.value = s
- leftRect.h.value = s
+ leftRect.w.value = s1
+ leftRect.h.value = s1
leftRect.x.value = x
- leftRect.y.value = height - GAMEPAD_HEIGHT + y2 + s + m
+ leftRect.y.value = height - gamePadHeight + y2 + s1 + m
downRect = arena.alloc()
- downRect.w.value = s
- downRect.h.value = s
- downRect.x.value = x + s + m
+ downRect.w.value = s1
+ downRect.h.value = s1
+ downRect.x.value = x + s1 + m
downRect.y.value = leftRect.y.value
dropRect = arena.alloc()
- dropRect.w.value = s
- dropRect.h.value = s
+ dropRect.w.value = s1
+ dropRect.h.value = s1
dropRect.x.value = downRect.x.value
- dropRect.y.value = height - GAMEPAD_HEIGHT + y2
+ dropRect.y.value = height - gamePadHeight + y2
rightRect = arena.alloc()
- rightRect.w.value = s
- rightRect.h.value = s
- rightRect.x.value = x + 2 * s + 2 * m
- rightRect.y.value = height - GAMEPAD_HEIGHT + y2 + s + m
+ rightRect.w.value = s1
+ rightRect.h.value = s1
+ rightRect.x.value = x + 2 * s1 + 2 * m
+ rightRect.y.value = height - gamePadHeight + y2 + s1 + m
rotateRect = arena.alloc()
- rotateRect.w.value = s
- rotateRect.h.value = s
- rotateRect.x.value = x + 3 * s + 2 * m + 2 * s
- rotateRect.y.value = height - GAMEPAD_HEIGHT + y1
+ rotateRect.w.value = s2
+ rotateRect.h.value = s2
+ rotateRect.x.value = x + 3 * s1 + 2 * m + m
+ rotateRect.y.value = height - gamePadHeight + y2 - m
}
fun getCommandAt(x: Int, y: Int): UserCommand? {
@@ -566,8 +569,8 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
}
private fun inside(rect: SDL_Rect, x: Int, y: Int): Boolean {
- return x >= rect.x.value && x <= rect.x.value + rect.w.value
- && y >= rect.y.value && y <= rect.y.value + rect.h.value
+ return x >= stretch(rect.x.value) && x <= stretch(rect.x.value + rect.w.value)
+ && y >= stretch(rect.y.value) && y <= stretch(rect.y.value + rect.h.value)
}
fun destroy() {
@@ -586,14 +589,13 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
private var displayHeight: Int = 0
private val fieldWidth: Int
private val fieldHeight: Int
- private val windowWidth: Int
- private val windowHeight: Int
private val windowX: Int
private val windowY: Int
private val window: CPointer
private val renderer: CPointer
private val texture: CPointer
- private val gamePadButtons: GamePadButtons
+ private val gamePadButtons: GamePadButtons?
+ private val platform: String
init {
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
@@ -601,6 +603,8 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
throw Error()
}
+ platform = SDL_GetPlatform()!!.toKString()
+
memScoped {
val displayMode = alloc()
if (SDL_GetCurrentDisplayMode(0, displayMode.ptr.reinterpret()) != 0) {
@@ -613,11 +617,24 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
}
fieldWidth = width * (CELL_SIZE + MARGIN) + MARGIN + BORDER_WIDTH * 2
fieldHeight = height * (CELL_SIZE + MARGIN) + MARGIN + BORDER_WIDTH * 2
- windowWidth = fieldWidth + INFO_SPACE_WIDTH
- windowHeight = fieldHeight + GAMEPAD_HEIGHT
- gamePadButtons = GamePadButtons(windowWidth, windowHeight)
- windowX = (displayWidth - windowWidth) / 2
- windowY = (displayHeight - windowHeight) / 2
+ var windowWidth = fieldWidth + INFO_SPACE_WIDTH
+ var windowHeight = 0
+ if (platform == "iOS") {
+ val gamePadHeight = (displayHeight * windowWidth - fieldHeight * displayWidth) / displayWidth
+ windowHeight = fieldHeight + gamePadHeight
+ gamePadButtons = GamePadButtons(windowWidth, windowHeight, gamePadHeight)
+ windowX = 0
+ windowY = 0
+ ratio = displayHeight.toFloat() / windowHeight
+ windowWidth = displayWidth
+ windowHeight = displayHeight
+ } else {
+ windowHeight = fieldHeight
+ gamePadButtons = null
+ windowX = (displayWidth - windowWidth) / 2
+ windowY = (displayHeight - windowHeight) / 2
+ ratio = 1.0f
+ }
val window = SDL_CreateWindow("Tetris", windowX, windowY, windowWidth, windowHeight, SDL_WINDOW_SHOWN)
if (window == null) {
println("SDL_CreateWindow Error: ${get_SDL_Error()}")
@@ -842,15 +859,27 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
}
private fun drawGamePad() {
+ if (gamePadButtons == null) return
SDL_SetRenderDrawColor(renderer, 127, 127, 127, SDL_ALPHA_OPAQUE.toByte())
- SDL_RenderFillRect(renderer, gamePadButtons.leftRect.ptr.reinterpret())
- SDL_RenderFillRect(renderer, gamePadButtons.downRect.ptr.reinterpret())
- SDL_RenderFillRect(renderer, gamePadButtons.dropRect.ptr.reinterpret())
- SDL_RenderFillRect(renderer, gamePadButtons.rightRect.ptr.reinterpret())
- SDL_RenderFillRect(renderer, gamePadButtons.rotateRect.ptr.reinterpret())
+ fillRect(gamePadButtons.leftRect)
+ fillRect(gamePadButtons.downRect)
+ fillRect(gamePadButtons.dropRect)
+ fillRect(gamePadButtons.rightRect)
+ fillRect(gamePadButtons.rotateRect)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE.toByte())
}
+ private fun fillRect(rect: SDL_Rect) {
+ memScoped {
+ val stretchedRect = alloc()
+ stretchedRect.w.value = stretch(rect.w.value)
+ stretchedRect.h.value = stretch(rect.h.value)
+ stretchedRect.x.value = stretch(rect.x.value)
+ stretchedRect.y.value = stretch(rect.y.value)
+ SDL_RenderFillRect(renderer, stretchedRect.ptr.reinterpret())
+ }
+ }
+
private fun copyRect(srcX: Int, srcY: Int, destX: Int, destY: Int, width: Int, height: Int) {
memScoped {
val srcRect = alloc()
@@ -859,10 +888,10 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
srcRect.h.value = height
srcRect.x.value = srcX
srcRect.y.value = srcY
- destRect.w.value = width
- destRect.h.value = height
- destRect.x.value = destX
- destRect.y.value = destY
+ destRect.w.value = stretch(width)
+ destRect.h.value = stretch(height)
+ destRect.x.value = stretch(destX)
+ destRect.y.value = stretch(destY)
SDL_RenderCopy(renderer, texture, srcRect.ptr.reinterpret(), destRect.ptr.reinterpret())
}
}
@@ -886,7 +915,7 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
SDL_SCANCODE_ESCAPE -> commands.add(UserCommand.EXIT)
}
}
- SDL_MOUSEBUTTONDOWN -> {
+ SDL_MOUSEBUTTONDOWN -> if (gamePadButtons != null) {
val mouseEvent = event.ptr.reinterpret().pointed
val x = mouseEvent.x.value
val y = mouseEvent.y.value
@@ -894,14 +923,6 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
if (command != null)
commands.add(command)
}
- SDL_FINGERDOWN -> {
- val touchFingerEvent = event.ptr.reinterpret().pointed
- val x = (touchFingerEvent.x.value * displayWidth).toInt() - windowX
- val y = (touchFingerEvent.y.value * displayHeight).toInt() - windowY
- val command = getCommandAt(x, y)
- if (command != null)
- commands.add(command)
- }
}
}
}
@@ -913,7 +934,7 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
SDL_DestroyRenderer(renderer)
SDL_DestroyWindow(window)
SDL_Quit()
- gamePadButtons.destroy()
+ gamePadButtons?.destroy()
}
}