mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-23 20:57:12 -04:00
Remove the yucky 'is entity FakePlayer', instead store ModelBlock as a field.
This commit is contained in:
parent
0695fe04eb
commit
a49fda440f
@ -27,6 +27,10 @@ namespace ClassicalSharp.Entities {
|
||||
/// <summary> The name of the model of this entity. </summary>
|
||||
public string ModelName;
|
||||
|
||||
/// <summary> BlockID if model name is a vaid block id. </summary>
|
||||
/// <remarks> This avoids needing to repeatedly parse ModelName as a byte. </remarks>
|
||||
public BlockID ModelBlock;
|
||||
|
||||
/// <summary> Scale applied to the model for collision detection and rendering. </summary>
|
||||
public Vector3 ModelScale = new Vector3(1.0f);
|
||||
|
||||
@ -69,8 +73,7 @@ namespace ClassicalSharp.Entities {
|
||||
|
||||
protected void UpdateModel() {
|
||||
BlockModel model = Model as BlockModel;
|
||||
if (model != null)
|
||||
model.CalcState(Utils.FastByte(ModelName));
|
||||
if (model != null) model.CalcState(ModelBlock);
|
||||
}
|
||||
|
||||
public abstract void Tick(double delta);
|
||||
@ -142,6 +145,11 @@ namespace ClassicalSharp.Entities {
|
||||
ModelScale *= 2;
|
||||
}
|
||||
|
||||
ModelBlock = Block.Air;
|
||||
if (Byte.TryParse(ModelName, out ModelBlock)) {
|
||||
ModelName = "block";
|
||||
}
|
||||
|
||||
Model = game.ModelCache.Get(ModelName);
|
||||
ParseScale(scale);
|
||||
lastModelChange = DateTime.UtcNow;
|
||||
|
@ -34,10 +34,10 @@ namespace ClassicalSharp.Model {
|
||||
public override float NameYOffset { get { return height + 0.075f; } }
|
||||
|
||||
public override float GetEyeY(Entity entity) {
|
||||
BlockID block = Byte.Parse(entity.ModelName);
|
||||
BlockID block = entity.ModelBlock;
|
||||
float minY = game.BlockInfo.MinBB[block].Y;
|
||||
float maxY = game.BlockInfo.MaxBB[block].Y;
|
||||
return block == 0 ? 1 : (minY + maxY) / 2;
|
||||
return block == Block.Air ? 1 : (minY + maxY) / 2;
|
||||
}
|
||||
|
||||
static Vector3 colShrink = new Vector3(0.75f/16, 0.75f/16, 0.75f/16);
|
||||
@ -66,15 +66,9 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
int lastTexId = -1;
|
||||
public override void DrawModel(Entity p) {
|
||||
// TODO: using 'is' is ugly, but means we can avoid creating
|
||||
// a string every single time held block changes.
|
||||
if (p is FakePlayer) {
|
||||
block = ((FakePlayer)p).Block;
|
||||
} else {
|
||||
block = Utils.FastByte(p.ModelName);
|
||||
}
|
||||
|
||||
block = p.ModelBlock;
|
||||
CalcState(block);
|
||||
|
||||
if (game.BlockInfo.FullBright[block]) {
|
||||
for (int i = 0; i < cols.Length; i++)
|
||||
cols[i] = FastColour.WhitePacked;
|
||||
|
@ -58,11 +58,6 @@ namespace ClassicalSharp.Model {
|
||||
|
||||
|
||||
public IModel Get(string modelName) {
|
||||
if (modelName == "block") return Models[0].Instance;
|
||||
byte blockId;
|
||||
if (Byte.TryParse(modelName, out blockId))
|
||||
modelName = "block";
|
||||
|
||||
for (int i = 0; i < Models.Count; i++) {
|
||||
CachedModel m = Models[i];
|
||||
if (m.Name != modelName) continue;
|
||||
|
@ -74,8 +74,8 @@ namespace ClassicalSharp.Renderers {
|
||||
// i.e. the block has gone to bottom of screen and is now returning back up
|
||||
// at this point we switch over to the new held block.
|
||||
if (pos.Y > last.Y)
|
||||
lastType = held.type;
|
||||
held.type = lastType;
|
||||
lastType = held.block;
|
||||
held.block = lastType;
|
||||
}
|
||||
} else {
|
||||
if (time >= period * 0.25) DigSecondCycle();
|
||||
|
@ -16,7 +16,7 @@ namespace ClassicalSharp.Renderers {
|
||||
|
||||
public class HeldBlockRenderer : IGameComponent {
|
||||
|
||||
internal BlockID type;
|
||||
internal BlockID block;
|
||||
IModel model;
|
||||
internal HeldBlockAnimation anim;
|
||||
|
||||
@ -26,7 +26,7 @@ namespace ClassicalSharp.Renderers {
|
||||
|
||||
public void Init(Game game) {
|
||||
this.game = game;
|
||||
model = game.ModelCache.Get("0");
|
||||
model = game.ModelCache.Get("block");
|
||||
held = new FakePlayer(game);
|
||||
game.Events.ProjectionChanged += ProjectionChanged;
|
||||
|
||||
@ -44,7 +44,7 @@ namespace ClassicalSharp.Renderers {
|
||||
|
||||
Vector3 last = anim.pos;
|
||||
anim.pos = Vector3.Zero;
|
||||
type = game.Inventory.Selected;
|
||||
block = game.Inventory.Selected;
|
||||
held.RotX = 0;
|
||||
if (anim.doAnim) anim.Update(delta, last);
|
||||
|
||||
@ -54,7 +54,7 @@ namespace ClassicalSharp.Renderers {
|
||||
SetMatrix();
|
||||
|
||||
game.Graphics.Texturing = true;
|
||||
game.Graphics.SetupAlphaState(game.BlockInfo.Draw[type]);
|
||||
game.Graphics.SetupAlphaState(game.BlockInfo.Draw[block]);
|
||||
game.Graphics.DepthTest = false;
|
||||
|
||||
SetPos();
|
||||
@ -68,7 +68,7 @@ namespace ClassicalSharp.Renderers {
|
||||
game.Graphics.SetMatrixMode(MatrixType.Modelview);
|
||||
|
||||
game.Graphics.Texturing = false;
|
||||
game.Graphics.RestoreAlphaState(game.BlockInfo.Draw[type]);
|
||||
game.Graphics.RestoreAlphaState(game.BlockInfo.Draw[block]);
|
||||
game.Graphics.DepthTest = true;
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ namespace ClassicalSharp.Renderers {
|
||||
void SetPos() {
|
||||
// Based off details from http://pastebin.com/KFV0HkmD (Thanks goodlyay!)
|
||||
BlockInfo info = game.BlockInfo;
|
||||
bool sprite = info.Draw[type] == DrawType.Sprite;
|
||||
bool sprite = info.Draw[block] == DrawType.Sprite;
|
||||
Vector3 offset = sprite ? sOffset : nOffset;
|
||||
Player p = game.LocalPlayer;
|
||||
held.ModelScale = new Vector3(0.4f);
|
||||
@ -92,7 +92,7 @@ namespace ClassicalSharp.Renderers {
|
||||
held.Position = p.EyePosition + anim.pos;
|
||||
held.Position += offset;
|
||||
if (!sprite) {
|
||||
float height = info.MaxBB[type].Y - info.MinBB[type].Y;
|
||||
float height = info.MaxBB[block].Y - info.MinBB[block].Y;
|
||||
held.Position.Y += 0.2f * (1 - height);
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ namespace ClassicalSharp.Renderers {
|
||||
held.HeadY = -45 + anim.angleY;
|
||||
held.RotY = -45 + anim.angleY;
|
||||
held.HeadX = 0;
|
||||
held.Block = type;
|
||||
held.ModelBlock = block;
|
||||
}
|
||||
|
||||
void ProjectionChanged(object sender, EventArgs e) {
|
||||
@ -126,7 +126,6 @@ namespace ClassicalSharp.Renderers {
|
||||
public FakePlayer(Game game) : base(game) {
|
||||
NoShade = true;
|
||||
}
|
||||
public BlockID Block;
|
||||
|
||||
public override void SetLocation(LocationUpdate update, bool interpolate) { }
|
||||
|
||||
|
@ -140,16 +140,6 @@ namespace ClassicalSharp {
|
||||
adjCol *= tint;
|
||||
return adjCol.Pack();
|
||||
}
|
||||
|
||||
public static byte FastByte(string s) {
|
||||
int sum = 0;
|
||||
switch (s.Length) {
|
||||
case 1: sum = (s[0] - '0'); break;
|
||||
case 2: sum = (s[0] - '0') * 10 + (s[1] - '0'); break;
|
||||
case 3: sum = (s[0] - '0') * 100 + (s[1] - '0') * 10 + (s[2] - '0'); break;
|
||||
}
|
||||
return (byte)sum;
|
||||
}
|
||||
|
||||
/// <summary> Determines the skin type of the specified bitmap. </summary>
|
||||
public static SkinType GetSkinType(Bitmap bmp) {
|
||||
|
@ -7,7 +7,7 @@ ModelPart Head, Head2, Head3, Torso, LeftLeg, RightLeg, LeftWing, RightWing;
|
||||
ModelVertex ChickenModel_Vertices[IModel_BoxVertices * 6 + (IModel_QuadVertices * 2) * 2];
|
||||
IModel ChickenModel;
|
||||
|
||||
ModelPart MakeLeg(Int32 x1, Int32 x2, Int32 legX1, Int32 legX2) {
|
||||
ModelPart ChickenModel_MakeLeg(Int32 x1, Int32 x2, Int32 legX1, Int32 legX2) {
|
||||
#define y1 (1.0f / 64.0f)
|
||||
#define y2 (5.0f / 16.0f)
|
||||
#define z2 (1.0f / 16.0f)
|
||||
@ -57,8 +57,8 @@ void ChickenModel_CreateParts(void) {
|
||||
BoxDesc_RotOrigin(&desc, 3, 11, 0);
|
||||
RightWing = BoxDesc_BuildBox(&ChickenModel, &desc);
|
||||
|
||||
LeftLeg = MakeLeg(-3, 0, -2, -1);
|
||||
RightLeg = MakeLeg(0, 3, 1, 2);
|
||||
LeftLeg = ChickenModel_MakeLeg(-3, 0, -2, -1);
|
||||
RightLeg = ChickenModel_MakeLeg(0, 3, 1, 2);
|
||||
}
|
||||
|
||||
Real32 ChickenModel_GetNameYOffset(void) { return 1.0125f; }
|
||||
|
@ -4,11 +4,10 @@
|
||||
#include "MiscEvents.h"
|
||||
#include "StringConvert.h"
|
||||
|
||||
String ModelCache_blockString, ModelCache_charPngString;
|
||||
String ModelCache_charPngString;
|
||||
Int32 ModelCache_texCount, ModelCache_modelCount;
|
||||
|
||||
void ModelCache_Init(void) {
|
||||
ModelCache_blockString = String_FromConstant("block");
|
||||
ModelCache_charPngString = String_FromConstant("char.png");
|
||||
ModelCache_RegisterDefaultModels();
|
||||
ModelCache_ContextRecreated();
|
||||
@ -33,20 +32,10 @@ void ModelCache_Free(void) {
|
||||
|
||||
|
||||
IModel* ModelCache_Get(STRING_TRANSIENT String* name) {
|
||||
if (String_Equals(name, &ModelCache_blockString)) {
|
||||
return ModelCache_Models[0].Instance;
|
||||
}
|
||||
|
||||
String* modelName = name;
|
||||
UInt8 blockId;
|
||||
if (Convert_TryParseByte(name, &blockId)) {
|
||||
modelName = &ModelCache_blockString;
|
||||
}
|
||||
|
||||
Int32 i;
|
||||
for (i = 0; i < ModelCache_modelCount; i++) {
|
||||
CachedModel* m = &ModelCache_Models[i];
|
||||
if (!String_Equals(&m->Name, modelName)) continue;
|
||||
if (!String_Equals(&m->Name, name)) continue;
|
||||
|
||||
if (!m->Instance->initalised) {
|
||||
m->Instance->CreateParts();
|
||||
|
Loading…
x
Reference in New Issue
Block a user