View Javadoc

1   /*
2    * Created on 2004-12-10
3    *
4    * TODO To change the template for this generated file go to
5    * Window - Preferences - Java - Code Style - Code Templates
6    */
7   package org.sourceforge.jvb3d.Model;
8   
9   import java.util.Enumeration;
10  
11  import javax.media.j3d.Behavior;
12  import javax.media.j3d.WakeupOnElapsedFrames;
13  
14  import com.sun.j3d.utils.timer.J3DTimer;
15  import java.lang.Thread;
16  import java.io.FileWriter;
17  
18  /***
19   * @author spootnick
20   *
21   * Klasa odpowiedzialna za wywoływanie metod liczący stany logiki w kolejnych chwilach czasowych
22   */
23  public class LogicBehavior extends Behavior {
24  	
25  	private Model model;
26  	private WakeupOnElapsedFrames condition= new WakeupOnElapsedFrames(1);
27  	private long lastEvent,event;
28  	private FileWriter file;
29  	
30  	/***
31  	 * Tworzy obiekt dla danego modelu
32  	 * @param model referencja do modelu (części logiki)
33  	 */
34  	public LogicBehavior(Model model){
35  		this.model=model;
36  			
37  	}
38  	/***
39  	 * @see javax.media.j3d.Behavior#initialize()
40  	 */
41  	public void initialize() {
42  		//set initial wakeup condition
43  		this.wakeupOn(condition);
44  		lastEvent=J3DTimer.getValue();
45  	}
46  
47  	/***
48  	 * @see javax.media.j3d.Behavior#processStimulus(java.util.Enumeration)
49  	 */
50  	public void processStimulus(Enumeration arg0){
51  		//do what is necessary in response to stimulus
52  		
53  		event=J3DTimer.getValue();
54  	
55  		model.nextTurn(event-lastEvent);
56  		lastEvent=event;
57  	
58  		this.wakeupOn(condition);
59  	}
60  
61  }