mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
optimize rendering a lil
This commit is contained in:
parent
9cdd73db7c
commit
41ed938d5f
7 changed files with 88 additions and 50 deletions
|
|
@ -366,7 +366,7 @@ class Marble extends GameObject {
|
|||
|
||||
if (Settings.optionsSettings.reflectionDetail > 0) {
|
||||
var csky = level != null ? level.sky : (@:privateAccess MarbleGame.instance.previewWorld.sky);
|
||||
this.cubemapRenderer = new CubemapRenderer(MarbleGame.instance.scene, csky, !this.controllable);
|
||||
this.cubemapRenderer = new CubemapRenderer(MarbleGame.instance.scene, csky, !this.controllable && level != null);
|
||||
|
||||
if (Settings.optionsSettings.marbleShader == null
|
||||
|| Settings.optionsSettings.marbleShader == "Default"
|
||||
|
|
@ -545,8 +545,8 @@ class Marble extends GameObject {
|
|||
|
||||
public function getMarbleAxis() {
|
||||
var motiondir = new Vector(0, -1, 0);
|
||||
if (level.isReplayingMovement)
|
||||
return level.currentInputMoves[1].marbleAxes;
|
||||
// if (level.isReplayingMovement)
|
||||
// return level.currentInputMoves[1].marbleAxes;
|
||||
if (this.controllable && !this.isNetUpdate) {
|
||||
motiondir.transform(Matrix.R(0, 0, camera.CameraYaw));
|
||||
motiondir.transform(level.newOrientationQuat.toMatrix());
|
||||
|
|
@ -642,8 +642,8 @@ class Marble extends GameObject {
|
|||
var R = currentGravityDir.multiply(-this._radius);
|
||||
var rollVelocity = this.omega.cross(R);
|
||||
var axes = this.getMarbleAxis();
|
||||
if (!level.isReplayingMovement)
|
||||
level.inputRecorder.recordAxis(axes);
|
||||
// if (!level.isReplayingMovement)
|
||||
// level.inputRecorder.recordAxis(axes);
|
||||
var sideDir = axes[0];
|
||||
var motionDir = axes[1];
|
||||
var upDir = axes[2];
|
||||
|
|
@ -923,7 +923,7 @@ class Marble extends GameObject {
|
|||
}
|
||||
|
||||
function bounceEmitter(speed:Float, normal:Vector) {
|
||||
if (!this.controllable || level.isReplayingMovement || this.isNetUpdate)
|
||||
if (!this.controllable || this.isNetUpdate)
|
||||
return;
|
||||
if (this.bounceEmitDelay == 0 && this._minBounceSpeed <= speed) {
|
||||
this.level.particleManager.createEmitter(bounceParticleOptions, this.bounceEmitterData,
|
||||
|
|
@ -958,7 +958,7 @@ class Marble extends GameObject {
|
|||
}
|
||||
|
||||
function playBoundSound(time:Float, contactVel:Float) {
|
||||
if (level.isReplayingMovement || this.isNetUpdate)
|
||||
if (this.isNetUpdate)
|
||||
return;
|
||||
if (minVelocityBounceSoft <= contactVel) {
|
||||
var hardBounceSpeed = minVelocityBounceHard;
|
||||
|
|
@ -990,8 +990,8 @@ class Marble extends GameObject {
|
|||
}
|
||||
|
||||
function updateRollSound(time:TimeState, contactPct:Float, slipAmount:Float) {
|
||||
if (level.isReplayingMovement)
|
||||
return;
|
||||
// if (level.isReplayingMovement)
|
||||
// return;
|
||||
var rSpat = rollSound.getEffect(Spatialization);
|
||||
rSpat.position = this.collider.transform.getPosition();
|
||||
|
||||
|
|
@ -1656,7 +1656,7 @@ class Marble extends GameObject {
|
|||
|
||||
newPos = this.collider.transform.getPosition();
|
||||
|
||||
if (this.prevPos != null) {
|
||||
if (this.prevPos != null && this.level != null) {
|
||||
var tempTimeState = timeState.clone();
|
||||
tempTimeState.currentAttemptTime = passedTime;
|
||||
this.level.callCollisionHandlers(cast this, tempTimeState, oldPos, newPos);
|
||||
|
|
@ -1918,8 +1918,8 @@ class Marble extends GameObject {
|
|||
move = recordMove();
|
||||
}
|
||||
|
||||
if (level.isReplayingMovement)
|
||||
move = level.currentInputMoves[1].move;
|
||||
// if (level.isReplayingMovement)
|
||||
// move = level.currentInputMoves[1].move;
|
||||
|
||||
if (this.controllable && this.level.isWatching) {
|
||||
move = new Move();
|
||||
|
|
@ -1934,7 +1934,7 @@ class Marble extends GameObject {
|
|||
this.level.replay.recordMarbleInput(move.d.x, move.d.y);
|
||||
}
|
||||
}
|
||||
if (!this.controllable && this.connection != null) {
|
||||
if (!this.controllable && (this.connection != null || this.level == null)) {
|
||||
move = new Move();
|
||||
move.d = new Vector(0, 0);
|
||||
}
|
||||
|
|
@ -2226,6 +2226,8 @@ class Marble extends GameObject {
|
|||
}
|
||||
|
||||
inline function isHelicopterEnabled(timeState:TimeState) {
|
||||
if (this.level == null)
|
||||
return false;
|
||||
if (!this.level.isMultiplayer) {
|
||||
return timeState.currentAttemptTime - this.helicopterEnableTime < 5;
|
||||
} else {
|
||||
|
|
@ -2238,6 +2240,8 @@ class Marble extends GameObject {
|
|||
}
|
||||
|
||||
inline function isMegaMarbleEnabled(timeState:TimeState) {
|
||||
if (this.level == null)
|
||||
return false;
|
||||
if (!this.level.isMultiplayer) {
|
||||
return timeState.currentAttemptTime - this.megaMarbleEnableTime < 10;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package src;
|
||||
|
||||
import net.Net;
|
||||
import gui.LevelSelectGui;
|
||||
import gui.MainMenuGui;
|
||||
#if !js
|
||||
|
|
@ -189,7 +190,7 @@ class MarbleGame {
|
|||
if (Util.isTouchDevice()) {
|
||||
touchInput.update();
|
||||
}
|
||||
if (!paused) {
|
||||
if (!paused || world.isMultiplayer) {
|
||||
world.update(dt * Debug.timeScale);
|
||||
}
|
||||
if (((Key.isPressed(Key.ESCAPE) #if js && paused #end) || Gamepad.isPressed(["start"]))
|
||||
|
|
|
|||
|
|
@ -1096,7 +1096,7 @@ class MarbleWorld extends Scheduler {
|
|||
if (ourMoveStruct != null) {
|
||||
var otherPred = predictions.retrieveState(clientMarbles[Net.clientIdMap[client]], ourMoveStruct.timeState.ticks);
|
||||
if (otherPred != null) {
|
||||
if (otherPred.getError(lastMove) > 0.001) {
|
||||
if (otherPred.getError(lastMove) > 0.1) {
|
||||
Debug.drawSphere(@:privateAccess clientMarbles[Net.clientIdMap[client]].newPos, 0.2, 0.5);
|
||||
// trace('Prediction error: ${otherPred.getError(lastMove)}');
|
||||
trace('Desync for tick ${ourMoveStruct.timeState.ticks}');
|
||||
|
|
@ -1129,7 +1129,7 @@ class MarbleWorld extends Scheduler {
|
|||
if (ourMoveStruct != null) {
|
||||
var ourPred = predictions.retrieveState(marble, ourMoveStruct.timeState.ticks);
|
||||
if (ourPred != null) {
|
||||
if (ourPred.getError(ourMove) > 0.001) {
|
||||
if (ourPred.getError(ourMove) > 0.1) {
|
||||
trace('Desync for tick ${ourMoveStruct.timeState.ticks}');
|
||||
marble.unpackUpdate(ourMove);
|
||||
needsPrediction |= 1 << Net.clientId;
|
||||
|
|
@ -1200,11 +1200,11 @@ class MarbleWorld extends Scheduler {
|
|||
var m = arr.packets[0];
|
||||
// if (m.serverTicks == ourLastMoveTime) {
|
||||
var marbleToUpdate = clientMarbles[Net.clientIdMap[client]];
|
||||
Debug.drawSphere(@:privateAccess marbleToUpdate.newPos, marbleToUpdate._radius);
|
||||
// Debug.drawSphere(@:privateAccess marbleToUpdate.newPos, marbleToUpdate._radius);
|
||||
|
||||
var distFromUs = @:privateAccess marbleToUpdate.newPos.distance(this.marble.newPos);
|
||||
// if (distFromUs < 5)
|
||||
m.calculationTicks = ourQueuedMoves.length; // ourQueuedMoves.length;
|
||||
m.calculationTicks = ourQueuedMoves.length;
|
||||
// else
|
||||
// m.calculationTicks = Std.int(Math.max(1, ourQueuedMoves.length - (distFromUs - 5) / 3));
|
||||
// - Std.int((@:privateAccess Net.clientConnection.moveManager.ackRTT - ourLastMove.moveQueueSize) / 2);
|
||||
|
|
@ -1220,7 +1220,7 @@ class MarbleWorld extends Scheduler {
|
|||
|
||||
for (move in ourQueuedMoves) {
|
||||
var m = move.move;
|
||||
// Debug.drawSphere(@:privateAccess this.marble.newPos, this.marble._radius);
|
||||
Debug.drawSphere(@:privateAccess this.marble.newPos, this.marble._radius);
|
||||
if (marbleNeedsPrediction & (1 << Net.clientId) > 0) {
|
||||
@:privateAccess this.marble.moveMotionDir = move.motionDir;
|
||||
@:privateAccess this.marble.advancePhysics(advanceTimeState, m, this.collisionWorld, this.pathedInteriors);
|
||||
|
|
@ -1231,7 +1231,7 @@ class MarbleWorld extends Scheduler {
|
|||
for (client => m in marblesToTick) {
|
||||
if (m.calculationTicks > 0) {
|
||||
var marbleToUpdate = clientMarbles[Net.clientIdMap[client]];
|
||||
// Debug.drawSphere(@:privateAccess marbleToUpdate.newPos, marbleToUpdate._radius);
|
||||
Debug.drawSphere(@:privateAccess marbleToUpdate.newPos, marbleToUpdate._radius);
|
||||
|
||||
var mv = m.move.move;
|
||||
@:privateAccess marbleToUpdate.isNetUpdate = true;
|
||||
|
|
@ -1262,6 +1262,14 @@ class MarbleWorld extends Scheduler {
|
|||
}
|
||||
}
|
||||
|
||||
public function removePlayer(cc:ClientConnection) {
|
||||
var otherMarble = this.clientMarbles[cc];
|
||||
this.predictions.removeMarbleFromPrediction(otherMarble);
|
||||
this.scene.removeChild(otherMarble);
|
||||
this.collisionWorld.removeMarbleEntity(otherMarble.collider);
|
||||
otherMarble.dispose();
|
||||
}
|
||||
|
||||
public function rollback(t:Float) {
|
||||
var newT = timeState.currentAttemptTime - t;
|
||||
var rewindFrame = rewindManager.getNextRewindFrame(timeState.currentAttemptTime - t);
|
||||
|
|
@ -1439,9 +1447,9 @@ class MarbleWorld extends Scheduler {
|
|||
obj.update(timeState);
|
||||
}
|
||||
|
||||
if (!isReplayingMovement) {
|
||||
inputRecorder.recordInput(timeState.currentAttemptTime);
|
||||
}
|
||||
// if (!isReplayingMovement) {
|
||||
// inputRecorder.recordInput(timeState.currentAttemptTime);
|
||||
// }
|
||||
|
||||
ProfilerUI.measure("updateMarbles");
|
||||
if (this.isMultiplayer) {
|
||||
|
|
@ -1535,9 +1543,9 @@ class MarbleWorld extends Scheduler {
|
|||
if (!this.rewinding && Settings.optionsSettings.rewindEnabled && !this.isMultiplayer)
|
||||
this.rewindManager.recordFrame();
|
||||
|
||||
if (!this.isReplayingMovement) {
|
||||
inputRecorder.recordMarble();
|
||||
}
|
||||
// if (!this.isReplayingMovement) {
|
||||
// inputRecorder.recordMarble();
|
||||
// }
|
||||
|
||||
this.updateTexts();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ class Renderer extends h3d.scene.Renderer {
|
|||
var growBufferTemps:Array<h3d.mat.Texture>;
|
||||
var copyPass:h3d.pass.Copy;
|
||||
var backBuffer:h3d.mat.Texture;
|
||||
var tempCubemapBuffer:h3d.mat.Texture;
|
||||
var tempCubemapIndex:Int;
|
||||
|
||||
public static var dirtyBuffers:Bool = true;
|
||||
|
||||
|
|
@ -51,6 +53,11 @@ class Renderer extends h3d.scene.Renderer {
|
|||
return sfxBuffer;
|
||||
}
|
||||
|
||||
public function setCubemapBuffer(tex:h3d.mat.Texture, idx:Int) {
|
||||
tempCubemapBuffer = tex;
|
||||
tempCubemapIndex = idx;
|
||||
}
|
||||
|
||||
inline function get_def()
|
||||
return defaultPass;
|
||||
|
||||
|
|
@ -93,7 +100,11 @@ class Renderer extends h3d.scene.Renderer {
|
|||
backBuffer = ctx.textures.allocTarget("backBuffer", cast ctx.engine.width / pixelRatio, cast ctx.engine.height / pixelRatio, false);
|
||||
backBuffer.depthBuffer = depthBuffer;
|
||||
}
|
||||
ctx.engine.pushTarget(backBuffer);
|
||||
if (tempCubemapBuffer != null) {
|
||||
ctx.engine.pushTarget(tempCubemapBuffer, tempCubemapIndex);
|
||||
} else {
|
||||
ctx.engine.pushTarget(backBuffer);
|
||||
}
|
||||
ctx.engine.clear(0, 1);
|
||||
|
||||
if (has("shadow"))
|
||||
|
|
@ -184,9 +195,13 @@ class Renderer extends h3d.scene.Renderer {
|
|||
|
||||
ctx.engine.popTarget();
|
||||
|
||||
copyPass.pass.blend(One, Zero);
|
||||
copyPass.shader.texture = backBuffer;
|
||||
copyPass.render();
|
||||
if (tempCubemapBuffer != null) {
|
||||
tempCubemapBuffer = null;
|
||||
} else {
|
||||
copyPass.pass.blend(One, Zero);
|
||||
copyPass.shader.texture = backBuffer;
|
||||
copyPass.render();
|
||||
}
|
||||
|
||||
// h3d.pass.Copy.run(backBuffers[0], backBuffers[1]);
|
||||
// renderPass(defaultPass, get("refract"));
|
||||
|
|
@ -199,18 +214,25 @@ class Renderer extends h3d.scene.Renderer {
|
|||
function bloomPass(ctx:h3d.scene.RenderContext) {
|
||||
h3d.pass.Copy.run(glowBuffer, growBufferTemps[0]);
|
||||
|
||||
var offsets = [-7.5, -6.25, -5, -3.75, -2.5, -1.25, 0, 1.25, 2.5, 3.75, 5, 6.25, 7.5];
|
||||
var divisors = [0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 1.0, 0.7, 0.5, 0.5, 0.4, 0.3, 0.1];
|
||||
static var offsets = [-7.5, -6.25, -5, -3.75, -2.5, -1.25, 0, 1.25, 2.5, 3.75, 5, 6.25, 7.5];
|
||||
static var divisors = [0.1, 0.3, 0.4, 0.5, 0.6, 0.7, 1.0, 0.7, 0.5, 0.5, 0.4, 0.3, 0.1];
|
||||
|
||||
var divisor = 0.0;
|
||||
|
||||
var kernel = [];
|
||||
for (i in 0...13) {
|
||||
kernel.push(new Vector(offsets[i] / 320, 0, divisors[i]));
|
||||
divisor += divisors[i];
|
||||
static var divisor = 0.0;
|
||||
static var kernelX = [];
|
||||
static var kernelY = [];
|
||||
static var kernelComputed = false;
|
||||
if (!kernelComputed) {
|
||||
for (i in 0...13) {
|
||||
kernelX.push(new Vector(offsets[i] / 320, 0, divisors[i]));
|
||||
divisor += divisors[i];
|
||||
}
|
||||
for (i in 0...13) {
|
||||
kernelY.push(new Vector(0, offsets[i] / 320, divisors[i]));
|
||||
}
|
||||
kernelComputed = true;
|
||||
}
|
||||
|
||||
blurShader.shader.kernel = kernel;
|
||||
blurShader.shader.kernel = kernelX;
|
||||
blurShader.shader.divisor = divisor;
|
||||
blurShader.shader.texture = growBufferTemps[0];
|
||||
ctx.engine.pushTarget(growBufferTemps[1]);
|
||||
|
|
@ -218,11 +240,7 @@ class Renderer extends h3d.scene.Renderer {
|
|||
blurShader.render();
|
||||
ctx.engine.popTarget();
|
||||
|
||||
for (i in 0...13) {
|
||||
kernel[i].set(0, offsets[i] / 320, divisors[i]);
|
||||
}
|
||||
|
||||
blurShader.shader.kernel = kernel;
|
||||
blurShader.shader.kernel = kernelY;
|
||||
blurShader.shader.divisor = divisor;
|
||||
blurShader.shader.texture = growBufferTemps[1];
|
||||
ctx.engine.pushTarget(growBufferTemps[0]);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class MarblePrediction {
|
|||
if (p.netFlags != 0)
|
||||
subs += 1;
|
||||
// if (p.powerUpId != powerupItemId)
|
||||
subs += 1; // temp
|
||||
// subs += 1; // temp
|
||||
// if (isControl)
|
||||
// subs += Math.abs(blastAmount - p.blastAmount);
|
||||
return subs;
|
||||
|
|
@ -78,4 +78,8 @@ class MarblePredictionStore {
|
|||
arr.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public function removeMarbleFromPrediction(marble:Marble) {
|
||||
this.predictions.remove(marble);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import haxe.Json;
|
|||
import net.Net.ServerInfo;
|
||||
import hx.ws.WebSocket;
|
||||
import src.Console;
|
||||
import hx.ws.Types.MessageType;
|
||||
|
||||
typedef RemoteServerInfo = {
|
||||
name:String,
|
||||
|
|
@ -15,7 +16,7 @@ typedef RemoteServerInfo = {
|
|||
}
|
||||
|
||||
class MasterServerClient {
|
||||
static var serverIp = "ws://localhost:8080";
|
||||
static var serverIp = "ws://89.58.58.191:8080";
|
||||
public static var instance:MasterServerClient;
|
||||
|
||||
var ws:WebSocket;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class CubemapRenderer {
|
|||
if (useSky)
|
||||
this.cubemap = sky.cubemap;
|
||||
else {
|
||||
this.cubemap = new Texture(128, 128, [Cube, Dynamic, Target], h3d.mat.Data.TextureFormat.RGB8);
|
||||
this.cubemap = new Texture(128, 128, [Cube, Dynamic, Target], h3d.mat.Data.TextureFormat.RGBA);
|
||||
this.cubemap.depthBuffer = new h3d.mat.DepthBuffer(128, 128, h3d.mat.DepthBuffer.DepthFormat.Depth24);
|
||||
}
|
||||
this.camera = new Camera(90, 1, 1, 0.1, 1000);
|
||||
|
|
@ -46,11 +46,13 @@ class CubemapRenderer {
|
|||
if (Settings.optionsSettings.reflectionDetail >= 4)
|
||||
Renderer.dirtyBuffers = true;
|
||||
|
||||
e.pushTarget(cubemap, index);
|
||||
// e.pushTarget(cubemap, index);
|
||||
var ourRenderer = cast(scene.renderer, Renderer);
|
||||
ourRenderer.setCubemapBuffer(cubemap, index);
|
||||
this.camera.setCubeMap(index, position);
|
||||
e.clear(0, 1);
|
||||
// e.clear(0, 1);
|
||||
scene.render(e);
|
||||
e.popTarget();
|
||||
// e.popTarget();
|
||||
|
||||
renderedFaces++;
|
||||
var time = haxe.Timer.stamp();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue