Main repository of MikuMikuStudio
Revision | 06fe326423e2d1005b9a96248a10fc8b18460307 (tree) |
---|---|
Time | 2004-01-05 02:25:14 |
Author | Anakan <Anakan@75d0...> |
Commiter | Anakan |
Scene controlling tests
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@193 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -36,12 +36,15 @@ | ||
36 | 36 | */ |
37 | 37 | package com.jme.test.demo; |
38 | 38 | |
39 | +import java.util.logging.Level; | |
40 | + | |
39 | 41 | import com.jme.image.Texture; |
40 | 42 | import com.jme.math.Vector3f; |
41 | 43 | import com.jme.scene.Node; |
42 | 44 | import com.jme.scene.Text; |
43 | 45 | import com.jme.scene.state.AlphaState; |
44 | 46 | import com.jme.scene.state.TextureState; |
47 | +import com.jme.util.LoggingSystem; | |
45 | 48 | import com.jme.util.TextureManager; |
46 | 49 | import com.jme.util.Timer; |
47 | 50 |
@@ -57,10 +60,11 @@ public class LoadingScene implements Scene { | ||
57 | 60 | private Timer timer; |
58 | 61 | private SceneEnabledGame demo; |
59 | 62 | private Node loadingNode; |
63 | + private static boolean firstTime= true; | |
60 | 64 | |
61 | 65 | public void init(SceneEnabledGame game) { |
62 | 66 | this.demo= game; |
63 | - timer=game.getTimer(); | |
67 | + timer= game.getTimer(); | |
64 | 68 | loadingNode= new Node(); |
65 | 69 | loadingNode.updateGeometricState(0.0f, true); |
66 | 70 | text= new Text("Loading Scene"); |
@@ -68,7 +72,11 @@ public class LoadingScene implements Scene { | ||
68 | 72 | TextureState ts= demo.getDisplaySystem().getRenderer().getTextureState(); |
69 | 73 | ts.setEnabled(true); |
70 | 74 | ts.setTexture( |
71 | - TextureManager.loadTexture("C:/eclipse/workspace/JavaMonkeyEngine/jme/data/Font/font.png", Texture.MM_LINEAR, Texture.FM_LINEAR, true)); | |
75 | + TextureManager.loadTexture( | |
76 | + "C:/eclipse/workspace/JavaMonkeyEngine/jme/data/Font/font.png", | |
77 | + Texture.MM_LINEAR, | |
78 | + Texture.FM_LINEAR, | |
79 | + true)); | |
72 | 80 | text.setRenderState(ts); |
73 | 81 | AlphaState as1= demo.getDisplaySystem().getRenderer().getAlphaState(); |
74 | 82 | as1.setBlendEnabled(true); |
@@ -78,37 +86,36 @@ public class LoadingScene implements Scene { | ||
78 | 86 | as1.setTestFunction(AlphaState.TF_GREATER); |
79 | 87 | text.setRenderState(as1); |
80 | 88 | loadingNode.attachChild(text); |
81 | - status=LOAD_NEXT_SCENE; | |
82 | - | |
89 | + status= READY; | |
90 | + | |
83 | 91 | } |
84 | 92 | |
85 | - | |
86 | - public int getStatus() { | |
93 | + public int getStatus() { | |
87 | 94 | return status; |
88 | 95 | } |
89 | 96 | |
90 | - | |
91 | 97 | public boolean update() { |
92 | 98 | timeElapsed += timer.getTimePerFrame(); |
93 | 99 | if (timeElapsed > 1) { |
94 | 100 | timeElapsed= 0; |
95 | 101 | text.print(text.getText().toString() + "."); |
102 | + | |
96 | 103 | } |
97 | 104 | timer.update(); |
98 | 105 | return true; |
99 | 106 | } |
100 | 107 | |
101 | - | |
102 | 108 | public boolean render() { |
109 | + if (status == READY) { | |
110 | + status= LOAD_NEXT_SCENE; | |
111 | + } | |
103 | 112 | demo.getDisplaySystem().getRenderer().clearBuffers(); |
104 | 113 | demo.getDisplaySystem().getRenderer().draw(loadingNode); |
105 | 114 | return true; |
106 | 115 | } |
107 | 116 | |
108 | - | |
109 | 117 | public void cleanup() { |
110 | - // TODO Auto-generated method stub | |
111 | - | |
118 | + loadingNode= null; | |
112 | 119 | } |
113 | 120 | |
114 | 121 | /* (non-Javadoc) |
@@ -125,13 +132,15 @@ public class LoadingScene implements Scene { | ||
125 | 132 | return "com.jme.test.demo.SoundPlayingScene"; |
126 | 133 | } |
127 | 134 | |
128 | - | |
129 | - | |
130 | 135 | /* (non-Javadoc) |
131 | 136 | * @see com.jme.test.demo.Scene#setStatus(int) |
132 | 137 | */ |
133 | 138 | public void setStatus(int status) { |
134 | - this.status=status; | |
139 | + this.status= status; | |
140 | + } | |
141 | + | |
142 | + public void finalize() { | |
143 | + LoggingSystem.getLogger().log(Level.INFO, "Finalizing " + getClass().getName()); | |
135 | 144 | } |
136 | 145 | |
137 | 146 | } |
@@ -36,6 +36,10 @@ | ||
36 | 36 | */ |
37 | 37 | package com.jme.test.demo; |
38 | 38 | |
39 | +import java.util.logging.Level; | |
40 | + | |
41 | +import com.jme.util.LoggingSystem; | |
42 | + | |
39 | 43 | /** |
40 | 44 | * @author Arman Ozcelik |
41 | 45 | * |
@@ -70,18 +74,20 @@ public class SceneController { | ||
70 | 74 | |
71 | 75 | public void update() { |
72 | 76 | game.getInput().update(1); |
77 | + if (playingScene.getStatus() == Scene.LOAD_NEXT_SCENE) { | |
78 | + playingScene.setStatus(Scene.LOADING_NEXT_SCENE); | |
79 | + preloadNextScene(); | |
80 | + } | |
73 | 81 | if (playingScene.getStatus() == Scene.READY |
74 | 82 | || playingScene.getStatus() == Scene.LOAD_NEXT_SCENE |
75 | 83 | || playingScene.getStatus() == Scene.LOADING_NEXT_SCENE) { |
76 | 84 | playingScene.update(); |
77 | 85 | } |
78 | - if (playingScene.getStatus() == Scene.LOAD_NEXT_SCENE) { | |
79 | - playingScene.setStatus(Scene.LOADING_NEXT_SCENE); | |
80 | - preloadNextScene(); | |
81 | - } | |
82 | 86 | if (nextScene != null) { |
83 | 87 | nextScene.update(); |
84 | 88 | if (nextScene.getStatus() == Scene.READY) { |
89 | + playingScene.cleanup(); | |
90 | + LoggingSystem.getLogger().log(Level.INFO, "Cleaning " + playingScene.getClass().getName()); | |
85 | 91 | playingScene= nextScene; |
86 | 92 | nextScene= null; |
87 | 93 | } |
@@ -94,26 +100,24 @@ public class SceneController { | ||
94 | 100 | } |
95 | 101 | |
96 | 102 | public void preloadNextScene() { |
97 | - if (!preloadStarted) { | |
98 | - preloadStarted= true; | |
99 | - Runnable r= new Runnable() { | |
100 | - public void run() { | |
101 | - try { | |
102 | - nextScene= (Scene)Class.forName(playingScene.getLinkedSceneClassName()).newInstance(); | |
103 | - } catch (InstantiationException e) { | |
104 | - e.printStackTrace(); | |
105 | - } catch (IllegalAccessException e) { | |
106 | - e.printStackTrace(); | |
107 | - } catch (ClassNotFoundException e) { | |
108 | - e.printStackTrace(); | |
109 | - } | |
110 | - nextScene.init(game); | |
111 | 103 | |
104 | + Runnable r= new Runnable() { | |
105 | + public void run() { | |
106 | + try { | |
107 | + nextScene= (Scene)Class.forName(playingScene.getLinkedSceneClassName()).newInstance(); | |
108 | + } catch (InstantiationException e) { | |
109 | + e.printStackTrace(); | |
110 | + } catch (IllegalAccessException e) { | |
111 | + e.printStackTrace(); | |
112 | + } catch (ClassNotFoundException e) { | |
113 | + e.printStackTrace(); | |
112 | 114 | } |
113 | - }; | |
114 | - Thread t= new Thread(r); | |
115 | - t.start(); | |
116 | - } | |
115 | + nextScene.init(game); | |
116 | + | |
117 | + } | |
118 | + }; | |
119 | + Thread t= new Thread(r); | |
120 | + t.start(); | |
117 | 121 | |
118 | 122 | } |
119 | 123 |
@@ -36,6 +36,10 @@ | ||
36 | 36 | */ |
37 | 37 | package com.jme.test.demo; |
38 | 38 | |
39 | + | |
40 | + | |
41 | +import java.util.logging.Level; | |
42 | + | |
39 | 43 | import com.jme.entity.Entity; |
40 | 44 | import com.jme.image.Texture; |
41 | 45 | import com.jme.math.Vector3f; |
@@ -47,6 +51,8 @@ import com.jme.sound.IEffectPlayer; | ||
47 | 51 | import com.jme.sound.IRenderer; |
48 | 52 | import com.jme.sound.utils.EffectRepository; |
49 | 53 | import com.jme.sound.utils.OnDemandSoundLoader; |
54 | + | |
55 | +import com.jme.util.LoggingSystem; | |
50 | 56 | import com.jme.util.TextureManager; |
51 | 57 | import com.jme.util.Timer; |
52 | 58 |
@@ -71,7 +77,9 @@ public class SoundPlayingScene implements Scene { | ||
71 | 77 | |
72 | 78 | private int status; |
73 | 79 | |
74 | - boolean toRight= true, ascending= true; | |
80 | + private boolean toRight= true, ascending= true; | |
81 | + | |
82 | + | |
75 | 83 | |
76 | 84 | public void init(SceneEnabledGame game) { |
77 | 85 | this.game= game; |
@@ -128,11 +136,16 @@ public class SoundPlayingScene implements Scene { | ||
128 | 136 | return false; |
129 | 137 | } |
130 | 138 | if (EffectRepository.getRepository().getSource(backgroundMusic.getId()) != null) { |
131 | - status= READY; | |
139 | + status=READY; | |
132 | 140 | } else { |
133 | 141 | return false; |
134 | 142 | } |
135 | 143 | timer.update(); |
144 | + timeElapsed+=timer.getTimePerFrame(); | |
145 | + if(timeElapsed>5 && status !=LOAD_NEXT_SCENE){ | |
146 | + timeElapsed=0; | |
147 | + status=LOAD_NEXT_SCENE; | |
148 | + } | |
136 | 149 | if (soundRenderer.getSoundPlayer(backgroundMusic).getStatus() != IEffectPlayer.LOOPING) { |
137 | 150 | soundRenderer.getSoundPlayer(backgroundMusic).loop( |
138 | 151 | EffectRepository.getRepository().getSource(backgroundMusic.getId())); |
@@ -151,8 +164,7 @@ public class SoundPlayingScene implements Scene { | ||
151 | 164 | toRight= true; |
152 | 165 | ascending=true; |
153 | 166 | } |
154 | - } | |
155 | - | |
167 | + } | |
156 | 168 | soundRenderer.getSoundPlayer(backgroundMusic).setPosition(soundPosition); |
157 | 169 | text.print("Position " + soundPosition); |
158 | 170 | return true; |
@@ -171,8 +183,9 @@ public class SoundPlayingScene implements Scene { | ||
171 | 183 | * @see com.jme.test.demo.Scene#cleanup() |
172 | 184 | */ |
173 | 185 | public void cleanup() { |
174 | - // TODO Auto-generated method stub | |
175 | - | |
186 | + soundRenderer.getSoundPlayer(backgroundMusic).stop(); | |
187 | + EffectRepository.getRepository().remove(backgroundMusic.getId()); | |
188 | + soundNode=null; | |
176 | 189 | } |
177 | 190 | |
178 | 191 | /* (non-Javadoc) |
@@ -187,8 +200,7 @@ public class SoundPlayingScene implements Scene { | ||
187 | 200 | * @see com.jme.test.demo.Scene#getLinkedSceneClassName() |
188 | 201 | */ |
189 | 202 | public String getLinkedSceneClassName() { |
190 | - // TODO Auto-generated method stub | |
191 | - return null; | |
203 | + return "com.jme.test.demo.LoadingScene"; | |
192 | 204 | } |
193 | 205 | |
194 | 206 | /* (non-Javadoc) |
@@ -197,5 +209,10 @@ public class SoundPlayingScene implements Scene { | ||
197 | 209 | public void setStatus(int status) { |
198 | 210 | this.status= status; |
199 | 211 | } |
200 | - | |
212 | + | |
213 | + public void finalize(){ | |
214 | + LoggingSystem.getLogger().log( | |
215 | + Level.INFO, | |
216 | + "Finalizing "+getClass().getName()); | |
217 | + } | |
201 | 218 | } |