1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "nel/misc/i_xml.h"
19 #include "nel/misc/stream.h"
20 #include "nel/pacs/primitive_block.h"
26 // ***************************************************************************
28 CPrimitiveDesc::CPrimitiveDesc ()
31 Type
= UMovePrimitive::_2DOrientedBox
;
32 Reaction
= UMovePrimitive::DoNothing
;
33 Trigger
= UMovePrimitive::NotATrigger
;
35 OcclusionMask
= 0xffffffff;
36 CollisionMask
= 0xffffffff;
39 // ***************************************************************************
41 void CPrimitiveDesc::serial (NLMISC::IStream
&s
)
44 sint ver
= s
.serialVersion (1);
51 s
.xmlSerial (Height
, "HEIGHT");
52 s
.xmlSerial (Attenuation
, "ATTENUATION");
58 s
.xmlPush ("REACTION");
59 s
.serialEnum (Reaction
);
62 s
.xmlPush ("TRIGGER");
63 s
.serialEnum (Trigger
);
66 s
.xmlSerial (Obstacle
, "OBSTACLE");
67 s
.xmlSerial (OcclusionMask
, "OCCLUSION_MASK");
68 s
.xmlSerial (CollisionMask
, "COLLISION_MASK");
69 s
.xmlSerial (Position
, "POSITION");
70 s
.xmlSerial (Orientation
, "ORIENTATION");
74 s
.xmlSerial (UserData
, "USER_DATA");
82 // ***************************************************************************
84 void CPrimitiveBlock::serial (NLMISC::IStream
&s
)
86 s
.xmlPush ("PRIMITIVE_BLOCK");
89 s
.serialCheck (NELID("KBRP"));
92 (void)s
.serialVersion (0);
94 s
.xmlPush ("PRIMITIVES");
95 s
.serialCont (Primitives
);
101 // ***************************************************************************
102 UPrimitiveBlock
*UPrimitiveBlock::createPrimitiveBlock(NLMISC::IStream
&src
)
105 nlassert(src
.isReading());
106 CUniquePtr
<CPrimitiveBlock
> pb(new CPrimitiveBlock
);
111 // ***************************************************************************
112 UPrimitiveBlock
*UPrimitiveBlock::createPrimitiveBlockFromFile(const std::string
&fileName
)
115 NLMISC::CIFile input
;
116 if (input
.open(fileName
))
118 NLMISC::CIXml xmlInput
;
120 if (xmlInput
.init (input
))
122 return createPrimitiveBlock(xmlInput
);
126 throw NLMISC::Exception(std::string("Unable to init an xml input file from ") + fileName
);