-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix matrix update, add globaltransform
- Loading branch information
1 parent
79e425e
commit 01766e2
Showing
13 changed files
with
211 additions
and
66 deletions.
There are no files selected for viewing
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
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,100 @@ | ||
// | ||
// StressExampleScene.swift | ||
// | ||
// | ||
// Created by Vladislav Prusakov on 06.06.2024. | ||
// | ||
|
||
import AdaEngine | ||
|
||
class ManySpritesExampleScene: Scene { | ||
override func sceneDidMove(to view: SceneView) { | ||
let tilesImage = try! ResourceManager.loadSync("Assets/tiles_packed.png", from: Bundle.editor) as Image | ||
|
||
let characterAtlas = TextureAtlas(from: tilesImage, size: [18, 18]) | ||
|
||
self.spawnEntityes(atlas: characterAtlas) | ||
|
||
let cameraEntity = OrthographicCamera() | ||
cameraEntity.camera.backgroundColor = Color(135/255, 206/255, 235/255, 1) | ||
cameraEntity.camera.clearFlags = .solid | ||
cameraEntity.camera.orthographicScale = 20 | ||
|
||
self.addEntity(cameraEntity) | ||
self.addSystem(CamMovementSystem.self) | ||
} | ||
|
||
func spawnEntityes(atlas: TextureAtlas) { | ||
let mapSize = Vector2(50) | ||
|
||
let halfX = Int(mapSize.x / 2.0) | ||
let halfY = Int(mapSize.y / 2.0) | ||
|
||
var entities: Int = 0 | ||
|
||
for y in -halfY..<halfY { | ||
for x in -halfX..<halfX { | ||
let position = Vector2(x: Float(x), y: Float(y)) | ||
let translation = Vector3(position, 1) | ||
let rotation = Quat(axis: Vector3(x: 0, y: 0, z: 1), angle: .random(in: 0..<2)) | ||
let scale = Vector3(.random(in: 0.3..<1)) | ||
|
||
let ent = Entity { | ||
Transform(rotation: rotation, scale: scale, position: translation) | ||
SpriteComponent(texture: atlas[Int.random(in: 0..<20), Int.random(in: 0..<9)]) | ||
NoFrustumCulling() | ||
} | ||
|
||
self.addEntity(ent) | ||
|
||
entities += 1 | ||
} | ||
} | ||
|
||
print("Spawned entities", entities) | ||
} | ||
|
||
struct CamMovementSystem: System { | ||
|
||
static let cameraQuery = EntityQuery(where: .has(Camera.self) && .has(Transform.self)) | ||
|
||
init(scene: Scene) { } | ||
|
||
func update(context: UpdateContext) { | ||
let cameraEntity: Entity = context.scene.performQuery(Self.cameraQuery).first! | ||
|
||
var (camera, cameraTransform) = cameraEntity.components[Camera.self, Transform.self] | ||
|
||
let speed: Float = Input.isKeyPressed(.space) ? 13 : 7 | ||
let speedNormalized: Float = speed * context.deltaTime | ||
|
||
if Input.isKeyPressed(.w) { | ||
cameraTransform.position.y += speedNormalized | ||
} | ||
|
||
if Input.isKeyPressed(.s) { | ||
cameraTransform.position.y -= speedNormalized | ||
} | ||
|
||
if Input.isKeyPressed(.a) { | ||
cameraTransform.position.x -= speedNormalized | ||
} | ||
|
||
if Input.isKeyPressed(.d) { | ||
cameraTransform.position.x += speedNormalized | ||
} | ||
|
||
if Input.isKeyPressed(.arrowUp) { | ||
camera.orthographicScale -= speedNormalized | ||
} | ||
|
||
if Input.isKeyPressed(.arrowDown) { | ||
camera.orthographicScale += speedNormalized | ||
} | ||
|
||
cameraEntity.components += cameraTransform | ||
cameraEntity.components += camera | ||
} | ||
} | ||
|
||
} |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.