Browse Source

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.

console
Nico de Poel 5 years ago
parent
commit
1a1c219bf6
  1. 8
      Assets/Scripts/Game/Entity.cs
  2. 10
      Assets/Scripts/Game/GameState.cs
  3. 6
      Assets/Scripts/Modules/GameModule.Interop.cs
  4. 40
      Assets/Scripts/Modules/GameModule.cs
  5. 7
      engine/Quake/cl_parse.c
  6. 2
      engine/Quake/client.h
  7. 6
      engine/UniQuake/game_uniquake.c

8
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)

10
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;
}

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

@ -35,12 +35,12 @@ public partial class GameModule : CallbackHandler<GameModule>
}
[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)]

40
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)

7
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

2
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);

6
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)

Loading…
Cancel
Save