Skip to content

Commit

Permalink
Merge pull request #506 from f3dm76/task/removeGlobalMaps
Browse files Browse the repository at this point in the history
Remove nodes map
  • Loading branch information
ystrot authored Nov 9, 2018
2 parents acd6499 + 4f23e46 commit b2b412b
Show file tree
Hide file tree
Showing 34 changed files with 424 additions and 509 deletions.
20 changes: 14 additions & 6 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@
574EC4271CB7DE7F0063F317 /* Examples */ = {
isa = PBXGroup;
children = (
5BAE3CAF20C54DA5006BEF51 /* Filters */,
57AF398A1E67E86400F0BFE2 /* Events */,
5747F9BB1E38B660004E338F /* Morphing */,
574EC4331CB7DE7F0063F317 /* Shapes */,
6699B7CE1DFFE8B90072585E /* Transform */,
574EC4421CBB607E0063F317 /* Animations */,
574EC4331CB7DE7F0063F317 /* Shapes */,
5B08CF00218832A700D37662 /* Easing */,
5747F9BB1E38B660004E338F /* Morphing */,
57AF398A1E67E86400F0BFE2 /* Events */,
5BAE3CAF20C54DA5006BEF51 /* Filters */,
574EC4401CB7E2440063F317 /* MenuViewController.swift */,
);
path = Examples;
Expand All @@ -117,8 +118,6 @@
children = (
574EC4431CBB60AF0063F317 /* AnimationsExampleController.swift */,
575129B51CBD14AF00BD3C2E /* AnimationsView.swift */,
B04416F91E041A420016BC50 /* EasingView.swift */,
B04416FB1E04282A0016BC50 /* EasingExampleController.swift */,
);
path = Animations;
sourceTree = "<group>";
Expand All @@ -131,6 +130,15 @@
path = Events;
sourceTree = "<group>";
};
5B08CF00218832A700D37662 /* Easing */ = {
isa = PBXGroup;
children = (
B04416FB1E04282A0016BC50 /* EasingExampleController.swift */,
B04416F91E041A420016BC50 /* EasingView.swift */,
);
path = Easing;
sourceTree = "<group>";
};
5BAE3CAF20C54DA5006BEF51 /* Filters */ = {
isa = PBXGroup;
children = (
Expand Down
10 changes: 6 additions & 4 deletions Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="pJi-Pa-uLB">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="pJi-Pa-uLB">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -96,7 +95,7 @@
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="1cy-cc-TWk">
<rect key="frame" x="162" y="622" width="50" height="30"/>
<rect key="frame" x="162.5" y="622" width="50" height="30"/>
<color key="backgroundColor" white="0.66666666666666663" alpha="0.29999999999999999" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="50" id="FfM-TK-kDH"/>
Expand All @@ -105,6 +104,9 @@
<state key="normal" title="Start">
<color key="titleColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="startAnimationAction" destination="eXI-AD-PfC" eventType="touchUpInside" id="1hi-aN-OHd"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down
6 changes: 0 additions & 6 deletions Macaw.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
57614B031F83D15600875933 /* UIImage2Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57900FF81EA0DEBF00809FFB /* UIImage2Image.swift */; };
57614B041F83D15600875933 /* SVGParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E1471E3B393900D1CB28 /* SVGParser.swift */; };
57614B051F83D15600875933 /* SWXMLHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 572CEFC61E2CED4B008C7C83 /* SWXMLHash.swift */; };
57614B061F83D15600875933 /* NodesMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E1511E3B393900D1CB28 /* NodesMap.swift */; };
57614B071F83D15600875933 /* RenderUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E1421E3B393900D1CB28 /* RenderUtils.swift */; };
57614B081F83D15600875933 /* FuncBounds.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E0F11E3B393900D1CB28 /* FuncBounds.swift */; };
57614B091F83D15600875933 /* MView_iOS.swift in Sources */ = {isa = PBXBuildFile; fileRef = A718CD461F45C28700966E06 /* MView_iOS.swift */; };
Expand Down Expand Up @@ -219,7 +218,6 @@
57E5E1B01E3B393900D1CB28 /* CGFloat+Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E14D1E3B393900D1CB28 /* CGFloat+Double.swift */; };
57E5E1B11E3B393900D1CB28 /* NSTimer+Closure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E14E1E3B393900D1CB28 /* NSTimer+Closure.swift */; };
57E5E1B21E3B393900D1CB28 /* MacawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E1501E3B393900D1CB28 /* MacawView.swift */; };
57E5E1B31E3B393900D1CB28 /* NodesMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E1511E3B393900D1CB28 /* NodesMap.swift */; };
57E5E1B41E3B393900D1CB28 /* ShapeLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57E5E1521E3B393900D1CB28 /* ShapeLayer.swift */; };
57F108741F502A3600DC365B /* Touchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F108731F502A3600DC365B /* Touchable.swift */; };
57F1087A1F53C92000DC365B /* MDisplayLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57F108791F53C92000DC365B /* MDisplayLink.swift */; };
Expand Down Expand Up @@ -657,7 +655,6 @@
57E5E14D1E3B393900D1CB28 /* CGFloat+Double.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CGFloat+Double.swift"; sourceTree = "<group>"; };
57E5E14E1E3B393900D1CB28 /* NSTimer+Closure.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSTimer+Closure.swift"; sourceTree = "<group>"; };
57E5E1501E3B393900D1CB28 /* MacawView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacawView.swift; sourceTree = "<group>"; };
57E5E1511E3B393900D1CB28 /* NodesMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NodesMap.swift; sourceTree = "<group>"; };
57E5E1521E3B393900D1CB28 /* ShapeLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShapeLayer.swift; sourceTree = "<group>"; };
57F108731F502A3600DC365B /* Touchable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Touchable.swift; sourceTree = "<group>"; };
57F108791F53C92000DC365B /* MDisplayLink.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MDisplayLink.swift; path = Source/platform/MDisplayLink.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -1285,7 +1282,6 @@
children = (
57F108731F502A3600DC365B /* Touchable.swift */,
57E5E1501E3B393900D1CB28 /* MacawView.swift */,
57E5E1511E3B393900D1CB28 /* NodesMap.swift */,
57E5E1521E3B393900D1CB28 /* ShapeLayer.swift */,
);
path = views;
Expand Down Expand Up @@ -2007,7 +2003,6 @@
5B6E194020AC58F900454E7E /* Stroke.swift in Sources */,
57614B041F83D15600875933 /* SVGParser.swift in Sources */,
57614B051F83D15600875933 /* SWXMLHash.swift in Sources */,
57614B061F83D15600875933 /* NodesMap.swift in Sources */,
57614B071F83D15600875933 /* RenderUtils.swift in Sources */,
57614B081F83D15600875933 /* FuncBounds.swift in Sources */,
57614B091F83D15600875933 /* MView_iOS.swift in Sources */,
Expand Down Expand Up @@ -2146,7 +2141,6 @@
57E5E1AB1E3B393900D1CB28 /* SVGParser.swift in Sources */,
5B6E193F20AC58F900454E7E /* Stroke.swift in Sources */,
572CEFC81E2CED4B008C7C83 /* SWXMLHash.swift in Sources */,
57E5E1B31E3B393900D1CB28 /* NodesMap.swift in Sources */,
57E5E1A71E3B393900D1CB28 /* RenderUtils.swift in Sources */,
57E5E1601E3B393900D1CB28 /* FuncBounds.swift in Sources */,
A718CD481F45C28700966E06 /* MView_iOS.swift in Sources */,
Expand Down
47 changes: 30 additions & 17 deletions MacawTests/Animation/AnimationUtilsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,41 @@ import XCTest
class AnimationUtilsTests: XCTestCase {

func testIndex() {
let shape = Circle(cx: 0, cy: 0, r: 10)

let rootGroup = Group()
let a = Node()
let a = Shape(form: shape)
rootGroup.contents.append(a)

let aGroup = Group()
let b = Node()
let c = Node()
aGroup.contents.append(b)
aGroup.contents.append(c)
rootGroup.contents.append(aGroup)
let bGroup = Group()
let c = Shape(form: shape)
let d = Shape(form: shape)
bGroup.contents.append(c)
bGroup.contents.append(d)
rootGroup.contents.append(bGroup)

let d = Node()
let e = Node()
rootGroup.contents.append(d)
let e = Shape(form: shape)
let f = Shape(form: shape)
rootGroup.contents.append(e)
rootGroup.contents.append(f)

let view = MacawView()
view.node = rootGroup
view.draw(CGRect(x: 0, y: 0, width: 100, height: 100))
let rootRenderer = view.renderer as? GroupRenderer
let aRenderer = rootRenderer?.renderers[0]
let bRenderer = rootRenderer?.renderers[1] as? GroupRenderer
let cRenderer = bRenderer?.renderers[0]
let dRenderer = bRenderer?.renderers[1]
let eRenderer = rootRenderer?.renderers[2]
let fRenderer = rootRenderer?.renderers[3]

XCTAssert(AnimationUtils.absoluteIndex(rootGroup) == 0)
XCTAssert(AnimationUtils.absoluteIndex(a) == 1)
XCTAssert(AnimationUtils.absoluteIndex(aGroup) == 2)
XCTAssert(AnimationUtils.absoluteIndex(b) == 3)
XCTAssert(AnimationUtils.absoluteIndex(c) == 4 )
XCTAssert(AnimationUtils.absoluteIndex(d) == 5 )
XCTAssert(AnimationUtils.absoluteIndex(e) == 6 )
XCTAssert(rootRenderer?.zPosition == 0)
XCTAssert(aRenderer?.zPosition == 1)
XCTAssert(bRenderer?.zPosition == 2)
XCTAssert(cRenderer?.zPosition == 3)
XCTAssert(dRenderer?.zPosition == 4 )
XCTAssert(eRenderer?.zPosition == 5 )
XCTAssert(fRenderer?.zPosition == 6 )
}
}
3 changes: 2 additions & 1 deletion Source/animation/AnimationImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ enum AnimationType {

class BasicAnimation: Animation {

var nodeId: String?
weak var node: Node?
weak var nodeRenderer: NodeRenderer?
var type = AnimationType.unknown
let ID: String
var next: BasicAnimation?
Expand Down
44 changes: 25 additions & 19 deletions Source/animation/AnimationProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let animationProducer = AnimationProducer()

class AnimationProducer {

var storedAnimations = [Node: BasicAnimation]()
var storedAnimations = [Node: BasicAnimation]() // is used to make sure node is in view hierarchy before actually creating the animation
var delayedAnimations = [BasicAnimation: Timer]()
var displayLink: MDisplayLinkProtocol?

Expand Down Expand Up @@ -66,11 +66,27 @@ class AnimationProducer {
}

// General case
guard let nodeId = animation.nodeId, let node = Node.nodeBy(id: nodeId) else {
guard let node = animation.node else {
return
}
for observer in node.animationObservers {
observer.processAnimation(animation)
}

switch animation.type {
case .unknown:
return
case .empty:
executeCompletion(animation)
case .sequence:
addAnimationSequence(animation)
case .combine:
addCombineAnimation(animation)
default:
break
}

guard let macawView = nodesMap.getView(node) else {
guard let macawView = animation.nodeRenderer?.view else {
storedAnimations[node] = animation
return
}
Expand All @@ -85,8 +101,6 @@ class AnimationProducer {

// swiftlint:disable superfluous_disable_command switch_case_alignment
switch animation.type {
case .unknown:
return
case .affineTransformation:
addTransformAnimation(animation, sceneLayer: layer, animationCache: cache, completion: {
if let next = animation.next {
Expand All @@ -99,10 +113,6 @@ class AnimationProducer {
self.addAnimation(next)
}
})
case .sequence:
addAnimationSequence(animation)
case .combine:
addCombineAnimation(animation)
case .contents:
addContentsAnimation(animation, cache: cache) {
if let next = animation.next {
Expand All @@ -121,8 +131,8 @@ class AnimationProducer {
self.addAnimation(next)
}
}
case .empty:
executeCompletion(animation)
default:
break
}
// swiftlint:enable superfluous_disable_command switch_case_alignment
}
Expand Down Expand Up @@ -282,10 +292,6 @@ class AnimationProducer {
return
}

guard let nodeId = animation.nodeId, let node = Node.nodeBy(id: nodeId) else {
return
}

if animation.autoreverses {
animation.autoreverses = false
addAnimation([animation, animation.reverse()].sequence() as! BasicAnimation)
Expand All @@ -311,7 +317,7 @@ class AnimationProducer {
unionBounds = unionBounds?.union(rect: contentsAnimation.getVFunc()(t).group().bounds!)
}

guard let layer = cache?.layerForNode(node, animation: contentsAnimation, customBounds: unionBounds) else {
guard let renderer = animation.nodeRenderer, let layer = cache?.layerForNodeRenderer(renderer, animation: contentsAnimation, customBounds: unionBounds) else {
return
}

Expand Down Expand Up @@ -348,7 +354,7 @@ class AnimationProducer {
for (index, animationDesc) in contentsAnimations.reversed().enumerated() {

let animation = animationDesc.animation
guard let nodeId = animation.nodeId, let group = Node.nodeBy(id: nodeId) as? Group else {
guard let group = animation.node as? Group, let renderer = animation.nodeRenderer else {
continue
}

Expand All @@ -373,7 +379,7 @@ class AnimationProducer {
}

contentsAnimations.remove(at: count - 1 - index)
animationDesc.cache?.freeLayer(group)
animationDesc.cache?.freeLayer(renderer)
animationDesc.completion?()
continue
}
Expand All @@ -386,7 +392,7 @@ class AnimationProducer {
if animation.manualStop || animation.paused {
defer {
contentsAnimations.remove(at: count - 1 - index)
animationDesc.cache?.freeLayer(group)
animationDesc.cache?.freeLayer(renderer)
}

if animation.manualStop {
Expand Down
Loading

0 comments on commit b2b412b

Please sign in to comment.