| 214 | } |
| 215 | |
| 216 | void NetworkTransform::Deserialize(NetworkStream* stream) |
| 217 | { |
| 218 | // Get transform |
| 219 | Transform transform; |
| 220 | if (const auto* parent = GetParent()) |
| 221 | transform = LocalSpace ? parent->GetLocalTransform() : parent->GetTransform(); |
| 222 | else |
| 223 | transform = Transform::Identity; |
| 224 | Transform transformLocal = transform; |
| 225 | |
| 226 | // Decode data |
| 227 | Data data; |
| 228 | stream->Read(data); |
| 229 | if (EnumHasAllFlags(data.Components, ReplicationComponents::All)) |
| 230 | { |
| 231 | stream->Read(transform); |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | if (EnumHasAllFlags(data.Components, ReplicationComponents::Position)) |
| 236 | { |
| 237 | stream->Read(transform.Translation); |
| 238 | } |
| 239 | else if (EnumHasAnyFlags(data.Components, ReplicationComponents::Position)) |
| 240 | { |
| 241 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::PositionX)) |
| 242 | stream->Read(transform.Translation.X); |
| 243 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::PositionY)) |
| 244 | stream->Read(transform.Translation.Y); |
| 245 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::PositionZ)) |
| 246 | stream->Read(transform.Translation.Z); |
| 247 | } |
| 248 | if (EnumHasAllFlags(data.Components, ReplicationComponents::Scale)) |
| 249 | { |
| 250 | stream->Read(transform.Scale); |
| 251 | } |
| 252 | else if (EnumHasAnyFlags(data.Components, ReplicationComponents::Scale)) |
| 253 | { |
| 254 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::ScaleX)) |
| 255 | stream->Read(transform.Scale.X); |
| 256 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::ScaleY)) |
| 257 | stream->Read(transform.Scale.Y); |
| 258 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::ScaleZ)) |
| 259 | stream->Read(transform.Scale.Z); |
| 260 | } |
| 261 | if (EnumHasAllFlags(data.Components, ReplicationComponents::Rotation)) |
| 262 | { |
| 263 | stream->Read(transform.Orientation); |
| 264 | } |
| 265 | else if (EnumHasAnyFlags(data.Components, ReplicationComponents::Rotation)) |
| 266 | { |
| 267 | Float3 rotation = transform.Orientation.GetEuler(); |
| 268 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::RotationX)) |
| 269 | stream->Read(rotation.X); |
| 270 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::RotationY)) |
| 271 | stream->Read(rotation.Y); |
| 272 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::RotationZ)) |
| 273 | stream->Read(rotation.Z); |
no test coverage detected