Browse Source

Reworked native-to-managed interface to particle effects, to group together similar types of effects and distinguish them using an enum. This reduces the need for a ton of similar-looking overloads and all of the callback delegate boilerplate that comes along with it.

readme
Nico de Poel 5 years ago
parent
commit
cd4ee6cba7
  1. 28
      Assets/Scripts/Modules/GameModule.Interop.cs
  2. 38
      Assets/Scripts/Modules/GameModule.cs
  3. 4
      Assets/Styles/GLQuake/Particles/Particle.mat
  4. 16
      engine/UniQuake/game_uniquake.c

28
Assets/Scripts/Modules/GameModule.Interop.cs

@ -19,8 +19,7 @@ public partial class GameModule : CallbackHandler<GameModule>
SetEntitySkin = CreateCallback<GameSetEntitySkinCallback>(Callback_GameSetEntitySkin), SetEntitySkin = CreateCallback<GameSetEntitySkinCallback>(Callback_GameSetEntitySkin),
RunParticleEffect = CreateCallback<RunParticleEffectCallback>(Callback_RunParticleEffect), RunParticleEffect = CreateCallback<RunParticleEffectCallback>(Callback_RunParticleEffect),
ParticleExplosion = CreateCallback<ParticleExplosionCallback>(Callback_ParticleExplosion),
TeleportSplash = CreateCallback<TeleportSplashCallback>(Callback_TeleportSplash),
CreateParticleEffect = CreateCallback<CreateParticleEffectCallback>(Callback_CreateParticleEffect),
}; };
RegisterCallbacks(callbacks); RegisterCallbacks(callbacks);
@ -39,8 +38,7 @@ public partial class GameModule : CallbackHandler<GameModule>
public IntPtr SetEntitySkin; public IntPtr SetEntitySkin;
public IntPtr RunParticleEffect; public IntPtr RunParticleEffect;
public IntPtr ParticleExplosion;
public IntPtr TeleportSplash;
public IntPtr CreateParticleEffect;
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@ -110,24 +108,18 @@ public partial class GameModule : CallbackHandler<GameModule>
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void ParticleExplosionCallback(IntPtr context, ref QVec3 origin);
private delegate void CreateParticleEffectCallback(IntPtr context, ParticleEffect type, ref QVec3 origin, uint colorMin, uint colorMax);
[MonoPInvokeCallback(typeof(ParticleExplosionCallback))]
private static void Callback_ParticleExplosion(IntPtr context, ref QVec3 origin)
[MonoPInvokeCallback(typeof(CreateParticleEffectCallback))]
private static void Callback_CreateParticleEffect(IntPtr context, ParticleEffect type, ref QVec3 origin, uint colorMin, uint colorMax)
{ {
Profiler.BeginSample("ParticleExplosion");
GetSelf(context).ParticleExplosion(origin.ToUnityPosition());
Profiler.EndSample();
}
Profiler.BeginSample("CreateParticleEffect");
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void TeleportSplashCallback(IntPtr context, ref QVec3 origin);
if (type == ParticleEffect.Explosion2)
GetSelf(context).CreateParticleExplosion(origin.ToUnityPosition(), colorMin.ToColor(), colorMax.ToColor());
else
GetSelf(context).CreateParticleEffect(type, origin.ToUnityPosition());
[MonoPInvokeCallback(typeof(TeleportSplashCallback))]
private static void Callback_TeleportSplash(IntPtr context, ref QVec3 origin)
{
Profiler.BeginSample("TeleportSplash");
GetSelf(context).TeleportSplash(origin.ToUnityPosition());
Profiler.EndSample(); Profiler.EndSample();
} }
} }

38
Assets/Scripts/Modules/GameModule.cs

@ -73,13 +73,43 @@ public partial class GameModule
uq.CurrentStyle.Particles.RunParticleEffect(position, direction, colorMin,colorMax, count, uq.GameLayer); uq.CurrentStyle.Particles.RunParticleEffect(position, direction, colorMin,colorMax, count, uq.GameLayer);
} }
private void ParticleExplosion(Vector3 position)
private void CreateParticleEffect(ParticleEffect type, Vector3 position)
{ {
uq.CurrentStyle.Particles.CreateExplosion(position, uq.GameLayer);
switch (type)
{
case ParticleEffect.Explosion:
uq.CurrentStyle.Particles.CreateExplosion(position, uq.GameLayer);
break;
case ParticleEffect.TeleportSplash:
uq.CurrentStyle.Particles.CreateTeleportSplash(position, uq.GameLayer);
break;
}
}
private void CreateParticleExplosion(Vector3 position, Color colorMin, Color colorMax)
{
}
// Should correspond to particle_effect_t in game_uniquake.c
private enum ParticleEffect
{
Explosion = 0,
Explosion2,
BlobExplosion,
LavaSplash,
TeleportSplash,
} }
private void TeleportSplash(Vector3 position)
// Should correspond to `int type` argument in R_RocketTrail
private enum ParticleTrail
{ {
uq.CurrentStyle.Particles.CreateTeleportSplash(position, uq.GameLayer);
Rocket = 0,
Smoke = 1,
Blood = 2,
Tracer = 3,
SlightBlood = 4,
Tracer2 = 5,
VoreBall = 6,
} }
} }

4
Assets/Styles/GLQuake/Particles/Particle.mat

@ -26,7 +26,7 @@ Material:
m_LightmapFlags: 4 m_LightmapFlags: 4
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
m_CustomRenderQueue: 3001
stringTagMap: stringTagMap:
RenderType: Transparent RenderType: Transparent
disabledShaderPasses: disabledShaderPasses:
@ -120,7 +120,7 @@ Material:
- _Mode: 0 - _Mode: 0
- _OcclusionStrength: 1 - _OcclusionStrength: 1
- _Parallax: 0.005 - _Parallax: 0.005
- _QueueOffset: 0
- _QueueOffset: 1
- _ReceiveShadows: 1 - _ReceiveShadows: 1
- _Smoothness: 0.5 - _Smoothness: 0.5
- _SmoothnessTextureChannel: 0 - _SmoothnessTextureChannel: 0

16
engine/UniQuake/game_uniquake.c

@ -11,8 +11,7 @@ typedef struct unity_gamecalls_s
void(*SetEntitySkin)(void *context, int entityNum, int skinNum); void(*SetEntitySkin)(void *context, int entityNum, int skinNum);
void(*RunParticleEffect)(void *context, vec3_t origin, vec3_t direction, unsigned int colorMin, unsigned int colorMax, int count); void(*RunParticleEffect)(void *context, vec3_t origin, vec3_t direction, unsigned int colorMin, unsigned int colorMax, int count);
void(*ParticleExplosion)(void *context, vec3_t origin);
void(*TeleportSplash)(void *context, vec3_t origin);
void(*CreateParticleEffect)(void *context, int type, vec3_t origin, unsigned int colorMin, unsigned int colorMax);
} unity_gamecalls_t; } unity_gamecalls_t;
static void *unity_context; static void *unity_context;
@ -57,12 +56,21 @@ void UQ_Game_RunParticleEffect(vec3_t origin, vec3_t direction, int color, int c
unity_gamecalls->RunParticleEffect(unity_context, origin, direction, colorMin, colorMax, count); unity_gamecalls->RunParticleEffect(unity_context, origin, direction, colorMin, colorMax, count);
} }
typedef enum
{
PARTFX_EXPLOSION = 0,
PARTFX_EXPLOSION2,
PARTFX_BLOB_EXPLOSION,
PARTFX_LAVA_SPLASH,
PARTFX_TELEPORT_SPLASH,
} particle_effect_t;
void UQ_Game_ParticleExplosion(vec3_t origin) void UQ_Game_ParticleExplosion(vec3_t origin)
{ {
unity_gamecalls->ParticleExplosion(unity_context, origin);
unity_gamecalls->CreateParticleEffect(unity_context, PARTFX_EXPLOSION, origin, 0, 0);
} }
void UQ_Game_TeleportSplash(vec3_t origin) void UQ_Game_TeleportSplash(vec3_t origin)
{ {
unity_gamecalls->TeleportSplash(unity_context, origin);
unity_gamecalls->CreateParticleEffect(unity_context, PARTFX_TELEPORT_SPLASH, origin, 0, 0);
} }
Loading…
Cancel
Save