Jump to content

Where's my mistake?


L B
 Share

Recommended Posts

I'm making a control code (move, change camera orientation, etc.), just like in any classic MMORPG. Losing 10 FPS with this, and it's just logic.

I know it's in C#, but anyone here would understand I think.

 

using Leadwerks;

namespace Origins
{
public enum PlayerState
{
	Idle,
	ForwardWalking,
	Dying,
	Hit,
	Jumping,
	Attacking,
	MagicAttacking,
	LeftWalking,
	RightWalking,
	BackwardWalking,
	Flying
}

public class Player
{
	public Camera Camera { get; set; }
	public Controller Controller { get; set; }
	public Mesh Mesh { get; set; }

	private Vector3 Rotation { get; set; }
	private Vector2 MouseDelta { get; set; }
	private Vector2 MouseOrigin { get; set; }
	private Vector3 Movement { get; set; }
	private float Zoom { get; set; }
	private float Jump { get; set; }
	private bool Reorient { get; set; }

	public PlayerState State { get; set; }
	private PlayerState OldState { get; set; }

	private int DeathFrame = 0;
	private int HitFrame = 80;
	private int IdleFrame = 106;
	private int JumpFrame = 176;
	private int MagicFrame = 203;
	private int MeleeFrame = 250;
	private int RunFrame = 297;
	private int SideFrame = 323;
	private int WalkFrame = 357;
	private int BackFrame = 393;

	public Player()
	{
		this.Camera = new Camera();

		this.Controller = new Controller(1.8f, 0.5f, 0.5f, 45.0f);
		this.Controller.Mass = 1;
		this.Controller.CollisionType = (int)CollisionType.Character;

		this.Mesh = Mesh.Load("abstract::wizard.gmf");
		this.Mesh.Parent = this.Controller;
		this.Mesh.Scale = new Vector3(0.01f);
		this.Mesh.Move(new Vector3(0, -90.0f, 0));

		this.Rotation = new Vector3();
		this.MouseDelta = new Vector2();
		this.MouseOrigin = new Vector2();
		this.Movement = new Vector3();
		this.Zoom = 1.0f;
		this.Jump = 0.0f;
		this.Reorient = false;

		//Light lantern = Light.CreatePoint(5);
		//lantern.ShadowmapSize = 16;
		//lantern.Color = new Vector4(1, 0, 0, 1);
		//lantern.Parent = this.Mesh.GetChild("stuff2");
	}

	public void Update()
	{
		this.OldState = this.State;

		this.State = PlayerState.Idle;

		switch (Keyboard.KeyHit(Key.Space) && !this.Controller.IsAirborne())
		{
			case true:
				this.Jump = 5.0f;
				break;

			case false:
				this.Jump = 0.0f;
				break;
		}

		switch (Keyboard.IntKeyDown(Key.W) - Keyboard.IntKeyDown(Key.S))
		{
			case 1:
				this.State = PlayerState.ForwardWalking;
				this.Movement.Z = 4.0f;
				break;

			case 0:
				this.Movement.Z = 0.0f;
				break;

			case -1:
				this.State = PlayerState.BackwardWalking;
				this.Movement.Z = -2.0f;
				break;
		}

		if (Mouse.ButtonDown(MouseButton.Left) || Mouse.ButtonDown(MouseButton.Right))
		{
			Mouse.Hide();

			switch (Keyboard.IntKeyDown(Key.D) - Keyboard.IntKeyDown(Key.A))
			{
				case 1:
					this.State = PlayerState.RightWalking;
					this.Movement.X = 2.0f;
					break;

				case 0:
					this.Movement.X = 0.0f;
					break;

				case -1:
					this.State = PlayerState.LeftWalking;
					this.Movement.X = -2.0f;
					break;
			}

			this.MouseDelta.X = Utilities.Curve(Mouse.X - this.MouseOrigin.X, this.MouseDelta.X, 5.0f);
			this.MouseDelta.Y = Utilities.Curve(Mouse.Y - this.MouseOrigin.Y, this.MouseDelta.Y, 5.0f);

			this.Rotation.X += this.MouseDelta.Y / 5.0f;
			this.Rotation.Y -= this.MouseDelta.X / 5.0f;

			Mouse.Move((int)this.MouseOrigin.X, (int)this.MouseOrigin.Y);
		}
		else
		{
			this.Movement.X = 0.0f;

			Mouse.Show();
			this.Rotation.Y -= (float)(Keyboard.IntKeyDown(Key.D) * 3 - Keyboard.IntKeyDown(Key.A) * 3);
		}

		if (this.Controller.IsAirborne())
		{
			this.State = PlayerState.Jumping;
		}

		if (Mouse.ButtonDown(MouseButton.Right) || Keyboard.KeyDown(Key.D) || Keyboard.KeyDown(Key.A) || Keyboard.KeyDown(Key.W) || Keyboard.KeyDown(Key.S))
		{
			this.Reorient = true;
		}
		else
		{
			this.Reorient = false;
		}

		this.Camera.Rotation = this.Rotation;

		this.Zoom = Utilities.Curve((float)-Mouse.Z, this.Zoom, 5.0f);

		if (this.Reorient)
		{
			this.Controller.Update(this.Rotation.Y, this.Movement.Z, this.Movement.X, this.Jump, 500.0f, 1);
		}
		else
		{
			this.Controller.Update(this.Controller.Rotation.Y, this.Movement.Z, this.Movement.X, this.Jump, 500.0f, 1);
		}

		this.Camera.Position = this.Controller.Position;
		this.Camera.Move(new Vector3(0.0f, 0.5f * this.Zoom, -2.5f * this.Zoom));

		this.MouseOrigin.X = (float)Mouse.X;
		this.MouseOrigin.Y = (float)Mouse.Y;

		if (this.State != this.OldState)
		{
			/*
				death     0   80
				hit       80  106
				idle      106 176
				jump      176 203
				magic     203 250
				melee     250 297
				run       297 323
				side      323 357
				walk      357 393
				walk back 393 429
			 */

			this.DeathFrame = 0;
			this.HitFrame = 80;
			this.IdleFrame = 106;
			this.JumpFrame = 176;
			this.MagicFrame = 203;
			this.MeleeFrame = 250;
			this.RunFrame = 297;
			this.SideFrame = 323;
			this.WalkFrame = 357;
			this.BackFrame = 393;
		}

		this.DeathFrame++;
		this.HitFrame++;
		this.IdleFrame++;
		this.JumpFrame++;
		this.MagicFrame++;
		this.MeleeFrame++;
		this.RunFrame++;
		this.SideFrame++;
		this.WalkFrame++;
		this.BackFrame++;

		if (DeathFrame == 80)
			DeathFrame = 1;

		if (HitFrame == 106)
			HitFrame = 81;

		if (IdleFrame == 176)
			IdleFrame = 107;

		if (MagicFrame == 250)
			MagicFrame = 204;

		if (MeleeFrame == 297)
			MeleeFrame = 251;

		if (RunFrame == 323)
			RunFrame = 298;

		if (SideFrame == 357)
			SideFrame = 324;

		if (WalkFrame == 393)
			WalkFrame = 358;

		if (BackFrame == 429)
			BackFrame = 394;

		switch (this.State)
		{
			case PlayerState.Idle:
				this.Mesh.Animate(IdleFrame, 1, 0, 1);
				break;

			case PlayerState.ForwardWalking:
				this.Mesh.Animate(RunFrame, 1, 0, 1);
				break;

			case PlayerState.BackwardWalking:
				this.Mesh.Animate(BackFrame, 1, 0, 1);
				break;

			case PlayerState.LeftWalking:
			case PlayerState.RightWalking:
				this.Mesh.Animate(SideFrame, 1, 0, 1);
				break;

			case PlayerState.Jumping:
				this.Mesh.Animate(JumpFrame, 1, 0, 1);
				break;

			case PlayerState.Flying:
				this.Mesh.Animate(185, 1, 0, 1);
				break;
		}
	}
}
}

Link to comment
Share on other sites

just out of curiosity, have you turned on debugphysics? I am curious to see how large the collisionbody for the wizard is whenever it gets loaded since you are scaling it by 0.01? you should really get UU3D and scale all of your assets before converting them to gmf... if you know someone you can trust to do the scaling/conversion for you, you should do it.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

just out of curiosity, have you turned on debugphysics? I am curious to see how large the collisionbody for the wizard is whenever it gets loaded since you are scaling it by 0.01? you should really get UU3D and scale all of your assets before converting them to gmf... if you know someone you can trust to do the scaling/conversion for you, you should do it.

 

Haven't turned on DebugPhysics, so that isn't it. I'll make serious models when I get to my actual game characters, but the wizard is a test model.

On a second note, it seems to only happen in the vicinity of many lights (a.k.a. directional + point + point). Are skinned meshes slow on lights?

Link to comment
Share on other sites

Haven't turned on DebugPhysics, so that isn't it.

 

 

Thats not what Mack meant.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Thats not what Mack meant.

 

Even if the collision body is big, it doesn't have more vertices. Nonetheless, is there a way to disable shadowing on specific lights and mesh combination? Like turn "CastShadow" off but only for a specified light?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...