00001
00057 #define _EXPORT_CCL_
00058
00059 #include "CigiEntityCtrlV1.h"
00060 #include "CigiExceptions.h"
00061 #include "CigiSwapping.h"
00062 #include <memory.h>
00063
00064
00065 #ifdef CIGI_LITTLE_ENDIAN
00066 #define CIGI_SCOPY2 CigiSwap2
00067 #define CIGI_SCOPY4 CigiSwap4
00068 #define CIGI_SCOPY8 CigiSwap8
00069 #else
00070 #define CIGI_SCOPY2 CigiCopy2
00071 #define CIGI_SCOPY4 CigiCopy4
00072 #define CIGI_SCOPY8 CigiCopy8
00073 #endif
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 CigiEntityCtrlV1::CigiEntityCtrlV1()
00086 {
00087
00088
00089 PacketID = CIGI_ENTITY_CTRL_PACKET_ID_V1;
00090 PacketSize = CIGI_ENTITY_CTRL_PACKET_SIZE_V1;
00091 Version = 1;
00092 MinorVersion = 0;
00093
00094 EntityID = 0;
00095 EntityType = 0;
00096 ParentID = 0;
00097
00098 Alpha = 255;
00099 Opacity = 100.0f;
00100 Temperature = 0.0f;
00101
00102 Roll = 0.0f;
00103 Pitch = 0.0f;
00104 Yaw = 0.0f;
00105 LatOrXoff = 0.0f;
00106 LonOrYoff = 0.0f;
00107 AltOrZoff = 0.0f;
00108
00109 EntityState = Standby;
00110 AttachState = Detach;
00111 CollisionDetectEn = Disable;
00112 InheritAlpha = NoInherit;
00113 GrndClamp = NoClamp;
00114 AnimationDir = Forward;
00115 AnimationLoopMode = OneShot;
00116 AnimationState = Stop;
00117 PastAnimationState = Stop;
00118 SmoothingEn = false;
00119
00120
00121 }
00122
00123
00124
00125
00126 CigiEntityCtrlV1::~CigiEntityCtrlV1()
00127 {
00128
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 int CigiEntityCtrlV1::Pack(CigiBasePacket * Base, Cigi_uint8 * Buff, void *Spec) const
00140 {
00141 EntityStV1Grp en_rslt;
00142 EffectStateGrp ef_rslt;
00143 float talt;
00144 double DBuf[6];
00145
00146 Cigi_uint8 *tBuf = (Cigi_uint8 *)DBuf;
00147
00148 PackPointer CDta;
00149
00150
00151 CigiAnimationTable *ATbl = (CigiAnimationTable *) Spec;
00152
00153 CigiBaseEntityCtrl * Data = ( CigiBaseEntityCtrl *)Base;
00154
00155 CDta.c = tBuf;
00156
00157 *CDta.c++ = PacketID;
00158 *CDta.c++ = PacketSize;
00159 CIGI_SCOPY2(CDta.s++, &Data->EntityID);
00160
00161 Cigi_uint8 HDta = (Cigi_uint8)(((Data->AttachState << 6) & 0x40) |
00162 ((Data->CollisionDetectEn << 5) & 0x20));
00163
00164
00165 if(Data->EntityState == Active)
00166 en_rslt = ConstructV1;
00167 else
00168 en_rslt = DestructV1;
00169
00170 HDta |= (Cigi_uint8)((en_rslt << 7) & 0x80);
00171
00172
00173 AnimationStateGrp tAState = Data->AnimationState;
00174 if((tAState >= 0)&&(tAState <= 9))
00175 tAState = ToV1[tAState];
00176 else
00177 tAState = NoAction;
00178
00179 if(tAState == Continue)
00180 {
00181 unsigned int PastAState = ATbl->GetPastAnimation(Data->EntityID);
00182 if((PastAState == Stop) ||
00183 (PastAState == Pause))
00184 tAState = LoadActivate;
00185 else
00186 tAState = NoAction;
00187 }
00188
00189 ef_rslt = (EffectStateGrp)(tAState - 4);
00190 HDta |= (Cigi_uint8)((ef_rslt << 2) & 0x1C);
00191
00192 tAState = ToV3[tAState];
00193 if(tAState != NoAction)
00194 ATbl->SetPastAnimation(Data->EntityID,tAState);
00195
00196
00197 *CDta.c++ = HDta;
00198 *CDta.c++ = 0;
00199 *CDta.s++ = 0;
00200 CIGI_SCOPY2(CDta.s++, &Data->EntityType);
00201 CIGI_SCOPY2(CDta.s++, &Data->ParentID);
00202 CIGI_SCOPY4(CDta.f++, &Data->Temperature);
00203 CIGI_SCOPY4(CDta.f++, &Data->Roll);
00204 CIGI_SCOPY4(CDta.f++, &Data->Pitch);
00205 CIGI_SCOPY4(CDta.f++, &Data->Yaw);
00206 talt = (float)Data->AltOrZoff;
00207 CIGI_SCOPY4(CDta.f++, &talt);
00208 CIGI_SCOPY8(CDta.d++, &Data->LatOrXoff);
00209 CIGI_SCOPY8(CDta.d++, &Data->LonOrYoff);
00210
00211 memcpy(Buff,tBuf,CIGI_ENTITY_CTRL_PACKET_SIZE_V1);
00212
00213 return(PacketSize);
00214
00215 }
00216
00217
00218
00219
00220
00221 int CigiEntityCtrlV1::Unpack(Cigi_uint8 * Buff, bool Swap, void *Spec)
00222 {
00223 float talt;
00224
00225 PackPointer CDta;
00226
00227 double DBuf[6];
00228
00229 Cigi_uint8 *tBuf = (Cigi_uint8 *)DBuf;
00230
00231 CigiAnimationTable *ATbl = (CigiAnimationTable *) Spec;
00232
00233 memcpy(tBuf,Buff,CIGI_ENTITY_CTRL_PACKET_SIZE_V1);
00234
00235 CDta.c = tBuf;
00236
00237 CDta.c += 2;
00238 CIGI_SCOPY2(&EntityID, CDta.s++);
00239
00240 Cigi_uint8 HDta = *CDta.c;
00241 AttachState = (AttachStateGrp)((HDta >> 6) &0x01);
00242 CollisionDetectEn = (CollisionDetectGrp)((HDta >> 5) & 0x01);
00243 SetEntityState((EntityStV1Grp)((HDta >> 7) & 0x01),false);
00244 AnimationState = (AnimationStateGrp)(((HDta >> 2) & 0x07) + 4);
00245
00246 PastAnimationState = (AnimationStateGrp)ATbl->GetPastAnimation(EntityID);
00247
00248 AnimationStateGrp tAState = AnimationState;
00249 if((tAState >= 0)&&(tAState <= 9))
00250 {
00251 tAState = ToV3[tAState];
00252 if((tAState >= 0)&&(tAState <= 3))
00253 ATbl->SetPastAnimation(EntityID,tAState);
00254 }
00255
00256 CDta.c += 4;
00257
00258 CIGI_SCOPY2(&EntityType, CDta.s++);
00259 CIGI_SCOPY2(&ParentID, CDta.s++);
00260 CIGI_SCOPY4(&Temperature, CDta.f++);
00261 CIGI_SCOPY4(&Roll, CDta.f++);
00262 CIGI_SCOPY4(&Pitch, CDta.f++);
00263 CIGI_SCOPY4(&Yaw, CDta.f++);
00264 CIGI_SCOPY4(&talt, CDta.f++);
00265 AltOrZoff = (double)talt;
00266 CIGI_SCOPY8(&LatOrXoff, CDta.d++);
00267 CIGI_SCOPY8(&LonOrYoff, CDta.d++);
00268
00269 Alpha = 255;
00270 Opacity = 100.0f;
00271
00272 return(CIGI_SUCCESS);
00273 }
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 int CigiEntityCtrlV1::SetHeading(const float Heading, bool bndchk)
00286 {
00287
00288 #ifndef CIGI_NO_BND_CHK
00289 if(bndchk && ((Heading < 0.0f)||(Heading > 360.0f)))
00290 {
00291 #ifndef CIGI_NO_EXCEPT
00292 throw CigiValueOutOfRangeException("Heading",(double)Heading,0.0,360.0);
00293 #endif
00294 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00295 }
00296 #endif
00297
00298 Yaw = Heading;
00299 return(CIGI_SUCCESS);
00300
00301 }
00302
00303
00304
00305
00306
00307 int CigiEntityCtrlV1::SetEntityState(const EntityStV1Grp EntityStateIn, bool bndchk)
00308 {
00309
00310 #ifndef CIGI_NO_BND_CHK
00311 if(bndchk && ((EntityStateIn < 0)||(EntityStateIn > 1)))
00312 {
00313 #ifndef CIGI_NO_EXCEPT
00314 throw CigiValueOutOfRangeException("EntityState",EntityStateIn,0,1);
00315 #endif
00316 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00317 }
00318 #endif
00319
00320 if(EntityStateIn == ConstructV1)
00321 EntityState = Active;
00322 else
00323 EntityState = Remove;
00324
00325 return(CIGI_SUCCESS);
00326
00327 }
00328
00329
00330
00331
00332
00333 int CigiEntityCtrlV1::SetEffectState(const EffectStateGrp EffectStateIn, bool bndchk)
00334 {
00335
00336 #ifndef CIGI_NO_BND_CHK
00337 if(bndchk && ((EffectStateIn < 0)||(EffectStateIn > 5)))
00338 {
00339 #ifndef CIGI_NO_EXCEPT
00340 throw CigiValueOutOfRangeException("EffectState",EffectStateIn,0,5);
00341 #endif
00342 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00343 }
00344 #endif
00345
00346 AnimationState = (AnimationStateGrp)(EffectStateIn + 4);
00347
00348 return(CIGI_SUCCESS);
00349
00350 }
00351
00352
00353
00354
00355
00356 CigiEntityCtrlV1::EntityStV1Grp CigiEntityCtrlV1::GetEntityState(void) const
00357 {
00358 EntityStV1Grp rslt;
00359
00360 if(EntityState == Active)
00361 rslt = ConstructV1;
00362 else
00363 rslt = DestructV1;
00364
00365 return(rslt);
00366
00367 }
00368
00369
00370
00371
00372
00373 CigiEntityCtrlV1::EffectStateGrp CigiEntityCtrlV1::GetEffectState() const
00374 {
00375
00376 AnimationStateGrp tAState = AnimationState;
00377 if((tAState >= 0)&&(tAState <= 9))
00378 tAState = ToV1[tAState];
00379 else
00380 tAState = NoAction;
00381
00382 if(tAState == Continue)
00383 {
00384 if((PastAnimationState == Stop) ||
00385 (PastAnimationState == Pause))
00386 tAState = LoadActivate;
00387 else
00388 tAState = NoAction;
00389 }
00390
00391 return((EffectStateGrp)(tAState - 4));
00392
00393 }
00394