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