From 9c7946384ea7e7fb7ca6ffe1bb2d6829ba155726 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sun, 19 Feb 2017 18:31:11 -0800 Subject: [PATCH] progress on getting ios version working well. --- desktop/gametodos.txt | 1 + desktop/src-common/advent/screens/scene.clj | 53 ++++++++-------- desktop/src-common/advent/screens/shader.clj | 65 ++++++++++++++++++-- desktop/src-common/advent/utils.clj | 9 ++- ios/Info.plist.xml | 2 +- ios/project.clj | 12 ++-- ios/robovm.xml | 2 +- 7 files changed, 103 insertions(+), 41 deletions(-) diff --git a/desktop/gametodos.txt b/desktop/gametodos.txt index 559133f4..f4661d66 100644 --- a/desktop/gametodos.txt +++ b/desktop/gametodos.txt @@ -8,3 +8,4 @@ move entrance to antique inventory selected item needs to be rendered on top +CLOJURE 1.8 direct linking diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index dfb7a8cd..1401828a 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -181,7 +181,8 @@ (and (get-in entities [:state :active?]) (or (not (get-in entities [:state :hud-active?])) (get-in entities [:fg-actions :script-running?])) - (= 0.0 (get-in entities [:fade :opacity]))) + (= 0.0 (get-in entities [:fade :opacity])) + (not (get-in entities [:cam :pinching]))) (left-click screen entities options) :else @@ -1013,7 +1014,8 @@ e))) (defn mouse-moved [screen entities {:keys [input-x input-y] :as options}] - (utils/update-override screen (assoc-in entities [:cursor :last-pos] [input-x input-y]) options)) + (when-not (get-in entities [:cam :pinching]) + (utils/update-override screen (assoc-in entities [:cursor :last-pos] [input-x input-y]) options))) (defn grab-layers [entities] (update-in entities [:room] @@ -1070,7 +1072,7 @@ (let [{cam :camera :as screen} (utils/setup-viewport screen 320 240) screen (assoc screen :total-time 0)] (set! (. cam zoom) utils/min-zoom) - (let [shader (ShaderProgram. ^String v-shader ^String pix-shader) + (let [shader (ShaderProgram. ^String (v-shader) ^String (pix-shader)) _ (log/info "shader log:" (.getLog shader)) state (get-state @utils/selected-save) start-pos [(:x state) (:y state)] @@ -1225,33 +1227,30 @@ (update-in [:cam] dissoc :start-zoom :pinching) ))) :on-pinch - (fn [screen entities {:keys [initial-pointer-1 initial-pointer-2]}] - (when (and (not (get-in entities [:cam :pinching])) - (get-in entities [:state :active?])) - (let [[pointer-1-x pointer-1-y] (utils/unproject screen nil [(.x initial-pointer-1) (.y initial-pointer-1)]) - [pointer-2-x pointer-2-y] (utils/unproject screen nil [(.x initial-pointer-2) (.y initial-pointer-2)])] - (-> entities - (remove-cam-tweens) - (assoc-in [:cursor :last-pos] [0 0]) - (assoc-in [:cam :ideal-x] (* 0.5 (+ pointer-1-x pointer-2-x))) - (assoc-in [:cam :ideal-y] (* 0.5 (+ pointer-1-y pointer-2-y))) - (assoc-in [:cam :pinching] true))))) - - :on-zoom - (fn [{:keys [^OrthographicCamera camera ^FitViewport viewport ^Stage renderer] :as screen} entities {:keys [initial-distance distance]}] + (fn [screen entities {:keys [initial-pointer-1 initial-pointer-2 pointer-1 pointer-2]}] + (log/info "pinching...") (when (get-in entities [:state :active?]) (let [start-zoom (get-in entities [:cam :start-zoom]) zoom (get-in entities [:cam :zoom]) - entities (as-> entities entities - (if (not start-zoom) - (assoc-in entities [:cam :start-zoom] zoom) - entities) - (remove-cam-tweens entities) - (assoc-in entities [:cam :zoom] (max utils/max-zoom (min utils/min-zoom (* (or start-zoom zoom) (/ initial-distance distance))))) - (assoc-in entities [:cam :x] (utils/bound-to-camera (get-in entities [:cam :ideal-x]) 320 (get-in entities [:cam :zoom])) ) - (assoc-in entities [:cam :y] (utils/bound-to-camera (get-in entities [:cam :ideal-y]) 240 (get-in entities [:cam :zoom])) ))] - entities - ))) + initial-distance (.dst initial-pointer-1 initial-pointer-2) + distance (.dst pointer-1 pointer-2) + [pointer-1-x pointer-1-y] (utils/unproject screen nil [(.x initial-pointer-1) (.y initial-pointer-1)]) + [pointer-2-x pointer-2-y] (utils/unproject screen nil [(.x initial-pointer-2) (.y initial-pointer-2)])] + (as-> entities entities + (remove-cam-tweens entities) + + (if (not start-zoom) + (assoc-in entities [:cam :start-zoom] zoom) + entities) + (assoc-in entities [:cursor :last-pos] [0 0]) + (assoc-in entities [:cam :ideal-x] (* 0.5 (+ pointer-1-x pointer-2-x))) + (assoc-in entities [:cam :ideal-y] (* 0.5 (+ pointer-1-y pointer-2-y))) + (assoc-in entities [:cam :pinching] true) + + (assoc-in entities [:cam :x] (utils/bound-to-camera (get-in entities [:cam :ideal-x]) 320 (get-in entities [:cam :zoom])) ) + (assoc-in entities [:cam :y] (utils/bound-to-camera (get-in entities [:cam :ideal-y]) 240 (get-in entities [:cam :zoom])) ) + (assoc-in entities [:cam :zoom] (max utils/max-zoom (min utils/min-zoom (* (or start-zoom zoom) (/ initial-distance distance))))))))) + #_#_:on-scrolled (fn [{:keys [^OrthographicCamera camera ^FitViewport viewport ^Stage renderer] :as screen} entities options] diff --git a/desktop/src-common/advent/screens/shader.clj b/desktop/src-common/advent/screens/shader.clj index a61aca3a..fc2389a8 100644 --- a/desktop/src-common/advent/screens/shader.clj +++ b/desktop/src-common/advent/screens/shader.clj @@ -1,6 +1,8 @@ -(ns advent.screens.shader) +(ns advent.screens.shader + (:require [advent.utils :as utils])) -(def v-shader "attribute vec4 a_position; + +(def v-shader (constantly "attribute vec4 a_position; attribute vec4 a_color; attribute vec2 a_texCoord0; @@ -13,10 +15,56 @@ void main() { v_color = a_color; v_texCoords = a_texCoord0; gl_Position = u_projTrans * a_position; -}") +}")) -(def pix-shader " +(def mobile-pix-shader + " + #ifdef GL_ES + #define LOWP lowp + #define HIGHP highp + precision mediump float; + #else + #define LOWP + #define HIGHP + #endif + + varying vec4 v_color; + varying HIGHP vec2 v_texCoords; + uniform HIGHP float multiply_amount; + uniform HIGHP float hue_amount; + + uniform sampler2D u_texture; + + vec4 toGrayscale(in vec4 color) + { + float average = (color.r + color.g + color.b) / 3.0; + return vec4(average, average, average, color.a); + } + + vec4 colorize(in vec4 grayscale, in vec4 color) + { + return (grayscale * color); + } + + + void main () + { + vec4 scaledColor = texture2D(u_texture, v_texCoords); + + vec4 grayscale = toGrayscale(scaledColor); + vec4 colorizedOutput = mix(scaledColor, colorize(grayscale, v_color.rgba), hue_amount); + + vec4 multiplied = mix(colorizedOutput.rgba, v_color.rgba * scaledColor.rgba, multiply_amount); + + gl_FragColor = vec4(multiplied.rgb, scaledColor.a * v_color.a); + + } + " + ) + +(def desktop-pix-shader + " #ifdef GL_ES #define LOWP lowp #define HIGHP highp @@ -64,6 +112,7 @@ void main () c3 *= frac.x * (1.0 - frac.y); c4 *= (1.0 - frac.x) * (1.0 - frac.y); vec4 scaledColor = (c1 + c2 + c3 + c4); + vec4 scaledColor = texture2D(u_texture, v_texCoords); vec4 grayscale = toGrayscale(scaledColor); vec4 colorizedOutput = mix(scaledColor, colorize(grayscale, v_color.rgba), hue_amount); @@ -74,3 +123,11 @@ void main () } ") + + +(defn pix-shader [] + (if utils/mobile? + mobile-pix-shader + desktop-pix-shader + + )) diff --git a/desktop/src-common/advent/utils.clj b/desktop/src-common/advent/utils.clj index 0c61ddc3..72c76747 100644 --- a/desktop/src-common/advent/utils.clj +++ b/desktop/src-common/advent/utils.clj @@ -388,13 +388,18 @@ (defn make-music [r] (try - (doto (music r) (music! :set-looping true)) + (if mobile? + (doto (music (str r ".mp3")) (music! :set-looping true)) + (doto (music r) (music! :set-looping true))) + (catch Exception _ (doto (music (str r ".mp3")) (music! :set-looping true))))) (defn load-sound [f] (try - (sound f) + (if mobile? + (sound (str f ".mp3")) + (sound f)) (catch Exception e (log/info e) (sound (str f ".mp3"))))) diff --git a/ios/Info.plist.xml b/ios/Info.plist.xml index 64ae85c2..5b51828d 100644 --- a/ios/Info.plist.xml +++ b/ios/Info.plist.xml @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 83 + 93 MinimumOSVersion 8.0 LSRequiresIPhoneOS diff --git a/ios/project.clj b/ios/project.clj index 5e1e5f05..4d0779b5 100644 --- a/ios/project.clj +++ b/ios/project.clj @@ -7,18 +7,18 @@ [org.clojars.notid/tools.logging "0.3.2-SNAPSHOT"] [log4j/log4j "1.2.16"] [org.clojure/clojure "1.8.0"] - [com.mobidevelop.robovm/robovm-cocoatouch "2.2.0"] - [com.mobidevelop.robovm/robovm-objc "2.2.0"] - [com.mobidevelop.robovm/robovm-rt "2.2.0"] - [com.mobidevelop.robovm/robovm-compiler "2.2.0"] - [com.mobidevelop.robovm/robovm-dist-compiler "2.2.0"] + [com.mobidevelop.robovm/robovm-cocoatouch "2.3.0"] + [com.mobidevelop.robovm/robovm-objc "2.3.0"] + [com.mobidevelop.robovm/robovm-rt "2.3.0"] + [com.mobidevelop.robovm/robovm-compiler "2.3.0"] + [com.mobidevelop.robovm/robovm-dist-compiler "2.3.0"] [play-clj "0.4.6-BRYCE"]] :source-paths ["src/clojure" "../desktop/src-common"] :java-source-paths ["src/java"] :plugins [[lein-fruit "0.2.4-SNAPSHOT"]] :javac-options ["-target" "1.7" "-source" "1.7" "-Xlint:-options"] :ios {:robovm-opts ["-config" "robovm.xml"] - :robovm-path "/Users/brycecovert/.robovm-sdks/robovm-2.2.1-SNAPSHOT/" + :robovm-path "/Users/brycecovert/.robovm-sdks/robovm-2.2.1-SNAPSHOT" :version 2.1} :aot :all :main advent.core.IOSLauncher) diff --git a/ios/robovm.xml b/ios/robovm.xml index 71ef1e30..be834e78 100644 --- a/ios/robovm.xml +++ b/ios/robovm.xml @@ -1,6 +1,6 @@ tickstales - ${app.mainclass} + advent.core.IOSLauncher ios arm64 ios