More code XML comments.

This commit is contained in:
UnknownShadow200 2015-08-29 11:54:55 +10:00
parent ffa96b651b
commit dab0e31bfc
20 changed files with 105 additions and 123 deletions

View File

@ -2,6 +2,7 @@
namespace ClassicalSharp {
/// <summary> Stores various properties about the blocks in Minecraft Classic. </summary>
public partial class BlockInfo {
internal bool[] isTransparent = new bool[BlocksCount];

View File

@ -2,6 +2,8 @@
namespace ClassicalSharp.Commands {
/// <summary> Reads and parses arguments for a client command. </summary>
/// <remarks> Spaces are designated as the argument separators. </remarks>
public class CommandReader {
string rawInput;
@ -16,7 +18,7 @@ namespace ClassicalSharp.Commands {
}
string arg = rawInput.Substring( curOffset, next - curOffset );
curOffset = next + 1; // skip space
curOffset = next + 1; // skip following space
return arg;
}

View File

@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.IO;
using System.Text;
using ClassicalSharp.Renderers;
using System;
using System.Collections.Generic;
using System.Text;
using ClassicalSharp.Renderers;
namespace ClassicalSharp.Commands {
/// <summary> Command that displays the list of all currently registered client commands. </summary>
public sealed class CommandsCommand : Command {
public CommandsCommand() {
@ -38,6 +36,7 @@ namespace ClassicalSharp.Commands {
}
}
/// <summary> Command that modifies various aspects of the environment of the current map. </summary>
public sealed class EnvCommand : Command {
public EnvCommand() {
@ -100,6 +99,7 @@ namespace ClassicalSharp.Commands {
}
}
/// <summary> Command that displays information about an input client command. </summary>
public sealed class HelpCommand : Command {
public HelpCommand() {
@ -209,6 +209,7 @@ namespace ClassicalSharp.Commands {
}
}
/// <summary> Command that modifies the font size of chat in the normal gui screen. </summary>
public sealed class ChatFontSizeCommand : Command {
public ChatFontSizeCommand() {
@ -239,6 +240,7 @@ namespace ClassicalSharp.Commands {
}
}
/// <summary> Command that modifies how sensitive the client is to changes in the mouse position. </summary>
public sealed class MouseSensitivityCommand : Command {
public MouseSensitivityCommand() {
@ -261,6 +263,7 @@ namespace ClassicalSharp.Commands {
}
}
/// <summary> Command that modifies how far the client can see. </summary>
public sealed class ViewDistanceCommand : Command {
public ViewDistanceCommand() {

View File

@ -1,9 +1,10 @@
using System;
using ClassicalSharp.Model;
using OpenTK;
namespace ClassicalSharp {
/// <summary> Stores data that describes either a relative position,
/// full position, or an orientation update for an entity. </summary>
public struct LocationUpdate {
public Vector3 Pos;

View File

@ -1,6 +1,6 @@
using System;
using ClassicalSharp.Renderers;
using OpenTK;
using System;
using ClassicalSharp.Renderers;
using OpenTK;
namespace ClassicalSharp {

View File

@ -38,7 +38,7 @@ namespace ClassicalSharp {
LogChatToFile( text );
chatArgs.Text = text;
chatArgs.Type = CpeMessage.Normal;
RaiseEvent( ChatReceived, chatArgs );
Raise( ChatReceived, chatArgs );
}
ChatEventArgs chatArgs = new ChatEventArgs();
@ -63,7 +63,7 @@ namespace ClassicalSharp {
}
chatArgs.Text = text;
chatArgs.Type = type;
RaiseEvent( ChatReceived, chatArgs );
Raise( ChatReceived, chatArgs );
}
DateTime last = new DateTime( 1, 1, 1 );

View File

@ -1,104 +1,78 @@
using System;
using ClassicalSharp;
using OpenTK;
using System;
namespace ClassicalSharp {
public partial class Game {
/// <summary> Raised when a player is spawned in the current world. </summary>
/// <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 a player is despawned from the current world. </summary>
/// <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;
/// <summary> Raised when an environment variable is changed by the user, CPE, or WoM config. </summary>
public event EventHandler<EnvVariableEventArgs> EnvVariableChanged;
internal void RaiseEnvVariableChanged( EnvVariable envVar ) { envArgs.Var = envVar; Raise( EnvVariableChanged, envArgs ); }
/// <summary> Raised when the user changed their view/fog distance. </summary>
public event EventHandler ViewDistanceChanged;
public event EventHandler OnNewMap;
public event EventHandler OnNewMapLoaded;
/// <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 terrain atlas("terrain.png") is changed. </summary>
public event EventHandler TerrainAtlasChanged;
public event EventHandler<ChatEventArgs> ChatReceived;
internal void RaiseOnNewMap() {
RaiseEvent( OnNewMap );
}
internal void RaiseHeldBlockChanged() {
RaiseEvent( HeldBlockChanged );
}
/// <summary> Raised when the server or a client-side command sends a message. </summary>
public event EventHandler<ChatEventArgs> ChatReceived;
// Cache event instances so we don't create needless new objects.
IdEventArgs idArgs = new IdEventArgs( 0 );
internal void RaiseEntityAdded( byte id ) {
idArgs.Id = id;
RaiseEvent( EntityAdded, idArgs );
}
internal void RaiseEntityRemoved( byte id ) {
idArgs.Id = id;
RaiseEvent( EntityRemoved, idArgs );
}
internal void RaiseCpeListInfoAdded( byte id ) {
idArgs.Id = id;
RaiseEvent( CpeListInfoAdded, idArgs );
}
internal void RaiseCpeListInfoChanged( byte id ) {
idArgs.Id = id;
RaiseEvent( CpeListInfoChanged, idArgs );
}
internal void RaiseCpeListInfoRemoved( byte id ) {
idArgs.Id = id;
RaiseEvent( CpeListInfoRemoved, idArgs );
}
internal void RaiseBlockPermissionsChanged() {
RaiseEvent( BlockPermissionsChanged );
}
internal void RaiseOnNewMapLoaded() {
RaiseEvent( OnNewMapLoaded );
}
MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs( 0 );
internal void RaiseMapLoading( byte progress ) {
loadingArgs.Progress = progress;
RaiseEvent( MapLoading, loadingArgs );
}
MapLoadingEventArgs loadingArgs = new MapLoadingEventArgs( 0 );
EnvVariableEventArgs envArgs = new EnvVariableEventArgs( 0 );
internal void RaiseEnvVariableChanged( EnvVariable variable ) {
envArgs.Variable = variable;
RaiseEvent( EnvVariableChanged, envArgs );
}
void RaiseEvent( EventHandler handler ) {
void Raise( EventHandler handler ) {
if( handler != null ) {
handler( this, EventArgs.Empty );
}
}
void RaiseEvent<T>( EventHandler<T> handler, T args ) where T : EventArgs {
void Raise<T>( EventHandler<T> handler, T args ) where T : EventArgs {
if( handler != null ) {
handler( this, args );
}
@ -132,10 +106,10 @@ namespace ClassicalSharp {
public sealed class EnvVariableEventArgs : EventArgs {
public EnvVariable Variable;
public EnvVariable Var;
public EnvVariableEventArgs( EnvVariable variable ) {
Variable = variable;
Var = variable;
}
}

View File

@ -103,7 +103,7 @@ namespace ClassicalSharp {
public void ChangeTerrainAtlas( Bitmap newAtlas ) {
LoadAtlas( newAtlas );
RaiseEvent( TerrainAtlasChanged );
Raise( TerrainAtlasChanged );
}
void PrintGraphicsInfo() {
@ -172,7 +172,7 @@ namespace ClassicalSharp {
public void SetViewDistance( int distance ) {
ViewDistance = distance;
Utils.LogDebug( "setting view distance to: " + distance );
RaiseEvent( ViewDistanceChanged );
Raise( ViewDistanceChanged );
UpdateProjection();
}

View File

@ -8,10 +8,11 @@ using OpenTK.Graphics.OpenGL;
namespace ClassicalSharp.GraphicsAPI {
/// <summary> Abstracts a 3D graphics rendering API. </summary>
/// <remarks> Only Direct3D9 and OpenGL support are implemented. </remarks>
public abstract class IGraphicsApi {
/// <summary> Maximum supported length of a dimension
/// (i.e. max width and max height) in a 2D texture. </summary>
/// <summary> Maximum supported length of a dimension (width and height) of a 2D texture. </summary>
public abstract int MaxTextureDimensions { get; }
public abstract bool Texturing { set; }
@ -227,7 +228,7 @@ namespace ClassicalSharp.GraphicsAPI {
AlphaBlending = false;
}
public unsafe int MakeDefaultIb() {
internal unsafe int MakeDefaultIb() {
const int maxIndices = 65536 / 4 * 6;
int element = 0;
ushort* indices = stackalloc ushort[maxIndices];

View File

@ -18,6 +18,7 @@ namespace ClassicalSharp.GraphicsAPI {
textureDimensions = texDims;
string extensions = new String( (sbyte*)GL.GetString( StringName.Extensions ) );
// NOTE: Not sure if there are any >= 1.5 drivers that support vbos but don't expose the ARB extension.
if( !extensions.Contains( "GL_ARB_vertex_buffer_object" ) ) {
Utils.LogError( "ClassicalSharp post 0.6 version requires OpenGL VBOs." );
Utils.LogWarning( "You may need to install and/or update your video card drivers." );

View File

@ -31,11 +31,11 @@ namespace ClassicalSharp.Renderers {
public abstract void Render( double deltaTime );
void EnvVariableChanged( object sender, EnvVariableEventArgs e ) {
if( e.Variable == EnvVariable.SkyColour ) {
if( e.Var == EnvVariable.SkyColour ) {
SkyColourChanged();
} else if( e.Variable == EnvVariable.FogColour ) {
} else if( e.Var == EnvVariable.FogColour ) {
FogColourChanged();
} else if( e.Variable == EnvVariable.CloudsColour ) {
} else if( e.Var == EnvVariable.CloudsColour ) {
CloudsColourChanged();
}
}

View File

@ -89,11 +89,11 @@ namespace ClassicalSharp {
}
void EnvVariableChanged( object sender, EnvVariableEventArgs e ) {
if( e.Variable == EnvVariable.EdgeBlock ) {
if( e.Var == EnvVariable.EdgeBlock ) {
MakeTexture( ref edgeTexId, ref lastEdgeTexLoc, Map.EdgeBlock );
} else if( e.Variable == EnvVariable.SidesBlock ) {
} else if( e.Var == EnvVariable.SidesBlock ) {
MakeTexture( ref sideTexId, ref lastSideTexLoc, Map.SidesBlock );
} else if( e.Variable == EnvVariable.WaterLevel ) {
} else if( e.Var == EnvVariable.WaterLevel ) {
ResetSidesAndEdges( null, null );
}
}

View File

@ -66,7 +66,7 @@ namespace ClassicalSharp {
}
void EnvVariableChanged( object sender, EnvVariableEventArgs e ) {
if( e.Variable == EnvVariable.SunlightColour || e.Variable == EnvVariable.ShadowlightColour ) {
if( e.Var == EnvVariable.SunlightColour || e.Var == EnvVariable.ShadowlightColour ) {
Refresh();
}
}

View File

@ -4,6 +4,7 @@ using System.Drawing.Imaging;
namespace ClassicalSharp {
/// <summary> Wrapper around a bitmap that allows extremely fast manipulation of 32bpp images. </summary>
public unsafe class FastBitmap : IDisposable {
public FastBitmap( Bitmap bmp, bool lockBits ) {
@ -57,19 +58,19 @@ namespace ClassicalSharp {
}
}
public int GetPixel( int x, int y ) {
// TODO: Does this work with big-endian systems?
int* row = (int*)( scan0Byte + ( y * Stride ) );
return row[x]; // b g r a
}
/// <summary> Returns a pointer to the start of the y'th scanline. </summary>
public int* GetRowPtr( int y ) {
return (int*)( scan0Byte + ( y * Stride ) );
}
public void SetPixel( int x, int y, int col ) {
int* row = (int*)( scan0Byte + ( y * Stride ) );
row[x] = col;
internal static void MovePortion( int srcX, int srcY, int dstX, int dstY, FastBitmap src, FastBitmap dst, int size ) {
for( int y = 0; y < size; y++ ) {
int* srcRow = src.GetRowPtr( srcY + y );
int* dstRow = dst.GetRowPtr( dstY + y );
for( int x = 0; x < size; x++ ) {
dstRow[dstX + x] = srcRow[srcX + x];
}
}
}
}
}

View File

@ -1,9 +1,10 @@
using System;
using System.Drawing;
using OpenTK.Graphics;
using System;
using System.Drawing;
namespace ClassicalSharp {
/// <summary> Structure that can be used for quick manipulations of A/R/G/B colours. </summary>
/// <remarks> This structure is **not** suitable for interop with OpenGL or Direct3D. </remarks>
public struct FastColour {
public byte A, R, G, B;

View File

@ -4,7 +4,8 @@ using ClassicalSharp.GraphicsAPI;
namespace ClassicalSharp {
public class TerrainAtlas1D : IDisposable {
/// <summary> Represents a 2D packed texture atlas that has been converted into an array of 1D atlases. </summary>
public sealed class TerrainAtlas1D : IDisposable {
int usedElementsPerAtlas1D;
internal int elementsPerBitmap;
@ -52,7 +53,7 @@ namespace ClassicalSharp {
for( int y_1D = 0; y_1D < usedElementsPerAtlas1D; y_1D++ ) {
int x = index & 0x0F;
int y = index >> 4;
Utils.MovePortion( x * elemSize, y * elemSize, 0, y_1D * elemSize, atlas, dst, elemSize );
FastBitmap.MovePortion( x * elemSize, y * elemSize, 0, y_1D * elemSize, atlas, dst, elemSize );
index++;
}
TexIds[i] = graphics.CreateTexture( dst );

View File

@ -14,6 +14,7 @@ namespace ClassicalSharp {
public const int Sides = 6;
}
/// <summary> Represents a 2D packed texture atlas, specifically for terrain.png. </summary>
public class TerrainAtlas2D : IDisposable {
public const int ElementsPerRow = 16, RowsCount = 16;
@ -40,10 +41,12 @@ namespace ClassicalSharp {
public int LoadTextureElement( int index ) {
int x = index & 0x0F;
int y = index >> 4;
int size = elementSize;
using( FastBitmap atlas = new FastBitmap( AtlasBitmap, true ) ) {
using( Bitmap bmp = new Bitmap( elementSize, elementSize ) ) {
using( Bitmap bmp = new Bitmap( size, size ) ) {
using( FastBitmap dst = new FastBitmap( bmp, true ) ) {
Utils.MovePortion( x * elementSize, y * elementSize, 0, 0, atlas, dst, elementSize );
FastBitmap.MovePortion( x * size, y * size, 0, 0, atlas, dst, size );
return graphics.CreateTexture( dst );
}
}
@ -67,15 +70,16 @@ namespace ClassicalSharp {
static ushort[] rowFlags = { 0xFFFF, 0xFFEE, 0xFFE0, 0xFFE0, 0xFFFF, 0xFA00 };
void MakeOptimisedTexture( FastBitmap atlas ) {
int srcIndex = 0, destIndex = 0;
int size = elementSize;
for( int y = 0; y < 6; y++ ) {
int flags = rowFlags[y];
for( int x = 0; x < ElementsPerRow; x++ ) {
bool isUsed = ( flags & 1 << ( 15 - x ) ) != 0;
if( isUsed && srcIndex != destIndex ) {
int dstX = ( destIndex & 0x0F ) * elementSize;
int dstY = ( destIndex >> 4 ) * elementSize;
Utils.MovePortion( x * elementSize, y * elementSize, dstX, dstY, atlas, atlas, elementSize );
int dstX = ( destIndex & 0x0F ) * size;
int dstY = ( destIndex >> 4 ) * size;
FastBitmap.MovePortion( x * size, y * size, dstX, dstY, atlas, atlas, size );
}
srcIndex++;

View File

@ -2,6 +2,7 @@
namespace ClassicalSharp {
/// <summary> Stores the four texture coordinates that bound a textured quad. </summary>
public struct TextureRectangle {
public float U1, V1, U2, V2;

View File

@ -239,15 +239,5 @@ namespace ClassicalSharp {
throw new NotSupportedException( "unsupported skin dimensions: " + bmp.Width + ", " + bmp.Height );
}
}
internal unsafe static void MovePortion( int srcX, int srcY, int dstX, int dstY, FastBitmap src, FastBitmap dst, int size ) {
for( int y = 0; y < size; y++ ) {
int* srcRow = src.GetRowPtr( srcY + y );
int* dstRow = dst.GetRowPtr( dstY + y );
for( int x = 0; x < size; x++ ) {
dstRow[dstX + x] = srcRow[srcX + x];
}
}
}
}
}

View File

@ -3,6 +3,7 @@ using OpenTK;
namespace ClassicalSharp {
/// <summary> Represents a 3D integer vector. </summary>
public struct Vector3I {
public static Vector3I Zero = new Vector3I( 0, 0, 0 );