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