mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Minor code cleanup, separate event classes.
This commit is contained in:
parent
a7210e3aa9
commit
8b73b0a713
@ -91,7 +91,7 @@ namespace ClassicalSharp {
|
||||
chat.Init();
|
||||
hotbar = new BlockHotbarWidget( game );
|
||||
hotbar.Init();
|
||||
game.Events.OnNewMap += OnNewMap;
|
||||
game.MapEvents.OnNewMap += OnNewMap;
|
||||
}
|
||||
|
||||
void OnNewMap( object sender, EventArgs e ) {
|
||||
|
@ -44,7 +44,7 @@ namespace ClassicalSharp {
|
||||
progressBoxTexture = drawer.Make2DTexture( bmp, size, (int)progX, (int)progY );
|
||||
}
|
||||
}
|
||||
game.Events.MapLoading += MapLoading;
|
||||
game.MapEvents.MapLoading += MapLoading;
|
||||
}
|
||||
|
||||
public void SetTitle( string title ) {
|
||||
@ -72,7 +72,7 @@ namespace ClassicalSharp {
|
||||
messageWidget.Dispose();
|
||||
titleWidget.Dispose();
|
||||
graphicsApi.DeleteTexture( ref progressBoxTexture );
|
||||
game.Events.MapLoading -= MapLoading;
|
||||
game.MapEvents.MapLoading -= MapLoading;
|
||||
}
|
||||
|
||||
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||
|
@ -25,11 +25,6 @@ namespace ClassicalSharp {
|
||||
for( int i = 0; i < labels.Length; i++ )
|
||||
labels[i].Render( delta );
|
||||
graphicsApi.Texturing = false;
|
||||
|
||||
if( textPath != null ) {
|
||||
SaveMap( textPath );
|
||||
textPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
||||
@ -147,20 +142,5 @@ namespace ClassicalSharp {
|
||||
return 0;
|
||||
return text == "" ? 0 : Int32.Parse( text );
|
||||
}
|
||||
|
||||
string textPath;
|
||||
void SaveMap( string path ) {
|
||||
path = Path.Combine( Program.AppDirectory, path );
|
||||
try {
|
||||
using( FileStream fs = new FileStream( path, FileMode.CreateNew, FileAccess.Write ) ) {
|
||||
IMapFileFormat map = new MapCw();
|
||||
map.Save( fs, game );
|
||||
}
|
||||
} catch( Exception ex ) {
|
||||
ErrorHandler.LogError( "saving map", ex );
|
||||
return;
|
||||
}
|
||||
game.SetNewScreen( new PauseScreen( game ) );
|
||||
}
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ namespace ClassicalSharp {
|
||||
|
||||
byte[] blocks = mapFile.Load( fs, game, out width, out height, out length );
|
||||
game.Map.SetData( blocks, width, height, length );
|
||||
game.Events.RaiseOnNewMapLoaded();
|
||||
game.MapEvents.RaiseOnNewMapLoaded();
|
||||
|
||||
LocalPlayer p = game.LocalPlayer;
|
||||
LocationUpdate update = LocationUpdate.MakePos( p.SpawnPoint, false );
|
||||
|
@ -53,16 +53,16 @@ namespace ClassicalSharp {
|
||||
Font titleFont;
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
game.Events.CpeListInfoAdded += PlayerListInfoAdded;
|
||||
game.Events.CpeListInfoRemoved += PlayerListInfoRemoved;
|
||||
game.Events.CpeListInfoChanged += PlayerListInfoChanged;
|
||||
game.EntityEvents.CpeListInfoAdded += PlayerListInfoAdded;
|
||||
game.EntityEvents.CpeListInfoRemoved += PlayerListInfoRemoved;
|
||||
game.EntityEvents.CpeListInfoChanged += PlayerListInfoChanged;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
game.Events.CpeListInfoAdded -= PlayerListInfoAdded;
|
||||
game.Events.CpeListInfoChanged -= PlayerListInfoChanged;
|
||||
game.Events.CpeListInfoRemoved -= PlayerListInfoRemoved;
|
||||
game.EntityEvents.CpeListInfoAdded -= PlayerListInfoAdded;
|
||||
game.EntityEvents.CpeListInfoChanged -= PlayerListInfoChanged;
|
||||
game.EntityEvents.CpeListInfoRemoved -= PlayerListInfoRemoved;
|
||||
titleFont.Dispose();
|
||||
}
|
||||
|
||||
|
@ -24,14 +24,14 @@ namespace ClassicalSharp {
|
||||
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
game.Events.EntityAdded += PlayerSpawned;
|
||||
game.Events.EntityRemoved += PlayerDespawned;
|
||||
game.EntityEvents.EntityAdded += PlayerSpawned;
|
||||
game.EntityEvents.EntityRemoved += PlayerDespawned;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
game.Events.EntityAdded -= PlayerSpawned;
|
||||
game.Events.EntityRemoved -= PlayerDespawned;
|
||||
game.EntityEvents.EntityAdded -= PlayerSpawned;
|
||||
game.EntityEvents.EntityRemoved -= PlayerDespawned;
|
||||
}
|
||||
|
||||
void PlayerSpawned( object sender, IdEventArgs e ) {
|
||||
|
@ -152,6 +152,9 @@
|
||||
<Compile Include="Entities\LocalPlayer.Physics.cs" />
|
||||
<Compile Include="Entities\LocationUpdate.cs" />
|
||||
<Compile Include="Entities\NetPlayer.cs" />
|
||||
<Compile Include="Events\EntityEvents.cs" />
|
||||
<Compile Include="Events\Events.cs" />
|
||||
<Compile Include="Events\MapEvents.cs" />
|
||||
<Compile Include="Game\Game.Properties.cs" />
|
||||
<Compile Include="Generator\FlatGrassGenerator.cs" />
|
||||
<Compile Include="Generator\IMapGenerator.cs" />
|
||||
@ -168,7 +171,6 @@
|
||||
<Compile Include="Entities\Player.Rendering.cs" />
|
||||
<Compile Include="Game\ChatLog.cs" />
|
||||
<Compile Include="Game\Game.cs" />
|
||||
<Compile Include="Game\Events.cs" />
|
||||
<Compile Include="Game\InputHandler.cs" />
|
||||
<Compile Include="Game\Inventory.cs" />
|
||||
<Compile Include="Game\KeyMap.cs" />
|
||||
@ -281,6 +283,7 @@
|
||||
<Folder Include="2D\Widgets\Menu" />
|
||||
<Folder Include="2D\Widgets\Chat" />
|
||||
<Folder Include="Blocks" />
|
||||
<Folder Include="Events" />
|
||||
<Folder Include="Generator" />
|
||||
<Folder Include="Android" />
|
||||
<Folder Include="Particles" />
|
||||
|
@ -216,7 +216,7 @@ namespace ClassicalSharp {
|
||||
if( UserType == 0x64 )
|
||||
ParseFlag( b => SetAllHacks( b ), joined, "ophax" );
|
||||
CheckHacksConsistency();
|
||||
game.Events.RaiseHackPermissionmsChanged();
|
||||
game.Events.RaiseHackPermissionsChanged();
|
||||
}
|
||||
|
||||
void SetAllHacks( bool allowed ) {
|
||||
|
36
ClassicalSharp/Events/EntityEvents.cs
Normal file
36
ClassicalSharp/Events/EntityEvents.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Contains events related to the spawning/despawning of entities,
|
||||
/// and the creation/removal of CPE player list entries. </summary>
|
||||
public sealed class EntityEvents : Events {
|
||||
|
||||
IdEventArgs idArgs = new IdEventArgs();
|
||||
|
||||
/// <summary> Raised when an entity is spawned in the current world. </summary>
|
||||
public event EventHandler<IdEventArgs> EntityAdded;
|
||||
internal void RaiseEntityAdded( byte id ) { idArgs.Id = id; Raise( EntityAdded, idArgs ); }
|
||||
|
||||
/// <summary> Raised when an entity is despawned from the current world. </summary>
|
||||
public event EventHandler<IdEventArgs> EntityRemoved;
|
||||
internal void RaiseEntityRemoved( byte id ) { idArgs.Id = id; Raise( EntityRemoved, idArgs ); }
|
||||
|
||||
/// <summary> Raised when a new CPE player list entry is created. </summary>
|
||||
public event EventHandler<IdEventArgs> CpeListInfoAdded;
|
||||
internal void RaiseCpeListInfoAdded( byte id ) { idArgs.Id = id; Raise( CpeListInfoAdded, idArgs ); }
|
||||
|
||||
/// <summary> Raised when a CPE player list entry is modified. </summary>
|
||||
public event EventHandler<IdEventArgs> CpeListInfoChanged;
|
||||
internal void RaiseCpeListInfoChanged( byte id ) { idArgs.Id = id; Raise( CpeListInfoChanged, idArgs ); }
|
||||
|
||||
/// <summary> Raised when a CPE player list entry is removed. </summary>
|
||||
public event EventHandler<IdEventArgs> CpeListInfoRemoved;
|
||||
internal void RaiseCpeListInfoRemoved( byte id ) { idArgs.Id = id; Raise( CpeListInfoRemoved, idArgs ); }
|
||||
}
|
||||
|
||||
public sealed class IdEventArgs : EventArgs {
|
||||
|
||||
public byte Id;
|
||||
}
|
||||
}
|
63
ClassicalSharp/Events/Events.cs
Normal file
63
ClassicalSharp/Events/Events.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public class Events {
|
||||
|
||||
/// <summary> Raised when the terrain atlas ("terrain.png") is changed. </summary>
|
||||
public event EventHandler TerrainAtlasChanged;
|
||||
internal void RaiseTerrainAtlasChanged() { Raise( TerrainAtlasChanged ); }
|
||||
|
||||
/// <summary> Raised when the user changed their view/fog distance. </summary>
|
||||
public event EventHandler ViewDistanceChanged;
|
||||
internal void RaiseViewDistanceChanged() { Raise( ViewDistanceChanged ); }
|
||||
|
||||
/// <summary> Raised when the held block is changed by the user or by CPE. </summary>
|
||||
public event EventHandler HeldBlockChanged;
|
||||
internal void RaiseHeldBlockChanged() { Raise( HeldBlockChanged ); }
|
||||
|
||||
/// <summary> Raised when the block permissions(can place or delete a block) for the player change. </summary>
|
||||
public event EventHandler BlockPermissionsChanged;
|
||||
internal void RaiseBlockPermissionsChanged() { Raise( BlockPermissionsChanged ); }
|
||||
|
||||
/// <summary> Raised when a block definition is changed. </summary>
|
||||
public event EventHandler BlockDefinitionChanged;
|
||||
internal void RaiseBlockDefinitionChanged() { Raise( BlockDefinitionChanged ); }
|
||||
|
||||
/// <summary> Raised when the server or a client-side command sends a message. </summary>
|
||||
public event EventHandler<ChatEventArgs> ChatReceived;
|
||||
internal void RaiseChatReceived( string text, CpeMessage type ) {
|
||||
chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); }
|
||||
|
||||
/// <summary> Raised when the user changes chat font to arial or back to bitmapped font,
|
||||
/// also raised when the bitmapped font changes. </summary>
|
||||
public event EventHandler ChatFontChanged;
|
||||
internal void RaiseChatFontChanged() { Raise( ChatFontChanged ); }
|
||||
|
||||
|
||||
/// <summary> Raised when the hack permissions of the player changes. </summary>
|
||||
public event EventHandler HackPermissionsChanged;
|
||||
internal void RaiseHackPermissionsChanged() { Raise( HackPermissionsChanged ); }
|
||||
|
||||
ChatEventArgs chatArgs = new ChatEventArgs();
|
||||
protected void Raise( EventHandler handler ) {
|
||||
if( handler != null )
|
||||
handler( this, EventArgs.Empty );
|
||||
}
|
||||
|
||||
protected void Raise<T>( EventHandler<T> handler, T args ) where T : EventArgs {
|
||||
if( handler != null )
|
||||
handler( this, args );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ChatEventArgs : EventArgs {
|
||||
|
||||
/// <summary> Where this chat message should appear on the screen. </summary>
|
||||
public CpeMessage Type;
|
||||
|
||||
/// <summary> Raw text of the message (including colour codes),
|
||||
/// with code page 437 indices converted to their unicode representations. </summary>
|
||||
public string Text;
|
||||
}
|
||||
}
|
53
ClassicalSharp/Events/MapEvents.cs
Normal file
53
ClassicalSharp/Events/MapEvents.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public class MapEvents : Events {
|
||||
|
||||
/// <summary> Raised when the player joins and begins loading a new map. </summary>
|
||||
public event EventHandler OnNewMap;
|
||||
internal void RaiseOnNewMap() { Raise( OnNewMap ); }
|
||||
|
||||
/// <summary> Raised when a portion of the map is read and decompressed, or generated. </summary>
|
||||
public event EventHandler<MapLoadingEventArgs> MapLoading;
|
||||
internal void RaiseMapLoading( byte progress ) { loadingArgs.Progress = progress; Raise( MapLoading, loadingArgs ); }
|
||||
|
||||
/// <summary> Raised when new map has finished loading and the player can now interact with it. </summary>
|
||||
public event EventHandler OnNewMapLoaded;
|
||||
internal void RaiseOnNewMapLoaded() { Raise( OnNewMapLoaded ); }
|
||||
|
||||
/// <summary> Raised when an environment variable of the map is changed by the user, CPE, or WoM config. </summary>
|
||||
public event EventHandler<EnvVarEventArgs> EnvVariableChanged;
|
||||
internal void RaiseEnvVariableChanged( EnvVar envVar ) { envArgs.Var = envVar; Raise( EnvVariableChanged, envArgs ); }
|
||||
|
||||
MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs();
|
||||
EnvVarEventArgs envArgs = new EnvVarEventArgs();
|
||||
}
|
||||
|
||||
public sealed class MapLoadingEventArgs : EventArgs {
|
||||
|
||||
/// <summary> Percentage of the map that has been fully decompressed, or generated. </summary>
|
||||
public int Progress;
|
||||
}
|
||||
|
||||
public sealed class EnvVarEventArgs : EventArgs {
|
||||
|
||||
/// <summary> Map environment variable that was changed. </summary>
|
||||
public EnvVar Var;
|
||||
}
|
||||
|
||||
public enum EnvVar {
|
||||
SidesBlock,
|
||||
EdgeBlock,
|
||||
EdgeLevel,
|
||||
CloudsLevel,
|
||||
CloudsSpeed,
|
||||
Weather,
|
||||
|
||||
SkyColour,
|
||||
CloudsColour,
|
||||
FogColour,
|
||||
SunlightColour,
|
||||
ShadowlightColour,
|
||||
}
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public sealed class Events {
|
||||
|
||||
/// <summary> Raised when an entity is spawned in the current world. </summary>
|
||||
public event EventHandler<IdEventArgs> EntityAdded;
|
||||
internal void RaiseEntityAdded( byte id ) { idArgs.Id = id; Raise( EntityAdded, idArgs ); }
|
||||
|
||||
/// <summary> Raised when an entity is despawned from the current world. </summary>
|
||||
public event EventHandler<IdEventArgs> EntityRemoved;
|
||||
internal void RaiseEntityRemoved( byte id ) { idArgs.Id = id; Raise( EntityRemoved, idArgs ); }
|
||||
|
||||
/// <summary> Raised when a new CPE player list entry is created. </summary>
|
||||
public event EventHandler<IdEventArgs> CpeListInfoAdded;
|
||||
internal void RaiseCpeListInfoAdded( byte id ) { idArgs.Id = id; Raise( CpeListInfoAdded, idArgs ); }
|
||||
|
||||
/// <summary> Raised when a CPE player list entry is modified. </summary>
|
||||
public event EventHandler<IdEventArgs> CpeListInfoChanged;
|
||||
internal void RaiseCpeListInfoChanged( byte id ) { idArgs.Id = id; Raise( CpeListInfoChanged, idArgs ); }
|
||||
|
||||
/// <summary> Raised when a CPE player list entry is removed. </summary>
|
||||
public event EventHandler<IdEventArgs> CpeListInfoRemoved;
|
||||
internal void RaiseCpeListInfoRemoved( byte id ) { idArgs.Id = id; Raise( CpeListInfoRemoved, idArgs ); }
|
||||
|
||||
|
||||
/// <summary> Raised when the client joins and begins loading a new map. </summary>
|
||||
public event EventHandler OnNewMap;
|
||||
internal void RaiseOnNewMap() { Raise( OnNewMap ); }
|
||||
|
||||
/// <summary> Raised when a portion of the map is read and decompressed by the client. </summary>
|
||||
public event EventHandler<MapLoadingEventArgs> MapLoading;
|
||||
internal void RaiseMapLoading( byte progress ) { loadingArgs.Progress = progress; Raise( MapLoading, loadingArgs ); }
|
||||
|
||||
/// <summary> Raised when the client has finished loading a new map and can now interact with it. </summary>
|
||||
public event EventHandler OnNewMapLoaded;
|
||||
internal void RaiseOnNewMapLoaded() { Raise( OnNewMapLoaded ); }
|
||||
|
||||
|
||||
/// <summary> Raised when the terrain atlas ("terrain.png") is changed. </summary>
|
||||
public event EventHandler TerrainAtlasChanged;
|
||||
internal void RaiseTerrainAtlasChanged() { Raise( TerrainAtlasChanged ); }
|
||||
|
||||
/// <summary> Raised when an environment variable is changed by the user, CPE, or WoM config. </summary>
|
||||
public event EventHandler<EnvVarEventArgs> EnvVariableChanged;
|
||||
internal void RaiseEnvVariableChanged( EnvVar envVar ) { envArgs.Var = envVar; Raise( EnvVariableChanged, envArgs ); }
|
||||
|
||||
/// <summary> Raised when the user changed their view/fog distance. </summary>
|
||||
public event EventHandler ViewDistanceChanged;
|
||||
internal void RaiseViewDistanceChanged() { Raise( ViewDistanceChanged ); }
|
||||
|
||||
/// <summary> Raised when the held block is changed by the user or by CPE. </summary>
|
||||
public event EventHandler HeldBlockChanged;
|
||||
internal void RaiseHeldBlockChanged() { Raise( HeldBlockChanged ); }
|
||||
|
||||
/// <summary> Raised when the client's block permissions(can place or delete a block) change. </summary>
|
||||
public event EventHandler BlockPermissionsChanged;
|
||||
internal void RaiseBlockPermissionsChanged() { Raise( BlockPermissionsChanged ); }
|
||||
|
||||
/// <summary> Raised when the a block definition is changed. </summary>
|
||||
public event EventHandler BlockDefinitionChanged;
|
||||
internal void RaiseBlockDefinitionChanged() { Raise( BlockDefinitionChanged ); }
|
||||
|
||||
/// <summary> Raised when the server or a client-side command sends a message. </summary>
|
||||
public event EventHandler<ChatEventArgs> ChatReceived;
|
||||
internal void RaiseChatReceived( string text, CpeMessage type ) {
|
||||
chatArgs.Type = type; chatArgs.Text = text; Raise( ChatReceived, chatArgs ); }
|
||||
|
||||
/// <summary> Raised when the user changes chat font to arial or back to bitmapped font,
|
||||
/// also raised when the bitmapped font changes. </summary>
|
||||
public event EventHandler ChatFontChanged;
|
||||
internal void RaiseChatFontChanged() { Raise( ChatFontChanged ); }
|
||||
|
||||
|
||||
/// <summary> Raised when the hack permissions of the player changes. </summary>
|
||||
public event EventHandler HackPermissionsChanged;
|
||||
internal void RaiseHackPermissionmsChanged() { Raise( HackPermissionsChanged ); }
|
||||
|
||||
// Cache event instances so we don't create needless new objects.
|
||||
IdEventArgs idArgs = new IdEventArgs();
|
||||
MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs();
|
||||
EnvVarEventArgs envArgs = new EnvVarEventArgs();
|
||||
ChatEventArgs chatArgs = new ChatEventArgs();
|
||||
|
||||
void Raise( EventHandler handler ) {
|
||||
if( handler != null ) {
|
||||
handler( this, EventArgs.Empty );
|
||||
}
|
||||
}
|
||||
|
||||
void Raise<T>( EventHandler<T> handler, T args ) where T : EventArgs {
|
||||
if( handler != null ) {
|
||||
handler( this, args );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class IdEventArgs : EventArgs {
|
||||
|
||||
public byte Id;
|
||||
}
|
||||
|
||||
public sealed class ChatEventArgs : EventArgs {
|
||||
|
||||
/// <summary> Where this chat message should appear on the screen. </summary>
|
||||
public CpeMessage Type;
|
||||
|
||||
/// <summary> Raw text of the message (including colour codes),
|
||||
/// with code page 437 indices converted to their unicode representations. </summary>
|
||||
public string Text;
|
||||
}
|
||||
|
||||
public sealed class MapLoadingEventArgs : EventArgs {
|
||||
|
||||
/// <summary> Percentage of the map that has been fully decompressed by the client. </summary>
|
||||
public int Progress;
|
||||
}
|
||||
|
||||
public sealed class EnvVarEventArgs : EventArgs {
|
||||
|
||||
/// <summary> Map environment variable that was changed. </summary>
|
||||
public EnvVar Var;
|
||||
}
|
||||
|
||||
public enum EnvVar {
|
||||
SidesBlock,
|
||||
EdgeBlock,
|
||||
EdgeLevel,
|
||||
CloudsLevel,
|
||||
CloudsSpeed,
|
||||
Weather,
|
||||
|
||||
SkyColour,
|
||||
CloudsColour,
|
||||
FogColour,
|
||||
SunlightColour,
|
||||
ShadowlightColour,
|
||||
}
|
||||
|
||||
public enum Weather {
|
||||
Sunny,
|
||||
Rainy,
|
||||
Snowy,
|
||||
}
|
||||
}
|
@ -73,6 +73,8 @@ namespace ClassicalSharp {
|
||||
FpsScreen fpsScreen;
|
||||
internal HudScreen hudScreen;
|
||||
public Events Events = new Events();
|
||||
public EntityEvents EntityEvents = new EntityEvents();
|
||||
public MapEvents MapEvents = new MapEvents();
|
||||
public InputHandler InputHandler;
|
||||
public ChatLog Chat;
|
||||
public BlockHandRenderer BlockHandRenderer;
|
||||
|
@ -224,15 +224,14 @@ namespace ClassicalSharp {
|
||||
const int ticksFrequency = 20;
|
||||
const double ticksPeriod = 1.0 / ticksFrequency;
|
||||
const double imageCheckPeriod = 30.0;
|
||||
const double cameraPeriod = 1.0 / 120, audioPeriod = 1.0 / 40;
|
||||
const double cameraPeriod = 1.0 / 120;
|
||||
double ticksAccumulator, imageCheckAccumulator,
|
||||
cameraAccumulator, audioAccumulator;
|
||||
cameraAccumulator;
|
||||
|
||||
void CheckScheduledTasks( double time ) {
|
||||
imageCheckAccumulator += time;
|
||||
ticksAccumulator += time;
|
||||
cameraAccumulator += time;
|
||||
audioAccumulator += time;
|
||||
|
||||
if( imageCheckAccumulator > imageCheckPeriod ) {
|
||||
imageCheckAccumulator -= imageCheckPeriod;
|
||||
@ -255,10 +254,6 @@ namespace ClassicalSharp {
|
||||
Camera.Tick( cameraPeriod );
|
||||
cameraAccumulator -= cameraPeriod;
|
||||
}
|
||||
while( audioAccumulator >= audioPeriod ) {
|
||||
AudioPlayer.Tick( audioPeriod );
|
||||
audioAccumulator -= audioPeriod;
|
||||
}
|
||||
|
||||
if( ticksThisFrame > ticksFrequency / 3 )
|
||||
Utils.LogDebug( "Falling behind (did {0} ticks this frame)", ticksThisFrame );
|
||||
|
@ -89,7 +89,7 @@ namespace ClassicalSharp {
|
||||
FogCol = DefaultFogColour;
|
||||
CloudsCol = DefaultCloudsColour;
|
||||
Weather = Weather.Sunny;
|
||||
game.Events.RaiseOnNewMap();
|
||||
game.MapEvents.RaiseOnNewMap();
|
||||
}
|
||||
|
||||
void ResetLight() {
|
||||
@ -110,7 +110,7 @@ namespace ClassicalSharp {
|
||||
block = Block.Bedrock;
|
||||
}
|
||||
SidesBlock = block;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVar.SidesBlock );
|
||||
game.MapEvents.RaiseEnvVariableChanged( EnvVar.SidesBlock );
|
||||
}
|
||||
|
||||
/// <summary> Sets the edge block to the given block, and raises the
|
||||
@ -122,7 +122,7 @@ namespace ClassicalSharp {
|
||||
block = Block.StillWater;
|
||||
}
|
||||
EdgeBlock = block;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVar.EdgeBlock );
|
||||
game.MapEvents.RaiseEnvVariableChanged( EnvVar.EdgeBlock );
|
||||
}
|
||||
|
||||
/// <summary> Sets the height of the clouds in world space, and raises the
|
||||
@ -157,7 +157,7 @@ namespace ClassicalSharp {
|
||||
Set( col, ref Sunlight, EnvVar.SunlightColour );
|
||||
FastColour.GetShaded( Sunlight, ref SunlightXSide,
|
||||
ref SunlightZSide, ref SunlightYBottom );
|
||||
game.Events.RaiseEnvVariableChanged( EnvVar.SunlightColour );
|
||||
game.MapEvents.RaiseEnvVariableChanged( EnvVar.SunlightColour );
|
||||
}
|
||||
|
||||
/// <summary> Sets the current shadowlight colour, and raises the
|
||||
@ -168,7 +168,7 @@ namespace ClassicalSharp {
|
||||
Set( col, ref Shadowlight, EnvVar.ShadowlightColour );
|
||||
FastColour.GetShaded( Shadowlight, ref ShadowlightXSide,
|
||||
ref ShadowlightZSide, ref ShadowlightYBottom );
|
||||
game.Events.RaiseEnvVariableChanged( EnvVar.ShadowlightColour );
|
||||
game.MapEvents.RaiseEnvVariableChanged( EnvVar.ShadowlightColour );
|
||||
}
|
||||
|
||||
/// <summary> Sets the current weather, and raises the
|
||||
@ -176,13 +176,13 @@ namespace ClassicalSharp {
|
||||
public void SetWeather( Weather weather ) {
|
||||
if( weather == Weather ) return;
|
||||
Weather = weather;
|
||||
game.Events.RaiseEnvVariableChanged( EnvVar.Weather );
|
||||
game.MapEvents.RaiseEnvVariableChanged( EnvVar.Weather );
|
||||
}
|
||||
|
||||
void Set<T>( T value, ref T target, EnvVar var ) where T : IEquatable<T> {
|
||||
if( value.Equals( target ) ) return;
|
||||
target = value;
|
||||
game.Events.RaiseEnvVariableChanged( var );
|
||||
game.MapEvents.RaiseEnvVariableChanged( var );
|
||||
}
|
||||
|
||||
/// <summary> Updates the underlying block array, heightmap, and dimensions of this map. </summary>
|
||||
|
@ -57,11 +57,13 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public enum CpeBlockFace {
|
||||
XMax,
|
||||
XMin,
|
||||
YMax,
|
||||
YMin,
|
||||
ZMax,
|
||||
ZMin,
|
||||
XMax, XMin, YMax,
|
||||
YMin, ZMax, ZMin,
|
||||
}
|
||||
|
||||
public enum Weather {
|
||||
Sunny,
|
||||
Rainy,
|
||||
Snowy,
|
||||
}
|
||||
}
|
||||
|
@ -190,10 +190,10 @@ namespace ClassicalSharp {
|
||||
// Only redraw the CPE player list info if something changed.
|
||||
if( info.PlayerName != oldInfo.PlayerName || info.ListName != oldInfo.ListName ||
|
||||
info.GroupName != oldInfo.GroupName || info.GroupRank != oldInfo.GroupRank ) {
|
||||
game.Events.RaiseCpeListInfoChanged( (byte)nameId );
|
||||
game.EntityEvents.RaiseCpeListInfoChanged( (byte)nameId );
|
||||
}
|
||||
} else {
|
||||
game.Events.RaiseCpeListInfoAdded( (byte)nameId );
|
||||
game.EntityEvents.RaiseCpeListInfoAdded( (byte)nameId );
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ namespace ClassicalSharp {
|
||||
nameId += 256;
|
||||
|
||||
if( nameId >= 0 && nameId <= 255 ) {
|
||||
game.Events.RaiseCpeListInfoRemoved( (byte)nameId );
|
||||
game.EntityEvents.RaiseCpeListInfoRemoved( (byte)nameId );
|
||||
game.CpePlayersList[nameId] = null;
|
||||
}
|
||||
}
|
||||
@ -370,7 +370,7 @@ namespace ClassicalSharp {
|
||||
float jumpHeight = reader.ReadInt16() / 32f;
|
||||
if( jumpHeight < 0 ) jumpHeight = 1.4f;
|
||||
p.CalculateJumpVelocity( jumpHeight );
|
||||
game.Events.RaiseHackPermissionmsChanged();
|
||||
game.Events.RaiseHackPermissionsChanged();
|
||||
}
|
||||
|
||||
void HandleCpeExtAddEntity2() {
|
||||
|
@ -141,7 +141,7 @@ namespace ClassicalSharp {
|
||||
|
||||
reader.Remove( 1024 );
|
||||
byte progress = reader.ReadUInt8();
|
||||
game.Events.RaiseMapLoading( progress );
|
||||
game.MapEvents.RaiseMapLoading( progress );
|
||||
}
|
||||
|
||||
void HandleLevelFinalise() {
|
||||
@ -158,7 +158,7 @@ namespace ClassicalSharp {
|
||||
double loadingMs = ( DateTime.UtcNow - receiveStart ).TotalMilliseconds;
|
||||
Utils.LogDebug( "map loading took:" + loadingMs );
|
||||
game.Map.SetData( map, mapWidth, mapHeight, mapLength );
|
||||
game.Events.RaiseOnNewMapLoaded();
|
||||
game.MapEvents.RaiseOnNewMapLoaded();
|
||||
|
||||
map = null;
|
||||
gzipStream.Dispose();
|
||||
@ -267,12 +267,12 @@ namespace ClassicalSharp {
|
||||
if( entityId != 0xFF ) {
|
||||
Player oldPlayer = game.Players[entityId];
|
||||
if( oldPlayer != null ) {
|
||||
game.Events.RaiseEntityRemoved( entityId );
|
||||
game.EntityEvents.RaiseEntityRemoved( entityId );
|
||||
oldPlayer.Despawn();
|
||||
}
|
||||
game.Players[entityId] = new NetPlayer( displayName, skinName, game, entityId );
|
||||
string identifier = game.Players[entityId].SkinIdentifier;
|
||||
game.Events.RaiseEntityAdded( entityId );
|
||||
game.EntityEvents.RaiseEntityAdded( entityId );
|
||||
game.AsyncDownloader.DownloadSkin( identifier, skinName );
|
||||
} else {
|
||||
game.LocalPlayer.SkinName = skinName;
|
||||
@ -291,13 +291,13 @@ namespace ClassicalSharp {
|
||||
if( player == null ) return;
|
||||
|
||||
if( entityId != 0xFF ) {
|
||||
game.Events.RaiseEntityRemoved( entityId );
|
||||
game.EntityEvents.RaiseEntityRemoved( entityId );
|
||||
player.Despawn();
|
||||
game.Players[entityId] = null;
|
||||
}
|
||||
// See comment about LegendCraft in HandleAddEntity
|
||||
if( needRemoveNames != null && needRemoveNames[entityId] ) {
|
||||
game.Events.RaiseCpeListInfoRemoved( entityId );
|
||||
game.EntityEvents.RaiseCpeListInfoRemoved( entityId );
|
||||
game.CpePlayersList[entityId] = null;
|
||||
needRemoveNames[entityId] = false;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace ClassicalSharp {
|
||||
Disconnected = false;
|
||||
receivedFirstPosition = false;
|
||||
lastPacket = DateTime.UtcNow;
|
||||
game.Events.OnNewMap += OnNewMap;
|
||||
game.MapEvents.OnNewMap += OnNewMap;
|
||||
|
||||
MakeLoginPacket( game.Username, game.Mppass );
|
||||
SendPacket();
|
||||
@ -54,7 +54,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
game.Events.OnNewMap -= OnNewMap;
|
||||
game.MapEvents.OnNewMap -= OnNewMap;
|
||||
socket.Close();
|
||||
Disconnected = true;
|
||||
}
|
||||
@ -217,7 +217,7 @@ namespace ClassicalSharp {
|
||||
// wipe all existing entity states
|
||||
for( int i = 0; i < 256; i++ ) {
|
||||
if( game.CpePlayersList[i] != null ) {
|
||||
game.Events.RaiseCpeListInfoRemoved( (byte)i );
|
||||
game.EntityEvents.RaiseCpeListInfoRemoved( (byte)i );
|
||||
game.CpePlayersList[i] = null;
|
||||
}
|
||||
RemoveEntity( (byte)i );
|
||||
|
@ -11,9 +11,9 @@ namespace ClassicalSharp.Renderers {
|
||||
|
||||
public virtual void Init() {
|
||||
graphics = game.Graphics;
|
||||
game.Events.OnNewMap += OnNewMap;
|
||||
game.Events.OnNewMapLoaded += OnNewMapLoaded;
|
||||
game.Events.EnvVariableChanged += EnvVariableChanged;
|
||||
game.MapEvents.OnNewMap += OnNewMap;
|
||||
game.MapEvents.OnNewMapLoaded += OnNewMapLoaded;
|
||||
game.MapEvents.EnvVariableChanged += EnvVariableChanged;
|
||||
}
|
||||
|
||||
public virtual void OnNewMap( object sender, EventArgs e ) {
|
||||
@ -23,9 +23,9 @@ namespace ClassicalSharp.Renderers {
|
||||
}
|
||||
|
||||
public virtual void Dispose() {
|
||||
game.Events.OnNewMap -= OnNewMap;
|
||||
game.Events.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
game.Events.EnvVariableChanged -= EnvVariableChanged;
|
||||
game.MapEvents.OnNewMap -= OnNewMap;
|
||||
game.MapEvents.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
game.MapEvents.EnvVariableChanged -= EnvVariableChanged;
|
||||
}
|
||||
|
||||
public abstract void Render( double deltaTime );
|
||||
|
@ -29,9 +29,9 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
game.Events.OnNewMap += OnNewMap;
|
||||
game.Events.OnNewMapLoaded += OnNewMapLoaded;
|
||||
game.Events.EnvVariableChanged += EnvVariableChanged;
|
||||
game.MapEvents.OnNewMap += OnNewMap;
|
||||
game.MapEvents.OnNewMapLoaded += OnNewMapLoaded;
|
||||
game.MapEvents.EnvVariableChanged += EnvVariableChanged;
|
||||
game.Events.ViewDistanceChanged += ResetSidesAndEdges;
|
||||
game.Events.TerrainAtlasChanged += ResetTextures;
|
||||
|
||||
@ -68,9 +68,9 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
game.Events.OnNewMap -= OnNewMap;
|
||||
game.Events.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
game.Events.EnvVariableChanged -= EnvVariableChanged;
|
||||
game.MapEvents.OnNewMap -= OnNewMap;
|
||||
game.MapEvents.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
game.MapEvents.EnvVariableChanged -= EnvVariableChanged;
|
||||
game.Events.ViewDistanceChanged -= ResetSidesAndEdges;
|
||||
game.Events.TerrainAtlasChanged -= ResetTextures;
|
||||
|
||||
|
@ -48,9 +48,9 @@ namespace ClassicalSharp {
|
||||
info = game.BlockInfo;
|
||||
|
||||
game.Events.TerrainAtlasChanged += TerrainAtlasChanged;
|
||||
game.Events.OnNewMap += OnNewMap;
|
||||
game.Events.OnNewMapLoaded += OnNewMapLoaded;
|
||||
game.Events.EnvVariableChanged += EnvVariableChanged;
|
||||
game.MapEvents.OnNewMap += OnNewMap;
|
||||
game.MapEvents.OnNewMapLoaded += OnNewMapLoaded;
|
||||
game.MapEvents.EnvVariableChanged += EnvVariableChanged;
|
||||
game.Events.BlockDefinitionChanged += BlockDefinitionChanged;
|
||||
}
|
||||
|
||||
@ -59,10 +59,10 @@ namespace ClassicalSharp {
|
||||
chunks = null;
|
||||
unsortedChunks = null;
|
||||
game.Events.TerrainAtlasChanged -= TerrainAtlasChanged;
|
||||
game.Events.OnNewMap -= OnNewMap;
|
||||
game.Events.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
game.Events.EnvVariableChanged -= EnvVariableChanged;
|
||||
game.Events.BlockDefinitionChanged -= BlockDefinitionChanged;
|
||||
game.MapEvents.OnNewMap -= OnNewMap;
|
||||
game.MapEvents.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
game.MapEvents.EnvVariableChanged -= EnvVariableChanged;
|
||||
game.MapEvents.BlockDefinitionChanged -= BlockDefinitionChanged;
|
||||
builder.Dispose();
|
||||
}
|
||||
|
||||
|
@ -111,13 +111,13 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
game.Events.OnNewMap += OnNewMap;
|
||||
game.Events.OnNewMapLoaded += OnNewMapLoaded;
|
||||
game.MapEvents.OnNewMap += OnNewMap;
|
||||
game.MapEvents.OnNewMapLoaded += OnNewMapLoaded;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
game.Events.OnNewMap -= OnNewMap;
|
||||
game.Events.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
game.MapEvents.OnNewMap -= OnNewMap;
|
||||
game.MapEvents.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
graphics.DeleteDynamicVb( weatherVb );
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ namespace ClassicalSharp.Selections {
|
||||
public SelectionManager( Game window ) {
|
||||
game = window;
|
||||
Graphics = window.Graphics;
|
||||
window.Events.OnNewMap += OnNewMap;
|
||||
window.MapEvents.OnNewMap += OnNewMap;
|
||||
}
|
||||
|
||||
List<SelectionBox> selections = new List<SelectionBox>( 256 );
|
||||
@ -69,7 +69,7 @@ namespace ClassicalSharp.Selections {
|
||||
|
||||
public void Dispose() {
|
||||
OnNewMap( null, null );
|
||||
game.Events.OnNewMap -= OnNewMap;
|
||||
game.MapEvents.OnNewMap -= OnNewMap;
|
||||
if( lineVb > 0 ) {
|
||||
Graphics.DeleteDynamicVb( vb );
|
||||
Graphics.DeleteDynamicVb( lineVb );
|
||||
|
@ -26,7 +26,7 @@ namespace ClassicalSharp.Singleplayer {
|
||||
this.game = game;
|
||||
map = game.Map;
|
||||
info = game.BlockInfo;
|
||||
game.Events.OnNewMapLoaded += ResetMap;
|
||||
game.MapEvents.OnNewMapLoaded += ResetMap;
|
||||
enabled = Options.GetBool( OptionsKey.SingleplayerPhysics, true );
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ namespace ClassicalSharp.Singleplayer {
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
game.Events.OnNewMapLoaded -= ResetMap;
|
||||
game.MapEvents.OnNewMapLoaded -= ResetMap;
|
||||
}
|
||||
|
||||
#region General
|
||||
|
@ -89,7 +89,7 @@ namespace ClassicalSharp.Singleplayer {
|
||||
generator.Height, generator.Length );
|
||||
generatedMap = null;
|
||||
|
||||
game.Events.RaiseOnNewMapLoaded();
|
||||
game.MapEvents.RaiseOnNewMapLoaded();
|
||||
ResetPlayerPosition();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user