/// <summary> /// Serialize a compressed value to an array buffer using this FloatCrusher. /// </summary> /// <param name="c">CompressedValue</param> /// <param name="buffer"></param> /// <param name="bitposition"></param> /// <param name="bcl"></param> /// <returns></returns> public static CompressedFloat Write(this FloatCrusher fc, CompressedFloat c, uint[] buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { int bits = fc._bits[(int)bcl]; buffer.Write(c.cvalue, ref bitposition, bits); return(c); }
//UNTESTED /// <summary> /// Reads (deserialize) a compressed value from the buffer, and returns a CompressedValue. /// </summary> /// <param name="buffer">Source buffer to read from.</param> /// <param name="bitposition">Auto-incremented read position for the buffer. Will begin reading bits from this position.</param> /// <param name="bcl"></param> /// <returns></returns> public static CompressedFloat Read(this FloatCrusher fc, ulong buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { int bits = fc._bits[(int)bcl]; uint c = (uint)buffer.Read(ref bitposition, bits); return(new CompressedFloat(fc, c)); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { // Hackjob way to get the target - needs to reference a serialized field in order to work. fc = (FloatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("_min")); return(CalculateHeight(fc)); }
public static CompressedFloat Write(this FloatCrusher fc, uint c, ref Bitstream bitstream, BitCullingLevel bcl = BitCullingLevel.NoCulling) { int bits = fc._bits[(int)bcl]; bitstream.Write(c, bits); return(new CompressedFloat(fc, c)); }
/// <summary> /// Serialize a compressed value to an array buffer using this FloatCrusher. /// </summary> /// <param name="c">CompressedValue</param> /// <param name="buffer"></param> /// <param name="bitposition"></param> /// <param name="bcl"></param> /// <returns></returns> public static CompressedFloat Write(this FloatCrusher fc, uint c, ulong[] buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { int bits = fc._bits[(int)bcl]; buffer.Write(c, ref bitposition, bits); return(new CompressedFloat(fc, c)); }
static NormCompress() { for (int i = 0; i <= 32; ++i) { uint maxval = FloatCrusher.GetMaxValueForBits(i); codecForBit[i] = new NormCompressCodec(i, maxval, 1f / maxval); } }
/// <summary> /// Compress (encode) a float value using this FloatCrusher, then Inject() that compressed value into the /// supplied buffer starting at the indicated bitposition. /// </summary> /// <param name="f">Float to be compressed and serialized</param> /// <param name="buffer">Target primitive buffer to serialize into.</param> /// <param name="bitposition">The auto-incremented position in the array (in bits) where we will begin reading.</param> /// <param name="bcl"></param> /// <returns>Returns the compressed uint that was serialized.</returns> public static CompressedFloat Write(this FloatCrusher fc, float f, ref byte buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { int bits = fc._bits[(int)bcl]; CompressedFloat c = fc.Compress(f); c.cvalue.Inject(ref buffer, ref bitposition, bits); return(c); }
public static CompressedFloat Read(this FloatCrusher fc, ref ulong buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { int bits = fc._bits[(int)bcl]; uint mask = fc.masks[(int)bcl]; uint c = (uint)((buffer >> bitposition) & mask); bitposition += bits; return(new CompressedFloat(fc, c)); }
private float CalculateHeight(FloatCrusher fc) { float rangeLine = (fc.BitsDeterminedBy == BitsDeterminedBy.HalfFloat) ? 0 :(LINEHEIGHT + SPACING); float accCenterLine = (fc.BitsDeterminedBy == BitsDeterminedBy.HalfFloat) ? 0 :LINEHEIGHT; // LINEHEIGHT; // (fc.BitsDeterminedBy >= 0 ? LINEHEIGHT : 0); return((fc.enabled) ? ENBLD_HGHT + rangeLine + accCenterLine: DISBL_HGHT); }
public override void OnAwake() { base.OnAwake(); respawnWaitAsTicks = ConvertSecsToTicks(respawnDelay); despawnWaitAsTicks = ConvertSecsToTicks(despawnDelay); bitsForTicksUntilRespawn = FloatCrusher.GetBitsForMaxValue((uint)respawnWaitAsTicks); bitsForTicksUntilDespawn = FloatCrusher.GetBitsForMaxValue((uint)despawnWaitAsTicks); }
public void SetTickInterval(float tickInterval) { // Convert seconds into ticks for a more deterministic and networkable count _decayDelayInTicks = (int)(decayDelay / tickInterval); _regenDelayInTicks = (int)(regenDelay / tickInterval); _decayPerTick = decayRate * tickInterval; _regenPerTick = regenRate * tickInterval; bitsForValue = FloatCrusher.GetBitsForMaxValue((uint)_maxValue); bitsForDecayDelay = FloatCrusher.GetBitsForMaxValue((uint)_decayDelayInTicks); bitsForRegenDelay = FloatCrusher.GetBitsForMaxValue((uint)_regenDelayInTicks); }
// constructor (not entirely sure if this is needed) static WorldVectorCompression() { Bounds bounds = NSTMapBounds.CombinedWorldBounds; axisRanges = new FloatCrusher[3]; for (int axis = 0; axis < 3; axis++) { axisRanges[axis] = new FloatCrusher(bounds.min[axis], bounds.max[axis], WorldCompressionSettings.Single.minPosResolution, (Axis)axis, TRSType.Position); } SetWorldRanges(bounds, true); }
private float CalculateHeight(FloatCrusher fc) { bool noSettings = (fc.BitsDeterminedBy == BitsDeterminedBy.HalfFloat || fc.BitsDeterminedBy == BitsDeterminedBy.Uncompressed || fc.BitsDeterminedBy == BitsDeterminedBy.Disabled); float bclLine = (fc.expandBCL) ? BCL_HEIGHT : (fc.showBCL) ? LINEHEIGHT : 0; float settingsLen = (noSettings) ? 0 : SETTINGS_HGHT + ACCCNTR_HGHT + ACTUAL_HGHT + bclLine; return(PADDING + HEADR_HGHT + PADDING + (fc.Enabled ? COMPMTHD_HGHT + ((noSettings) ? 0 : settingsLen) : 0)); }
private float CalculateHeight(FloatCrusher fc, int hash) { bool noSettings = (fc.BitsDeterminedBy == BitsDeterminedBy.HalfFloat || fc.BitsDeterminedBy == BitsDeterminedBy.Uncompressed || fc.BitsDeterminedBy == BitsDeterminedBy.Disabled); bool noRange = fc.TRSType == TRSType.Normal; float bclLine = (fc.expandBCL) ? BCL_HEIGHT : (fc.showBCL) ? LINEHEIGHT : 0; float settingsLen = (noSettings) ? 0 : (noRange ? 0 : SETTINGS_HGHT) + ACCCNTR_HGHT + ACTUAL_HGHT + bclLine; return(PADDING + HEADR_HGHT + PADDING + (fc.Enabled && fc.expanded ? (COMPMTHD_HGHT + ((noSettings) ? 0 : settingsLen)) : 0)); }
public override void OnStart() { /// TEST - this code fixed startup rendering, but not fully tested. Likely needs to stay here. ChangeState(new StateChangeInfo(initialState, transform.parent ? transform.parent.GetComponent <Mount>() : null, true)); base.OnStart(); /// Cache values for mountType serialization. We get the total possible mount options from this objects SyncState var mountableToCount = (mountableTo.mask).CountTrueBits(out indexToMountTypeId, MountSettings.Single.mountNames.Count); bitsForMountType = FloatCrusher.GetBitsForMaxValue((uint)(mountableToCount)); for (int i = 0; i < mountableToCount; ++i) { mountTypeIdToIndex.Add(indexToMountTypeId[i], i); } }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { base.OnGUI(r, property, label); if (isExpanded) { int bits = (maskValue).CountTrueBits(MountSettings.Single.mountNames.Count); int serbits = FloatCrusher.GetBitsForMaxValue((uint)(bits)); bitsGC.text = serbits.ToString() + " bits"; reuseGC.text = " "; reuseGC.tooltip = label.tooltip; EditorGUI.LabelField(new Rect(r) { height = LINE_SPACING }, reuseGC, bitsGC, (GUIStyle)"RightLabel"); } }
protected void DrawValueAndBitsNeeded(Rect inner, SerializedProperty sp, float tickduration) { EditorGUI.PropertyField(new Rect(inner) { xMax = inner.xMax - BITS_WIDTH }, sp); if (sp.floatValue < 1) { sp.floatValue = 1; sp.serializedObject.ApplyModifiedProperties(); } int bits = FloatCrusher.GetBitsForMaxValue((uint)(sp.floatValue / tickduration)); EditorGUI.LabelField(new Rect(inner) { xMin = inner.xMax - BITS_WIDTH - 4 }, bits.ToString() + " Bits", miniLabelRight); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); base.OnGUI(r, property, label); // Hackjob way to get the target fc = (FloatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("_min")); height = CalculateHeight(fc); this.r = r; savedIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; line = r.yMin; colortex = (fc.axis == Axis.X) ? SolidTextures.red2D : (fc.axis == Axis.Y) ? SolidTextures.green2D : (fc.axis == Axis.Z) ? SolidTextures.blue2D : SolidTextures.gray2D; SolidTextures.DrawTexture(new Rect(r.xMin - 1, line - 1, r.width + 2, height + 2), SolidTextures.lowcontrast2D); SolidTextures.DrawTexture(new Rect(r.xMin, line, r.width, height), colortex); line += SPACING; DrawHeader(r, label); if (fc.enabled) { line += HHEIGHT + SPACING; DrawResolution(); DrawCodecSettings(property); line += LINEHEIGHT + 3; DrawFooter(); } EditorGUI.indentLevel = savedIndentLevel; EditorGUI.EndProperty(); }
/// <summary> /// Finds all active and inactive colliders on an object /// </summary> /// <param name="netObj"></param> public static void IndexColliders(this NetObject netObj) { var indexed = netObj.indexedColliders; var lookup = netObj.colliderLookup; lookup.Clear(); indexed.Clear(); /// Find ALL components, we will loop through this. netObj.transform.GetNestedComponentsInChildren(reusableComponents); /// Check each component to see if it is a Collider/Collider2D int compCnt = reusableComponents.Count; for (int c = 0; c < compCnt; ++c) { Component comp = reusableComponents[c]; Collider collider = comp as Collider; if (collider) { indexed.Add(comp); } else { Collider2D collider2D = comp as Collider2D; if (collider2D) { indexed.Add(comp); } } } /// Populate the lookup with the found colliders int cnt = indexed.Count; for (int i = 0; i < cnt; ++i) { lookup.Add(indexed[i], i); } netObj.bitsForColliderIndex = FloatCrusher.GetBitsForMaxValue((uint)indexed.Count - 1); }
private void Defaults(TRSType trs) { if (trs == TRSType.Quaternion || trs == TRSType.Euler) { xcrusher = new FloatCrusher(BitPresets.Bits10, -90f, 90f, Axis.X, TRSType.Euler, true); ycrusher = new FloatCrusher(BitPresets.Bits12, -180f, 180f, Axis.Y, TRSType.Euler, true); zcrusher = new FloatCrusher(BitPresets.Bits10, -180f, 180f, Axis.Z, TRSType.Euler, true); //ucrusher = new FloatCrusher(Axis.Uniform, TRSType.Scale, true); qcrusher = new QuatCrusher(true, false); } else if (trs == TRSType.Scale) { xcrusher = new FloatCrusher(BitPresets.Bits12, 0f, 2f, Axis.X, TRSType.Scale, true); ycrusher = new FloatCrusher(BitPresets.Bits10, 0f, 2f, Axis.Y, TRSType.Scale, true); zcrusher = new FloatCrusher(BitPresets.Bits10, 0f, 2f, Axis.Z, TRSType.Scale, true); ucrusher = new FloatCrusher(BitPresets.Bits10, 0f, 2f, Axis.Uniform, TRSType.Scale, true); } else { xcrusher = new FloatCrusher(BitPresets.Bits12, -20f, 20f, Axis.X, trs, true); ycrusher = new FloatCrusher(BitPresets.Bits10, -5f, 5f, Axis.Y, trs, true); zcrusher = new FloatCrusher(BitPresets.Bits10, -5f, 5f, Axis.Z, trs, true); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); Rect r = EditorGUILayout.GetControlRect(); if (GUI.Button(r, index_Default)) { t.RebuildIndexedNames(); showSummary[uid] = true; } showSummary[uid] = IndentedFoldout(new GUIContent("Indexed Name Summary"), showSummary[uid], 1); if (showSummary[uid]) { sb.Length = 0; sb.Append((uint)t.sharedTriggIndexes.Count).Append(" Triggers found.\n"); for (int i = 0; i < t.sharedTriggIndexes.Count; ++i) { sb.Append(t.sharedTriggNames[i]).Append(" : ").Append(t.sharedTriggIndexes[i]).Append("\n"); } sb.Append(FloatCrusher.GetBitsForMaxValue((uint)t.sharedTriggIndexes.Count - 1) + 1).Append(" bits per indexed Trigger.\n33 bits per non-indexed Trigger.\n\n"); sb.Append((uint)t.sharedStateIndexes.Count).Append(" States found.\n"); for (int i = 0; i < t.sharedStateIndexes.Count; ++i) { sb.Append(t.sharedStateNames[i]).Append(" : ").Append(t.sharedStateIndexes[i]).Append("\n"); } sb.Append(FloatCrusher.GetBitsForMaxValue((uint)t.sharedStateIndexes.Count - 1) + 1).Append(" bits per indexed State.\n33 bits per non-indexed State.\n\n"); //sb.Append((uint)t.sharedTransIndexes.Count).Append(" Transitions found.\n"); //for (int i = 0; i < t.sharedTransIndexes.Count; ++i) // sb.Append(t.sharedTransNames[i]).Append(" : ").Append(t.sharedTransIndexes[i].hash).Append("\n"); //sb.Append(FloatCrusher.GetBitsForMaxValue((uint)t.sharedTransIndexes.Count - 1) + 1).Append(" bits per indexed Transition.\n33 bits per non-indexed Transitions."); EditorGUILayout.HelpBox(sb.ToString(), MessageType.None); } Divider(); /// Passthrus t.syncPassThrus = EditorGUILayout.BeginToggleGroup(passthruLabel, t.syncPassThrus); if (t.syncPassThrus) { NormTimeCompressEnum(EditorGUILayout.GetControlRect(), new GUIContent("Compress NormalizedTime"), ref t.passthruNormTimeCompress); //EditorGUILayout.HelpBox(passThruHelpText, MessageType.None); } EditorGUILayout.EndToggleGroup(); Divider(); /// States t.syncStates = EditorGUILayout.BeginToggleGroup(statesLabel, t.syncStates); if (t.syncStates) { StatesSection(); } EditorGUILayout.EndToggleGroup(); Divider(); /// Layer Weights t.syncLayerWeights = EditorGUILayout.BeginToggleGroup(layerWeightsLabel, t.syncLayerWeights); if (t.syncLayerWeights) { LayerWeightsSection(); } EditorGUILayout.EndToggleGroup(); Divider(); /// Parameters t.syncParams = EditorGUILayout.BeginToggleGroup(paramsLabel, t.syncParams); if (t.syncParams) { ParamSection(); } EditorGUILayout.EndToggleGroup(); EditorGUILayout.Space(); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } }
public static CompressedFloat Read(this FloatCrusher fc, ref Bitstream bitstream, BitCullingLevel bcl = BitCullingLevel.NoCulling) { int bits = fc._bits[(int)bcl]; return(new CompressedFloat(fc, (uint)bitstream.Read(bits))); }
public static float ReadAndDecompress(this FloatCrusher fc, ref Bitstream bitstream, BitCullingLevel bcl = BitCullingLevel.NoCulling) { CompressedFloat c = fc.Read(ref bitstream, bcl); return(fc.Decompress(c)); }
public override void OnGUI(Rect r, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(r, label, property); haschanged = false; p = property; base.OnGUI(r, property, label); bool isWrappedInElementCrusher = DrawerUtils.GetParent(property) is ElementCrusher; bool disableRange = (label.tooltip != null && label.tooltip.Contains("DISABLE_RANGE")); gc_fc.text = label.text; gc_fc.tooltip = (disableRange) ? null : label.tooltip; holdindent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; // Hackjob way to get the target fc = (FloatCrusher)DrawerUtils.GetParent(property.FindPropertyRelative("_min")); height = CalculateHeight(fc); this.r = r; line = r.yMin; colortex = (fc.axis == Axis.X) ? SolidTextures.red2D : (fc.axis == Axis.Y) ? SolidTextures.green2D : (fc.axis == Axis.Z) ? SolidTextures.blue2D : SolidTextures.gray2D; //SolidTextures.DrawTexture(new Rect(ir.xMin - 1, line - 1, ir.width + 2, height + 2), SolidTextures.lowcontrast2D); if (!isWrappedInElementCrusher) { Rect outline = ir; outline.xMin--; outline.yMin--; outline.xMax++; outline.yMax++; SolidTextures.DrawTexture(outline, SolidTextures.lowcontrast2D); } SolidTextures.DrawTexture(ir, colortex); //SolidTextures.DrawTexture(new Rect(ir.xMin, line, ir.width, height), colortex); //SolidTextures.DrawTexture(new Rect(ir.xMin + 1, ir.yMin + 1, ir.width - 2, ir.height - 2), colortex); line++; line += SPACING; DrawHeader(r, gc_fc); line += PADDING + HEADR_HGHT; if (fc.Enabled) { bool noSettings = (fc.BitsDeterminedBy == BitsDeterminedBy.HalfFloat || fc.BitsDeterminedBy == BitsDeterminedBy.Uncompressed || fc.BitsDeterminedBy == BitsDeterminedBy.Disabled); DrawCompressionMethod(); EditorGUI.BeginDisabledGroup(disableRange); if (!noSettings && !(fc.TRSType == TRSType.Normal)) { DrawCodecSettings(property); } EditorGUI.EndDisabledGroup(); if (!noSettings) { DrawAccurateCenter(); } if (!noSettings && fc.showBCL) { DrawBCL(); } if (!noSettings) { DrawActualValues(); } } //EditorGUI.indentLevel = savedIndentLevel; if (haschanged) { EditorUtility.SetDirty(property.serializedObject.targetObject); } EditorGUI.indentLevel = holdindent; EditorGUI.EndProperty(); }
/// <summary> /// Deserializes a compressed (encoded) float out of an array from the indicated bitpostion, and Decode() it. /// </summary> /// <param name="buffer">Source array buffer.</param> /// <param name="bitposition">The auto-incremented position in the array (in bits) where we will begin reading.</param> /// <returns>Restored float value.</returns> public static float ReadAndDecompress(this FloatCrusher fc, ulong[] buffer, ref int bitposition) { uint c = buffer.ReadUInt32(ref bitposition, fc._bits[0]); return(fc.Decompress(c)); }
/// <summary> /// Deserializes a CompressedValue from an array buffer. /// </summary> /// <param name="buffer">Source array buffer.</param> /// <param name="bitposition">Auto-incremented read position for buffer.</param> /// <param name="bcl"></param> /// <returns></returns> public static CompressedFloat Read(this FloatCrusher fc, uint[] buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { int bits = fc._bits[(int)bcl]; return(new CompressedFloat(fc, buffer.ReadUInt32(ref bitposition, bits))); }
public void OnAwake() { CollectMounts(); bitsForMountId = (indexedMounts.Count == 0) ? 0 : FloatCrusher.GetBitsForMaxValue((uint)(indexedMounts.Count - 1)); }
/// <summary> /// Inject() a previously compressed value into the supplied ulong buffer starting at the indicated bitposition. /// </summary> /// <param name="c">Compressed value to be written</param> /// <param name="buffer">Where the bits will be written</param> /// <param name="bitposition">The position in the buffer to start writing at. Ref value will be increased by the bits used.</param> /// <param name="bcl"></param> /// <returns>Returns the compressed uint that was serialized.</returns> public static CompressedFloat Write(this FloatCrusher fc, CompressedFloat c, ref ulong buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { c.cvalue.Inject(ref buffer, ref bitposition, fc._bits[(int)bcl]); return(c); }