• R/O
  • SSH
  • HTTPS

mmosf: 提交


Commit MetaInfo

修訂103 (tree)
時間2010-02-28 23:16:56
作者msz006

Log Message

(empty log message)

Change Summary

差異

--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/SampleClient3.java (revision 102)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/SampleClient3.java (nonexistent)
@@ -1,122 +0,0 @@
1-/*
2- * Copyright (c) 2007, MMO Server Framework Project
3- *
4- * All rights reserved.
5- *
6- * Redistribution and use in source and binary forms, with or without modification,
7- * are permitted provided that the following conditions are met:
8- *
9- * Redistributions of source code must retain the above copyright notice,
10- * this list of conditions and the following disclaimer.
11- *
12- * Redistributions in binary form must reproduce the above copyright notice,
13- * this list of conditions and the following disclaimer in the documentation
14- * and/or other materials provided with the distribution.
15- *
16- * Neither the name of the MMO Server Framework Project nor the names of its
17- * contributors may be used to endorse or promote products derived from this
18- * software without specific prior written permission.
19- *
20- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31- */
32-
33-package jp.sourceforge.mmosf.client.sample;
34-
35-import java.io.BufferedReader;
36-import java.io.File;
37-import java.io.FileReader;
38-import java.net.InetSocketAddress;
39-import java.net.URL;
40-
41-import javax.swing.JFrame;
42-
43-import jp.sourceforge.mmosf.server.sample.SampleGameServer;
44-
45-import org.apache.commons.logging.Log;
46-import org.apache.commons.logging.LogFactory;
47-import org.apache.log4j.PropertyConfigurator;
48-
49-public class SampleClient3 {
50-
51- static Log log = LogFactory.getLog(SampleClient3.class);
52- /**
53- * @param args
54- */
55- public static void main(String[] args) {
56- // TODO 自動生成されたメソッド・スタブ
57- LogFactory.getFactory().setAttribute("org.apache.commons.logging.log", "org.apache.commons.logging.impl.Log4JLogger");
58-// PropertyConfigurator.configure(args[0]);
59- URL path = SampleGameServer.class.getClassLoader().getResource("jp/sourceforge/mmosf/client/sample/conf/log4j.properties");
60- PropertyConfigurator.configure(path.getPath());
61- log.info("client start.");
62-/*
63- SampleLoginFrame loginFrame;
64- try {
65- loginFrame = new SampleLoginFrame("127.0.0.1",2001);
66- } catch (UnknownHostException e1) {
67- log.error("get host error.",e1);
68- return ;
69- }
70-
71- loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
72- loginFrame.setVisible(true);
73-
74- if(!loginFrame.start()){
75- System.exit(0);
76- }
77-*/
78- SampleClientFrame frame = new SampleClientFrame();
79- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
80- try{
81-// frame.connect(loginFrame.getConnectAddr(), loginFrame.connectId);
82- InetSocketAddress addr = loadConf();
83- if(addr == null){
84- addr = new InetSocketAddress("127.0.0.1",2000);
85- log.info("connect 127.0.0.1:2000");
86- }
87- frame.connect(addr, "admin");
88- }catch(Exception e){
89- log.error("failed connect gameserver.",e);
90- }
91- frame.setVisible(true);
92-
93- frame.start();
94- }
95-
96- static private InetSocketAddress loadConf(){
97- try{
98- File file = new File("client.conf");
99- if(!file.exists()){
100- return null;
101- }
102-
103- BufferedReader r = new BufferedReader(new FileReader(file));
104- String str = r.readLine();
105- r.close();
106-
107- String[] addr = str.split(":");
108- if(addr == null || addr.length != 2){
109- return null;
110- }
111-
112- log.info("connect "+str);
113- return new InetSocketAddress(addr[0],Integer.valueOf(addr[1]));
114-
115- }catch(Exception e){
116- log.error("error in load conf, ",e);
117- return null;
118- }
119- }
120-
121-
122-}
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/SampleClientFrame.java (revision 102)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/SampleClientFrame.java (nonexistent)
@@ -1,374 +0,0 @@
1-/*
2- * Copyright (c) 2007, MMO Server Framework Project
3- *
4- * All rights reserved.
5- *
6- * Redistribution and use in source and binary forms, with or without modification,
7- * are permitted provided that the following conditions are met:
8- *
9- * Redistributions of source code must retain the above copyright notice,
10- * this list of conditions and the following disclaimer.
11- *
12- * Redistributions in binary form must reproduce the above copyright notice,
13- * this list of conditions and the following disclaimer in the documentation
14- * and/or other materials provided with the distribution.
15- *
16- * Neither the name of the MMO Server Framework Project nor the names of its
17- * contributors may be used to endorse or promote products derived from this
18- * software without specific prior written permission.
19- *
20- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31- */
32-
33-package jp.sourceforge.mmosf.client.sample;
34-
35-import java.awt.BorderLayout;
36-import java.awt.Font;
37-import java.awt.event.ActionEvent;
38-import java.awt.event.ActionListener;
39-import java.io.IOException;
40-import java.net.SocketAddress;
41-import java.util.Iterator;
42-import java.util.List;
43-
44-import javax.swing.JFrame;
45-import javax.swing.JLabel;
46-import javax.swing.JPanel;
47-import javax.swing.JScrollPane;
48-import javax.swing.JTextField;
49-
50-import jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime;
51-import jp.sourceforge.mmosf.server.level.GeomapData;
52-import jp.sourceforge.mmosf.server.object.ChatMessage;
53-import jp.sourceforge.mmosf.server.object.Mob;
54-import jp.sourceforge.mmosf.server.object.Position;
55-import jp.sourceforge.mmosf.server.packet.Packet;
56-import jp.sourceforge.mmosf.server.packet.PacketFactory;
57-import jp.sourceforge.mmosf.server.packet.PacketFormatException;
58-
59-import org.apache.commons.logging.Log;
60-import org.apache.commons.logging.LogFactory;
61-
62-public class SampleClientFrame extends JFrame implements ActionListener/*,KeyListener*/,LoggingResponseTime{
63- static Log log = LogFactory.getLog(SampleClientFrame.class);
64-
65- protected long time;
66- protected long timeMove;
67-
68- protected StringBuffer timelogBuffer;
69- protected final int SIZE_TIMELOG_BFFER = 256;
70-
71- class MapManeger{
72-
73- protected GeomapData zone = new GeomapData();
74-
75- MapManeger() {
76- super();
77- // TODO 自動生成されたコンストラクター・スタブ
78- }
79-
80- protected int getOffset(int pos, int viewSize, int mapSize) {
81- int Offset = pos - viewSize/2;
82- if(Offset < 0){
83- Offset = 0;
84- }else if(Offset > (mapSize - viewSize)){
85- Offset = mapSize - viewSize;
86- }
87- return Offset;
88- }
89-
90- char[][] getMapChar(int xPos, int yPos, int xSize, int ySize){
91- char[][] map = new char[ySize][xSize];
92- for(int i=0;i<ySize;i++){
93- for(int j=0;j<xSize;j++){
94- map[i][j] = zone.map[yPos+i][xPos+j];
95- }
96- }
97- return map;
98- }
99-/*
100- char[][] initMapChar(int ySize, int xSize) {
101- char[][] map = new char[ySize][xSize];
102- for(int i=0;i<ySize;i++){
103- for(int j=0;j<xSize;j++){
104- map[i][j] = '□';
105- }
106- }
107- return map;
108- }
109-*/
110- StringBuffer update2(Mob self, List<Mob> listMob) {
111- // List<String> list = new LinkedList<String>();
112- // listMob = updateCache.update(listMob);
113- // Mob self = updateCache.get(charactorId);
114-
115- int ySize = 20;
116- int xSize = 20;
117-
118- int yLimit = zone.getZLimit();//40;
119- int xLimit = zone.getXLimit();//40;
120-
121- int yOffset = getOffset(self.moving.getPosition().getY(), ySize, yLimit);
122- int xOffset = getOffset(self.moving.getPosition().getX(), xSize, xLimit);
123-
124- // char[][] map = initMapChar(ySize, xSize);
125- char[][] map = getMapChar(xOffset, yOffset, xSize, ySize);
126-
127- Iterator<Mob> it = listMob.iterator();
128- while(it.hasNext()){
129- Mob mob = it.next();
130- // map[mob.pos.y][mob.pos.x] = mob.c;
131- //*
132- int y2 = mob.moving.getPosition().getY() - yOffset;
133- int x2 = mob.moving.getPosition().getX() - xOffset;
134- if(0 <= y2 && y2 < map.length && 0<= x2 && x2 <map[0].length){
135- map[y2][x2] = mob.c;
136- }
137- //*/
138- }
139-
140- StringBuffer buff = new StringBuffer();
141- buff.append("<html>");
142- for(int i=0;i<map.length;i++){
143- buff.append(map[i]);
144- buff.append("<br>");
145- }
146- buff.append("</html>");
147- return buff;
148- }
149-
150- }
151-
152- /*
153- public void keyPressed(KeyEvent e) {
154- inputProcess.keyPressed(e);
155- }
156-
157- public void keyReleased(KeyEvent e) {
158- inputProcess.keyReleased(e);
159- }
160-
161- public void keyTyped(KeyEvent e) {
162- inputProcess.keyTyped(e);
163- }
164-*/
165- /**
166- *
167- */
168- private static final long serialVersionUID = -5938590566332483922L;
169- protected JMessageLabel message;
170- protected JTextField input;
171- public PacketProcess process;
172- public InputProcess inputProcess;
173- public MapManeger mmaneg;
174-/*
175- protected JButton up;
176- protected JButton down;
177- protected JButton left;
178- protected JButton right;
179-*/
180-
181- protected JLabel map;
182-
183- public SampleClientFrame(){
184- setTitle("Sample Client");
185- setBounds( 10, 10, 400, 300);
186-
187- message = new JMessageLabel();
188- JScrollPane scroll = new JScrollPane(message,
189- JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
190- JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
191-
192- input = new JTextField(10);
193-
194- mmaneg = new MapManeger();
195-
196- map = new JLabel();
197- Font font = new Font("MS ゴシック",Font.PLAIN,8);
198- map.setFont(font);
199- /*
200- JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
201- pane.setLeftComponent(map);
202- pane.setRightComponent(scroll);
203-*/
204- BorderLayout layout = new BorderLayout();
205-// layout.addLayoutComponent(input, BorderLayout.SOUTH);
206-// layout.addLayoutComponent(message, BorderLayout.EAST);
207-// layout.addLayoutComponent(map, BorderLayout.CENTER);
208-// getContentPane().setLayout(layout);
209-
210- JPanel panel = new JPanel();
211- panel.setLayout(layout);
212- panel.add(input,BorderLayout.SOUTH);
213- panel.add(scroll,BorderLayout.CENTER);
214- panel.add(map,BorderLayout.WEST);
215-
216- getContentPane().add(panel,BorderLayout.CENTER);
217-
218- getMessage().setVerticalAlignment(JLabel.TOP);
219-// message.redrawMessage(this);
220-
221- inputProcess = new InputProcess(){
222- @Override
223- public void send(Packet packet){
224- process.send(packet);
225- }
226-
227- @Override
228- public boolean isLogout() {
229- return process.isLogout();
230- }
231-
232- @Override
233- public void select() {
234- // TODO 自動生成されたメソッド・スタブ
235-
236- }
237-
238- @Override
239- protected Position getNowPosition() {
240- // TODO 自動生成されたメソッド・スタブ
241- return null;
242- }
243-
244-
245- };
246-
247- input.addKeyListener(inputProcess);
248-
249- process = new PacketProcess(){
250- public void receiveMessage(ChatMessage message){
251- getMessage().addMessage(message);
252- }
253-
254- public void receiveUpdate(Mob self, List<Mob> listUpdate, List<Mob> listDelete){
255- update(self, listUpdate);
256- }
257-
258- @Override
259- public void receivePacket(Packet packet) {
260- // TODO 自動生成されたメソッド・スタブ
261-
262- }
263- };
264-
265- process.setFrame(this);
266-
267- getInput().addActionListener(this);
268- }
269-
270- public void update(Mob self, List<Mob> listUpdate){
271- StringBuffer buff = mmaneg.update2(self, listUpdate);
272-
273- this.map.setText(buff.toString());
274- }
275-
276- public void actionPerformed(ActionEvent e) {
277- // TODO 自動生成されたメソッド・スタブ
278- String str = getInput().getText();
279- process.sendMessage(str);
280-
281- getInput().setText("");
282- }
283-
284- public JMessageLabel getMessage() {
285- return message;
286- }
287-
288- public JLabel getMap() {
289- return map;
290- }
291-
292- public JTextField getInput() {
293- return input;
294- }
295-
296- public void start() {
297- process.start();
298- }
299-
300- public boolean connect(SocketAddress addr, String connectId) throws InterruptedException, IOException, PacketFormatException {
301- return process.connect(addr, connectId);
302- }
303- /* (非 Javadoc)
304- * @see jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime#startLogTimeMove()
305- */
306- public void startLogTimeMove(){
307- if(!isTime()){
308- return;
309- }
310-
311- timeMove = System.nanoTime();
312- }
313-
314- /* (非 Javadoc)
315- * @see jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime#startLogTime()
316- */
317- public void startLogTime(){
318- if(!isTime()){
319- return;
320- }
321-
322- time = System.nanoTime();
323- }
324-
325- /* (非 Javadoc)
326- * @see jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime#logTimeMove()
327- */
328- public void logTimeMove(){
329- if(!isTime()){
330- return;
331- }
332-
333- if(timeMove == 0){
334- return;
335- }
336- long timePast = System.nanoTime() - timeMove;
337- logTime("move:"+((double)timePast)/1000000000);
338- timeMove = 0;
339- }
340-
341- /* (非 Javadoc)
342- * @see jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime#logTime(jp.sourceforge.mmosf.server.packet.Packet)
343- */
344- public void logTime(Packet packet) throws PacketFormatException{
345- if(!isTime()){
346- return;
347- }
348-
349- long timePast = System.nanoTime() - time;
350- logTime("past("+packet.getType()+"):"+((double)timePast)/1000000000);
351- }
352-
353- protected boolean isTime(){
354- return true;
355- }
356-
357- protected void logTime(String string){
358- timelogBuffer.append(string+";");
359- if(timelogBuffer.length() < SIZE_TIMELOG_BFFER){
360- return ;
361- }
362-
363- sendLog();
364- }
365-
366- public void sendLog() {
367- if(!isTime()){
368- return;
369- }
370- Packet pac = PacketFactory.createLogPacket(timelogBuffer.toString());
371- process.send(pac);
372- timelogBuffer.setLength(0);
373- }
374-}
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/LocalConnection.java (nonexistent)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/LocalConnection.java (revision 103)
@@ -0,0 +1,94 @@
1+/*
2+ * Copyright (c) 2007-2010, MMO Server Framework Project
3+ *
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without modification,
7+ * are permitted provided that the following conditions are met:
8+ *
9+ * Redistributions of source code must retain the above copyright notice,
10+ * this list of conditions and the following disclaimer.
11+ *
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * Neither the name of the MMO Server Framework Project nor the names of its
17+ * contributors may be used to endorse or promote products derived from this
18+ * software without specific prior written permission.
19+ *
20+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+ */
32+
33+package jp.sourceforge.mmosf.client.sample;
34+
35+import java.io.IOException;
36+import java.util.LinkedList;
37+import java.util.List;
38+
39+import jp.sourceforge.mmosf.server.DirectConnection;
40+import jp.sourceforge.mmosf.server.object.Mob;
41+import jp.sourceforge.mmosf.server.object.MovingVector;
42+import jp.sourceforge.mmosf.server.object.PlayerCharactor;
43+import jp.sourceforge.mmosf.server.object.Position;
44+import jp.sourceforge.mmosf.server.object.UpdateCache;
45+import jp.sourceforge.mmosf.server.object.Vector;
46+import jp.sourceforge.mmosf.server.packet.MovePacket;
47+import jp.sourceforge.mmosf.server.packet.Packet;
48+import jp.sourceforge.mmosf.server.packet.PacketFactory;
49+import jp.sourceforge.mmosf.server.packet.PacketFormatException;
50+import jp.sourceforge.mmosf.server.packet.Type;
51+
52+public class LocalConnection extends DirectConnection {
53+
54+ private int charactorId;
55+ private UpdateCache updateCache;
56+ public LocalConnection(int charactorId, UpdateCache updateCache) {
57+ this.charactorId = charactorId;
58+ this.updateCache = updateCache;
59+ }
60+
61+ @Override
62+ public void send(Packet packet) throws IOException, PacketFormatException {
63+ if(packet.getType() == Type.MOVE){
64+ Packet resPacket = process(packet);
65+ sendServerRequest(resPacket);
66+ }
67+ }
68+
69+ public Packet process(Packet packet) throws PacketFormatException, IOException{
70+ Vector vec = ((MovePacket)packet).getVector();
71+
72+// return PacketFactory.createMoveResponsePacket(mv);
73+/*
74+ Mob mob = updateCache.get(charactorId);
75+ Position pos;
76+ if(vec.isZero()){
77+ pos = ((MovePacket)packet).getPosition();
78+ }else{
79+ pos = mob.getPosition();
80+ }
81+
82+ mob.moving.setDirection(vec.getDirection());
83+ if(pos != null){
84+ mob.moving.setPosition(pos.getMoved(vec));
85+ }
86+*/
87+ List<Mob> list = new LinkedList<Mob>();
88+// list.add(mob);
89+
90+ return PacketFactory.createUpdatePacket(list, new LinkedList<Mob>());
91+ }
92+
93+
94+}
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/GameObjectPanel.java (nonexistent)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/GameObjectPanel.java (revision 103)
@@ -0,0 +1,49 @@
1+/*
2+ * Copyright (c) 2007-2010, MMO Server Framework Project
3+ *
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without modification,
7+ * are permitted provided that the following conditions are met:
8+ *
9+ * Redistributions of source code must retain the above copyright notice,
10+ * this list of conditions and the following disclaimer.
11+ *
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * Neither the name of the MMO Server Framework Project nor the names of its
17+ * contributors may be used to endorse or promote products derived from this
18+ * software without specific prior written permission.
19+ *
20+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+ */
32+
33+package jp.sourceforge.mmosf.client.sample.jme;
34+
35+import jp.sourceforge.mmosf.server.level.GeomapData;
36+
37+public class GameObjectPanel extends JMEObjectPanel {
38+
39+ public GameObjectPanel() {
40+ super();
41+ // TODO 自動生成されたコンストラクター・スタブ
42+ }
43+
44+ public GameObjectPanel(GeomapData data) {
45+ super(data);
46+ // TODO 自動生成されたコンストラクター・スタブ
47+ }
48+
49+}
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/JMEObjectPanel.java (nonexistent)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/JMEObjectPanel.java (revision 103)
@@ -0,0 +1,1148 @@
1+/*
2+ * Copyright (c) 2007-2010, MMO Server Framework Project
3+ *
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without modification,
7+ * are permitted provided that the following conditions are met:
8+ *
9+ * Redistributions of source code must retain the above copyright notice,
10+ * this list of conditions and the following disclaimer.
11+ *
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * Neither the name of the MMO Server Framework Project nor the names of its
17+ * contributors may be used to endorse or promote products derived from this
18+ * software without specific prior written permission.
19+ *
20+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+ */
32+
33+package jp.sourceforge.mmosf.client.sample.jme;
34+
35+import java.awt.Point;
36+import java.awt.event.MouseEvent;
37+import java.net.URL;
38+import java.util.ArrayList;
39+import java.util.HashMap;
40+import java.util.Iterator;
41+import java.util.LinkedList;
42+import java.util.List;
43+import java.util.Map;
44+import java.util.Queue;
45+import java.util.Map.Entry;
46+import java.util.concurrent.ConcurrentLinkedQueue;
47+
48+import jp.sourceforge.mmosf.admin.LocalMonitor;
49+import jp.sourceforge.mmosf.client.sample.command.Command;
50+import jp.sourceforge.mmosf.client.sample.command.CommandReceiver;
51+import jp.sourceforge.mmosf.client.sample.jme.QuarterViewPanel.ViewSetting;
52+import jp.sourceforge.mmosf.server.level.GeomapData;
53+import jp.sourceforge.mmosf.server.level.MobFactory;
54+import jp.sourceforge.mmosf.server.mobmove.MoveData;
55+import jp.sourceforge.mmosf.server.mobmove.MoveDataQueue;
56+import jp.sourceforge.mmosf.server.object.Direction;
57+import jp.sourceforge.mmosf.server.object.Mob;
58+import jp.sourceforge.mmosf.server.object.ObjectStatus;
59+import jp.sourceforge.mmosf.server.object.Position;
60+import jp.sourceforge.mmosf.server.object.Vector;
61+import jp.sourceforge.mmosf.server.packet.MovePacket;
62+import jp.sourceforge.mmosf.server.packet.PacketFormatException;
63+
64+import com.jme.animation.SpatialTransformer;
65+import com.jme.bounding.BoundingBox;
66+import com.jme.image.Texture;
67+import com.jme.intersection.BoundingPickResults;
68+import com.jme.intersection.PickResults;
69+import com.jme.math.FastMath;
70+import com.jme.math.Quaternion;
71+import com.jme.math.Ray;
72+import com.jme.math.Vector2f;
73+import com.jme.math.Vector3f;
74+import com.jme.renderer.ColorRGBA;
75+import com.jme.scene.Controller;
76+import com.jme.scene.Node;
77+import com.jme.scene.SceneElement;
78+import com.jme.scene.SharedMesh;
79+import com.jme.scene.Spatial;
80+import com.jme.scene.TriMesh;
81+import com.jme.scene.shape.Arrow;
82+import com.jme.scene.state.TextureState;
83+import com.jme.system.DisplaySystem;
84+import com.jme.system.SystemProvider;
85+import com.jme.system.lwjgl.LWJGLDisplaySystem;
86+import com.jme.util.TextureManager;
87+import com.jme.util.geom.BufferUtils;
88+
89+public class JMEObjectPanel extends QuarterViewPanel {
90+
91+ public class ObjectManager{
92+
93+ private Map<Integer, Mob> mapMob;
94+ protected final Queue<Mob> listDeleteMob;
95+ private final Queue<Mob> listMob;
96+ protected Position oldPos;
97+ private Mob oldSelf;
98+ private Mob self;
99+
100+ public ObjectManager() {
101+ super();
102+ listDeleteMob = new ConcurrentLinkedQueue<Mob>();
103+ listMob = new ConcurrentLinkedQueue<Mob>();
104+ mapMob = new HashMap<Integer, Mob>();
105+ }
106+
107+ public void update(Mob self, List<Mob> listUpdate, List<Mob> listDelete){
108+ /*
109+ if(oldSelf == null){
110+ oldSelf = this.self = self;
111+ }
112+ */
113+ if(true){// || !this.self.moving.getPosition().equals(self.moving.getPosition())){
114+ if(oldPos == null){
115+ oldPos = self.getPosition();
116+ }
117+ //*
118+ objectManager.setOldSelf(getSelf());
119+ objectManager.setSelf(self);
120+
121+ // System.out.println("update:"+self.getPosition());
122+
123+ if(getFrame() != null){
124+ getFrame().logTimeMove();
125+ }
126+ //*/
127+ }
128+ /*
129+ if(oldSelf != null){
130+ oldSelf = self;
131+ }
132+ */
133+ // this.listMob = listUpdate;
134+ Iterator<Mob> it = listUpdate.iterator();
135+ while (it.hasNext()) {
136+ Mob mob = (Mob) it.next();
137+ listMob.add(mob);
138+ mapMob.put(Integer.valueOf(mob.getId()), mob);
139+ }
140+ // getListMob().addAll(listUpdate);
141+
142+ Iterator<Mob> it2 = listDelete.iterator();
143+ while (it2.hasNext()) {
144+ Mob mob = (Mob) it2.next();
145+ objectManager.getListDeleteMob().add(mob);
146+ mapMob.remove(Integer.valueOf(mob.getId()));
147+ }
148+ }
149+
150+ public Mob findMob(Integer mobId) {
151+ return mapMob.get(mobId);
152+ }
153+
154+ public Mob pollListMob() {
155+ if(listMob != null){
156+ return listMob.poll();
157+ }
158+ return null;
159+ }
160+
161+ public Mob getSelf() {
162+ return self;
163+ }
164+
165+ protected Mob getOldSelf() {
166+ return oldSelf;
167+ }
168+
169+ public Position getMyPosition() {
170+ return self.moving.getPosition();
171+ }
172+
173+ protected void setSelf(Mob self) {
174+ this.self = self;
175+ }
176+
177+ protected void setOldSelf(Mob oldSelf) {
178+ this.oldSelf = oldSelf;
179+ }
180+
181+ protected Queue<Mob> getListDeleteMob() {
182+ return listDeleteMob;
183+ }
184+
185+ }
186+
187+ public class VisibleItems{
188+ private Node nodeMap;
189+ public Node nodeChar;
190+ private Node nodeRotate1;
191+ private Node nodeRotate2;
192+ protected Node nodeOffset;
193+
194+ public void setup(){
195+ nodeMap = new Node();
196+ nodeChar = new Node();
197+ nodeOffset = new Node();
198+ nodeRotate1 = new Node();
199+ nodeRotate2 = new Node();
200+
201+ nodeMap.attachChild(nodeChar);
202+
203+ nodeOffset.attachChild(nodeMap);
204+ // nodeOffset.attachChild(nodeChar);
205+ nodeRotate1.attachChild(nodeOffset);
206+ nodeRotate2.attachChild(nodeRotate1);
207+
208+ }
209+
210+ public void initGround() {
211+
212+ TriMesh src_quad = getQuad("src_quad",ViewSetting.fsize,ViewSetting.fsize);
213+ src_quad.setDefaultColor(ColorRGBA.white);
214+ // src_quad.setRandomColors();
215+ URL fileGlassTex = QuarterViewPanel.class.getClassLoader().getResource("jp/sourceforge/mmosf/client/sample/jme/glass.jpg");
216+ TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
217+ Texture tx = TextureManager.loadTexture(fileGlassTex);
218+ ts.setEnabled(true);
219+ ts.setTexture(tx);
220+ src_quad.setRenderState(ts);
221+ src_quad.setTextureCombineMode(TextureState.REPLACE);
222+
223+ // Box src_box = new Box("src_box",min,max);
224+ // src_box.setRandomColors();
225+ for(int i=0;i<map.getZLimit();i++){
226+ for(int j=0;j<map.getXLimit();j++){
227+
228+ // if(map.map[i][j] != ''){
229+ if(true){
230+ // Box box = new Box(i+","+j,min,max);
231+ // Quad box = new Quad(i+","+j,max.x,max.y);
232+ // TriMesh box = getQuad(i+","+j,max.x,max.y);
233+ TriMesh box = new SharedMesh(i+","+j,src_quad);
234+ // TriMesh box = src_quad;
235+
236+ // box.setModelBound(bb);
237+ box.setModelBound(new BoundingBox());
238+ Vector3f vec = createVector3f(j, i);
239+ vec.y = 0f;//-1*fsize;
240+ box.setLocalTranslation(vec);
241+
242+ box.setCullMode(SceneElement.CULL_NEVER);
243+ box.setIsCollidable(false);
244+ // Quaternion q = new Quaternion();
245+ // q.fromAngles(-FastMath.HALF_PI, 0, 0);
246+ // box.setLocalRotation(q);
247+ // box.setRandomColors();
248+ nodeMap.attachChild(box);
249+ }else{
250+ //
251+ // Box box = new Box(i+","+j,min,max);
252+ //*
253+ // TriMesh box = new SharedMesh(i+","+j,src_box);
254+ TriMesh box = ModelObjectFactory.createWall(i+","+j, ViewSetting.fsize, MobFactory.VISUAL_WALL,ObjectStatus.SELECT_DISABLE).getMesh();
255+ box.setModelBound(new BoundingBox());
256+ box.setLocalTranslation(createVector3f(j, i));
257+ // box.setRandomColors();
258+ nodeMap.attachChild(box);
259+ //*/
260+ }
261+ }
262+ }
263+ // System.out.println(System.currentTimeMillis());
264+ /*
265+ BinaryExporter ex = BinaryExporter.getInstance();
266+ try{
267+ File file = new File("c:\\test.data");
268+ ex.save(nodeMap, file);
269+ }catch(IOException e){
270+ System.out.println(e.toString());
271+ }
272+ //*/
273+ }
274+
275+ private void setAngle() {
276+ Quaternion rote1 = new Quaternion();
277+ rote1.fromAngles(FastMath.HALF_PI/4/*0.5f*/, 0f, 0f);
278+ // rote1.fromAngles(FastMath.HALF_PI/*0.5f*/, 0f, 0f);
279+ nodeRotate2.setLocalRotation(rote1);
280+ Quaternion rote2 = new Quaternion();
281+ // double qp = 0.8;//0.7853981633974483;//java.lang.Math.PI / 4d;
282+ // rote2.fromAngles(0f,(float)qp, 0f);
283+ rote2.fromAngles(0f,FastMath.HALF_PI/2.0f/*0.5f*/, 0f);
284+ nodeRotate1.setLocalRotation(rote2);
285+ }
286+ }
287+
288+ public class JMEMove{
289+ public final Vector3f start;
290+ public final Vector3f end;
291+ public final float frame;
292+ public JMEMove(Vector3f start, Vector3f end, float frame) {
293+ super();
294+ this.start = start;
295+ this.end = end;
296+ this.frame = frame;
297+ }
298+
299+ }
300+ public JMEObjectPanel() {
301+ super();
302+ objectManager = new ObjectManager();
303+ moveDataQueue = new MoveDataQueue();
304+ }
305+ public JMEObjectPanel(GeomapData data) {
306+ super(data);
307+ objectManager = new ObjectManager();
308+ moveDataQueue = new MoveDataQueue();
309+ }
310+ protected final VisibleItems vItems = new VisibleItems();
311+ protected final ObjectManager objectManager;
312+ protected ModelObject myChar2;
313+ protected ModelObject myChar3;
314+ protected java.awt.Point p;
315+ protected Map<Integer, ModelObject> mapMobModel;
316+ protected Mob selectedMob = null;
317+ protected TriMesh cursol;
318+ protected MoveDataQueue moveDataQueue;
319+
320+ @Override
321+ protected void simpleSetup2() {
322+ super.simpleSetup2();
323+ getRootNode().detachAllChildren();
324+
325+ vItems.setup();
326+ vItems.initGround();
327+
328+ initMyChar();
329+
330+ initCursol();
331+
332+
333+ vItems.setAngle();
334+ getRootNode().setLocalTranslation(0,0,ViewSetting.length);//-80);
335+
336+ getRootNode().attachChild(vItems.nodeRotate2);
337+
338+ // mapSpatialMob = new HashMap<Spatial, Mob>();
339+ mapMobModel = new HashMap<Integer, ModelObject>();
340+
341+ }
342+ private void initCursol() {
343+ cursol = new Arrow("cursol",1*ViewSetting.fsize,0.5f*ViewSetting.fsize);
344+ // cursol = new Disk("cursol",8,8,fsize);
345+ // cursol = new Torus("cursol",16,4,fsize/2f/3f,fsize/2f);
346+ Quaternion q = new Quaternion();
347+ q.fromAngles(0, 0/*FastMath.HALF_PI*/, FastMath.PI);
348+ cursol.setLocalRotation(q);
349+ cursol.setDefaultColor(ColorRGBA.red);
350+ cursol.setTextureCombineMode(TextureState.OFF);
351+ }
352+ protected void initMyChar() {
353+ // myChar1 = new Box("self",min,maxBoard);
354+ // myChar.attachChild(new Box("self",min,max));
355+ // TriMesh my = getMobMesh("self");
356+ // myChar2 = getMobMesh("self");
357+ // myChar2 = getMobMesh("self",fileMan,0);
358+ // myChar3 = getMobMesh("self",fileMan,10);
359+ // myChar2 = getAnimatedMob("self",fileMan,fileManTex,0);
360+ myChar2 = ModelObjectFactory.createPC("self",ViewSetting.fsize,0);
361+ // myChar3 = getAnimatedMob("self",fileMan,null,10);
362+ // myChar3 = ModelObjectFactory.createMan("self2",fsize,10);
363+ myChar3 = ModelObjectFactory.createPC("self2",ViewSetting.fsize,10);
364+ // BoundingBox bb = new BoundingBox();
365+ // myChar1.setModelBound(bb);
366+ // myChar1.updateModelBound();
367+
368+ // myChar2.getMesh().setDefaultColor(ColorRGBA.lightGray);
369+ myChar3.getMesh().setDefaultColor(ColorRGBA.magenta);
370+ // myChar1.setLocalTranslation(0,0,0);
371+ myChar2.getNodeTranslation().setLocalTranslation(0,0,0);
372+ myChar3.getNodeTranslation().setLocalTranslation(0,0,0);
373+ // myChar.attachChild(my);
374+
375+ // nodeChar.attachChild(selfSt);
376+ // nodeChar.attachChild(myChar1);
377+ vItems.nodeChar.attachChild(myChar2.getObject());
378+ // nodeChar.attachChild(myChar3.getObject());
379+ }
380+ protected void dispCursol() {
381+ ModelObject modelObject = null;
382+ if(selectedMob != null){
383+ modelObject = mapMobModel.get(selectedMob.getId());
384+ }
385+
386+ if(modelObject != null){
387+ Node selectedObject = modelObject.getNodeTranslation();
388+ if(cursol.getParent() != selectedObject) {
389+ selectedObject.attachChild(cursol);
390+ cursol.updateRenderState();
391+ Vector3f v = new Vector3f();
392+ v.x += 0.5f*ViewSetting.fsize;
393+ v.y += 4f*ViewSetting.fsize;
394+ v.z += 0.5f*ViewSetting.fsize;
395+ cursol.setLocalTranslation(v);
396+ }
397+ }else{
398+ if(cursol.getParent() != null){
399+ cursol.getParent().detachChild(cursol);
400+ }
401+
402+ }
403+
404+ }
405+ protected void moveMob() {
406+ for(int i=0;i<updateCount /*&& /*it.hasNext()*/;i++) {
407+ // Mob mob = it.next();
408+ // it.remove();
409+ Mob mob = objectManager.pollListMob();
410+ if(mob == null){
411+ break;
412+ }
413+
414+ if(mob.getId() == objectManager.getSelf().getId()){
415+ continue;
416+ }
417+ // Spatial box = nodeChar.getChild(Integer.toString(mob.getId()));
418+ ModelObject obj = mapMobModel.get(mob.getId());
419+ if(obj != null){
420+ if(obj.getVisual() != mob.vis.getVtype()){
421+ vItems.nodeChar.detachChild(obj.getObject());
422+ mapMobModel.remove(Integer.valueOf(mob.getId()));
423+ // mapSpatialMob.remove(obj.getObject());
424+
425+ obj = null;
426+ }
427+ }
428+
429+ if(obj == null){
430+ ModelObject obj2 = getModelObject(mob);
431+
432+ vItems.nodeChar.attachChild(obj2.getObject());
433+
434+ obj = obj2;
435+ // mapSpatialMob.put(obj2.getMesh(),mob);
436+ mapMobModel.put(Integer.valueOf(mob.getId()), obj2);
437+ }
438+ // box.setLocalTranslation(createVector3f(mob.getPos().getX(),mob.getPos().getY()));
439+ // obj.setDirection(mob);
440+ // obj.setTranslation(createVector3f(mob));
441+ setAnimation2(obj,
442+ mob.moving.getPosition(),
443+ null,
444+ mob.moving.getVector(),
445+ mob.moving.getSpeed(),
446+ mob.moving.getDirection(), false, 3.8f);
447+ // myChar3.setDirection(mob);
448+ // myChar3.setTranslation(createVector3f(mob));
449+
450+ // mapSpatialMob.get(obj.getMesh()).moving.setPosition(mob.moving.getPosition());
451+ }
452+
453+
454+ }
455+ @Override
456+ protected void simpleUpdate2() {
457+ try{
458+ moveSelf2();
459+
460+ moveMob();
461+
462+ // if(listDeleteMob.size() > 0){
463+ for(int i=0;i<20 /*&&listDeleteMob.size()>0*/;i++) {
464+ // while(listDeleteMob.size()>0){
465+ Mob mob = objectManager.getListDeleteMob().poll();
466+ if(mob == null){
467+ break;
468+ }
469+ deleteMob(mob);
470+
471+ }
472+ // }
473+ // getRootNode().setLocalTranslation(0,0,length);//-80);
474+ // setAngle();
475+ //*
476+ if(p != null){
477+ selectMob(p);
478+ p = null;
479+ }
480+ //*/
481+ dispCursol();
482+
483+ getRootNode().updateRenderState();
484+ }catch(Exception e){
485+ log.error("error in simpleUpdate2,",e);
486+ }
487+
488+ }
489+ private void deleteMob(Mob mob) {
490+ Integer mobId = Integer.valueOf(mob.getId());
491+
492+ ModelObject obj = mapMobModel.get(mobId);
493+ if(obj != null){
494+ vItems.nodeChar.detachChild(obj.getObject());
495+ mapMobModel.remove(mobId);
496+ // mapSpatialMob.remove(obj.getObject());
497+ obj.clear();
498+ }
499+ }
500+ protected void selectMob(Point pt) {
501+ Spatial sp = getSelectedSpatial(pt);
502+
503+ if(sp != null){
504+ // selectedMob = mapSpatialMob.get(sp);
505+ Integer selectedMobId = getMobId(sp);
506+ selectedMob = objectManager.findMob(selectedMobId);
507+
508+ if(getFrame() != null && selectedMob != null){
509+ getFrame().selectMob(selectedMob);
510+ }
511+ }
512+ }
513+ private Integer getMobId(Spatial sp) {
514+ Integer mobId = null;
515+ Iterator<Entry<Integer, ModelObject>> it = mapMobModel.entrySet().iterator();
516+ while (it.hasNext()) {
517+ Map.Entry<Integer, ModelObject> entry = (Map.Entry<Integer, ModelObject>) it.next();
518+ if(entry.getValue().getMesh() == sp){
519+ mobId = entry.getKey();
520+ break;
521+ }
522+
523+ }
524+ return mobId;
525+ }
526+
527+ public void moveSmooth2(Spatial target, MoveData moveData, long nowTime) {
528+ // target.clearControllers();
529+ // if(end.equals(getEndPosition(target))){
530+ // return ;
531+ // }
532+
533+ ArrayList<Controller> list = target.getControllers();
534+ Iterator<Controller> it = list.iterator();
535+ while (it.hasNext()) {
536+ Controller controller = (Controller) it.next();
537+ if(controller instanceof SpatialTransformer){
538+ // target.removeController(controller);
539+ it.remove();
540+ }
541+ }
542+
543+ SpatialTransformer st= new SpatialTransformer(1);
544+
545+ st.setObject(target, 0,-1);
546+
547+ // st.setPosition(0, moveData.getStartTme(),createVector3f(moveData.getStart()));
548+ JMEMove jmeMove = createJMEMove(moveData, nowTime);
549+
550+ st.setPosition(0, 0, jmeMove.start);
551+ st.setPosition(0,jmeMove.frame, jmeMove.end);
552+ // st.setCurTime(nowTime);
553+ //st.setSpeed(0.1f);
554+ st.interpolateMissing();
555+
556+ target.addController(st);
557+ }
558+ private JMEMove createJMEMove(MoveData moveData, long nowTime) {
559+ Vector3f start = createVector3f2(moveData.getMovedPosition(nowTime - moveData.getStartTme()));
560+
561+ long time;
562+ Vector3f end;
563+ if(moveData.isValidEndTime()){
564+ time = moveData.getStopTime() - nowTime;
565+ end = createVector3f2(moveData.getStopPosition());
566+ // st.setPosition(0, time, end);
567+ }else{
568+ // st.setPosition(0, nowTime, createVector3f(moveData.getMovedPosition(nowTime - moveData.getStartTme())));
569+ // st.setPosition(0,0.5f,end);
570+ time = 10000;
571+ end = createVector3f2(moveData.getMovedPosition((nowTime + time) - moveData.getStartTme()));
572+ }
573+
574+ JMEMove jmeMove = new JMEMove(start,end,time/1000);
575+ return jmeMove;
576+ }
577+
578+ public void moveScroll(MoveData moveData, long nowTime) {
579+ // target.clearControllers();
580+ // if(end.equals(getEndPosition(target))){
581+ // return ;
582+ // }
583+
584+ ArrayList<Controller> list = vItems.nodeOffset.getControllers();
585+ Iterator<Controller> it = list.iterator();
586+ while (it.hasNext()) {
587+ Controller controller = (Controller) it.next();
588+ if(controller instanceof SpatialTransformer){
589+ // target.removeController(controller);
590+ it.remove();
591+ }
592+ }
593+
594+ SpatialTransformer st= new SpatialTransformer(1);
595+
596+ st.setObject(vItems.nodeOffset, 0,-1);
597+
598+ st.setPosition(0, moveData.getStartTme(),createVector3f(moveData.getStart()).negate());
599+ st.setPosition(0, nowTime, createVector3f(moveData.getMovedPosition(nowTime - moveData.getStartTme())).negate());
600+ // st.setPosition(0,0.5f,end);
601+ st.setPosition(0,nowTime + 10000,createVector3f(moveData.getMovedPosition((nowTime + 10000) - moveData.getStartTme())).negate());
602+ st.setCurTime(nowTime);
603+ //st.setSpeed(0.1f);
604+ st.interpolateMissing();
605+
606+ vItems.nodeOffset.addController(st);
607+ }
608+ protected void setAnimation2(ModelObject obj, Position pos, Position oldPos,
609+ Vector vec, double speed, Direction direction, boolean isScroll, float frame) {
610+
611+ if(speed > 0){
612+ frame = 3.6f / (float)speed;
613+ }
614+
615+ if(oldPos == null){
616+ oldPos = pos;
617+ }
618+
619+ if(!vec.isZero() /*&& oldPos.equals(pos)*/){
620+ if(!SpatialUtility.isAnimateEnd(obj.getNodeTranslation())){
621+ return;
622+ }
623+
624+ Vector3f now = SpatialUtility.getNowPosition(obj.getNodeTranslation());
625+ if(now == null){
626+ now = createVector3f(pos);
627+ }
628+
629+ Vector3f animeEnd = SpatialUtility.getEndPosition(obj.getNodeTranslation());
630+ if(animeEnd == null){
631+ animeEnd = createVector3f(pos);
632+ }
633+
634+ // frame = adjustAnimeSpeed(frame, now, pos, vec);
635+ if(obj instanceof AnimationModelObject){
636+ AnimationModelObject amo = (AnimationModelObject)obj;
637+ // if(now.distance(end) < fsize * 0.1f){
638+ // if(now.distance(end)/fsize*2f < 0.1f){
639+ amo.startAnimation();
640+ LocalMonitor.getMonitor().log("start animation");
641+ }
642+
643+ // Vector next = vec.getBaseVector();
644+ Vector next = vec.getDirection().getVector();
645+ // Vector next2 = vec.getDirection2();
646+ // if(!next.equals(next2)){
647+ // System.out.println("1)please test:"+vec);
648+ // }
649+ Vector3f end = animeEnd.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
650+ // calcGap(myChar2.getNodeTranslation(), next);
651+ if(isScroll){
652+ SpatialUtility.moveSmooth(vItems.nodeOffset, now.negate(), end.negate(),frame);
653+ // System.out.println("1:"+direction.toString());
654+ }
655+ SpatialUtility.moveSmooth(obj.getNodeTranslation(),now,end,frame);
656+ obj.setDirection(direction);
657+ }else{
658+
659+ Vector3f now = SpatialUtility.getNowPosition(obj.getNodeTranslation());
660+ if(now == null){
661+ now = createVector3f(pos);
662+ }
663+
664+ Vector3f newStart = createVector3f(pos);
665+
666+ // Vector next = vec.getBaseVector();
667+ Vector next = vec.getDirection().getVector();
668+ // Vector next2 = vec.getDirection2();
669+ // if(!next.equals(next2)){
670+ // System.out.println("2)please test:"+vec);
671+ // }
672+ Vector3f end = newStart.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
673+
674+ // if(now.distance(newStart) >= fsize){
675+ // end.add(now.subtract(newStart));
676+ // }
677+
678+ if(vec.isZero()){
679+ frame = adjustAnimeSpeed(frame, now.distance(end));
680+ }else{
681+ /*
682+ Vector3f start = createVector3f(pos.getX(), pos.getY());
683+ if (start.distance(now) > fsize*2f){
684+ LocalMonitor.getMonitor().log("before adjust:start="+start+";now="+now+":end="+end);
685+ Vector3f adj = now.subtract(start);
686+ end = end.add(adj);
687+ LocalMonitor.getMonitor().log("after adjust:"+end);
688+ }
689+ */
690+ }
691+
692+ if(obj instanceof AnimationModelObject){
693+ AnimationModelObject amo = (AnimationModelObject)obj;
694+ // if(now.distance(end) < fsize * 0.1f){
695+ // if(now.distance(end)/fsize*2f < 0.1f){
696+ if(frame <= 0.1f){
697+ amo.stopAnimation();
698+ // LocalMonitor.getMonitor().log("stop animation");
699+ }else{
700+ amo.startAnimation();
701+ // LocalMonitor.getMonitor().log("start animation");
702+ }
703+ }
704+
705+ if(isScroll){
706+ SpatialUtility.moveSmooth(vItems.nodeOffset, now.negate(), end.negate(),frame);
707+ // System.out.println("2:"+direction.toString());
708+ }
709+
710+ SpatialUtility.moveSmooth(obj.getNodeTranslation(),now,end,frame);
711+ obj.setDirection(direction);
712+ // this.objectManager.oldPos = pos;
713+ }
714+
715+
716+ }
717+ protected void setAnimation(ModelObject obj, Position pos, Position oldPos,
718+ Vector vec, double speed, Direction direction, boolean isScroll, float frame) {
719+ // frame = 2.4f;//0.6f;//1.9f;
720+
721+ if(speed > 0){
722+ frame = 3.6f / (float)speed;
723+ }
724+
725+ if(oldPos == null){
726+ oldPos = pos;
727+ }
728+
729+ if(!vec.isZero() && oldPos.equals(pos)){
730+ if(!SpatialUtility.isAnimateEnd(obj.getNodeTranslation())){
731+ return;
732+ }
733+
734+ Vector3f now = SpatialUtility.getNowPosition(obj.getNodeTranslation());
735+ if(now == null){
736+ now = createVector3f(pos);
737+ }
738+
739+ Vector3f animeEnd = SpatialUtility.getEndPosition(obj.getNodeTranslation());
740+ if(animeEnd == null){
741+ animeEnd = createVector3f(pos);
742+ }
743+
744+ if(obj instanceof AnimationModelObject){
745+ AnimationModelObject amo = (AnimationModelObject)obj;
746+ amo.startAnimation();
747+ LocalMonitor.getMonitor().log("start animation");
748+ }
749+
750+ Vector next = vec.getDirection().getVector();
751+
752+ Vector3f end = animeEnd.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
753+
754+ if(isScroll){
755+ SpatialUtility.moveSmooth(vItems.nodeOffset, now.negate(), end.negate(),frame);
756+ }
757+ SpatialUtility.moveSmooth(obj.getNodeTranslation(),now,end,frame);
758+ obj.setDirection(direction);
759+ }else{
760+
761+ Vector3f now = SpatialUtility.getNowPosition(obj.getNodeTranslation());
762+ if(now == null){
763+ now = createVector3f(pos);
764+ }
765+
766+ Vector3f newStart = createVector3f(pos);
767+
768+ Vector next = vec.getDirection().getVector();
769+
770+ Vector3f end = newStart.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
771+
772+ if(vec.isZero()){
773+ frame = adjustAnimeSpeed(frame, now.distance(end));
774+ }else{
775+ }
776+
777+ if(obj instanceof AnimationModelObject){
778+ AnimationModelObject amo = (AnimationModelObject)obj;
779+ if(frame <= 0.1f){
780+ amo.stopAnimation();
781+ // LocalMonitor.getMonitor().log("stop animation");
782+ }else{
783+ amo.startAnimation();
784+ // LocalMonitor.getMonitor().log("start animation");
785+ }
786+ }
787+
788+ if(isScroll){
789+ SpatialUtility.moveSmooth(vItems.nodeOffset, now.negate(), end.negate(),frame);
790+ }
791+
792+ SpatialUtility.moveSmooth(obj.getNodeTranslation(),now,end,frame);
793+ obj.setDirection(direction);
794+ // this.objectManager.oldPos = pos;
795+ }
796+ }
797+
798+ protected void startAnimation(ModelObject obj, Vector vec, double speed, Direction direction, boolean isScroll, float frame) {
799+ // frame = 2.4f;//0.6f;//1.9f;
800+
801+ JMEMove move = getJMEMove(obj, vec, speed, frame);
802+ if(move != null){
803+ startAnimation(obj, move, direction);
804+ }
805+
806+ }
807+
808+ private void startScroll(JMEMove move) {
809+ SpatialUtility.moveSmooth(vItems.nodeOffset, move.start.negate(), move.end.negate(), move.frame);
810+ }
811+
812+ private void startAnimation(ModelObject obj, JMEMove move,
813+ Direction direction) {
814+ if(obj instanceof AnimationModelObject){
815+ AnimationModelObject amo = (AnimationModelObject)obj;
816+ amo.startAnimation();
817+ LocalMonitor.getMonitor().log("start animation");
818+ }
819+
820+ SpatialUtility.moveSmooth(obj.getNodeTranslation(), move.start, move.end, move.frame);
821+ obj.setDirection(direction);
822+ }
823+
824+ private JMEMove getJMEMove(ModelObject obj, Vector vec, double speed,
825+ float frame) {
826+ if(speed > 0){
827+ frame = 3.6f / (float)speed;
828+ }
829+
830+ if(!SpatialUtility.isAnimateEnd(obj.getNodeTranslation())){
831+ return null;
832+ }
833+
834+ Vector3f now = SpatialUtility.getNowPosition(obj.getNodeTranslation());
835+
836+ Vector next = vec.getDirection().getVector();
837+
838+ Vector3f end = now.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
839+
840+ JMEMove move = new JMEMove(now, end, frame);
841+ return move;
842+ }
843+
844+ protected void moveSelf2() {
845+ // Vector3f v;
846+ // v = createVector3f(self);
847+ MoveData moveData = moveDataQueue.getFirst();
848+ if(moveData != null){
849+ JMEMove move = createJMEMove(moveData, System.currentTimeMillis());
850+ // moveSmooth2(myChar2.getNodeTranslation(), moveData, System.currentTimeMillis()) ;
851+ // moveScroll(moveData, System.currentTimeMillis());
852+ if(SpatialUtility.isAnimateEnd(myChar2.getNodeTranslation())){
853+ SpatialUtility.moveSmooth(myChar2.getNodeTranslation(), move.start, move.end, move.frame);
854+ SpatialUtility.moveSmooth(vItems.nodeOffset, move.start.negate(), move.end.negate(), move.frame);
855+ myChar2.setDirection(moveData.getDirection());
856+ if(myChar2 instanceof AnimationModelObject){
857+ AnimationModelObject amo = (AnimationModelObject)myChar2;
858+ amo.startAnimation();
859+ LocalMonitor.getMonitor().log("start animation");
860+ }
861+ }
862+ if(moveData.isValidEndTime()){
863+ moveDataQueue.removeFirst();
864+ SpatialUtility.moveSmooth(myChar2.getNodeTranslation(), move.start, move.end, move.frame);
865+ SpatialUtility.moveSmooth(vItems.nodeOffset, move.start.negate(), move.end.negate(), move.frame);
866+ // myChar2.setTranslation(move.end);
867+ // vItems.nodeOffset.setLocalTranslation(move.end);
868+ if(myChar2 instanceof AnimationModelObject){
869+ AnimationModelObject amo = (AnimationModelObject)myChar2;
870+ amo.stopAnimation();
871+ LocalMonitor.getMonitor().log("stop animation");
872+ }
873+ objectManager.oldPos = moveData.getStopPosition();
874+ }
875+ }else{
876+ moveDataQueue.reloadFirst();
877+
878+ }
879+ /*
880+ if(objectManager.getSelf() != null){
881+ float frame = 1.8f;//1.9f;//2.4f;
882+ setAnimation2(myChar2,
883+ objectManager.getSelf().moving.getPosition(),
884+ objectManager.oldPos,
885+ objectManager.getSelf().moving.getVector(),
886+ objectManager.getSelf().moving.getSpeed(),
887+ objectManager.getSelf().moving.getDirection(), true, frame);
888+ // setAnimation2(myChar2,self.moving.getPosition(), oldPos, Vector.ZERO, self.moving.getSpeed(), self.moving.getDirection(), true, frame);
889+
890+ objectManager.setOldSelf(objectManager.getSelf());
891+
892+ // myChar1.setLocalTranslation(v);
893+ // myChar2.getNodeTranslation().setLocalTranslation(v);
894+ // myChar3.getNodeTranslation().setLocalTranslation(createVector3f(self));
895+ }
896+ */
897+ }
898+ public int getSelectedMobId() {
899+ if (selectedMob != null) {
900+ return selectedMob.getId();
901+ }
902+
903+ return -1;
904+ }
905+ public void select() {
906+ LinkedList<Mob> list = new LinkedList<Mob>();
907+ double distance = 10;
908+ /*
909+ Iterator<Entry<Spatial, Mob>> it = mapSpatialMob.entrySet().iterator();
910+ while (it.hasNext()) {
911+ Entry<Spatial, Mob> next = it.next();
912+ Spatial sp = next.getKey();
913+ Mob mob = next.getValue();
914+ mapMobModel.get(mob).getMesh();
915+
916+ }
917+ */
918+ }
919+ public void resetSelect() {
920+ selectedMob = null;
921+ p = null;
922+ }
923+ @Override
924+ public void mouseClicked(MouseEvent e) {
925+ p = e.getPoint();
926+ }
927+ protected Spatial getSelectedSpatial(Point pt) {
928+ Spatial sp = null;
929+
930+ Vector2f screenPos = new Vector2f();
931+ // Get the position that the mouse is pointing to
932+ screenPos.set(pt.x, pt.y);
933+ // Get the world location of that X,Y value
934+ SystemProvider systemProvider = LWJGLDisplaySystem.getSystemProvider();
935+ DisplaySystem displaySystem = systemProvider.getDisplaySystem();
936+ Ray mouseRay = displaySystem.getPickRay(screenPos, true, null);
937+ PickResults pr = new BoundingPickResults();;
938+ pr.clear();
939+ getRootNode().findPick(mouseRay, pr);
940+
941+ for (int i = 0; i < pr.getNumber(); i++) {
942+ // pr.getPickData(i).getTargetMesh().setRandomColors();
943+ sp = pr.getPickData(i).getTargetMesh().getParentGeom();
944+ Integer id = getMobId(sp);
945+ // ModelObject mo = mapMobModel.get(id);
946+ Mob mob = objectManager.findMob(id);
947+ if(mob != null && mob.vis.getVtype() != 7){
948+ return sp;//continue;
949+ }
950+
951+ }
952+ return null;//sp;
953+ }
954+ static TriMesh getQuad(String name, float x, float z) {
955+ TriMesh m=new TriMesh("Quad");
956+ // Vertex positions for the mesh
957+ Vector3f[] vertexes={
958+ new Vector3f(0,0,0),
959+ new Vector3f(x,0,0),
960+ new Vector3f(0,0,z),
961+ new Vector3f(x,0,z)
962+ };
963+ // Normal directions for each vertex position
964+ Vector3f[] normals={
965+ new Vector3f(0,-1,0),
966+ new Vector3f(0,-1,0),
967+ new Vector3f(0,-1,0),
968+ new Vector3f(0,-1,0)
969+ };
970+ // Color for each vertex position
971+ ColorRGBA[] colors={
972+ // new ColorRGBA(1,0,0,1),
973+ // new ColorRGBA(1,0,0,1),
974+ // new ColorRGBA(0,1,0,1),
975+ // new ColorRGBA(0,1,0,1)
976+ ColorRGBA.white,
977+ ColorRGBA.white,
978+ ColorRGBA.white,
979+ ColorRGBA.white
980+ };
981+ // Texture Coordinates for each position
982+ Vector2f[] texCoords={
983+ new Vector2f(0,0),
984+ new Vector2f(1,0),
985+ new Vector2f(0,1),
986+ new Vector2f(1,1)
987+ };
988+ // The indexes of Vertex/Normal/Color/TexCoord sets. Every 3
989+ // makes a triangle.
990+ int[] indexes={
991+ 0,1,2,1,2,3
992+ // 0,1,3,0,2,3
993+ };
994+ // Feed the information to the TriMesh
995+ m.reconstruct(BufferUtils.createFloatBuffer(vertexes),BufferUtils.createFloatBuffer(normals),
996+ BufferUtils.createFloatBuffer(colors),BufferUtils.createFloatBuffer(texCoords),
997+ BufferUtils.createIntBuffer(indexes));
998+
999+ return m;
1000+ }
1001+ //*/
1002+ static public ModelObject getModelObject(Mob mob) {
1003+ ModelObject obj2 = null;// = getMobMesh(Integer.toString(mob.getId()),fileMan);
1004+ ColorRGBA color = null;//ColorRGBA.red;
1005+ // AnimationModelObject.setDisplaySystem(display);
1006+ switch(mob.vis.getVtype()){
1007+ case 0://NPC
1008+ // color = ColorRGBA.blue;
1009+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileMan,mob.vis.getVtype());
1010+ // obj2 = getAnimatedMob(Integer.toString(mob.getId()),fileMan,fileManTex,mob.vis.getVtype());
1011+ obj2 = ModelObjectFactory.createNPC(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype());
1012+ break;
1013+ case 1://other PC
1014+ color = ColorRGBA.red;
1015+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileMan,mob.vis.getVtype());
1016+ // obj2 = getAnimatedMob(Integer.toString(mob.getId()),fileMan,fileManTex,mob.vis.getVtype());
1017+ obj2 = ModelObjectFactory.createPC(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype());
1018+ break;
1019+ case 2://tree
1020+ color = ColorRGBA.brown;
1021+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileTree,mob.vis.getVtype());
1022+ obj2 = ModelObjectFactory.createTree(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype());
1023+ break;
1024+ case 3://fire
1025+ color = ColorRGBA.red;
1026+ color.a = 0.1f;
1027+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileFire,mob.vis.getVtype());
1028+ obj2 = ModelObjectFactory.createFire(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype());
1029+ break;
1030+ case 4://QuestNPC
1031+ // color = ColorRGBA.green;
1032+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileMan,mob.vis.getVtype());
1033+ // obj2 = getAnimatedMob(Integer.toString(mob.getId()),fileMan,fileManTex,mob.vis.getVtype());
1034+ obj2 = ModelObjectFactory.createQNPC(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype());
1035+ break;//other PC
1036+ case 5://Closed Door
1037+ color = ColorRGBA.darkGray;
1038+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileDoorClose,mob.vis.getVtype());
1039+ obj2 = ModelObjectFactory.createDoorClose(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype());
1040+ break;//other PC
1041+ case 6://Opened Door
1042+ color = ColorRGBA.darkGray;
1043+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileDoorOpen,mob.vis.getVtype());
1044+ obj2 = ModelObjectFactory.createDoorOpen(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype());
1045+ break;//other PC
1046+ case 7://Wall
1047+ color = ColorRGBA.darkGray;
1048+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileDoorOpen,mob.vis.getVtype());
1049+ // obj2 = ModelObjectFactory.createDoorOpen(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
1050+ obj2 = ModelObjectFactory.createWall(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype(),mob.getObjectStatus().getSelectable());
1051+ break;//other PC
1052+ default:
1053+ color = ColorRGBA.randomColor();
1054+ // obj2 = getMobMesh(Integer.toString(mob.getId()),fileMan,mob.vis.getVtype());
1055+ // obj2 = getAnimatedMob(Integer.toString(mob.getId()),fileMan,fileManTex,mob.vis.getVtype());
1056+ obj2 = ModelObjectFactory.createPC(Integer.toString(mob.getId()),ViewSetting.fsize,mob.vis.getVtype());
1057+ }
1058+
1059+ if(color != null){
1060+ // obj2.getMesh().setDefaultColor(color);
1061+ }
1062+
1063+ // obj2.getObject().updateRenderState();
1064+ // impl.doRender();
1065+
1066+ return obj2;
1067+ }
1068+ protected float adjustAnimeSpeed(float frame, float distance) {
1069+ float adjust = distance / (ViewSetting.fsize*2f);
1070+ if(adjust < frame){
1071+ frame = adjust;
1072+ }else{
1073+ // System.out.println("over");
1074+ }
1075+
1076+ if(frame < 0.1f){
1077+ frame = 0.1f;
1078+ }
1079+ // System.out.println("frame:"+frame);
1080+ /*
1081+ if(distance <= fsize){
1082+ frame = 0.1f;
1083+ }else if(distance <= fsize*2){
1084+ frame = 1f;
1085+ }
1086+ */
1087+ return frame;
1088+ }
1089+
1090+ public void receiveCommand(int id, Command com) {
1091+ if(com != Command.MOVE_STOP){
1092+ Vector vec = CommandReceiver.getVector(com);
1093+ MoveData move = MoveData.createStart(id, vec, vec.getDirection(), 2, System.currentTimeMillis());
1094+ // Position pos = objectManager.getSelf().getPosition();
1095+ // move.setEnd(pos);
1096+ // move.setStart(position);
1097+ move.setStart(objectManager.oldPos);
1098+ moveDataQueue.add(move);
1099+
1100+ }else{
1101+ MoveData data = moveDataQueue.find(id);
1102+ if(data != null){
1103+ MoveData move = MoveData.createEnd(id, System.currentTimeMillis());
1104+ // Position pos = objectManager.getSelf().getPosition();
1105+ // move.setEnd(pos);
1106+ moveDataQueue.add(move);
1107+ // objectManager.oldPos = move.getStopPosition();
1108+ }
1109+ }
1110+
1111+ }
1112+ @Override
1113+ public void receiveMovePacket(MovePacket packet) {
1114+ try {
1115+ // MoveData.create(objectManager.getSelf(), movePacket, startTime);
1116+ Position start = packet.getPosition();
1117+ Position next = packet.getNext();
1118+ int id = packet.getCommandId();
1119+ long time = packet.getTime();
1120+ double speed = packet.getSpeed();
1121+ Vector vec = packet.getVector();
1122+
1123+ if(start != null && !vec.isZero()){
1124+ MoveData move = moveDataQueue.find(id);
1125+ if(move != null){
1126+ objectManager.oldPos = start;
1127+ move.setStart(start);
1128+ }
1129+// moveDataQueue.add(move);
1130+
1131+ }else if (next != null){
1132+ MoveData move = moveDataQueue.find(id);
1133+ if(move != null){
1134+
1135+// MoveData stop = MoveData.createEnd(id, -1);
1136+// move.setEnd(next);
1137+ MoveData stop = MoveData.createEnd(id, time);
1138+ moveDataQueue.add(stop);
1139+ }
1140+
1141+ }
1142+ } catch (PacketFormatException e) {
1143+ // TODO 自動生成された catch ブロック
1144+ e.printStackTrace();
1145+ }
1146+ }
1147+
1148+}
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/SpatialUtility.java (nonexistent)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/SpatialUtility.java (revision 103)
@@ -0,0 +1,167 @@
1+/*
2+ * Copyright (c) 2007-2010, MMO Server Framework Project
3+ *
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without modification,
7+ * are permitted provided that the following conditions are met:
8+ *
9+ * Redistributions of source code must retain the above copyright notice,
10+ * this list of conditions and the following disclaimer.
11+ *
12+ * Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * Neither the name of the MMO Server Framework Project nor the names of its
17+ * contributors may be used to endorse or promote products derived from this
18+ * software without specific prior written permission.
19+ *
20+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+ */
32+
33+package jp.sourceforge.mmosf.client.sample.jme;
34+
35+import java.util.ArrayList;
36+import java.util.Iterator;
37+
38+import jp.sourceforge.mmosf.server.object.Position;
39+import jp.sourceforge.mmosf.server.object.Vector;
40+
41+import com.jme.animation.SpatialTransformer;
42+import com.jme.animation.SpatialTransformer.PointInTime;
43+import com.jme.math.Vector3f;
44+import com.jme.scene.Controller;
45+import com.jme.scene.Spatial;
46+
47+public class SpatialUtility {
48+
49+ static public Vector3f getEndPosition(Spatial sp){
50+ ArrayList<Controller> list = sp.getControllers();
51+ Iterator<Controller> it = list.iterator();
52+ while (it.hasNext()) {
53+ Controller controller = (Controller) it.next();
54+ if(!(controller instanceof SpatialTransformer)){
55+ continue;
56+ }
57+
58+ SpatialTransformer st = (SpatialTransformer)controller;
59+ ArrayList<SpatialTransformer.PointInTime> listFrame = st.keyframes;
60+ SpatialTransformer.PointInTime end = listFrame.get(1);
61+ Vector3f endV = end.look[0].getTranslation();
62+
63+ return endV;
64+ }
65+
66+ return null;
67+ }
68+
69+ static public boolean isAnimateEnd(Spatial sp){
70+ ArrayList<Controller> list = sp.getControllers();
71+ Iterator<Controller> it = list.iterator();
72+ while (it.hasNext()) {
73+ Controller controller = (Controller) it.next();
74+ if(!(controller instanceof SpatialTransformer)){
75+ continue;
76+ }
77+
78+ SpatialTransformer st = (SpatialTransformer)controller;
79+ if(st.getCurTime() < st.getMaxTime()){
80+ return false;
81+ }else{
82+ return true;
83+ }
84+ }
85+ return true;
86+ }
87+
88+ public static void moveSmooth(Spatial target, Vector3f start, Vector3f end, float speed) {
89+ // target.clearControllers();
90+ // if(end.equals(getEndPosition(target))){
91+ // return ;
92+ // }
93+
94+ ArrayList<Controller> list = target.getControllers();
95+ Iterator<Controller> it = list.iterator();
96+ while (it.hasNext()) {
97+ Controller controller = (Controller) it.next();
98+ if(controller instanceof SpatialTransformer){
99+ // target.removeController(controller);
100+ it.remove();
101+ }
102+ }
103+
104+ SpatialTransformer st= new SpatialTransformer(1);
105+
106+ st.setObject(target, 0,-1);
107+ st.setPosition(0,0,start);
108+ // st.setPosition(0,0.5f,end);
109+ st.setPosition(0,speed,end);
110+ //st.setSpeed(0.1f);
111+ st.interpolateMissing();
112+
113+ target.addController(st);
114+ }
115+
116+
117+ public static Vector3f getNowPosition(Spatial sp){
118+ ArrayList<Controller> list = sp.getControllers();
119+ Iterator<Controller> it = list.iterator();
120+ while (it.hasNext()) {
121+ Controller controller = (Controller) it.next();
122+ if(!(controller instanceof SpatialTransformer)){
123+ continue;
124+ }
125+
126+ SpatialTransformer st = (SpatialTransformer)controller;
127+ ArrayList<SpatialTransformer.PointInTime> listFrame = st.keyframes;
128+ SpatialTransformer.PointInTime start = listFrame.get(0);
129+ Vector3f startV = start.look[0].getTranslation();
130+ SpatialTransformer.PointInTime end = listFrame.get(1);
131+ Vector3f endV = end.look[0].getTranslation();
132+ // System.out.println("curTime:"+st.getCurTime());
133+ Vector3f move = endV.subtract(startV);
134+ // Vector3f move = startV.subtract(endV);
135+ Vector3f move2 = move.mult(st.getCurTime()/st.getMaxTime());
136+
137+ Vector3f now = startV.add(move2);
138+
139+ return now;
140+ }
141+
142+ return null;
143+
144+ }
145+
146+ public static Vector3f getStartPosition(Spatial sp){
147+ ArrayList<Controller> list = sp.getControllers();
148+ Iterator<Controller> it = list.iterator();
149+ while (it.hasNext()) {
150+ Controller controller = (Controller) it.next();
151+ if(!(controller instanceof SpatialTransformer)){
152+ continue;
153+ }
154+
155+ SpatialTransformer st = (SpatialTransformer)controller;
156+ ArrayList<SpatialTransformer.PointInTime> listFrame = st.keyframes;
157+ SpatialTransformer.PointInTime start = listFrame.get(0);
158+ Vector3f startV = start.look[0].getTranslation();
159+
160+ return startV;
161+ }
162+
163+ return null;
164+
165+ }
166+
167+}
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/command/CommandReceiver.java (nonexistent)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/command/CommandReceiver.java (revision 103)
@@ -0,0 +1,90 @@
1+package jp.sourceforge.mmosf.client.sample.command;
2+
3+import org.apache.commons.logging.Log;
4+import org.apache.commons.logging.LogFactory;
5+
6+import jp.sourceforge.mmosf.server.object.Direction;
7+import jp.sourceforge.mmosf.server.object.Vector;
8+import jp.sourceforge.mmosf.server.packet.MovePacket;
9+import jp.sourceforge.mmosf.server.packet.Packet;
10+import jp.sourceforge.mmosf.server.packet.PacketFactory;
11+import jp.sourceforge.mmosf.server.packet.PacketFormatException;
12+
13+public class CommandReceiver {
14+ static private Log log = LogFactory.getLog(CommandReceiver.class);
15+
16+ protected MovePacket prevMovePackt;
17+
18+ protected int move_id;
19+
20+ public CommandReceiver() {
21+ // TODO 自動生成されたコンストラクター・スタブ
22+ }
23+
24+ public static Vector getVector(Command com){
25+
26+ switch (com) {
27+ case MOVE_UP:
28+ return Direction.NORTH.getVector();
29+ case MOVE_DOWN:
30+ return Direction.SOUTH.getVector();
31+ case MOVE_LEFT:
32+ return Direction.WEST.getVector();
33+ case MOVE_RIGHT:
34+ return Direction.EAST.getVector();
35+ case MOVE_UP_LEFT:
36+ return Direction.NORTH_WEST.getVector();
37+ case MOVE_UP_RIGHT:
38+ return Direction.NORTH_EAST.getVector();
39+ case MOVE_DOWN_LEFT:
40+ return Direction.SOUTH_WEST.getVector();
41+ case MOVE_DOWN_RIGHT:
42+ return Direction.SOUTH_EAST.getVector();
43+ case MOVE_STOP:
44+ return Vector.ZERO;
45+ default:
46+ break;
47+ }
48+
49+ return null;
50+ }
51+
52+ public Packet createPacket(Command com){
53+ try{
54+ return createMovePacket(com);
55+
56+ }catch(Exception e){
57+ log.error("error in send move packet, ",e);
58+ }
59+ return null;
60+ }
61+
62+ private Packet createMovePacket(Command com) throws PacketFormatException {
63+ Vector v = getVector(com);
64+
65+ if(v != null){
66+ Packet packet = null;
67+ if(com == Command.MOVE_STOP){
68+
69+ MovePacket movePacket = (MovePacket)prevMovePackt;
70+ int move_id = movePacket.getCommandId();
71+
72+ Direction dir = movePacket.getDirection();
73+
74+ packet = PacketFactory.createMovePacket(null, null, Vector.ZERO, dir, move_id);
75+
76+ }else{
77+
78+ move_id++;
79+
80+ packet = PacketFactory.createMovePacket(null, null, v, v.getDirection(), move_id);
81+ prevMovePackt = (MovePacket)packet;
82+ }
83+
84+ return packet;
85+ }
86+
87+ return null;
88+ }
89+
90+}
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/command/Command.java (nonexistent)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/command/Command.java (revision 103)
@@ -0,0 +1,14 @@
1+package jp.sourceforge.mmosf.client.sample.command;
2+
3+public enum Command {
4+ MOVE_UP,
5+ MOVE_DOWN,
6+ MOVE_LEFT,
7+ MOVE_RIGHT,
8+ MOVE_UP_LEFT,
9+ MOVE_UP_RIGHT,
10+ MOVE_DOWN_LEFT,
11+ MOVE_DOWN_RIGHT,
12+ MOVE_STOP,
13+ MESSAGE
14+}
Show on old repository browser