请选择 进入手机版 | 继续访问电脑版

 找回密码
 点一下
查看: 2724|回复: 6

网络同步延迟获取法.

[复制链接]
发表于 2009-10-16 18:26:11 | 显示全部楼层 |阅读模式
[jass]
function FreshDelayTime takes nothing returns nothing
    local string s="|cff00ff00"
    if GetLocalPlayer()==Player(0) then
    call StoreInteger(gc,"GameTime","GetDelay",GetStoredInteger(gc,"GameTime","GetDelay")-1)
    endif
    if GetStoredInteger(gc,"GameTime","GetDelay")>500 then
    set s="|cffff0000"
    elseif GetStoredInteger(gc,"GameTime","GetDelay")>250 then
    set s="|cffffff00"
    endif
    call MultiboardSetTitleText(mb,"|cffffffff网络延迟: |r"+s+I2S(GetStoredInteger(gc,"GameTime","GetDelay"))+"|r |cffffffffms|r")
endfunction

function GetDelayTime takes nothing returns nothing
    if GetStoredInteger(gc,"GameTime","LastDelay")!=GetStoredInteger(gc,"GameTime","Delay") then
    call StoreInteger(gc,"GameTime","GetDelay",ms-GetStoredInteger(gc,"GameTime","Delay"))
    call StoreInteger(gc,"GameTime","LastDelay",GetStoredInteger(gc,"GameTime","Delay"))
    call FreshDelayTime()
    endif
endfunction

function DelayTime takes nothing returns nothing
    if GetLocalPlayer()==Player(0) then
    call StoreInteger(gc,"GameTime","Delay",ms)
    call SyncStoredInteger(gc,"GameTime","Delay")
    endif
endfunction

function TimeClock takes nothing returns nothing
    set ms=ms+1
endfunction

function ClockTime takes nothing returns nothing
    call TimerStart(Clock,0.001,true,function TimeClock)
    call TimerStart(CreateTimer(),1,true,function DelayTime)
    call TimerStart(DelayClock,0.001,true,function GetDelayTime)
endfunction
[/jass]
以上为全部代码,其中ms为自定义的全局整型变量,gc为自定义的全局游戏缓存变量,mb是自定义的全局多面板变量.Clock和DelayClock是自定义的全局计时器变量

不明白的同学请不要随便乱用额.可能引起掉线.

评分

参与人数 1威望 +4 收起 理由
血戮魔动冰 + 4

查看全部评分

发表于 2009-10-16 18:51:00 | 显示全部楼层
事实上就是把玩家1的timer计数同步给别的玩家。
然后所有玩家比对自己的timer计数。如果有不同则把自己的网络延迟打印在多面板上。
想法很不错。
但是:
1.频繁SyncCache的数据开销很大
2.当主机不是玩家1的时候,怎么办呢?
仅此而已。

当然,这东西能否实际使用还存在疑问…………
毕竟你的Timer计数能否真正反映延迟我不确定。
回复

使用道具 举报

发表于 2009-10-16 18:52:11 | 显示全部楼层
因为你的威望为0,所以特别多加一些分。
回复

使用道具 举报

发表于 2009-10-16 19:17:07 | 显示全部楼层
http://bbs.islga.org/read-htm-tid-2716-keyword-%D1%D3%B3%D9.html
具体的内容贴找不到了……
反正至今没有精确的结果
回复

使用道具 举报

 楼主| 发表于 2009-10-16 20:08:43 | 显示全部楼层
已经试过,可以使用.不会掉线.至于SYNC其实还好,不算频繁,才1秒一次而已.如果还是太多的话修改下计时器的计时循环就可以了......就一个数值的问题而已.......
该方法获得的是缓存同步的延迟.和网络延迟存在一定关系.个人"估计"为网络延迟的7~10倍左右.这个只是估计而已.不准确的说.同一个局域网我和同学两台机子显示的延迟大概在80~200之间晃动.一般来说局域网是10~20ms.所以我是根据这个估计出来的.
回复

使用道具 举报

 楼主| 发表于 2009-10-16 20:11:41 | 显示全部楼层
至于主机是不是玩家一不重要.......因为这个是我的图里面必须需要玩家1才能开始的.所以就这么写了.
网络延迟不一定非要主机的说.至少我是这么想的- -!
回复

使用道具 举报

发表于 2009-10-16 23:43:59 | 显示全部楼层
就是sync函数呗。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-4-18 17:46 , Processed in 0.114163 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表