Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Added C_ParticleFX data implementation. #40

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion PxCs.Tests/PxDaedalusScriptTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class PxDaedalusScriptTest : PxPhoenixTest
{
protected const string VmGothicPath = "_work/DATA/scripts/_compiled/GOTHIC.DAT";
protected const string VmSfxPath = "_work/DATA/scripts/_compiled/SFX.DAT";
protected const string VmPfxPath = "_work/DATA/scripts/_compiled/PARTICLEFX.DAT";
protected const string VmMenuPath = "_work/DATA/scripts/_compiled/MENU.DAT";


Expand Down Expand Up @@ -52,4 +53,4 @@ protected IntPtr LoadVm(string relativeFilePath)
return vmPtr;
}
}
}
}
13 changes: 13 additions & 0 deletions PxCs.Tests/PxVmTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ public void Test_instantiate_Sfx_by_name()
PxVm.pxVmDestroy(vmPtr);
}

[Fact]
public void Test_instantiate_Pfx_by_name()
{
var vmPtr = LoadVm(VmPfxPath);

var firePfx = PxVm.InitializePfx(vmPtr, "FIRE");

Assert.NotEqual(firePfx!.instancePtr, IntPtr.Zero);
Assert.True(firePfx.shpType.ToLower() == "sphere", "Fire has wrong shpType.");

PxVm.pxVmDestroy(vmPtr);
}

[Fact]
public void Test_instantiate_Npc_by_index()
{
Expand Down
87 changes: 87 additions & 0 deletions PxCs/Data/Vm/PxVmPfxData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;

namespace PxCs.Data.Vm
{
[Serializable]
public class PxVmPfxData : PxVmData
{
// 1) Emitter: zeitliches Austoss-Verhalten, particles-per-second
public float ppsValue;
public string ppsScaleKeys = default!;
public bool ppsIsLooping;
public bool ppsIsSmooth;
public float ppsFPS;
public string ppsCreateEm;
public float ppsCreateEmDelay;

// 2) Emitter: raeumliches Austoss-Verhalten
public string shpType = default!; // "point, line, box, circle, sphere, mesh"
public string shpFOR = default!; // "object,world"
public string shpOffsetVec = default!;
public string shpDistribType = default!;// "RAND, UNIFORM, WALK"
public float shpDistribWalkSpeed;
public bool shpIsVolume;
public string shpDim = default!; // "", "30", "10 20 30", "30", "30", "" // line: nur 1 Dimension !=0 // shape Dimensions
public string shpMesh = default!; // "cross.3ds"
public bool shpMeshRender;
public string shpScaleKeys = default!; // "[1.0] [0.8 0.9 0.2] [1.0]"
public bool shpScaleIsLooping;
public bool shpScaleIsSmooth;
public float shpScaleFPS;

// 3) Partikel: Start Richtung/Speed:
public string dirMode = default!; // "DIR, TARGET, MESH_POLY"
public string dirFOR = default!; // "OBJECT, WORLD"
public string dirModeTargetFOR = default!;
public string dirModeTargetPos = default!;// "30 23 67"
public float dirAngleHead;
public float dirAngleHeadVar;
public float dirAngleElev;
public float dirAngleElevVar;
public float velAvg;
public float velVar;

// 4) Partikel: Lebensdauer
public float lspPartAvg;
public float lspPartVar;

// 5) Partikel: Flugverhalten (gravity, nicht-linear?, mesh-selfRot?,..)
// grav: a) nur Y, b) XYZ, c) auf Ziel zu steuern
// public string flyMode_S; // "LINEAR, LIN_SINUS,.."
// flyMeshSelfRotSpeedMin, flyMeshSelfRotSpeedMax
public string flyGravity = default!;
public bool flyCollDet;

// 6) Partikel: Visualisierung
public string visName = default!; // "NAME_V0_A0.TGA/.3DS" (Variation, Animation)
public string visOrientation = default!;// "NONE, VELO"
public bool visTexIsQuadPoly; // 0=triMesh, 1=quadMesh
public float visTexAniFPS;
public bool visTexAniIsLooping; // 0=oneShot, 1=looping

// color (nur Tex, lifeSpan-Sync)
public string visTexColorStart = default!;
public string visTexColorEnd = default!;

// size-ani (nur Tex, lifeSpan-Sync)
public string visSizeStart = default!;
public float visSizeEndScale;

// alpha (lifeSpan-Sync)
public string visAlphaFunc = default!;
public float visAlphaStart;
public float visAlphaEnd;

// 7) misc effects

// trail
public float trlFadeSpeed;
public string trlTexture = default!;
public float trlWidth;

// marks
public float mrkFadeSpeed;
public string mrkTexture = default!;
public float mrkSize;
}
}
140 changes: 139 additions & 1 deletion PxCs/Interface/PxVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public enum PxVmInstanceType
PxVmInstanceTypeSfx = 3,
PxVmInstanceTypeMusic = 4,
PxVmInstanceTypeMenu = 5,
PxVmInstanceTypeMenuItem = 6
PxVmInstanceTypeMenuItem = 6,
PxVmInstanceTypePfx = 7
};

[Flags]
Expand Down Expand Up @@ -294,6 +295,61 @@ public enum PxVmCMenuItemSelectAction
[DllImport(DLLNAME)] public static extern int pxVmInstanceMusicGetTransitionType(IntPtr instance);
[DllImport(DLLNAME)] public static extern int pxVmInstanceMusicGetTransitionSubType(IntPtr instance);

// C_ParticleFX
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetPpsValue(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetPpsScaleKeys(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetPpsIsLooping(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetPpsIsSmooth(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetPpsFps(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetPpsCrateEm(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetPpsCreateEmDelay(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetShpType(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetShpFor(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetShpOffsetVec(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetShpDistribType(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetShpDistribWalkSpeed(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetShpIsVolume(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetShpDim(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetShpMesh(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetShpMeshRender(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetShpScaleKeys(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetShpScaleIsLooping(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetShpScaleIsSmooth(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetShpScaleFps(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetDirMode(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetDirFor(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetDirModeTargetFor(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetDirModeTargetPos(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetDirAngleHead(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetDirAngleHeadVar(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetDirAngleElev(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetDirAngleElevVar(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetVelAvg(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetVelVar(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetLspPartAvg(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetLspPartVar(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetFlyGravity(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetFlyCollDet(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetVisName(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetVisOrientation(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetVisTexIsQuadPoly(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetVisTexAniFps(IntPtr instance);
[DllImport(DLLNAME)] public static extern bool pxVmInstancePfxGetVisTexAniIsLooping(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetVisTexColorStart(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetVisTexColorEnd(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetVisSizeStart(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetVisSizeEndScale(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetVisAlphaFunc(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetVisAlphaStart(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetVisAlphaEnd(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetTrlFadeSpeed(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetTrlTexture(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetTrlWidth(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetMrkFadeSpeed(IntPtr instance);
[DllImport(DLLNAME)] public static extern IntPtr pxVmInstancePfxGetMrkTexture(IntPtr instance);
[DllImport(DLLNAME)] public static extern float pxVmInstancePfxGetMrkSize(IntPtr instance);


public static bool CallFunction(IntPtr vmPtr, string methodName, params object[] parameters)
{
StackPushParameters(vmPtr, parameters);
Expand Down Expand Up @@ -440,6 +496,16 @@ public static string VmStackPopString(IntPtr vmPtr)
return GetMusicByInstancePtr(sfxPtr);
}

public static PxVmPfxData? InitializePfx(IntPtr vmPtr, string name)
{
var pfxPtr = pxVmInstanceInitializeByName(vmPtr, name, PxVmInstanceType.PxVmInstanceTypePfx, IntPtr.Zero);

if (pfxPtr == IntPtr.Zero)
return null;

return GetPfxByInstancePtr(pfxPtr);
}

public static string[] GetInstancesByClassName(IntPtr vmPtr, string name)
{
var names = new List<string>();
Expand Down Expand Up @@ -686,6 +752,78 @@ private static PxVmSfxData GetSfxByInstancePtr(IntPtr instancePtr)

return sfx;
}

private static PxVmPfxData GetPfxByInstancePtr(IntPtr instancePtr)
{
var pfx = new PxVmPfxData();
AddInstanceData(pfx, instancePtr);

pfx.ppsValue = pxVmInstancePfxGetPpsValue(instancePtr);
pfx.ppsScaleKeys = pxVmInstancePfxGetPpsScaleKeys(instancePtr).MarshalAsString();
pfx.ppsIsLooping = pxVmInstancePfxGetPpsIsLooping(instancePtr);
pfx.ppsIsSmooth = pxVmInstancePfxGetPpsIsSmooth(instancePtr);
pfx.ppsFPS = pxVmInstancePfxGetPpsFps(instancePtr);
pfx.ppsCreateEm = pxVmInstancePfxGetPpsCrateEm(instancePtr).MarshalAsString();
pfx.ppsCreateEmDelay = pxVmInstancePfxGetPpsCreateEmDelay(instancePtr);

pfx.shpType = pxVmInstancePfxGetShpType(instancePtr).MarshalAsString();
pfx.shpFOR = pxVmInstancePfxGetShpFor(instancePtr).MarshalAsString();
pfx.shpOffsetVec = pxVmInstancePfxGetShpOffsetVec(instancePtr).MarshalAsString();
pfx.shpDistribType = pxVmInstancePfxGetShpDistribType(instancePtr).MarshalAsString();
pfx.shpDistribWalkSpeed = pxVmInstancePfxGetShpDistribWalkSpeed(instancePtr);
pfx.shpIsVolume = pxVmInstancePfxGetShpIsVolume(instancePtr);
pfx.shpDim = pxVmInstancePfxGetShpDim(instancePtr).MarshalAsString();
pfx.shpMesh = pxVmInstancePfxGetShpMesh(instancePtr).MarshalAsString();
pfx.shpMeshRender = pxVmInstancePfxGetShpMeshRender(instancePtr);
pfx.shpScaleKeys = pxVmInstancePfxGetShpScaleKeys(instancePtr).MarshalAsString();
pfx.shpScaleIsLooping = pxVmInstancePfxGetShpScaleIsLooping(instancePtr);
pfx.shpScaleIsSmooth = pxVmInstancePfxGetShpScaleIsSmooth(instancePtr);
pfx.shpScaleFPS = pxVmInstancePfxGetShpScaleFps(instancePtr);

pfx.dirMode = pxVmInstancePfxGetDirMode(instancePtr).MarshalAsString();
pfx.dirFOR = pxVmInstancePfxGetDirFor(instancePtr).MarshalAsString();
pfx.dirModeTargetFOR = pxVmInstancePfxGetDirModeTargetFor(instancePtr).MarshalAsString();
pfx.dirModeTargetPos = pxVmInstancePfxGetDirModeTargetPos(instancePtr).MarshalAsString();
pfx.dirAngleHead = pxVmInstancePfxGetDirAngleHead(instancePtr);
pfx.dirAngleHeadVar = pxVmInstancePfxGetDirAngleHeadVar(instancePtr);
pfx.dirAngleElev = pxVmInstancePfxGetDirAngleElev(instancePtr);
pfx.dirAngleElevVar = pxVmInstancePfxGetDirAngleElevVar(instancePtr);
pfx.velAvg = pxVmInstancePfxGetVelAvg(instancePtr);
pfx.velVar = pxVmInstancePfxGetVelVar(instancePtr);

pfx.lspPartAvg = pxVmInstancePfxGetLspPartAvg(instancePtr);
pfx.lspPartVar = pxVmInstancePfxGetLspPartVar(instancePtr);

pfx.flyGravity = pxVmInstancePfxGetFlyGravity(instancePtr).MarshalAsString();
pfx.flyCollDet = pxVmInstancePfxGetFlyCollDet(instancePtr);

pfx.visName = pxVmInstancePfxGetVisName(instancePtr).MarshalAsString();
pfx.visOrientation = pxVmInstancePfxGetVisOrientation(instancePtr).MarshalAsString();
pfx.visTexIsQuadPoly = pxVmInstancePfxGetVisTexIsQuadPoly(instancePtr);
pfx.visTexAniFPS = pxVmInstancePfxGetVisTexAniFps(instancePtr);
pfx.visTexAniIsLooping = pxVmInstancePfxGetVisTexAniIsLooping(instancePtr);

pfx.visTexColorStart = pxVmInstancePfxGetVisTexColorStart(instancePtr).MarshalAsString();
pfx.visTexColorEnd = pxVmInstancePfxGetVisTexColorEnd(instancePtr).MarshalAsString();

pfx.visSizeStart = pxVmInstancePfxGetVisSizeStart(instancePtr).MarshalAsString();
pfx.visSizeEndScale = pxVmInstancePfxGetVisSizeEndScale(instancePtr);

pfx.visAlphaFunc = pxVmInstancePfxGetVisAlphaFunc(instancePtr).MarshalAsString();
pfx.visAlphaStart = pxVmInstancePfxGetVisAlphaStart(instancePtr);
pfx.visAlphaEnd = pxVmInstancePfxGetVisAlphaEnd(instancePtr);

pfx.trlFadeSpeed = pxVmInstancePfxGetTrlFadeSpeed(instancePtr);
pfx.trlTexture = pxVmInstancePfxGetTrlTexture(instancePtr).MarshalAsString();
pfx.trlWidth = pxVmInstancePfxGetTrlWidth(instancePtr);

pfx.mrkFadeSpeed = pxVmInstancePfxGetMrkFadeSpeed(instancePtr);
pfx.mrkTexture = pxVmInstancePfxGetMrkTexture(instancePtr).MarshalAsString();
pfx.mrkSize = pxVmInstancePfxGetMrkSize(instancePtr);

return pfx;
}

private static PxVmMusicData GetMusicByInstancePtr(IntPtr instancePtr)
{
var music = new PxVmMusicData();
Expand Down