mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Move player handling into new EntityList class.
This commit is contained in:
parent
152133d95c
commit
e95429dbef
@ -34,20 +34,19 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
void PlayerSpawned( object sender, IdEventArgs e ) {
|
||||
Player player = Window.NetPlayers[e.Id];
|
||||
Player player = Window.Players[e.Id];
|
||||
AddPlayerInfo( player );
|
||||
columns = (int)Math.Ceiling( (double)namesCount / namesPerColumn );
|
||||
SortPlayerInfo();
|
||||
}
|
||||
|
||||
protected override void CreateInitialPlayerInfo() {
|
||||
for( int i = 0; i < Window.NetPlayers.Length; i++ ) {
|
||||
Player player = Window.NetPlayers[i];
|
||||
for( int i = 0; i < Window.Players.MaxCount; i++ ) {
|
||||
Player player = Window.Players[i];
|
||||
if( player != null ) {
|
||||
AddPlayerInfo( player );
|
||||
}
|
||||
}
|
||||
AddPlayerInfo( Window.LocalPlayer );
|
||||
}
|
||||
|
||||
void AddPlayerInfo( Player player ) {
|
||||
|
@ -110,6 +110,7 @@
|
||||
<Compile Include="Blocks\BlockInfo.Culling.cs" />
|
||||
<Compile Include="Blocks\BlockInfo.Optimised.cs" />
|
||||
<Compile Include="Entities\Entity.cs" />
|
||||
<Compile Include="Entities\EntityList.cs" />
|
||||
<Compile Include="Entities\LocalPlayer.cs" />
|
||||
<Compile Include="Entities\NetPlayer.cs" />
|
||||
<Compile Include="Entities\Particles\Particle.cs" />
|
||||
|
39
Entities/EntityList.cs
Normal file
39
Entities/EntityList.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public class EntityList {
|
||||
|
||||
public int MaxCount = 256;
|
||||
public Player[] Players = new Player[256];
|
||||
|
||||
public void Tick( double delta ) {
|
||||
for( int i = 0; i < Players.Length; i++ ) {
|
||||
if( Players[i] != null ) {
|
||||
Players[i].Tick( delta );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Render( double delta, float t ) {
|
||||
for( int i = 0; i < Players.Length; i++ ) {
|
||||
if( Players[i] != null ) {
|
||||
Players[i].Render( delta, t );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
for( int i = 0; i < Players.Length; i++ ) {
|
||||
if( Players[i] != null ) {
|
||||
Players[i].Despawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Player this[int id] {
|
||||
get { return Players[id]; }
|
||||
set { Players[id] = value; }
|
||||
}
|
||||
}
|
||||
}
|
30
Game/Game.cs
30
Game/Game.cs
@ -21,7 +21,7 @@ namespace ClassicalSharp {
|
||||
public Map Map;
|
||||
public NetworkProcessor Network;
|
||||
|
||||
public Player[] NetPlayers = new Player[256];
|
||||
public EntityList Players = new EntityList();
|
||||
public CpeListInfo[] CpePlayersList = new CpeListInfo[256];
|
||||
public LocalPlayer LocalPlayer;
|
||||
public Camera Camera;
|
||||
@ -131,6 +131,7 @@ namespace ClassicalSharp {
|
||||
BlockInfo.SetDefaultBlockPermissions( CanPlace, CanDelete );
|
||||
Map = new Map( this );
|
||||
LocalPlayer = new LocalPlayer( 255, this );
|
||||
Players[255] = LocalPlayer;
|
||||
width = Width;
|
||||
height = Height;
|
||||
MapRenderer = new MapRenderer( this );
|
||||
@ -202,14 +203,9 @@ namespace ClassicalSharp {
|
||||
int ticksThisFrame = 0;
|
||||
while( ticksAccumulator >= ticksPeriod ) {
|
||||
Network.Tick( ticksPeriod );
|
||||
LocalPlayer.Tick( ticksPeriod );
|
||||
Players.Tick( ticksPeriod );
|
||||
Camera.Tick( ticksPeriod );
|
||||
ParticleManager.Tick( ticksPeriod );
|
||||
for( int i = 0; i < NetPlayers.Length; i++ ) {
|
||||
if( NetPlayers[i] != null ) {
|
||||
NetPlayers[i].Tick( ticksPeriod );
|
||||
}
|
||||
}
|
||||
ticksThisFrame++;
|
||||
ticksAccumulator -= ticksPeriod;
|
||||
}
|
||||
@ -228,7 +224,7 @@ namespace ClassicalSharp {
|
||||
|
||||
bool visible = activeScreen == null || !activeScreen.BlocksWorld;
|
||||
if( visible ) {
|
||||
RenderPlayers( e.Time, t );
|
||||
Players.Render( e.Time, t );
|
||||
ParticleManager.Render( e.Time, t );
|
||||
Camera.GetPickedBlock( SelectedPos ); // TODO: only pick when necessary
|
||||
if( SelectedPos.Valid )
|
||||
@ -264,17 +260,6 @@ namespace ClassicalSharp {
|
||||
Graphics.EndFrame( this );
|
||||
}
|
||||
|
||||
void RenderPlayers( double deltaTime, float t ) {
|
||||
//Graphics.AlphaTest = true;
|
||||
for( int i = 0; i < NetPlayers.Length; i++ ) {
|
||||
if( NetPlayers[i] != null ) {
|
||||
NetPlayers[i].Render( deltaTime, t );
|
||||
}
|
||||
}
|
||||
LocalPlayer.Render( deltaTime, t );
|
||||
//Graphics.AlphaTest = false;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
MapRenderer.Dispose();
|
||||
MapEnvRenderer.Dispose();
|
||||
@ -288,12 +273,7 @@ namespace ClassicalSharp {
|
||||
ModelCache.Dispose();
|
||||
Picking.Dispose();
|
||||
ParticleManager.Dispose();
|
||||
for( int i = 0; i < NetPlayers.Length; i++ ) {
|
||||
if( NetPlayers[i] != null ) {
|
||||
NetPlayers[i].Despawn();
|
||||
}
|
||||
}
|
||||
LocalPlayer.Despawn();
|
||||
Players.Dispose();
|
||||
Graphics.CheckResources();
|
||||
AsyncDownloader.Dispose();
|
||||
if( writer != null ) {
|
||||
|
@ -383,11 +383,11 @@ namespace ClassicalSharp {
|
||||
case PacketId.RemoveEntity:
|
||||
{
|
||||
byte entityId = reader.ReadUInt8();
|
||||
Player player = Window.NetPlayers[entityId];
|
||||
if( player != null ) {
|
||||
Player player = Window.Players[entityId];
|
||||
if( entityId != 0xFF && player != null ) {
|
||||
Window.RaiseEntityRemoved( entityId );
|
||||
player.Despawn();
|
||||
Window.NetPlayers[entityId] = null;
|
||||
Window.Players[entityId] = null;
|
||||
}
|
||||
} break;
|
||||
|
||||
@ -588,7 +588,7 @@ namespace ClassicalSharp {
|
||||
{
|
||||
byte playerId = reader.ReadUInt8();
|
||||
string modelName = reader.ReadAsciiString().ToLowerInvariant();
|
||||
Player player = playerId == 0xFF ? Window.LocalPlayer : Window.NetPlayers[playerId];
|
||||
Player player = Window.Players[playerId];
|
||||
if( player != null ) {
|
||||
player.SetModel( modelName );
|
||||
}
|
||||
@ -647,12 +647,12 @@ namespace ClassicalSharp {
|
||||
|
||||
void AddEntity( byte entityId, string displayName, string skinName, bool readPosition ) {
|
||||
if( entityId != 0xFF ) {
|
||||
Player oldPlayer = Window.NetPlayers[entityId];
|
||||
Player oldPlayer = Window.Players[entityId];
|
||||
if( oldPlayer != null ) {
|
||||
Window.RaiseEntityRemoved( entityId );
|
||||
oldPlayer.Despawn();
|
||||
}
|
||||
Window.NetPlayers[entityId] = new NetPlayer( entityId, displayName, skinName, Window );
|
||||
Window.Players[entityId] = new NetPlayer( entityId, displayName, skinName, Window );
|
||||
Window.RaiseEntityAdded( entityId );
|
||||
Window.AsyncDownloader.DownloadSkin( skinName );
|
||||
}
|
||||
@ -706,7 +706,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
void UpdateLocation( byte playerId, LocationUpdate update, bool interpolate ) {
|
||||
Player player = playerId == 0xFF ? Window.LocalPlayer : Window.NetPlayers[playerId];
|
||||
Player player = Window.Players[playerId];
|
||||
if( player != null ) {
|
||||
player.SetLocation( update, interpolate );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user