make it kinda work on js

This commit is contained in:
RandomityGuy 2023-06-26 19:35:39 +05:30
parent 364f9e614c
commit 5122d1335b
21 changed files with 155 additions and 101 deletions

View file

@ -52,6 +52,10 @@ class Console {
entries = [];
}
public static function time() {
return haxe.Timer.stamp();
}
function getTime() {
return Std.int((haxe.Timer.stamp() - timeSinceStart) * 1000) / 1000;
}

View file

@ -759,7 +759,7 @@ class DifBuilder {
return vec;
}
if (makeCollideable) {
var time = Sys.time();
var time = Console.time();
for (colliderSurface in colliderSurfaces) {
var i = 0;
while (i < colliderSurface.indices.length) {
@ -803,10 +803,10 @@ class DifBuilder {
i += 3;
}
}
var interval = Sys.time() - time;
var interval = Console.time() - time;
Console.log('Collision build time: ${interval}');
}
var time = Sys.time();
var time = Console.time();
for (vtex => buckets in vertexBuckets) {
for (i in 0...buckets.length) {
var bucket = buckets[i];
@ -845,7 +845,7 @@ class DifBuilder {
mats.set(value.texture, [value]);
}
}
var interval = Sys.time() - time;
var interval = Console.time() - time;
Console.log('Normal smoothing build time: ${interval}');
collider.difEdgeMap = difEdges;
}
@ -906,14 +906,16 @@ class DifBuilder {
loadtexs.push(tex(grp));
}
}
#if hl
var memStats = hl.Gc.stats();
trace('Interior: ${path} ${memStats.currentMemory} ${memStats.totalAllocated} ${memStats.allocationCount}');
#end
var worker = new ResourceLoaderWorker(() -> {
var shaderWorker = new ResourceLoaderWorker(() -> {
onFinish();
});
var time = Sys.time();
var time = Console.time();
for (grp => tris in mats) {
var points = [];
var normals = [];
@ -994,7 +996,7 @@ class DifBuilder {
material.mainPass.wireframe = true;
var mesh = new Mesh(prim, material, itr);
}
var interval = Sys.time() - time;
var interval = Console.time() - time;
Console.log('Geometry build time ${interval}');
shaderWorker.run();

View file

@ -387,13 +387,29 @@ class DtsObject extends GameObject {
function postProcessMaterial(matName:String, material:Material) {}
function getPreloadMaterials(dts:DtsFile) {
var texToLoad = [];
var directoryPath = Path.directory(this.dtsPath);
for (i in 0...dts.matNames.length) {
var matName = this.matNameOverride.exists(dts.matNames[i]) ? this.matNameOverride.get(dts.matNames[i]) : dts.matNames[i];
if (matName.indexOf('/') != -1)
matName = matName.substring(matName.lastIndexOf('/') + 1);
var fullNames = ResourceLoader.getFullNamesOf(directoryPath + '/' + matName).filter(x -> haxe.io.Path.extension(x) != "dts");
var fullName = fullNames.length > 0 ? fullNames[0] : null;
if (fullName != null) {
texToLoad.push(fullName);
}
}
return texToLoad;
}
function computeMaterials() {
var environmentMaterial:Material = null;
for (i in 0...dts.matNames.length) {
var matName = matNameOverride.exists(dts.matNames[i]) ? matNameOverride.get(dts.matNames[i]) : this.dts.matNames[i];
if (matName.indexOf('/') != -1)
matName = matName.substring(matName.lastIndexOf('/'));
matName = matName.substring(matName.lastIndexOf('/') + 1);
var flags = dts.matFlags[i];
var fullNames = ResourceLoader.getFullNamesOf(this.directoryPath + '/' + matName).filter(x -> Path.extension(x) != "dts");
var fullName = fullNames.length > 0 ? fullNames[0] : null;
@ -455,7 +471,7 @@ class DtsObject extends GameObject {
#end
// Apparently creating these bitmap datas dont work so we'll just get the snag a white texture in the filesystem
#if js
var texture:Texture = ResourceLoader.getResource("data/shapes/pads/white.jpg", ResourceLoader.getTexture, this.textureResources);
var texture:Texture = ResourceLoader.getResource("data/shapes/hazards/null.png", ResourceLoader.getTexture, this.textureResources);
texture.wrap = Wrap.Repeat;
#end
Console.warn('Unable to load ${matName}');

View file

@ -173,6 +173,7 @@ class MarbleGame {
JSPlatform.initFullscreenEnforcer();
Window.getInstance().removeEventTarget(@:privateAccess Key.onEvent);
Window.getInstance().addResizeEvent(() -> {});
#end
scene2d.addEventListener(e -> {
_mouseWheelDelta = e.wheelDelta;

View file

@ -362,6 +362,7 @@ class MarbleWorld extends Scheduler {
var marblefiles = [
"particles/star.png",
"particles/smoke.png",
"particles/burst.png",
"sound/rolling_hard.wav",
"sound/sliding.wav",
"sound/use_gyrocopter.wav",
@ -374,11 +375,15 @@ class MarbleWorld extends Scheduler {
"sound/bouncehard4.wav",
"sound/spawn_alternate.wav",
"sound/missinggems.wav",
"sound/level_text.wav",
"sound/level_finish.wav",
"sound/finish.wav",
"shapes/images/helicopter.dts",
"shapes/images/helicopter.jpg", // These irk us a lot because ifl shit
"shapes/items/gem.dts", // Ew ew
"shapes/items/gemshine.png",
"shapes/items/enviro1.jpg",
"shapes/hazards/null.png"
];
if (this.game == "ultra") {
marblefiles.push("shapes/balls/pack1/marble20.normal.png");
@ -796,18 +801,7 @@ class MarbleWorld extends Scheduler {
ResourceLoader.load(obj.dtsPath).entry.load(() -> {
var dtsFile = ResourceLoader.loadDts(obj.dtsPath);
var directoryPath = haxe.io.Path.directory(obj.dtsPath);
var texToLoad = [];
for (i in 0...dtsFile.resource.matNames.length) {
var matName = obj.matNameOverride.exists(dtsFile.resource.matNames[i]) ? obj.matNameOverride.get(dtsFile.resource.matNames[i]) : dtsFile.resource.matNames[i];
if (matName.indexOf('/') != -1)
matName = matName.substring(matName.lastIndexOf('/'));
var fullNames = ResourceLoader.getFullNamesOf(directoryPath + '/' + matName).filter(x -> haxe.io.Path.extension(x) != "dts");
var fullName = fullNames.length > 0 ? fullNames[0] : null;
if (fullName != null) {
texToLoad.push(fullName);
}
}
var texToLoad = obj.getPreloadMaterials(dtsFile.resource);
var worker = new ResourceLoaderWorker(() -> {
obj.idInLevel = this.dtsObjects.length; // Set the id of the thing
@ -834,27 +828,7 @@ class MarbleWorld extends Scheduler {
});
for (texPath in texToLoad) {
if (haxe.io.Path.extension(texPath) == "ifl") {
if (isTsStatic)
obj.useInstancing = false;
worker.addTask(fwd -> {
parseIfl(texPath, keyframes -> {
var innerWorker = new ResourceLoaderWorker(() -> {
fwd();
});
var loadedkf = [];
for (kf in keyframes) {
if (!loadedkf.contains(kf)) {
innerWorker.loadFile(directoryPath + '/' + kf);
loadedkf.push(kf);
}
}
innerWorker.run();
});
});
} else {
worker.loadFile(texPath);
}
worker.loadFile(texPath);
}
worker.run();

View file

@ -35,30 +35,30 @@ class MissionList {
#end
var difficultyMissions = [];
for (file in difficultyFiles) {
var subfiles = ResourceLoader.fileSystem.dir(file.path);
for (file in subfiles) {
if (file.extension == "mis") {
var misParser = new MisParser(file.getText());
var mInfo = misParser.parseMissionInfo();
var mission = Mission.fromMissionInfo(file.path, mInfo);
if (game != "custom")
mission.game = game;
else if (mInfo.game != null && mInfo.game != "")
mission.game = mInfo.game.toLowerCase();
else
mission.game = game; // Last case scenario
if (game == "custom")
mission.isCustom = true;
// do egg thing
if (StringTools.contains(file.getText().toLowerCase(), 'datablock = "easteregg"')) { // Ew
mission.hasEgg = true;
if (file.isDirectory)
for (sfile in file) {
if (sfile.extension == "mis") {
var misParser = new MisParser(sfile.getText());
var mInfo = misParser.parseMissionInfo();
var mission = Mission.fromMissionInfo(sfile.path, mInfo);
if (game != "custom")
mission.game = game;
else if (mInfo.game != null && mInfo.game != "")
mission.game = mInfo.game.toLowerCase();
else
mission.game = game; // Last case scenario
if (game == "custom")
mission.isCustom = true;
// do egg thing
if (StringTools.contains(sfile.getText().toLowerCase(), 'datablock = "easteregg"')) { // Ew
mission.hasEgg = true;
}
mission.difficultyIndex = difficultyIndex;
missions.set(sfile.path, mission);
missionsFilenameLookup.set(sfile.name.toLowerCase(), mission);
difficultyMissions.push(mission);
}
mission.difficultyIndex = difficultyIndex;
missions.set(file.path, mission);
missionsFilenameLookup.set(file.name.toLowerCase(), mission);
difficultyMissions.push(mission);
}
}
}
difficultyMissions.sort((a, b) -> Std.parseInt(a.missionInfo.level) - Std.parseInt(b.missionInfo.level));

View file

@ -188,9 +188,9 @@ class PreviewWorld extends Scheduler {
itrAddTime = 0;
for (elem in itrpaths) {
worker.addTask(fwd -> {
var startTime = Sys.time();
var startTime = Console.time();
addInteriorFromMis(cast elem, () -> {
itrAddTime += Sys.time() - startTime;
itrAddTime += Console.time() - startTime;
fwd();
});
});
@ -436,18 +436,7 @@ class PreviewWorld extends Scheduler {
ResourceLoader.load(obj.dtsPath).entry.load(() -> {
var dtsFile = ResourceLoader.loadDts(obj.dtsPath);
var directoryPath = haxe.io.Path.directory(obj.dtsPath);
var texToLoad = [];
for (i in 0...dtsFile.resource.matNames.length) {
var matName = obj.matNameOverride.exists(dtsFile.resource.matNames[i]) ? obj.matNameOverride.get(dtsFile.resource.matNames[i]) : dtsFile.resource.matNames[i];
if (matName.indexOf('/') != -1)
matName = matName.substring(matName.lastIndexOf('/'));
var fullNames = ResourceLoader.getFullNamesOf(directoryPath + '/' + matName).filter(x -> haxe.io.Path.extension(x) != "dts");
var fullName = fullNames.length > 0 ? fullNames[0] : null;
if (fullName != null) {
texToLoad.push(fullName);
}
}
var texToLoad = obj.getPreloadMaterials(dtsFile.resource);
var worker = new ResourceLoaderWorker(() -> {
obj.isTSStatic = isTsStatic;
@ -464,27 +453,7 @@ class PreviewWorld extends Scheduler {
});
for (texPath in texToLoad) {
if (haxe.io.Path.extension(texPath) == "ifl") {
if (isTsStatic)
obj.useInstancing = false;
worker.addTask(fwd -> {
parseIfl(texPath, keyframes -> {
var innerWorker = new ResourceLoaderWorker(() -> {
fwd();
});
var loadedkf = [];
for (kf in keyframes) {
if (!loadedkf.contains(kf)) {
innerWorker.loadFile(directoryPath + '/' + kf);
loadedkf.push(kf);
}
}
innerWorker.run();
});
});
} else {
worker.loadFile(texPath);
}
worker.loadFile(texPath);
}
worker.run();

View file

@ -172,6 +172,7 @@ class ResourceLoader {
}
}
var worker = new ResourceLoaderWorker(onFinish);
worker.loadFile('englishStrings.inf');
for (file in toloadfiles) {
worker.addTaskParallel((fwd) -> file.load(fwd));
}
@ -180,8 +181,7 @@ class ResourceLoader {
static function preloadMusic(onFinish:Void->Void) {
var worker = new ResourceLoaderWorker(onFinish);
worker.loadFile("sound/music/shell.ogg");
worker.loadFile("sound/music/pianoforte.ogg");
worker.loadFile("sound/music/Tim Trance.ogg");
worker.run();
}

View file

@ -367,6 +367,12 @@ class Settings {
if (json.gamepad != null) {
gamepadSettings = json.gamepad;
}
if (gamepadSettings.respawn == null) {
gamepadSettings.respawn = ["back"];
}
if (gamepadSettings.blast == null) {
gamepadSettings.blast = ["X", "LB", "RB"];
}
if (gamepadSettings.rewind == null) {
gamepadSettings.rewind = ["Y"];
}

View file

@ -1,5 +1,6 @@
package shapes;
import dts.DtsFile;
import src.ResourceLoader;
import mis.MissionElement.MissionElementItem;
import src.TimeState;
@ -50,6 +51,13 @@ class AntiGravity extends PowerUp {
});
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/items/antigrav_bump.png");
mats.push("data/shapes/items/antigrav_glow.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "antigrav_skin") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/items/antigrav_skin.png").resource;

View file

@ -35,6 +35,13 @@ class Blast extends PowerUp {
this.level.blastAmount = 1.2;
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/images/blast_orbit_bump.png");
mats.push("data/shapes/items/item_glow.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "blast_orbit_skin") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/images/blast_orbit_skin.png").resource;

View file

@ -24,6 +24,13 @@ class BlastWave extends DtsObject {
super.update(timeState);
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/images/blast_glow.png");
mats.push("data/shapes/pads/endpad_glow.png");
return mats;
}
override function postProcessMaterial(matName:String, material:Material) {
if (matName == "refract") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/images/blast_glow.png").resource;

View file

@ -42,6 +42,12 @@ class EasterEgg extends PowerUp {
public function use(timeState:src.TimeState) {}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/skies/gemCubemapUp.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "egg_skin") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/items/egg_skin.png").resource;

View file

@ -66,6 +66,12 @@ class Gem extends DtsObject {
this.setOpacity(1);
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/skies/gemCubemapUp.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "red.gem") {
var diffuseTex = ResourceLoader.getTexture('data/shapes/items/red.gem.png').resource;

View file

@ -36,6 +36,14 @@ class Glass extends DtsObject {
this.identifier = datablockLowercase;
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/structures/glass.png");
mats.push("data/shapes/structures/glass2.png");
mats.push("data/shapes/structures/glass.normal.png");
return mats;
}
override function postProcessMaterial(matName:String, material:Material) {
var refractTex = ResourceLoader.getTexture('data/shapes/structures/glass.png').resource;
refractTex.wrap = Repeat;

View file

@ -27,6 +27,7 @@ class MegaMarble extends PowerUp {
worker.loadFile("sound/mega_bouncehard3.wav");
worker.loadFile("sound/mega_bouncehard4.wav");
worker.loadFile("sound/mega_roll.wav");
worker.loadFile("sound/MegaShrink.wav");
worker.loadFile("sound/use_mega.wav");
this.pickupSound = ResourceLoader.getResource("data/sound/mega_marble.wav", ResourceLoader.getAudio, this.soundResources);
worker.run();
@ -44,6 +45,13 @@ class MegaMarble extends PowerUp {
AudioManager.playSound(ResourceLoader.getResource('data/sound/use_mega.wav', ResourceLoader.getAudio, this.soundResources));
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/images/grow_bump.png");
mats.push("data/shapes/images/grow_glow.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "grow") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/images/grow.png").resource;

View file

@ -16,6 +16,13 @@ class RoundBumper extends AbstractBumper {
animateSubObjectOpacities = true;
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/items/antigrav_glow.png");
mats.push("data/shapes/images/blastwave.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "bumper") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/bumpers/bumper.png").resource;

View file

@ -25,6 +25,12 @@ class SignPlain extends DtsObject {
this.identifier = "SignPlain" + direction;
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/signs/arrowsign_post_bump.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "arrowsign_arrow") {
var diffuseTex = ResourceLoader.getTexture('data/shapes/signs/arrowsign_arrow.png').resource;
@ -133,7 +139,7 @@ class SignPlain extends DtsObject {
var diffuseTex = ResourceLoader.getTexture('data/shapes/signs/arrowsign_post.png').resource;
diffuseTex.wrap = Repeat;
diffuseTex.mipMap = Nearest;
var normalTex = ResourceLoader.getTexture("data/shapes/items/arrowsign_post_bump.png").resource;
var normalTex = ResourceLoader.getTexture("data/shapes/signs/arrowsign_post_bump.png").resource;
normalTex.wrap = Repeat;
normalTex.mipMap = Nearest;
var shader = new shaders.DefaultMaterial(diffuseTex, normalTex, 12, new h3d.Vector(0.8, 0.8, 0.6, 1), 1);

View file

@ -22,6 +22,12 @@ class StartPad extends DtsObject {
doSequenceOnceBeginTime = level.timeState.timeSinceLoad;
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/pads/ringnormal.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "ringglass") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/pads/ringglass.png").resource;

View file

@ -79,6 +79,12 @@ class SuperJump extends PowerUp {
this.level.deselectPowerUp();
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/items/superjump_bump.png");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "superJump_skin") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/items/superjump_skin.png").resource;

View file

@ -48,6 +48,13 @@ class TimeTravel extends PowerUp {
level.addBonusTime(this.timeBonus);
}
override function getPreloadMaterials(dts:dts.DtsFile) {
var mats = super.getPreloadMaterials(dts);
mats.push("data/shapes/structures/glass.png");
mats.push("data/shapes/structures/time.normal.jpg");
return mats;
}
override function postProcessMaterial(matName:String, material:h3d.mat.Material) {
if (matName == "timeTravel_skin") {
var diffuseTex = ResourceLoader.getTexture("data/shapes/items/timeTravel_skin.png").resource;