//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {License Information: Creative Commons}
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace ElementalGame
{
#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using System.Xml;
#endregion
/*
* GameObject Interface is child of GameFlow.
* * Objects inheriting this interface must overload all methods for GameFlow and GameObject
*
* Methods of GameObject follow the GameFlow pattern to ensure quick and efficient loading and unloading procedures.
* Additional properties are included in GameObject and are used by Renderer and Update to manipulate the GameObject.
* Each object specifies its draw and update procedures internally and is passed to Physics for in game motion and rotation.
*
*
*/
public struct VertexFogBinormalTangentWeightTess
{
public Vector4 Fog;
public Vector4 Binormal;
public Vector4 Tangent;
public Vector4 BlendWeight;
public Vector4 Color;
}
public class GameObject : GameObjectInterface
{
/* GameObject Interface Properties
*
*/
public int _id;
public Mass _mass;
public Model _model;
public Effect _effect;
public BasicEffect _basicEffect;
public Matrix _matrix = new Matrix();
public BoundingSphere _boundingSphere;
public List _textureList = new List();
public string _objectModelName;
public bool _isCollectable;
public bool _isKey;
public int id { get { return _id; } set { _id = value; } }
public Mass mass { get { return _mass; } set { _mass = value; } }
public Model model { get { return _model; } set { _model = value; } }
public Effect effect { get { return _effect; } set { _effect = value; } }
public BasicEffect basicEffect { get { return _basicEffect; } set { _basicEffect = value; } }
public Matrix matrix { get { return _matrix; } set { _matrix = value; } }
public BoundingSphere boundingSphere { get { return _boundingSphere; } set { _boundingSphere = value; } }
public List textureList { get { return _textureList; } set { _textureList = value; } }
public string objectModelName { get { return _objectModelName; } set { _objectModelName = value; } }
public bool isCollectable { get { return _isCollectable; } set { _isCollectable = value; } }
public bool isKey { get { return _isKey; } set { _isKey = value; } }
public static VertexBuffer vertexBuffer; // Buffer to store vertices
public static VertexPositionNormalTexture[] vertices; // Array to store vertex Position, Normal and Texture information
//private static VertexDeclaration vertexDeclaration; // Vertex Declaration
public static float[] materialDiffuse = { 0.7f, 0.7f, 0.7f, 1.0f }; // Diffuse cofactor
public static float[] materialSpecular = { 0.1f, 0.1f, 0.1f, 1.0f }; // Specular cofactor
public VertexFogBinormalTangentWeightTess objectValues;
/// Load Level from XML files
public virtual void Load(XmlNode node)
{
}
/// Update this object
public virtual void Update(ObjectLibrary objectLibrary)
{
}
// Draw this object's shadow
public virtual void DrawShadow(ModelManager modelManager)
{
}
// Draw this object
public virtual void Draw(ModelManager modelManager)
{
/*
// Lighting
ShaderParameters.coreShininess.SetValue(7000.0f);
ShaderParameters.coreMaterialDiffuse.SetValue(materialDiffuse);
ShaderParameters.coreMaterialSpecular.SetValue(materialSpecular);
effect.CurrentTechnique = effect.Techniques["BasicLightingNoShadowsShaderMain"];
ElementalGame.graphics.GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
// Load resources for that catagory
ShaderParameters.modelTexture1.SetValue(textureList[0]);
ShaderParameters.bumpTexture1.SetValue(textureList[1]);
// Render our quad
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
ElementalGame.graphics.GraphicsDevice.VertexDeclaration = vertexDeclaration;
ElementalGame.graphics.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);
pass.End();
}
effect.End();
*/
}
public Vector4 GetCurrentPosition()
{
return new Vector4(mass.currentPosition, 0.0f);
}
// Test Function to update energy distribution
public void UpdateHeatDissipation(ObjectLibrary objectLibrary)
{
/*
List newParticlesToAddToList = new List();
foreach (Particle particle in particles)
{
particle.mass.UpdatePosition();
}
// Iterate through dynamic particles
for (int i = 0; i < particles.Count; i++)
{
Particle particle = particles[i];
// List to store the pointers to neighboring particles
List neighboringParticleList = new List();
// Used to calculate the average value of all neighboring particles
float averageEnergy = particle.mass.energy;
// Get the list of neighboring particle pointers
neighboringParticleList = GetSurroundingParticles(particle.mass.currentPosition, objectLibrary);
// Calculate their total energy
foreach (Particle neigborParticle in neighboringParticleList)
{
averageEnergy += neigborParticle.mass.energy;
}
// Find the average
averageEnergy /= neighboringParticleList.Count + 1;
// If the average value is not equal to zero then we have some heat dissipation to do
if (averageEnergy != particle.mass.energy && neighboringParticleList.Count != 0)
{
// Iterate through neighboring particles
foreach (Particle neigborParticle in neighboringParticleList)
{
// If their value is not equal to the average set it and set the flag
if (neigborParticle.mass.energy != averageEnergy)
{
neigborParticle.mass.SetEnergy(averageEnergy);
if (!neigborParticle.mass.isChanging)
{
neigborParticle.mass.isChanging = true;
newParticlesToAddToList.Add(neigborParticle);
}
}
}
// Set the starting particle's energy to average value as well
particle.mass.SetEnergy(averageEnergy);
}
else if (particle.mass.energy != 0.0f)
{
DissipateHeat(particle);
}
else
{
// The particle and it's neighbors are in equilibrium so remove it from the list
particle.mass.isChanging = false;
if (!particle.mass.isMoving)
{
// Particle needs to be put back into the static list
MoveParticle(particles, particles, particle);
}
else
{
particles.Remove(particle);
}
i--;
}
}
foreach (Particle newParticle in newParticlesToAddToList)
{
if (particles.Contains(newParticle))
{
continue;
}
if (newParticle.mass.isMoving)
{
CopyParticle(particles, particles, newParticle);
}
else
{
MoveParticle(particles, particles, newParticle);
}
}
*/
}
public void StateChange(ObjectLibrary objectLibrary, float elementUse, GameObject gameObject)
{
/*
Particle particle = (Particle)gameObject;
gameObject.mass.ChangeEnergy(elementUse / 2.0f);
if (gameObject.mass.isChanging)
{
return;
}
else if (gameObject.mass.isMoving)
{
// Particle is in the dynamic list so we need to copy it to the Thermal list
switch (particle.particleType)
{
case Particle.ParticleType.Air:
{
objectLibrary.particleManager.air.CopyParticle(objectLibrary.particleManager.air.dynamicParticles,
objectLibrary.particleManager.air.thermalParticles,
particle);
break;
}
case Particle.ParticleType.Water:
{
objectLibrary.particleManager.water.CopyParticle(objectLibrary.particleManager.water.dynamicParticles,
objectLibrary.particleManager.water.thermalParticles,
particle);
break;
}
case Particle.ParticleType.Earth:
{
objectLibrary.particleManager.earth.CopyParticle(objectLibrary.particleManager.earth.dynamicParticles,
objectLibrary.particleManager.earth.thermalParticles,
particle);
break;
}
}
gameObject.mass.isChanging = true;
}
else
{
// It's in the static list, so move the particle to the dynamic list
switch (particle.particleType)
{
case Particle.ParticleType.Air:
{
objectLibrary.particleManager.air.MoveParticle(objectLibrary.particleManager.air.staticParticles,
objectLibrary.particleManager.air.thermalParticles,
particle);
break;
}
case Particle.ParticleType.Water:
{
objectLibrary.particleManager.water.MoveParticle(objectLibrary.particleManager.water.staticParticles,
objectLibrary.particleManager.water.thermalParticles,
particle);
break;
}
case Particle.ParticleType.Earth:
{
objectLibrary.particleManager.earth.MoveParticle(objectLibrary.particleManager.earth.staticParticles,
objectLibrary.particleManager.earth.thermalParticles,
particle);
break;
}
}
gameObject.mass.isChanging = true;
}
*/
}
}
}