本文整理汇总了C#中Server.PlayerBlockPosition方法的典型用法代码示例。如果您正苦于以下问题:C# Server.PlayerBlockPosition方法的具体用法?C# Server.PlayerBlockPosition怎么用?C# Server.PlayerBlockPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.PlayerBlockPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public override void Update(Server server, float dt)
{
int sizexchunks = server.mapsizexchunks();
int sizeychunks = server.mapsizeychunks();
int sizezchunks = server.mapsizezchunks();
for (int i = 0; i < 100; i++)
{
MapUtilCi.PosInt(CompressUnusedIteration, sizexchunks, sizeychunks, chunkpos);
ServerChunk c = server.d_Map.GetChunkValid(chunkpos.X, chunkpos.Y, chunkpos.Z);
bool stop = false;
if (c != null)
{
var globalpos = new Vector3i(chunkpos.X * Server.chunksize, chunkpos.Y * Server.chunksize, chunkpos.Z * Server.chunksize);
bool unload = true;
foreach (var k in server.clients)
{
if (k.Value.IsBot)
{
// don't hold chunks in memory for bots
continue;
}
// unload distance = view distance + 60% (prevents chunks from being unloaded too early (square loading vs. circular unloading))
int viewdist = (int)(server.chunkdrawdistance * Server.chunksize * 1.8f);
if (server.DistanceSquared(server.PlayerBlockPosition(k.Value), globalpos) <= viewdist * viewdist)
{
//System.Console.WriteLine("No Unload: {0},{1},{2}", chunkpos.X, chunkpos.Y, chunkpos.Z);
unload = false;
}
}
if (unload)
{
// unload if chunk isn't seen by anyone
if (c.DirtyForSaving)
{
// save changes to disk if necessary
server.DoSaveChunk(chunkpos.X, chunkpos.Y, chunkpos.Z, c);
}
server.d_Map.SetChunkValid(chunkpos.X, chunkpos.Y, chunkpos.Z, null);
foreach (var client in server.clients)
{
// mark chunks unseen for all players
server.ClientSeenChunkRemove(client.Key, chunkpos.X, chunkpos.Y, chunkpos.Z);
}
stop = true;
}
}
CompressUnusedIteration++;
if (CompressUnusedIteration >= sizexchunks * sizeychunks * sizezchunks)
{
CompressUnusedIteration = 0;
}
if (stop)
{
// only unload one chunk at a time
return;
}
}
}
示例2: ChunkSimulation
void ChunkSimulation(Server server)
{
unchecked
{
foreach (var k in server.clients)
{
var pos = server.PlayerBlockPosition(k.Value);
long oldesttime = long.MaxValue;
Vector3i oldestpos = new Vector3i();
foreach (var p in ChunksAroundPlayer(server, pos))
{
if (!MapUtil.IsValidPos(server.d_Map, p.x, p.y, p.z)) { continue; }
ServerChunk c = server.d_Map.GetChunkValid(server.invertChunk(p.x) , server.invertChunk( p.y), server.invertChunk( p.z));
//ServerChunk c = server.d_Map.GetChunkValid(p.x / Server.chunksize, p.y / Server.chunksize, p.z / Server.chunksize);
if (c == null)
{
continue;
}
if (c.data == null)
{
continue;
}
if (c.LastUpdate > server.simulationcurrentframe) { c.LastUpdate = server.simulationcurrentframe; }
if (c.LastUpdate < oldesttime)
{
oldesttime = c.LastUpdate;
oldestpos = p;
}
if (!c.IsPopulated)
{
PopulateChunk(server, p);
c.IsPopulated = true;
}
}
if (server.simulationcurrentframe - oldesttime > chunksimulation_every(server))
{
ChunkUpdate(server, oldestpos, oldesttime);
ServerChunk c = server.d_Map.GetChunkValid(server.invertChunk( oldestpos.x),server.invertChunk( oldestpos.y), server.invertChunk( oldestpos.z));
//ServerChunk c = server.d_Map.GetChunkValid(oldestpos.x / Server.chunksize, oldestpos.y / Server.chunksize, oldestpos.z / Server.chunksize);
c.LastUpdate = (int)server.simulationcurrentframe;
return;
}
}
}
}
示例3: NotifyPlayerPositions
// EntityPositionAndOrientation
void NotifyPlayerPositions(Server server, int clientid, float dt)
{
ClientOnServer c = server.clients[clientid];
c.notifyPlayerPositionsAccum += dt;
if (c.notifyPlayerPositionsAccum < (one / PlayerPositionUpdatesPerSecond))
{
return;
}
c.notifyPlayerPositionsAccum = 0;
foreach (var k in server.clients)
{
if (k.Value.state != ClientStateOnServer.Playing)
{
continue;
}
if (!c.IsSpectator && k.Value.IsSpectator)
{
// Do not send position updates for spectating players if player is not spectator himself
continue;
}
if (k.Key == clientid)
{
if (k.Value.positionOverride == null)
{
continue;
}
else
{
k.Value.entity.position = k.Value.positionOverride;
k.Value.positionOverride = null;
}
}
else
{
if (server.DistanceSquared(server.PlayerBlockPosition(server.clients[k.Key]), server.PlayerBlockPosition(server.clients[clientid])) > server.config.PlayerDrawDistance * server.config.PlayerDrawDistance)
{
continue;
}
}
Packet_PositionAndOrientation position = ToNetworkEntityPosition(server.serverPlatform, server.clients[k.Key].entity.position);
server.SendPacket(clientid, ServerPackets.EntityPositionAndOrientation(k.Key, position));
}
}
示例4: Update
public override void Update(Server server, float dt)
{
Stopwatch s = new Stopwatch();
s.Start();
int areasizechunks = server.playerareasize / Server.chunksize;
int areasizeZchunks = server.d_Map.MapSizeZ / Server.chunksize;
int mapsizeXchunks = server.d_Map.MapSizeX / Server.chunksize;
int mapsizeYchunks = server.d_Map.MapSizeY / Server.chunksize;
int mapsizeZchunks = server.d_Map.MapSizeZ / Server.chunksize;
int[] retNearest = new int[3];
bool loaded = true;
while ((loaded) && (s.ElapsedMilliseconds < 10))
{
loaded = false;
foreach (var k in server.clients)
{
if (k.Value.state == ClientStateOnServer.Connecting)
{
continue;
}
Vector3i playerpos = server.PlayerBlockPosition(k.Value);
NearestDirty(server, k.Key, playerpos.x, playerpos.y, playerpos.z, retNearest);
if (retNearest[0] != -1)
{
LoadAndSendChunk(server, k.Key, retNearest[0], retNearest[1], retNearest[2], s);
loaded = true;
}
}
}
}