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

Commit

Permalink
Merge branch 'main' into voxelgi
Browse files Browse the repository at this point in the history
  • Loading branch information
e2002e authored Jan 10, 2024
2 parents 784cad7 + f4fd0b2 commit 1465292
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Sources/iron/Scene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ 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
42 changes: 41 additions & 1 deletion Sources/iron/Trait.hx
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/ShaderData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ShaderContext {
public function new(raw: TShaderContext, done: ShaderContext->Void, overrideContext: TShaderOverride = null) {
this.raw = raw;
#if (rp_voxels == "Off")
if (raw.name == "voxel" || raw.name == "voxelbounce") {
if (raw.name == "voxel") {
done(this);
return;
}
Expand Down
14 changes: 8 additions & 6 deletions Sources/iron/object/Tilesheet.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Tilesheet {
}
setFrame(action.start);
paused = false;
time = 0.0;
}

public function pause() {
Expand Down Expand Up @@ -100,16 +101,17 @@ class Tilesheet {
function setFrame(f: Int) {
frame = f;

var tx = frame % raw.tilesx;
var ty = Std.int(frame / raw.tilesx);
tileX = tx * (1 / raw.tilesx);
tileY = ty * (1 / raw.tilesy);

// Action end
if (frame >= action.end && action.start < action.end) {
if (frame > action.end && action.start < action.end) {
if (onActionComplete != null) onActionComplete();
if (action.loop) setFrame(action.start);
else paused = true;
return;
}

var tx = frame % raw.tilesx;
var ty = Std.int(frame / raw.tilesx);
tileX = tx * (1 / raw.tilesx);
tileY = ty * (1 / raw.tilesy);
}
}

0 comments on commit 1465292

Please sign in to comment.