#include "content.h"
#include "input.h"
#include "particleSystem.h"

void Content::setup()
{
    //load particle texture
    Renderer::textureList["base"]=Renderer::LoadTextureTGA("icon_base.tga",64,1);

    //load 3D point cloud
    std::string stringName;
    stringName.append("inkScanData.xml");

    glutSetCursor(GLUT_CURSOR_NONE);

    TiXmlDocument doc( stringName );

    if (!doc.LoadFile())
        {
        cout << "there was an error!" << endl;
        return;
        }

    cout << "Loading..." <<endl;

    //load an actor...
    TiXmlHandle hDoc(&doc);
    TiXmlElement * myInfo;

    myInfo=hDoc.FirstChildElement().Element();
    // should always have a valid root but handle gracefully if it doesn't
    if (!myInfo) return;

    TiXmlHandle hRoot(0);
    // save this for later
    hRoot=TiXmlHandle(myInfo);

    TiXmlElement* element=hRoot.FirstChild( "Actor" ).Element();
    string myType;
    for( element; element!=NULL; element=element->NextSiblingElement())
	  {
      cout << element->Value() << " " << element->GetText() <<endl;
	  myType=element->GetText();
	  Actor * A=Renderer::actorInfo[myType].actorReference;
	  A->create();
      A=Renderer::actorList.back();
      //***********************************************************************
      //Fill up Properties
      //***********************************************************************
      A->load(element);
      A->setup();
      }
 }

void Content::reset(){

Renderer::actorList.clear();
setup();
}

    //*************************************************
    // Nodes
    //*************************************************
//    but=new RootNode;
//    but->location=Vector3f(100,100,0);
//    Renderer::buttonList.push_back(but);
//    Control::nodeList.push_back((Node*)but);
//
//    but=new WaitForTimerNode;
//    but->location=Vector3f(100,200,0);
//    Renderer::buttonList.push_back(but);
//    Control::nodeList.push_back((Node*)but);
//
//    but=new Node;
//    but->location=Vector3f(400,100,0);
//    Renderer::buttonList.push_back(but);
//    Control::nodeList.push_back((Node*)but);


    //*************************************************
    // CityScape
    //*************************************************
    //a=new Actor;
    //a->drawType=1;

    //a->name="surrounding";

    //*********************************
    //Physics Ragdoll with ODE!!!
    //**********************************/

    //a=new RagDoll();
    //a->name="ragDoll";

    //a->location=Vector3f(1,10,-8);
    //a->rotation=Vector3f(0,0,0);

    //Renderer::actorList.push_back(a);

    //a->mesh="surrounding";

    //optional:
    //a->shaderProgramName="ammiShader";
    //a->vertexShaderFileName="shaders/ammi.vert";
    //a->fragmentShaderFileName="shaders/ammi.frag";

    //Renderer::actorList.push_back(a);

    //*********************************
    //Physics Ragdoll with ODE!!!
    //**********************************/

    //a=new RagDoll();
    //a->name="ragDoll";

    //a->location=Vector3f(1,10,-8);
    //a->rotation=Vector3f(0,0,0);

    //Renderer::actorList.push_back(a);


    //************************
    //Flex Grid
    //************************

    //a=new FlexGrid;
    //a->name="flexGrid";
    //a->color=Vector4f(1.0,0.5,0.0,1.0);
    //Renderer::actorList.push_back(a);

    //************************
    //Particle System
    //************************

    //ParticleSystem *p;
    //p=new ParticleSystem;
    //p->name="particleSystem";
    //p->shaderProgramName="particle";
    //p->vertexShaderFileName="shaders/particle.vert";
    //p->fragmentShaderFileName="shaders/particle.frag";
    //p->texture=Renderer::textureList[1];
    //p->addRandomParticles(5,1);
    //Renderer::actorList.push_back(p);


   //*************************************************
    // Pilot for RagDoll KeyFraming with Mouse
    //*************************************************

    //MousePilot * mPilot=new MousePilot;
    //RagDoll * r=new RagDoll();
    //r->color=Vector4f(0,0,0,1);
    //r->bFullBright=true;
    //Renderer::actorList.push_back(r);
    //mPilot->controlledActor=r;
    //Renderer::buttonList.push_back(mPilot);



    //*************************************************
    // UDP connections for RagDoll One
    //*************************************************
    /*
    Pilot * pilot=new Pilot;
    UdpInput *udp;
    udp= new UdpInput;
    udp->location.x=460.0f;
    udp->location.y=0;
    udp->texture="flat";
    udp->channel=1;
    Renderer::buttonList.push_back(udp);
    Input::controller->udpOne=udp;

    pilot->handControl=udp;
    udp= new UdpInput;
    udp->location.x=500.0f;
    udp->location.y=0;
    udp->texture="flat";
    udp->channel=2;
    Renderer::buttonList.push_back(udp);
    Input::controller->udpTwo=udp;
    pilot->footControl=udp;

    pilot->location.x=500.0f;
    pilot->location.y=60;
    pilot->texture="flat";
    pilot->channel=1;

    RagDoll * r=new RagDoll();
    r->color=Vector4f(0,0,0,1);
    r->bFullBright=true;
     Renderer::actorList.push_back(r);

    pilot->controlledActor=r;
    Renderer::buttonList.push_back(pilot);
    Input::controller->pilotOne=pilot;

    //*************************************************
    // UDP connections for RagDoll Two
    //*************************************************

    pilot=new Pilot;
    udp= new UdpInput;
    udp->location.x=460.0f;
    udp->location.y=0;
    udp->texture="flat";
    udp->channel=5;
    Renderer::buttonList.push_back(udp);
    Input::controller->udpThree=udp;

    pilot->handControl=udp;
    udp= new UdpInput;
    udp->location.x=500.0f;
    udp->location.y=0;
    udp->texture="flat";
    udp->channel=6;
    Renderer::buttonList.push_back(udp);
    Input::controller->udpFour=udp;
    pilot->footControl=udp;

    pilot->location.x=500.0f;
    pilot->location.y=60;
    pilot->texture="flat";
    pilot->channel=1;

    r=new RagDoll();
    r->color=Vector4f(1,0,0,1);
    r->bFullBright=true;
    r->setLocation(Vector3f(0,0,3));
    r->setRotation(Vector3f(0,90,0));       //todo: this is weird, rotation should be 180! not 90
    Renderer::actorList.push_back(r);

    pilot->controlledActor=r;
    Renderer::buttonList.push_back(pilot);
    Input::controller->pilotTwo=pilot;

    */
