Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
star-dash/star-dash.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// EventManager.swift | ||
// star-dash | ||
// | ||
// Created by Jason Qiu on 14/3/24. | ||
// | ||
|
||
import DequeModule | ||
import Foundation | ||
|
||
typealias EventQueue = Deque<Event> | ||
|
||
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |