Commit 39be0e66 authored by Nico Mack's avatar Nico Mack

Implementation of ModeChangeEvents

parent c20d1eec
......@@ -47,6 +47,7 @@ EFFECTIVITY_THRESHOLD_NODE=effectivityThreshold
EMPTY_STRING=
END_NODE=end
ENDING_NODE=ending
ENERGY_THRESHOLD_NODE=energyThreshold
EXCLUSIVE_NODE=exclusive
FACE_COLOUR_ELEMENT=faceColour
FADE_IN_TIME_NODE=fadeInTime
......
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.event.modal;
import java.util.List;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
public interface Modal {
/**
* returns a list of all possible modes the implementing class may be in.
*
* @return a list of possible modes.
*/
List<String> getModes();
/**
* adds the specified listener to the list of listeners to be notified when a mode change occurred.
*
* @param listener
* specifies the listener wishing to be notified when a mode change occurs.
*/
public void addModeChangeListener(ModeChangeListener listener);
/**
* removes the specified listener from the list of listeners to be notified when a mode change
* occurred.
*
* @param listener
* specifies the listener wishing to no longer be notified when a mode change occurs.
*/
public void removeModeChangeListener(ModeChangeListener listener);
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.event.modal;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class ModeChangeEvent {
private Object source;
private String currentMode;
private String previousMode;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param source
* @param previousMode
* @param currentMode
*/
// ---------------------------------------------------------------------------
public ModeChangeEvent(Object source, String previousMode, String currentMode) {
this.source = source;
this.previousMode = previousMode;
this.currentMode = currentMode;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* Simple getter method for source.
*
* @return The value of source.
*/
// ---------------------------------------------------------------------------
public Object getSource() {
return source;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for currentMode.
*
* @return The value of currentMode.
*/
// ---------------------------------------------------------------------------
public String getCurrentMode() {
return currentMode;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for previousMode.
*
* @return The value of previousMode.
*/
// ---------------------------------------------------------------------------
public String getPreviousMode() {
return previousMode;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
/**
* Copyright Luxembourg Institute of Science and Technology, 2018. All rights reserved.
*
* This file is part of TULIP.
*
* TULIP is free software: you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation, version 3 of the
* License.
*
* TULIP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with TULIP. If
* not, see <http://www.gnu.org/licenses/lgpl-3.0.html>.
*/
package lu.list.itis.dkd.tui.event.modal;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
public interface ModeChangeListener {
/**
* @param event
*/
public void modeChanged(ModeChangeEvent event);
}
package lu.list.itis.dkd.tui.event.modal;
import java.util.ArrayList;
import java.util.List;
/**
* @author Nico Mack [nico.mack@list.lu]
* @since 2.5
* @version 1.0.0
*/
// ***************************************************************************
// * Class Definition and Members *
// ***************************************************************************
public class ModeEventSource {
private List<ModeChangeListener> listeners;
// ***************************************************************************
// * Constants *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public ModeEventSource() {
listeners = new ArrayList<>();
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Primitives *
// ***************************************************************************
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Class Body *
// ***************************************************************************
// ---------------------------------------------------------------------------
/**
* @param listener
*/
// ---------------------------------------------------------------------------
public void addModeChangeListener(ModeChangeListener listener) {
listeners.add(listener);
}
// ---------------------------------------------------------------------------
/**
* @param listener
*/
// ---------------------------------------------------------------------------
public void removeModeChangeListener(ModeChangeListener listener) {
listeners.remove(listener);
}
// ---------------------------------------------------------------------------
/**
* @param event
*/
// ---------------------------------------------------------------------------
public void notifyModeChangeListener(ModeChangeEvent event) {
for (ModeChangeListener listener : listeners) {
listener.modeChanged(event);
}
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of Class *
// ***************************************************************************
// ---------------------------------------------------------------------------
}
\ No newline at end of file
......@@ -82,6 +82,7 @@ public class Externalization extends NLS {
public static String EMPTY_STRING;
public static String END_NODE;
public static String ENDING_NODE;
public static String ENERGY_THRESHOLD_NODE;
public static String EXCLUSIVE_NODE;
public static String FACE_COLOUR_ELEMENT;
public static String FADE_IN_TIME_NODE;
......
......@@ -366,7 +366,7 @@ public class Point extends Float implements Comparable<Point>, KdComparator<Poin
* The first point to test for equality.
* @param b
* The second point to test for equality.
* @return <code>True</code> if and only if a.agle == b.angle within the delta of a floating point
* @return <code>True</code> if and only if a.angle == b.angle within the delta of a floating point
* number, and both points hold the same class of {@link CoordinateState}.
*/
public static boolean areAnglesEqual(Point a, Point b) {
......
......@@ -550,7 +550,7 @@ public abstract class Corona implements Comparable<Corona>, Cloneable, Touchable
/**
* Comparison as defined by the {@link Comparable} interface. This comparison is based on the
* integer comparison of the draw priorities, ordering lower priorities first. This will result in
* lower priority {@link Corona} instances being overlapped by prioritised ones.<br>
* lower priority {@link Corona} instances being overlapped by prioritized ones.<br>
* <br>
*
* <b>Note</b>: As the {@link Multimap} used to store {@link Corona} instances uses the
......
......@@ -42,6 +42,8 @@ public class Force {
private double effectivityThreshold;
private double energyThreshold;
// ---------------------------------------------------------------------------
// ***************************************************************************
// * Constructor(s) *
......@@ -55,11 +57,12 @@ public class Force {
*/
// ---------------------------------------------------------------------------
public Force(double magnitude, double shortRange, double longRange, double effectivityThreshold) {
public Force(double magnitude, double shortRange, double longRange, double effectivityThreshold, double energyThreshold) {
this.magnitude = magnitude;
this.shortRange = shortRange;
this.longRange = longRange;
this.effectivityThreshold = effectivityThreshold;
this.energyThreshold = energyThreshold;
}
// ---------------------------------------------------------------------------
......@@ -76,6 +79,7 @@ public class Force {
this.shortRange = BootstrappingUtils.getContentAsDouble(forceElement, Externalization.SHORT_RANGE_NODE, BootstrappingUtils.MANDATORY, null, bootstrapContext);
this.longRange = BootstrappingUtils.getContentAsDouble(forceElement, Externalization.LONG_RANGE_NODE, BootstrappingUtils.MANDATORY, null, bootstrapContext);
this.effectivityThreshold = BootstrappingUtils.getContentAsDouble(forceElement, Externalization.EFFECTIVITY_THRESHOLD_NODE, BootstrappingUtils.OPTIONAL, 10e-1, bootstrapContext);
this.energyThreshold = BootstrappingUtils.getContentAsDouble(forceElement, Externalization.ENERGY_THRESHOLD_NODE, BootstrappingUtils.OPTIONAL, 10e-3, bootstrapContext);
}
// ---------------------------------------------------------------------------
......@@ -130,6 +134,18 @@ public class Force {
return effectivityThreshold;
}
// ---------------------------------------------------------------------------
/**
* Simple getter method for energyThreshold.
*
* @return The value of energyThreshold.
*/
// ---------------------------------------------------------------------------
public double getEnergyThreshold() {
return energyThreshold;
}
// ---------------------------------------------------------------------------
// ***************************************************************************
// * End of class *
......
......@@ -46,14 +46,15 @@ public class ForceManager implements Runnable {
private ForceGenerator generator;
private List<ForceReactive> potentialSubjects;
private List<Motionable> motionables;
private boolean running;
// ***************************************************************************
// * Constants *
// ***************************************************************************
private static final double HYSTERESIS = 5;
private static final long TIMESTEP = 40; // 40ms => 25 fps
private static final Logger logger = LoggerFactory.getLogger(ForceManager.class.getSimpleName());
private static final Logger LOGGER = LoggerFactory.getLogger(ForceManager.class.getSimpleName());
// ---------------------------------------------------------------------------
// ***************************************************************************
......@@ -69,6 +70,7 @@ public class ForceManager implements Runnable {
this.generator = generator;
this.potentialSubjects = new ArrayList<>();
this.motionables = new ArrayList<>();
this.running = false;
}
// ---------------------------------------------------------------------------
......@@ -148,7 +150,7 @@ public class ForceManager implements Runnable {
this.motionables.add((Motionable) potential);
}
} else {
logger.warn("Attempt to add an already known ForceReactive object as a potential subject!"); //$NON-NLS-1$
LOGGER.warn("Attempt to add an already known ForceReactive object as a potential subject!"); //$NON-NLS-1$
}
}
......@@ -168,7 +170,7 @@ public class ForceManager implements Runnable {
this.potentialSubjects.remove(potential);
this.motionables.remove(potential);
} else {
logger.warn("Attempt to remove an unknown ForceReactive object from list of potential subject!"); //$NON-NLS-1$
LOGGER.warn("Attempt to remove an unknown ForceReactive object from list of potential subject!"); //$NON-NLS-1$
}
}
......@@ -198,8 +200,42 @@ public class ForceManager implements Runnable {
/** {@inheritDoc} */
@Override
public void run() {
// TODO Auto-generated method stub
this.running = true;
Force generated = this.generator.getGeneratedForce();
Point origin = this.generator.getOrigin();
double threshold = generated.getEnergyThreshold();
double deltaT = (double) TIMESTEP / 1000;
double energy;
do {
energy = 0d;
for (Motionable motionable : this.motionables) {
this.exertForce(origin, motionable, generated);
motionable.updateVelocity(deltaT);
motionable.updatePosition(motionable.getPosition(), deltaT);
energy += motionable.getKineticEnergy();
}
try {
Thread.sleep(TIMESTEP);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} while (energy >= threshold);
LOGGER.info("Equilibrum reached!"); //$NON-NLS-1$
this.running = false;
}
// ---------------------------------------------------------------------------
/**
*
*/
// ---------------------------------------------------------------------------
public void start() {
if (!running && !this.motionables.isEmpty()) {
Thread runner = new Thread(this, "Force Manager"); //$NON-NLS-1$
runner.start();
}
}
// ---------------------------------------------------------------------------
......
......@@ -63,6 +63,8 @@ public class MotionManager {
public MotionManager(double mass) {
this.mass = mass;
this.acceleration = new Vector2D();
this.velocity = new Vector2D();
}
// ---------------------------------------------------------------------------
......
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