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