Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9f3e239
add Commands
rrbox Aug 12, 2023
ba5a664
add Entity commands
rrbox Aug 12, 2023
c6f819b
add EntityCommnads's methods
rrbox Aug 12, 2023
730d89c
add system parameter protocol
rrbox Aug 12, 2023
7958aef
add implement of world
rrbox Aug 12, 2023
467fb21
add Chunk
rrbox Aug 12, 2023
30858cf
add queries
rrbox Aug 12, 2023
008cd9c
add resource
rrbox Aug 12, 2023
d717077
add system plug in API
rrbox Aug 12, 2023
ecffd6a
add update systems
rrbox Aug 12, 2023
b922909
add methods of world
rrbox Aug 12, 2023
7b91738
update pachage.swift
rrbox Aug 12, 2023
3dd3b67
add files
rrbox Aug 15, 2023
60c3233
add macos version
rrbox Aug 15, 2023
0cfed82
change Archetype to EntityRecord
rrbox Aug 15, 2023
c6b52ed
add struct Entities
rrbox Aug 15, 2023
cf57929
add Chunk/applyCurrentState
rrbox Aug 16, 2023
c7e6720
change: addComponent, removeComponent コマンド実行後に applyCurrentState を実行す…
rrbox Aug 17, 2023
6f8f31c
add: set up system
rrbox Aug 17, 2023
adf4fbe
add: files
rrbox Aug 19, 2023
9163dac
add: files
rrbox Aug 19, 2023
3282f0e
add: Graphic
rrbox Aug 19, 2023
3d94fa7
add: files
rrbox Sep 13, 2023
cc6c5da
add: Graphic module
rrbox Sep 13, 2023
e4ac4fa
feat: change access modifier Buffer, Command and Commands to public
rrbox Sep 13, 2023
9c2034e
add: EntityCommands
rrbox Sep 13, 2023
3f57254
add: Event system
rrbox Sep 13, 2023
025a721
add: methods of queries for single entity
rrbox Sep 13, 2023
f35f781
chore: add `@discardableResult` attribute to `addResource` method of …
rrbox Sep 13, 2023
9648aa0
change: omit external parameter name of parameter name of initializer…
rrbox Sep 13, 2023
30d0a5f
add: Entity count resource
rrbox Sep 13, 2023
e41179d
add: DidSpawnEvent, WillDespawnEvent
rrbox Sep 13, 2023
c0f7c7a
add: add plugin method of world
rrbox Sep 13, 2023
92cf0c4
change: entity count resource の追加, spawn/despawn event の設定をプロセスに追加
rrbox Sep 13, 2023
85ffdf7
change: frame cycle
rrbox Sep 13, 2023
f511dfb
chore: get entity record method
rrbox Sep 13, 2023
63caf17
rename: Graphic -> Graphic2D
rrbox Oct 22, 2023
34bded3
add: tests
rrbox Oct 22, 2023
b34805b
add: Filtered query
rrbox Oct 22, 2023
261e8c2
change: Query
rrbox Oct 22, 2023
beeda0e
add: Camera
rrbox Oct 22, 2023
b3161c4
add: MouseEvent
rrbox Oct 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>classNames</key>
<dict>
<key>ecs_swiftTests</key>
<dict>
<key>testPerformance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.004780</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
<key>testUpdate4Performance()</key>
<dict>
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
<dict>
<key>baselineAverage</key>
<real>0.015800</real>
<key>baselineIntegrationDisplayName</key>
<string>Local Baseline</string>
</dict>
</dict>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>runDestinationsByUUID</key>
<dict>
<key>2AC02D75-F4A4-4DFA-8C0B-FAD0AD501706</key>
<dict>
<key>localComputer</key>
<dict>
<key>busSpeedInMHz</key>
<integer>0</integer>
<key>cpuCount</key>
<integer>1</integer>
<key>cpuKind</key>
<string>Apple M1</string>
<key>cpuSpeedInMHz</key>
<integer>0</integer>
<key>logicalCPUCoresPerPackage</key>
<integer>8</integer>
<key>modelCode</key>
<string>MacBookPro17,1</string>
<key>physicalCPUCoresPerPackage</key>
<integer>8</integer>
<key>platformIdentifier</key>
<string>com.apple.platform.macosx</string>
</dict>
<key>targetArchitecture</key>
<string>arm64</string>
</dict>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/ECS-Package.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/ECS.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
78 changes: 50 additions & 28 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,42 @@ struct Module {
extension Module {
static let ecs = Module(name: "ECS")
static let plugIns = Module(name: "PlugIns")
static let graphic2d = Module(name: "ECS_Graphic", path: "Sources/PlugIns/Graphic2D")
static let keyboard = Module(name: "ECS_Keyboard", path: "Sources/PlugIns/Keyboard")
static let mouse = Module(name: "ECS_Mouse", path: "Sources/PlugIns/Mouse")
static let objectLink = Module(name: "ECS_ObjectLink", path: "Sources/PlugIns/ObjectLink")
static let scene = Module(name: "ECS_Scene", path: "Sources/PlugIns/Scene")
static let scroll = Module(name: "ECS_Scroll", path: "Sources/PlugIns/Scroll")

static let ecs_swiftTests = Module(name: "ecs-swiftTests")
static let graphicPlugInTests = Module(name: "GraphicPlugInTests")
static let keyBoardPlugInTests = Module(name: "KeyBoardPlugInTests")
static let mousePlugInTests = Module(name: "MousePlugInTests")
static let objectLinkPlugInTests = Module(name: "ObjectLinkPlugInTests")
static let scenePlugInTests = Module(name: "ScenePlugInTests")
static let scrollPlugInTests = Module(name: "ScrollPlugInTests")
}

extension Target {
static func target(module: Module, dependencies: [Module]) -> Target {
.target(
name: module.name,
dependencies: dependencies.map { $0.dependency },
path: module.path)
}

static func testTarget(module: Module, dependencies: [Module]) -> Target {
.testTarget(
name: module.name,
dependencies: dependencies.map { $0.dependency },
path: module.path
)
}
}

let package = Package(
name: "ECS_Swift",
platforms: [.macOS(.v10_15)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
Expand All @@ -45,6 +65,7 @@ let package = Package(
.library(
name: Module.plugIns.name,
targets: [
Module.graphic2d.name,
Module.keyboard.name,
Module.mouse.name,
Module.objectLink.name,
Expand All @@ -60,45 +81,46 @@ let package = Package(
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: Module.ecs.name,
module: .ecs,
dependencies: []),
.target(
name: Module.keyboard.name,
dependencies: [Module.ecs.dependency],
path: Module.keyboard.path),
module: .graphic2d,
dependencies: [.ecs]),
.target(
name: Module.mouse.name,
dependencies: [Module.ecs.dependency],
path: Module.mouse.path),
module: .keyboard,
dependencies: [.ecs]),
.target(
name: Module.objectLink.name,
dependencies: [Module.ecs.dependency],
path: Module.objectLink.path),
module: .mouse,
dependencies: [.ecs]),
.target(
name: Module.scene.name,
dependencies: [Module.ecs.dependency],
path: Module.scene.path),
module: .objectLink,
dependencies: [.ecs]),
.target(
name: Module.scroll.name,
dependencies: [Module.ecs.dependency],
path: Module.scroll.path),
module: .scene,
dependencies: [.ecs]),
.target(
module: .scroll,
dependencies: [.ecs]),
.testTarget(
module: .ecs_swiftTests,
dependencies: [.ecs]),
.testTarget(
name: Module.ecs_swiftTests.name,
dependencies: [Module.ecs.dependency]),
module: .graphicPlugInTests,
dependencies: [.graphic2d]),
.testTarget(
name: Module.keyBoardPlugInTests.name,
dependencies: [Module.keyboard.dependency]),
module: .keyBoardPlugInTests,
dependencies: [.keyboard]),
.testTarget(
name: Module.mousePlugInTests.name,
dependencies: [Module.mouse.dependency]),
module: .mousePlugInTests,
dependencies: [.mouse]),
.testTarget(
name: Module.objectLinkPlugInTests.name,
dependencies: [Module.objectLink.dependency]),
module: .objectLinkPlugInTests,
dependencies: [.objectLink]),
.testTarget(
name: Module.scenePlugInTests.name,
dependencies: [Module.scene.dependency]),
module: .scenePlugInTests,
dependencies: [.scene]),
.testTarget(
name: Module.scrollPlugInTests.name,
dependencies: [Module.scroll.dependency]),
module: .scrollPlugInTests,
dependencies: [.scroll]),
]
)
8 changes: 6 additions & 2 deletions Sources/ECS/Chunk/Chunk.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//
// File.swift
// Chunk.swift
//
//
// Created by rrbox on 2023/08/11.
//

import Foundation
public class Chunk {
func spawn(entity: Entity, entityRecord: EntityRecord) {}
func despawn(entity: Entity) {}
func applyCurrentState(_ entityRecord: EntityRecord, forEntity entity: Entity) {}
}
9 changes: 7 additions & 2 deletions Sources/ECS/Chunk/ChunkBuffer+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extension ChunkBuffer {
self.buffer.component(ofType: ChunkEntityInterface.self)!.add(chunk: chunk)
}

func push(entity: Entity, value: Archetype) {
self.buffer.component(ofType: ChunkEntityInterface.self)!.push(entity: entity, value: value)
func push(entity: Entity, entityRecord: EntityRecord) {
self.buffer.component(ofType: ChunkEntityInterface.self)!.push(entity: entity, entityRecord: entityRecord)
}

func applyEntityQueue() {
Expand All @@ -27,4 +27,9 @@ extension ChunkBuffer {
self.buffer.component(ofType: ChunkEntityInterface.self)!.despawn(entity: entity)
}

// entity を最新の状態に更新します.
func applyCurrentState(_ entityRecord: EntityRecord, forEntity entity: Entity) {
self.buffer.component(ofType: ChunkEntityInterface.self)!.applyCurrentState(entityRecord, forEntity: entity)
}

}
32 changes: 31 additions & 1 deletion Sources/ECS/Chunk/ChunkBuffer.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
//
// File.swift
// ChunkBuffer.swift
//
//
// Created by rrbox on 2023/08/11.
//

import Foundation

/// Chunk を種類別で格納します
final public class ChunkBuffer {
class ChunkRegistry<ChunkType: Chunk>: BufferElement {
let chunk: ChunkType
init(chunk: ChunkType) {
self.chunk = chunk
super.init()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

let buffer: Buffer
init(buffer: Buffer) {
self.buffer = buffer
}

public func chunk<ChunkType: Chunk>(ofType type: ChunkType.Type) -> ChunkType? {
self.buffer.component(ofType: ChunkRegistry<ChunkType>.self)?.chunk
}
}

public extension WorldBuffer {
var chunkBuffer: ChunkBuffer {
ChunkBuffer(buffer: self)
}
}
57 changes: 57 additions & 0 deletions Sources/ECS/Chunk/ChunkEntityInterface.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// ChunkEntityInterface.swift
//
//
// Created by rrbox on 2023/08/11.
//

/// Chunk を種類関係なく格納するためのコンポーネントです.
///
/// Entity の変更を全ての Chunk に反映させる目的で使用されます.
class ChunkEntityInterface: BufferElement {
/// entity が spawn されてから component が完全に挿入されるまでの間, entity を queue に保管します.
///
/// Entity が ``Commands/spawn()`` され, ``EntityCommands/addComponent(_:)`` されるまでの間, Entity は実際には Chunk に反映されず,
var prespawnedEntityQueue = [(Entity, EntityRecord)]()
var chunks = [Chunk]()

/// chunk を追加します
func add(chunk: Chunk) {
self.chunks.append(chunk)
}

/// World に entity が追加された時に実行します.
///
/// entity が queue に追加され、フレームの終わりに全ての chunk に entity を反映します.
func push(entity: Entity, entityRecord: EntityRecord) {
self.prespawnedEntityQueue.append((entity, entityRecord))
}

/// Spawn 処理された entity を, 実際に chunk に追加します.
///
/// Component が完全に追加された後にこの処理を呼び出すことで, Entity の Component の有無が Chunk に反映されるようになります.
func applyEntityQueue() {
for (entity, entityRecord) in prespawnedEntityQueue {
for chunk in self.chunks {
chunk.spawn(entity: entity, entityRecord: entityRecord)
}
}
self.prespawnedEntityQueue = []
}

/// World から entity が削除される時に実行します.
///
/// フレームの終わりに全ての chunk から entity を削除します.
func despawn(entity: Entity) {
for chunk in self.chunks {
chunk.despawn(entity: entity)
}
}

func applyCurrentState(_ entityRecord: EntityRecord, forEntity entity: Entity) {
for chunk in self.chunks {
chunk.applyCurrentState(entityRecord, forEntity: entity)
}
}

}
50 changes: 0 additions & 50 deletions Sources/ECS/Chunk/Spawn+Chunk.swift

This file was deleted.

Loading