| 147 | } |
| 148 | |
| 149 | void NetworkTransform::Serialize(NetworkStream* stream) |
| 150 | { |
| 151 | // Get transform |
| 152 | Transform transform; |
| 153 | if (const auto* parent = GetParent()) |
| 154 | transform = LocalSpace ? parent->GetLocalTransform() : parent->GetTransform(); |
| 155 | else |
| 156 | transform = Transform::Identity; |
| 157 | |
| 158 | // Encode data |
| 159 | Data data; |
| 160 | Platform::MemoryClear(&data, sizeof(data)); |
| 161 | data.LocalSpace = LocalSpace; |
| 162 | data.HasSequenceIndex = Mode == ReplicationModes::Prediction; |
| 163 | data.Components = Components; |
| 164 | stream->Write(data); |
| 165 | if (EnumHasAllFlags(data.Components, ReplicationComponents::All)) |
| 166 | { |
| 167 | stream->Write(transform); |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | if (EnumHasAllFlags(data.Components, ReplicationComponents::Position)) |
| 172 | { |
| 173 | stream->Write(transform.Translation); |
| 174 | } |
| 175 | else if (EnumHasAnyFlags(data.Components, ReplicationComponents::Position)) |
| 176 | { |
| 177 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::PositionX)) |
| 178 | stream->Write(transform.Translation.X); |
| 179 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::PositionY)) |
| 180 | stream->Write(transform.Translation.Y); |
| 181 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::PositionZ)) |
| 182 | stream->Write(transform.Translation.Z); |
| 183 | } |
| 184 | if (EnumHasAllFlags(data.Components, ReplicationComponents::Scale)) |
| 185 | { |
| 186 | stream->Write(transform.Scale); |
| 187 | } |
| 188 | else if (EnumHasAnyFlags(data.Components, ReplicationComponents::Scale)) |
| 189 | { |
| 190 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::ScaleX)) |
| 191 | stream->Write(transform.Scale.X); |
| 192 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::ScaleY)) |
| 193 | stream->Write(transform.Scale.Y); |
| 194 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::ScaleZ)) |
| 195 | stream->Write(transform.Scale.Z); |
| 196 | } |
| 197 | if (EnumHasAllFlags(data.Components, ReplicationComponents::Rotation)) |
| 198 | { |
| 199 | stream->Write(transform.Orientation); |
| 200 | } |
| 201 | else if (EnumHasAnyFlags(data.Components, ReplicationComponents::Rotation)) |
| 202 | { |
| 203 | const Float3 rotation = transform.Orientation.GetEuler(); |
| 204 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::RotationX)) |
| 205 | stream->Write(rotation.X); |
| 206 | if (EnumHasAnyFlags(data.Components, ReplicationComponents::RotationY)) |
no test coverage detected