Skip to content

Commit

Permalink
[Client, SimAntics] Fix some client and TS1 things
Browse files Browse the repository at this point in the history
- Also revive the weather particle system from the dead.
- MP3 players no longer leak threads.
  • Loading branch information
riperiperi committed Dec 7, 2019
1 parent cbeeff0 commit fa24e20
Show file tree
Hide file tree
Showing 36 changed files with 173 additions and 12 deletions.
1 change: 1 addition & 0 deletions TSOClient/FSO.IDE/EditorComponent/PrimitiveRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static class PrimitiveRegistry
{18, typeof(RemoveObjectInstanceDescriptor) },
{20, typeof(RunFunctionalTreeDescriptor) },
{22, typeof(LookTowardsDescriptor) },
{21, typeof(ShowStringDescriptor) },
{23, typeof(PlaySoundEventDescriptor) },
{24, typeof(OldRelationshipDescriptor) },
{25, typeof(TransferFundsDescriptor) },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using FSO.Files.Formats.IFF.Chunks;
using FSO.IDE.EditorComponent.Model;
using FSO.IDE.EditorComponent.OperandForms;
using FSO.IDE.EditorComponent.OperandForms.DataProviders;
using FSO.SimAntics.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FSO.IDE.EditorComponent.Primitives
{
public class ShowStringDescriptor : PrimitiveDescriptor
{
public override PrimitiveGroup Group { get { return PrimitiveGroup.Debug; } }

public override Type OperandType { get { return typeof(VMShowStringOperand); } }

public override PrimitiveReturnTypes Returns { get { return PrimitiveReturnTypes.TrueFalse; } }

public override string GetBody(EditorScope scope)
{
var op = (VMShowStringOperand)Operand;
var result = new StringBuilder();

var str = scope.GetResource<STR>(op.StringTable, ScopeSource.Private);

if (str == null) result.Append("String #" + op.StringID + " STR#" + op.StringTable);
else result.Append(str.GetString(op.StringID - 1));

return result.ToString();
}

public override void PopulateOperandView(BHAVEditor master, EditorScope escope, TableLayoutPanel panel)
{
panel.Controls.Add(new OpLabelControl(master, escope, Operand, new OpStaticTextProvider("Allows the stack object to print a string. " +
"In FreeSO, this message prints to chat, and can be used to make NPCs talk.")));
panel.Controls.Add(new OpValueControl(master, escope, Operand, "STR Table:", "StringTable", new OpStaticValueBoundsProvider(0, 65535)));
panel.Controls.Add(new OpValueControl(master, escope, Operand, "String ID:", "StringID", new OpStaticValueBoundsProvider(0, 65535)));
}
}
}
1 change: 1 addition & 0 deletions TSOClient/FSO.IDE/FSO.IDE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@
<Compile Include="EditorComponent\Primitives\DialogDescriptors.cs" />
<Compile Include="EditorComponent\Primitives\GenericTSOCallDescriptor.cs" />
<Compile Include="EditorComponent\Primitives\SetBalloonHeadlineDescriptor.cs" />
<Compile Include="EditorComponent\Primitives\ShowStringDescriptor.cs" />
<Compile Include="EditorComponent\Primitives\TS1InventoryOperationsDescriptor.cs" />
<Compile Include="EditorComponent\Primitives\InvokePluginDescriptor.cs" />
<Compile Include="EditorComponent\Primitives\PushInteractionDescriptor.cs" />
Expand Down
1 change: 1 addition & 0 deletions TSOClient/FSO.Server.Database/DA/Objects/IObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public interface IObjects
List<DbObjectAttribute> GetObjectAttributes(List<uint> objects);
int GetSpecificObjectAttribute(uint objectID, int index);
void SetObjectAttributes(List<DbObjectAttribute> attrs);
int TotalObjectAttributes(uint guid, int index);
}
}
7 changes: 7 additions & 0 deletions TSOClient/FSO.Server.Database/DA/Objects/SqlObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,12 @@ public void SetObjectAttributes(List<DbObjectAttribute> attrs)
{
Context.Connection.ExecuteBufferedInsert("INSERT INTO fso_object_attributes (object_id, `index`, value) VALUES (@object_id, @index, @value) ON DUPLICATE KEY UPDATE value = @value", attrs, 100);
}

public int TotalObjectAttributes(uint guid, int index)
{
return Context.Connection.Query<int>("SELECT SUM(a.value) " +
"FROM fso_object_attributes a JOIN fso_objects o ON a.object_id = o.object_id " +
"WHERE `type` = @guid AND `index` = @index", new { guid, index }).FirstOrDefault();
}
}
}
12 changes: 12 additions & 0 deletions TSOClient/FSO.Server/Servers/Lot/Domain/LotServerGlobalLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,13 @@ public void GetBulletinState(VM vm, VMAsyncBulletinCallback callback)
});
}

private void TokenTotal(IDA db, uint guid, List<int> attributeData, VMAsyncTokenCallback callback)
{
var index = attributeData[0];
int total = db.Objects.TotalObjectAttributes(guid, index);
callback(true, new List<int>() { index, total });
}

public void TokenRequest(VM vm, uint avatarID, uint guid, VMTokenRequestMode mode, List<int> attributeData, VMAsyncTokenCallback callback)
{
var setAll = mode == VMTokenRequestMode.GetOrCreate || mode == VMTokenRequestMode.Replace;
Expand All @@ -1079,6 +1086,11 @@ public void TokenRequest(VM vm, uint avatarID, uint guid, VMTokenRequestMode mod
}
using (var db = DAFactory.Get())
{
if (mode == VMTokenRequestMode.TotalAttribute)
{
TokenTotal(db, guid, attributeData, callback);
return;
}
var obj = db.Objects.ObjOfTypeInAvatarInventory(avatarID, guid).FirstOrDefault();
if (obj == null)
{
Expand Down
10 changes: 10 additions & 0 deletions TSOClient/tso.client/UI/Screens/SandboxGameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using FSO.Client.UI.Panels;
using FSO.Client.UI.Panels.WorldUI;
using FSO.Common;
using FSO.Common.Model;
using FSO.Common.Rendering.Framework;
using FSO.Common.Utils;
using FSO.Files.Formats.IFF.Chunks;
Expand Down Expand Up @@ -201,6 +202,15 @@ public override void GameResized()

public void Initialize(string propertyName, bool external)
{
DynamicTuning.Global = new DynamicTuning(new DynTuningEntry[] {
new DynTuningEntry()
{
tuning_type = "city",
tuning_index = 0,
tuning_table = 0,
value = -1
}
});
Title.SetTitle(propertyName);
GameFacade.CurrentCityName = propertyName;
ZoomLevel = 1; //screen always starts at near zoom
Expand Down
2 changes: 1 addition & 1 deletion TSOClient/tso.common/Audio/MP3Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void Dispose()
Inst?.Dispose();
Stream?.Dispose();

Active = true;
Active = false;
DecodeNext.Set(); //end the mp3 thread immediately

EndOfStream = true;
Expand Down
Binary file modified TSOClient/tso.content/Content/DX/Effects/ParticleShader.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Fonts/Fallbacks/thai.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Fonts/mobile.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Fonts/simdialogue.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/DX/Fonts/trebuchet.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Effects/ParticleShader.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Fonts/mobile.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Fonts/simdialogue.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/OGL/Fonts/trebuchet.xnb
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/Objects/Christmas_Station.iff
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/Objects/food_s1_xmaspudding.iff
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/Patch/Event/christmastree.piff
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/Patch/buffettable.piff
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/Patch/buffettable.str.piff
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/Patch/buffettablevacation.piff
Binary file not shown.
Binary file modified TSOClient/tso.content/Content/Patch/buffettablevacation.str.piff
Binary file not shown.
3 changes: 2 additions & 1 deletion TSOClient/tso.content/ContentSrc/Effects/ParticleShader.fx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ float3 RotateXY(float3 posIn, float angle) {
//miny, yrange, fall speed, fall speed variation
//wind x, wind z, wind variation, rotation variation
//minx, xrange, minz, zrange
//scale
ParticleOutput SnowVS(in ParticleInput input)
{
ParticleOutput output = (ParticleOutput)0;
Expand All @@ -104,7 +105,7 @@ ParticleOutput SnowVS(in ParticleInput input)
float2 xzbase = (Parameters3.xz + boxCtr.xz); //test
xz = ((xz - xzbase) % Parameters3.yw) + xzbase;

float flakeSize = sin(input.Position.y * 1000)*0.15 + 1;
float flakeSize = (sin(input.Position.y * 1000)*0.15 + 1) * Parameters4.x;
float4 realCtr = float4(xz.x, newY + boxCtr.y, xz.y, 1);
float4 realPos = Billboard(realCtr, float4(RotateXY(input.ModelPosition, rotSpeed*realTime) * flakeSize, 1));

Expand Down
Binary file modified TSOClient/tso.content/ContentSrc/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public enum VMTokenRequestMode
GetAttribute,
SetAttribute,
ModifyAttribute,
TransactionAttribute
TransactionAttribute,
TotalAttribute
}
}
1 change: 1 addition & 0 deletions TSOClient/tso.simantics/FSO.SimAntics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
<Compile Include="Primitives\VMSetBalloonHeadline.cs" />
<Compile Include="Primitives\VMSetMotiveChange.cs" />
<Compile Include="Primitives\VMSetToNext.cs" />
<Compile Include="Primitives\VMShowString.cs" />
<Compile Include="Primitives\VMSnap.cs" />
<Compile Include="Primitives\VMSpecialEffect.cs" />
<Compile Include="Primitives\VMStopAllSounds.cs" />
Expand Down
3 changes: 2 additions & 1 deletion TSOClient/tso.simantics/Marshals/VMMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class VMMarshal : VMSerializable
// 34 - Upgrade Level
// 35 - FSO Inventory Retrieve
// 36 - FSO Inventory Token (inventory ops async state has temp list)
public static readonly int LATEST_VERSION = 36;
// 37 - Inventory Token Total
public static readonly int LATEST_VERSION = 37;

public int Version = LATEST_VERSION;
public bool Compressed = true;
Expand Down
7 changes: 6 additions & 1 deletion TSOClient/tso.simantics/Model/TS1Platform/VMTS1LotState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public void ActivateFamily(VM vm, FAMI family)
/// </summary>
public void VerifyFamily(VM vm)
{
if (CurrentFamily == null) return;
if (CurrentFamily == null)
{
vm.SetGlobalValue(32, 1);
return;
}
vm.SetGlobalValue(32, 0);
vm.SetGlobalValue(9, (short)CurrentFamily.ChunkID);
var missingMembers = new HashSet<uint>(CurrentFamily.RuntimeSubset);
foreach (var avatar in vm.Context.ObjectQueries.Avatars)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public override bool Execute(VM vm)
nobj.ExecuteEntryPoint(2, vm.Context, true);
}
vm.TS1State.VerifyFamily(vm);

}
else
{
Expand Down
9 changes: 8 additions & 1 deletion TSOClient/tso.simantics/VMContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ public static void InitVMConfig(bool ts1)
OperandModel = typeof(VMRunFunctionalTreeOperand)
});

//Show string: may be used but no functional result.
//Show string: hijacked by freeso

AddPrimitive(new VMPrimitiveRegistration(new VMShowString())
{
Opcode = 21,
Name = "show_string",
OperandModel = typeof(VMShowStringOperand)
});

AddPrimitive(new VMPrimitiveRegistration(new VMLookTowards())
{
Expand Down
10 changes: 6 additions & 4 deletions TSOClient/tso.simantics/primitives/VMInventoryOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOpe
}
}
}
if (state.WriteResult) VMMemory.SetVariable(context, state.WriteScope, state.WriteData, state.Temp0Value);
if (state.WriteResult) VMMemory.SetBigVariable(context, state.WriteScope, state.WriteData, state.Temp0Value);
if (state.TempWrite.Count > 0)
{
var length = Math.Min(context.Thread.TempRegisters.Length, state.TempWrite.Count);
Expand Down Expand Up @@ -270,7 +270,7 @@ private void TokenResponse(VM vm, VMInventoryOperationsOperand op, short threadI
}
else
{
var value = (short)((result.Count > 1) ? result[1] : 0);
var value = ((result.Count > 1) ? result[1] : 0);
vm.SendCommand(new VMNetAsyncResponseCmd(threadID, new VMInventoryOpState
{
Responded = true,
Expand Down Expand Up @@ -365,13 +365,14 @@ public enum VMInventoryOpMode : byte
FSOTokenSetAttributeTemp0 = 35,
FSOTokenModifyAttributeTemp0 = 36,
FSOTokenTransactionAttributeTemp0 = 37, //same as above but can fail if value goes below 0
FSOTokenTotalAttributeTemp0 = 38, //total all instances of an attribute (guid, attribute) and return value (can be int size)
}

public class VMInventoryOpState : VMAsyncState
{
public bool Success;
public bool WriteResult;
public short Temp0Value;
public int Temp0Value;
public uint ObjectPersistID;
public VMVariableScope WriteScope = VMVariableScope.INVALID;
public short WriteData;
Expand All @@ -382,7 +383,8 @@ public override void Deserialize(BinaryReader reader)
base.Deserialize(reader);
Success = reader.ReadBoolean();
WriteResult = reader.ReadBoolean();
Temp0Value = reader.ReadInt16();
Temp0Value = (Version > 36) ? reader.ReadInt32() : reader.ReadInt16();

if (Version > 34)
{
ObjectPersistID = reader.ReadUInt32();
Expand Down
64 changes: 64 additions & 0 deletions TSOClient/tso.simantics/primitives/VMShowString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using FSO.Files.Formats.IFF.Chunks;
using FSO.Files.Utils;
using FSO.SimAntics.Engine;
using FSO.SimAntics.NetPlay.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FSO.SimAntics.Primitives
{
public class VMShowString : VMPrimitiveHandler
{
public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
{
if (context.StackObject is VMGameObject) return VMPrimitiveExitCode.GOTO_TRUE;
var operand = (VMShowStringOperand)args;

var table = context.ScopeResource.Get<STR>(operand.StringTable);
var avatar = context.StackObject as VMAvatar;

if (table != null)
{
var message = VMDialogHandler.ParseDialogString(context, table.GetString(operand.StringID - 1), table);
var vm = context.VM;

var channelID = 0;

vm.SignalChatEvent(new VMChatEvent(avatar, VMChatEventType.Message, (byte)(channelID & 0x7f), avatar.Name, message));
if ((channelID & 0x80) == 0) avatar.Message = message;
}

return VMPrimitiveExitCode.GOTO_TRUE;
}
}

public class VMShowStringOperand : VMPrimitiveOperand
{
public ushort StringTable { get; set; } = 300;
public ushort StringID { get; set; }

#region VMPrimitiveOperand Members
public void Read(byte[] bytes)
{
using (var io = IoBuffer.FromBytes(bytes, ByteOrder.LITTLE_ENDIAN))
{
StringTable = io.ReadUInt16();
StringID = io.ReadUInt16();
}
}

public void Write(byte[] bytes)
{
using (var io = new BinaryWriter(new MemoryStream(bytes)))
{
io.Write(StringTable);
io.Write(StringID);
}
}
#endregion
}
}
1 change: 1 addition & 0 deletions TSOClient/tso.simantics/utils/VMTS1Activator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public Blueprint LoadFromIff(IffFile iff)
nobj.ExecuteEntryPoint(11, VM.Context, true);
}

VM.TS1State.VerifyFamily(VM);
arch.SignalTerrainRedraw();
VM.Context.World?.InitBlueprint(Blueprint);
arch.Tick();
Expand Down
5 changes: 3 additions & 2 deletions TSOClient/tso.world/Components/ParticleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,10 @@ private void InternalDraw(GraphicsDevice device, Effect effect, int scale, bool
//minx, xrange, minz, zrange
switch (Mode) {
case ParticleType.SNOW:
effect.Parameters["Parameters1"].SetValue(new Vector4(Volume.Min.Y, Volume.Max.Y - Volume.Min.Y, 1f, 0.2f));
effect.Parameters["Parameters2"].SetValue(new Vector4(30f, 10f, 10f, 100f));
effect.Parameters["Parameters1"].SetValue(new Vector4(Volume.Min.Y, Volume.Max.Y - Volume.Min.Y, 1.33f, 0.2f));
effect.Parameters["Parameters2"].SetValue(new Vector4(30f, 10f, 12.5f, 100f));
effect.Parameters["Parameters3"].SetValue(new Vector4(Volume.Min.X, Volume.Max.X - Volume.Min.X, Volume.Min.Z, Volume.Max.Z - Volume.Min.Z));
effect.Parameters["Parameters4"].SetValue(new Vector4((cam3d)?0.66f:0.8f, 0f, 0f, 0f));
break;
case ParticleType.RAIN:
effect.Parameters["Parameters1"].SetValue(new Vector4(Volume.Min.Y, Volume.Max.Y - Volume.Min.Y, 0.20f, 0.01f)); //0.1f
Expand Down

0 comments on commit fa24e20

Please sign in to comment.