Skip to content

Commit

Permalink
UI progress
Browse files Browse the repository at this point in the history
  • Loading branch information
STREGA committed Jan 17, 2025
1 parent 1236c0d commit 8ad5964
Show file tree
Hide file tree
Showing 32 changed files with 519 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

public final class Collision2DSystem: System {
public override func update(context: ECSContext, input: HID, withTimePassed deltaTime: Float) async {
for entity in game.entities {
for entity in context.entities {
guard entity.hasComponent(Collision2DComponent.self) else { continue }
guard entity.hasComponent(Transform2Component.self) else { continue }
entity[Collision2DComponent.self].updateColliders(entity.transform2)
}

guard
let quadtreeEntity = game.entities.first(where: {
let quadtreeEntity = context.entities.first(where: {
$0.hasComponent(QuadtreeComponent.self)
})
else {
return
}
let quadtree = quadtreeEntity[QuadtreeComponent.self].quadtree!

for entity in game.entities {
for entity in context.entities {
guard entity.hasComponent(Collision2DComponent.self) else { continue }
if let transformComponent = entity.component(ofType: Transform2Component.self) {
let object = entity[Collision2DComponent.self]
Expand Down Expand Up @@ -69,9 +69,3 @@ public final class Collision2DSystem: System {
public override class var phase: System.Phase { .simulation }
public override class func sortOrder() -> SystemSortOrder? { .collision2DSystem }
}

@MainActor extension Game {
public var collision2DSystem: Collision2DSystem {
return self.system(ofType: Collision2DSystem.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class Physics2DSystem: System {
// Skip Physics if we don't have at least 20 fps
guard deltaTime < 1 / 20 else { return }

for entity in game.entities {
for entity in context.entities {
guard let physicsComponent = entity.component(ofType: Physics2DComponent.self) else {
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public final class SpriteSystem: System {
public override func update(context: ECSContext, input: HID, withTimePassed deltaTime: Float) async {
for entity in game.entities {
for entity in context.entities {
if let spriteComponent = entity.component(ofType: SpriteComponent.self) {
if spriteComponent.moveToNextAnimationIfNeeded {
spriteComponent.moveToNextAnimationIfNeeded = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public final class TileMapSystem: System {
public override func update(context: ECSContext, input: HID, withTimePassed deltaTime: Float) async {
for entity in game.entities {
for entity in context.entities {
if let component = entity.component(ofType: TileMapComponent.self) {
if component.needsSetup {
self.setup(component)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

public final class BillboardSystem: System {
public override func update(context: ECSContext, input: HID, withTimePassed deltaTime: Float) async {
guard let camera = game.cameraEntity else {return}
guard let camera = context.cameraEntity else {return}
let cameraTransform = camera.transform3

for entity in game.entities {
for entity in context.entities {
guard let billboardComponent = entity.component(ofType: BillboardComponent.self) else {continue}
guard let transformComponent = entity.component(ofType: Transform3Component.self) else {continue}

Expand Down
2 changes: 1 addition & 1 deletion Sources/GateEngine/ECS/3D Specific/CameraComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public final class CameraComponent: Component {
public static let componentID: ComponentID = ComponentID()
}

@MainActor extension Game {
@MainActor extension ECSContext {
public var cameraEntity: Entity? {
return self.entities.first(where: {
return $0.component(ofType: CameraComponent.self)?.isActive == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public final class ObjectAnimation3DSystem: System {
var checkedIDs: Set<ObjectIdentifier> = []
func getFarAway(from entities: ContiguousArray<Entity>) -> Entity? {
func getFarAway(from entities: Set<Entity>) -> Entity? {
func filter(_ entity: Entity) -> Bool {
if let objectAnimation = entity.component(ofType: ObjectAnimation3DComponent.self) {
return objectAnimation.disabled == false && objectAnimation.deltaAccumulator > 0
Expand All @@ -30,7 +30,7 @@ public final class ObjectAnimation3DSystem: System {
public override func update(context: ECSContext, input: HID, withTimePassed deltaTime: Float) async {
func shouldAccumulate(entity: Entity) -> Bool {
guard
let cameraTransform = game.cameraEntity?.component(ofType: Transform3Component.self)
let cameraTransform = context.cameraEntity?.component(ofType: Transform3Component.self)
else {
return false
}
Expand Down Expand Up @@ -64,11 +64,11 @@ public final class ObjectAnimation3DSystem: System {
}
}

let slowEntity = getFarAway(from: game.entities)
let slowEntity = getFarAway(from: context.entities)
if let entity = slowEntity {
updateAnimation(for: entity)
}
for entity in game.entities {
for entity in context.entities {
guard entity != slowEntity else { continue }
if let component = entity.component(ofType: ObjectAnimation3DComponent.self),
component.disabled == false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public final class Collision3DSystem: System {
public override func update(context: ECSContext, input: HID, withTimePassed deltaTime: Float) async {
let staticEntities = game.entities.filter({
let staticEntities = context.entities.filter({
guard let collisionComponenet = $0.component(ofType: Collision3DComponent.self) else {return false}
if case .static = collisionComponenet.kind {
return true
Expand All @@ -17,7 +17,7 @@ public final class Collision3DSystem: System {
for entity in staticEntities {
entity.collision3DComponent.updateColliders(entity.transform3)
}
let dynamicEntities = game.entities.filter({
let dynamicEntities = context.entities.filter({
guard let collisionComponenet = $0.component(ofType: Collision3DComponent.self) else {return false}
if case .dynamic(_) = collisionComponenet.kind {
return true
Expand Down Expand Up @@ -526,9 +526,8 @@ extension Collision3DSystem {
}

extension Collision3DSystem {
@_transparent
private var octrees: [OctreeComponent] {
return game.entities.compactMap({ $0.component(ofType: OctreeComponent.self) })
return context.entities.compactMap({ $0.component(ofType: OctreeComponent.self) })
}

@inline(__always)
Expand Down Expand Up @@ -594,7 +593,7 @@ extension Collision3DSystem {
) -> [Entity] {
var entities: [Entity] = []

for entity in game.entities {
for entity in context.entities {
if
let collisionComponent = entity.component(ofType: Collision3DComponent.self),
filter?(entity) ?? true
Expand All @@ -616,7 +615,7 @@ extension Collision3DSystem {
) -> [Entity] {
var entities: [Entity] = []

for entity in game.entities {
for entity in context.entities {
if
let collisionComponent = entity.component(ofType: Collision3DComponent.self),
filter?(entity) ?? true,
Expand Down Expand Up @@ -694,7 +693,7 @@ extension Collision3DSystem {
}
}

@MainActor extension Game {
@MainActor extension ECSContext {
@_transparent
public var collision3DSystem: Collision3DSystem {
return self.system(ofType: Collision3DSystem.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class Physics3DSystem: System {
// Skip Physics if we don't have at least 20 fps
guard deltaTime < 1 / 20 else { return }

for entity in game.entities {
for entity in context.entities {
var deltaTime = deltaTime
if let scale = entity.component(ofType: TimeScaleComponent.self)?.scale {
deltaTime *= scale
Expand Down
14 changes: 7 additions & 7 deletions Sources/GateEngine/ECS/3D Specific/Rig/Rig3DSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class RigSystem {}

public final class Rig3DSystem: System {
var checkedIDs: Set<ObjectIdentifier> = []
func getFarAway(from entities: ContiguousArray<Entity>) -> Entity? {
func getFarAway(from entities: Set<Entity>) -> Entity? {
func filter(_ entity: Entity) -> Bool {
if let rig = entity.component(ofType: Rig3DComponent.self) {
return rig.disabled == false && rig.deltaAccumulator > 0
Expand All @@ -33,7 +33,7 @@ public final class Rig3DSystem: System {
public override func update(context: ECSContext, input: HID, withTimePassed deltaTime: Float) async {
func shouldAccumulate(entity: Entity) -> Bool {
guard
let cameraTransform = game.cameraEntity?.component(ofType: Transform3Component.self)
let cameraTransform = context.cameraEntity?.component(ofType: Transform3Component.self)
else {
return false
}
Expand Down Expand Up @@ -81,11 +81,11 @@ public final class Rig3DSystem: System {
}
}

let slowEntity = getFarAway(from: game.entities)
let slowEntity = getFarAway(from: context.entities)
if let entity = slowEntity {
updateAnimation(for: entity)
}
for entity in game.entities {
for entity in context.entities {
guard entity != slowEntity else { continue }
if let component = entity.component(ofType: Rig3DComponent.self),
component.disabled == false
Expand All @@ -98,7 +98,7 @@ public final class Rig3DSystem: System {
}
}

for entity in game.entities {
for entity in context.entities {
if let rigAttachmentComponent = entity.component(ofType: RigAttachmentComponent.self) {
updateRigAttachmentTransform(
game,
Expand Down Expand Up @@ -127,12 +127,12 @@ public final class Rig3DSystem: System {
rigAttachmentComponent: RigAttachmentComponent
) {
guard
let parent = game.entities.first(where: {
let parent = context.entities.first(where: {
$0.id == rigAttachmentComponent.parentEntityID
})
else {
//If the parent is gone trash the attachment
game.removeEntity(entity)
context.removeEntity(entity)
return
}
guard let parentTransform = parent.component(ofType: Transform3Component.self) else {
Expand Down
Loading

0 comments on commit 8ad5964

Please sign in to comment.