Show klightlist.cpp syntax highlighted
/*
Copyright (C) 2003, 2004, 2005 by Luca Cappa
Written by Luca Cappa groton@users.sourceforge.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cssysdef.h"
#include "csutil/sysfunc.h"
#include "csutil/cscolor.h"
#include "csutil/cmdhelp.h"
#include "csutil/cspmeter.h"
#include "csutil/csstring.h"
#include "csutil/scfstr.h"
#include "csutil/xmltiny.h"
#include "csutil/array.h"
#include "cstool/csview.h"
#include "cstool/initapp.h"
#include "cstool/collider.h"
#include "iutil/vfs.h"
#include "iutil/eventq.h"
#include "iutil/event.h"
#include "iutil/objreg.h"
#include "iutil/csinput.h"
#include "iutil/virtclk.h"
#include "iutil/plugin.h"
#include "iutil/string.h"
#include "iutil/document.h"
#include "iengine/sector.h"
#include "iengine/engine.h"
#include "iengine/camera.h"
#include "iengine/light.h"
#include "iengine/texture.h"
#include "iengine/mesh.h"
#include "iengine/movable.h"
#include "iengine/material.h"
#include "imesh/thing.h"
#include "imesh/object.h"
#include "imesh/sprite3d.h"
#include "ivideo/graph3d.h"
#include "ivideo/graph2d.h"
#include "ivideo/natwin.h"
#include "ivideo/txtmgr.h"
#include "ivideo/texture.h"
#include "ivideo/material.h"
#include "ivideo/fontserv.h"
#include "igraphic/imageio.h"
#include "imap/loader.h"
#include "ivaria/reporter.h"
#include "ivaria/stdrep.h"
#include "ivaria/conout.h"
#include "ivaria/reporter.h"
#include "ivaria/stdrep.h"
#include "ivaria/collider.h"
#include "csgeom/quaterni.h"
#include "csgeom/transfrm.h"
#include "csgeom/math3d_d.h"
#include "csgeom/math3d.h"
#include "igeom/polymesh.h"
#include "igeom/objmodel.h"
#include "imap/loader.h"
#include "iaws/aws.h"
#include "iaws/awscnvs.h"
//
#include "korientation.h"
#include "kblock.h"
#include "kmap.h"
#include "kblockid.h"
#include "kflags.h"
#include "kappstate.h"
#include "ske.h"
#include "kdata.h"
#include "kutil.h"
#include "kquaternion.h"
#include "klight.h"
//Include for this file.
#include "klightlist.h"
SCF_IMPLEMENT_IBASE (KLightList)
SCF_IMPLEMENTS_INTERFACE (iKXMLWriter)
SCF_IMPLEMENTS_INTERFACE (iKXMLReader)
SCF_IMPLEMENT_IBASE_END
KLightList::KLightList (const char* p_name)
{
SCF_CONSTRUCT_IBASE (0);
m_name = csStrNew (p_name);
}
KLightList::KLightList ()
{
SCF_CONSTRUCT_IBASE (0);
m_name = csStrNew ("<unknown>");
}
KLightList::~KLightList()
{
delete const_cast<char*>(m_name);
RemoveAll ();
SCF_DESTRUCT_IBASE ();
}
size_t KLightList::GetCount () const
{
return m_lights.Length ();
}
KLight* KLightList::Get (int p_n) const
{
return m_lights.Get (p_n);
}
int KLightList::Add (KLight* p_light)
{
return m_lights.Push (p_light);
}
bool KLightList::Remove (KLight* p_light)
{
if (m_lights.DeleteIndex (m_lights.Find (p_light)))
return true;
else
return false;
}
bool KLightList::Remove (int p_n)
{
KLight* l_light = this->Get (p_n);
if (m_lights.DeleteIndex (p_n))
return true;
else
return false;
}
void KLightList::RemoveAll ()
{
m_lights.DeleteAll ();
}
int KLightList::Find (KLight* p_light) const
{
return m_lights.Find (p_light);
}
KLight* KLightList::FindByName (const char *p_name) const
{
KLight* l_light = 0;
csString l_string (p_name);
size_t i = 0;
for (i = 0; i < GetCount (); i++)
{
l_light = Get (i);
scfString l_string2 (l_light->GetName ());
if (l_string.Compare (l_string2))
return l_light;
}//for
return 0;
}
//
//
bool KLightList::Write (iDocumentNode* p_parent) const
{
csRef<iDocumentNode> l_lightsListNode =
p_parent->CreateNodeBefore (CS_NODE_ELEMENT, 0);
l_lightsListNode->SetValue ("lights_list");
l_lightsListNode->SetAttribute ("name", m_name);
int l_count = GetCount ();
int i;
for (i = 0; i < l_count; i++)
{
KLight* l_light = Get (i);//get the light.
l_light->Write (l_lightsListNode);
}//for
return true;
}
bool KLightList::Read (iDocumentNode* p_parent)
{
//
//Empty the list.
RemoveAll ();
const char* l_name = p_parent->GetValue ();
if (stricmp (l_name, "lights_list"))
return false;
csRef<iDocumentNodeIterator> l_it (p_parent->GetNodes ());
while (l_it->HasNext ())
{
csRef<iDocumentNode> l_lNode = l_it->Next ();
if (l_lNode->GetType () != CS_NODE_ELEMENT)
continue;
const char* value = l_lNode->GetValue ();
if (!strcmpi (value, "light"))
{
csRef<KLight> l_light = csPtr<KLight> (new KLight ());
l_light->Read (l_lNode);
Add (l_light);
}//if
else
{
//?? TO DO: report the error here!
}//else
}//while
return true;
}
See more files for this project here