| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include <stdlib.h> |
|---|
| 24 | #include <stdio.h> |
|---|
| 25 | #include <string.h> |
|---|
| 26 | |
|---|
| 27 | #include <trpage_geom.h> |
|---|
| 28 | #include <trpage_read.h> |
|---|
| 29 | |
|---|
| 30 | #if defined(_WIN32) |
|---|
| 31 | #define ALIGNMENT_WORKAROUND false |
|---|
| 32 | #else |
|---|
| 33 | #define ALIGNMENT_WORKAROUND true |
|---|
| 34 | #endif |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | trpgLightAttr::trpgLightAttr(void) |
|---|
| 41 | { |
|---|
| 42 | data.commentStr = NULL; |
|---|
| 43 | Reset(); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | trpgLightAttr::trpgLightAttr(const trpgLightAttr& in): |
|---|
| 47 | trpgReadWriteable(in) |
|---|
| 48 | { |
|---|
| 49 | data.commentStr = NULL; |
|---|
| 50 | operator=(in); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | trpgLightAttr::~trpgLightAttr(void) |
|---|
| 54 | { |
|---|
| 55 | if (data.commentStr) |
|---|
| 56 | delete [] data.commentStr; |
|---|
| 57 | data.commentStr = NULL; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | void trpgLightAttr::SetType( trpgLightAttr::LightType in_type ) |
|---|
| 63 | { |
|---|
| 64 | data.type = in_type; |
|---|
| 65 | } |
|---|
| 66 | void trpgLightAttr::SetDirectionality( trpgLightAttr::LightDirectionality in_directionality ) |
|---|
| 67 | { |
|---|
| 68 | data.directionality = in_directionality; |
|---|
| 69 | } |
|---|
| 70 | void trpgLightAttr::SetFrontColor( trpgColor in_frontColor ) |
|---|
| 71 | { |
|---|
| 72 | data.frontColor = in_frontColor; |
|---|
| 73 | } |
|---|
| 74 | void trpgLightAttr::SetFrontIntensity( float64 in_frontIntensity ) |
|---|
| 75 | { |
|---|
| 76 | data.frontIntensity = in_frontIntensity; |
|---|
| 77 | } |
|---|
| 78 | void trpgLightAttr::SetBackColor( trpgColor in_backColor ) |
|---|
| 79 | { |
|---|
| 80 | data.backColor = in_backColor; |
|---|
| 81 | } |
|---|
| 82 | void trpgLightAttr::SetBackIntensity( float64 in_backIntensity ) |
|---|
| 83 | { |
|---|
| 84 | data.backIntensity = in_backIntensity; |
|---|
| 85 | } |
|---|
| 86 | void trpgLightAttr::SetNormal( trpg3dPoint in_normal ) |
|---|
| 87 | { |
|---|
| 88 | data.normal = in_normal; |
|---|
| 89 | } |
|---|
| 90 | void trpgLightAttr::SetSMC( int32 in_smc ) |
|---|
| 91 | { |
|---|
| 92 | data.smc = in_smc; |
|---|
| 93 | } |
|---|
| 94 | void trpgLightAttr::SetFID( int32 in_fid ) |
|---|
| 95 | { |
|---|
| 96 | data.fid = in_fid; |
|---|
| 97 | } |
|---|
| 98 | void trpgLightAttr::SetFlags( int32 in_flags ) |
|---|
| 99 | { |
|---|
| 100 | data.flags = in_flags; |
|---|
| 101 | } |
|---|
| 102 | void trpgLightAttr::SetHLobeAngle( float64 in_hLobeAngle ) |
|---|
| 103 | { |
|---|
| 104 | data.horizontalLobeAngle = in_hLobeAngle; |
|---|
| 105 | } |
|---|
| 106 | void trpgLightAttr::SetVLobeAngle( float64 in_vLobeAngle ) |
|---|
| 107 | { |
|---|
| 108 | data.verticalLobeAngle = in_vLobeAngle; |
|---|
| 109 | } |
|---|
| 110 | void trpgLightAttr::SetLobeRollAngle( float64 in_lobeRollAngle ) |
|---|
| 111 | { |
|---|
| 112 | data.lobeRollAngle = in_lobeRollAngle; |
|---|
| 113 | } |
|---|
| 114 | void trpgLightAttr::SetLobeFalloff( float64 in_lobeFalloff ) |
|---|
| 115 | { |
|---|
| 116 | data.lobeFalloff = in_lobeFalloff; |
|---|
| 117 | } |
|---|
| 118 | void trpgLightAttr::SetAmbient( float64 in_ambientIntensity ) |
|---|
| 119 | { |
|---|
| 120 | data.ambientIntensity = in_ambientIntensity; |
|---|
| 121 | } |
|---|
| 122 | void trpgLightAttr::SetQuality( trpgLightAttr::LightQuality in_quality ) |
|---|
| 123 | { |
|---|
| 124 | data.quality = in_quality; |
|---|
| 125 | } |
|---|
| 126 | void trpgLightAttr::SetRascalSignificance( float64 in_rascalSignificance ) |
|---|
| 127 | { |
|---|
| 128 | data.rascalSignificance = in_rascalSignificance; |
|---|
| 129 | } |
|---|
| 130 | void trpgLightAttr::SetRandomIntensity( trpgLightAttr::LightQuality in_randomIntensity ) |
|---|
| 131 | { |
|---|
| 132 | data.randomIntensity = in_randomIntensity; |
|---|
| 133 | } |
|---|
| 134 | void trpgLightAttr::SetCalligraphicAttr( trpgLightAttr::CalligraphicAttr& in_calligraphicAttr ) |
|---|
| 135 | { |
|---|
| 136 | data.calligraphicAttr = in_calligraphicAttr; |
|---|
| 137 | } |
|---|
| 138 | void trpgLightAttr::SetCalligraphicDrawOrder( int32 in_drawOrder ) |
|---|
| 139 | { |
|---|
| 140 | data.calligraphicAttr.drawOrder = in_drawOrder; |
|---|
| 141 | } |
|---|
| 142 | void trpgLightAttr::SetCalligraphicMinDefocus( float64 in_minDefocus ) |
|---|
| 143 | { |
|---|
| 144 | data.calligraphicAttr.minDefocus = in_minDefocus; |
|---|
| 145 | } |
|---|
| 146 | void trpgLightAttr::SetCalligraphicMaxDefocus( float64 in_maxDefocus ) |
|---|
| 147 | { |
|---|
| 148 | data.calligraphicAttr.maxDefocus = in_maxDefocus; |
|---|
| 149 | } |
|---|
| 150 | void trpgLightAttr::SetPerformerAttr( trpgLightAttr::PerformerAttr& in_performerAttr ) |
|---|
| 151 | { |
|---|
| 152 | data.performerAttr = in_performerAttr; |
|---|
| 153 | } |
|---|
| 154 | void trpgLightAttr::SetPerformerFlags( int32 in_flags ) |
|---|
| 155 | { |
|---|
| 156 | data.performerAttr.flags = in_flags & trpgLightAttr::trpg_PerformerMask; |
|---|
| 157 | data.flags |= data.performerAttr.flags; |
|---|
| 158 | } |
|---|
| 159 | void trpgLightAttr::SetPerformerMinPixelSize( float64 in_minPxSize ) |
|---|
| 160 | { |
|---|
| 161 | data.performerAttr.minPixelSize = in_minPxSize; |
|---|
| 162 | } |
|---|
| 163 | void trpgLightAttr::SetPerformerMaxPixelSize( float64 in_maxPxSize ) |
|---|
| 164 | { |
|---|
| 165 | data.performerAttr.maxPixelSize = in_maxPxSize; |
|---|
| 166 | } |
|---|
| 167 | void trpgLightAttr::SetPerformerActualSize( float64 in_actualSize ) |
|---|
| 168 | { |
|---|
| 169 | data.performerAttr.actualSize = in_actualSize; |
|---|
| 170 | } |
|---|
| 171 | void trpgLightAttr::SetPerformerTpPixelSize( float64 in_tpPixelSize ) |
|---|
| 172 | { |
|---|
| 173 | data.performerAttr.transparentPixelSize = in_tpPixelSize; |
|---|
| 174 | } |
|---|
| 175 | void trpgLightAttr::SetPerformerTpFalloffExp( float64 in_tpFalloffExp ) |
|---|
| 176 | { |
|---|
| 177 | data.performerAttr.transparentFallofExp = in_tpFalloffExp; |
|---|
| 178 | } |
|---|
| 179 | void trpgLightAttr::SetPerformerTpScale( float64 in_tpScale ) |
|---|
| 180 | { |
|---|
| 181 | data.performerAttr.transparentScale = in_tpScale; |
|---|
| 182 | } |
|---|
| 183 | void trpgLightAttr::SetPerformerTpClamp( float64 in_tpClamp ) |
|---|
| 184 | { |
|---|
| 185 | data.performerAttr.transparentClamp = in_tpClamp; |
|---|
| 186 | } |
|---|
| 187 | void trpgLightAttr::SetPerformerFogScale( float64 in_fogScale ) |
|---|
| 188 | { |
|---|
| 189 | data.performerAttr.fogScale = in_fogScale; |
|---|
| 190 | } |
|---|
| 191 | void trpgLightAttr::SetAnimationAttr( trpgLightAttr::AnimationAttr& in_animationAttr ) |
|---|
| 192 | { |
|---|
| 193 | data.animationAttr = in_animationAttr; |
|---|
| 194 | } |
|---|
| 195 | void trpgLightAttr::SetAnimationPeriod( float64 in_period ) |
|---|
| 196 | { |
|---|
| 197 | data.animationAttr.period = in_period; |
|---|
| 198 | } |
|---|
| 199 | void trpgLightAttr::SetAnimationPhaseDelay( float64 in_phaseDelay ) |
|---|
| 200 | { |
|---|
| 201 | data.animationAttr.phaseDelay = in_phaseDelay; |
|---|
| 202 | } |
|---|
| 203 | void trpgLightAttr::SetAnimationTimeOn( float64 in_timeOn ) |
|---|
| 204 | { |
|---|
| 205 | data.animationAttr.timeOn = in_timeOn; |
|---|
| 206 | } |
|---|
| 207 | void trpgLightAttr::SetAnimationVector( trpg3dPoint in_vector ) |
|---|
| 208 | { |
|---|
| 209 | data.animationAttr.vector = in_vector; |
|---|
| 210 | } |
|---|
| 211 | void trpgLightAttr::SetAnimationFlags( int32 flags ) |
|---|
| 212 | { |
|---|
| 213 | data.animationAttr.flags = flags & trpgLightAttr::trpg_AnimationMask; |
|---|
| 214 | data.flags |= data.animationAttr.flags; |
|---|
| 215 | } |
|---|
| 216 | void trpgLightAttr::SetComment(const char *inStr) |
|---|
| 217 | { |
|---|
| 218 | if (!inStr) |
|---|
| 219 | return; |
|---|
| 220 | |
|---|
| 221 | if (data.commentStr) |
|---|
| 222 | delete [] data.commentStr; |
|---|
| 223 | data.commentStr = new char[strlen(inStr)+1]; |
|---|
| 224 | strcpy(data.commentStr,inStr); |
|---|
| 225 | } |
|---|
| 226 | |
|---|
| 227 | void trpgLightAttr::GetType( trpgLightAttr::LightType& out_type ) |
|---|
| 228 | { |
|---|
| 229 | out_type = data.type; |
|---|
| 230 | } |
|---|
| 231 | void trpgLightAttr::GetDirectionality( trpgLightAttr::LightDirectionality& out_directionality ) |
|---|
| 232 | { |
|---|
| 233 | out_directionality = data.directionality; |
|---|
| 234 | } |
|---|
| 235 | void trpgLightAttr::GetFrontColor( trpgColor& out_frontColor ) |
|---|
| 236 | { |
|---|
| 237 | out_frontColor = data.frontColor; |
|---|
| 238 | } |
|---|
| 239 | void trpgLightAttr::GetFrontIntensity( float64& out_frontIntensity ) |
|---|
| 240 | { |
|---|
| 241 | out_frontIntensity = data.frontIntensity; |
|---|
| 242 | } |
|---|
| 243 | void trpgLightAttr::GetBackColor( trpgColor& out_backColor ) |
|---|
| 244 | { |
|---|
| 245 | out_backColor = data.backColor; |
|---|
| 246 | } |
|---|
| 247 | void trpgLightAttr::GetBackIntensity( float64& out_backIntensity ) |
|---|
| 248 | { |
|---|
| 249 | out_backIntensity = data.backIntensity; |
|---|
| 250 | } |
|---|
| 251 | void trpgLightAttr::GetNormal( trpg3dPoint& out_normal ) |
|---|
| 252 | { |
|---|
| 253 | out_normal = data.normal; |
|---|
| 254 | } |
|---|
| 255 | void trpgLightAttr::GetSMC( int32& out_smc ) |
|---|
| 256 | { |
|---|
| 257 | out_smc = data.smc; |
|---|
| 258 | } |
|---|
| 259 | void trpgLightAttr::GetFID( int32& out_fid ) |
|---|
| 260 | { |
|---|
| 261 | out_fid = data.fid; |
|---|
| 262 | } |
|---|
| 263 | void trpgLightAttr::GetFlags( int32& out_flags ) |
|---|
| 264 | { |
|---|
| 265 | out_flags = data.flags; |
|---|
| 266 | } |
|---|
| 267 | void trpgLightAttr::GetHLobeAngle( float64& out_hLobeAngle ) |
|---|
| 268 | { |
|---|
| 269 | out_hLobeAngle = data.horizontalLobeAngle; |
|---|
| 270 | } |
|---|
| 271 | void trpgLightAttr::GetVLobeAngle( float64& out_vLobeAngle ) |
|---|
| 272 | { |
|---|
| 273 | out_vLobeAngle = data.verticalLobeAngle; |
|---|
| 274 | } |
|---|
| 275 | void trpgLightAttr::GetLobeRollAngle( float64& out_lobeRollAngle ) |
|---|
| 276 | { |
|---|
| 277 | out_lobeRollAngle = data.lobeRollAngle; |
|---|
| 278 | } |
|---|
| 279 | void trpgLightAttr::GetLobeFalloff( float64& out_lobeFalloff ) |
|---|
| 280 | { |
|---|
| 281 | out_lobeFalloff = data.lobeFalloff; |
|---|
| 282 | } |
|---|
| 283 | void trpgLightAttr::GetAmbient( float64& out_ambientIntensity ) |
|---|
| 284 | { |
|---|
| 285 | out_ambientIntensity = data.ambientIntensity; |
|---|
| 286 | } |
|---|
| 287 | void trpgLightAttr::GetQuality( trpgLightAttr::LightQuality& out_quality ) |
|---|
| 288 | { |
|---|
| 289 | out_quality = data.quality; |
|---|
| 290 | } |
|---|
| 291 | void trpgLightAttr::GetRascalSignificance( float64& out_rascalSignificance ) |
|---|
| 292 | { |
|---|
| 293 | out_rascalSignificance = data.rascalSignificance; |
|---|
| 294 | } |
|---|
| 295 | void trpgLightAttr::GetRandomIntensity( trpgLightAttr::LightQuality& out_randomIntensity ) |
|---|
| 296 | { |
|---|
| 297 | out_randomIntensity = data.randomIntensity; |
|---|
| 298 | } |
|---|
| 299 | void trpgLightAttr::GetCalligraphicAttr( trpgLightAttr::CalligraphicAttr& out_calligraphicAttr ) |
|---|
| 300 | { |
|---|
| 301 | out_calligraphicAttr = data.calligraphicAttr; |
|---|
| 302 | } |
|---|
| 303 | void trpgLightAttr::GetCalligraphicDrawOrder( int32& out_drawOrder ) |
|---|
| 304 | { |
|---|
| 305 | out_drawOrder = data.calligraphicAttr.drawOrder; |
|---|
| 306 | } |
|---|
| 307 | void trpgLightAttr::GetCalligraphicMinDefocus( float64& out_minDefocus ) |
|---|
| 308 | { |
|---|
| 309 | out_minDefocus = data.calligraphicAttr.minDefocus; |
|---|
| 310 | } |
|---|
| 311 | void trpgLightAttr::GetCalligraphicMaxDefocus( float64& out_maxDefocus ) |
|---|
| 312 | { |
|---|
| 313 | out_maxDefocus = data.calligraphicAttr.maxDefocus; |
|---|
| 314 | } |
|---|
| 315 | void trpgLightAttr::GetPerformerAttr( trpgLightAttr::PerformerAttr& out_performerAttr ) |
|---|
| 316 | { |
|---|
| 317 | out_performerAttr = data.performerAttr; |
|---|
| 318 | } |
|---|
| 319 | void trpgLightAttr::GetPerformerFlags( int32& out_flags ) |
|---|
| 320 | { |
|---|
| 321 | out_flags = data.performerAttr.flags; |
|---|
| 322 | } |
|---|
| 323 | void trpgLightAttr::GetPerformerMinPixelSize( float64& out_minPxSize ) |
|---|
| 324 | { |
|---|
| 325 | out_minPxSize = data.performerAttr.minPixelSize; |
|---|
| 326 | } |
|---|
| 327 | void trpgLightAttr::GetPerformerMaxPixelSize( float64& out_maxPxSize ) |
|---|
| 328 | { |
|---|
| 329 | out_maxPxSize = data.performerAttr.maxPixelSize; |
|---|
| 330 | } |
|---|
| 331 | void trpgLightAttr::GetPerformerActualSize( float64& out_actualSize ) |
|---|
| 332 | { |
|---|
| 333 | out_actualSize = data.performerAttr.actualSize; |
|---|
| 334 | } |
|---|
| 335 | void trpgLightAttr::GetPerformerTpPixelSize( float64& out_tpPixelSize ) |
|---|
| 336 | { |
|---|
| 337 | out_tpPixelSize = data.performerAttr.transparentPixelSize; |
|---|
| 338 | } |
|---|
| 339 | void trpgLightAttr::GetPerformerTpFalloffExp( float64& out_tpFalloffExp ) |
|---|
| 340 | { |
|---|
| 341 | out_tpFalloffExp = data.performerAttr.transparentFallofExp; |
|---|
| 342 | } |
|---|
| 343 | void trpgLightAttr::GetPerformerTpScale( float64& out_tpScale ) |
|---|
| 344 | { |
|---|
| 345 | out_tpScale = data.performerAttr.transparentScale; |
|---|
| 346 | } |
|---|
| 347 | void trpgLightAttr::GetPerformerTpClamp( float64& out_tpClamp ) |
|---|
| 348 | { |
|---|
| 349 | out_tpClamp = data.performerAttr.transparentClamp; |
|---|
| 350 | } |
|---|
| 351 | void trpgLightAttr::GetPerformerFogScale( float64& out_fogScale ) |
|---|
| 352 | { |
|---|
| 353 | out_fogScale = data.performerAttr.fogScale; |
|---|
| 354 | } |
|---|
| 355 | void trpgLightAttr::GetAnimationAttr( trpgLightAttr::AnimationAttr& out_animationAttr ) |
|---|
| 356 | { |
|---|
| 357 | out_animationAttr = data.animationAttr; |
|---|
| 358 | } |
|---|
| 359 | void trpgLightAttr::GetAnimationPeriod( float64& out_period ) |
|---|
| 360 | { |
|---|
| 361 | out_period = data.animationAttr.period; |
|---|
| 362 | } |
|---|
| 363 | void trpgLightAttr::GetAnimationPhaseDelay( float64& out_phaseDelay ) |
|---|
| 364 | { |
|---|
| 365 | out_phaseDelay = data.animationAttr.phaseDelay; |
|---|
| 366 | } |
|---|
| 367 | void trpgLightAttr::GetAnimationTimeOn( float64& out_timeOn ) |
|---|
| 368 | { |
|---|
| 369 | out_timeOn = data.animationAttr.timeOn; |
|---|
| 370 | } |
|---|
| 371 | void trpgLightAttr::GetAnimationVector( trpg3dPoint& out_vector ) |
|---|
| 372 | { |
|---|
| 373 | out_vector = data.animationAttr.vector; |
|---|
| 374 | } |
|---|
| 375 | void trpgLightAttr::GetAnimationFlags( int32& flags ) |
|---|
| 376 | { |
|---|
| 377 | flags = data.animationAttr.flags; |
|---|
| 378 | } |
|---|
| 379 | const char *trpgLightAttr::GetComment() |
|---|
| 380 | { |
|---|
| 381 | return data.commentStr; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | bool trpgLightAttr::Write(trpgWriteBuffer &buf) |
|---|
| 385 | { |
|---|
| 386 | buf.Begin(TRPGLIGHTATTR); |
|---|
| 387 | |
|---|
| 388 | buf.Begin(TRPGLIGHTATTR_BASIC); |
|---|
| 389 | buf.Add((int)data.type); |
|---|
| 390 | buf.Add((int)data.directionality); |
|---|
| 391 | buf.Add(data.frontColor); |
|---|
| 392 | buf.Add(data.frontIntensity); |
|---|
| 393 | buf.Add(data.backColor); |
|---|
| 394 | buf.Add(data.backIntensity); |
|---|
| 395 | buf.Add(data.normal); |
|---|
| 396 | buf.Add(data.smc); |
|---|
| 397 | buf.Add(data.fid); |
|---|
| 398 | buf.Add(data.flags); |
|---|
| 399 | buf.Add(data.horizontalLobeAngle); |
|---|
| 400 | buf.Add(data.verticalLobeAngle); |
|---|
| 401 | buf.Add(data.lobeRollAngle); |
|---|
| 402 | buf.Add(data.lobeFalloff); |
|---|
| 403 | buf.Add(data.ambientIntensity); |
|---|
| 404 | buf.Add((int)data.quality); |
|---|
| 405 | buf.Add((int)data.randomIntensity); |
|---|
| 406 | buf.End(); |
|---|
| 407 | |
|---|
| 408 | buf.Begin(TRPGLIGHTATTR_RASCAL); |
|---|
| 409 | buf.Add(data.rascalSignificance); |
|---|
| 410 | buf.End(); |
|---|
| 411 | |
|---|
| 412 | buf.Begin(TRPGLIGHTATTR_CALLIGRAPHIC); |
|---|
| 413 | buf.Add(data.calligraphicAttr.drawOrder); |
|---|
| 414 | buf.Add(data.calligraphicAttr.minDefocus); |
|---|
| 415 | buf.Add(data.calligraphicAttr.maxDefocus); |
|---|
| 416 | buf.End(); |
|---|
| 417 | |
|---|
| 418 | buf.Begin(TRPGLIGHTATTR_PERFORMER); |
|---|
| 419 | buf.Add(data.performerAttr.actualSize); |
|---|
| 420 | buf.Add(data.performerAttr.fogScale); |
|---|
| 421 | buf.Add(data.performerAttr.minPixelSize); |
|---|
| 422 | buf.Add(data.performerAttr.maxPixelSize); |
|---|
| 423 | buf.Add(data.performerAttr.transparentClamp); |
|---|
| 424 | buf.Add(data.performerAttr.transparentFallofExp); |
|---|
| 425 | buf.Add(data.performerAttr.transparentPixelSize); |
|---|
| 426 | buf.Add(data.performerAttr.transparentScale); |
|---|
| 427 | buf.End(); |
|---|
| 428 | |
|---|
| 429 | buf.Begin(TRPGLIGHTATTR_ANIMATION); |
|---|
| 430 | buf.Add(data.animationAttr.period); |
|---|
| 431 | buf.Add(data.animationAttr.phaseDelay); |
|---|
| 432 | buf.Add(data.animationAttr.timeOn); |
|---|
| 433 | buf.Add(data.animationAttr.vector); |
|---|
| 434 | buf.End(); |
|---|
| 435 | |
|---|
| 436 | if (data.commentStr) { |
|---|
| 437 | buf.Begin(TRPGLIGHTATTR_COMMENT); |
|---|
| 438 | buf.Add(data.commentStr); |
|---|
| 439 | buf.End(); |
|---|
| 440 | } |
|---|
| 441 | |
|---|
| 442 | if(writeHandle) { |
|---|
| 443 | buf.Begin(TRPGLIGHTATTR_HANDLE); |
|---|
| 444 | buf.Add((int)handle); |
|---|
| 445 | buf.End(); |
|---|
| 446 | } |
|---|
| 447 | buf.End(); |
|---|
| 448 | |
|---|
| 449 | return true; |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | class lightAttrCB : public trpgr_Callback { |
|---|
| 456 | public: |
|---|
| 457 | void * Parse(trpgToken,trpgReadBuffer &); |
|---|
| 458 | trpgLightAttr *lightAttr; |
|---|
| 459 | }; |
|---|
| 460 | void * lightAttrCB::Parse(trpgToken tok,trpgReadBuffer &buf) |
|---|
| 461 | { |
|---|
| 462 | int type_data; |
|---|
| 463 | int directionality_data; |
|---|
| 464 | trpgColor color_data;; |
|---|
| 465 | float64 float64_data; |
|---|
| 466 | trpg3dPoint point_data;; |
|---|
| 467 | int32 int32_data; |
|---|
| 468 | int quality_data; |
|---|
| 469 | char commentStr[1024]; |
|---|
| 470 | |
|---|
| 471 | try { |
|---|
| 472 | switch (tok) { |
|---|
| 473 | case TRPGLIGHTATTR_BASIC: |
|---|
| 474 | buf.Get(type_data); |
|---|
| 475 | lightAttr->SetType((trpgLightAttr::LightType)type_data); |
|---|
| 476 | buf.Get(directionality_data); |
|---|
| 477 | lightAttr->SetDirectionality((trpgLightAttr::LightDirectionality)directionality_data); |
|---|
| 478 | buf.Get(color_data); |
|---|
| 479 | lightAttr->SetFrontColor(color_data); |
|---|
| 480 | buf.Get(float64_data); |
|---|
| 481 | lightAttr->SetFrontIntensity(float64_data); |
|---|
| 482 | buf.Get(color_data); |
|---|
| 483 | lightAttr->SetBackColor(color_data); |
|---|
| 484 | buf.Get(float64_data); |
|---|
| 485 | lightAttr->SetBackIntensity(float64_data); |
|---|
| 486 | buf.Get(point_data); |
|---|
| 487 | lightAttr->SetNormal(point_data); |
|---|
| 488 | buf.Get(int32_data); |
|---|
| 489 | lightAttr->SetSMC(int32_data); |
|---|
| 490 | buf.Get(int32_data); |
|---|
| 491 | lightAttr->SetFID(int32_data); |
|---|
| 492 | buf.Get(int32_data); |
|---|
| 493 | lightAttr->SetFlags(int32_data); |
|---|
| 494 | lightAttr->SetPerformerFlags(int32_data); |
|---|
| 495 | lightAttr->SetAnimationFlags(int32_data); |
|---|
| 496 | buf.Get(float64_data); |
|---|
| 497 | lightAttr->SetHLobeAngle(float64_data); |
|---|
| 498 | buf.Get(float64_data); |
|---|
| 499 | lightAttr->SetVLobeAngle(float64_data); |
|---|
| 500 | buf.Get(float64_data); |
|---|
| 501 | lightAttr->SetLobeRollAngle(float64_data); |
|---|
| 502 | buf.Get(float64_data); |
|---|
| 503 | lightAttr->SetLobeFalloff(float64_data); |
|---|
| 504 | buf.Get(float64_data); |
|---|
| 505 | lightAttr->SetAmbient(float64_data); |
|---|
| 506 | buf.Get(quality_data); |
|---|
| 507 | lightAttr->SetQuality((trpgLightAttr::LightQuality)quality_data); |
|---|
| 508 | buf.Get(quality_data); |
|---|
| 509 | lightAttr->SetRandomIntensity((trpgLightAttr::LightQuality)quality_data); |
|---|
| 510 | break; |
|---|
| 511 | case TRPGLIGHTATTR_RASCAL: |
|---|
| 512 | buf.Get(float64_data); |
|---|
| 513 | lightAttr->SetRascalSignificance(float64_data); |
|---|
| 514 | break; |
|---|
| 515 | case TRPGLIGHTATTR_PERFORMER: |
|---|
| 516 | buf.Get(float64_data); |
|---|
| 517 | lightAttr->SetPerformerActualSize(float64_data); |
|---|
| 518 | buf.Get(float64_data); |
|---|
| 519 | lightAttr->SetPerformerFogScale(float64_data); |
|---|
| 520 | buf.Get(float64_data); |
|---|
| 521 | lightAttr->SetPerformerMinPixelSize(float64_data); |
|---|
| 522 | buf.Get(float64_data); |
|---|
| 523 | lightAttr->SetPerformerMaxPixelSize(float64_data); |
|---|
| 524 | buf.Get(float64_data); |
|---|
| 525 | lightAttr->SetPerformerTpClamp(float64_data); |
|---|
| 526 | buf.Get(float64_data); |
|---|
| 527 | lightAttr->SetPerformerTpFalloffExp(float64_data); |
|---|
| 528 | buf.Get(float64_data); |
|---|
| 529 | lightAttr->SetPerformerTpPixelSize(float64_data); |
|---|
| 530 | buf.Get(float64_data); |
|---|
| 531 | lightAttr->SetPerformerTpScale(float64_data); |
|---|
| 532 | break; |
|---|
| 533 | case TRPGLIGHTATTR_CALLIGRAPHIC: |
|---|
| 534 | buf.Get(int32_data); |
|---|
| 535 | lightAttr->SetCalligraphicDrawOrder(int32_data); |
|---|
| 536 | buf.Get(float64_data); |
|---|
| 537 | lightAttr->SetCalligraphicMinDefocus(float64_data); |
|---|
| 538 | buf.Get(float64_data); |
|---|
| 539 | lightAttr->SetCalligraphicMaxDefocus(float64_data); |
|---|
| 540 | break; |
|---|
| 541 | case TRPGLIGHTATTR_ANIMATION: |
|---|
| 542 | buf.Get(float64_data); |
|---|
| 543 | lightAttr->SetAnimationPeriod(float64_data); |
|---|
| 544 | buf.Get(float64_data); |
|---|
| 545 | lightAttr->SetAnimationPhaseDelay(float64_data); |
|---|
| 546 | buf.Get(float64_data); |
|---|
| 547 | lightAttr->SetAnimationTimeOn(float64_data); |
|---|
| 548 | buf.Get(point_data); |
|---|
| 549 | lightAttr->SetAnimationVector(point_data); |
|---|
| 550 | break; |
|---|
| 551 | case TRPGLIGHTATTR_COMMENT: |
|---|
| 552 | buf.Get(commentStr,1024); |
|---|
| 553 | lightAttr->SetComment(commentStr); |
|---|
| 554 | break; |
|---|
| 555 | case TRPGLIGHTATTR_HANDLE: |
|---|
| 556 | int hdl; |
|---|
| 557 | buf.Get(hdl); |
|---|
| 558 | lightAttr->SetHandle(hdl); |
|---|
| 559 | break; |
|---|
| 560 | default: |
|---|
| 561 | break; |
|---|
| 562 | } |
|---|
| 563 | } |
|---|
| 564 | catch (...) { |
|---|
| 565 | return NULL; |
|---|
| 566 | } |
|---|
| 567 | |
|---|
| 568 | return lightAttr; |
|---|
| 569 | } |
|---|
| 570 | |
|---|
| 571 | |
|---|
| 572 | bool trpgLightAttr::Read(trpgReadBuffer &buf) |
|---|
| 573 | { |
|---|
| 574 | Reset(); |
|---|
| 575 | |
|---|
| 576 | trpgr_Parser parse; |
|---|
| 577 | lightAttrCB lightAttrCb; |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | |
|---|
| 581 | lightAttrCb.lightAttr = this; |
|---|
| 582 | parse.AddCallback(TRPGLIGHTATTR_BASIC,&lightAttrCb,false); |
|---|
| 583 | parse.AddCallback(TRPGLIGHTATTR_PERFORMER,&lightAttrCb,false); |
|---|
| 584 | parse.AddCallback(TRPGLIGHTATTR_RASCAL,&lightAttrCb,false); |
|---|
| 585 | parse.AddCallback(TRPGLIGHTATTR_CALLIGRAPHIC,&lightAttrCb,false); |
|---|
| 586 | parse.AddCallback(TRPGLIGHTATTR_ANIMATION,&lightAttrCb,false); |
|---|
| 587 | parse.AddCallback(TRPGLIGHTATTR_COMMENT,&lightAttrCb,false); |
|---|
| 588 | parse.AddCallback(TRPGLIGHTATTR_HANDLE,&lightAttrCb,false); |
|---|
| 589 | parse.Parse(buf); |
|---|
| 590 | |
|---|
| 591 | return isValid(); |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | bool trpgLightAttr::isValid(void) const |
|---|
| 595 | { |
|---|
| 596 | return true; |
|---|
| 597 | } |
|---|
| 598 | |
|---|
| 599 | trpgLightAttr& trpgLightAttr::operator = (const trpgLightAttr& in) |
|---|
| 600 | { |
|---|
| 601 | data = in.data; |
|---|
| 602 | if (in.data.commentStr) { |
|---|
| 603 | data.commentStr = new char[strlen(in.data.commentStr)+1]; |
|---|
| 604 | strcpy(data.commentStr,in.data.commentStr); |
|---|
| 605 | } |
|---|
| 606 | handle = in.handle; |
|---|
| 607 | writeHandle = in.writeHandle; |
|---|
| 608 | return *this; |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | bool trpgLightAttr::operator == (const trpgLightAttr& in) |
|---|
| 612 | { |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | if ( data.type != in.data.type ) |
|---|
| 617 | return false; |
|---|
| 618 | if ( data.directionality != in.data.directionality ) |
|---|
| 619 | return false; |
|---|
| 620 | if ( data.frontColor != in.data.frontColor ) |
|---|
| 621 | return false; |
|---|
| 622 | if ( data.frontIntensity != in.data.frontIntensity ) |
|---|
| 623 | return false; |
|---|
| 624 | if ( data.backColor != in.data.backColor ) |
|---|
| 625 | return false; |
|---|
| 626 | if ( data.backIntensity != in.data.backIntensity ) |
|---|
| 627 | return false; |
|---|
| 628 | if ( data.normal != in.data.normal ) |
|---|
| 629 | return false; |
|---|
| 630 | if ( data.smc != in.data.smc ) |
|---|
| 631 | return false; |
|---|
| 632 | if ( data.fid != in.data.fid ) |
|---|
| 633 | return false; |
|---|
| 634 | if ( data.flags != in.data.flags ) |
|---|
| 635 | return false; |
|---|
| 636 | if ( data.horizontalLobeAngle != in.data.horizontalLobeAngle ) |
|---|
| 637 | return false; |
|---|
| 638 | if ( data.verticalLobeAngle != in.data.verticalLobeAngle ) |
|---|
| 639 | return false; |
|---|
| 640 | if ( data.lobeRollAngle != in.data.lobeRollAngle ) |
|---|
| 641 | return false; |
|---|
| 642 | if ( data.lobeFalloff != in.data.lobeFalloff ) |
|---|
| 643 | return false; |
|---|
| 644 | if ( data.ambientIntensity != in.data.ambientIntensity ) |
|---|
| 645 | return false; |
|---|
| 646 | if ( data.quality != in.data.quality ) |
|---|
| 647 | return false; |
|---|
| 648 | if ( data.randomIntensity != in.data.randomIntensity ) |
|---|
| 649 | return false; |
|---|
| 650 | if ( data.rascalSignificance != in.data.rascalSignificance ) |
|---|
| 651 | return false; |
|---|
| 652 | if ( data.calligraphicAttr.drawOrder != in.data.calligraphicAttr.drawOrder ) |
|---|
| 653 | return false; |
|---|
| 654 | if ( data.calligraphicAttr.minDefocus != in.data.calligraphicAttr.minDefocus ) |
|---|
| 655 | return false; |
|---|
| 656 | if ( data.calligraphicAttr.maxDefocus != in.data.calligraphicAttr.maxDefocus ) |
|---|
| 657 | return false; |
|---|
| 658 | if ( data.performerAttr.flags != in.data.performerAttr.flags ) |
|---|
| 659 | return false; |
|---|
| 660 | if ( data.performerAttr.minPixelSize != in.data.performerAttr.minPixelSize ) |
|---|
| 661 | return false; |
|---|
| 662 | if ( data.performerAttr.maxPixelSize != in.data.performerAttr.maxPixelSize ) |
|---|
| 663 | return false; |
|---|
| 664 | if ( data.performerAttr.actualSize != in.data.performerAttr.actualSize ) |
|---|
| 665 | return false; |
|---|
| 666 | if ( data.performerAttr.transparentPixelSize != in.data.performerAttr.transparentPixelSize ) |
|---|
| 667 | return false; |
|---|
| 668 | if ( data.performerAttr.transparentFallofExp != in.data.performerAttr.transparentFallofExp ) |
|---|
| 669 | return false; |
|---|
| 670 | if ( data.performerAttr.transparentScale != in.data.performerAttr.transparentScale ) |
|---|
| 671 | return false; |
|---|
| 672 | if ( data.performerAttr.transparentClamp != in.data.performerAttr.transparentClamp ) |
|---|
| 673 | return false; |
|---|
| 674 | if ( data.performerAttr.fogScale != in.data.performerAttr.fogScale ) |
|---|
| 675 | return false; |
|---|
| 676 | if ( data.animationAttr.period != in.data.animationAttr.period ) |
|---|
| 677 | return false; |
|---|
| 678 | if ( data.animationAttr.phaseDelay != in.data.animationAttr.phaseDelay ) |
|---|
| 679 | return false; |
|---|
| 680 | if ( data.animationAttr.timeOn != in.data.animationAttr.timeOn ) |
|---|
| 681 | return false; |
|---|
| 682 | if ( data.animationAttr.vector != in.data.animationAttr.vector ) |
|---|
| 683 | return false; |
|---|
| 684 | if ( data.animationAttr.flags != in.data.animationAttr.flags ) |
|---|
| 685 | return false; |
|---|
| 686 | if ( (data.commentStr && !in.data.commentStr) || |
|---|
| 687 | (!data.commentStr && in.data.commentStr)) |
|---|
| 688 | return false; |
|---|
| 689 | if (data.commentStr && in.data.commentStr && strcmp(data.commentStr,in.data.commentStr)) |
|---|
| 690 | return false; |
|---|
| 691 | if (handle != in.handle) |
|---|
| 692 | return false; |
|---|
| 693 | if (writeHandle != in.writeHandle) |
|---|
| 694 | return false; |
|---|
| 695 | return true; |
|---|
| 696 | } |
|---|
| 697 | |
|---|
| 698 | bool trpgLightAttr::operator != (const trpgLightAttr& in) |
|---|
| 699 | { |
|---|
| 700 | return !operator==(in); |
|---|
| 701 | } |
|---|
| 702 | |
|---|
| 703 | void trpgLightAttr::Reset(void) |
|---|
| 704 | { |
|---|
| 705 | errMess[0] = '\0'; |
|---|
| 706 | data.type = trpg_Raster; |
|---|
| 707 | data.directionality = trpg_Omnidirectional; |
|---|
| 708 | data.frontColor = trpgColor(0,0,0); |
|---|
| 709 | data.frontIntensity = 0; |
|---|
| 710 | data.backColor = trpgColor(0,0,0); |
|---|
| 711 | data.backIntensity = 0; |
|---|
| 712 | data.normal = trpg3dPoint(0,0,1); |
|---|
| 713 | data.smc = 0; |
|---|
| 714 | data.fid = 0; |
|---|
| 715 | data.flags = 0; |
|---|
| 716 | data.horizontalLobeAngle = 0; |
|---|
| 717 | data.verticalLobeAngle = 0; |
|---|
| 718 | data.lobeRollAngle = 0; |
|---|
| 719 | data.lobeFalloff = 0; |
|---|
| 720 | data.ambientIntensity = 0; |
|---|
| 721 | data.quality = trpg_Low; |
|---|
| 722 | data.randomIntensity = trpg_Low; |
|---|
| 723 | data.rascalSignificance = 0; |
|---|
| 724 | data.calligraphicAttr.drawOrder = 0; |
|---|
| 725 | data.calligraphicAttr.minDefocus = 0; |
|---|
| 726 | data.calligraphicAttr.maxDefocus = 0; |
|---|
| 727 | data.performerAttr.flags = 0; |
|---|
| 728 | data.performerAttr.minPixelSize = 0; |
|---|
| 729 | data.performerAttr.maxPixelSize = 0; |
|---|
| 730 | data.performerAttr.actualSize = 0; |
|---|
| 731 | data.performerAttr.transparentPixelSize = 0; |
|---|
| 732 | data.performerAttr.transparentFallofExp = 0; |
|---|
| 733 | data.performerAttr.transparentScale = 0; |
|---|
| 734 | data.performerAttr.transparentClamp = 0; |
|---|
| 735 | data.performerAttr.fogScale = 0; |
|---|
| 736 | data.animationAttr.period = 0; |
|---|
| 737 | data.animationAttr.phaseDelay = 0; |
|---|
| 738 | data.animationAttr.timeOn = 0; |
|---|
| 739 | data.animationAttr.vector = trpg3dPoint(0,0,1); |
|---|
| 740 | data.animationAttr.flags = 0; |
|---|
| 741 | if (data.commentStr) |
|---|
| 742 | delete [] data.commentStr; |
|---|
| 743 | data.commentStr = NULL; |
|---|
| 744 | handle = -1; |
|---|
| 745 | writeHandle = false; |
|---|
| 746 | } |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | |
|---|
| 750 | |
|---|
| 751 | |
|---|
| 752 | trpgLight::trpgLight(void) |
|---|
| 753 | { |
|---|
| 754 | index = -1; |
|---|
| 755 | } |
|---|
| 756 | |
|---|
| 757 | trpgLight::trpgLight(const trpgLight &in): |
|---|
| 758 | trpgReadWriteable(in) |
|---|
| 759 | { |
|---|
| 760 | operator=(in); |
|---|
| 761 | } |
|---|
| 762 | |
|---|
| 763 | trpgLight::~trpgLight(void) |
|---|
| 764 | { |
|---|
| 765 | Reset(); |
|---|
| 766 | } |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | void trpgLight::SetAttrIndex(int ix) |
|---|
| 770 | { |
|---|
| 771 | index = ix; |
|---|
| 772 | } |
|---|
| 773 | |
|---|
| 774 | |
|---|
| 775 | void trpgLight::AddVertex(trpg3dPoint pt) |
|---|
| 776 | { |
|---|
| 777 | lightPoints.push_back(pt); |
|---|
| 778 | } |
|---|
| 779 | |
|---|
| 780 | |
|---|
| 781 | void trpgLight::GetNumVertices(uint32 &nvertices) const |
|---|
| 782 | { |
|---|
| 783 | nvertices = lightPoints.size(); |
|---|
| 784 | } |
|---|
| 785 | |
|---|
| 786 | |
|---|
| 787 | bool trpgLight::GetVertex(uint32 ix, trpg3dPoint &pt) const |
|---|
| 788 | { |
|---|
| 789 | if (ix < lightPoints.size() ) { |
|---|
| 790 | pt = lightPoints[ix]; |
|---|
| 791 | return true; |
|---|
| 792 | } |
|---|
| 793 | else |
|---|
| 794 | return false; |
|---|
| 795 | } |
|---|
| 796 | |
|---|
| 797 | bool trpgLight::GetVertices(trpg3dPoint *pts) const |
|---|
| 798 | { |
|---|
| 799 | unsigned int i; |
|---|
| 800 | |
|---|
| 801 | if (!isValid()) return false; |
|---|
| 802 | |
|---|
| 803 | if (lightPoints.size() != 0) |
|---|
| 804 | for (i=0;i<lightPoints.size();i++) |
|---|
| 805 | pts[i] = lightPoints[i]; |
|---|
| 806 | |
|---|
| 807 | return true; |
|---|
| 808 | } |
|---|
| 809 | |
|---|
| 810 | bool trpgLight::GetVertices(float64 *fts) const |
|---|
| 811 | { |
|---|
| 812 | unsigned int i; |
|---|
| 813 | unsigned int j = 0; |
|---|
| 814 | |
|---|
| 815 | if (!isValid()) return false; |
|---|
| 816 | |
|---|
| 817 | if (lightPoints.size() != 0) |
|---|
| 818 | for (i=0;i<lightPoints.size();i++) { |
|---|
| 819 | fts[j++] = lightPoints[i].x; |
|---|
| 820 | fts[j++] = lightPoints[i].y; |
|---|
| 821 | fts[j++] = lightPoints[i].z; |
|---|
| 822 | } |
|---|
| 823 | |
|---|
| 824 | return true; |
|---|
| 825 | } |
|---|
| 826 | |
|---|
| 827 | bool trpgLight::GetVertices(float32 *fts) const |
|---|
| 828 | { |
|---|
| 829 | unsigned int i; |
|---|
| 830 | unsigned int j = 0; |
|---|
| 831 | |
|---|
| 832 | if (!isValid()) return false; |
|---|
| 833 | |
|---|
| 834 | if (lightPoints.size() != 0) |
|---|
| 835 | for (i=0;i<lightPoints.size();i++) { |
|---|
| 836 | fts[j++] = (float32)lightPoints[i].x; |
|---|
| 837 | fts[j++] = (float32)lightPoints[i].y; |
|---|
| 838 | fts[j++] = (float32)lightPoints[i].z; |
|---|
| 839 | } |
|---|
| 840 | |
|---|
| 841 | return true; |
|---|
| 842 | } |
|---|
| 843 | |
|---|
| 844 | |
|---|
| 845 | |
|---|
| 846 | void trpgLight::GetAttrIndex(int &ix) const |
|---|
| 847 | { |
|---|
| 848 | ix = index; |
|---|
| 849 | } |
|---|
| 850 | |
|---|
| 851 | |
|---|
| 852 | bool trpgLight::isValid(void) const |
|---|
| 853 | { |
|---|
| 854 | return true; |
|---|
| 855 | } |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | void trpgLight::Reset(void) |
|---|
| 859 | { |
|---|
| 860 | lightPoints.clear(); |
|---|
| 861 | index =-1; |
|---|
| 862 | } |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | bool trpgLight::Write(trpgWriteBuffer &buf) |
|---|
| 866 | { |
|---|
| 867 | int numVertices = lightPoints.size(); |
|---|
| 868 | |
|---|
| 869 | if (!isValid()) |
|---|
| 870 | return false; |
|---|
| 871 | |
|---|
| 872 | buf.Begin(TRPGLIGHT); |
|---|
| 873 | |
|---|
| 874 | buf.Add(index); |
|---|
| 875 | buf.Add(numVertices); |
|---|
| 876 | for (unsigned int i=0;i<lightPoints.size();i++) |
|---|
| 877 | buf.Add(lightPoints[i]); |
|---|
| 878 | |
|---|
| 879 | buf.End(); |
|---|
| 880 | |
|---|
| 881 | return true; |
|---|
| 882 | } |
|---|
| 883 | |
|---|
| 884 | |
|---|
| 885 | bool trpgLight::Read(trpgReadBuffer &buf) |
|---|
| 886 | { |
|---|
| 887 | Reset(); |
|---|
| 888 | |
|---|
| 889 | int numVertices; |
|---|
| 890 | buf.Get(index); |
|---|
| 891 | buf.Get(numVertices); |
|---|
| 892 | for ( int i = 0; i < numVertices; i++ ) { |
|---|
| 893 | trpg3dPoint vx; |
|---|
| 894 | buf.Get(vx); |
|---|
| 895 | lightPoints.push_back(vx); |
|---|
| 896 | } |
|---|
| 897 | |
|---|
| 898 | return isValid(); |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | |
|---|
| 902 | trpgLight& trpgLight::operator = (const trpgLight &in) |
|---|
| 903 | { |
|---|
| 904 | Reset(); |
|---|
| 905 | |
|---|
| 906 | index = in.index; |
|---|
| 907 | for (unsigned int i = 0; i < in.lightPoints.size(); i++ ) |
|---|
| 908 | lightPoints.push_back(in.lightPoints[i]); |
|---|
| 909 | |
|---|
| 910 | return *this; |
|---|
| 911 | } |
|---|
| 912 | |
|---|
| 913 | |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | trpgLightTable::trpgLightTable() |
|---|
| 920 | { |
|---|
| 921 | } |
|---|
| 922 | |
|---|
| 923 | trpgLightTable::trpgLightTable(const trpgLightTable &in): |
|---|
| 924 | trpgReadWriteable(in) |
|---|
| 925 | { |
|---|
| 926 | *this = in; |
|---|
| 927 | } |
|---|
| 928 | |
|---|
| 929 | |
|---|
| 930 | void trpgLightTable::Reset() |
|---|
| 931 | { |
|---|
| 932 | errMess[0] = '\0'; |
|---|
| 933 | |
|---|
| 934 | lightMap.clear(); |
|---|
| 935 | } |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | trpgLightTable::~trpgLightTable() |
|---|
| 939 | { |
|---|
| 940 | Reset(); |
|---|
| 941 | } |
|---|
| 942 | |
|---|
| 943 | |
|---|
| 944 | bool trpgLightTable::isValid() const |
|---|
| 945 | { |
|---|
| 946 | LightMapType::const_iterator itr = lightMap.begin(); |
|---|
| 947 | for ( ; itr != lightMap.end( ); itr++) |
|---|
| 948 | { |
|---|
| 949 | if (!itr->second.isValid()) |
|---|
| 950 | { |
|---|
| 951 | if(itr->second.getErrMess()) |
|---|
| 952 | strcpy(errMess, itr->second.getErrMess()); |
|---|
| 953 | return false; |
|---|
| 954 | } |
|---|
| 955 | } |
|---|
| 956 | |
|---|
| 957 | return true; |
|---|
| 958 | } |
|---|
| 959 | |
|---|
| 960 | |
|---|
| 961 | int trpgLightTable::AddLightAttr(const trpgLightAttr& inLight) |
|---|
| 962 | { |
|---|
| 963 | int handle = inLight.GetHandle(); |
|---|
| 964 | if(handle==-1) { |
|---|
| 965 | handle = lightMap.size(); |
|---|
| 966 | } |
|---|
| 967 | lightMap[handle] = inLight; |
|---|
| 968 | return handle; |
|---|
| 969 | } |
|---|
| 970 | int trpgLightTable::FindAddLightAttr(const trpgLightAttr& inLight) |
|---|
| 971 | { |
|---|
| 972 | LightMapType::iterator itr = lightMap.begin(); |
|---|
| 973 | for ( ; itr != lightMap.end( ); itr++) { |
|---|
| 974 | if(itr->second==inLight) |
|---|
| 975 | return itr->first; |
|---|
| 976 | } |
|---|
| 977 | return AddLightAttr(inLight); |
|---|
| 978 | } |
|---|
| 979 | |
|---|
| 980 | |
|---|
| 981 | |
|---|
| 982 | trpgLightTable &trpgLightTable::operator = (const trpgLightTable &in) |
|---|
| 983 | { |
|---|
| 984 | Reset(); |
|---|
| 985 | |
|---|
| 986 | LightMapType::const_iterator itr = in.lightMap.begin(); |
|---|
| 987 | for ( ; itr != in.lightMap.end( ); itr++) { |
|---|
| 988 | AddLightAttr(itr->second); |
|---|
| 989 | } |
|---|
| 990 | |
|---|
| 991 | |
|---|
| 992 | return *this; |
|---|
| 993 | } |
|---|
| 994 | |
|---|
| 995 | |
|---|
| 996 | bool trpgLightTable::Write(trpgWriteBuffer &buf) |
|---|
| 997 | { |
|---|
| 998 | int32 numLights; |
|---|
| 999 | |
|---|
| 1000 | if (!isValid()) |
|---|
| 1001 | return false; |
|---|
| 1002 | |
|---|
| 1003 | buf.Begin(TRPGLIGHTTABLE); |
|---|
| 1004 | numLights = lightMap.size(); |
|---|
| 1005 | buf.Add(numLights); |
|---|
| 1006 | LightMapType::iterator itr = lightMap.begin(); |
|---|
| 1007 | for ( ; itr != lightMap.end( ); itr++) |
|---|
| 1008 | itr->second.Write(buf); |
|---|
| 1009 | |
|---|
| 1010 | |
|---|
| 1011 | buf.End(); |
|---|
| 1012 | |
|---|
| 1013 | return true; |
|---|
| 1014 | } |
|---|
| 1015 | |
|---|
| 1016 | |
|---|
| 1017 | |
|---|
| 1018 | |
|---|
| 1019 | |
|---|
| 1020 | |
|---|
| 1021 | bool trpgLightTable::GetNumLightAttrs(int &no) const |
|---|
| 1022 | { |
|---|
| 1023 | if (!isValid()) return false; |
|---|
| 1024 | no = lightMap.size(); |
|---|
| 1025 | return true; |
|---|
| 1026 | } |
|---|
| 1027 | |
|---|
| 1028 | const trpgLightAttr* trpgLightTable::GetLightAttrRef(int id) const |
|---|
| 1029 | { |
|---|
| 1030 | if (id < 0) return NULL; |
|---|
| 1031 | |
|---|
| 1032 | LightMapType::const_iterator itr = lightMap.find(id); |
|---|
| 1033 | if(itr == lightMap.end()) { |
|---|
| 1034 | return NULL; |
|---|
| 1035 | } |
|---|
| 1036 | |
|---|
| 1037 | return &itr->second; |
|---|
| 1038 | } |
|---|
| 1039 | |
|---|
| 1040 | bool trpgLightTable::Read(trpgReadBuffer &buf) |
|---|
| 1041 | { |
|---|
| 1042 | int32 numLights; |
|---|
| 1043 | trpgToken lightTok; |
|---|
| 1044 | int32 len; |
|---|
| 1045 | |
|---|
| 1046 | try { |
|---|
| 1047 | buf.Get(numLights); |
|---|
| 1048 | for (int i=0;i<numLights;i++) { |
|---|
| 1049 | buf.GetToken(lightTok,len); |
|---|
| 1050 | if (lightTok != TRPGLIGHTATTR) throw 1; |
|---|
| 1051 | buf.PushLimit(len); |
|---|
| 1052 | trpgLightAttr light; |
|---|
| 1053 | bool status = light.Read(buf); |
|---|
| 1054 | buf.PopLimit(); |
|---|
| 1055 | if (!status) throw 1; |
|---|
| 1056 | AddLightAttr(light); |
|---|
| 1057 | } |
|---|
| 1058 | } |
|---|
| 1059 | catch (...) { |
|---|
| 1060 | return false; |
|---|
| 1061 | } |
|---|
| 1062 | |
|---|
| 1063 | return true; |
|---|
| 1064 | } |
|---|