Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StatefulObjects #1759

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public final void setDirection(Vector3f dir){
if (!direction.isUnitVector()) {
direction.normalizeLocal();
}
updateStates(null);
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion jme3-core/src/main/java/com/jme3/light/Light.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.Camera;
import com.jme3.scene.Spatial;
import com.jme3.util.StatefulObject;
import com.jme3.util.TempVars;
import java.io.IOException;

Expand All @@ -45,7 +46,7 @@
* <p>
* All light source types have a color.
*/
public abstract class Light implements Savable, Cloneable {
public abstract class Light extends StatefulObject implements Savable, Cloneable {

/**
* Describes the light type.
Expand Down Expand Up @@ -171,6 +172,7 @@ public float getLastDistance(){
*/
public void setColor(ColorRGBA color){
this.color.set(color);
updateStates(null);
}


Expand All @@ -189,6 +191,7 @@ public boolean isEnabled() {
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
updateStates(null);
}

public boolean isFrustumCheckNeeded() {
Expand Down
2 changes: 2 additions & 0 deletions jme3-core/src/main/java/com/jme3/light/PointLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public Vector3f getPosition() {
*/
public final void setPosition(Vector3f position) {
this.position.set(position);
updateStates(null);
}

/**
Expand Down Expand Up @@ -171,6 +172,7 @@ public final void setRadius(float radius) {
} else {
this.invRadius = 0;
}
updateStates(null);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions jme3-core/src/main/java/com/jme3/light/SpotLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public Vector3f getDirection() {

public final void setDirection(Vector3f direction) {
this.direction.set(direction);
updateStates(null);
}

public Vector3f getPosition() {
Expand All @@ -325,6 +326,7 @@ public Vector3f getPosition() {

public final void setPosition(Vector3f position) {
this.position.set(position);
updateStates(null);
}

public float getSpotRange() {
Expand Down Expand Up @@ -354,6 +356,7 @@ public void setSpotRange(float spotRange) {
} else {
this.invSpotRange = 0;
}
updateStates(null);
}

/**
Expand Down Expand Up @@ -387,6 +390,7 @@ public void setSpotInnerAngle(float spotInnerAngle) {
}
this.spotInnerAngle = spotInnerAngle;
computeAngleParameters();
updateStates(null);
}

/**
Expand All @@ -413,6 +417,7 @@ public void setSpotOuterAngle(float spotOuterAngle) {
}
this.spotOuterAngle = spotOuterAngle;
computeAngleParameters();
updateStates(null);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion jme3-core/src/main/java/com/jme3/renderer/Camera.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector4f;
import com.jme3.export.*;
import com.jme3.math.*;
import com.jme3.util.StatefulObject;
import com.jme3.util.TempVars;
import java.io.IOException;
import java.util.logging.Level;
Expand All @@ -70,7 +73,7 @@
* @author Mark Powell
* @author Joshua Slack
*/
public class Camera implements Savable, Cloneable {
public class Camera extends StatefulObject implements Savable, Cloneable {

private static final Logger logger = Logger.getLogger(Camera.class.getName());

Expand Down Expand Up @@ -1247,6 +1250,7 @@ public void updateViewProjection() {
//viewProjectionMatrix.set(viewMatrix).multLocal(projectionMatrix);
viewProjectionMatrix.set(projectionMatrix).multLocal(viewMatrix);
}
updateStates(null);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions jme3-core/src/main/java/com/jme3/scene/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
* @author Joshua Slack
*/
public class Node extends Spatial {
public enum StateUpdateHints {
INVALIDATE_UPDATE_LIST
}
private static final Logger logger = Logger.getLogger(Node.class.getName());
/**
* This node's children.
Expand Down Expand Up @@ -201,6 +204,7 @@ private void addUpdateChildren(SafeArrayList<Spatial> results) {
* that would change state.
*/
void invalidateUpdateList() {
updateStates(StateUpdateHints.INVALIDATE_UPDATE_LIST);
updateListValid = false;
if (parent != null) {
parent.invalidateUpdateList();
Expand Down
15 changes: 12 additions & 3 deletions jme3-core/src/main/java/com/jme3/scene/Spatial.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Node.StateUpdateHints;
import com.jme3.scene.control.Control;
import com.jme3.util.SafeArrayList;
import com.jme3.util.StatefulObject;
import com.jme3.util.TempVars;
import com.jme3.util.clone.Cloner;
import com.jme3.util.clone.IdentityCloneFunction;
Expand All @@ -68,8 +70,8 @@
* @author Joshua Slack
* @version $Revision: 4075 $, $Data$
*/
public abstract class Spatial implements Savable, Cloneable, Collidable,
CloneableSmartAsset, JmeCloneable, HasLocalTransform {
public abstract class Spatial extends StatefulObject implements Savable, Cloneable, Collidable, CloneableSmartAsset, JmeCloneable, HasLocalTransform {

private static final Logger logger = Logger.getLogger(Spatial.class.getName());

/**
Expand Down Expand Up @@ -775,6 +777,7 @@ public void addControl(Control control) {
boolean before = requiresUpdates();
controls.add(control);
control.setSpatial(this);
updateStates(StateUpdateHints.INVALIDATE_UPDATE_LIST);
boolean after = requiresUpdates();
// If the requirement to be updated has changed,
// then we need to let the parent node know, so it
Expand All @@ -799,6 +802,7 @@ public void removeControl(Class<? extends Control> controlType) {
break; // added to match the javadoc -pspeed
}
}
updateStates(StateUpdateHints.INVALIDATE_UPDATE_LIST);
boolean after = requiresUpdates();
// If the requirement to be updated has changed,
// then we need to let the parent node know, so it
Expand All @@ -824,13 +828,15 @@ public boolean removeControl(Control control) {
control.setSpatial(null);
}

boolean after = requiresUpdates();
updateStates(StateUpdateHints.INVALIDATE_UPDATE_LIST);
boolean after = requiresUpdates();
// If the requirement to be updated has changed,
// then we need to let the parent node know, so it
// can rebuild its update list.
if (parent != null && before != after) {
parent.invalidateUpdateList();
}

return result;
}

Expand Down Expand Up @@ -906,6 +912,7 @@ public void updateGeometricState() {
// assume that this Spatial is a leaf, a proper implementation
// for this method should be provided by Node.

int refreshFlagsCp = refreshFlags;
// NOTE: Update world transforms first because
// bound transform depends on them.
if ((refreshFlags & RF_LIGHTLIST) != 0) {
Expand All @@ -921,6 +928,8 @@ public void updateGeometricState() {
updateMatParamOverrides();
}
assert refreshFlags == 0;

updateStates(refreshFlagsCp);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/NanoTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ public void update() {
tpf = (getTime() - previousTime) * (1.0f / TIMER_RESOLUTION);
fps = 1.0f / tpf;
previousTime = getTime();
updateStates(null);
}

@Override
public void reset() {
startTime = System.nanoTime();
previousTime = getTime();
updateStates(null);
}
}
4 changes: 3 additions & 1 deletion jme3-core/src/main/java/com/jme3/system/Timer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
*/
package com.jme3.system;

import com.jme3.util.StatefulObject;

/**
* <code>Timer</code> is the base class for a high resolution timer. It is
* created from getTimer("display system")
*
* @author Mark Powell
* @version $Id: Timer.java,v 1.18 2007/03/09 10:19:34 rherlitz Exp $
*/
public abstract class Timer {
public abstract class Timer extends StatefulObject{

/**
* Returns the current time in ticks. A tick is an arbitrary measure of time
Expand Down
3 changes: 2 additions & 1 deletion jme3-core/src/main/java/com/jme3/util/NativeObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* collected by the garbage collector, and then invoke the proper destructor
* on the OpenGL library to delete it from memory.
*/
public abstract class NativeObject implements Cloneable {
public abstract class NativeObject extends StatefulObject implements Cloneable {

public static final int INVALID_ID = -1;

Expand Down Expand Up @@ -130,6 +130,7 @@ public int getId(){
* and its state needs to be updated.
*/
public void setUpdateNeeded(){
updateStates(null);
updateNeeded = true;
}

Expand Down
Loading