mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
dts optimization: share node transforms
This commit is contained in:
parent
605ef6d2d0
commit
992b79f8b7
18 changed files with 189 additions and 124 deletions
|
|
@ -97,6 +97,12 @@ class DtsObject extends GameObject {
|
|||
var lastSequenceKeyframes:Map<Sequence, Float> = new Map();
|
||||
var doSequenceOnce:Bool;
|
||||
var doSequenceOnceBeginTime:Float;
|
||||
var sharedNodeTransforms:Bool = false;
|
||||
|
||||
static var sharedGraphNodesMap:Map<String, Array<Object>> = [];
|
||||
|
||||
var sharedGraphNodes:Array<Object> = [];
|
||||
var isSharedGraphNodesRoot = false;
|
||||
|
||||
var graphNodes:Array<Object> = [];
|
||||
var dirtyTransforms:Array<Bool> = [];
|
||||
|
|
@ -358,6 +364,16 @@ class DtsObject extends GameObject {
|
|||
|
||||
rootObject = new Object(this);
|
||||
|
||||
if (this.sharedNodeTransforms) {
|
||||
if (sharedGraphNodesMap.exists(this.identifier)) {
|
||||
sharedGraphNodes = sharedGraphNodesMap.get(this.identifier);
|
||||
isSharedGraphNodesRoot = false;
|
||||
} else {
|
||||
sharedGraphNodesMap.set(this.identifier, graphNodes.concat([this.rootObject]));
|
||||
isSharedGraphNodesRoot = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (i in rootNodesIdx) {
|
||||
rootObject.addChild(this.graphNodes[i]);
|
||||
}
|
||||
|
|
@ -1143,6 +1159,8 @@ class DtsObject extends GameObject {
|
|||
continue;
|
||||
var t = (actualKeyframe - keyframeLow) % 1;
|
||||
|
||||
if (rot > 0 || trans > 0 || scale > 0) {
|
||||
if ((!this.sharedNodeTransforms || this.isSharedGraphNodesRoot)) {
|
||||
if (rot > 0) {
|
||||
for (i in 0...this.dts.nodes.length) {
|
||||
var affected = ((1 << i) & rot) != 0;
|
||||
|
|
@ -1282,6 +1300,20 @@ class DtsObject extends GameObject {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.sharedNodeTransforms && !this.isSharedGraphNodesRoot) {
|
||||
for (i in 0...this.dts.nodes.length) {
|
||||
var node = this.graphNodes[i];
|
||||
var shared = this.sharedGraphNodes[i];
|
||||
node.setPosition(shared.x, shared.y, shared.z);
|
||||
node.qRot.load(shared.qRot);
|
||||
node.scaleX = shared.scaleX;
|
||||
node.scaleY = shared.scaleY;
|
||||
node.scaleZ = shared.scaleZ;
|
||||
// this.graphNodes[i].setTransform(this.sharedGraphNodes[i].getTransform());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
affectedCount = 0;
|
||||
var visIterIdx = 0;
|
||||
|
|
@ -1422,6 +1454,7 @@ class DtsObject extends GameObject {
|
|||
}
|
||||
|
||||
if (this.ambientRotate) {
|
||||
if ((!this.sharedNodeTransforms || this.isSharedGraphNodesRoot)) {
|
||||
var spinAnimation = new Quat();
|
||||
spinAnimation.initRotateAxis(0, 0, -1, timeState.timeSinceLoad * this.ambientSpinFactor);
|
||||
|
||||
|
|
@ -1431,6 +1464,16 @@ class DtsObject extends GameObject {
|
|||
this.rootObject.getRotationQuat().load(spinAnimation);
|
||||
this.rootObject.posChanged = true;
|
||||
}
|
||||
if (this.sharedNodeTransforms && !this.isSharedGraphNodesRoot) {
|
||||
var node = this.rootObject;
|
||||
var shared = this.sharedGraphNodes[this.sharedGraphNodes.length - 1];
|
||||
node.setPosition(shared.x, shared.y, shared.z);
|
||||
node.qRot.load(shared.qRot);
|
||||
node.scaleX = shared.scaleX;
|
||||
node.scaleY = shared.scaleY;
|
||||
node.scaleZ = shared.scaleZ;
|
||||
}
|
||||
}
|
||||
|
||||
for (i in 0...this.colliders.length) {
|
||||
if (this.dirtyTransforms[this.colliders[i].userData]) {
|
||||
|
|
@ -1529,6 +1572,11 @@ class DtsObject extends GameObject {
|
|||
this.level = null;
|
||||
boundingCollider = null;
|
||||
colliders = null;
|
||||
sharedGraphNodes = null;
|
||||
this.dtsResource.release();
|
||||
}
|
||||
|
||||
public static function disposeShared() {
|
||||
sharedGraphNodesMap = [];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2327,6 +2327,7 @@ class MarbleWorld extends Scheduler {
|
|||
dtsObject.dispose();
|
||||
}
|
||||
dtsObjects = null;
|
||||
DtsObject.disposeShared();
|
||||
powerUps = [];
|
||||
for (trigger in this.triggers) {
|
||||
trigger.dispose();
|
||||
|
|
|
|||
|
|
@ -301,6 +301,7 @@ class PreviewWorld extends Scheduler {
|
|||
for (marb in marbles) {
|
||||
marb.dispose();
|
||||
}
|
||||
DtsObject.disposeShared();
|
||||
interiors = [];
|
||||
dtsObjects = [];
|
||||
marbles = [];
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class AntiGravity extends PowerUp {
|
|||
this.autoUse = true;
|
||||
this.useInstancing = true;
|
||||
this.animateSubObjectOpacities = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
if (MisParser.parseBoolean(element.permanent))
|
||||
norespawn = true;
|
||||
if (norespawn)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class Blast extends PowerUp {
|
|||
this.pickUpName = "a Blast powerup";
|
||||
this.ambientRotate = false;
|
||||
this.autoUse = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
}
|
||||
|
||||
public override function init(level:MarbleWorld, onFinish:Void->Void) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class DuctFan extends ForceObject {
|
|||
this.dtsPath = "data/shapes/hazards/ductfan.dts";
|
||||
this.isCollideable = true;
|
||||
this.isTSStatic = false;
|
||||
this.sharedNodeTransforms = true;
|
||||
this.identifier = "DuctFan";
|
||||
this.forceDatas = [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class EasterEgg extends PowerUp {
|
|||
this.identifier = "EasterEgg";
|
||||
this.pickUpName = "Easter Egg";
|
||||
this.autoUse = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
}
|
||||
|
||||
public function pickUp(marble:Marble):Bool {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class Gem extends DtsObject {
|
|||
this.isBoundingBoxCollideable = true;
|
||||
pickedUp = false;
|
||||
useInstancing = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
showSequences = false; // Gems actually have an animation for the little shiny thing, but the actual game ignores that. I get it, it was annoying as hell.
|
||||
|
||||
var GEM_COLORS = ["red"];
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ class GemBeam extends DtsObject {
|
|||
this.isTSStatic = false;
|
||||
this.identifier = "GemBeam";
|
||||
this.useInstancing = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
this.animateSubObjectOpacities = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class Helicopter extends PowerUp {
|
|||
this.isTSStatic = false;
|
||||
this.showSequences = false;
|
||||
this.identifier = "Helicopter";
|
||||
this.sharedNodeTransforms = true;
|
||||
this.pickUpName = "a Gyrocopter powerup";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class MegaMarble extends PowerUp {
|
|||
this.isTSStatic = false;
|
||||
this.showSequences = true;
|
||||
this.identifier = "MegaMarble";
|
||||
this.sharedNodeTransforms = true;
|
||||
this.pickUpName = "a Mega-Marble powerup";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class Sign extends DtsObject {
|
|||
this.dtsPath = "data/shapes/signs/sign.dts";
|
||||
this.isCollideable = true;
|
||||
this.useInstancing = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
|
||||
var d = "";
|
||||
if (element.datablock.toLowerCase() != 'arrow') {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class SignCaution extends DtsObject {
|
|||
this.dtsPath = "data/shapes/signs/cautionsign.dts";
|
||||
this.isCollideable = true;
|
||||
this.useInstancing = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
|
||||
var type = element.datablock.substring("SignCaution".length).toLowerCase();
|
||||
switch (type) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class SignPlain extends DtsObject {
|
|||
|
||||
this.isCollideable = true;
|
||||
this.useInstancing = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
|
||||
// Determine the direction to show
|
||||
var direction = element.datablock.substring("Arrow".length).toLowerCase();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class SmallDuctFan extends ForceObject {
|
|||
this.dtsPath = "data/shapes/hazards/ductfan.dts";
|
||||
this.isCollideable = true;
|
||||
this.isTSStatic = false;
|
||||
this.sharedNodeTransforms = true;
|
||||
this.identifier = "DuctFan";
|
||||
this.forceDatas = [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class SuperJump extends PowerUp {
|
|||
this.identifier = "SuperJump";
|
||||
this.pickUpName = "a Super Jump powerup";
|
||||
this.showSequences = false;
|
||||
this.sharedNodeTransforms = true;
|
||||
sjEmitterParticleData = new ParticleData();
|
||||
sjEmitterParticleData.identifier = "superJumpParticle";
|
||||
sjEmitterParticleData.texture = ResourceLoader.getResource("data/particles/twirl.png", ResourceLoader.getTexture, this.textureResources);
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ class SuperSpeed extends PowerUp {
|
|||
this.identifier = "SuperSpeed";
|
||||
this.pickUpName = "a Super Speed powerup";
|
||||
this.useInstancing = true;
|
||||
this.sharedNodeTransforms = true;
|
||||
ssEmitterParticleData = new ParticleData();
|
||||
ssEmitterParticleData.identifier = "superSpeedParticle";
|
||||
ssEmitterParticleData.texture = ResourceLoader.getResource("data/particles/smoke.png", ResourceLoader.getTexture, this.textureResources);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class TimeTravel extends PowerUp {
|
|||
this.dtsPath = "data/shapes/items/timetravel.dts";
|
||||
this.isCollideable = false;
|
||||
this.isTSStatic = false;
|
||||
this.sharedNodeTransforms = true;
|
||||
this.identifier = "TimeTravel";
|
||||
|
||||
if (element.timebonus != null) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue