1 Star 0 Fork 0

wuzpdev/goworld

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_client.go 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
seis 提交于 2017-10-25 16:37 . -S to set start clientid
package main
import (
"flag"
"sync"
"math/rand"
"time"
_ "net/http/pprof"
"os"
"github.com/xiaonanln/goTimer"
"github.com/xiaonanln/goworld/engine/binutil"
"github.com/xiaonanln/goworld/engine/config"
"github.com/xiaonanln/goworld/engine/gwlog"
)
var (
quiet bool
configFile string
serverHost string
useWebSocket bool
useKCP bool
numClients int
startClientId int
noEntitySync bool
)
func parseArgs() {
flag.BoolVar(&quiet, "quiet", false, "run client quietly with much less output")
flag.StringVar(&configFile, "configfile", "", "set config file path")
flag.IntVar(&numClients, "N", 1000, "Number of clients")
flag.IntVar(&startClientId, "S", 1, "Start ID of clients")
flag.StringVar(&serverHost, "server", "localhost", "replace server address")
flag.BoolVar(&useWebSocket, "ws", false, "use WebSocket to connect server")
flag.BoolVar(&useKCP, "kcp", false, "use KCP to connect server")
flag.BoolVar(&noEntitySync, "nosync", false, "disable entity sync")
flag.Parse()
}
func main() {
rand.Seed(time.Now().UnixNano())
parseArgs()
if configFile != "" {
config.SetConfigFile(configFile)
}
binutil.SetupGWLog("test_client", "info", "test_client.log", true)
binutil.SetupHTTPServer("localhost", 18888, nil)
if useWebSocket && useKCP {
gwlog.Errorf("Can not use both websocket and KCP")
os.Exit(1)
}
if useWebSocket {
gwlog.Infof("Using websocket clients ...")
} else if useKCP {
gwlog.Infof("Using KCP clients ...")
}
var wait sync.WaitGroup
wait.Add(numClients)
for i := 0; i < numClients; i++ {
bot := newClientBot(startClientId+i, useWebSocket, useKCP, noEntitySync, &wait)
go bot.run()
}
timer.StartTicks(time.Millisecond * 100)
wait.Wait()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzpdev/goworld.git
git@gitee.com:wuzpdev/goworld.git
wuzpdev
goworld
goworld
v0.1.4

搜索帮助