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 Dec 12, 2023
1 parent 9253cc5 commit 654a101
Show file tree
Hide file tree
Showing 43 changed files with 441 additions and 550 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package iron.object;
package iron;

import js.lib.Uint32Array;
import iron.math.Vec4;
import iron.math.Mat4;
import iron.math.Quat;
import iron.data.SceneFormat;
import iron.SceneFormat;

class Animation {

public var isSkinned: Bool;
public var isSampled: Bool;
public var action = "";
#if arm_skin
public var armature: iron.data.Armature; // Bone
public var armature: iron.Armature; // Bone
#end

// Lerp
Expand Down
2 changes: 1 addition & 1 deletion Sources/iron/App.hx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class App {
static function render(g2: Graphics2, g4: Graphics4) {
update();

iron.system.Time.update();
Time.update();

if (Scene.active == null || !Scene.active.ready) {
render2D(g2);
Expand Down
2 changes: 1 addition & 1 deletion Sources/iron/system/ArmPack.hx → Sources/iron/ArmPack.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package iron.system;
package iron;

import js.lib.ArrayBuffer;
import js.lib.DataView;
Expand Down
6 changes: 3 additions & 3 deletions Sources/iron/data/Armature.hx → Sources/iron/Armature.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package iron.data;
package iron;

#if arm_skin

import iron.data.SceneFormat;
import iron.math.Mat4;
import iron.SceneFormat;
import iron.Mat4;

class Armature {
public var uid: Int;
Expand Down
10 changes: 6 additions & 4 deletions Sources/iron/system/Audio.hx → Sources/iron/Audio.hx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package iron.system;
package iron;

import iron.System;

#if arm_audio

class Audio {
public static function play(sound: kha.System.Sound, loop = false, stream = false): AudioChannel {
public static function play(sound: Sound, loop = false, stream = false): AudioChannel {
var channel = new AudioChannel(sound, loop);
channel.play();
return channel;
}
}

class AudioChannel {
var sound: kha.System.Sound;
var sound: Sound;
var loop: Bool;

public function new(sound: kha.System.Sound, loop: Bool) {
public function new(sound: Sound, loop: Bool) {
this.sound = sound;
this.loop = loop;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
package iron.object;
package iron;

#if arm_skin

import js.lib.Float32Array;
import iron.math.Vec4;
import iron.math.Mat4;
import iron.math.Quat;
import iron.data.MeshData;
import iron.data.SceneFormat;
import iron.data.Armature;
import iron.data.Data;
import iron.math.Ray;
import iron.SceneFormat;

class BoneAnimation extends Animation {

Expand Down Expand Up @@ -108,7 +101,6 @@ class BoneAnimation extends Animation {
}
}

@:access(iron.object.Transform)
function updateBoneChildren(bone: TObj, bm: Mat4) {
var ar = boneChildren.get(bone.name);
if (ar == null) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package iron.data;
package iron;

import iron.data.SceneFormat;
import iron.SceneFormat;

class CameraData {

Expand All @@ -17,7 +17,7 @@ class CameraData {
Data.getSceneRaw(name, function(format: TSceneFormat) {
var raw: TCameraData = Data.getCameraRawByName(format.camera_datas, id);
if (raw == null) {
trace('Camera data "$id" not found!');
Krom.log('Camera data "$id" not found!');
done(null);
}
new CameraData(raw, done);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package iron.object;
package iron;

import iron.System;
import iron.Scene;
import iron.RenderPath;
import iron.math.Mat4;
import iron.math.Vec4;
import iron.math.Quat;
import iron.data.CameraData;

class CameraObject extends Object {

public var data: CameraData;
public var P: Mat4;
public var noJitterP = Mat4.identity();
var frame = 0;
public var frame = 0;
public var V: Mat4;
public var prevV: Mat4 = null;
public var VP: Mat4;
Expand Down Expand Up @@ -50,7 +44,7 @@ class CameraObject extends Object {
P = Mat4.ortho(data.raw.ortho[0], data.raw.ortho[1], data.raw.ortho[2], data.raw.ortho[3], data.raw.near_plane, data.raw.far_plane);
}
else {
if (screenAspect == null) screenAspect = iron.App.w() / iron.App.h();
if (screenAspect == null) screenAspect = App.w() / App.h();
var aspect = data.raw.aspect != null ? data.raw.aspect : screenAspect;
P = Mat4.persp(data.raw.fov, aspect, data.raw.near_plane, data.raw.far_plane);
}
Expand All @@ -73,7 +67,7 @@ class CameraObject extends Object {
prevV.setFrom(V);
}

function projectionJitter() {
public function projectionJitter() {
var w = RenderPath.active.currentW;
var h = RenderPath.active.currentH;
P.setFrom(noJitterP);
Expand Down
17 changes: 16 additions & 1 deletion Sources/iron/data/ConstData.hx → Sources/iron/ConstData.hx

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions Sources/iron/data/Data.hx → Sources/iron/Data.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package iron.data;
package iron;

import haxe.Json;
import iron.data.SceneFormat;
import iron.system.ArmPack;
import iron.system.Lz4;
import iron.SceneFormat;
import iron.System;
using StringTools;

Expand Down
49 changes: 24 additions & 25 deletions Sources/iron/system/Input.hx → Sources/iron/Input.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package iron.system;
package iron;

import iron.System;
import iron.system.Input.KeyCode;

class Input {

Expand Down Expand Up @@ -83,16 +82,16 @@ class Mouse {
var buttonsStarted = [false, false, false, false, false];
var buttonsReleased = [false, false, false, false, false];

public var x(default, null) = 0.0;
public var y(default, null) = 0.0;
public var x = 0.0;
public var y = 0.0;
public var viewX(get, null) = 0.0;
public var viewY(get, null) = 0.0;
public var moved(default, null) = false;
public var movementX(default, null) = 0.0;
public var movementY(default, null) = 0.0;
public var wheelDelta(default, null) = 0.0;
public var locked(default, null) = false;
public var hidden(default, null) = false;
public var moved = false;
public var movementX = 0.0;
public var movementY = 0.0;
public var wheelDelta = 0.0;
public var locked = false;
public var hidden = false;
public var lastX = -1.0;
public var lastY = -1.0;

Expand Down Expand Up @@ -255,11 +254,11 @@ class Mouse {
#end

inline function get_viewX(): Float {
return x - iron.App.x();
return x - App.x();
}

inline function get_viewY(): Float {
return y - iron.App.y();
return y - App.y();
}
}

Expand All @@ -270,14 +269,14 @@ class Pen {
var buttonsStarted = [false];
var buttonsReleased = [false];

public var x(default, null) = 0.0;
public var y(default, null) = 0.0;
public var x = 0.0;
public var y = 0.0;
public var viewX(get, null) = 0.0;
public var viewY(get, null) = 0.0;
public var moved(default, null) = false;
public var movementX(default, null) = 0.0;
public var movementY(default, null) = 0.0;
public var pressure(default, null) = 0.0;
public var moved = false;
public var movementX = 0.0;
public var movementY = 0.0;
public var pressure = 0.0;
public var connected = false;
public var inUse = false;
var lastX = -1.0;
Expand Down Expand Up @@ -323,7 +322,7 @@ class Pen {
this.pressure = pressure;

#if (!krom_android && !krom_ios)
@:privateAccess Input.getMouse().downListener(0, x, y);
Input.getMouse().downListener(0, x, y);
#end
}

Expand All @@ -339,7 +338,7 @@ class Pen {
this.pressure = pressure;

#if (!krom_android && !krom_ios)
@:privateAccess Input.getMouse().upListener(0, x, y);
Input.getMouse().upListener(0, x, y);
inUse = true; // On pen release, additional mouse down & up events are fired at once - filter those out
#end
}
Expand All @@ -349,7 +348,7 @@ class Pen {
// Listen to pen hover if no other input is active
if (!buttonsDown[0] && pressure == 0.0) {
if (!Input.getMouse().downAny()) {
@:privateAccess Input.getMouse().moveListener(x, y, 0, 0);
Input.getMouse().moveListener(x, y, 0, 0);
}
return;
}
Expand All @@ -371,11 +370,11 @@ class Pen {
}

inline function get_viewX(): Float {
return x - iron.App.x();
return x - App.x();
}

inline function get_viewY(): Float {
return y - iron.App.y();
return y - App.y();
}
}

Expand Down Expand Up @@ -540,7 +539,7 @@ class Keyboard {
#if krom_android_rmb // Detect right mouse button on Android..
if (code == KeyCode.Back) {
var m = Input.getMouse();
@:privateAccess if (!m.buttonsDown[1]) m.downListener(1, Std.int(m.x), Std.int(m.y));
if (!m.buttonsDown[1]) m.downListener(1, Std.int(m.x), Std.int(m.y));
}
#end
}
Expand All @@ -554,7 +553,7 @@ class Keyboard {
#if krom_android_rmb
if (code == KeyCode.Back) {
var m = Input.getMouse();
@:privateAccess m.upListener(1, Std.int(m.x), Std.int(m.y));
m.upListener(1, Std.int(m.x), Std.int(m.y));
}
#end
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/iron/data/LightData.hx → Sources/iron/LightData.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package iron.data;
package iron;

import iron.data.SceneFormat;
import iron.SceneFormat;

class LightData {

Expand All @@ -27,7 +27,7 @@ class LightData {
Data.getSceneRaw(name, function(format: TSceneFormat) {
var raw: TLightData = Data.getLightRawByName(format.light_datas, id);
if (raw == null) {
trace('Light data "$id" not found!');
Krom.log('Light data "$id" not found!');
done(null);
}
new LightData(raw, done);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package iron.object;
package iron;

import js.lib.Float32Array;
import iron.System;
import iron.math.Mat4;
import iron.math.Vec4;
import iron.data.LightData;
import iron.object.CameraObject;
import iron.CameraObject;

class LightObject extends Object {

Expand Down
4 changes: 2 additions & 2 deletions Sources/iron/system/Lz4.hx → Sources/iron/Lz4.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package iron.system;
package iron;

import js.lib.Int32Array;
import js.lib.Uint8Array;
Expand All @@ -37,7 +37,7 @@ class Lz4 {
var iBuf = new Uint8Array(b);
var iLen = iBuf.length;
if (iLen >= 0x7e000000) {
trace("LZ4 range error");
Krom.log("LZ4 range error");
return null;
}

Expand Down
Loading

0 comments on commit 654a101

Please sign in to comment.