From 1a1c219bf62fa6051e8d1055624109c29ed30223 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Fri, 9 Jul 2021 14:37:20 +0200 Subject: [PATCH] Removed frame number stuff from SetEntityModel since it's not producing the correct values. Correctly detect non-world brush models and sprites, although they're not implemented yet. --- Assets/Scripts/Game/Entity.cs | 8 +++- Assets/Scripts/Game/GameState.cs | 10 ++++- Assets/Scripts/Modules/GameModule.Interop.cs | 6 +-- Assets/Scripts/Modules/GameModule.cs | 40 +++++++++++++------- engine/Quake/cl_parse.c | 7 +--- engine/Quake/client.h | 2 +- engine/UniQuake/game_uniquake.c | 6 +-- 7 files changed, 51 insertions(+), 28 deletions(-) diff --git a/Assets/Scripts/Game/Entity.cs b/Assets/Scripts/Game/Entity.cs index 1cf1878..ec5005f 100644 --- a/Assets/Scripts/Game/Entity.cs +++ b/Assets/Scripts/Game/Entity.cs @@ -34,12 +34,18 @@ public class Entity Object.Destroy(gameObject); } + public void ClearModel() + { + aliasModel = null; + meshRenderer.sharedMesh = null; + } + public void SetAliasModel(AliasModel model) { aliasModel = model; // Set a default pose based on the first animation frame - UpdateAnimation(0); + UpdateAnimation(0); } public void UpdateAnimation(int frameNum) diff --git a/Assets/Scripts/Game/GameState.cs b/Assets/Scripts/Game/GameState.cs index c3044d5..950156b 100644 --- a/Assets/Scripts/Game/GameState.cs +++ b/Assets/Scripts/Game/GameState.cs @@ -69,6 +69,14 @@ public class GameState } } + public void ClearEntityModel(int entityNum) + { + if (entities.TryGetValue(entityNum, out var entity)) + { + entity.ClearModel(); + } + } + public void SetEntityAliasModel(int entityNum, string modelName) { if (!entities.TryGetValue(entityNum, out var entity)) @@ -79,7 +87,7 @@ public class GameState if (!uq.GameAssets.TryGetAliasModel(modelName, out var aliasModel)) { - Debug.LogWarning($"Unknown alias model name: {aliasModel}"); + Debug.LogWarning($"Unknown alias model name: {modelName}"); return; } diff --git a/Assets/Scripts/Modules/GameModule.Interop.cs b/Assets/Scripts/Modules/GameModule.Interop.cs index 181552d..c673003 100644 --- a/Assets/Scripts/Modules/GameModule.Interop.cs +++ b/Assets/Scripts/Modules/GameModule.Interop.cs @@ -35,12 +35,12 @@ public partial class GameModule : CallbackHandler } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void GameSetEntityModelCallback(IntPtr target, int entityNum, [MarshalAs(UnmanagedType.LPStr)] string modelName, int frame); + private delegate void GameSetEntityModelCallback(IntPtr target, int entityNum, [MarshalAs(UnmanagedType.LPStr)] string modelName); [MonoPInvokeCallback(typeof(GameSetEntityModelCallback))] - private static void Callback_GameSetEntityModel(IntPtr target, int entityNum, string modelName, int frame) + private static void Callback_GameSetEntityModel(IntPtr target, int entityNum, string modelName) { - GetSelf(target).SetEntityModel(entityNum, modelName, frame); + GetSelf(target).SetEntityModel(entityNum, modelName); } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] diff --git a/Assets/Scripts/Modules/GameModule.cs b/Assets/Scripts/Modules/GameModule.cs index bfb3cd5..b091962 100644 --- a/Assets/Scripts/Modules/GameModule.cs +++ b/Assets/Scripts/Modules/GameModule.cs @@ -12,27 +12,41 @@ public partial class GameModule BuildCallbacks(); } - private void SetEntityModel(int entityNum, string modelName, int frame) + private void SetEntityModel(int entityNum, string modelName) { - if (modelName != null) + if (string.IsNullOrEmpty(modelName)) { - if (modelName.StartsWith("*")) + uq.GameState.ClearEntityModel(entityNum); + return; + } + + if (modelName.StartsWith("*")) + { + if (!int.TryParse(modelName.Substring(1), out int subModelNum)) { - if (!int.TryParse(modelName.Substring(1), out int subModelNum)) - { - Debug.LogWarning($"Invalid world submodel index: {modelName}"); - return; - } - - uq.GameState.SetEntityWorldModel(entityNum, subModelNum); + Debug.LogWarning($"Invalid world submodel index: {modelName}"); return; } - // TODO: identify non-world brush model names - uq.GameState.SetEntityAliasModel(entityNum, modelName); + uq.GameState.SetEntityWorldModel(entityNum, subModelNum); + return; + } + + if (modelName.EndsWith(".bsp")) + { + // TODO: non-world brush model + uq.GameState.ClearEntityModel(entityNum); + return; + } + + if (modelName.EndsWith(".spr")) + { + // TODO: sprite + uq.GameState.ClearEntityModel(entityNum); + return; } - uq.GameState.UpdateEntityAnimation(entityNum, frame); + uq.GameState.SetEntityAliasModel(entityNum, modelName); } private void SetEntityTransform(int entityNum, QVec3 origin, QVec3 angles) diff --git a/engine/Quake/cl_parse.c b/engine/Quake/cl_parse.c index 3f021c9..d153925 100644 --- a/engine/Quake/cl_parse.c +++ b/engine/Quake/cl_parse.c @@ -618,12 +618,7 @@ void CL_ParseUpdate (int bits) ent->lerpflags |= LERP_RESETANIM; //johnfitz -- don't lerp animation across model changes - UQ_Game_SetEntityModel(num, model->name, ent->frame); - } - else - { - // Model hasn't changed, just update the animation info - UQ_Game_SetEntityModel(num, NULL, ent->frame); + UQ_Game_SetEntityModel(num, model ? model->name : NULL); } //johnfitz diff --git a/engine/Quake/client.h b/engine/Quake/client.h index b2ccb0c..853820b 100644 --- a/engine/Quake/client.h +++ b/engine/Quake/client.h @@ -372,7 +372,7 @@ void TraceLine (vec3_t start, vec3_t end, vec3_t impact); void Chase_UpdateForClient (void); //johnfitz void Chase_UpdateForDrawing (void); //johnfitz -void UQ_Game_SetEntityModel(int entityNum, const char *modelName, int frame); +void UQ_Game_SetEntityModel(int entityNum, const char *modelName); void UQ_Game_SetEntityTransform(int entityNum, vec3_t origin, vec3_t angles); void UQ_Game_RemoveEntity(int entityNum); diff --git a/engine/UniQuake/game_uniquake.c b/engine/UniQuake/game_uniquake.c index 3f3c814..4057c4a 100644 --- a/engine/UniQuake/game_uniquake.c +++ b/engine/UniQuake/game_uniquake.c @@ -6,16 +6,16 @@ typedef struct unity_gamecalls_s { void *target; - void(*SetEntityModel)(void *target, int entityNum, const char *modelName, int frame); + void(*SetEntityModel)(void *target, int entityNum, const char *modelName); void(*SetEntityTransform)(void *target, int entityNum, vec3_t origin, vec3_t angles); void(*RemoveEntity)(void *target, int entityNum); } unity_gamecalls_t; const unity_gamecalls_t *unity_gamecalls; -void UQ_Game_SetEntityModel(int entityNum, const char *modelName, int frame) +void UQ_Game_SetEntityModel(int entityNum, const char *modelName) { - unity_gamecalls->SetEntityModel(unity_gamecalls->target, entityNum, modelName, frame); + unity_gamecalls->SetEntityModel(unity_gamecalls->target, entityNum, modelName); } void UQ_Game_SetEntityTransform(int entityNum, vec3_t origin, vec3_t angles)