Skip to content

Commit

Permalink
Prepare iron to c port
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Jan 29, 2024
1 parent 270ceaa commit 6b06036
Show file tree
Hide file tree
Showing 13 changed files with 356 additions and 539 deletions.
4 changes: 2 additions & 2 deletions Sources/iron/Animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Animation {
static vs = new Vec4();

constructor() {
Scene.active.animations.push(this);
Scene.animations.push(this);
}

playSuper = (action = "", onComplete: ()=>void = null, blendTime = 0.0, speed = 1.0, loop = true) => {
Expand Down Expand Up @@ -77,7 +77,7 @@ class Animation {
}

remove = () => {
array_remove(Scene.active.animations, this);
array_remove(Scene.animations, this);
}

updateSuper = (delta: f32) => {
Expand Down
12 changes: 6 additions & 6 deletions Sources/iron/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class App {
}

static update = () => {
if (Scene.active == null || !Scene.active.ready) return;
if (!Scene.ready) return;
if (App.pauseUpdates) return;

Scene.active.updateFrame();
Scene.updateFrame();

let i = 0;
let l = App.traitUpdates.length;
Expand Down Expand Up @@ -74,8 +74,8 @@ class App {
if (App.lastw != App.w() || App.lasth != App.h()) {
if (App.onResize != null) App.onResize();
else {
if (Scene.active != null && Scene.active.camera != null) {
Scene.active.camera.buildProjection();
if (Scene.camera != null) {
Scene.camera.buildProjection();
}
}
}
Expand All @@ -88,7 +88,7 @@ class App {

Time.update();

if (Scene.active == null || !Scene.active.ready) {
if (!Scene.ready) {
App.render2D(g2);
return;
}
Expand All @@ -101,7 +101,7 @@ class App {
App.traitInits.splice(0, App.traitInits.length);
}

Scene.active.renderFrame(g4);
Scene.renderFrame(g4);

for (let f of App.traitRenders) {
if (App.traitRenders.length > 0) f(g4);
Expand Down
10 changes: 5 additions & 5 deletions Sources/iron/BaseObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BaseObject {
this.uid = BaseObject.uidCounter++;
this.transform = new Transform(this);
this.isEmpty = this.constructor == BaseObject;
if (this.isEmpty && Scene.active != null) Scene.active.empties.push(this);
if (this.isEmpty && Scene.ready) Scene.empties.push(this);
}

setParent = (parentObject: BaseObject, parentInverse = false, keepTransform = false) => {
Expand All @@ -35,15 +35,15 @@ class BaseObject {
}

if (parentObject == null) {
parentObject = Scene.active.sceneParent;
parentObject = Scene.sceneParent;
}
this.parent = parentObject;
this.parent.children.push(this);
if (parentInverse) this.transform.applyParentInverse();
}

removeSuper = () => {
if (this.isEmpty && Scene.active != null) array_remove(Scene.active.empties, this);
if (this.isEmpty && Scene.ready) array_remove(Scene.empties, this);
if (this.animation != null) this.animation.remove();
while (this.children.length > 0) this.children[0].remove();
if (this.parent != null) {
Expand Down Expand Up @@ -77,7 +77,7 @@ class BaseObject {

///if arm_skin
getParentArmature = (name: string): BoneAnimation => {
for (let a of Scene.active.animations) if (a.armature != null && a.armature.name == name) return a as BoneAnimation;
for (let a of Scene.animations) if (a.armature != null && a.armature.name == name) return a as BoneAnimation;
return null;
}
///end
Expand All @@ -86,7 +86,7 @@ class BaseObject {
// Parented to bone
///if arm_skin
if (this.raw.parent_bone != null) {
Scene.active.notifyOnInit(() => {
Scene.notifyOnInit(() => {
let banim = this.getParentArmature(this.parent.name);
if (banim != null) banim.addBoneChild(this.raw.parent_bone, this);
});
Expand Down
2 changes: 1 addition & 1 deletion Sources/iron/BoneAnimation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BoneAnimation extends Animation {
constructor(armatureName = "") {
super();
this.isSampled = false;
for (let a of Scene.active.armatures) {
for (let a of Scene.armatures) {
if (a.name == armatureName) {
this.armature = a;
break;
Expand Down
13 changes: 5 additions & 8 deletions Sources/iron/CameraObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CameraObject extends BaseObject {
for (let i = 0; i < 6; ++i) this.frustumPlanes.push(new FrustumPlane());
}

Scene.active.cameras.push(this);
Scene.cameras.push(this);
}

buildProjection = (screenAspect: Null<f32> = null) => {
Expand All @@ -51,24 +51,21 @@ class CameraObject extends BaseObject {
}

override remove = () => {
array_remove(Scene.active.cameras, this);
array_remove(Scene.cameras, this);
// if (renderTarget != null) renderTarget.unload();
this.removeSuper();
}

renderFrame = (g: Graphics4) => {
this.projectionJitter();

this.buildMatrix();

RenderPath.active.renderFrame(g);

RenderPath.renderFrame(g);
this.prevV.setFrom(this.V);
}

projectionJitter = () => {
let w = RenderPath.active.currentW;
let h = RenderPath.active.currentH;
let w = RenderPath.currentW;
let h = RenderPath.currentH;
this.P.setFrom(this.noJitterP);
let x = 0.0;
let y = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion Sources/iron/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Data {
Data.cachedMaterials = new Map();
Data.cachedParticles = new Map();
Data.cachedWorlds = new Map();
if (RenderPath.active != null) RenderPath.active.unload();
RenderPath.unload();

Data.cachedBlobs = new Map();
for (let c of Data.cachedImages.values()) c.unload();
Expand Down
11 changes: 5 additions & 6 deletions Sources/iron/LightObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ class LightObject extends BaseObject {
this.P = Mat4.persp(fov, 1, data.near_plane, data.far_plane);
}

Scene.active.lights.push(this);
Scene.lights.push(this);
}

override remove = () => {
if (Scene.active != null) array_remove(Scene.active.lights, this);
let rp = RenderPath.active;
if (rp.light == this) { rp.light = null; }
if (rp.point == this) { rp.point = null; }
else if (rp.sun == this) { rp.sun = null; }
array_remove(Scene.lights, this);
if (RenderPath.light == this) { RenderPath.light = null; }
if (RenderPath.point == this) { RenderPath.point = null; }
else if (RenderPath.sun == this) { RenderPath.sun = null; }
this.removeSuper();
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/iron/MeshObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MeshObject extends BaseObject {

this.materials = materials;
this.setData(data);
Scene.active.meshes.push(this);
Scene.meshes.push(this);
}

setData = (data: MeshData) => {
Expand All @@ -46,7 +46,7 @@ class MeshObject extends BaseObject {
this.particleSystems = null;
}
///end
if (Scene.active != null) array_remove(Scene.active.meshes, this);
array_remove(Scene.meshes, this);
this.data.refcount--;
this.removeSuper();
}
Expand Down Expand Up @@ -143,7 +143,7 @@ class MeshObject extends BaseObject {
render = (g: Graphics4, context: string, bindParams: string[]) => {
if (this.data == null || !this.data.ready) return; // Data not yet streamed
if (!this.visible) return; // Skip render if object is hidden
if (this.cullMesh(context, Scene.active.camera, RenderPath.active.light)) return;
if (this.cullMesh(context, Scene.camera, RenderPath.light)) return;
let meshContext = this.raw != null ? context == "mesh" : false;

///if arm_particles
Expand All @@ -152,8 +152,8 @@ class MeshObject extends BaseObject {
if (this.particleChildren == null) {
this.particleChildren = [];
for (let psys of this.particleSystems) {
// let c: MeshObject = Scene.active.getChild(psys.data.raw.instance_object);
Scene.active.spawnObject(psys.data.instance_object, null, (o: BaseObject) => {
// let c: MeshObject = Scene.getChild(psys.data.raw.instance_object);
Scene.spawnObject(psys.data.instance_object, null, (o: BaseObject) => {
if (o != null) {
let c: MeshObject = o as MeshObject;
this.particleChildren.push(c);
Expand Down
Loading

0 comments on commit 6b06036

Please sign in to comment.