當前位置: 首頁>>代碼示例>>Golang>>正文


Golang IPlayerClient.TransmitPacket方法代碼示例

本文整理匯總了Golang中chunkymonkey/gamerules.IPlayerClient.TransmitPacket方法的典型用法代碼示例。如果您正苦於以下問題:Golang IPlayerClient.TransmitPacket方法的具體用法?Golang IPlayerClient.TransmitPacket怎麽用?Golang IPlayerClient.TransmitPacket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chunkymonkey/gamerules.IPlayerClient的用法示例。


在下文中一共展示了IPlayerClient.TransmitPacket方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: reqSubscribeChunk

func (chunk *Chunk) reqSubscribeChunk(entityId EntityId, player gamerules.IPlayerClient, notify bool) {
	if _, ok := chunk.subscribers[entityId]; ok {
		// Already subscribed.
		return
	}

	chunk.subscribers[entityId] = player

	// Transmit the chunk data to the new player.
	buf := new(bytes.Buffer)
	// chunk.shard.pktSerial.WritePacketsBuffer(buf, &proto.PacketPreChunk{ //@TODO 1.5.1
	//     ChunkLoc: chunk.loc,
	//     Mode:     ChunkInit,
	// })
	player.TransmitPacket(buf.Bytes())
	player.TransmitPacket(chunk.chunkPacket())
	if notify {
		player.NotifyChunkLoad()
	}

	// Send spawn packets for all entities in the chunk to the player.
	if len(chunk.entities) > 0 {
		buf := new(bytes.Buffer)
		for _, entity := range chunk.entities {
			pkts := entity.SpawnPackets(nil)
			chunk.shard.pktSerial.WritePacketsBuffer(buf, pkts...)
		}
		player.TransmitPacket(buf.Bytes())
	}

	// Spawn existing players for new player.
	if len(chunk.playersData) > 0 {
		buf := new(bytes.Buffer)
		for _, existing := range chunk.playersData {
			if existing.entityId != entityId {
				pkts := existing.SpawnPackets(nil)
				chunk.shard.pktSerial.WritePacketsBuffer(buf, pkts...)
			}
		}
		player.TransmitPacket(buf.Bytes())
	}
}
開發者ID:b1naryth1ef,項目名稱:chunkymonkey,代碼行數:42,代碼來源:chunk.go

示例2: reqSubscribeChunk

func (chunk *Chunk) reqSubscribeChunk(entityId EntityId, player gamerules.IPlayerClient, notify bool) {
	if _, ok := chunk.subscribers[entityId]; ok {
		// Already subscribed.
		return
	}

	chunk.subscribers[entityId] = player

	buf := new(bytes.Buffer)
	proto.WritePreChunk(buf, &chunk.loc, ChunkInit)
	player.TransmitPacket(buf.Bytes())

	player.TransmitPacket(chunk.chunkPacket())
	if notify {
		player.NotifyChunkLoad()
	}

	// Send spawns packets for all entities in the chunk.
	if len(chunk.entities) > 0 {
		buf := new(bytes.Buffer)
		for _, e := range chunk.entities {
			e.SendSpawn(buf)
		}
		player.TransmitPacket(buf.Bytes())
	}

	// Spawn existing players for new player.
	if len(chunk.playersData) > 0 {
		playersPacket := new(bytes.Buffer)
		for _, existing := range chunk.playersData {
			if existing.entityId != entityId {
				existing.sendSpawn(playersPacket)
			}
		}
		player.TransmitPacket(playersPacket.Bytes())
	}
}
開發者ID:nictuku,項目名稱:chunkymonkey,代碼行數:37,代碼來源:chunk.go


注:本文中的chunkymonkey/gamerules.IPlayerClient.TransmitPacket方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。