more console support

This commit is contained in:
RandomityGuy 2022-12-26 22:17:55 +05:30
parent eb08a1e18a
commit de20dbf0b8
20 changed files with 88 additions and 72 deletions

View file

@ -1,5 +1,7 @@
package src;
import src.Settings;
@:publicFields
class ConsoleEntry {
var time:Float;
@ -21,6 +23,10 @@ class Console {
var consumers:Array<ConsoleEntry->Void>;
var timeSinceStart:Float;
#if hl
var consoleFileHandle:sys.io.FileOutput;
#end
public function new() {
if (instance == null) {
instance = this;
@ -28,6 +34,9 @@ class Console {
entries = [];
consumers = [];
timeSinceStart = haxe.Timer.stamp();
#if hl
consoleFileHandle = sys.io.File.write(haxe.io.Path.join([Settings.settingsDir, "console.log"]), false);
#end
}
public function clear() {
@ -41,6 +50,9 @@ class Console {
function addEntry(type:String, msg:String) {
var e = new ConsoleEntry(getTime(), type, msg);
entries.push(e);
#if hl
consoleFileHandle.writeString('[${e.time}] ${e.text}\n');
#end
for (c in consumers) {
c(e);
}

View file

@ -31,6 +31,7 @@ import dif.Dif;
import src.InteriorObject;
import src.MarbleGame;
import src.ResourceLoaderWorker;
import src.Console;
class DifBuilderTriangle {
public var texture:String;
@ -746,6 +747,7 @@ class DifBuilder {
material.receiveShadows = true;
}
} else {
Console.warn('Unable to load ${grp} texture for dif ${path}');
material = Material.create();
material.shadows = false;
material.receiveShadows = true;

View file

@ -33,6 +33,7 @@ import dts.DtsFile;
import h3d.Matrix;
import src.Util;
import src.Resource;
import src.Console;
var DROP_TEXTURE_FOR_ENV_MAP = ['shapes/items/superjump.dts', 'shapes/items/antigravity.dts'];
@ -373,6 +374,7 @@ class DtsObject extends GameObject {
if (fullName == null || (this.isTSStatic && ((flags & (1 << 31) > 0)))) {
if (this.isTSStatic) {
Console.warn('Unsupported material type for ${fullName}, dts: ${this.dtsPath}');
// TODO USE PBR???
}
} else if (Path.extension(fullName) == "ifl") {
@ -417,6 +419,7 @@ class DtsObject extends GameObject {
var texture:Texture = ResourceLoader.getResource("data/shapes/pads/white.jpg", ResourceLoader.getTexture, this.textureResources);
texture.wrap = Wrap.Repeat;
#end
Console.warn('Unable to load ${matName}');
material.texture = texture;
dtsshader.texture = texture;
material.mainPass.addShader(dtsshader);
@ -461,6 +464,7 @@ class DtsObject extends GameObject {
if (this.materials.length == 0) {
var mat = Material.create();
this.materials.push(mat);
Console.warn('No materials found for ${this.dtsPath}}');
// TODO THIS
}
}
@ -655,41 +659,6 @@ class DtsObject extends GameObject {
return materialGeometry;
}
function mergeMaterialGeometries(materialGeometries:Array<Array<MaterialGeometry>>) {
var merged = materialGeometries[0].map(x -> {
vertices: [],
normals: [],
uvs: [],
indices: []
});
for (matGeom in materialGeometries) {
for (i in 0...matGeom.length) {
merged[i].vertices = merged[i].vertices.concat(matGeom[i].vertices);
merged[i].normals = merged[i].normals.concat(matGeom[i].normals);
merged[i].uvs = merged[i].uvs.concat(matGeom[i].uvs);
merged[i].indices = merged[i].indices.concat(matGeom[i].indices);
}
}
return merged;
}
function createGeometryFromMaterialGeometry(materialGeometry:Array<MaterialGeometry>) {
var geo = new Object();
for (i in 0...materialGeometry.length) {
if (materialGeometry[i].vertices.length == 0)
continue;
var poly = new Polygon(materialGeometry[i].vertices.map(x -> x.toPoint()));
poly.normals = materialGeometry[i].normals.map(x -> x.toPoint());
poly.uvs = materialGeometry[i].uvs;
var obj = new Mesh(poly, materials[i], geo);
}
return geo;
}
public override function setTransform(mat:Matrix) {
super.setTransform(mat);
if (this.isBoundingBoxCollideable) {

View file

@ -75,7 +75,7 @@ class InstanceManager {
minfo.meshbatch.shadersChanged = true;
minfo.meshbatch.material.mainPass.setPassName(minfo.mesh.material.mainPass.name);
minfo.meshbatch.material.mainPass.enableLights = minfo.mesh.material.mainPass.enableLights;
minfo.meshbatch.setTransform(transform);
minfo.meshbatch.worldPosition = transform;
minfo.meshbatch.emitInstance();
}
}
@ -98,7 +98,7 @@ class InstanceManager {
// minfo.transparencymeshbatch.shadersChanged = true;
// }
var transform = instance.emptyObj.getAbsPos();
minfo.transparencymeshbatch.setTransform(transform);
minfo.transparencymeshbatch.worldPosition = transform;
minfo.transparencymeshbatch.emitInstance();
}
}

View file

@ -65,17 +65,23 @@ class Main extends hxd.App {
Console.log("System: " + Sys.systemName());
#end
Settings.init();
ResourceLoader.init(s2d, () -> {
AudioManager.init();
AudioManager.playShell();
marbleGame = new MarbleGame(s2d, s3d);
MarbleGame.canvas.setContent(new MainMenuGui());
try {
Settings.init();
ResourceLoader.init(s2d, () -> {
AudioManager.init();
AudioManager.playShell();
marbleGame = new MarbleGame(s2d, s3d);
MarbleGame.canvas.setContent(new MainMenuGui());
new ProfilerUI(s2d);
new ProfilerUI(s2d);
loaded = true;
});
loaded = true;
});
} catch (e) {
Console.error(e.message);
Console.error(e.stack.toString());
throw e;
}
// ResourceLoader.init(s2d, () -> {
// Settings.init();
@ -103,7 +109,13 @@ class Main extends hxd.App {
if (loaded) {
ProfilerUI.begin();
ProfilerUI.measure("updateBegin");
marbleGame.update(dt);
try {
marbleGame.update(dt);
} catch (e) {
Console.error(e.message);
Console.error(e.stack.toString());
throw e;
}
// world.update(dt);
ProfilerUI.update(this.engine.fps);
}

View file

@ -192,7 +192,7 @@ class MarbleGame {
if (Key.isPressed(Key.QWERTY_TILDE)) {
consoleShown = !consoleShown;
if (consoleShown) {
if (console == null)
if (console == null || @:privateAccess console._disposed)
console = new ConsoleDlg();
@:privateAccess console.isShowing = true;
canvas.pushDialog(console);

View file

@ -257,6 +257,7 @@ class MarbleWorld extends Scheduler {
MarbleGame.canvas.clearContent();
this.endPad.generateCollider();
this.playGui.formatGemCounter(this.gemCount, this.totalGems);
Console.log("MISSION LOADED");
start();
});
}
@ -403,6 +404,7 @@ class MarbleWorld extends Scheduler {
}
public function restart(full:Bool = false) {
Console.log("LEVEL RESTART");
if (!full && this.currentCheckpoint != null) {
this.loadCheckpointState();
return 0; // Load checkpoint
@ -917,6 +919,7 @@ class MarbleWorld extends Scheduler {
} else if (datablockLowercase == "checkpointtrigger") {
trigger = new CheckpointTrigger(element, cast this);
} else {
Console.error("Unknown trigger: " + element.datablock);
onFinish();
return;
}
@ -1699,6 +1702,7 @@ class MarbleWorld extends Scheduler {
if (this.marble.heldPowerup != null)
if (this.marble.heldPowerup.identifier == powerUp.identifier)
return false;
Console.log("PowerUp pickup: " + powerUp.identifier);
this.marble.heldPowerup = powerUp;
this.playGui.setPowerupImage(powerUp.identifier);
MarbleGame.instance.touchInput.powerupButton.setEnabled(true);
@ -1880,6 +1884,10 @@ class MarbleWorld extends Scheduler {
this.marble.setPosition(mpos.x, mpos.y, mpos.z);
marble.velocity.load(new Vector(0, 0, 0));
marble.omega.load(new Vector(0, 0, 0));
Console.log('Respawn:');
Console.log('Marble Position: ${mpos.x} ${mpos.y} ${mpos.z}');
Console.log('Marble Velocity: ${marble.velocity.x} ${marble.velocity.y} ${marble.velocity.z}');
Console.log('Marble Angular: ${marble.omega.x} ${marble.omega.y} ${marble.omega.z}');
// Set camera orientation
var euler = this.currentCheckpoint.obj.getRotationQuat().toEuler();
this.marble.camera.CameraYaw = euler.z + Math.PI / 2;

View file

@ -2,6 +2,7 @@ import haxe.Json;
import mis.MisParser;
import src.ResourceLoader;
import src.Mission;
import src.Console;
@:publicFields
class MissionList {
@ -92,6 +93,19 @@ class MissionList {
missionList.set("platinum", platinumMissions);
missionList.set("ultra", ultraMissions);
Console.log("Loaded MissionList");
Console.log("Gold Beginner: " + goldMissions["beginner"].length);
Console.log("Gold Intermediate: " + goldMissions["intermediate"].length);
Console.log("Gold Advanced: " + goldMissions["advanced"].length);
Console.log("Platinum Beginner: " + platinumMissions["beginner"].length);
Console.log("Platinum Intermediate: " + platinumMissions["intermediate"].length);
Console.log("Platinum Advanced: " + platinumMissions["advanced"].length);
Console.log("Platinum Expert: " + platinumMissions["expert"].length);
Console.log("Ultra Beginner: " + ultraMissions["beginner"].length);
Console.log("Ultra Intermediate: " + ultraMissions["intermediate"].length);
Console.log("Ultra Advanced: " + ultraMissions["advanced"].length);
Console.log("Custom: " + customMissions.length);
// parseCLAList();
_build = true;

View file

@ -21,6 +21,7 @@ import h3d.Vector;
import h3d.scene.MeshBatch;
import h3d.scene.Mesh;
import src.ResourceLoader;
import src.Console;
@:publicFields
class ParticleData {
@ -303,6 +304,7 @@ class ParticleManager {
var emitters:Array<ParticleEmitter> = [];
public function new(level:MarbleWorld) {
Console.log("Initializing Particle Manager");
this.level = level;
this.scene = level.scene;
}

View file

@ -74,9 +74,6 @@ class PathedInterior extends InteriorObject {
pathedInterior.simGroup = simGroup;
pathedInterior.element = interiorElement;
level.interiors.push(pathedInterior);
// await
// Util.wait(10); // See shapes for the meaning of this hack
// await
pathedInterior.init(level, () -> {
onFinish(pathedInterior);
});

View file

@ -11,6 +11,7 @@ import haxe.EnumFlags;
import h3d.Quat;
import h3d.Vector;
import src.Util;
import src.Console;
enum ReplayMarbleState {
UsedPowerup;
@ -429,8 +430,10 @@ class Replay {
}
public function read(data:Bytes) {
Console.log("Loading replay");
var replayVersion = data.get(0);
if (replayVersion > version) {
Console.log("Replay loading failed: unknown version");
return false;
}
var uncompressedLength = data.getInt32(1);

View file

@ -25,7 +25,6 @@ class Resource<T> {
public function release() {
this.referenceCount--;
if (this.referenceCount == 0) {
Console.log("Freeing: " + identifier);
disposeFunc(this.resource);
this.resourceMap.remove(this.identifier);
// trace('Releasing Resource ${this.identifier}');

View file

@ -280,7 +280,6 @@ class ResourceLoader {
if (interiorResources.exists(path))
return interiorResources.get(path);
else {
Console.log("Load Interior: " + path);
var itr:Dif;
// var lock = new Lock();
// threadPool.run(() -> {
@ -299,7 +298,6 @@ class ResourceLoader {
if (dtsResources.exists(path))
return dtsResources.get(path);
else {
Console.log("Load DTS: " + path);
var dts = new DtsFile();
// var lock = new Lock();
// threadPool.run(() -> {
@ -318,7 +316,6 @@ class ResourceLoader {
if (textureCache.exists(path))
return textureCache.get(path);
if (fileSystem.exists(path)) {
Console.log("Load Texture: " + path);
var img = loader.load(path).toImage();
Image.setupTextureFlags = (texObj) -> {
texObj.flags.set(MipMapped);
@ -341,7 +338,6 @@ class ResourceLoader {
if (imageCache.exists(path))
return imageCache.get(path);
if (fileSystem.exists(path)) {
Console.log("Load Image: " + path);
var tex = loader.load(path).toImage();
var imageresource = new Resource(tex, path, imageCache, img -> {});
imageCache.set(path, imageresource);
@ -357,7 +353,6 @@ class ResourceLoader {
if (audioCache.exists(path))
return audioCache.get(path);
if (fileSystem.exists(path)) {
Console.log("Load Audio: " + path);
var snd = loader.load(path).toSound();
// @:privateAccess snd.watchCallb();
var audioresource = new Resource(snd, path, audioCache, snd -> snd.dispose());

View file

@ -259,6 +259,7 @@ class Settings {
FileSystem.createDirectory(settingsDir);
}
File.saveContent(Path.join([settingsDir, "settings.json"]), json);
Console.log("Saved settings to " + Path.join([settingsDir, "settings.json"]));
#end
#if js
var localStorage = js.Browser.getLocalStorage();

View file

@ -16,6 +16,7 @@ import h3d.scene.Object;
import src.Resource;
import hxd.res.Image;
import src.ResourceLoaderWorker;
import src.Console;
class Sky extends Object {
public var dmlPath:String;
@ -101,6 +102,7 @@ class Sky extends Object {
skyboxImages.push(pixels);
// var tex = new h3d.mat.Texture();
// skyboxImages.push(new BitmapData(128, 128));
Console.error("Skybox image " + filenames[0] + " does not exist");
} else {
var image = ResourceLoader.getResource(filenames[0], ResourceLoader.getImage, this.imageResources).toBitmap();
var pixels = image.getPixels();

View file

@ -152,18 +152,6 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
var tform = transform.clone();
// tform.setPosition(tform.getPosition().add(this.velocity.multiply(timeState.dt)));
function toDifPoint(pt:Vector) {
return new Point3F(pt.x, pt.y, pt.z);
}
function fromDifPoint(pt:Point3F) {
return new Vector(pt.x, pt.y, pt.z);
}
function hashEdge(i1:Int, i2:Int) {
return i1 >= i2 ? i1 * i1 + i1 + i2 : i1 + i2 * i2;
}
var contacts = [];
for (obj in surfaces) {

View file

@ -94,7 +94,6 @@ class ConsoleDlg extends GuiControl {
consoleContent.text.text += txt;
if (isShowing) {
scroll.setScrollMax(consoleContent.text.textHeight);
haxe.Timer.delay(() -> scroll.setScrollPercentage(1), 1);
}
};

View file

@ -76,7 +76,7 @@ class GuiConsoleScrollCtrl extends GuiControl {
this.scrollBarY = new Graphics();
this.scrollBarY.scale(Settings.uiScale);
this.clickInteractive = new Interactive(10 * Settings.uiScale, 1);
this.clickInteractive = new Interactive(18 * Settings.uiScale, 1);
this.clickInteractive.onPush = (e) -> {
if (!this.pressed) {
this.pressed = true;
@ -111,7 +111,10 @@ class GuiConsoleScrollCtrl extends GuiControl {
}
public function setScrollMax(max:Float) {
this.scrollY = 0;
var renderRect = this.getRenderRectangle();
var scrollExtentY = renderRect.extent.y - 34 * Settings.uiScale;
var scrollBarYSize = (scrollExtentY * scrollExtentY / (maxScrollY * Settings.uiScale - 34 * Settings.uiScale));
this.scrollY = scrollExtentY - scrollBarYSize * Settings.uiScale;
this.maxScrollY = max;
this.dirty = true;
this.updateScrollVisual();

View file

@ -53,6 +53,8 @@ class GuiControl {
var textureResources:Array<Resource<Texture>> = [];
var soundResources:Array<Resource<Sound>> = [];
var _disposed = false;
public function new() {}
public function render(scene2d:Scene) {
@ -240,6 +242,8 @@ class GuiControl {
for (audioResource in soundResources) {
audioResource.release();
}
_disposed = true;
}
public function onMouseDown(mouseState:MouseState) {}

View file

@ -6,6 +6,7 @@ import src.AudioManager;
import mis.MisParser;
import src.MarbleWorld;
import mis.MissionElement.MissionElementTrigger;
import src.Console;
class TeleportTrigger extends Trigger {
var delay:Float = 2;
@ -103,6 +104,11 @@ class TeleportTrigger extends Trigger {
if (!MisParser.parseBoolean(chooseNonNull(this.element.keepangular, destination.element.keepangular)))
this.level.marble.omega.set(0, 0, 0);
Console.log('Teleport:');
Console.log('Marble Position: ${position.x} ${position.y} ${position.z}');
Console.log('Marble Velocity: ${this.level.marble.velocity.x} ${this.level.marble.velocity.y} ${this.level.marble.velocity.z}');
Console.log('Marble Angular: ${this.level.marble.omega.x} ${this.level.marble.omega.y} ${this.level.marble.omega.z}');
// Determine camera orientation
if (!MisParser.parseBoolean(chooseNonNull(this.element.keepcamera, destination.element.keepcamera))) {
var yaw:Float;