Commit 5a6c7809 authored by Vladimír Ulman's avatar Vladimír Ulman
Browse files

S ADD,FIX: changing spheres, lines etc. content shall be now

           synchronized upon DisplayScene::lockOnChaningSceneContent
parent 54834f0e
......@@ -218,6 +218,8 @@ public class CommandFromCLI implements Runnable
void CreateFakeCells()
{
synchronized (scene.lockOnChangingSceneContent)
{
final float xStep = scene.sceneSize[0] / 6.0f;
final float yStep = scene.sceneSize[1] / 6.0f;
......@@ -255,5 +257,6 @@ public class CommandFromCLI implements Runnable
scene.addUpdateOrRemovePoint(ID,c);
}
}
}
}
}
......@@ -229,7 +229,13 @@ public class DisplayScene extends SceneryBase implements Runnable
private int tickCounter = 0;
//
public
void increaseTickCounter() { ++tickCounter; }
void increaseTickCounter()
{
synchronized (lockOnChangingSceneContent)
{
++tickCounter;
}
}
/** attempts to turn on/off the "push mode", and reports the state */
public
......@@ -418,6 +424,14 @@ public class DisplayScene extends SceneryBase implements Runnable
//----------------------------------------------------------------------------
/** A handle on a lock (synchronization subject) that shall be used when a caller
wants to modify any of the pointNodes, lineNodes, vectorNodes or tickCounter.
Since the DisplayScene's API for updating the displayed graphics was not
designed for concurrent access, the callers have to synchronize explicitly
among themselves. And they shall do it precisely around this attribute. */
public final Object lockOnChangingSceneContent = new Object();
/** these points are registered with the display, but not necessarily always visible */
private final Map<Integer,Point> pointNodes = new HashMap<>();
/** these lines are registered with the display, but not necessarily always visible */
......@@ -430,6 +444,8 @@ public class DisplayScene extends SceneryBase implements Runnable
public
void addUpdateOrRemovePoint(final int ID,final Point p)
{
synchronized (lockOnChangingSceneContent)
{
//attempt to retrieve node of this ID
Point n = pointNodes.get(ID);
......@@ -465,6 +481,7 @@ public class DisplayScene extends SceneryBase implements Runnable
n.lastSeenTick = tickCounter;
this.nodeSetNeedsUpdate(n.node);
}
}
......@@ -472,6 +489,8 @@ public class DisplayScene extends SceneryBase implements Runnable
public
void addUpdateOrRemoveLine(final int ID,final Line l)
{
synchronized (lockOnChangingSceneContent)
{
//attempt to retrieve node of this ID
Line n = lineNodes.get(ID);
......@@ -510,6 +529,7 @@ public class DisplayScene extends SceneryBase implements Runnable
n.node.setMaterial(materials[n.color % materials.length]);
n.lastSeenTick = tickCounter;
}
}
......@@ -517,6 +537,8 @@ public class DisplayScene extends SceneryBase implements Runnable
public
void addUpdateOrRemoveVector(final int ID,final Vector v)
{
synchronized (lockOnChangingSceneContent)
{
//attempt to retrieve node of this ID
Vector n = vectorNodes.get(ID);
......@@ -563,14 +585,18 @@ public class DisplayScene extends SceneryBase implements Runnable
n.lastSeenTick = tickCounter;
this.nodeSetNeedsUpdate(n.node);
}
}
public
void removeAllObjects()
{
synchronized (lockOnChangingSceneContent)
{
tickCounter = Integer.MAX_VALUE;
garbageCollect(-1);
}
}
public
......@@ -583,6 +609,8 @@ public class DisplayScene extends SceneryBase implements Runnable
public
void garbageCollect(int tolerance)
{
synchronized (lockOnChangingSceneContent)
{
//NB: HashMap may be modified while being swept through only via iterator
// (and iterator must remove the elements actually)
Iterator<Integer> i = pointNodes.keySet().iterator();
......@@ -621,6 +649,7 @@ public class DisplayScene extends SceneryBase implements Runnable
i.remove();
}
}
}
}
//
/** flag for external modules to see if they should call garbageCollect() */
......@@ -646,7 +675,10 @@ public class DisplayScene extends SceneryBase implements Runnable
public
void suspendNodesUpdating()
{
synchronized (lockOnChangingSceneContent)
{
updateNodesImmediately = false;
}
}
/** calls processNodesYetToBeSmth() and switches back to the 'online process' mode,
......@@ -654,8 +686,11 @@ public class DisplayScene extends SceneryBase implements Runnable
public
void resumeNodesUpdating()
{
synchronized (lockOnChangingSceneContent)
{
updateNodesImmediately = true;
processNodesYetToBeSmth();
}
}
/** processes (ideally at the same time) and clears the content of
......@@ -718,12 +753,15 @@ public class DisplayScene extends SceneryBase implements Runnable
void setVectorsStretch(final float vs)
{
synchronized (lockOnChangingSceneContent)
{
//update the stretch factor...
vectorsStretch = vs;
vectorsStretchGLvec = new GLVector(vectorsStretch,3);
//...and rescale all vectors presently existing in the system
vectorNodes.values().forEach( n -> n.node.setScale(vectorsStretchGLvec) );
}
}
/** shortcut zero vector to prevent from coding "new GLVector(0.f,3)" where needed */
......@@ -757,6 +795,8 @@ public class DisplayScene extends SceneryBase implements Runnable
public
boolean ToggleDisplayCellSpheres()
{
synchronized (lockOnChangingSceneContent)
{
//toggle the flag
spheresShown.g_Mode ^= true;
......@@ -766,33 +806,42 @@ public class DisplayScene extends SceneryBase implements Runnable
showOrHideMe(ID,pointNodes.get(ID).node,spheresShown);
return spheresShown.g_Mode;
}
}
public
boolean ToggleDisplayCellLines()
{
synchronized (lockOnChangingSceneContent)
{
linesShown.g_Mode ^= true;
for (Integer ID : lineNodes.keySet())
showOrHideMe(ID,lineNodes.get(ID).node,linesShown);
return linesShown.g_Mode;
}
}
public
boolean ToggleDisplayCellVectors()
{
synchronized (lockOnChangingSceneContent)
{
vectorsShown.g_Mode ^= true;
for (Integer ID : vectorNodes.keySet())
showOrHideMe(ID,vectorNodes.get(ID).node,vectorsShown);
return vectorsShown.g_Mode;
}
}
public
boolean ToggleDisplayCellDebug()
{
synchronized (lockOnChangingSceneContent)
{
cellDebugShown ^= true;
//"debug" objects might be present in any shape primitive
......@@ -804,12 +853,15 @@ public class DisplayScene extends SceneryBase implements Runnable
showOrHideMe(ID,vectorNodes.get(ID).node,vectorsShown);
return cellDebugShown;
}
}
public
boolean ToggleDisplayGeneralDebugSpheres()
{
synchronized (lockOnChangingSceneContent)
{
//toggle the flag
spheresShown.G_Mode ^= true;
......@@ -819,33 +871,42 @@ public class DisplayScene extends SceneryBase implements Runnable
showOrHideMe(ID,pointNodes.get(ID).node,spheresShown);
return spheresShown.G_Mode;
}
}
public
boolean ToggleDisplayGeneralDebugLines()
{
synchronized (lockOnChangingSceneContent)
{
linesShown.G_Mode ^= true;
for (Integer ID : lineNodes.keySet())
showOrHideMe(ID,lineNodes.get(ID).node,linesShown);
return linesShown.G_Mode;
}
}
public
boolean ToggleDisplayGeneralDebugVectors()
{
synchronized (lockOnChangingSceneContent)
{
vectorsShown.G_Mode ^= true;
for (Integer ID : vectorNodes.keySet())
showOrHideMe(ID,vectorNodes.get(ID).node,vectorsShown);
return vectorsShown.G_Mode;
}
}
public
boolean ToggleDisplayGeneralDebug()
{
synchronized (lockOnChangingSceneContent)
{
generalDebugShown ^= true;
//"debug" objects might be present in any shape primitive
......@@ -857,6 +918,7 @@ public class DisplayScene extends SceneryBase implements Runnable
showOrHideMe(ID,vectorNodes.get(ID).node,vectorsShown);
return generalDebugShown;
}
}
......
......@@ -14,11 +14,6 @@ import de.mpicbg.ulman.simviewer.DisplayScene;
* is utilized, e.g., in the CommandFromNetwork and CommandFromFlightRecorder
* classes.
*
* Since the DisplayScene's API for updating the displayed graphics was not
* designed for concurrent access, the callers have to synchronize explicitly
* among themselves. This is why, the methods of this class are synchronized
* on this object.
*
* This file was created and is being developed by Vladimir Ulman, 2019.
*/
public class NetMessagesProcessor
......@@ -34,10 +29,12 @@ public class NetMessagesProcessor
may trigger a short waiting before a screen shot of the commanding window is
requested (see the code of the processTickMessage()) and the waiting can be
interrupted, this method may throw an InterruptedException */
public synchronized
public
void processMsg(final String msg)
throws InterruptedException
{
synchronized (scene.lockOnChangingSceneContent)
{
try {
if (msg.startsWith("v1 points")) processPoints(msg);
else
......@@ -54,6 +51,7 @@ public class NetMessagesProcessor
catch (java.util.InputMismatchException e) {
System.out.println("NetMessagesProcessor: Parsing error: " + e.getMessage());
}
}
}
//----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment