public void AddDevice(IMechanicalPowerRenderable device) { if (device.Shape == null) { return; } int index = -1; string rendererCode = "generic"; if (device.Block.Attributes?["mechanicalPower"]?["renderer"].Exists == true) { rendererCode = device.Block.Attributes?["mechanicalPower"]?["renderer"].AsString("generic"); } int hashCode = device.Shape.GetHashCode() + rendererCode.GetHashCode(); if (!MechBlockRendererByShape.TryGetValue(hashCode, out index)) { object obj = Activator.CreateInstance(RendererByCode[rendererCode], capi, mechanicalPowerMod, device.Block, device.Shape); MechBlockRenderer.Add((MechBlockRenderer)obj); MechBlockRendererByShape[hashCode] = index = MechBlockRenderer.Count - 1; } MechBlockRenderer[index].AddDevice(device); }
public bool RemoveDevice(IMechanicalPowerRenderable device) { bool ok = renderedDevices.Remove(device.Position); quantityBlocks = renderedDevices.Count; return(ok); }
public void RemoveDevice(IMechanicalPowerRenderable device) { if (device.Shape == null) { return; } foreach (var val in MechBlockRenderer) { if (val.RemoveDevice(device)) { return; } } }
public void AddDeviceForRender(IMechanicalPowerRenderable device) { Renderer?.AddDevice(device); }
public void RemoveDeviceForRender(IMechanicalPowerRenderable device) { Renderer?.RemoveDevice(device); }
protected override void UpdateLightAndTransformMatrix(int index, Vec3f distToCamera, float rotation, IMechanicalPowerRenderable dev) { float rot1 = dev.AngleRad; float rot2 = GameMath.TWOPI - dev.AngleRad; float rot3 = rot1 * 2f; float axX = -Math.Abs(dev.AxisSign[0]); float axZ = -Math.Abs(dev.AxisSign[2]); //axle float rotX = rot1 * axX; float rotZ = rot1 * axZ; UpdateLightAndTransformMatrix(matrixAndLightFloats1.Values, index, distToCamera, dev.LightRgba, rotX, rotZ, axisCentre, null); //contra-rotating axle parts rotX = rot2 * axX; rotZ = rot2 * axZ; UpdateLightAndTransformMatrix(matrixAndLightFloats2.Values, index, distToCamera, dev.LightRgba, rotX, rotZ, axisCentre, null); //the spin bar rotX = rot3 * axX; rotZ = rot3 * axZ; UpdateLightAndTransformMatrix(matrixAndLightFloats3.Values, index, distToCamera, dev.LightRgba, rotX, rotZ, axisCentre, null); //position the ball on the spin bar (45 degrees ahead of the spinbar) rotX = (rot3 + GameMath.PI / 4) * axX; rotZ = (rot3 + GameMath.PI / 4) * axZ; TransformMatrix(distToCamera, rotX, rotZ, axisCentre); rotX = axX == 0 ? rot1 * 2f : 0f; rotZ = axZ == 0 ? -rot1 * 2f : 0f; axX = dev.AxisSign[0] * 0.05f; axZ = dev.AxisSign[2] * 0.05f; UpdateLightAndTransformMatrix(matrixAndLightFloats4.Values, index, distToCamera, dev.LightRgba, rotX, rotZ, new Vec3f(0.5f + axX, 0.5f, 0.5f + axZ), (float[])tmpMat.Clone()); //position the other ball on the spin bar (225 degrees ahead of the spinbar i.e. opposite side from the first one) rotX = (rot3 + GameMath.PI * 1.25f) * -Math.Abs(dev.AxisSign[0]); rotZ = (rot3 + GameMath.PI * 1.25f) * -Math.Abs(dev.AxisSign[2]); TransformMatrix(distToCamera, rotX, rotZ, axisCentre); rotX = axX == 0 ? rot1 * 2f : 0f; rotZ = axZ == 0 ? -rot1 * 2f : 0f; UpdateLightAndTransformMatrix(matrixAndLightFloats5.Values, index, distToCamera, dev.LightRgba, rotX, rotZ, new Vec3f(0.5f + axX, 0.5f, 0.5f + axZ), (float[])tmpMat.Clone()); }
protected override void UpdateLightAndTransformMatrix(int index, Vec3f distToCamera, float rotationRad, IMechanicalPowerRenderable dev) { BEBehaviorMPAngledGears gear = dev as BEBehaviorMPAngledGears; if (gear != null) { BlockFacing inTurn = gear.GetPropagationDirection(); if (inTurn == gear.axis1 || inTurn == gear.axis2) { rotationRad = -rotationRad; } } float rotX = rotationRad * dev.AxisSign[0]; float rotY = rotationRad * dev.AxisSign[1]; float rotZ = rotationRad * dev.AxisSign[2]; UpdateLightAndTransformMatrix(floatsPeg.Values, index, distToCamera, dev.LightRgba, rotX, rotY, rotZ);// - 0.08f); if (dev.AxisSign.Length < 4) { //System.Diagnostics.Debug.WriteLine("3 length AxisSign"); return; } rotX = rotationRad * dev.AxisSign[3]; rotY = rotationRad * dev.AxisSign[4]; rotZ = rotationRad * dev.AxisSign[5]; UpdateLightAndTransformMatrix(floatsCage.Values, index, distToCamera, dev.LightRgba, rotX, rotY, rotZ); }
protected override void UpdateLightAndTransformMatrix(int index, Vec3f distToCamera, float rotation, IMechanicalPowerRenderable dev) { BEBehaviorMPPulverizer bhpu = dev as BEBehaviorMPPulverizer; float rot = bhpu.bepu.hasAxle ? dev.AngleRad : 0; float axX = -Math.Abs(dev.AxisSign[0]); float axZ = -Math.Abs(dev.AxisSign[2]); // Axle if (bhpu.bepu.hasAxle) { float rotX = rot * axX; float rotZ = rot * axZ; UpdateLightAndTransformMatrix(matrixAndLightFloatsAxle.Values, quantityAxles, distToCamera, dev.LightRgba, rotX, rotZ, axisCentre, 0f); quantityAxles++; } if ((dev.Block as BlockPulverizer).InvertPoundersOnRender) { rot = -rot; } // Pounder-left if (bhpu.bepu.hasLPounder) { bool leftEmpty = bhpu.bepu.Inventory[1].Empty; int metalIndexLeft = bhpu.bepu.CapMetalIndexL; float progress = GetProgress(bhpu.bepu.hasAxle ? rot - 0.45f + GameMath.PIHALF / 2f : 0f, 0f); UpdateLightAndTransformMatrix(matrixAndLightFloatsLPounder[metalIndexLeft].Values, quantityLPounders[metalIndexLeft], distToCamera, dev.LightRgba, 0f, 0f, axisCentre, Math.Max(progress / 6f + 0.0071f, leftEmpty ? -1 : 1 / 32f)); if (progress < bhpu.prevProgressLeft && progress < 0.25f) { if (bhpu.leftDir == 1) { bhpu.OnClientSideImpact(false); } bhpu.leftDir = -1; } else { bhpu.leftDir = 1; } bhpu.prevProgressLeft = progress; quantityLPounders[metalIndexLeft]++; } // Pounder-right if (bhpu.bepu.hasRPounder) { bool rightEmpty = bhpu.bepu.Inventory[0].Empty; int metalIndexRight = bhpu.bepu.CapMetalIndexR; float progress = GetProgress(bhpu.bepu.hasAxle ? rot - 0.45f : 0f, 0f); UpdateLightAndTransformMatrix(matrixAndLightFloatsRPounder[metalIndexRight].Values, quantityRPounders[metalIndexRight], distToCamera, dev.LightRgba, 0f, 0f, axisCentre, Math.Max(progress / 6f + 0.0071f, rightEmpty ? -1 : 1 / 32f)); if (progress < bhpu.prevProgressRight && progress < 0.25f) { if (bhpu.rightDir == 1) { bhpu.OnClientSideImpact(true); } bhpu.rightDir = -1; } else { bhpu.rightDir = 1; } bhpu.prevProgressRight = progress; quantityRPounders[metalIndexRight]++; } }
protected override void UpdateLightAndTransformMatrix(int index, Vec3f distToCamera, float rotation, IMechanicalPowerRenderable dev) { float rotX = rotation * dev.AxisSign[0]; float rotY = rotation * dev.AxisSign[1]; float rotZ = rotation * dev.AxisSign[2]; if (dev is BEBehaviorMPToggle tog && (rotX == 0 ^ tog.isRotationReversed())) { rotY = GameMath.PI; rotZ = -rotZ; } UpdateLightAndTransformMatrix(matrixAndLightFloats.Values, index, distToCamera, dev.LightRgba, rotX, rotY, rotZ); }
protected abstract void UpdateLightAndTransformMatrix(int index, Vec3f distToCamera, float rotRad, IMechanicalPowerRenderable dev);
public void AddDevice(IMechanicalPowerRenderable device) { renderedDevices[device.Position] = device; quantityBlocks = renderedDevices.Count; }
protected override void UpdateLightAndTransformMatrix(int index, Vec3f distToCamera, float rotation, IMechanicalPowerRenderable dev) { BEClutch clutch = dev as BEClutch; if (clutch == null) { return; } float rot1 = clutch.AngleRad; float rot2 = clutch.RotationNeighbour(); float rotX = rot1 * dev.AxisSign[0]; float rotY = rot1 * dev.AxisSign[1]; float rotZ = rot1 * dev.AxisSign[2]; UpdateLightAndTransformMatrix(matrixAndLightFloats1.Values, index, distToCamera, dev.LightRgba, rotX, rotY, rotZ, clutch.hinge, null); Vec3f axis = new Vec3f(0.5f - dev.AxisSign[2] * 0.125f, 0.625f, 0.5f + dev.AxisSign[0] * 0.125f); rotX = rot2 * dev.AxisSign[0]; rotY = rot2 * dev.AxisSign[1]; rotZ = rot2 * dev.AxisSign[2]; UpdateLightAndTransformMatrix(matrixAndLightFloats2.Values, index, distToCamera, dev.LightRgba, rotX, rotY, rotZ, axis, (float[])tmpMat.Clone()); }
protected override void UpdateLightAndTransformMatrix(int index, Vec3f distToCamera, float rotation, IMechanicalPowerRenderable dev) { BEBehaviorMPAngledGears gear = dev as BEBehaviorMPAngledGears; rotation = gear.LargeGearAngleRad(rotation); float rotX = rotation * dev.AxisSign[0]; float rotY = rotation * dev.AxisSign[1]; float rotZ = rotation * dev.AxisSign[2]; UpdateLightAndTransformMatrix(matrixAndLightFloats.Values, index, distToCamera, dev.LightRgba, rotX, rotY, rotZ); }
protected override void UpdateLightAndTransformMatrix(int index, Vec3f distToCamera, float rotation, IMechanicalPowerRenderable dev) { BEBehaviorMPTransmission trans = dev as BEBehaviorMPTransmission; if (trans == null) { return; } float rot1 = trans.RotationNeighbour(1, true); float rot2 = trans.RotationNeighbour(0, true); float rotX = rot1 * dev.AxisSign[0]; float rotY = rot1 * dev.AxisSign[1]; float rotZ = rot1 * dev.AxisSign[2]; UpdateLightAndTransformMatrix(matrixAndLightFloats1.Values, index, distToCamera, dev.LightRgba, rotX, rotY, rotZ); rotX = rot2 * dev.AxisSign[0]; rotY = rot2 * dev.AxisSign[1]; rotZ = rot2 * dev.AxisSign[2]; UpdateLightAndTransformMatrix(matrixAndLightFloats2.Values, index, distToCamera, dev.LightRgba, rotX, rotY, rotZ); }