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