Skip to content

Commit

Permalink
soft reset.
Browse files Browse the repository at this point in the history
  • Loading branch information
e2002e committed Jan 10, 2024
1 parent c00bce9 commit 784cad7
Show file tree
Hide file tree
Showing 29 changed files with 513 additions and 340 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
58 changes: 17 additions & 41 deletions Sources/iron/RenderPath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import iron.object.MeshObject;
import iron.object.Uniforms;

class RenderPath {

public static var active: RenderPath;

public var frameScissor = false;
Expand Down Expand Up @@ -53,10 +52,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,19 +64,6 @@ class RenderPath {
var depthBuffers: Array<{name: String, format: String}> = [];
var additionalTargets: Array<kha.Canvas>;

#if (rp_voxels != "Off")
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
return true;
#else
return ++voxelized > 2 ? false : true;
#end
}
#end

#if arm_debug
public static var drawCalls = 0;
public static var batchBuckets = 0;
Expand All @@ -91,6 +73,23 @@ class RenderPath {
public static var numTrisShadow = 0;
#end

#if (rp_voxels != "Off")
static var voxelized = 0;
public function voxelize() : Bool {
if(iron.Scene.active.camera.transform.diff() && armory.renderpath.RenderPathCreator.clipmapLevel == 0) {
voxelized = 0;
}
else
for (mesh in iron.Scene.active.meshes) {
if (mesh.transform.diff() && armory.renderpath.RenderPathCreator.clipmapLevel == 0) {
voxelized = 0;
break;
}
}
return ++voxelized > Main.voxelgiClipmapCount ? false : true;
}
#end

public static function setActive(renderPath: RenderPath) {
active = renderPath;
}
Expand All @@ -100,11 +99,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 +158,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 +241,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 +251,6 @@ class RenderPath {
}
}
currentG.clear(colorFlag, depthFlag, null);
#end
}

public function clearImage(target: String, color: Int) {
Expand Down Expand Up @@ -719,12 +697,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
32 changes: 17 additions & 15 deletions Sources/iron/Scene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import iron.data.TerrainStream;
import iron.data.SceneStream;
import iron.data.MeshBatch;
import iron.system.Time;

using StringTools;

class Scene {
Expand Down Expand Up @@ -213,9 +214,6 @@ class Scene {
Data.getSceneRaw(sceneName, function(format: TSceneFormat) {
Scene.create(format, function(o: Object) {
if (done != null) done(o);
#if (rp_voxels != "Off") // Revoxelize
RenderPath.active.voxelized = 0;
#end

#if (rp_background == "World")
if (removeWorldShader != null) {
Expand Down Expand Up @@ -325,7 +323,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 +571,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 +581,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 +596,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 +613,7 @@ class Scene {
groupOwner.transform.reset();
done();
}
});
}, true, format);
}
}
}
Expand All @@ -623,27 +622,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 +678,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
Empty file modified Sources/iron/Trait.hx
100755 → 100644
Empty file.
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
5 changes: 4 additions & 1 deletion Sources/iron/data/MeshBatch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class MeshBatch {
m.materials != null &&
m.materials.length == 1 &&
!m.data.geom.instanced &&
!m.data.isSkinned &&
m.data.raw.morph_target == null &&
!m.depthRead;
return batch;
}

public function addMesh(m: MeshObject, isLod: Bool): Bool {
if (!isBatchable(m) || isLod) { // No instancing, multimat or lod batching
// No instancing, multimat, skinning, morph targets or lod batching
if (!isBatchable(m) || isLod) {
nonBatched.push(m);
return false;
}
Expand Down
25 changes: 13 additions & 12 deletions Sources/iron/data/SceneFormat.hx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ typedef TIndexArray = {
#end
public var values: Uint32Array; // size = 3
public var material: Int;
@:optional public var vertex_map: Uint32Array; // size = 3
}

#if js
Expand Down Expand Up @@ -189,12 +190,12 @@ typedef TBindConstant = {
@:structInit class TBindConstant {
#end
public var name: String;
@:optional public var vec4: Float32Array;
@:optional public var vec3: Float32Array;
@:optional public var vec2: Float32Array;
@:optional public var float: Null<FastFloat>;
@:optional public var bool: Null<Bool>;
@:optional public var int: Null<Int>;
@:optional public var vec4Value: Float32Array;
@:optional public var vec3Value: Float32Array;
@:optional public var vec2Value: Float32Array;
@:optional public var floatValue: Null<FastFloat>;
@:optional public var boolValue: Null<Bool>;
@:optional public var intValue: Null<Int>;
}

#if js
Expand Down Expand Up @@ -274,12 +275,12 @@ typedef TShaderConstant = {
public var name: String;
public var type: String;
@:optional public var link: String;
@:optional public var vec4: Float32Array;
@:optional public var vec3: Float32Array;
@:optional public var vec2: Float32Array;
@:optional public var float: Null<FastFloat>;
@:optional public var bool: Null<Bool>;
@:optional public var int: Null<Int>;
@:optional public var vec4Value: Float32Array;
@:optional public var vec3Value: Float32Array;
@:optional public var vec2Value: Float32Array;
@:optional public var floatValue: Null<FastFloat>;
@:optional public var boolValue: Null<Bool>;
@:optional public var intValue: Null<Int>;
@:optional public var is_arm_parameter: Null<Bool>;
}

Expand Down
Loading

0 comments on commit 784cad7

Please sign in to comment.