Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
soft reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
e2002e committed Feb 14, 2024
1 parent c00bce9 commit 781859c
Show file tree
Hide file tree
Showing 30 changed files with 549 additions and 327 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/krom.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Krom

on: [push]
on:
push:
pull_request:

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![](https://armory3d.org/img/iron.jpg)
![](https://armory3d.org/git/iron.jpg)

iron
==============
Expand Down
19 changes: 4 additions & 15 deletions Sources/iron/App.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@ package iron;

class App {

#if arm_appwh
public static inline function w(): Int { return arm.App.w(); }
public static inline function h(): Int { return arm.App.h(); }
public static inline function x(): Int { return arm.App.x(); }
public static inline function y(): Int { return arm.App.y(); }
#else
public static inline function w(): Int { return kha.System.windowWidth(); }
public static inline function h(): Int { return kha.System.windowHeight(); }
public static inline function x(): Int { return 0; }
public static inline function y(): Int { return 0; }
#end
public static dynamic function w(): Int { return kha.System.windowWidth(); }
public static dynamic function h(): Int { return kha.System.windowHeight(); }
public static dynamic function x(): Int { return 0; }
public static dynamic function y(): Int { return 0; }

static var onResets: Array<Void->Void> = null;
static var onEndFrames: Array<Void->Void> = null;
Expand All @@ -30,11 +23,9 @@ class App {
public static var renderPathTime: Float;
public static var endFrameCallbacks: Array<Void->Void> = [];
#end
#if arm_resizable
static var lastw = -1;
static var lasth = -1;
public static var onResize: Void->Void = null;
#end

public static function init(done: Void->Void) {
new App(done);
Expand Down Expand Up @@ -94,7 +85,6 @@ class App {
updateTime = kha.Scheduler.realTime() - startTime;
#end

#if arm_resizable
// Rebuild projection on window resize
if (lastw == -1) {
lastw = App.w();
Expand All @@ -110,7 +100,6 @@ class App {
}
lastw = App.w();
lasth = App.h();
#end
}

static function render(frames: Array<kha.Framebuffer>) {
Expand Down
31 changes: 2 additions & 29 deletions Sources/iron/RenderPath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ class RenderPath {
public var currentW: Int;
public var currentH: Int;
public var currentD: Int;
#if kha_metal
public var clearShader: String = null;
public var clearColor: kha.Color = 0xff000000;
#end
var lastW = 0;
var lastH = 0;
var bindParams: Array<String>;
Expand All @@ -69,12 +65,12 @@ class RenderPath {
var depthBuffers: Array<{name: String, format: String}> = [];
var additionalTargets: Array<kha.Canvas>;

#if (rp_voxels != "Off")
#if rp_voxels
public var voxelized = 0;
public var onVoxelize: Void->Bool = null;
public function voxelize() { // Returns true if scene should be voxelized
if (onVoxelize != null) return onVoxelize();
#if arm_voxelgi_revoxelize
#if arm_voxelgi_revox
return true;
#else
return ++voxelized > 2 ? false : true;
Expand All @@ -100,11 +96,9 @@ class RenderPath {
public function renderFrame(g: Graphics) {
if (!ready || paused || iron.App.w() == 0 || iron.App.h() == 0) return;

#if arm_resizable
if (lastW > 0 && (lastW != iron.App.w() || lastH != iron.App.h())) resize();
lastW = iron.App.w();
lastH = iron.App.h();
#end

frameTime = Time.time() - lastFrameTime;
lastFrameTime = Time.time();
Expand Down Expand Up @@ -161,12 +155,10 @@ class RenderPath {
currentH = iron.App.h();
if (frameScissor) setFrameScissor();
begin(frameG);
#if arm_appwh
if (!isProbe) {
setCurrentViewport(iron.App.w(), iron.App.h());
setCurrentScissor(iron.App.w(), iron.App.h());
}
#end
}
}
else { // Render target
Expand Down Expand Up @@ -246,22 +238,6 @@ class RenderPath {
}

public function clearTarget(colorFlag: Null<Int> = null, depthFlag: Null<Float> = null) {
#if kha_metal
if (clearShader != null) {
clearColor = colorFlag != null ? colorFlag : 0xff000000;
var ext = "";
if (colorFlag != null) ext += "_color";
if (depthFlag != null) ext += "_depth";
ext += "_" + currentTarget.raw.format.toLowerCase();
var cc: CachedShaderContext = cachedShaderContexts.get(clearShader + ext);
if (ConstData.screenAlignedVB == null) ConstData.createScreenAlignedData();
currentG.setPipeline(cc.context.pipeState);
Uniforms.setContextConstants(currentG, cc.context, bindParams);
currentG.setVertexBuffer(ConstData.screenAlignedVB);
currentG.setIndexBuffer(ConstData.screenAlignedIB);
currentG.drawIndexedVertices();
}
#else
if (colorFlag == -1) { // -1 == 0xffffffff
if (Scene.active.world != null) {
colorFlag = Scene.active.world.raw.background_color;
Expand All @@ -272,7 +248,6 @@ class RenderPath {
}
}
currentG.clear(colorFlag, depthFlag, null);
#end
}

public function clearImage(target: String, color: Int) {
Expand Down Expand Up @@ -719,12 +694,10 @@ class RenderPath {
setFrameScissor();
}
beginStream(frameG);
#if arm_appwh
if (!isProbe) {
setCurrentViewport(iron.App.w(), iron.App.h());
setCurrentScissor(iron.App.w(), iron.App.h());
}
#end
}
}
else { // Render target
Expand Down
30 changes: 17 additions & 13 deletions Sources/iron/Scene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Scene {
Data.getSceneRaw(sceneName, function(format: TSceneFormat) {
Scene.create(format, function(o: Object) {
if (done != null) done(o);
#if (rp_voxels != "Off") // Revoxelize
#if rp_voxels // Revoxelize
RenderPath.active.voxelized = 0;
#end

Expand Down Expand Up @@ -325,7 +325,7 @@ class Scene {
if (g == null) {
g = [];
groups.set(name, g);
var refs = getGroupObjectRefs(name);
var refs = getGroupObjectRefs(name, active.raw);
if (refs == null) return g;
for (ref in refs) {
var c = getChild(ref);
Expand Down Expand Up @@ -573,7 +573,7 @@ class Scene {
var object = addObject(parent);
returnObject(object, o, function(ro: Object) {
if (o.group_ref != null) { // Instantiate group objects
spawnGroup(format, o.group_ref, ro, function() { done(ro); });
spawnGroup(format, o.group_ref, ro, () -> done(ro), () -> done(ro) /* also call done when failed to ensure loading progress */);
}
else done(ro);
});
Expand All @@ -583,9 +583,10 @@ class Scene {

function spawnGroup(format: TSceneFormat, groupRef: String, groupOwner: Object, done: Void->Void, ?failed: Void->Void) {
var spawned = 0;
var object_refs = getGroupObjectRefs(groupRef);
var object_refs = getGroupObjectRefs(groupRef, format);

if (object_refs == null) { // Group doesn't exist
trace('Failed to spawn group "$groupRef", group doesn\'t exist');
if (failed != null) failed();
}
else if (object_refs.length == 0) {
Expand All @@ -597,7 +598,7 @@ class Scene {
spawnObject(object_ref, groupOwner, function(spawnedObject: Object) {
// Apply collection/group instance offset to all
// top-level parents of that group
if (!isObjectInGroup(groupRef, spawnedObject.parent)) {
if (!isObjectInGroup(groupRef, spawnedObject.parent, format)) {
for (group in format.groups) {
if (group.name == groupRef) {
spawnedObject.transform.applyParent();
Expand All @@ -614,7 +615,7 @@ class Scene {
groupOwner.transform.reset();
done();
}
});
}, true, format);
}
}
}
Expand All @@ -623,27 +624,29 @@ class Scene {
Returns all object names of the given group.
Returns `null` if the group does not exist.
@param group_ref The name of the group
@param format The raw scene data
@return `Array<String>`
**/
function getGroupObjectRefs(group_ref: String): Array<String> {
for (g in active.raw.groups) if (g.name == group_ref) return g.object_refs;
function getGroupObjectRefs(group_ref: String, format: TSceneFormat): Array<String> {
for (g in format.groups) if (g.name == group_ref) return g.object_refs;
return null;
}

/**
Returns all objects in scene data format (`TObj`) of the given group.
If the group does not exist or is empty, an empty array is returned.
@param groupRef The name of the group
@param format The raw scene data
@return `Array<TObj>`
**/
function getGroupObjectsRaw(groupRef: String): Array<TObj> {
var objectRefs = getGroupObjectRefs(groupRef);
function getGroupObjectsRaw(groupRef: String, format: TSceneFormat): Array<TObj> {
var objectRefs = getGroupObjectRefs(groupRef, format);
var objects: Array<TObj> = new Array<TObj>();

if (objectRefs == null) return objects;

for (objRef in objectRefs) {
var rawObj = getRawObjectByName(raw, objRef);
var rawObj = getRawObjectByName(format, objRef);
objects.push(rawObj);

var childRefs = getChildObjectsRaw(rawObj);
Expand Down Expand Up @@ -677,10 +680,11 @@ class Scene {
Checks if an object is an element of the given group.
@param groupRef The name of the group
@param object The object
@param format The raw scene data
@return Bool
**/
function isObjectInGroup(groupRef: String, object: Object): Bool {
for (obj in getGroupObjectsRaw(groupRef)) {
function isObjectInGroup(groupRef: String, object: Object, format: TSceneFormat): Bool {
for (obj in getGroupObjectsRaw(groupRef, format)) {
if (obj.name == object.name) {
return true;
}
Expand Down
42 changes: 41 additions & 1 deletion Sources/iron/Trait.hx
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import iron.object.Object;
class Trait {

public var name: String = "";
public var object: Object; // Object this trait belongs to

/**
Object this trait belongs to.
**/
public var object: Object;

var _add: Array<Void->Void> = null;
var _init: Array<Void->Void> = null;
Expand All @@ -17,65 +21,101 @@ class Trait {

public function new() {}

/**
Remove the trait from the object.
**/
public function remove() {
object.removeTrait(this);
}

/**
Trait is added to an object.
**/
public function notifyOnAdd(f: Void->Void) {
if (_add == null) _add = [];
_add.push(f);
}

/**
Object which this trait belongs to is added to scene.
**/
public function notifyOnInit(f: Void->Void) {
if (_init == null) _init = [];
_init.push(f);
App.notifyOnInit(f);
}

/**
Object which this trait belongs to is removed from scene.
**/
public function notifyOnRemove(f: Void->Void) {
if (_remove == null) _remove = [];
_remove.push(f);
}

/**
Add game logic handler.
**/
public function notifyOnUpdate(f: Void->Void) {
if (_update == null) _update = [];
_update.push(f);
App.notifyOnUpdate(f);
}

/**
Remove game logic handler.
**/
public function removeUpdate(f: Void->Void) {
_update.remove(f);
App.removeUpdate(f);
}

/**
Add late game logic handler.
**/
public function notifyOnLateUpdate(f: Void->Void) {
if (_lateUpdate == null) _lateUpdate = [];
_lateUpdate.push(f);
App.notifyOnLateUpdate(f);
}

/**
Remove late game logic handler.
**/
public function removeLateUpdate(f: Void->Void) {
_lateUpdate.remove(f);
App.removeLateUpdate(f);
}

/**
Add render handler.
**/
public function notifyOnRender(f: kha.graphics4.Graphics->Void) {
if (_render == null) _render = [];
_render.push(f);
App.notifyOnRender(f);
}

/**
Remove render handler.
**/
public function removeRender(f: kha.graphics4.Graphics->Void) {
_render.remove(f);
App.removeRender(f);
}

/**
Add 2D render handler.
**/
public function notifyOnRender2D(f: kha.graphics2.Graphics->Void) {
if (_render2D == null) _render2D = [];
_render2D.push(f);
App.notifyOnRender2D(f);
}

/**
Remove 2D render handler.
**/
public function removeRender2D(f: kha.graphics2.Graphics->Void) {
_render2D.remove(f);
App.removeRender2D(f);
Expand Down
2 changes: 1 addition & 1 deletion Sources/iron/data/Data.hx
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ class Data {
}

public static function isAbsolute(file: String): Bool {
return file.charAt(0) == "/" || file.charAt(1) == ":" || (file.charAt(0) == "\\" && file.charAt(1) == "\\");
return file.charAt(0) == "/" || file.charAt(1) == ":" || file.charAt(4) == ":" || (file.charAt(0) == "\\" && file.charAt(1) == "\\");
}

static inline function isUp(file: String): Bool {
Expand Down
Loading

0 comments on commit 781859c

Please sign in to comment.