Files
armorpaint/Sources/Main.hx
T

113 lines
2.8 KiB
Haxe
Raw Normal View History

2019-12-09 00:28:10 +01:00
package;
2019-06-22 00:25:38 +02:00
import kha.Window;
import kha.WindowOptions;
import kha.WindowMode;
import kha.System;
2019-08-21 11:53:56 +02:00
import iron.object.Object;
2019-06-22 00:25:38 +02:00
import iron.Scene;
import iron.RenderPath;
import arm.render.Inc;
2020-04-27 14:01:45 +02:00
import arm.render.RenderPathForward;
2019-06-22 00:25:38 +02:00
import arm.render.RenderPathDeferred;
2019-08-25 21:21:56 +02:00
import arm.render.Uniforms;
2020-03-26 17:52:56 +01:00
import arm.util.BuildMacros;
2019-06-22 00:25:38 +02:00
import arm.Config;
2020-04-27 14:01:45 +02:00
import arm.Context;
2020-08-07 15:22:56 +02:00
#if arm_vr
import arm.render.RenderPathForwardVR;
#end
2019-06-22 00:25:38 +02:00
2019-05-25 20:15:08 +02:00
class Main {
2019-10-06 19:03:59 +02:00
2020-03-18 20:26:28 +01:00
public static var version = "0.8";
2020-03-26 17:52:56 +01:00
public static var sha = BuildMacros.sha().substr(1, 7);
public static var date = BuildMacros.date().split(" ")[0];
2020-03-18 20:26:28 +01:00
2019-12-09 00:28:10 +01:00
static var tasks: Int;
2019-06-22 00:25:38 +02:00
2020-11-03 15:19:41 +01:00
// Generating snapshot
2019-06-22 00:25:38 +02:00
public static function main() {
2020-11-03 15:19:41 +01:00
js.Syntax.code("globalThis.kickstart = Main.kickstart");
}
// Program startup
@:keep
public static function kickstart() {
2020-03-18 20:26:28 +01:00
// Used to locate external application data folder
2020-01-24 12:51:18 +01:00
Krom.setApplicationName("ArmorPaint");
2020-03-18 20:26:28 +01:00
2019-06-22 00:25:38 +02:00
tasks = 1;
2019-08-21 11:53:56 +02:00
tasks++; Config.load(function() { tasks--; start(); });
2019-12-03 00:25:38 +01:00
#if arm_physics
2020-03-18 20:26:28 +01:00
tasks++; arm.plugin.PhysicsWorld.load();
2019-12-03 00:25:38 +01:00
#end
2019-06-22 00:25:38 +02:00
tasks--; start();
}
static function start() {
if (tasks > 0) return;
2019-10-06 19:03:59 +02:00
2020-01-21 09:49:13 +01:00
Config.init();
2019-06-22 00:25:38 +02:00
var c = Config.raw;
2020-03-18 20:26:28 +01:00
2019-06-22 00:25:38 +02:00
var windowMode = c.window_mode == 0 ? WindowMode.Windowed : WindowMode.Fullscreen;
var windowFeatures = None;
if (c.window_resizable) windowFeatures |= FeatureResizable;
if (c.window_maximizable) windowFeatures |= FeatureMaximizable;
if (c.window_minimizable) windowFeatures |= FeatureMinimizable;
2020-01-24 12:51:18 +01:00
var title = "untitled - ArmorPaint";
2019-12-09 00:28:10 +01:00
var options: kha.SystemOptions = {
title: title,
window: {
width: c.window_w,
height: c.window_h,
x: c.window_x,
y: c.window_y,
mode: windowMode,
windowFeatures: windowFeatures
},
framebuffer: {
samplesPerPixel: 1,
2020-06-30 17:41:22 +02:00
verticalSync: c.window_vsync,
frequency: c.window_frequency
2019-12-09 00:28:10 +01:00
}
};
System.start(options, function(window: Window) {
2020-09-07 14:44:01 +02:00
if (Config.raw.layout == null) Config.initLayout();
2020-01-24 12:51:18 +01:00
Krom.setApplicationName("ArmorPaint");
2019-06-22 00:25:38 +02:00
iron.App.init(function() {
2019-12-09 00:28:10 +01:00
Scene.setActive("Scene", function(o: Object) {
2019-08-25 21:21:56 +02:00
Uniforms.init();
2019-08-22 12:05:03 +02:00
var path = new RenderPath();
Inc.init(path);
2020-04-27 14:01:45 +02:00
2020-08-07 15:22:56 +02:00
#if arm_vr
RenderPathDeferred.init(path); // Allocate gbuffer
RenderPathForward.init(path);
RenderPathForwardVR.init(path);
path.commands = RenderPathForwardVR.commands;
#else
2020-04-27 14:01:45 +02:00
if (Context.renderMode == RenderForward) {
RenderPathDeferred.init(path); // Allocate gbuffer
RenderPathForward.init(path);
path.commands = RenderPathForward.commands;
}
else {
RenderPathDeferred.init(path);
path.commands = RenderPathDeferred.commands;
}
2020-08-07 15:22:56 +02:00
#end
2020-04-27 14:01:45 +02:00
2019-08-22 12:05:03 +02:00
RenderPath.setActive(path);
new arm.App();
2019-12-03 00:25:38 +01:00
#if arm_physics
o.addTrait(new arm.plugin.PhysicsWorld());
#end
2019-06-22 00:25:38 +02:00
});
});
});
}
2019-05-25 20:15:08 +02:00
}