• R/O
  • SSH
  • HTTPS

mmosf: 提交


Commit MetaInfo

修訂102 (tree)
時間2010-02-28 23:14:55
作者msz006

Log Message

クライアント側移動プロトコル修正

Change Summary

差異

--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/PacketProcess.java (revision 101)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/PacketProcess.java (revision 102)
@@ -40,12 +40,16 @@
4040 import java.util.List;
4141
4242 import jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime;
43+import jp.sourceforge.mmosf.server.DirectConnection;
4344 import jp.sourceforge.mmosf.server.SocketManager;
4445 import jp.sourceforge.mmosf.server.UserConnection;
4546 import jp.sourceforge.mmosf.server.object.ChatMessage;
4647 import jp.sourceforge.mmosf.server.object.Mob;
48+import jp.sourceforge.mmosf.server.object.Position;
4749 import jp.sourceforge.mmosf.server.object.UpdateCache;
50+import jp.sourceforge.mmosf.server.object.Vector;
4851 import jp.sourceforge.mmosf.server.packet.MessagePacket;
52+import jp.sourceforge.mmosf.server.packet.MovePacket;
4953 import jp.sourceforge.mmosf.server.packet.Packet;
5054 import jp.sourceforge.mmosf.server.packet.PacketFactory;
5155 import jp.sourceforge.mmosf.server.packet.PacketFormatException;
@@ -69,6 +73,7 @@
6973 // this.sampleClientFrame = sampleClientFrame;
7074 // }
7175 protected UserConnection conn;
76+ protected LocalConnection localConn;
7277 // protected SocketChannel channel;
7378 protected UpdateCache updateCache = new UpdateCache();
7479 protected boolean isLogout = false;
@@ -130,8 +135,9 @@
130135 try{
131136 frame.startLogTime();
132137 conn.send(packet);
138+ localConn.send(packet);
133139 }catch(Exception ex){
134- SampleClientFrame.log.error("send packet error.",ex);
140+ log.error("send packet error.",ex);
135141 }
136142 }
137143
@@ -145,7 +151,7 @@
145151 // Thread.sleep(100);
146152 Thread.yield();
147153 }catch(Throwable e){
148- SampleClient3.log.error("receive error.",e);
154+ log.error("receive error.",e);
149155 }
150156 }
151157 }
@@ -163,6 +169,11 @@
163169 // frame.getMessage().redrawMessage();
164170 // System.out.println(pack.toString());
165171 }
172+
173+ if(localConn.isReceive()){
174+ Packet pack = localConn.receive();
175+// parsePacket(pack);
176+ }
166177 }
167178
168179 public void sendMessage(String str) {
@@ -198,7 +209,7 @@
198209
199210 Packet ret = conn.receive();
200211 if(ret.getType() != Type.CONNECT){
201- SampleClient3.log.error("invalid packet.");
212+ log.error("invalid packet.");
202213 // conn.abort();
203214 conn.close();
204215 return false;
@@ -209,6 +220,8 @@
209220 this.conn = conn;
210221 charactorId = charId;
211222
223+ this.localConn = new LocalConnection(charactorId, updateCache);
224+
212225 isLogout = false;
213226 return true;
214227 }
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/test/Test.java (revision 101)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/test/Test.java (revision 102)
@@ -32,18 +32,56 @@
3232
3333 package jp.sourceforge.mmosf.client.sample.jme.test;
3434
35+import java.awt.Point;
36+import java.util.Iterator;
37+import java.util.LinkedList;
38+import java.util.List;
39+import java.util.Map;
40+import java.util.Queue;
41+import java.util.Map.Entry;
42+
43+import jp.sourceforge.mmosf.admin.LocalMonitor;
44+import jp.sourceforge.mmosf.client.sample.jme.AnimationModelObject;
45+import jp.sourceforge.mmosf.client.sample.jme.GameObjectPanel;
46+import jp.sourceforge.mmosf.client.sample.jme.ModelObject;
47+import jp.sourceforge.mmosf.client.sample.jme.ModelObjectFactory;
3548 import jp.sourceforge.mmosf.client.sample.jme.QuarterViewPanel;
49+import jp.sourceforge.mmosf.client.sample.jme.JMEObjectPanel.ObjectManager;
50+import jp.sourceforge.mmosf.client.sample.jme.JMEObjectPanel.VisibleItems;
51+import jp.sourceforge.mmosf.server.object.Direction;
52+import jp.sourceforge.mmosf.server.object.Mob;
53+import jp.sourceforge.mmosf.server.object.Position;
54+import jp.sourceforge.mmosf.server.object.Vector;
3655 import junit.framework.Assert;
3756
3857 import com.jme.math.Vector2f;
58+import com.jme.math.Vector3f;
59+import com.jme.renderer.ColorRGBA;
60+import com.jme.scene.Node;
61+import com.jme.scene.Spatial;
62+import com.jme.scene.TriMesh;
3963
4064
4165 public class Test {
42- private class TestPanel extends QuarterViewPanel{
66+ private class TestPanel extends GameObjectPanel{
4367 /**
4468 *
4569 */
4670 private static final long serialVersionUID = 1L;
71+// protected final VisibleItems vItems = new VisibleItems();
72+// protected final ObjectManager objectManager;
73+// protected Mob self;
74+// protected Mob oldSelf;
75+// protected final Queue<Mob> listMob;
76+// protected final Queue<Mob> listDeleteMob;
77+// protected ModelObject myChar2;
78+// protected ModelObject myChar3;
79+// protected java.awt.Point p;
80+// protected Map<Spatial, Mob> mapSpatialMob;
81+// protected Map<Integer, ModelObject> mapMobModel;
82+// protected Mob selectedMob = null;
83+// protected TriMesh cursol;
84+// protected Position oldPos;
4785
4886 @Override
4987 public Vector2f getCameraRect(float width, float height) {
@@ -50,6 +88,490 @@
5088 // TODO 自動生成されたメソッド・スタブ
5189 return super.getCameraRect(width, height);
5290 }
91+
92+ protected void initMyChar() {
93+ // myChar1 = new Box("self",min,maxBoard);
94+ // myChar.attachChild(new Box("self",min,max));
95+ // TriMesh my = getMobMesh("self");
96+ // myChar2 = getMobMesh("self");
97+ // myChar2 = getMobMesh("self",fileMan,0);
98+ // myChar3 = getMobMesh("self",fileMan,10);
99+ // myChar2 = getAnimatedMob("self",fileMan,fileManTex,0);
100+ myChar2 = ModelObjectFactory.createPC("self",ViewSetting.fsize,0);
101+ // myChar3 = getAnimatedMob("self",fileMan,null,10);
102+ // myChar3 = ModelObjectFactory.createMan("self2",fsize,10);
103+ myChar3 = ModelObjectFactory.createPC("self2",ViewSetting.fsize,10);
104+ // BoundingBox bb = new BoundingBox();
105+ // myChar1.setModelBound(bb);
106+ // myChar1.updateModelBound();
107+
108+ // myChar2.getMesh().setDefaultColor(ColorRGBA.lightGray);
109+ myChar3.getMesh().setDefaultColor(ColorRGBA.magenta);
110+ // myChar1.setLocalTranslation(0,0,0);
111+ myChar2.getNodeTranslation().setLocalTranslation(0,0,0);
112+ myChar3.getNodeTranslation().setLocalTranslation(0,0,0);
113+ // myChar.attachChild(my);
114+
115+ // nodeChar.attachChild(selfSt);
116+ // nodeChar.attachChild(myChar1);
117+ vItems.nodeChar.attachChild(myChar2.getObject());
118+ // nodeChar.attachChild(myChar3.getObject());
119+ }
120+
121+ protected void dispCursol() {
122+ ModelObject modelObject = null;
123+ if(selectedMob != null){
124+ modelObject = mapMobModel.get(selectedMob.getId());
125+ }
126+
127+ if(modelObject != null){
128+ Node selectedObject = modelObject.getNodeTranslation();
129+ if(cursol.getParent() != selectedObject) {
130+ selectedObject.attachChild(cursol);
131+ cursol.updateRenderState();
132+ Vector3f v = new Vector3f();
133+ v.x += 0.5f*ViewSetting.fsize;
134+ v.y += 4f*ViewSetting.fsize;
135+ v.z += 0.5f*ViewSetting.fsize;
136+ cursol.setLocalTranslation(v);
137+ }
138+ }else{
139+ if(cursol.getParent() != null){
140+ cursol.getParent().detachChild(cursol);
141+ }
142+
143+ }
144+
145+ }
146+
147+ protected Queue<Mob> getListDeleteMob() {
148+ return listDeleteMob;
149+ }
150+
151+ protected Queue<Mob> getListMob() {
152+ return listMob;
153+ }
154+
155+ protected void setSelf(Mob self) {
156+ this.self = self;
157+ }
158+
159+ protected void setOldSelf(Mob oldSelf) {
160+ this.oldSelf = oldSelf;
161+ }
162+
163+ protected Mob getOldSelf() {
164+ return oldSelf;
165+ }
166+
167+ protected void moveMob() {
168+ for(int i=0;i<updateCount /*&& /*it.hasNext()*/;i++) {
169+ // Mob mob = it.next();
170+ // it.remove();
171+ Mob mob = getListMob().poll();
172+ if(mob == null){
173+ break;
174+ }
175+
176+ if(mob.getId() == getSelf().getId()){
177+ continue;
178+ }
179+ // Spatial box = nodeChar.getChild(Integer.toString(mob.getId()));
180+ ModelObject obj = mapMobModel.get(mob.getId());
181+ if(obj != null){
182+ //*
183+ // if(mob.vis.getVtype() == MobFactory.VISUAL_DOOR_OPEN){
184+ // System.out.println("open");
185+ // }
186+
187+ if(obj.getVisual() != mob.vis.getVtype()){
188+ vItems.nodeChar.detachChild(obj.getObject());
189+ mapMobModel.remove(Integer.valueOf(mob.getId()));
190+ mapSpatialMob.remove(obj.getObject());
191+
192+ obj = null;
193+ }
194+ //*/
195+ }
196+
197+ if(obj == null){
198+ // Box box2 = new Box(Integer.toString(mob.getId()),min,max);
199+ // box2.setModelBound(bb);
200+ // box2.updateModelBound();
201+ // box2.setLocalTranslation(0,0,0);
202+ ModelObject obj2 = getModelObject(mob);
203+
204+ vItems.nodeChar.attachChild(obj2.getObject());
205+
206+ // obj2.getMesh().updateRenderState();
207+
208+ obj = obj2;
209+ // mapMobModel.put(Integer.valueOf(mob.getId()), box2);
210+ // mapMobIndex.put(box2, Integer.valueOf(mob.getId()));
211+ mapSpatialMob.put(obj2.getMesh(),mob);
212+ mapMobModel.put(Integer.valueOf(mob.getId()), obj2);
213+ }
214+ // box.setLocalTranslation(createVector3f(mob.getPos().getX(),mob.getPos().getY()));
215+ // obj.setDirection(mob);
216+ // obj.setTranslation(createVector3f(mob));
217+ setAnimation2(obj,mob.moving.getPosition(), null, mob.moving.getVector(), mob.moving.getSpeed(), mob.moving.getDirection(), false, 3.8f);
218+ // myChar3.setDirection(mob);
219+ // myChar3.setTranslation(createVector3f(mob));
220+
221+ mapSpatialMob.get(obj.getMesh()).moving.setPosition(mob.moving.getPosition());
222+ }
223+
224+
225+ }
226+
227+ @Override
228+ protected void simpleUpdate2() {
229+ try{
230+ // if(self != null){
231+ moveSelf2();
232+ // }
233+ //*
234+ if(getListMob() != null){
235+ moveMob();
236+ }
237+
238+ // if(listDeleteMob.size() > 0){
239+ for(int i=0;i<20 /*&&listDeleteMob.size()>0*/;i++) {
240+ // while(listDeleteMob.size()>0){
241+ Mob mob = getListDeleteMob().poll();
242+ if(mob == null){
243+ break;
244+ }
245+ ModelObject obj = mapMobModel.get(mob.getId());
246+ if(obj == null){
247+ continue;
248+ }
249+
250+ vItems.nodeChar.detachChild(obj.getObject());
251+ mapMobModel.remove(Integer.valueOf(mob.getId()));
252+ mapSpatialMob.remove(obj.getObject());
253+ obj.clear();
254+ }
255+ // }
256+ // getRootNode().setLocalTranslation(0,0,length);//-80);
257+ // setAngle();
258+ //*
259+ if(p != null){
260+ selectMob(p);
261+ p = null;
262+ }
263+ //*/
264+ dispCursol();
265+
266+ getRootNode().updateRenderState();
267+ }catch(Exception e){
268+ log.error("error in simpleUpdate2,",e);
269+ }
270+
271+ }
272+
273+ protected void selectMob(Point pt) {
274+ Spatial sp = getSelectedSpatial(pt);
275+
276+ if(sp != null){
277+ /*
278+ MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
279+ /*
280+ ms.setShininess(100f);
281+ ms.setEnabled(true);
282+ ms.setAmbient(ColorRGBA.lightGray);
283+ // ms.setEmissive(ColorRGBA.white);
284+ ms.setMaterialFace(MaterialState.MF_FRONT_AND_BACK);
285+ sp.setRenderState(ms);
286+ sp.updateRenderState();
287+ //*/
288+ /*
289+ if (sp instanceof TriMesh) {
290+ TriMesh mesh = (TriMesh) sp;
291+ mesh.setSolidColor(ColorRGBA.yellow);
292+ }
293+ */
294+ // selectedId = mapMobIndex.get(sp);
295+ // selectedMob = getSelectedMob();
296+ // sp.getParent().attachChild(cursol);
297+ selectedMob = mapSpatialMob.get(sp);
298+ // dispCursol();
299+ if(getFrame() != null){
300+ getFrame().selectMob(selectedMob);
301+ }
302+ }
303+ }
304+
305+ protected void setAnimation2(ModelObject obj, Position pos, Position oldPos,
306+ Vector vec, double speed, Direction direction, boolean isScroll, float frame) {
307+ // if(!vec.isZero()){
308+ // System.out.println("aaa");
309+ // }
310+
311+ // frame = 2.4f;//0.6f;//1.9f;
312+
313+ if(speed > 0){
314+ frame = 3.6f / (float)speed;
315+ }
316+
317+ if(oldPos == null){
318+ oldPos = pos;
319+ }
320+ /*
321+ if(obj instanceof AnimationModelObject){
322+ AnimationModelObject amo = (AnimationModelObject)obj;
323+ // if(now.distance(end) < fsize * 0.1f){
324+ // if(now.distance(end)/fsize*2f < 0.1f){
325+ // if(vec.isZero()){
326+ if(vec.isZero() && oldPos.equals(pos)){
327+ amo.stopAnimation();
328+ }else{
329+ amo.startAnimation();
330+ }
331+ }
332+ //*/
333+ if(!vec.isZero() && oldPos.equals(pos)){
334+ if(!isAnimateEnd(obj.getNodeTranslation())){
335+ return;
336+ }
337+
338+ Vector3f now = getNowPosition(obj.getNodeTranslation());
339+ if(now == null){
340+ now = createVector3f(pos);
341+ }
342+
343+ Vector3f animeEnd = getEndPosition(obj.getNodeTranslation());
344+ if(animeEnd == null){
345+ animeEnd = createVector3f(pos);
346+ }
347+
348+ // frame = adjustAnimeSpeed(frame, now, pos, vec);
349+ if(obj instanceof AnimationModelObject){
350+ AnimationModelObject amo = (AnimationModelObject)obj;
351+ // if(now.distance(end) < fsize * 0.1f){
352+ // if(now.distance(end)/fsize*2f < 0.1f){
353+ amo.startAnimation();
354+ LocalMonitor.getMonitor().log("start animation");
355+ }
356+
357+ // Vector next = vec.getBaseVector();
358+ Vector next = vec.getDirection().getVector();
359+ // Vector next2 = vec.getDirection2();
360+ // if(!next.equals(next2)){
361+ // System.out.println("1)please test:"+vec);
362+ // }
363+ Vector3f end = animeEnd.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
364+ // calcGap(myChar2.getNodeTranslation(), next);
365+ if(isScroll){
366+ moveSmooth(vItems.nodeOffset, now.negate(), end.negate(),frame);
367+ // System.out.println("1:"+direction.toString());
368+ }
369+ moveSmooth(obj.getNodeTranslation(),now,end,frame);
370+ obj.setDirection(direction);
371+ }else{
372+
373+ Vector3f now = getNowPosition(obj.getNodeTranslation());
374+ if(now == null){
375+ now = createVector3f(pos);
376+ }
377+
378+ Vector3f newStart = createVector3f(pos);
379+
380+ // Vector next = vec.getBaseVector();
381+ Vector next = vec.getDirection().getVector();
382+ // Vector next2 = vec.getDirection2();
383+ // if(!next.equals(next2)){
384+ // System.out.println("2)please test:"+vec);
385+ // }
386+ Vector3f end = newStart.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
387+
388+ // if(now.distance(newStart) >= fsize){
389+ // end.add(now.subtract(newStart));
390+ // }
391+
392+ if(vec.isZero()){
393+ frame = adjustAnimeSpeed(frame, now.distance(end));
394+ }else{
395+ /*
396+ Vector3f start = createVector3f(pos.getX(), pos.getY());
397+ if (start.distance(now) > fsize*2f){
398+ LocalMonitor.getMonitor().log("before adjust:start="+start+";now="+now+":end="+end);
399+ Vector3f adj = now.subtract(start);
400+ end = end.add(adj);
401+ LocalMonitor.getMonitor().log("after adjust:"+end);
402+ }
403+ */
404+ }
405+
406+ if(obj instanceof AnimationModelObject){
407+ AnimationModelObject amo = (AnimationModelObject)obj;
408+ // if(now.distance(end) < fsize * 0.1f){
409+ // if(now.distance(end)/fsize*2f < 0.1f){
410+ if(frame <= 0.1f){
411+ amo.stopAnimation();
412+ // LocalMonitor.getMonitor().log("stop animation");
413+ }else{
414+ amo.startAnimation();
415+ // LocalMonitor.getMonitor().log("start animation");
416+ }
417+ }
418+
419+ if(isScroll){
420+ moveSmooth(vItems.nodeOffset, now.negate(), end.negate(),frame);
421+ // System.out.println("2:"+direction.toString());
422+ }
423+ /*
424+ if(obj.getVisual() == 7){
425+ if(!now.equals(end)){
426+ System.out.println("bad animation.");
427+ }
428+ }
429+ */
430+ moveSmooth(obj.getNodeTranslation(),now,end,frame);
431+ obj.setDirection(direction);
432+ this.oldPos = pos;
433+ }
434+
435+
436+ }
437+
438+ protected void setAnimation(ModelObject obj, Position pos, Position oldPos,
439+ Vector vec, double speed, Direction direction, boolean isScroll, float frame) {
440+ // frame = 2.4f;//0.6f;//1.9f;
441+
442+ if(speed > 0){
443+ frame = 3.6f / (float)speed;
444+ }
445+
446+ if(oldPos == null){
447+ oldPos = pos;
448+ }
449+
450+ if(!vec.isZero() && oldPos.equals(pos)){
451+ if(!isAnimateEnd(obj.getNodeTranslation())){
452+ return;
453+ }
454+
455+ Vector3f now = getNowPosition(obj.getNodeTranslation());
456+ if(now == null){
457+ now = createVector3f(pos);
458+ }
459+
460+ Vector3f animeEnd = getEndPosition(obj.getNodeTranslation());
461+ if(animeEnd == null){
462+ animeEnd = createVector3f(pos);
463+ }
464+
465+ if(obj instanceof AnimationModelObject){
466+ AnimationModelObject amo = (AnimationModelObject)obj;
467+ amo.startAnimation();
468+ LocalMonitor.getMonitor().log("start animation");
469+ }
470+
471+ Vector next = vec.getDirection().getVector();
472+
473+ Vector3f end = animeEnd.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
474+
475+ if(isScroll){
476+ moveSmooth(vItems.nodeOffset, now.negate(), end.negate(),frame);
477+ }
478+ moveSmooth(obj.getNodeTranslation(),now,end,frame);
479+ obj.setDirection(direction);
480+ }else{
481+
482+ Vector3f now = getNowPosition(obj.getNodeTranslation());
483+ if(now == null){
484+ now = createVector3f(pos);
485+ }
486+
487+ Vector3f newStart = createVector3f(pos);
488+
489+ Vector next = vec.getDirection().getVector();
490+
491+ Vector3f end = newStart.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
492+
493+ if(vec.isZero()){
494+ frame = adjustAnimeSpeed(frame, now.distance(end));
495+ }else{
496+ }
497+
498+ if(obj instanceof AnimationModelObject){
499+ AnimationModelObject amo = (AnimationModelObject)obj;
500+ if(frame <= 0.1f){
501+ amo.stopAnimation();
502+ // LocalMonitor.getMonitor().log("stop animation");
503+ }else{
504+ amo.startAnimation();
505+ // LocalMonitor.getMonitor().log("start animation");
506+ }
507+ }
508+
509+ if(isScroll){
510+ moveSmooth(vItems.nodeOffset, now.negate(), end.negate(),frame);
511+ }
512+
513+ moveSmooth(obj.getNodeTranslation(),now,end,frame);
514+ obj.setDirection(direction);
515+ this.oldPos = pos;
516+ }
517+ }
518+
519+ protected void moveSelf2() {
520+ // Vector3f v;
521+ // v = createVector3f(self);
522+ if(getSelf() != null){
523+ float frame = 1.8f;//1.9f;//2.4f;
524+ setAnimation2(myChar2,getSelf().moving.getPosition(), oldPos, getSelf().moving.getVector(), getSelf().moving.getSpeed(), getSelf().moving.getDirection(), true, frame);
525+ // setAnimation2(myChar2,self.moving.getPosition(), oldPos, Vector.ZERO, self.moving.getSpeed(), self.moving.getDirection(), true, frame);
526+
527+ setOldSelf(getSelf());
528+
529+ // myChar1.setLocalTranslation(v);
530+ // myChar2.getNodeTranslation().setLocalTranslation(v);
531+ // myChar3.getNodeTranslation().setLocalTranslation(createVector3f(self));
532+ }
533+
534+ }
535+
536+ public int getSelectedMobId() {
537+ if (selectedMob != null) {
538+ return selectedMob.getId();
539+ }
540+
541+ return -1;
542+ }
543+
544+ public void select() {
545+ LinkedList<Mob> list = new LinkedList<Mob>();
546+ double distance = 10;
547+
548+ Iterator<Entry<Spatial, Mob>> it = mapSpatialMob.entrySet().iterator();
549+ while (it.hasNext()) {
550+ Entry<Spatial, Mob> next = it.next();
551+ Spatial sp = next.getKey();
552+ Mob mob = next.getValue();
553+ mapMobModel.get(mob).getMesh();
554+
555+ }
556+
557+ }
558+
559+ public void resetSelect() {
560+ selectedMob = null;
561+ p = null;
562+ }
563+
564+ public Mob getSelf() {
565+ return self;
566+ }
567+
568+ public void update(Mob self, List<Mob> listUpdate, List<Mob> listDelete) {
569+ this.objectManager.update(self, listUpdate, listDelete);
570+ }
571+
572+ public Position getMyPosition() {
573+ return self.moving.getPosition();
574+ }
53575 };
54576
55577
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/JHPPanel.java (revision 101)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/JHPPanel.java (revision 102)
@@ -131,7 +131,7 @@
131131 sb.append(namePC);
132132 sb.append("<br>");
133133 sb.append("<table border=0 cellspacing=0 cellpadding=0 width=100%><tr width=100%>");
134- sb.append("<td bgcolor=#00ff00 width=");
134+ sb.append("<td bgcolor=#0000ff width=");
135135 int percent = (status.getHitpoint()*barWidth)/status.getHitpointMax();
136136 // int percent = (int)(0.98*barWidth);
137137 sb.append(percent);
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/SampleClientFrame.java (revision 101)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/SampleClientFrame.java (revision 102)
@@ -55,6 +55,8 @@
5555 import jp.sourceforge.mmosf.client.sample.InputProcess;
5656 import jp.sourceforge.mmosf.client.sample.JScrollMessageLabel;
5757 import jp.sourceforge.mmosf.client.sample.PacketProcess;
58+import jp.sourceforge.mmosf.client.sample.command.Command;
59+import jp.sourceforge.mmosf.client.sample.command.CommandReceiver;
5860 import jp.sourceforge.mmosf.server.MatchingServer;
5961 import jp.sourceforge.mmosf.server.level.GeomapData;
6062 import jp.sourceforge.mmosf.server.object.ChatMessage;
@@ -96,11 +98,13 @@
9698
9799 protected PacketProcess process;
98100 protected InputProcess input;
101+
102+ protected CommandReceiver commandReceiver;
99103
100104 protected Position pos;
101105
102106 protected GeomapData zone = new GeomapData();
103- protected QuarterViewPanel viewPanel;
107+ protected JMEObjectPanel viewPanel;
104108
105109 protected Mob selectedMob = null;
106110 protected int selectedSlot = -1;
@@ -139,7 +143,7 @@
139143
140144 @Override
141145 public void receiveUpdate(Mob self, List<Mob> listUpdate, List<Mob> listDelete) {
142- viewPanel.update(self,listUpdate,listDelete);
146+ viewPanel.objectManager.update(self, listUpdate, listDelete);
143147 hpPanel.setTarget(viewPanel.getSelectedMobId());
144148 hpPanel.update(self, listUpdate, listDelete);
145149 }
@@ -151,20 +155,23 @@
151155
152156 @Override
153157 protected void onLogout() {
154- input.send(Vector.ZERO);
158+// input.queue(Vector.ZERO);
159+ input.queue(Command.MOVE_STOP);
155160 }
156161 };
157162
158163 process.setFrame(this);
159164
165+ commandReceiver = new CommandReceiver();
166+
160167 input = new InputProcess(){
161- @Override
168+/* @Override
162169 public void send(Packet packet) {
163170 // log.debug("send move packet.");
164171 startLogTimeMove();
165172 process.send(packet);
166173 }
167-
174+*/
168175 @Override
169176 public boolean isLogout() {
170177 return process.isLogout();
@@ -175,10 +182,25 @@
175182 viewPanel.select();
176183
177184 }
185+
178186 @Override
179- protected Position getNowPosition() {
180- return viewPanel.getMyPosition();
181- }
187+ public void send(Command com) {
188+ Packet packet = commandReceiver.createPacket(com);
189+ if(packet != null){
190+ process.send(packet);
191+ }
192+ if(packet instanceof MovePacket){
193+ try{
194+ int id = ((MovePacket)packet).getCommandId();
195+ viewPanel.receiveCommand(id,com);
196+ }catch(PacketFormatException e){
197+ log.warn(e);
198+ }
199+// }else{
200+// viewPanel.receiveCommand(com);
201+ }
202+
203+ }
182204 };
183205
184206 new Thread(input,"InputProcess").start();
@@ -190,7 +212,7 @@
190212 JPanel panel = new JPanel();
191213 BorderLayout layout = new BorderLayout();
192214 panel.setLayout(layout);
193- viewPanel = new QuarterViewPanel();
215+ viewPanel = new GameObjectPanel();
194216 panel.add(viewPanel,BorderLayout.CENTER);
195217
196218 JPanel panel2 = new JPanel();
@@ -224,7 +246,6 @@
224246 menuPanel = new JMenuPanel(){
225247 @Override
226248 protected void onButton(ActionElement act) {
227- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
228249 // super.onButton(strActionCommand);
229250 Packet packet;
230251 if(selectedMob != null){
@@ -233,7 +254,7 @@
233254 packet = PacketFactory.createActionPacket(selectedSlot, act);
234255 }
235256 if(isReplyMessage()){
236- message.addMessage(ChatMessage.createTell(String.valueOf(viewPanel.getSelf().c),act.name));
257+ message.addMessage(ChatMessage.createTell(String.valueOf(viewPanel.objectManager.getSelf().c),act.name));
237258 }
238259 process.send(packet);
239260 clearMenu();
@@ -242,7 +263,6 @@
242263 // menuPanel.setSize(0, menuPanel.getHeight());
243264
244265 // JLabel lavel = new JLabel();
245-// lavel.setText("?ス?ス?スj?ス?ス?ス[");
246266 // menuPanel.add(lavel);
247267 menuPanel.setText("Command");
248268 menuPanel.setPreferredSize(new Dimension(200,200));
@@ -251,7 +271,6 @@
251271
252272 @Override
253273 protected void onButton(ActionElement act) {
254- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
255274 selectItem(act.id);
256275 // Packet packet = PacketFactory.createMenuRequestPaket(act.id);
257276 // process.send(packet);
@@ -299,6 +318,10 @@
299318 timelogBuffer = new StringBuffer();
300319 }
301320
321+ protected void receiveCommand(Command com){
322+
323+ }
324+
302325 public boolean connect(SocketAddress addr, String connectId)/*
303326 throws IOException, PacketFormatException, InterruptedException */{
304327 try{
@@ -326,7 +349,6 @@
326349 }
327350
328351 public void actionPerformed(ActionEvent arg0) {
329- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
330352 process.sendMessage(chatInput.getText());
331353
332354 chatInput.setText("");
@@ -366,7 +388,7 @@
366388 {
367389 double distance = 0;
368390 if(selectedMob != null){
369- distance = MatchingServer.getDistance(getSelf().moving.getPosition(), selectedMob.moving.getPosition());
391+ distance = Position.getDistance(getSelf().moving.getPosition(), selectedMob.moving.getPosition());
370392 }
371393 String target = packet.getString(MenuPacket.TARGET);
372394 String text = packet.getString(MenuPacket.TEXT);
@@ -390,7 +412,7 @@
390412 // Item item = PacketFactory.parseGetItemStatusPacket((StatusPacket)packet);
391413 Entry<Integer, Item> ret = PacketFactory.parseGetItemStatusPacket((StatusPacket)packet);
392414
393- message.addMessage(ChatMessage.createSysMsg(ret.getValue().name+"?ス?ス?ス?スノ難ソス黷ス?スB"));
415+ message.addMessage(ChatMessage.createSysMsg(ret.getValue().name+"を手にいれました。"));
394416 // listItem.set(ret.getKey().intValue(), ret.getValue());
395417 listItem[ret.getKey().intValue()] = ret.getValue();
396418
@@ -423,19 +445,19 @@
423445 switch(packet.getInt(QuestPacket.PROGRESS)){
424446 case QuestPacket.START:
425447 {
426- message.addMessage(ChatMessage.createSysMsg("\""+packet.getString(QuestPacket.NAME)+"\"?ス?ス?スJ?スn?ス?ス?スワゑソス?ス?ス?スB"));
448+ message.addMessage(ChatMessage.createSysMsg("\""+packet.getString(QuestPacket.NAME)+"\"を開始しました。"));
427449 questPanel.addNewQuest(packet);
428450 break;
429451 }
430452 case QuestPacket.UPDATE:
431453 {
432- message.addMessage(ChatMessage.createSysMsg("\""+packet.getString(QuestPacket.NAME)+"\"?ス?ス?スX?スV?ス?ス?スワゑソス?ス?ス?スB"));
454+ message.addMessage(ChatMessage.createSysMsg("\""+packet.getString(QuestPacket.NAME)+"\"を更新しました。"));
433455 questPanel.updateQuest(packet);
434456 break;
435457 }
436458 case QuestPacket.COMPLETE:
437459 {
438- message.addMessage(ChatMessage.createSysMsg("\""+packet.getString(QuestPacket.NAME)+"\"?ス?ス?ス?ス?ス?ス?ス?ス?スワゑソス?ス?ス?スB"));
460+ message.addMessage(ChatMessage.createSysMsg("\""+packet.getString(QuestPacket.NAME)+"\"を完了しました"));
439461 questPanel.completeQuest(packet);
440462 break;
441463 }
@@ -479,17 +501,14 @@
479501 }
480502
481503 public void windowActivated(WindowEvent e) {
482- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
483504
484505 }
485506
486507 public void windowClosed(WindowEvent e) {
487- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
488508
489509 }
490510
491511 public void windowClosing(WindowEvent e) {
492- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
493512 sendLog();
494513 Packet packet = SystemPacketFactory.createLogoutPacket(true);
495514 process.send(packet);
@@ -496,32 +515,25 @@
496515 }
497516
498517 public void windowDeactivated(WindowEvent e) {
499- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
500518
501519 }
502520
503521 public void windowDeiconified(WindowEvent e) {
504- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
505522
506523 }
507524
508525 public void windowIconified(WindowEvent e) {
509- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
510526
511527 }
512528
513529 public void windowOpened(WindowEvent e) {
514- // TODO ?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス黷ス?ス?ス?ス\?スb?スh?スE?スX?ス^?スu
515530
516531 }
517532
518533 public Mob getSelf(){
519- return viewPanel.getSelf();
534+ return viewPanel.objectManager.getSelf();
520535 }
521536
522- /* (?ス?ス Javadoc)
523- * @see jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime#startLogTimeMove()
524- */
525537 public void startLogTimeMove(){
526538 if(!isTime()){
527539 return;
@@ -530,9 +542,6 @@
530542 timeMove = System.nanoTime();
531543 }
532544
533- /* (?ス?ス Javadoc)
534- * @see jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime#startLogTime()
535- */
536545 public void startLogTime(){
537546 if(!isTime()){
538547 return;
@@ -541,9 +550,6 @@
541550 time = System.nanoTime();
542551 }
543552
544- /* (?ス?ス Javadoc)
545- * @see jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime#logTimeMove()
546- */
547553 public void logTimeMove(){
548554 if(!isTime()){
549555 return;
@@ -557,9 +563,6 @@
557563 timeMove = 0;
558564 }
559565
560- /* (?ス?ス Javadoc)
561- * @see jp.sourceforge.mmosf.client.sample.jme.LoggingResponseTime#logTime(jp.sourceforge.mmosf.server.packet.Packet)
562- */
563566 public void logTime(Packet packet) throws PacketFormatException{
564567 if(!isTime()){
565568 return;
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/QuarterViewPanel.java (revision 101)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/jme/QuarterViewPanel.java (revision 102)
@@ -32,30 +32,17 @@
3232
3333 package jp.sourceforge.mmosf.client.sample.jme;
3434
35-import java.awt.Point;
3635 import java.awt.event.MouseEvent;
3736 import java.awt.event.MouseListener;
3837 import java.awt.event.MouseMotionListener;
39-import java.net.URL;
40-import java.util.ArrayList;
4138 import java.util.Comparator;
4239 import java.util.HashMap;
43-import java.util.Iterator;
44-import java.util.LinkedList;
45-import java.util.List;
46-import java.util.Map;
47-import java.util.Queue;
48-import java.util.Map.Entry;
4940 import java.util.concurrent.ConcurrentLinkedQueue;
5041
51-import jp.sourceforge.mmosf.admin.LocalMonitor;
5242 import jp.sourceforge.mmosf.server.level.GeomapData;
53-import jp.sourceforge.mmosf.server.level.MobFactory;
54-import jp.sourceforge.mmosf.server.object.Direction;
5543 import jp.sourceforge.mmosf.server.object.Mob;
5644 import jp.sourceforge.mmosf.server.object.Moving;
5745 import jp.sourceforge.mmosf.server.object.MovingVector;
58-import jp.sourceforge.mmosf.server.object.ObjectStatus;
5946 import jp.sourceforge.mmosf.server.object.Position;
6047 import jp.sourceforge.mmosf.server.object.Vector;
6148 import jp.sourceforge.mmosf.server.packet.MovePacket;
@@ -64,30 +51,10 @@
6451 import org.apache.commons.logging.Log;
6552 import org.apache.commons.logging.LogFactory;
6653
67-import com.jme.animation.SpatialTransformer;
68-import com.jme.bounding.BoundingBox;
69-import com.jme.image.Texture;
70-import com.jme.intersection.BoundingPickResults;
71-import com.jme.intersection.PickResults;
72-import com.jme.math.FastMath;
73-import com.jme.math.Quaternion;
74-import com.jme.math.Ray;
7554 import com.jme.math.Vector2f;
7655 import com.jme.math.Vector3f;
7756 import com.jme.renderer.Camera;
78-import com.jme.renderer.ColorRGBA;
79-import com.jme.scene.Controller;
80-import com.jme.scene.Node;
81-import com.jme.scene.SharedMesh;
82-import com.jme.scene.Spatial;
83-import com.jme.scene.TriMesh;
8457 import com.jme.scene.shape.Arrow;
85-import com.jme.scene.state.TextureState;
86-import com.jme.system.DisplaySystem;
87-import com.jme.system.SystemProvider;
88-import com.jme.system.lwjgl.LWJGLDisplaySystem;
89-import com.jme.util.TextureManager;
90-import com.jme.util.geom.BufferUtils;
9158
9259 public class QuarterViewPanel extends SampleJMEPanel implements MouseListener, MouseMotionListener{
9360 /**
@@ -95,84 +62,17 @@
9562 */
9663 private static final long serialVersionUID = 1L;
9764
98- private static final Log log = LogFactory.getLog(QuarterViewPanel.class);
65+ protected static final Log log = LogFactory.getLog(QuarterViewPanel.class);
9966
100- public class ObjectManager{
67+ public static class ViewSetting{
68+ public static final float angle = 1.0f;//0.1f;
69+ public static final float length = -80.0f/angle;
70+ public static final float fsize = 0.2f;
10171
102- public void update(Mob self, List<Mob> listUpdate, List<Mob> listDelete){
103- /*
104- if(oldSelf == null){
105- oldSelf = this.self = self;
106- }
107- */
108- if(true){// || !this.self.moving.getPosition().equals(self.moving.getPosition())){
109- setOldSelf(getSelf());
110- setSelf(self);
111- // System.out.println("update:"+self);
112- if(getFrame() != null){
113- getFrame().logTimeMove();
114- }
115- }
116- /*
117- if(oldSelf != null){
118- oldSelf = self;
119- }
120- */
121- // this.listMob = listUpdate;
122- getListMob().addAll(listUpdate);
123-
124- Iterator<Mob> it = listDelete.iterator();
125- while (it.hasNext()) {
126- Mob mob = (Mob) it.next();
127- // try{
128- // System.out.println("delete "+mob.getId());
129- getListDeleteMob().add(mob);
130- // }catch(InterruptedException e){
131-
132- // }
133- }
134- }
135-
13672 }
13773
138- private final ObjectManager objectManager;
139-
14074 public GeomapData map;
141- private Node nodeMap;
142- protected Node nodeChar;
143- private Node nodeRotate1;
144- private Node nodeRotate2;
145- protected Node nodeOffset;
14675
147- private Mob self;
148- private Mob oldSelf;
149-// protected List<Mob> listMob;
150- private final Queue<Mob> listMob;
151-// protected List<Mob> listMobStock;
152-// protected BlockingQueue<Mob> listDeleteMob;
153- private final Queue<Mob> listDeleteMob;
154- private float fsize = 0.2f;
155-// private Vector3f min = new Vector3f(0,0,0);
156-// private Vector3f max = new Vector3f(fsize,fsize,fsize);
157-// private Vector3f maxBoard = new Vector3f(fsize,fsize/4,fsize);
158-// private Node myChar;
159-// private TriMesh myChar1;
160- protected ModelObject myChar2;
161- protected ModelObject myChar3;
162- private float angle = 1.0f;//0.1f;
163- private float length = -80.0f/angle;
164-// private int intStataus = false;
165- protected java.awt.Point p;
166-
167-// protected Map<Integer, Spatial> mapMobModel;
168-// protected Map<Spatial, Integer> mapMobIndex;
169- protected Map<Spatial, Mob> mapSpatialMob;
170- protected Map<Integer, ModelObject> mapMobModel;
171-
172-// protected Integer selectedId;
173- protected Mob selectedMob = null;
174- protected TriMesh cursol;
175-
17676 private SampleClientFrame frame;
17777
17878 // private Vector selfVector;
@@ -180,10 +80,8 @@
18080 // private Position selfPosition;
18181 // private Vector selfDirection;
18282
183- private Position oldPos;
83+ protected static final int updateCount = 100;
18484
185- private static final int updateCount = 100;
186-
18785 // private LightState ls;
18886
18987 // private TriMesh model;
@@ -190,18 +88,11 @@
19088
19189 public QuarterViewPanel() {
19290 // initGround();
193- listDeleteMob = new ConcurrentLinkedQueue<Mob>();
194- listMob = new ConcurrentLinkedQueue<Mob>();
195- objectManager = new ObjectManager();
19691 }
19792
19893 public QuarterViewPanel(GeomapData data) {
199- // TODO �����������ꂽ�R���X�g���N�^�[�E�X�^�u
20094 setMap(data);
20195 // initGround();
202- listDeleteMob = new ConcurrentLinkedQueue<Mob>();
203- listMob = new ConcurrentLinkedQueue<Mob>();
204- objectManager = new ObjectManager();
20596 }
20697
20798 public void setFrame(SampleClientFrame frame){
@@ -210,739 +101,44 @@
210101
211102 @Override
212103 protected void simpleSetup2() {
213- // TODO �����������ꂽ���\�b�h�E�X�^�u
214- getRootNode().detachAllChildren();
215-
216-// myChar = new Node();
217- nodeChar = new Node();
218- nodeOffset = new Node();
219- nodeRotate1 = new Node();
220- nodeRotate2 = new Node();
221-
222- initGround();
223-
224104 AnimationModelObject.setDisplaySystem(display);
225105
226- initMyChar();
227-
228- cursol = new Arrow("cursol",1*fsize,0.5f*fsize);
229-// cursol = new Disk("cursol",8,8,fsize);
230-// cursol = new Torus("cursol",16,4,fsize/2f/3f,fsize/2f);
231- Quaternion q = new Quaternion();
232- q.fromAngles(0, 0/*FastMath.HALF_PI*/, FastMath.PI);
233- cursol.setLocalRotation(q);
234- cursol.setDefaultColor(ColorRGBA.red);
235- cursol.setTextureCombineMode(TextureState.OFF);
236-
237-// nodeChar.attachChild(load());
238-
239- nodeMap.attachChild(nodeChar);
240-
241- nodeOffset.attachChild(nodeMap);
242-// nodeOffset.attachChild(nodeChar);
243- nodeRotate1.attachChild(nodeOffset);
244- nodeRotate2.attachChild(nodeRotate1);
245-// getRootNode().attachChild(nodeRotate2);
246-/*
247- getCamea().setFrustumPerspective(1.0f,//45.0f,
248- (float)comp.getWidth()/(float)comp.getHeight(), 1,1000);
249- getRootNode().setLocalTranslation(0,0,-250);//-80);
250-
251- setAngle();
252-*/
253106 getCamea().setParallelProjection(true);
254107 resizeCamera(getCamea(), /*getWidth()*/comp.getWidth(),/*getHeight()*/ comp.getHeight());
255108 // getCamea().setFrustumPerspective(angle, (float)comp.getWidth()/(float)comp.getHeight(), 1, 1000);
256109
257- setAngle();
258- getRootNode().setLocalTranslation(0,0,length);//-80);
259-
260- getRootNode().attachChild(nodeRotate2);
261-
262-// self = new Mob(-20,-20,'A');
263-
264-// addMouseListener(this);
265110 comp.addMouseListener(this);
266111
267-// mapMobModel = new HashMap<Integer, Spatial>();
268-// mapMobIndex = new HashMap<Spatial, Integer>();
269-/*
270- PointLight l=new PointLight();
271-// DirectionalLight l = new DirectionalLight();
272- l.setLocation(new Vector3f(-100,100,-100));
273-// l.setDirection(new Vector3f(-0.4f,-1.0f,-0.4f));
274- l.setDiffuse(ColorRGBA.white);
275-// l.setShadowCaster(true);
276- l.setEnabled(true);
277- ls = display.getRenderer().createLightState();
278- ls.attach(l);
279- ls.setEnabled(true);
280-
281- getRootNode().setRenderState(ls);
282-//*/
283-
284- mapSpatialMob = new HashMap<Spatial, Mob>();
285- mapMobModel = new HashMap<Integer, ModelObject>();
286-
287112 }
288113
289- protected void initMyChar() {
290- // myChar1 = new Box("self",min,maxBoard);
291- // myChar.attachChild(new Box("self",min,max));
292- // TriMesh my = getMobMesh("self");
293- // myChar2 = getMobMesh("self");
294- // myChar2 = getMobMesh("self",fileMan,0);
295- // myChar3 = getMobMesh("self",fileMan,10);
296- // myChar2 = getAnimatedMob("self",fileMan,fileManTex,0);
297- myChar2 = ModelObjectFactory.createPC("self",fsize,0);
298- // myChar3 = getAnimatedMob("self",fileMan,null,10);
299- // myChar3 = ModelObjectFactory.createMan("self2",fsize,10);
300- myChar3 = ModelObjectFactory.createPC("self2",fsize,10);
301- // BoundingBox bb = new BoundingBox();
302- // myChar1.setModelBound(bb);
303- // myChar1.updateModelBound();
304-
305- // myChar2.getMesh().setDefaultColor(ColorRGBA.lightGray);
306- myChar3.getMesh().setDefaultColor(ColorRGBA.magenta);
307- // myChar1.setLocalTranslation(0,0,0);
308- myChar2.getNodeTranslation().setLocalTranslation(0,0,0);
309- myChar3.getNodeTranslation().setLocalTranslation(0,0,0);
310- // myChar.attachChild(my);
311-
312- // nodeChar.attachChild(selfSt);
313- // nodeChar.attachChild(myChar1);
314- nodeChar.attachChild(myChar2.getObject());
315- // nodeChar.attachChild(myChar3.getObject());
114+ protected Vector3f createVector3f(int x, int z) {
115+ return new Vector3f((x - map.getXLimit()/2)*ViewSetting.fsize,0,
116+ (z - map.getZLimit()/2)*ViewSetting.fsize);
316117 }
317-
318- private void setAngle() {
319- Quaternion rote1 = new Quaternion();
320- rote1.fromAngles(FastMath.HALF_PI/4/*0.5f*/, 0f, 0f);
321-// rote1.fromAngles(FastMath.HALF_PI/*0.5f*/, 0f, 0f);
322- nodeRotate2.setLocalRotation(rote1);
323- Quaternion rote2 = new Quaternion();
324-// double qp = 0.8;//0.7853981633974483;//java.lang.Math.PI / 4d;
325-// rote2.fromAngles(0f,(float)qp, 0f);
326- rote2.fromAngles(0f,FastMath.HALF_PI/2.0f/*0.5f*/, 0f);
327- nodeRotate1.setLocalRotation(rote2);
328- }
329-
330- public void initGround() {
331-/*
332- try{
333- System.out.println(System.currentTimeMillis());
334- URL url = QuarterViewPanel.class.getClassLoader().getResource("jp/sourceforge/mmosf/client/sample/jme/test.data");
335-// File file = new File(url.toURI());
336-
337-// File file = new File("c:\\test.data");
338- if(true){
339-// if(file.exists()){
340- BinaryImporter im = BinaryImporter.getInstance();
341- try{
342- Savable s = im.load(url);
343-// Savable s = im.load(file);
344- if(s instanceof Node){
345- nodeMap = (Node)s;
346- // nodeMap = new Node();
347- System.out.println(System.currentTimeMillis());
348- return;
349- }
350- }catch(IOException e){
351- log.error("error in init ground, ",e);
352- }
353- }else{
354- log.error("file not found goround.");
355- }
356- }catch(Exception e){
357- log.error("error in init ground, ",e);
358- }
359-//*/
360-//*
361-
362-// BoundingBox bb = new BoundingBox();
363- System.out.println(System.currentTimeMillis());
364-
365- TriMesh src_quad = getQuad("src_quad",fsize,fsize);
366- src_quad.setDefaultColor(ColorRGBA.white);
367-// src_quad.setRandomColors();
368- URL fileGlassTex = QuarterViewPanel.class.getClassLoader().getResource("jp/sourceforge/mmosf/client/sample/jme/glass.jpg");
369- TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
370- Texture tx = TextureManager.loadTexture(fileGlassTex);
371- ts.setEnabled(true);
372- ts.setTexture(tx);
373- src_quad.setRenderState(ts);
374- src_quad.setTextureCombineMode(TextureState.REPLACE);
375-
376-// Box src_box = new Box("src_box",min,max);
377-// src_box.setRandomColors();
378- nodeMap = new Node();
379- for(int i=0;i<map.getZLimit();i++){
380- for(int j=0;j<map.getXLimit();j++){
381-
382-// if(map.map[i][j] != '�w'){
383- if(true){
384-// Box box = new Box(i+","+j,min,max);
385-// Quad box = new Quad(i+","+j,max.x,max.y);
386-// TriMesh box = getQuad(i+","+j,max.x,max.y);
387- TriMesh box = new SharedMesh(i+","+j,src_quad);
388-// TriMesh box = src_quad;
389-
390-// box.setModelBound(bb);
391- box.setModelBound(new BoundingBox());
392- Vector3f vec = createVector3f(j, i);
393- vec.y = 0f;//-1*fsize;
394- box.setLocalTranslation(vec);
395-// Quaternion q = new Quaternion();
396-// q.fromAngles(-FastMath.HALF_PI, 0, 0);
397-// box.setLocalRotation(q);
398-// box.setRandomColors();
399- nodeMap.attachChild(box);
400- }else{
401-//
402-// Box box = new Box(i+","+j,min,max);
403-//*
404-// TriMesh box = new SharedMesh(i+","+j,src_box);
405- TriMesh box = ModelObjectFactory.createWall(i+","+j, fsize, MobFactory.VISUAL_WALL,ObjectStatus.SELECT_DISABLE).getMesh();
406- box.setModelBound(new BoundingBox());
407- box.setLocalTranslation(createVector3f(j, i));
408-// box.setRandomColors();
409- nodeMap.attachChild(box);
410-//*/
411- }
412- }
413- }
414-// System.out.println(System.currentTimeMillis());
415-/*
416- BinaryExporter ex = BinaryExporter.getInstance();
417- try{
418- File file = new File("c:\\test.data");
419- ex.save(nodeMap, file);
420- }catch(IOException e){
421- System.out.println(e.toString());
422- }
423-//*/
424- }
425-//*
426- TriMesh getQuad(String name,float x, float z){
427- TriMesh m=new TriMesh("Quad");
428- // Vertex positions for the mesh
429- Vector3f[] vertexes={
430- new Vector3f(0,0,0),
431- new Vector3f(x,0,0),
432- new Vector3f(0,0,z),
433- new Vector3f(x,0,z)
434- };
435- // Normal directions for each vertex position
436- Vector3f[] normals={
437- new Vector3f(0,-1,0),
438- new Vector3f(0,-1,0),
439- new Vector3f(0,-1,0),
440- new Vector3f(0,-1,0)
441- };
442- // Color for each vertex position
443- ColorRGBA[] colors={
444-// new ColorRGBA(1,0,0,1),
445-// new ColorRGBA(1,0,0,1),
446-// new ColorRGBA(0,1,0,1),
447-// new ColorRGBA(0,1,0,1)
448- ColorRGBA.white,
449- ColorRGBA.white,
450- ColorRGBA.white,
451- ColorRGBA.white
452- };
453- // Texture Coordinates for each position
454- Vector2f[] texCoords={
455- new Vector2f(0,0),
456- new Vector2f(1,0),
457- new Vector2f(0,1),
458- new Vector2f(1,1)
459- };
460- // The indexes of Vertex/Normal/Color/TexCoord sets. Every 3
461- // makes a triangle.
462- int[] indexes={
463- 0,1,2,1,2,3
464-// 0,1,3,0,2,3
465- };
466- // Feed the information to the TriMesh
467- m.reconstruct(BufferUtils.createFloatBuffer(vertexes),BufferUtils.createFloatBuffer(normals),
468- BufferUtils.createFloatBuffer(colors),BufferUtils.createFloatBuffer(texCoords),
469- BufferUtils.createIntBuffer(indexes));
470-
471- return m;
472- }
473- //*/
474118
475- private Vector3f createVector3f(int x, int z) {
476- return new Vector3f((x - map.getXLimit()/2)*fsize,0,
477- (z - map.getZLimit()/2)*fsize);
119+ protected Vector3f createVector3f2(Position pos) {
120+// return new Vector3f((pos.getX() - map.getXLimit()/2)*ViewSetting.fsize,pos.getY(),
121+// (pos.getZ() - map.getZLimit()/2)*ViewSetting.fsize);
122+// float x = (float)((pos.getdX() - (map.getXLimit()/2))*ViewSetting.fsize);
123+// float z = (float)((pos.getdZ() - (map.getZLimit()/2))*ViewSetting.fsize);
124+ double x = (pos.getdX() - (map.getXLimit()/2))*ViewSetting.fsize;
125+ double z = (pos.getdZ() - (map.getZLimit()/2))*ViewSetting.fsize;
126+// double x = pos.getdX()*ViewSetting.fsize - (map.getXLimit()*ViewSetting.fsize)/2d;
127+// double z = pos.getdZ()*ViewSetting.fsize - (map.getZLimit()*ViewSetting.fsize)/2d;
128+ return new Vector3f((float)x, (float)pos.getdY()*ViewSetting.fsize, (float)z);
478129 }
479130
480131 protected Vector3f createVector3f(Position pos) {
481- return new Vector3f((pos.getX() - map.getXLimit()/2)*fsize,pos.getY(),
482- (pos.getZ() - map.getZLimit()/2)*fsize);
132+ return new Vector3f((pos.getX() - map.getXLimit()/2)*ViewSetting.fsize,pos.getY(),
133+ (pos.getZ() - map.getZLimit()/2)*ViewSetting.fsize);
134+// return new Vector3f((float)((pos.getdX() - map.getXLimit()/2)*ViewSetting.fsize),
135+// (float)pos.getdY(),
136+// (float)((pos.getdZ() - map.getZLimit()/2)*ViewSetting.fsize));
483137 }
484-/*
485- private Vector3f createVector3f2(float x, float z) {
486- return new Vector3f((x - (float)(map.getMapWidth()/2))*fsize,0,
487- (z - (float)(map.getMapHeight()/2))*fsize);
488- }
489-//*/
490- @Override
491- protected void simpleUpdate2() {
492- try{
493-// if(self != null){
494- moveSelf2();
495-// }
496- //*
497- if(getListMob() != null){
498- moveMob();
499- }
500-
501-// if(listDeleteMob.size() > 0){
502- for(int i=0;i<20 /*&&listDeleteMob.size()>0*/;i++) {
503-// while(listDeleteMob.size()>0){
504- Mob mob = getListDeleteMob().poll();
505- if(mob == null){
506- break;
507- }
508- ModelObject obj = mapMobModel.get(mob.getId());
509- if(obj == null){
510- continue;
511- }
512-
513- nodeChar.detachChild(obj.getObject());
514- mapMobModel.remove(Integer.valueOf(mob.getId()));
515- mapSpatialMob.remove(obj.getObject());
516- obj.clear();
517- }
518-// }
519- // getRootNode().setLocalTranslation(0,0,length);//-80);
520- // setAngle();
521-//*
522- if(p != null){
523- selectMob(p);
524- p = null;
525- }
526-//*/
527- dispCursol();
528-
529- getRootNode().updateRenderState();
530- }catch(Exception e){
531- log.error("error in simpleUpdate2,",e);
532- }
533-
534- }
535-
536- protected void selectMob(Point pt) {
537- Spatial sp = getSelectedSpatial(pt);
538-
539- if(sp != null){
540-/*
541- MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
542-/*
543- ms.setShininess(100f);
544- ms.setEnabled(true);
545- ms.setAmbient(ColorRGBA.lightGray);
546-// ms.setEmissive(ColorRGBA.white);
547- ms.setMaterialFace(MaterialState.MF_FRONT_AND_BACK);
548- sp.setRenderState(ms);
549- sp.updateRenderState();
550-//*/
551-/*
552- if (sp instanceof TriMesh) {
553- TriMesh mesh = (TriMesh) sp;
554- mesh.setSolidColor(ColorRGBA.yellow);
555- }
556-*/
557-// selectedId = mapMobIndex.get(sp);
558-// selectedMob = getSelectedMob();
559-// sp.getParent().attachChild(cursol);
560- selectedMob = mapSpatialMob.get(sp);
561- // dispCursol();
562- if(getFrame() != null){
563- getFrame().selectMob(selectedMob);
564- }
565- }
566- }
567-
568- protected Spatial getSelectedSpatial(Point pt) {
569- Spatial sp = null;
570-
571- Vector2f screenPos = new Vector2f();
572- // Get the position that the mouse is pointing to
573- screenPos.set(pt.x, pt.y);
574- // Get the world location of that X,Y value
575- SystemProvider systemProvider = LWJGLDisplaySystem.getSystemProvider();
576- DisplaySystem displaySystem = systemProvider.getDisplaySystem();
577- Ray mouseRay = displaySystem.getPickRay(screenPos, true, null);
578- PickResults pr = new BoundingPickResults();;
579- pr.clear();
580- getRootNode().findPick(mouseRay, pr);
581-
582- for (int i = 0; i < pr.getNumber(); i++) {
583-// pr.getPickData(i).getTargetMesh().setRandomColors();
584- sp = pr.getPickData(i).getTargetMesh().getParentGeom();
585- }
586- return sp;
587- }
588-
589- protected void moveMob() {
590- for(int i=0;i<updateCount /*&& /*it.hasNext()*/;i++) {
591-// Mob mob = it.next();
592-// it.remove();
593- Mob mob = getListMob().poll();
594- if(mob == null){
595- break;
596- }
597-
598- if(mob.getId() == getSelf().getId()){
599- continue;
600- }
601-// Spatial box = nodeChar.getChild(Integer.toString(mob.getId()));
602- ModelObject obj = mapMobModel.get(mob.getId());
603- if(obj != null){
604-//*
605-// if(mob.vis.getVtype() == MobFactory.VISUAL_DOOR_OPEN){
606-// System.out.println("open");
607-// }
608-
609- if(obj.getVisual() != mob.vis.getVtype()){
610- nodeChar.detachChild(obj.getObject());
611- mapMobModel.remove(Integer.valueOf(mob.getId()));
612- mapSpatialMob.remove(obj.getObject());
613-
614- obj = null;
615- }
616-//*/
617- }
618-
619- if(obj == null){
620-// Box box2 = new Box(Integer.toString(mob.getId()),min,max);
621-// box2.setModelBound(bb);
622-// box2.updateModelBound();
623-// box2.setLocalTranslation(0,0,0);
624- ModelObject obj2 = getModelObject(mob);
625-
626- nodeChar.attachChild(obj2.getObject());
627-
628-// obj2.getMesh().updateRenderState();
629-
630- obj = obj2;
631-// mapMobModel.put(Integer.valueOf(mob.getId()), box2);
632-// mapMobIndex.put(box2, Integer.valueOf(mob.getId()));
633- mapSpatialMob.put(obj2.getMesh(),mob);
634- mapMobModel.put(Integer.valueOf(mob.getId()), obj2);
635- }
636-// box.setLocalTranslation(createVector3f(mob.getPos().getX(),mob.getPos().getY()));
637-// obj.setDirection(mob);
638-// obj.setTranslation(createVector3f(mob));
639- setAnimation2(obj,mob.moving.getPosition(), null, mob.moving.getVector(), mob.moving.getSpeed(), mob.moving.getDirection(), false, 3.8f);
640-// myChar3.setDirection(mob);
641-// myChar3.setTranslation(createVector3f(mob));
642-
643- mapSpatialMob.get(obj.getMesh()).moving.setPosition(mob.moving.getPosition());
644- }
645-
646-
647- }
648-
649- private ModelObject getModelObject(Mob mob) {
650- ModelObject obj2 = null;// = getMobMesh(Integer.toString(mob.getId()),fileMan);
651- ColorRGBA color = null;//ColorRGBA.red;
652- AnimationModelObject.setDisplaySystem(display);
653- switch(mob.vis.getVtype()){
654- case 0://NPC
655-// color = ColorRGBA.blue;
656-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileMan,mob.vis.getVtype());
657-// obj2 = getAnimatedMob(Integer.toString(mob.getId()),fileMan,fileManTex,mob.vis.getVtype());
658- obj2 = ModelObjectFactory.createNPC(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
659- break;//other PC
660- case 1:
661- color = ColorRGBA.red;
662-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileMan,mob.vis.getVtype());
663-// obj2 = getAnimatedMob(Integer.toString(mob.getId()),fileMan,fileManTex,mob.vis.getVtype());
664- obj2 = ModelObjectFactory.createPC(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
665- break;
666- case 2://tree
667- color = ColorRGBA.brown;
668-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileTree,mob.vis.getVtype());
669- obj2 = ModelObjectFactory.createTree(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
670- break;
671- case 3://fire
672- color = ColorRGBA.red;
673- color.a = 0.1f;
674-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileFire,mob.vis.getVtype());
675- obj2 = ModelObjectFactory.createFire(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
676- break;
677- case 4://QuestNPC
678-// color = ColorRGBA.green;
679-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileMan,mob.vis.getVtype());
680-// obj2 = getAnimatedMob(Integer.toString(mob.getId()),fileMan,fileManTex,mob.vis.getVtype());
681- obj2 = ModelObjectFactory.createQNPC(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
682- break;//other PC
683- case 5://Closed Door
684- color = ColorRGBA.darkGray;
685-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileDoorClose,mob.vis.getVtype());
686- obj2 = ModelObjectFactory.createDoorClose(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
687- break;//other PC
688- case 6://Opened Door
689- color = ColorRGBA.darkGray;
690-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileDoorOpen,mob.vis.getVtype());
691- obj2 = ModelObjectFactory.createDoorOpen(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
692- break;//other PC
693- case 7://Wall
694- color = ColorRGBA.darkGray;
695-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileDoorOpen,mob.vis.getVtype());
696-// obj2 = ModelObjectFactory.createDoorOpen(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
697- obj2 = ModelObjectFactory.createWall(Integer.toString(mob.getId()),fsize,mob.vis.getVtype(),mob.getObjectStatus().getSelectable());
698- break;//other PC
699- default:
700- color = ColorRGBA.randomColor();
701-// obj2 = getMobMesh(Integer.toString(mob.getId()),fileMan,mob.vis.getVtype());
702-// obj2 = getAnimatedMob(Integer.toString(mob.getId()),fileMan,fileManTex,mob.vis.getVtype());
703- obj2 = ModelObjectFactory.createPC(Integer.toString(mob.getId()),fsize,mob.vis.getVtype());
704- }
705-
706- if(color != null){
707-// obj2.getMesh().setDefaultColor(color);
708- }
709-
710-// obj2.getObject().updateRenderState();
711-// impl.doRender();
712-
713- return obj2;
714- }
715-
716138 private Vector3f createVector3f(Mob mob) {
717139 // return createVector3f(mob.moving.getPosition().getX(),mob.moving.getPosition().getZ());
718140 return createVector3f(mob.moving.getPosition());
719141 }
720- protected void moveSelf2() {
721-// Vector3f v;
722-// v = createVector3f(self);
723- if(getSelf() != null){
724- float frame = 1.8f;//1.9f;//2.4f;
725- setAnimation2(myChar2,getSelf().moving.getPosition(), oldPos, getSelf().moving.getVector(), getSelf().moving.getSpeed(), getSelf().moving.getDirection(), true, frame);
726-// setAnimation2(myChar2,self.moving.getPosition(), oldPos, Vector.ZERO, self.moving.getSpeed(), self.moving.getDirection(), true, frame);
727-
728- setOldSelf(getSelf());
729-
730-// myChar1.setLocalTranslation(v);
731-// myChar2.getNodeTranslation().setLocalTranslation(v);
732-// myChar3.getNodeTranslation().setLocalTranslation(createVector3f(self));
733- }
734-
735- }
736-
737- protected void setAnimation2(ModelObject obj,Position pos,Position oldPos,Vector vec,double speed,Direction direction, boolean isScroll,float frame){
738-// if(!vec.isZero()){
739-// System.out.println("aaa");
740-// }
741-
742-// frame = 2.4f;//0.6f;//1.9f;
743-
744- if(speed > 0){
745- frame = 3.6f / (float)speed;
746- }
747-
748- if(oldPos == null){
749- oldPos = pos;
750- }
751-/*
752- if(obj instanceof AnimationModelObject){
753- AnimationModelObject amo = (AnimationModelObject)obj;
754-// if(now.distance(end) < fsize * 0.1f){
755-// if(now.distance(end)/fsize*2f < 0.1f){
756-// if(vec.isZero()){
757- if(vec.isZero() && oldPos.equals(pos)){
758- amo.stopAnimation();
759- }else{
760- amo.startAnimation();
761- }
762- }
763-//*/
764- if(!vec.isZero() && oldPos.equals(pos)){
765- if(!isAnimateEnd(obj.getNodeTranslation())){
766- return;
767- }
768-
769- Vector3f now = getNowPosition(obj.getNodeTranslation());
770- if(now == null){
771- now = createVector3f(pos);
772- }
773-
774- Vector3f animeEnd = getEndPosition(obj.getNodeTranslation());
775- if(animeEnd == null){
776- animeEnd = createVector3f(pos);
777- }
778-
779-// frame = adjustAnimeSpeed(frame, now, pos, vec);
780- if(obj instanceof AnimationModelObject){
781- AnimationModelObject amo = (AnimationModelObject)obj;
782-// if(now.distance(end) < fsize * 0.1f){
783-// if(now.distance(end)/fsize*2f < 0.1f){
784- amo.startAnimation();
785- LocalMonitor.getMonitor().log("start animation");
786- }
787-
788-// Vector next = vec.getBaseVector();
789- Vector next = vec.getDirection().getVector();
790-// Vector next2 = vec.getDirection2();
791-// if(!next.equals(next2)){
792-// System.out.println("1)please test:"+vec);
793-// }
794- Vector3f end = animeEnd.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
795-// calcGap(myChar2.getNodeTranslation(), next);
796- if(isScroll){
797- moveSmooth(nodeOffset, now.negate(), end.negate(),frame);
798-// System.out.println("1:"+direction.toString());
799- }
800- moveSmooth(obj.getNodeTranslation(),now,end,frame);
801- obj.setDirection(direction);
802- }else{
803-
804- Vector3f now = getNowPosition(obj.getNodeTranslation());
805- if(now == null){
806- now = createVector3f(pos);
807- }
808-
809- Vector3f newStart = createVector3f(pos);
810-
811-// Vector next = vec.getBaseVector();
812- Vector next = vec.getDirection().getVector();
813-// Vector next2 = vec.getDirection2();
814-// if(!next.equals(next2)){
815-// System.out.println("2)please test:"+vec);
816-// }
817- Vector3f end = newStart.add(new Vector3f((float)next.getdX(),0,(float) next.getdZ()));
818-
819-// if(now.distance(newStart) >= fsize){
820-// end.add(now.subtract(newStart));
821-// }
822-
823- if(vec.isZero()){
824- frame = adjustAnimeSpeed(frame, now.distance(end));
825- }else{
826-/*
827- Vector3f start = createVector3f(pos.getX(), pos.getY());
828- if (start.distance(now) > fsize*2f){
829- LocalMonitor.getMonitor().log("before adjust:start="+start+";now="+now+":end="+end);
830- Vector3f adj = now.subtract(start);
831- end = end.add(adj);
832- LocalMonitor.getMonitor().log("after adjust:"+end);
833- }
834-*/
835- }
836-
837- if(obj instanceof AnimationModelObject){
838- AnimationModelObject amo = (AnimationModelObject)obj;
839-// if(now.distance(end) < fsize * 0.1f){
840-// if(now.distance(end)/fsize*2f < 0.1f){
841- if(frame <= 0.1f){
842- amo.stopAnimation();
843-// LocalMonitor.getMonitor().log("stop animation");
844- }else{
845- amo.startAnimation();
846-// LocalMonitor.getMonitor().log("start animation");
847- }
848- }
849-
850- if(isScroll){
851- moveSmooth(nodeOffset, now.negate(), end.negate(),frame);
852-// System.out.println("2:"+direction.toString());
853- }
854-/*
855- if(obj.getVisual() == 7){
856- if(!now.equals(end)){
857- System.out.println("bad animation.");
858- }
859- }
860-*/
861- moveSmooth(obj.getNodeTranslation(),now,end,frame);
862- obj.setDirection(direction);
863- this.oldPos = pos;
864- }
865-
866-
867- }
868-
869- private float adjustAnimeSpeed(float frame, float distance) {
870- float adjust = distance / (fsize*2f);
871- if(adjust < frame){
872- frame = adjust;
873- }else{
874-// System.out.println("over");
875- }
876-
877- if(frame < 0.1f){
878- frame = 0.1f;
879- }
880-// System.out.println("frame:"+frame);
881-/*
882- if(distance <= fsize){
883- frame = 0.1f;
884- }else if(distance <= fsize*2){
885- frame = 1f;
886- }
887-*/
888- return frame;
889- }
890-
891- private void moveSmooth(Spatial target, Vector3f start, Vector3f end, float speed) {
892-// target.clearControllers();
893-// if(end.equals(getEndPosition(target))){
894-// return ;
895-// }
896-
897- ArrayList<Controller> list = target.getControllers();
898- Iterator<Controller> it = list.iterator();
899- while (it.hasNext()) {
900- Controller controller = (Controller) it.next();
901- if(controller instanceof SpatialTransformer){
902-// target.removeController(controller);
903- it.remove();
904- }
905- }
906-
907-
908- SpatialTransformer st= new SpatialTransformer(1);
909-
910- st.setObject(target, 0,-1);
911- st.setPosition(0,0,start);
912-// st.setPosition(0,0.5f,end);
913- st.setPosition(0,speed,end);
914- //st.setSpeed(0.1f);
915- st.interpolateMissing();
916-
917- target.addController(st);
918- }
919-
920- protected void dispCursol() {
921- ModelObject modelObject = null;
922- if(selectedMob != null){
923- modelObject = mapMobModel.get(selectedMob.getId());
924- }
925-
926- if(modelObject != null){
927- Node selectedObject = modelObject.getNodeTranslation();
928- if(cursol.getParent() != selectedObject) {
929- selectedObject.attachChild(cursol);
930- cursol.updateRenderState();
931- Vector3f v = new Vector3f();
932- v.x += 0.5f*fsize;
933- v.y += 4f*fsize;
934- v.z += 0.5f*fsize;
935- cursol.setLocalTranslation(v);
936- }
937- }else{
938- if(cursol.getParent() != null){
939- cursol.getParent().detachChild(cursol);
940- }
941-
942- }
943-
944- }
945-
946142 protected void resizeCamera(Camera camea, int width, int height) {
947143 Vector2f rect = getCameraRect(width, height);
948144
@@ -957,8 +153,8 @@
957153 Vector2f rect = new Vector2f();
958154 float aspect = 640.0f / 480.0f;
959155
960- float width2 = fsize*20;//comp.getWidth()/12;
961- float height2 = fsize*20;//comp.getHeight()/12;
156+ float width2 = ViewSetting.fsize*20;//comp.getWidth()/12;
157+ float height2 = ViewSetting.fsize*20;//comp.getHeight()/12;
962158 if(width/height < aspect){
963159 // width/height = width2/height2;
964160 width2 = (width/height) * height2;
@@ -975,10 +171,6 @@
975171 this.map = map;
976172 }
977173
978- public void update(Mob self, List<Mob> listUpdate, List<Mob> listDelete){
979- this.objectManager.update(self, listUpdate, listDelete);
980- }
981-
982174 protected int getOffset(int pos, int viewSize, int mapSize) {
983175 int Offset = pos - viewSize/2;
984176 if(Offset < 0){
@@ -990,41 +182,24 @@
990182 }
991183
992184 public void mouseClicked(MouseEvent e) {
993- p = e.getPoint();
185+// p = e.getPoint();
994186 }
995187
996188 public void mouseEntered(MouseEvent e) {
997- // TODO �����������ꂽ���\�b�h�E�X�^�u
998189
999190 }
1000191
1001192 public void mouseExited(MouseEvent e) {
1002- // TODO �����������ꂽ���\�b�h�E�X�^�u
1003193
1004194 }
1005195
1006196 public void mousePressed(MouseEvent e) {
1007- // TODO �����������ꂽ���\�b�h�E�X�^�u
1008197
1009198 }
1010199
1011200 public void mouseReleased(MouseEvent e) {
1012- // TODO �����������ꂽ���\�b�h�E�X�^�u
1013201
1014202 }
1015-/*
1016- public Mob getSelectedMob() {
1017- return selectedMob;
1018- }
1019-*/
1020- public void resetSelect(){
1021- selectedMob = null;
1022- p = null;
1023- }
1024-
1025- public Mob getSelf(){
1026- return self;
1027- }
1028203 /*
1029204 protected ModelObject getMobMesh(String name,URL objFile,int visual) {
1030205 try{
@@ -1036,9 +211,9 @@
1036211 }
1037212 */
1038213 public void receiveMovePacket(MovePacket packet){
1039- if(getSelf() == null){
1040- return;
1041- }
214+// if(getSelf() == null){
215+// return;
216+// }
1042217
1043218 try{
1044219 Moving mv = MovingVector.valueOf2(packet.getString(MovePacket.MOVING));
@@ -1049,155 +224,21 @@
1049224
1050225 }
1051226
1052- protected Vector3f getNowPosition(Spatial sp){
1053- ArrayList<Controller> list = sp.getControllers();
1054- Iterator<Controller> it = list.iterator();
1055- while (it.hasNext()) {
1056- Controller controller = (Controller) it.next();
1057- if(!(controller instanceof SpatialTransformer)){
1058- continue;
1059- }
1060-
1061- SpatialTransformer st = (SpatialTransformer)controller;
1062- ArrayList<SpatialTransformer.PointInTime> listFrame = st.keyframes;
1063- SpatialTransformer.PointInTime start = listFrame.get(0);
1064- Vector3f startV = start.look[0].getTranslation();
1065- SpatialTransformer.PointInTime end = listFrame.get(1);
1066- Vector3f endV = end.look[0].getTranslation();
1067-// System.out.println("curTime:"+st.getCurTime());
1068- Vector3f move = endV.subtract(startV);
1069-// Vector3f move = startV.subtract(endV);
1070- Vector3f move2 = move.mult(st.getCurTime()/st.getMaxTime());
1071-
1072- Vector3f now = startV.add(move2);
1073-
1074- return now;
1075- }
1076-
1077- return null;
1078-
1079- }
1080-
1081- private Vector3f getStartPosition(Spatial sp){
1082- ArrayList<Controller> list = sp.getControllers();
1083- Iterator<Controller> it = list.iterator();
1084- while (it.hasNext()) {
1085- Controller controller = (Controller) it.next();
1086- if(!(controller instanceof SpatialTransformer)){
1087- continue;
1088- }
1089-
1090- SpatialTransformer st = (SpatialTransformer)controller;
1091- ArrayList<SpatialTransformer.PointInTime> listFrame = st.keyframes;
1092- SpatialTransformer.PointInTime start = listFrame.get(0);
1093- Vector3f startV = start.look[0].getTranslation();
1094-
1095- return startV;
1096- }
1097-
1098- return null;
1099-
1100- }
1101-
1102- private Vector3f getEndPosition(Spatial sp){
1103- ArrayList<Controller> list = sp.getControllers();
1104- Iterator<Controller> it = list.iterator();
1105- while (it.hasNext()) {
1106- Controller controller = (Controller) it.next();
1107- if(!(controller instanceof SpatialTransformer)){
1108- continue;
1109- }
1110-
1111- SpatialTransformer st = (SpatialTransformer)controller;
1112- ArrayList<SpatialTransformer.PointInTime> listFrame = st.keyframes;
1113- SpatialTransformer.PointInTime end = listFrame.get(1);
1114- Vector3f endV = end.look[0].getTranslation();
1115-
1116- return endV;
1117- }
1118-
1119- return null;
1120- }
1121-
1122- private boolean isAnimateEnd(Spatial sp){
1123- ArrayList<Controller> list = sp.getControllers();
1124- Iterator<Controller> it = list.iterator();
1125- while (it.hasNext()) {
1126- Controller controller = (Controller) it.next();
1127- if(!(controller instanceof SpatialTransformer)){
1128- continue;
1129- }
1130-
1131- SpatialTransformer st = (SpatialTransformer)controller;
1132- if(st.getCurTime() < st.getMaxTime()){
1133- return false;
1134- }else{
1135- return true;
1136- }
1137- }
1138- return true;
1139- }
1140-//*
227+ //*
1141228 protected Position createPosition(Vector3f vec){
1142- int x = (int)(vec.x / fsize + map.getXLimit()/2);
1143- int z = (int)(vec.z / fsize + map.getZLimit()/2);
229+ int x = (int)(vec.x / ViewSetting.fsize + map.getXLimit()/2);
230+ int z = (int)(vec.z / ViewSetting.fsize + map.getZLimit()/2);
1144231 return new Position(x,0,z);
1145232 }
1146233
1147234 public void mouseDragged(MouseEvent arg0) {
1148- // TODO �����������ꂽ���\�b�h�E�X�^�u
1149235
1150236 }
1151237
1152238 public void mouseMoved(MouseEvent arg0) {
1153- // TODO �����������ꂽ���\�b�h�E�X�^�u
1154239
1155240 }
1156241
1157- public int getSelectedMobId(){
1158- if (selectedMob != null) {
1159- return selectedMob.getId();
1160- }
1161-
1162- return -1;
1163- }
1164-
1165- public void select() {
1166- // TODO �����������ꂽ���\�b�h�E�X�^�u
1167- LinkedList<Mob> list = new LinkedList<Mob>();
1168- double distance = 10;
1169-
1170- Iterator<Entry<Spatial, Mob>> it = mapSpatialMob.entrySet().iterator();
1171- while (it.hasNext()) {
1172- Entry<Spatial, Mob> next = it.next();
1173- Spatial sp = next.getKey();
1174- Mob mob = next.getValue();
1175- mapMobModel.get(mob).getMesh();
1176-
1177- }
1178-
1179- }
1180-
1181- protected Queue<Mob> getListMob() {
1182- return listMob;
1183- }
1184-
1185- protected Queue<Mob> getListDeleteMob() {
1186- return listDeleteMob;
1187- }
1188-
1189- protected void setSelf(Mob self) {
1190- this.self = self;
1191- }
1192-
1193- protected void setOldSelf(Mob oldSelf) {
1194- this.oldSelf = oldSelf;
1195- }
1196-
1197- protected Mob getOldSelf() {
1198- return oldSelf;
1199- }
1200-
1201242 protected SampleClientFrame getFrame() {
1202243 return frame;
1203244 }
@@ -1214,7 +255,6 @@
1214255 }
1215256
1216257 public int compare(Mob o1, Mob o2) {
1217- // TODO �����������ꂽ���\�b�h�E�X�^�u
1218258 Vector v1 = selfPos.getVector(o1.moving.getPosition());
1219259 double d1 = ((int)v1.getdX())^2+((int)v1.getdY())^2;
1220260 Vector v2 = selfPos.getVector(o2.moving.getPosition());
@@ -1241,8 +281,4 @@
1241281 }
1242282
1243283 }
1244-
1245- public Position getMyPosition() {
1246- return self.moving.getPosition();
1247- }
1248284 }
--- sample/trunk/src/jp/sourceforge/mmosf/client/sample/InputProcess.java (revision 101)
+++ sample/trunk/src/jp/sourceforge/mmosf/client/sample/InputProcess.java (revision 102)
@@ -41,9 +41,11 @@
4141 import java.util.concurrent.LinkedBlockingQueue;
4242
4343 import jp.sourceforge.mmosf.admin.LocalMonitor;
44+import jp.sourceforge.mmosf.client.sample.command.Command;
4445 import jp.sourceforge.mmosf.server.object.Direction;
4546 import jp.sourceforge.mmosf.server.object.Position;
4647 import jp.sourceforge.mmosf.server.object.Vector;
48+import jp.sourceforge.mmosf.server.packet.MovePacket;
4749 import jp.sourceforge.mmosf.server.packet.Packet;
4850 import jp.sourceforge.mmosf.server.packet.PacketFactory;
4951
@@ -61,22 +63,29 @@
6163 protected boolean pressRight;
6264 protected boolean pressLeft;
6365
64- protected BlockingQueue<Vector> queueMove;
66+// protected BlockingQueue<Vector> queueMove;
67+ protected BlockingQueue<Command> queueCommand;
68+
6569 protected static final int QUEUE_SIZE = 3;
6670 protected final int interval = 100;
71+
72+// protected MovePacket prevMovePackt;
73+
74+// protected int move_id;
6775
6876 public InputProcess() {
6977 super();
70- queueMove = new LinkedBlockingQueue<Vector>();
78+// queueMove = new LinkedBlockingQueue<Vector>();
79+ queueCommand = new LinkedBlockingQueue<Command>();
7180 pressUp = false;
7281 pressDown = false;
7382 pressRight = false;
7483 pressLeft = false;
7584 // isRepeat = false;
85+// move_id = 0;
7686 }
7787
7888 public void keyTyped(KeyEvent e) {
79- // TODO �����������ꂽ���\�b�h�E�X�^�u
8089 }
8190
8291 protected boolean isArrowKey(KeyEvent e,boolean isPress) {
@@ -145,89 +154,10 @@
145154 // return false;
146155 }
147156
148- abstract public void send(Packet packet);
149-
150- public void move(int keyCode){
151- Direction v;
152- switch(keyCode){
153- case KeyEvent.VK_UP:
154- v = Direction.NORTH;
155- if(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.VK_RIGHT){
156- v = Direction.NORTH_EAST;
157- }else if(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.VK_LEFT){
158- v = Direction.NORTH_WEST;
159- }
160- break;
161- case KeyEvent.VK_DOWN:
162- v = Direction.SOUTH;
163- if(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.VK_RIGHT){
164- v = Direction.SOUTH_EAST;
165- }else if(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.VK_LEFT){
166- v = Direction.SOUTH_WEST;
167- }
168- //v = Vector.SOUTH_WEST;
169- break;
170- case KeyEvent.VK_LEFT:
171- v = Direction.WEST;
172- if(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.VK_UP){
173- v = Direction.NORTH_WEST;
174- }else if(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.VK_DOWN){
175- v = Direction.SOUTH_WEST;
176- }
177-// v = Vector.NORTH_WEST;
178- break;
179- case KeyEvent.VK_RIGHT:
180- v = Direction.EAST;
181- if(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.VK_UP){
182- v = Direction.NORTH_EAST;
183- }else if(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.VK_DOWN){
184- v = Direction.SOUTH_EAST;
185- }
186-// v = Vector.SOUTH_EAST;
187- break;
188- default:
189- return;
190- }
191-
192- if(queueMove.size() < QUEUE_SIZE){
193- try{
194-// System.out.println("push :"+v.toString());
195- queueMove.put(v.getVector());
196- }catch(InterruptedException e){
197-
198- }
199- }
200-/*
201- Packet pac = PacketFactory.createMovePacket(v);
202- if(log.isTraceEnabled()){
203- try{
204- log.trace(new String(pac.toBytes().array()));
205- }catch(PacketFormatException e){
206- log.error("error in trace, ",e);
207- }
208- }
209- send(pac);
210-*/ // process.send(pac);
211- }
212-
213- public void stop(){
157+// abstract public void send(Packet packet);
158+/*
159+ public void queue(Vector vec){
214160 try{
215- if(queueMove.size() < QUEUE_SIZE+1){
216-// System.out.println("push :"+Vector.ZERO.toString());
217- queueMove.put(Vector.ZERO);
218- }
219- }catch(InterruptedException e){
220-
221- }
222- /*
223- Packet pac = PacketFactory.createMovePacket(v);
224- // process.send(pac);
225- send(pac);
226-*/
227- }
228-
229- public void send(Vector vec){
230- try{
231161 LocalMonitor.getMonitor().log("input vector:"+getVector().toString());
232162 if(vec.isZero()){
233163 if(queueMove.size() < QUEUE_SIZE+1){
@@ -244,6 +174,25 @@
244174
245175 }
246176 }
177+*/
178+ public void queue(Command com){
179+ try{
180+ LocalMonitor.getMonitor().log("input vector:"+com.toString());
181+ if(com == Command.MOVE_STOP){
182+ if(queueCommand.size() < QUEUE_SIZE+1){
183+ // System.out.println("push :"+Vector.ZERO.toString());
184+ queueCommand.put(com);
185+ }
186+ }else{
187+ if(queueCommand.size() < QUEUE_SIZE){
188+// System.out.println("push :"+v.toString());
189+ queueCommand.put(com);
190+ }
191+ }
192+ }catch(InterruptedException e){
193+
194+ }
195+ }
247196
248197 public Vector getVector(){
249198 Direction v = Direction.ZERO;
@@ -287,12 +236,49 @@
287236 return v.getVector();
288237 }
289238
239+
240+ private Command getCommand(){
241+
242+ int vertical = 0;
243+ if(pressUp && !pressDown){
244+ vertical = -1;//UP
245+ }else if(!pressUp && pressDown){
246+ vertical = 1;//DOWN
247+ }
248+
249+ int horizonal = 0;
250+ if(pressRight && !pressLeft){
251+ horizonal = 1;//RIGHT
252+ }else if(!pressRight && pressLeft){
253+ horizonal = -1;//LEFT
254+ }
255+
256+ if(vertical == -1 && horizonal == 0){
257+ return Command.MOVE_UP_RIGHT;//v = Direction.NORTH_EAST;
258+ }else if(vertical == 1 && horizonal == 0){
259+ return Command.MOVE_DOWN_LEFT;//v = Direction.SOUTH_WEST;
260+ }else if(vertical == 0 && horizonal == 1){
261+ return Command.MOVE_DOWN_RIGHT;//v = Direction.SOUTH_EAST;
262+ }else if(vertical == 0 && horizonal == -1){
263+ return Command.MOVE_UP_LEFT;//v = Direction.NORTH_WEST;
264+ }else if(vertical == -1 && horizonal == 1){
265+ return Command.MOVE_RIGHT;//v = Direction.EAST;
266+ }else if(vertical == -1 && horizonal == -1){
267+ return Command.MOVE_UP;//v = Direction.NORTH;
268+ }else if(vertical == 1 && horizonal == 1){
269+ return Command.MOVE_DOWN;//v = Direction.SOUTH;
270+ }else if(vertical == 1 && horizonal == -1){
271+ return Command.MOVE_LEFT;//v = Direction.WEST;
272+ }
273+
274+ return Command.MOVE_STOP;
275+ }
290276 public void keyReleased(KeyEvent e) {
291- // TODO �����������ꂽ���\�b�h�E�X�^�u
292277 log.trace("release,"+e.getKeyCode());
293278 if(isArrowKey(e,false) || isArrowKey2(e, false)){
294279 //stop();
295- send(getVector());
280+// queue(getVector());
281+ queue(getCommand());
296282
297283 }
298284 // isRepeat = false;
@@ -312,7 +298,8 @@
312298
313299 if(isArrowKey(e,true) || isArrowKey2(e, true)){
314300 // move(e.getKeyCode());
315- send(getVector());
301+// queue(getVector());
302+ queue(getCommand());
316303 }
317304
318305
@@ -363,7 +350,8 @@
363350 if(isLogout()){
364351 break;
365352 }
366- send();
353+// send();
354+ send2();
367355 // System.out.println("loop:"+System.currentTimeMillis());
368356 Thread.yield();
369357 }
@@ -396,7 +384,7 @@
396384 }
397385 //*/
398386 }
399-
387+/*
400388 public void send(){
401389 try{
402390 // if(queueMove.isEmpty()){
@@ -418,10 +406,20 @@
418406 if(v != null){
419407 Packet packet = null;
420408 if(v.isZero()){
421- packet = PacketFactory.createMovePacket(getNowPosition());
409+// packet = PacketFactory.createMovePacket(getNowPosition());
410+ MovePacket movePacket = (MovePacket)prevMovePackt;
411+ int move_id = movePacket.getCommandId();
412+// Position startPosition = movePacket.getPosition();
413+ Direction dir = movePacket.getDirection();
414+// packet = PacketFactory.createMovePacket(startPosition, getNowPosition(), Vector.ZERO, dir, move_id);
415+ packet = PacketFactory.createMovePacket(null, null, Vector.ZERO, dir, move_id);
422416
423417 }else{
424- packet = PacketFactory.createMovePacket(v);
418+// packet = PacketFactory.createMovePacket(v);
419+ move_id++;
420+// packet = PacketFactory.createMovePacket(getNowPosition(), null, v, v.getDirection(), move_id);
421+ packet = PacketFactory.createMovePacket(null, null, v, v.getDirection(), move_id);
422+ prevMovePackt = (MovePacket)packet;
425423 }
426424 send(packet);
427425 LocalMonitor.getMonitor().log("send input:",packet);
@@ -432,9 +430,35 @@
432430 log.error("error in send move packet, ",e);
433431 }
434432 }
433+*/
435434
436- abstract protected Position getNowPosition();
435+ public void send2(){
436+ try{
437+ Command com = queueCommand.take();
438+ if(isLogout()){
439+ return;
440+ }
441+
442+ while(com != null && com == Command.MOVE_STOP){
443+ if(queueCommand.isEmpty()){
444+ break;
445+ }
446+ com = queueCommand.take();
447+ }
437448
449+ if(com != null){
450+ send(com);
451+// LocalMonitor.getMonitor().log("send input:",packet);
452+ }
453+ }catch(InterruptedException e){
454+ log.error("error in send move packet, ",e);
455+ }catch(Exception e){
456+ log.error("error in send move packet, ",e);
457+ }
458+ }
459+
460+ abstract public void send(Command com);
461+
438462 abstract public boolean isLogout();
439463
440464 }
\ No newline at end of file
Show on old repository browser