Modularise game class somewhat, start commenting the fields/properties of game class.

This commit is contained in:
UnknownShadow200 2015-11-28 20:20:04 +11:00
parent 1171ee9b61
commit b83a5228f8
9 changed files with 178 additions and 108 deletions

View File

@ -66,8 +66,8 @@ namespace ClassicalSharp {
}
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
blockSize = (int)(50 * Math.Sqrt(game.GuiScale()));
selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale()));
blockSize = (int)(50 * Math.Sqrt(game.GuiScale));
selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale));
startX = game.Width / 2 - (blockSize * blocksPerRow) / 2;
startY = game.Height / 2 - (rows * blockSize) / 2;
@ -76,8 +76,8 @@ namespace ClassicalSharp {
}
public override void Init() {
blockSize = (int)(50 * Math.Sqrt(game.GuiScale()));
selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale()));
blockSize = (int)(50 * Math.Sqrt(game.GuiScale));
selBlockExpand = (float)(25 * Math.Sqrt(game.GuiScale));
game.Events.BlockPermissionsChanged += BlockPermissionsChanged;
RecreateBlockTextures();
}

View File

@ -79,16 +79,16 @@ namespace ClassicalSharp {
Font chatFont, chatInputFont, chatUnderlineFont, announcementFont;
public override void Init() {
int fontSize = (int)(12 * game.GuiScale() * game.ChatScale);
int fontSize = (int)(12 * game.GuiScale * game.ChatScale);
Utils.Clamp( ref fontSize, 8, 60 );
chatFont = new Font( "Arial", fontSize );
chatInputFont = new Font( "Arial", fontSize, FontStyle.Bold );
chatUnderlineFont = new Font( "Arial", fontSize, FontStyle.Underline );
fontSize = (int)(14 * game.GuiScale());
fontSize = (int)(14 * game.GuiScale);
Utils.Clamp( ref fontSize, 8, 60 );
announcementFont = new Font( "Arial", fontSize );
blockSize = (int)(40 * game.GuiScale());
blockSize = (int)(40 * game.GuiScale);
textInput = new TextInputWidget( game, chatFont, chatInputFont );
textInput.YOffset = blockSize + 5;
@ -182,7 +182,7 @@ namespace ClassicalSharp {
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
announcementTex.X1 += (width - oldWidth) / 2;
announcementTex.Y1 += (height - oldHeight) / 2;
blockSize = (int)(40 * game.GuiScale());
blockSize = (int)(40 * game.GuiScale);
textInput.YOffset = blockSize + 5;
bottomRight.YOffset = blockSize * 3 / 2;

View File

@ -29,8 +29,8 @@ namespace ClassicalSharp {
static FastColour outlineCol = new FastColour( 151, 120, 180 );
static FastColour selCol = new FastColour( 213, 200, 223 );
public override void Init() {
blockSize = (int)(38 * game.GuiScale());
borderSize = (int)(3 * game.GuiScale());
blockSize = (int)(38 * game.GuiScale);
borderSize = (int)(3 * game.GuiScale);
int width = blockSize * hotbarCount;
X = game.Width / 2 - width / 2;
Y = game.Height - blockSize;

View File

@ -139,6 +139,7 @@
<Compile Include="Entities\LocalPlayer.cs" />
<Compile Include="Entities\LocationUpdate.cs" />
<Compile Include="Entities\NetPlayer.cs" />
<Compile Include="Game\Game.Properties.cs" />
<Compile Include="Particles\CollidableParticle.cs" />
<Compile Include="Particles\Particle.cs" />
<Compile Include="Particles\ParticleManager.cs" />

View File

@ -16,6 +16,9 @@ namespace ClassicalSharp {
public byte UserType;
public bool PushbackBlockPlacing;
/// <summary> Whether the player is allowed to use the types of cameras that use third person. </summary>
public bool CanUseThirdPersonCamera = true;
/// <summary> Whether the player is allowed to increase its speed beyond the normal walking speed. </summary>
public bool CanSpeed = true;
@ -228,10 +231,10 @@ namespace ClassicalSharp {
string joined = name + motd;
if( joined.Contains( "-hax" ) ) {
CanFly = CanNoclip = CanRespawn = CanSpeed =
CanPushbackBlocks = game.CanUseThirdPersonCamera = false;
CanPushbackBlocks = CanUseThirdPersonCamera = false;
} else { // By default (this is also the case with WoM), we can use hacks.
CanFly = CanNoclip = CanRespawn = CanSpeed =
CanPushbackBlocks = game.CanUseThirdPersonCamera = true;
CanPushbackBlocks = CanUseThirdPersonCamera = true;
}
ParseFlag( b => CanFly = b, joined, "fly" );
@ -260,7 +263,7 @@ namespace ClassicalSharp {
if( !CanSpeed) speeding = false;
if( !CanPushbackBlocks ) PushbackBlockPlacing = false;
if( !game.CanUseThirdPersonCamera )
if( !CanUseThirdPersonCamera )
game.SetCamera( false );
}

View File

@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Net;
using ClassicalSharp.Audio;
using ClassicalSharp.Commands;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Model;
using ClassicalSharp.Network;
using ClassicalSharp.Particles;
using ClassicalSharp.Renderers;
using ClassicalSharp.Selections;
using ClassicalSharp.TexturePack;
using OpenTK;
namespace ClassicalSharp {
public partial class Game : GameWindow {
/// <summary> Abstracts the underlying 3D graphics rendering API. </summary>
public IGraphicsApi Graphics;
/// <summary> Contains the block data and metadata of the player's current world. </summary>
public Map Map;
/// <summary> Represents a connection to a multiplayer or a singleplayer server. </summary>
public INetworkProcessor Network;
/// <summary> List of all entities in the current map, including the player. </summary>
public EntityList Players;
/// <summary> Entity representing the player. </summary>
public LocalPlayer LocalPlayer;
/// <summary> Contains extended player listing information for each player in the current world. </summary>
/// <remarks> Only used if CPE extension ExtPlayerList is enabled. </remarks>
public CpeListInfo[] CpePlayersList = new CpeListInfo[256];
/// <summary> Current camera the player is using to view the world with. </summary>
/// <remarks> e.g. first person, thid person, forward third person, etc. </remarks>
public Camera Camera;
Camera firstPersonCam, thirdPersonCam, forwardThirdPersonCam;
/// <summary> Contains the metadata about each currently defined block. </summary>
/// <remarks> e.g. blocks light, height, texture IDs, etc. </remarks>
public BlockInfo BlockInfo;
/// <summary> Total rendering time(in seconds) elapsed since the client was started. </summary>
public double accumulator;
public TerrainAtlas2D TerrainAtlas;
public TerrainAtlas1D TerrainAtlas1D;
public SkinType DefaultPlayerSkinType;
/// <summary> Accumulator for the number of chunk updates performed. Reset every second. </summary>
public int ChunkUpdates;
public MapRenderer MapRenderer;
public MapBordersRenderer MapBordersRenderer;
public EnvRenderer EnvRenderer;
public WeatherRenderer WeatherRenderer;
public Inventory Inventory;
public IDrawer2D Drawer2D;
public CommandManager CommandManager;
public SelectionManager SelectionManager;
public ParticleManager ParticleManager;
public PickingRenderer Picking;
public PickedPos SelectedPos = new PickedPos();
public ModelCache ModelCache;
internal string skinServer, chatInInputBuffer = null;
internal int defaultIb;
FpsScreen fpsScreen;
internal HudScreen hudScreen;
public Events Events = new Events();
public InputHandler InputHandler;
public ChatLog Chat;
public BlockHandRenderer BlockHandRenderer;
public AudioManager AudioManager;
/// <summary> Account username of the player. </summary>
public string Username;
/// <summary> Verification key used for multiplayer, unique for the username and individual server. </summary>
public string Mppass;
/// <summary> IP address of multiplayer server connected to, null if singleplayer. </summary>
public IPAddress IPAddress;
/// <summary> Port of multiplayer server connected to, 0 if singleplayer. </summary>
public int Port;
/// <summary> Radius of the sphere the player can see around the position of the current camera. </summary>
public int ViewDistance = 512;
/// <summary> Field of view for the current camera in degrees. </summary>
public int FieldOfView = 70;
/// <summary> Strategy used to limit how many frames should be displayed at most each second. </summary>
public FpsLimitMethod FpsLimit;
public long Vertices;
public FrustumCulling Culling;
int width, height;
public AsyncDownloader AsyncDownloader;
public Matrix4 View, Projection, HeldBlockProjection;
/// <summary> How sensitive the client is to changes in the player's mouse position. </summary>
public int MouseSensitivity = 30;
public int ChatLines = 12;
public bool ClickableChat, HideGui, ShowFPS = true;
internal float HudScale = 1.0f, ChatScale = 1.0f;
public bool ViewBobbing, UseGuiPng;
public bool UseSound, UseMusic;
public Animations Animations;
internal int CloudsTextureId, RainTextureId, SnowTextureId;
internal bool screenshotRequested;
internal List<WarningScreen> WarningScreens = new List<WarningScreen>();
internal AcceptedUrls AcceptedUrls = new AcceptedUrls();
/// <summary> Calculates the amount that 2D widgets should be scaled by when rendered. </summary>
/// <remarks> Affected by both the current resolution of the window, as well as the
/// scaling specified by the user (field HudScale). </remarks>
public float GuiScale {
get {
float scaleX = Width / 640f, scaleY = Height / 480f;
return Math.Min( scaleX, scaleY ) * HudScale;
}
}
string defTexturePack = "default.zip";
/// <summary> Gets or sets the path of the default texture pack that should be used by the client. </summary>
/// <remarks> If the custom default texture pack specified by the user could not be found,
/// this method returns "default.zip". </remarks>
public string DefaultTexturePack {
get {
return File.Exists( defTexturePack )
? defTexturePack : "default.zip"; }
set {
defTexturePack = value;
Options.Set( OptionsKey.DefaultTexturePack, value );
}
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Net;
@ -20,90 +19,7 @@ using OpenTK.Input;
namespace ClassicalSharp {
public partial class Game : GameWindow {
public IGraphicsApi Graphics;
public Map Map;
public INetworkProcessor Network;
public EntityList Players;
public CpeListInfo[] CpePlayersList = new CpeListInfo[256];
public LocalPlayer LocalPlayer;
public Camera Camera;
Camera firstPersonCam, thirdPersonCam, forwardThirdPersonCam;
public BlockInfo BlockInfo;
public double accumulator;
public TerrainAtlas2D TerrainAtlas;
public TerrainAtlas1D TerrainAtlas1D;
public SkinType DefaultPlayerSkinType;
public int ChunkUpdates;
public MapRenderer MapRenderer;
public MapBordersRenderer MapBordersRenderer;
public EnvRenderer EnvRenderer;
public WeatherRenderer WeatherRenderer;
public Inventory Inventory;
public IDrawer2D Drawer2D;
public CommandManager CommandManager;
public SelectionManager SelectionManager;
public ParticleManager ParticleManager;
public PickingRenderer Picking;
public PickedPos SelectedPos = new PickedPos();
public ModelCache ModelCache;
internal string skinServer, chatInInputBuffer = null;
internal int defaultIb;
public bool CanUseThirdPersonCamera = true;
FpsScreen fpsScreen;
internal HudScreen hudScreen;
public Events Events = new Events();
public InputHandler InputHandler;
public ChatLog Chat;
public BlockHandRenderer BlockHandRenderer;
public AudioManager AudioManager;
public IPAddress IPAddress;
public string Username;
public string Mppass;
public int Port;
public int ViewDistance = 512;
public int FieldOfView = 70;
public FpsLimitMethod FpsLimit;
public long Vertices;
public FrustumCulling Culling;
int width, height;
public AsyncDownloader AsyncDownloader;
public Matrix4 View, Projection, HeldBlockProjection;
public int MouseSensitivity = 30;
public int ChatLines = 12;
public bool ClickableChat, HideGui, ShowFPS = true;
internal float HudScale = 1.0f, ChatScale = 1.0f;
public bool ViewBobbing, UseGuiPng;
public bool UseSound, UseMusic;
public Animations Animations;
internal int CloudsTextureId, RainTextureId, SnowTextureId;
internal bool screenshotRequested;
public Bitmap FontBitmap;
internal List<WarningScreen> WarningScreens = new List<WarningScreen>();
internal AcceptedUrls AcceptedUrls = new AcceptedUrls();
public float GuiScale() {
float scaleX = Width / 640f, scaleY = Height / 480f;
return Math.Min( scaleX, scaleY ) * HudScale;
}
string defTexturePack = "default.zip";
public string DefaultTexturePack {
get {
return File.Exists( defTexturePack )
? defTexturePack : "default.zip"; }
set {
defTexturePack = value;
Options.Set( OptionsKey.DefaultTexturePack, value );
}
}
void LoadAtlas( Bitmap bmp ) {
TerrainAtlas1D.Dispose();
TerrainAtlas.Dispose();
@ -411,9 +327,11 @@ namespace ClassicalSharp {
public void SetCamera( bool thirdPerson ) {
PerspectiveCamera oldCam = (PerspectiveCamera)Camera;
Camera = (thirdPerson && CanUseThirdPersonCamera) ?
bool canUseThird = LocalPlayer.CanUseThirdPersonCamera;
Camera = (thirdPerson && canUseThird) ?
(Camera is FirstPersonCamera ? thirdPersonCam : forwardThirdPersonCam ) :
firstPersonCam;
PerspectiveCamera newCam = (PerspectiveCamera)Camera;
newCam.delta = oldCam.delta;
newCam.previous = oldCam.previous;

View File

@ -348,16 +348,17 @@ namespace ClassicalSharp {
}
void HandleCpeHackControl() {
game.LocalPlayer.CanFly = reader.ReadUInt8() != 0;
game.LocalPlayer.CanNoclip = reader.ReadUInt8() != 0;
game.LocalPlayer.CanSpeed = reader.ReadUInt8() != 0;
game.LocalPlayer.CanRespawn = reader.ReadUInt8() != 0;
game.CanUseThirdPersonCamera = reader.ReadUInt8() != 0;
game.LocalPlayer.CheckHacksConsistency();
LocalPlayer p = game.LocalPlayer;
p.CanFly = reader.ReadUInt8() != 0;
p.CanNoclip = reader.ReadUInt8() != 0;
p.CanSpeed = reader.ReadUInt8() != 0;
p.CanRespawn = reader.ReadUInt8() != 0;
p.CanUseThirdPersonCamera = reader.ReadUInt8() != 0;
p.CheckHacksConsistency();
float jumpHeight = reader.ReadInt16() / 32f;
if( jumpHeight < 0 ) jumpHeight = 1.4f;
game.LocalPlayer.CalculateJumpVelocity( jumpHeight );
p.CalculateJumpVelocity( jumpHeight );
}
void HandleCpeExtAddEntity2() {

View File

@ -88,8 +88,8 @@ namespace ClassicalSharp.TexturePack {
}
void SetFontBitmap( Game game, Stream stream ) {
game.FontBitmap = new Bitmap( stream );
game.Drawer2D.SetFontBitmap( game.FontBitmap );
Bitmap bmp = new Bitmap( stream );
game.Drawer2D.SetFontBitmap( bmp );
game.Events.RaiseChatFontChanged();
}