Browse Source

Allow entity skin number to be passed and apply the corresponding textures to the entity material

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

24
Assets/Scripts/Game/Entity.cs

@ -6,11 +6,14 @@ public class Entity
private readonly int entityNum;
private readonly VisualStyle visualStyle;
private int skinNumber;
private GameObject gameObject;
private MeshFilter meshFilter;
private MeshRenderer meshRenderer;
private SkinnedMeshRenderer skinnedMeshRenderer;
private Material material;
private AliasModel aliasModel;
private GameObject brushModel;
@ -127,9 +130,24 @@ public class Entity
gameObject.transform.rotation = rotation;
}
public void SetSkin(int skinNum)
{
skinNumber = skinNum;
if (material == null)
return;
var skins = aliasModel.Textures.Skins;
if (skinNumber >= 0 && skinNumber < skins.Count)
{
var skin = skins[skinNumber];
if (skin.Frames.Count > 0)
visualStyle.SetAliasModelTextures(material, skin.Frames[0].MainTexture, skin.Frames[0].FullBrightTexture);
}
}
private void AssignMeshRenderer()
{
Material material;
if (aliasModel.IsAnimated)
{
visualStyle.SetupAliasModelRenderer(skinnedMeshRenderer);
@ -143,8 +161,6 @@ public class Entity
meshRenderer.enabled = true;
}
var textures = aliasModel.Textures.PrimaryTextures;
if (textures != null)
visualStyle.SetAliasModelTextures(material, textures.MainTexture, textures.FullBrightTexture);
SetSkin(skinNumber);
}
}

12
Assets/Scripts/Game/GameState.cs

@ -74,12 +74,6 @@ public class GameState
}
public Entity GetEntity(int entityNum)
{
entities.TryGetValue(entityNum, out var entity);
return entity;
}
private Entity GetOrCreateEntity(int entityNum)
{
if (!entities.TryGetValue(entityNum, out var entity))
{
@ -92,7 +86,7 @@ public class GameState
public void SetEntityAliasModel(int entityNum, string modelName)
{
var entity = GetOrCreateEntity(entityNum);
var entity = GetEntity(entityNum);
if (!uq.GameAssets.TryGetAliasModel(modelName, out var aliasModel))
{
@ -105,7 +99,7 @@ public class GameState
public void SetEntityBrushModel(int entityNum, string modelName)
{
var entity = GetOrCreateEntity(entityNum);
var entity = GetEntity(entityNum);
if (!uq.GameAssets.TryGetBrushModel(modelName, out var brushModel))
{
@ -125,7 +119,7 @@ public class GameState
public void SetEntityWorldModel(int entityNum, int subModelNum)
{
var entity = GetOrCreateEntity(entityNum);
var entity = GetEntity(entityNum);
if (!uq.GameAssets.TryGetWorldSubModel(subModelNum, out var subModel))
{

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

@ -17,6 +17,7 @@ public partial class GameModule : CallbackHandler<GameModule>
SetEntityTransform = CreateCallback<GameSetEntityTransformCallback>(Callback_GameSetEntityTransform),
RemoveEntity = CreateCallback<GameRemoveEntityCallback>(Callback_GameRemoveEntity),
UpdateEntityAnimation = CreateCallback<GameUpdateEntityAnimationCallback>(Callback_GameUpdateEntityAnimation),
SetEntitySkin = CreateCallback<GameSetEntitySkinCallback>(Callback_GameSetEntitySkin),
};
RegisterCallbacks(callbacks);
@ -34,6 +35,7 @@ public partial class GameModule : CallbackHandler<GameModule>
public IntPtr SetEntityTransform;
public IntPtr RemoveEntity;
public IntPtr UpdateEntityAnimation;
public IntPtr SetEntitySkin;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@ -71,4 +73,13 @@ public partial class GameModule : CallbackHandler<GameModule>
{
GetSelf(target).UpdateEntityAnimation(entityNum, frameNum);
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void GameSetEntitySkinCallback(IntPtr target, int entityNum, int skinNum);
[MonoPInvokeCallback(typeof(GameSetEntitySkinCallback))]
private static void Callback_GameSetEntitySkin(IntPtr target, int entityNum, int skinNum)
{
GetSelf(target).SetEntitySkin(entityNum, skinNum);
}
}

5
Assets/Scripts/Modules/GameModule.cs

@ -62,4 +62,9 @@ public partial class GameModule
{
uq.GameState.GetEntity(entityNum)?.UpdateAnimation(frameNum);
}
private void SetEntitySkin(int entityNum, int skinNum)
{
uq.GameState.GetEntity(entityNum)?.SetSkin(skinNum);
}
}

2
engine/Quake/cl_parse.c

@ -514,6 +514,8 @@ void CL_ParseUpdate (int bits)
ent->skinnum = skin;
if (num > 0 && num <= cl.maxclients)
R_TranslateNewPlayerSkin (num - 1); //johnfitz -- was R_TranslatePlayerSkin
UQ_Game_SetEntitySkin(num, skin);
}
if (bits & U_EFFECTS)
ent->effects = MSG_ReadByte();

1
engine/Quake/client.h

@ -376,6 +376,7 @@ 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);
void UQ_Game_UpdateEntityAnimation(int entityNum, float frameNum);
void UQ_Game_SetEntitySkin(int entityNum, int skinNum);
#endif /* _CLIENT_H_ */

6
engine/UniQuake/game_uniquake.c

@ -10,6 +10,7 @@ typedef struct unity_gamecalls_s
void(*SetEntityTransform)(void *target, int entityNum, vec3_t origin, vec3_t angles);
void(*RemoveEntity)(void *target, int entityNum);
void(*UpdateEntityAnimation)(void *target, int entityNum, float frameNum);
void(*SetEntitySkin)(void *target, int entityNum, int skinNum);
} unity_gamecalls_t;
const unity_gamecalls_t *unity_gamecalls;
@ -33,3 +34,8 @@ void UQ_Game_UpdateEntityAnimation(int entityNum, float frameNum)
{
unity_gamecalls->UpdateEntityAnimation(unity_gamecalls->target, entityNum, frameNum);
}
void UQ_Game_SetEntitySkin(int entityNum, int skinNum)
{
unity_gamecalls->SetEntitySkin(unity_gamecalls->target, entityNum, skinNum);
}
Loading…
Cancel
Save