HTML5技术

结合WebSocket编写WebGL综合场景示例 - ljzc002(10)

字号+ 作者:H5之家 来源:H5之家 2016-11-07 12:00 我要评论( )

1 case "addnewplayer" : dt= new Date(); 4 console.log(dt.getTime()+"get addnewplayer"+arr[0 ]); 5 var flag=0 ;//加载完成标志 6 for ( var key in arr_myplayers)//先在本机的玩家列表里找 7 { { obj_key= a

1 case "addnewplayer": dt=new Date(); 4 console.log(dt.getTime()+"get addnewplayer"+arr[0]); 5 var flag=0;//加载完成标志 6 for(var key in arr_myplayers)//先在本机的玩家列表里找 7 { { obj_key=arr_myplayers[key]; 12 arr_webplayers[arr[0]] = MyCloneplayer(obj_key,arr); 13 shadowGenerator.getShadowMap().renderList.push(arr_webplayers[arr[0]].mesh);//阴影生成器似乎对含有submesh的Mesh不起作用 14 writeToScreen('<span>addnewplayer: ' + arr[0] + '</span>'); 15 flag=1; addoldplayer(arr[0]); 19 break; 20 } 21 } { 24 for(var key in arr_webplayers) 25 { { 28 var obj_key=arr_webplayers[key]; 29 arr_webplayers[arr[0]] = MyCloneplayer(obj_key,arr); 30 shadowGenerator.getShadowMap().renderList.push(arr_webplayers[arr[0]].mesh); 31 writeToScreen('<span>addnewplayer: ' + arr[0] + '</span>'); 32 flag=1; addoldplayer(arr[0]); 35 break; 36 } 37 } 38 } { (tempobj[arr[14]]&&tempobj[arr[14]]!="OK") { } { 48 tempobj[arr[14]] = arr;//用tempobj暂存该物体的初始化参数 Tom = new Player; 51 var obj_p = {}; arr = tempobj[obj_p.mesh.name]; obj_p.position = obj_p.rotation = obj_p.checkCollisions = obj_p.ellipsoid = obj_p.ellipsoidOffset = obj_p.skeletonsPlayer = skeletons; 61 obj_p.methodofmove = "controlwitha"; 62 obj_p.id = arr[0]; 63 obj_p.name = arr[0]; 64 obj_p.p1 = arr[11]; 65 obj_p.p2 = arr[12]; 66 obj_p.p3 = arr[13]; arr=[]; 69 for(var i=1;i<len;i++) 70 { 71 arr.push(newMeshes[i]); 72 } 73 obj_p.submeshs=arr; 74 Tom.init( 75 obj_p 76 ); 77 tempobj[obj_p.mesh.name] = "OK"; 78 arr_webplayers[arr[0]] = Tom; 79 shadowGenerator.getShadowMap().renderList.push(arr_webplayers[arr[0]].mesh); 80 81 writeToScreen('<span>addnewplayer: ' + arr[0] + '</span>'); 82 flag=1; addoldplayer(arr[0]); 85 86 }); 87 } 88 } 89 break; 90 } "addoldplayer": dt=new Date(); 95 console.log(dt.getTime()+"get addoldplayer"+arr[0]); 96 var flag=0; 97 for(var key in arr_myplayers) 98 { { 101 var obj_key=arr_myplayers[key]; 102 arr_webplayers[arr[0]] =MyCloneplayer(obj_key,arr); 103 shadowGenerator.getShadowMap().renderList.push(arr_webplayers[arr[0]].mesh); 104 writeToScreen('<span>addoldplayer: ' + arr[0] + '</span>'); 105 flag=1; ; 108 } 109 } { 112 for(var key in arr_webplayers) 113 { { 116 var obj_key=arr_webplayers[key]; 117 arr_webplayers[arr[0]] = MyCloneplayer(obj_key,arr); 118 shadowGenerator.getShadowMap().renderList.push(arr_webplayers[arr[0]].mesh); 119 writeToScreen('<span>addoldplayer: ' + arr[0] + '</span>'); 120 flag=1; 121 break; 122 } 123 } 124 } { (tempobj[arr[14]]&&tempobj[arr[14]]!="OK") { } { 134 tempobj[arr[14]] = arr; Tom = new Player; 137 var obj_p = {}; arr = tempobj[obj_p.mesh.name]; obj_p.position = obj_p.rotation = obj_p.checkCollisions = obj_p.ellipsoid = obj_p.ellipsoidOffset = obj_p.skeletonsPlayer = skeletons; 147 obj_p.methodofmove = "controlwitha"; 148 obj_p.id = arr[0]; 149 obj_p.name = arr[0]; 150 obj_p.p1 = arr[11]; 151 obj_p.p2 = arr[12]; 152 obj_p.p3 = arr[13]; arr=[]; 155 for(var i=1;i<len;i++) 156 { 157 arr.push(newMeshes[i]); 158 } 159 obj_p.submeshs=arr; 160 Tom.init( 161 obj_p 162 ); 163 tempobj[obj_p.mesh.name] = "OK"; 164 arr_webplayers[arr[0]] = Tom; 165 shadowGenerator.getShadowMap().renderList.push(arr_webplayers[arr[0]].mesh); 166 writeToScreen('<span>addoldplayer: ' + arr[0] + '</span>'); 167 flag=1; 168 169 }); 170 } 171 } 172 break; 173 }

  这里的主要难点是如何处理多个异步的添加玩家请求,经过思考和实验部分的解决了问题。

b、多个客户端之间同步玩家的状态:

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • HTML5 WebSocket - Roberter

    HTML5 WebSocket - Roberter

    2016-10-25 16:00

  • websocket初探 - 2778085001

    websocket初探 - 2778085001

    2016-07-16 15:11

  • DIV+CSS:如何编写代码才能更有效率 - 2778085001

    DIV+CSS:如何编写代码才能更有效率 - 2778085001

    2016-06-29 15:00

  • 用node实现websocket协议 - 2778085001

    用node实现websocket协议 - 2778085001

    2016-06-25 14:00

网友点评