Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / nel / src / pacs / primitive_block_pacs.cpp
blobc2f40c40ca725a0f6fa5f071f5706d0b6d0f3d39
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
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.
8 //
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/>.
17 #include "stdpacs.h"
18 #include "nel/misc/i_xml.h"
19 #include "nel/misc/stream.h"
20 #include "nel/pacs/primitive_block.h"
23 namespace NLPACS
26 // ***************************************************************************
28 CPrimitiveDesc::CPrimitiveDesc ()
30 Attenuation = 1;
31 Type = UMovePrimitive::_2DOrientedBox;
32 Reaction = UMovePrimitive::DoNothing;
33 Trigger = UMovePrimitive::NotATrigger;
34 Obstacle = true;
35 OcclusionMask = 0xffffffff;
36 CollisionMask = 0xffffffff;
39 // ***************************************************************************
41 void CPrimitiveDesc::serial (NLMISC::IStream &s)
43 // Serial the version
44 sint ver = s.serialVersion (1);
46 s.xmlPush ("LENGTH");
47 s.serial (Length[0]);
48 s.serial (Length[1]);
49 s.xmlPop ();
51 s.xmlSerial (Height, "HEIGHT");
52 s.xmlSerial (Attenuation, "ATTENUATION");
54 s.xmlPush ("TYPE");
55 s.serialEnum (Type);
56 s.xmlPop ();
58 s.xmlPush ("REACTION");
59 s.serialEnum (Reaction);
60 s.xmlPop ();
62 s.xmlPush ("TRIGGER");
63 s.serialEnum (Trigger);
64 s.xmlPop ();
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");
72 if (ver>=1)
74 s.xmlSerial (UserData, "USER_DATA");
76 else
78 UserData = 0;
82 // ***************************************************************************
84 void CPrimitiveBlock::serial (NLMISC::IStream &s)
86 s.xmlPush ("PRIMITIVE_BLOCK");
88 // Serial checks
89 s.serialCheck (NELID("KBRP"));
91 // Serial the version
92 (void)s.serialVersion (0);
94 s.xmlPush ("PRIMITIVES");
95 s.serialCont (Primitives);
96 s.xmlPop ();
98 s.xmlPop ();
101 // ***************************************************************************
102 UPrimitiveBlock *UPrimitiveBlock::createPrimitiveBlock(NLMISC::IStream &src)
105 nlassert(src.isReading());
106 CUniquePtr<CPrimitiveBlock> pb(new CPrimitiveBlock);
107 pb->serial(src);
108 return pb.release();
111 // ***************************************************************************
112 UPrimitiveBlock *UPrimitiveBlock::createPrimitiveBlockFromFile(const std::string &fileName)
115 NLMISC::CIFile input;
116 if (input.open(fileName))
118 NLMISC::CIXml xmlInput;
119 // Init
120 if (xmlInput.init (input))
122 return createPrimitiveBlock(xmlInput);
124 else
126 throw NLMISC::Exception(std::string("Unable to init an xml input file from ") + fileName);
129 return NULL;
135 } // NLPACS