/// <summary> /// Registers the given package format. /// </summary> /// <param name="format">The package format you want to register.</param> /// <param name="id">The ID of the package format.</param> /// <remarks> /// This ID is used in packages to define the format of every package. /// Warning! If peers want to communicate over a network environment, then all of them should define exactly /// the same package formats with the same IDs otherwise the communication is not possible. /// </remarks> /// <exception cref="RCPackageException">If you want to register a package format with no fields.</exception> public static void RegisterFormat(RCPackageFormat format, int id) { if (format == null) { throw new ArgumentNullException("format"); } if (id < 0 || id > ushort.MaxValue) { throw new ArgumentOutOfRangeException("id"); } if (format.fieldDefinitions.Count == 0) { throw new RCPackageException("Registering RCPackageFormat with no fields is not possible!"); } if (formatRegister[id] != null) { throw new RCPackageException(string.Format("An RCPackageFormat with ID '{0}' has already been registered!", id)); } formatRegister[id] = format; format.formatID = id; format.definitionFinished = true; }
/// <summary> /// Class-level initializer function. /// </summary> static RCPackageFormat() { formatRegister = new RCPackageFormat[(int)ushort.MaxValue + 1]; }