diff --git a/star-dash/.DS_Store b/star-dash/.DS_Store index 102d7e02..7b08c2ce 100644 Binary files a/star-dash/.DS_Store and b/star-dash/.DS_Store differ diff --git a/star-dash/star-dash.xcodeproj/project.pbxproj b/star-dash/star-dash.xcodeproj/project.pbxproj index b00983bf..c2732986 100644 --- a/star-dash/star-dash.xcodeproj/project.pbxproj +++ b/star-dash/star-dash.xcodeproj/project.pbxproj @@ -12,6 +12,11 @@ 461148932BA1D04B0073E7E1 /* System.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461148922BA1D04B0073E7E1 /* System.swift */; }; 461148962BA1D53D0073E7E1 /* PositionSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461148952BA1D53D0073E7E1 /* PositionSystem.swift */; }; 461148982BA1E41F0073E7E1 /* PhysicsSystem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461148972BA1E41F0073E7E1 /* PhysicsSystem.swift */; }; + 145F2C802BA203B400457549 /* Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 145F2C7F2BA203B400457549 /* Event.swift */; }; + 145F2C842BA22CA300457549 /* EventModifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 145F2C832BA22CA300457549 /* EventModifiable.swift */; }; + 14E2478E2BA22FCE0071FFC0 /* MoveEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14E2478D2BA22FCE0071FFC0 /* MoveEvent.swift */; }; + 14E247932BA2CA920071FFC0 /* DequeModule in Frameworks */ = {isa = PBXBuildFile; productRef = 14E247922BA2CA920071FFC0 /* DequeModule */; }; + 14E247952BA2CB480071FFC0 /* EventManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14E247942BA2CB480071FFC0 /* EventManager.swift */; }; 4E630EF62B9F7E070008F887 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF52B9F7E070008F887 /* AppDelegate.swift */; }; 4E630EF82B9F7E070008F887 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF72B9F7E070008F887 /* SceneDelegate.swift */; }; 4E630EFA2B9F7E070008F887 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E630EF92B9F7E070008F887 /* ViewController.swift */; }; @@ -67,6 +72,10 @@ 461148922BA1D04B0073E7E1 /* System.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = System.swift; sourceTree = ""; }; 461148952BA1D53D0073E7E1 /* PositionSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionSystem.swift; sourceTree = ""; }; 461148972BA1E41F0073E7E1 /* PhysicsSystem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhysicsSystem.swift; sourceTree = ""; }; + 145F2C7F2BA203B400457549 /* Event.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Event.swift; sourceTree = ""; }; + 145F2C832BA22CA300457549 /* EventModifiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventModifiable.swift; sourceTree = ""; }; + 14E2478D2BA22FCE0071FFC0 /* MoveEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoveEvent.swift; sourceTree = ""; }; + 14E247942BA2CB480071FFC0 /* EventManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventManager.swift; sourceTree = ""; }; 4E630EF22B9F7E070008F887 /* star-dash.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "star-dash.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 4E630EF52B9F7E070008F887 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 4E630EF72B9F7E070008F887 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -108,6 +117,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 14E247932BA2CA920071FFC0 /* DequeModule in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -139,6 +149,17 @@ path = Systems; sourceTree = ""; }; + 145F2C7E2BA2039700457549 /* Events */ = { + isa = PBXGroup; + children = ( + 145F2C7F2BA203B400457549 /* Event.swift */, + 14E247942BA2CB480071FFC0 /* EventManager.swift */, + 145F2C832BA22CA300457549 /* EventModifiable.swift */, + 14E2478D2BA22FCE0071FFC0 /* MoveEvent.swift */, + ); + path = Events; + sourceTree = ""; + }; 4E630EE92B9F7E070008F887 = { isa = PBXGroup; children = ( @@ -170,6 +191,7 @@ 4E86605D2BA095CC0035530D /* Constants */, 4E630F352B9F91C20008F887 /* Enums */, 4E630F252B9F7E500008F887 /* Entities */, + 145F2C7E2BA2039700457549 /* Events */, 4E630EF52B9F7E070008F887 /* AppDelegate.swift */, 4E630EF72B9F7E070008F887 /* SceneDelegate.swift */, 4E630EF92B9F7E070008F887 /* ViewController.swift */, @@ -294,6 +316,9 @@ dependencies = ( ); name = "star-dash"; + packageProductDependencies = ( + 14E247922BA2CA920071FFC0 /* DequeModule */, + ); productName = "star-dash"; productReference = 4E630EF22B9F7E070008F887 /* star-dash.app */; productType = "com.apple.product-type.application"; @@ -366,6 +391,9 @@ Base, ); mainGroup = 4E630EE92B9F7E070008F887; + packageReferences = ( + 14E247912BA2CA920071FFC0 /* XCRemoteSwiftPackageReference "swift-collections" */, + ); productRefGroup = 4E630EF32B9F7E070008F887 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -433,6 +461,7 @@ files = ( 4E630F272B9F7E770008F887 /* Entity.swift in Sources */, 4E630F2C2B9F7F460008F887 /* Component.swift in Sources */, + 14E2478E2BA22FCE0071FFC0 /* MoveEvent.swift in Sources */, 4E8660622BA0964A0035530D /* Obstacle.swift in Sources */, 461148932BA1D04B0073E7E1 /* System.swift in Sources */, 4E8660642BA096600035530D /* Tool.swift in Sources */, @@ -441,11 +470,13 @@ 4E86605F2BA095E30035530D /* Collectible.swift in Sources */, 4E8660662BA097D40035530D /* PhysicsConstants.swift in Sources */, 461148912BA1CDBF0073E7E1 /* SystemManager.swift in Sources */, + 145F2C842BA22CA300457549 /* EventModifiable.swift in Sources */, 4E630EFA2B9F7E070008F887 /* ViewController.swift in Sources */, 4E630F322B9F887C0008F887 /* PhysicsComponent.swift in Sources */, 4E630EF62B9F7E070008F887 /* AppDelegate.swift in Sources */, 461148962BA1D53D0073E7E1 /* PositionSystem.swift in Sources */, 4E630F2A2B9F7EF60008F887 /* PositionComponent.swift in Sources */, + 14E247952BA2CB480071FFC0 /* EventManager.swift in Sources */, 4E630EF82B9F7E070008F887 /* SceneDelegate.swift in Sources */, E6A7451B2BA0C1890080C1BE /* PlayerView.swift in Sources */, E6A745162BA057040080C1BE /* MTKRenderer.swift in Sources */, @@ -459,6 +490,7 @@ 461148982BA1E41F0073E7E1 /* PhysicsSystem.swift in Sources */, 4E630F2E2B9F81850008F887 /* HealthComponent.swift in Sources */, 4E86605C2BA095460035530D /* Monster.swift in Sources */, + 145F2C802BA203B400457549 /* Event.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -817,6 +849,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 14E247912BA2CA920071FFC0 /* XCRemoteSwiftPackageReference "swift-collections" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/apple/swift-collections.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.1.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 14E247922BA2CA920071FFC0 /* DequeModule */ = { + isa = XCSwiftPackageProductDependency; + package = 14E247912BA2CA920071FFC0 /* XCRemoteSwiftPackageReference "swift-collections" */; + productName = DequeModule; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 4E630EEA2B9F7E070008F887 /* Project object */; } diff --git a/star-dash/star-dash.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/star-dash/star-dash.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000..1a0f4251 --- /dev/null +++ b/star-dash/star-dash.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb", + "version" : "1.1.0" + } + } + ], + "version" : 2 +} diff --git a/star-dash/star-dash/.DS_Store b/star-dash/star-dash/.DS_Store index fda27587..5b7104a3 100644 Binary files a/star-dash/star-dash/.DS_Store and b/star-dash/star-dash/.DS_Store differ diff --git a/star-dash/star-dash/Events/Event.swift b/star-dash/star-dash/Events/Event.swift new file mode 100644 index 00000000..a4150334 --- /dev/null +++ b/star-dash/star-dash/Events/Event.swift @@ -0,0 +1,15 @@ +// +// Event.swift +// star-dash +// +// Created by Jason Qiu on 13/3/24. +// + +import Foundation + +protocol Event { + var timestamp: Date { get } + var entityId: EntityId { get } + + func execute(on target: EventModifiable) +} diff --git a/star-dash/star-dash/Events/EventManager.swift b/star-dash/star-dash/Events/EventManager.swift new file mode 100644 index 00000000..4ab6e198 --- /dev/null +++ b/star-dash/star-dash/Events/EventManager.swift @@ -0,0 +1,29 @@ +// +// EventManager.swift +// star-dash +// +// Created by Jason Qiu on 14/3/24. +// + +import DequeModule +import Foundation + +typealias EventQueue = Deque + +class EventManager { + private var events: EventQueue + + init() { + events = EventQueue() + } + + func add(event: Event) { + events.append(event) + } + + func executeAll(on target: EventModifiable) { + while let event = events.popFirst() { + event.execute(on: target) + } + } +} diff --git a/star-dash/star-dash/Events/EventModifiable.swift b/star-dash/star-dash/Events/EventModifiable.swift new file mode 100644 index 00000000..844297e0 --- /dev/null +++ b/star-dash/star-dash/Events/EventModifiable.swift @@ -0,0 +1,11 @@ +// +// EventModifiable.swift +// star-dash +// +// Created by Jason Qiu on 14/3/24. +// + +import Foundation + +/// EventModifiable represents objects that can be modified by events. +protocol EventModifiable { } diff --git a/star-dash/star-dash/Events/MoveEvent.swift b/star-dash/star-dash/Events/MoveEvent.swift new file mode 100644 index 00000000..475009e8 --- /dev/null +++ b/star-dash/star-dash/Events/MoveEvent.swift @@ -0,0 +1,25 @@ +// +// MoveEvent.swift +// star-dash +// +// Created by Jason Qiu on 14/3/24. +// + +import Foundation + +class MoveEvent: Event { + var entityId: EntityId + var timestamp: Date + + var displacement: CGVector + + init(entityId: EntityId, displacement: CGVector, timestamp: Date = Date.now) { + self.entityId = entityId + self.timestamp = timestamp + self.displacement = displacement + } + + func execute(on target: EventModifiable) { + // TODO: Use PositionSystem from target to modify entity of entityId + } +}