• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


Commit MetaInfo

Revisionc5366311a8bc2b41efd602f50174746aaadf97e8 (tree)
Time2003-10-26 00:34:58
Authormojomonkey <mojomonkey@75d0...>
Commitermojomonkey

Log Message

Test for sound within the game loop

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@111 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

Change Summary

Incremental Difference

--- /dev/null
+++ b/src/com/jme/test/sound/TestSoundLoop.java
@@ -0,0 +1,190 @@
1+/*
2+ * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions are met:
7+ *
8+ * Redistributions of source code must retain the above copyright notice, this
9+ * list of conditions and the following disclaimer.
10+ *
11+ * Redistributions in binary form must reproduce the above copyright notice,
12+ * this list of conditions and the following disclaimer in the documentation
13+ * and/or other materials provided with the distribution.
14+ *
15+ * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
16+ * names of its contributors may be used to endorse or promote products derived
17+ * from this software without specific prior written permission.
18+ *
19+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+ * POSSIBILITY OF SUCH DAMAGE.
30+ *
31+ */
32+package com.jme.test.sound;
33+
34+
35+import com.jme.app.AbstractGame;
36+import com.jme.image.Texture;
37+import com.jme.math.Vector3f;
38+import com.jme.renderer.Camera;
39+import com.jme.renderer.ColorRGBA;
40+import com.jme.renderer.LWJGLCamera;
41+import com.jme.scene.Node;
42+import com.jme.scene.Text;
43+import com.jme.scene.state.AlphaState;
44+import com.jme.scene.state.TextureState;
45+import com.jme.system.JmeException;
46+import com.jme.system.LWJGLDisplaySystem;
47+import com.jme.util.TextureManager;
48+
49+
50+import com.jme.sound.SoundSystem;
51+import com.jme.sound.SoundRenderer;
52+
53+/**
54+ * <code>TestSoundLoop</code>
55+ * @author Mark Powell
56+ * @version
57+ */
58+public class TestSoundLoop extends AbstractGame {
59+
60+ private Text text;
61+ private Camera cam;
62+ private Node scene;
63+ private SoundRenderer soundRenderer;
64+
65+ public static void main(String[] args) {
66+ TestSoundLoop app = new TestSoundLoop();
67+ app.useDialogAlways(true);
68+ app.start();
69+ }
70+
71+ /**
72+ * Not used.
73+ * @see com.jme.app.AbstractGame#update()
74+ */
75+ protected void update() {
76+ if(!soundRenderer.getSoundPlayer("NPC").isPlaying()) {
77+ soundRenderer.getSoundPlayer("NPC").play("bored");
78+
79+ }
80+ }
81+
82+ /**
83+ * draws the scene graph
84+ * @see com.jme.app.AbstractGame#render()
85+ */
86+ protected void render() {
87+ display.getRenderer().clearBuffers();
88+
89+ display.getRenderer().draw(scene);
90+
91+ }
92+
93+ /**
94+ * initializes the display and camera.
95+ * @see com.jme.app.AbstractGame#initSystem()
96+ */
97+ protected void initSystem() {
98+ try {
99+ if("LWJGL".equalsIgnoreCase(properties.getRenderer())) {
100+ display = new LWJGLDisplaySystem();
101+ display.createWindow(properties.getWidth(), properties.getHeight(),
102+ properties.getDepth(), properties.getFreq(),
103+ properties.getFullscreen());
104+ cam = new LWJGLCamera(properties.getWidth(),properties.getHeight());
105+ }
106+ } catch (JmeException e) {
107+ e.printStackTrace();
108+ System.exit(1);
109+ }
110+
111+ SoundSystem system=SoundSystem.getSoundSystem("LWJGL");
112+ soundRenderer=system.getRenderer();
113+
114+
115+ ColorRGBA blueColor = new ColorRGBA();
116+ blueColor.r = 0;
117+ blueColor.g = 0;
118+ display.getRenderer().setBackgroundColor(blueColor);
119+ cam.setFrustum(1.0f,1000.0f,-0.55f,0.55f,0.4125f,-0.4125f);
120+ Vector3f loc = new Vector3f(4.0f,0.0f,0.0f);
121+ Vector3f left = new Vector3f(0.0f,-1.0f,0.0f);
122+ Vector3f up = new Vector3f(0.0f,0.0f,1.0f);
123+ Vector3f dir = new Vector3f(-1.0f,0f,0.0f);
124+ cam.setFrame(loc,left,up,dir);
125+
126+ display.getRenderer().setCamera(cam);
127+
128+ }
129+
130+ /**
131+ * initializes the scene
132+ * @see com.jme.app.AbstractGame#initGame()
133+ */
134+ protected void initGame() {
135+ text = new Text("Testing Text");
136+ text.setLocalTranslation(new Vector3f(1,60,0));
137+ TextureState ts = display.getRenderer().getTextureState();
138+ ts.setEnabled(true);
139+ ts.setTexture(
140+ TextureManager.loadTexture(
141+ "data/Font/font.png",
142+ Texture.MM_LINEAR,
143+ Texture.FM_LINEAR,
144+ true));
145+ text.setRenderState(ts);
146+ AlphaState as1 = display.getRenderer().getAlphaState();
147+ as1.setBlendEnabled(true);
148+ as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
149+ as1.setDstFunction(AlphaState.DB_ONE);
150+ as1.setTestEnabled(true);
151+ as1.setTestFunction(AlphaState.TF_GREATER);
152+ text.setRenderState(as1);
153+ scene = new Node();
154+ scene.attachChild(text);
155+ cam.update();
156+
157+ scene.updateGeometricState(0.0f, true);
158+
159+ soundRenderer.addSoundPlayer("MONSTER");
160+ soundRenderer.addSoundPlayer("NPC");
161+
162+ soundRenderer.loadSoundAs("music", "cu.wav");
163+ soundRenderer.loadSoundAs("bored", "data/music/02 Butterfly Wings.mp3");
164+
165+ soundRenderer.getSoundPlayer("MONSTER").setNumberOfBuffers(1);
166+ soundRenderer.getSoundPlayer("NPC").setNumberOfBuffers(128);
167+
168+ soundRenderer.getSoundPlayer("MONSTER").updatePosition(1, 0, 0);
169+ soundRenderer.getSoundPlayer("NPC").updatePosition(0, 0, 0);
170+ soundRenderer.getSoundPlayer("NPC").updateVelocity(0, 0, 0);
171+
172+ }
173+
174+ /**
175+ * not used.
176+ * @see com.jme.app.AbstractGame#reinit()
177+ */
178+ protected void reinit() {
179+
180+ }
181+
182+ /**
183+ * not used.
184+ * @see com.jme.app.AbstractGame#cleanup()
185+ */
186+ protected void cleanup() {
187+
188+ }
189+
190+}