Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/cz/cvut/cognitive/distractors/BoxDistraction.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ public void collision(float tpf){

}
}

}
51 changes: 42 additions & 9 deletions src/cz/cvut/cognitive/distractors/DistractionClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import cz.cvut.cognitive.load.CognitiveFunction;
import eu.opends.car.SteeringCar;
import eu.opends.main.Simulator;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
Expand All @@ -23,17 +26,21 @@ Ensures that every distraction contains spawn (spawn) and remove method.
probability - preset value of every initialized
distraction
*/
public abstract class DistractionClass {
public abstract class DistractionClass implements Runnable {

private static ArrayList<DistractionClass> activeDistractors = new ArrayList<>();
//protected
protected float probability;
protected final float REWARD;
public final float COG_DIFFICULTY; //FIXME make protected too (WeatherD)
//private
private final static ArrayList<DistractionClass> activeDistractors = new ArrayList<>();
private final AtomicInteger tpf_atomic = new AtomicInteger();
private final int DURATION; //ms
/**
* if the Distraction is currently active/used
*/
private boolean isActive = false;
private Thread runner;

protected final Simulator sim;
protected final SteeringCar car;
Expand All @@ -60,6 +67,13 @@ protected DistractionClass(Simulator sim, float reward, float probability, float
this.manager = sim.getAssetManager();
this.bulletAppState = sim.getBulletAppState();
this.camera = sim.getCamera();

if(this.getClass().equals(TextDistraction.class)) {
DURATION=20000; //20sec
}
else {
DURATION = 5000; //TODO random/param
}
}

//abstract
Expand All @@ -82,14 +96,14 @@ public void update(float f) {
System.out.println("PROB="+probability+" n="+n+" active="+isActive+" "+this.getClass().getSimpleName());
if (n > this.probability || isActive || probability==0.0f) { return; }

spawn(f);

CognitiveFunction.distScore += this.COG_DIFFICULTY;
CognitiveFunction.activeDistCount++;
CognitiveFunction.activeDistNames[0] = 1; //FIXME remove
CognitiveFunction.activeDistNames[0] = 1; //FIXME remove

this.isActive = true;
}
tpf_atomic.set((int)f);
runner = new Thread(this);
runner.start();
}

/**
*
Expand All @@ -99,7 +113,7 @@ public boolean isActive() {
return isActive;
}

public void remove() {
private void remove() {
if(!isActive) return; //do nothing on inactive

remove_local();
Expand All @@ -111,4 +125,23 @@ public void remove() {
isActive=false;
}

@Override
public void run() {
// start
float step = (float)this.tpf_atomic.get();
spawn(step);
this.isActive = true;
System.out.println(this.getClass().getSimpleName()+" RUNNING "+step);
try {
//wait
System.out.println("SLEEP");
TimeUnit.MILLISECONDS.sleep(DURATION);
} catch (InterruptedException ex) {
Logger.getLogger(DistractionClass.class.getName()).log(Level.SEVERE, null, ex);
}
//collisions?
collision(step);
//remove
remove();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void clickAnswerButton(){
} else {
userAnswers[questionIndex] = answerField.getRealText();
answersToFile(answerField.getRealText(),userAnswersFilePath);
textDistraction.remove();
textDistraction.notify();

}
}
Expand All @@ -254,7 +254,7 @@ public void clickAnswerButton(){
public void clickCancelButton()
{
answersToFile("User clicked Cancel Button - no answer",userAnswersFilePath);
textDistraction.remove();
textDistraction.notify();
}

/**
Expand Down