Show kflags.h 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.
*/
#ifndef __KFLAGS_H__
#define __KFLAGS_H__
struct iEngine;
struct iSector;
struct iGraphics3D;
struct iMaterialWrapper;
struct iMeshWrapper;
class csTransform;
struct iPolygon3D;
class csVector3;
class KBlockId;
class KBlock;
class KOrientation;
class KFlags
{
public:
static const int s_nC;//central connection.
static const int s_eC;
static const int s_sC;
static const int s_wC;
static const int s_nS;//right side connection.
static const int s_eS;
static const int s_sS;
static const int s_wS;
static const int s_nOS;//left side connection.
static const int s_eOS;
static const int s_sOS;
static const int s_wOS;
bool m_flag[12];
KFlags()
{
int i;
for (i = 0; i < 12; i++)
m_flag[i] = false;
}
void Set(int p_index)
{
m_flag[p_index] = true;
}
void Unset(int p_index)
{
m_flag[p_index] = false;
}
void Rotate (const KOrientation& p_o)
{
if (p_o == KOrientation::NORTH)
{}//default is north, so dont rotate.
else if(p_o==KOrientation::WEST)
{
bool l_flag[12];
memcpy(l_flag,m_flag,sizeof(bool)*12);
m_flag[0]=l_flag[1];
m_flag[1]=l_flag[2];
m_flag[2]=l_flag[3];
m_flag[3]=l_flag[0];
m_flag[4]=l_flag[5];
m_flag[5]=l_flag[6];
m_flag[6]=l_flag[7];
m_flag[7]=l_flag[4];
m_flag[8]=l_flag[9];
m_flag[9]=l_flag[10];
m_flag[10]=l_flag[11];
m_flag[11]=l_flag[8];
}//else if
else if(p_o==KOrientation::SOUTH)
{
bool l_flag[12];
memcpy(l_flag,m_flag,sizeof(bool)*12);
m_flag[0]=l_flag[2];
m_flag[1]=l_flag[3];
m_flag[2]=l_flag[0];
m_flag[3]=l_flag[1];
m_flag[4]=l_flag[6];
m_flag[5]=l_flag[7];
m_flag[6]=l_flag[4];
m_flag[7]=l_flag[5];
m_flag[8]=l_flag[10];
m_flag[9]=l_flag[11];
m_flag[10]=l_flag[8];
m_flag[11]=l_flag[9];
}//else if
else if(p_o==KOrientation::EAST)
{
bool l_flag[12];
memcpy(l_flag,m_flag,sizeof(bool)*12);
m_flag[0]=l_flag[3];
m_flag[1]=l_flag[0];
m_flag[2]=l_flag[1];
m_flag[3]=l_flag[2];
m_flag[4]=l_flag[7];
m_flag[5]=l_flag[4];
m_flag[6]=l_flag[5];
m_flag[7]=l_flag[6];
m_flag[8]=l_flag[11];
m_flag[9]=l_flag[8];
m_flag[10]=l_flag[9];
m_flag[11]=l_flag[10];
}//else if
}
bool Compatible (KFlags const& p_f,const KOrientation& p_o)
{
if (p_o == KOrientation::NORTH)
{
if(p_f.m_flag[s_nC] && this->m_flag[s_sC])
return true;
if(p_f.m_flag[s_nS] && this->m_flag[s_sOS])
return true;
if(p_f.m_flag[s_nOS]&&this->m_flag[s_sS])
return true;
}
else if (p_o == KOrientation::EAST)
{
if(p_f.m_flag[s_eC]&&this->m_flag[s_wC])
return true;
if(p_f.m_flag[s_eS]&&this->m_flag[s_wOS])
return true;
if(p_f.m_flag[s_eOS]&&this->m_flag[s_wS])
return true;
}
else if(p_o==KOrientation::SOUTH)
{
if(p_f.m_flag[s_sC]&&this->m_flag[s_nC])
return true;
if(p_f.m_flag[s_sS]&&this->m_flag[s_nOS])
return true;
if(p_f.m_flag[s_sOS]&&this->m_flag[s_nS])
return true;
}
else if(p_o==KOrientation::WEST)
{
if(p_f.m_flag[s_wC]&&this->m_flag[s_eC])
return true;
if(p_f.m_flag[s_wS]&&this->m_flag[s_eOS])
return true;
if(p_f.m_flag[s_wOS]&&this->m_flag[s_eS])
return true;
}//if
return false;
}
};
#endif
See more files for this project here