001:/*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/internalplugins/BenchmarkPlugin.java,v 1.2 2007/01/26 19:31:29 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is Java 3D(tm) Fly Through.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018:package org.jdesktop.j3dfly.utils.internalplugins;
019:
020:import org.jdesktop.j3dfly.plugins.PluginPreference;
021:import org.jdesktop.j3dfly.plugins.J3dFlyPlugin;
022:import org.jdesktop.j3dfly.J3dFly;
023:import org.jdesktop.j3dfly.J3dFlyContext;
024:import org.jdesktop.j3dfly.event.FlyEventListener;
025:import org.jdesktop.j3dfly.event.EventProcessor;
026:import org.jdesktop.j3dfly.event.FileLoadEvent;
027:import org.jdesktop.j3dfly.event.DefaultLightingRequiredEvent;
028:import org.jdesktop.j3dfly.utils.behaviors.PerfBehaviorListener;
029://import org.jdesktop.j3dfly.utils.behaviors.PerfBehavior;
030:import java.io.File;
031:
032:import javax.media.j3d.BranchGroup;
033:import javax.media.j3d.TransformGroup;
034:
035:/**
036: *
037: * @author paulby
038: * @version
039: */
040:public class BenchmarkPlugin extends org.jdesktop.j3dfly.plugins.J3dFlyPlugin
041: implements FlyEventListener, PerfBehaviorListener {
042:
043: private static String geometryFilename = "geometry/Buildings/CGSD_City.j3f";
044: private static String splineFilename = "benchmark/city_house.kbsp";
045: private static boolean finiteLoop = true;
046: private static int loopCount=10;
047: private static int memCount=0;
048:
049: /** Creates new BenchMarkPlugin */
050: public BenchmarkPlugin() {
051: }
052:
053: /**
054: * Install the plugin into j3dfly with the supplied preferences
055: */
056: public void installPlugin( PluginPreference pluginPref, J3dFlyContext j3dflyContext ) {
057: super .installPlugin( pluginPref, j3dflyContext );
058:
059: j3dflyContext.getEventProcessor().addListener( this , FileLoadEvent.class );
060: //j3dfly.getController().loadScene( new File(geometryFilename));
061:
062: }
063:
064: /**
065: * Get the title of the plugin
066: */
067: public String getPluginTitle() {
068: return "Benchmark Plugin";
069: }
070:
071: /**
072: * Returns the control panel for this plugin, or null if there
073: * is no control panel
074: */
075: public javax.swing.JPanel getControlPanel() {
076: return null;
077: }
078:
079: /**
080: * Returns the class of the plugin preference.
081: *
082: * Plugins that require more preference information should provide a
083: * subclass of PluginPrefernece that contains all the extra preference
084: * data. This class must be Serializable.
085: */
086: public Class getPluginPreferenceClass() {
087: return BenchmarkPluginPreference.class;
088: }
089:
090: /**
091: * Called by EventProcessor when an event occurs for which this
092: * listener has registered interest
093: */
094: public void processFlyEvent(org.jdesktop.j3dfly.event.FlyEvent evt) {
095: System.out.println("File Loaded");
096:
097: BranchGroup bg = new BranchGroup();
098: BenchmarkBehavior behavior = new BenchmarkBehavior( j3dflyContext.getJ3dFly().getUniverse().getViewingPlatform().getViewPlatformTransform(), splineFilename );
099: PerfBehavior perf = new PerfBehavior( new javax.media.j3d.BoundingSphere(new javax.vecmath.Point3d(), Double.POSITIVE_INFINITY), false, memCount );
100: perf.setFiniteLoop( finiteLoop );
101: perf.setLoopCount( loopCount );
102: bg.addChild(perf);
103:
104: bg.addChild( behavior );
105:
106: j3dflyContext.getJ3dFly().getUniverse().getLocale().addBranchGraph( bg );
107:
108: behavior.setEnabled( true );
109: }
110:
111: /**
112: * Called by PerfBehavior when new performance figures are available
113: */
114: public void updatePerformanceFigures(float framesPerSecond) {
115: System.out.println( framesPerSecond );
116: }
117:
118: public static class BenchmarkPluginPreference extends PluginPreference {
119:
120: public BenchmarkPluginPreference() {
121: super ();
122: }
123:
124: public BenchmarkPluginPreference( boolean enabled, boolean installed ) {
125: super ( enabled, installed );
126: }
127:
128: public J3dFlyPlugin instantiatePlugin() {
129: return new BenchmarkPlugin();
130: }
131:
132: public void setFiniteLoop( boolean finite ) {
133: finiteLoop = finite;
134: }
135:
136: public boolean isFiniteLoop() {
137: return finiteLoop;
138: }
139:
140: public void setLoopCount( int count ) {
141: loopCount = count;
142: }
143:
144: public int getLoopCount() {
145: return loopCount;
146: }
147:
148: public void setMemCount( int count ) {
149: memCount = count;
150: }
151:
152: public int getMemCount() {
153: return memCount;
154: }
155:
156: public void setGeometryFilename( String geometryFile ) {
157: geometryFilename = geometryFile;
158: }
159:
160: public String getGeometryFilename() {
161: return geometryFilename;
162: }
163:
164: public void setSplineFilename( String splineFile ) {
165: splineFilename = splineFile;
166: }
167:
168: public String getSplineFilename() {
169: return splineFilename;
170: }
171:
172: /**
173: * Return a description of this plugin
174: */
175: public String getDescription() {
176: return "Java 3D benchmark plugin";
177: }
178:
179: /**
180: * Return the name of the Plugin for this prefernece.
181: * This is the name that will appear in the list of plugins
182: */
183: public String getName() {
184: return "Java 3D Benchmark";
185: }
186:
187: }
188:
189: public class BenchmarkBehavior extends org.jdesktop.j3dfly.utils.behaviors.DemoKBSplineBehavior {
190: public BenchmarkBehavior( TransformGroup target, String filename ) {
191: super ( target, filename );
192: //alpha.setLoopCount( 10 );
193: //this.addChild( new TerminateBehavior( alpha ));
194: }
195:
196: class TerminateBehavior extends javax.media.j3d.Behavior {
197:
198: private javax.media.j3d.Alpha alpha;
199: private javax.media.j3d.WakeupOnElapsedFrames wakeup = new javax.media.j3d.WakeupOnElapsedFrames(0);
200:
201: public TerminateBehavior( javax.media.j3d.Alpha alpha ) {
202: this .alpha = alpha;
203: this .setSchedulingBounds( new javax.media.j3d.BoundingSphere( new javax.vecmath.Point3d(), Double.POSITIVE_INFINITY ));
204: }
205:
206: public void initialize() {
207: wakeupOn( wakeup );
208: }
209:
210: public void processStimulus( java.util.Enumeration enum ) {
211: if (alpha.finished())
212: System.exit(1);
213: wakeupOn( wakeup );
214: }
215: }
216: }
217:
218:}
|