• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubybathyscaphegamepythonphpguiwindowsc翻訳omegattwitterframeworkbtronarduinovb.net計画中(planning stage)directxpreviewertestゲームエンジンdom

VS plugin mod for Basic Armour


Commit MetaInfo

Revisionf0a27eed8378aef611fa20877feb634cff0f2a63 (tree)
Zeit2019-06-13 10:59:43
Autormelchior <melchior@user...>
Commitermelchior

Log Message

Modified client event handling use non-polling method
Change variable casing for renderer (consistency)

Ändern Zusammenfassung

Diff

--- a/ArmourMod/Armour/AmourMeshRenderer.cs
+++ b/ArmourMod/Armour/AmourMeshRenderer.cs
@@ -14,7 +14,7 @@ namespace ArmourMod
1414 {
1515 public class ArmourMeshRenderer : IRenderer
1616 {
17- protected ICoreClientAPI ClientApi { get; set; }
17+ protected ICoreClientAPI ClientAPI { get; set; }
1818 private Dictionary<AssetLocation,ArmourModelData> Armoury;
1919 private bool enabled = true;
2020
@@ -30,7 +30,7 @@ namespace ArmourMod
3030
3131 public ArmourMeshRenderer(ICoreClientAPI capi,Dictionary<AssetLocation,ArmourModelData> armoury )
3232 {
33- this.ClientApi = capi;
33+ this.ClientAPI = capi;
3434 this.Armoury = armoury;
3535 //Pre-cached up ALL the damm armours; Mesh + Texture, Translations, Origins, other important parameters
3636 }
@@ -39,8 +39,8 @@ namespace ArmourMod
3939 {
4040 if (enabled) {
4141 try {
42- for (int i = 0; i < ClientApi.World.AllOnlinePlayers.Length; i++) {
43- var aPlayer = ClientApi.World.AllOnlinePlayers[i];
42+ for (int i = 0; i < ClientAPI.World.AllOnlinePlayers.Length; i++) {
43+ var aPlayer = ClientAPI.World.AllOnlinePlayers[i];
4444
4545 if (aPlayer?.Entity == null) continue;//Out of range
4646
@@ -52,12 +52,12 @@ namespace ArmourMod
5252 EntityArmourPlayer armouredPlayer = aPlayer.Entity as EntityArmourPlayer;
5353
5454 if (armouredPlayer == null) {
55- ClientApi.Logger.Error("Could not cast EntityPlayer to EntityArmourPlayer");
55+ ClientAPI.Logger.Error("Could not cast EntityPlayer to EntityArmourPlayer");
5656 return;
5757 }
5858
5959 if (armouredPlayer.RenderableWornArmours == null) {
60- ClientApi.Logger.Error("RenderableWornArmours was NULL!");
60+ ClientAPI.Logger.Error("RenderableWornArmours was NULL!");
6161 return;
6262 }
6363
@@ -70,7 +70,7 @@ namespace ArmourMod
7070
7171 } catch (Exception problem)
7272 {
73- ClientApi.Logger.Error("ArmourMeshRenderer FAULT: {0} Disabling.", problem.Message);
73+ ClientAPI.Logger.Error("ArmourMeshRenderer FAULT: {0} Disabling.", problem.Message);
7474 enabled = false;
7575 }
7676 }
@@ -84,10 +84,10 @@ namespace ArmourMod
8484 /// <param name="isShadowPass">If set to <c>true</c> is shadow pass.</param>
8585 private void RenderWornArmour(EntityArmourPlayer armouredPlayer, EntityShapeRenderer entityShapeRender, bool isShadowPass)
8686 {
87- IRenderAPI rpi = ClientApi.Render;
87+ IRenderAPI rpi = ClientAPI.Render;
8888 IStandardShaderProgram prog = null;
8989
90- if ( ClientApi.World.Player.Entity.EntityId == armouredPlayer.EntityId ) {
90+ if ( ClientAPI.World.Player.Entity.EntityId == armouredPlayer.EntityId ) {
9191 //Is current player in First-person.... skip rendering
9292 if ( rpi.CameraType == EnumCameraMode.FirstPerson ) return;
9393 }
@@ -95,7 +95,7 @@ namespace ArmourMod
9595 foreach(var wornItemTuple in armouredPlayer.RenderableWornArmours) {
9696
9797 if ( !Armoury.ContainsKey( wornItemTuple.Value.Code ) ) {
98- ClientApi.Logger.Warning( "Armoury Item Missing KEY: {0} ! ** RENDER ABORTED **", wornItemTuple.Value.Code );
98+ ClientAPI.Logger.Warning( "Armoury Item Missing KEY: {0} ! ** RENDER ABORTED **", wornItemTuple.Value.Code );
9999 return;
100100 }
101101
@@ -113,7 +113,7 @@ namespace ArmourMod
113113
114114 default:
115115 attachPoise = null;
116- ClientApi.Logger.Warning( "Unsupported armour Attachment Type: {0} ! ** RENDER ABORTED **", wornItemTuple.Key.ToString() );
116+ ClientAPI.Logger.Warning( "Unsupported armour Attachment Type: {0} ! ** RENDER ABORTED **", wornItemTuple.Key.ToString() );
117117 return;
118118 }
119119
@@ -129,7 +129,7 @@ namespace ArmourMod
129129 armourModelMatrix.Set(entityShapeRender.ModelMat);
130130 armourModelMatrix.Mul(attachPoise.AnimModelMatrix);
131131
132- viewMatrix.Set( ClientApi.Render.CameraMatrixOriginf );
132+ viewMatrix.Set( ClientAPI.Render.CameraMatrixOriginf );
133133
134134
135135 if ( isShadowPass ) {
@@ -151,8 +151,8 @@ namespace ArmourMod
151151
152152 var headMatrix = Mat4f.Create( );
153153 Mat4f.Identity(headMatrix);
154- Mat4f.RotateY(headMatrix, headMatrix, ClientApi.World.Player.Entity.HeadYaw);
155- Mat4f.RotateZ(headMatrix, headMatrix, ClientApi.World.Player.Entity.HeadPitch);
154+ Mat4f.RotateY(headMatrix, headMatrix, ClientAPI.World.Player.Entity.HeadYaw);
155+ Mat4f.RotateZ(headMatrix, headMatrix, ClientAPI.World.Player.Entity.HeadPitch);
156156
157157 armourModelMatrix
158158 .Scale( armourData.Armour_Transform.ScaleXYZ.X, armourData.Armour_Transform.ScaleXYZ.Y, armourData.Armour_Transform.ScaleXYZ.Z )
@@ -175,16 +175,16 @@ namespace ArmourMod
175175
176176
177177 if ( isShadowPass ) {
178- armourModelMatrix.Mul(ClientApi.Render.CurrentShadowProjectionMatrix);
179- ClientApi.Render.CurrentActiveShader.UniformMatrix( "mvpMatrix", armourModelMatrix.Values );
180- ClientApi.Render.CurrentActiveShader.Uniform( "origin", new Vec3f());//OpenGL version of CONST/GLOBAL <-- what is VALUE???
178+ armourModelMatrix.Mul(ClientAPI.Render.CurrentShadowProjectionMatrix);
179+ ClientAPI.Render.CurrentActiveShader.UniformMatrix( "mvpMatrix", armourModelMatrix.Values );
180+ ClientAPI.Render.CurrentActiveShader.Uniform( "origin", new Vec3f());//OpenGL version of CONST/GLOBAL <-- what is VALUE???
181181 } else {
182182 prog.ModelMatrix = armourModelMatrix.Values;
183183 prog.ViewMatrix = viewMatrix.Values;
184- prog.ProjectionMatrix = ClientApi.Render.CurrentProjectionMatrix;
184+ prog.ProjectionMatrix = ClientAPI.Render.CurrentProjectionMatrix;
185185 }
186186
187- ClientApi.Render.RenderMesh( armourData.ArmourMeshReference );
187+ ClientAPI.Render.RenderMesh( armourData.ArmourMeshReference );
188188
189189
190190 if ( !isShadowPass )
@@ -197,7 +197,7 @@ namespace ArmourMod
197197 //Manually clean up Meshs'
198198 foreach(ArmourModelData armr in Armoury.Values)
199199 {
200- ClientApi.Render.DeleteMesh( armr.ArmourMeshReference );
200+ ClientAPI.Render.DeleteMesh( armr.ArmourMeshReference );
201201 }
202202
203203 }
--- a/ArmourMod/Armour/EntityArmourPlayer.cs
+++ b/ArmourMod/Armour/EntityArmourPlayer.cs
@@ -11,8 +11,7 @@ using Vintagestory.API.Server;
1111 namespace ArmourMod
1212 {
1313 public class EntityArmourPlayer : EntityPlayer
14- {
15- private static string _clientHookIdKey = @"ClientDelayHookId";
14+ {
1615 protected ICoreAPI CoreAPI;
1716 protected ICoreClientAPI ClientAPI;
1817 protected ICoreServerAPI ServerAPI;
@@ -24,9 +23,6 @@ namespace ArmourMod
2423 //Pre-compute values;
2524 private DamageFilter finalFilter;
2625
27- private bool slotEventAttached;
28-
29-
3026 internal ArmourModConfig CachedConfiguration
3127 {
3228 get
@@ -39,32 +35,9 @@ namespace ArmourMod
3935 }
4036 }
4137
42- private long CachedClientCallbackId
43- {
44- get
45- {
46- if (ClientAPI.ObjectCache.ContainsKey(_clientHookIdKey + ClientAPI.World.Player.PlayerUID))
47- {
48- return (long)ClientAPI.ObjectCache[_clientHookIdKey + ClientAPI.World.Player.PlayerUID];
49- } else {
50- return -1L;
51- }
52- }
53- set
54- {
55- if (ClientAPI.ObjectCache.ContainsKey(_clientHookIdKey + ClientAPI.World.Player.PlayerUID))
56- {
57- Logger.Error("Trying to register duplicate callback-id [value: {0}]", value); ;
58- }
59- else
60- {
61- ClientAPI.ObjectCache[_clientHookIdKey + ClientAPI.World.Player.PlayerUID] = value;
62- }
63- }
64- }
38+ public bool OwnEventsAttached { get; internal set;}
6539
66-
67- public Dictionary<EnumCharacterDressType,Item> RenderableWornArmours { get; private set;}//Needs to be client side
40+ public Dictionary<EnumCharacterDressType, Item> RenderableWornArmours { get; private set; }//Needs to be client side
6841
6942 public override void Initialize(Vintagestory.API.Common.Entities.EntityProperties properties, ICoreAPI api, long chunkindex3d)
7043 {
@@ -78,38 +51,17 @@ namespace ArmourMod
7851 this.ClientAPI = api as ICoreClientAPI;
7952 this.RenderableWornArmours = new Dictionary<EnumCharacterDressType, Item>(); // BEFORE RENDERER GETS THERE!
8053 Logger.VerboseDebug("Renderable Worn Armours Dict assigned");
54+
55+ ClientAPI.Event.PlayerEntitySpawn += HandlePlayerSpawn;
56+ ClientAPI.Event.PlayerEntityDespawn += HandlePlayerDespawn;
8157 }
8258
8359 if (CoreAPI.Side.IsServer( )) {
8460 this.ServerAPI = api as ICoreServerAPI;
85- //from Config set values;
86- //ServerAPI.ModLoader.
87- //ArmourModHookin._domain
8861 }
8962 }
9063
91- public override void OnGameTick(float dt)
92- {
93- base.OnGameTick(dt);
94-
9564
96- if (CoreAPI.Side.IsClient( )) {
97-
98- if (ClientAPI.World.Player != null) {
99-
100- if (this.CachedClientCallbackId > 0) {
101- #if DEBUG
102- Logger.VerboseDebug("[OnEntityLoaded] Duplicate event attach prevented");
103- #endif
104- } else {
105- this.CachedClientCallbackId = ClientAPI.Event.RegisterGameTickListener(ClientDelayHook, 250);
106- #if DEBUG
107- Logger.VerboseDebug("[OnEntityLoaded] oneShotDelayId: {0}", this.CachedClientCallbackId);
108- #endif
109- }
110- }
111- }
112- }
11365
11466
11567 public override void OnEntitySpawn()
@@ -296,32 +248,6 @@ namespace ArmourMod
296248 return false;
297249 }
298250
299-
300- protected void ClientDelayHook(float delay)
301- {
302- #if DEBUG
303- Logger.VerboseDebug("[clientDelayHook] oneShotDelayId: {0}", this.CachedClientCallbackId);
304- #endif
305-
306- if (this.GearInventory == null) {
307- Logger.Error("ClientDelayHook: base.GearInventory IS NULL! ");
308-
309- return;
310- }
311-
312- if (slotEventAttached == false) {
313- slotEventAttached = true;
314- #if DEBUG
315- Logger.VerboseDebug("Attached ClientWatchSlotModified (ClientDelayHook)");
316- #endif
317- this.GearInventory.SlotModified += ClientWatchSlotModified;
318- }
319-
320- ClientAPI.Event.UnregisterGameTickListener(this.CachedClientCallbackId);
321-
322- PopulateWornArmourModels( );
323- }
324-
325251 private void ServerWatchSlotModified (int slotId)
326252 {
327253 var watchedSlot = this.GearInventory[slotId];
@@ -356,7 +282,7 @@ namespace ArmourMod
356282 }
357283 }
358284
359- private void ClientWatchSlotModified (int slotId)
285+ protected void ClientWatchSlotModified (int slotId)
360286 {
361287 #if DEBUG
362288 Logger.VerboseDebug( "(Client) WatchSlotModified:{0} PlayerID: {1} InventoryID: {2}", slotId, ClientAPI.World.Player.PlayerUID,this.GearInventory.InventoryID );
@@ -378,14 +304,62 @@ namespace ArmourMod
378304 }
379305 }
380306
381- /*
382- private void WatchSlotNotified(int slotId)
307+ /// <summary>
308+ /// Add Watcher for armour change -- could be _ANY_ player (not just self!)
309+ /// </summary>
310+ /// <remarks>Client side</remarks>
311+ /// <param name="byPlayer">By player.</param>
312+ private void HandlePlayerSpawn(IClientPlayer byPlayer)
313+ {
314+ Logger.VerboseDebug("Handling Spawn for: {0}", byPlayer.PlayerName);
315+
316+ if (byPlayer.Entity != null && byPlayer.Entity is EntityArmourPlayer) {
317+ EntityArmourPlayer targetPlayer = byPlayer.Entity as EntityArmourPlayer;//CHECK: Cast from - not actual instance?
318+
319+ if (targetPlayer.GearInventory == null) {
320+ Logger.Error("HandlePlayerSpawn: base.GearInventory IS NULL! ");
321+
322+ return;
323+ }
324+
325+ if (targetPlayer.PlayerUID == ClientAPI.World.Player.PlayerUID)
326+ {
327+ if (targetPlayer.OwnEventsAttached == false) {
328+ targetPlayer.OwnEventsAttached = true;
329+ #if DEBUG
330+ Logger.VerboseDebug("Attached event: (ClientWatchSlotModified) for {0}", byPlayer.PlayerName);
331+ #endif
332+ targetPlayer.GearInventory.SlotModified += targetPlayer.ClientWatchSlotModified;
333+ PopulateWornArmourModels(targetPlayer);
334+ } else {
335+ #if DEBUG
336+ Logger.VerboseDebug("Duplicate event: (ClientWatchSlotModified) for {0}", byPlayer.PlayerName);
337+ #endif
338+ }
339+ } else {
340+ if (targetPlayer.OwnEventsAttached == false) {
341+ targetPlayer.OwnEventsAttached = true;
342+ #if DEBUG
343+ Logger.VerboseDebug("Non-local Attached event: (ClientWatchSlotModified) for {0}", byPlayer.PlayerName);
344+ #endif
345+ targetPlayer.GearInventory.SlotModified += targetPlayer.ClientWatchSlotModified;
346+ PopulateWornArmourModels(targetPlayer);
347+ } else {
348+ #if DEBUG
349+ Logger.VerboseDebug("Non-local Duplicate event: (ClientWatchSlotModified) for {0}", byPlayer.PlayerName);
350+ #endif
351+ }
352+ }
353+ }
354+ }
355+
356+
357+ private void HandlePlayerDespawn(IClientPlayer byPlayer)
383358 {
384- var watchedSlot = base.GearInventory[slotId];
359+ //Unlink watcher event
360+ Logger.VerboseDebug("Handling Despawn for: {0}", byPlayer.PlayerName);
385361
386- Logger.VerboseDebug( "WatchSlotNotified:{0}", slotId );
387362 }
388- */
389363
390364
391365
@@ -484,26 +458,26 @@ namespace ArmourMod
484458 /// Client Side rendering; What armours are visibly worn
485459 /// </summary>
486460 /// <returns>The worn armour models.</returns>
487- private void PopulateWornArmourModels()
461+ internal void PopulateWornArmourModels(EntityArmourPlayer targetPlayer)
488462 {
489- if ( this.GearInventory != null && this.GearInventory.Count > 0 ) {
490- foreach(var itemSlot in this.GearInventory ) {
463+ if ( targetPlayer.GearInventory != null && targetPlayer.GearInventory.Count > 0 ) {
464+ foreach(var itemSlot in targetPlayer.GearInventory ) {
491465
492- int slotId = this.GearInventory.GetSlotId( itemSlot );
466+ int slotId = targetPlayer.GearInventory.GetSlotId( itemSlot );
493467 if ( !itemSlot.Empty ) {
494468
495469 if ( itemSlot.StorageType == EnumItemStorageFlags.Outfit && itemSlot.Itemstack.Class == EnumItemClass.Item ) {
496470
497471 if ( CheckIfClothesIsArmour(itemSlot) )
498- {
472+ {
499473 #if DEBUG
500- Logger.VerboseDebug( "Now wearing armour:{0}", itemSlot.Itemstack.Item.Code.ToString( ) );
474+ Logger.VerboseDebug( "{0} is wearing armour: {1}", targetPlayer.Player.PlayerName, itemSlot.Itemstack.Item.Code.ToString( ) );
501475 #endif
502476
503477 if (RenderableWornArmours.ContainsKey(( EnumCharacterDressType )slotId)) {
504478 Logger.Warning("DUPLICATE assignment; Armour in slot: {0} named: {1}", slotId, itemSlot.Itemstack.Item.Code.ToString( ));
505479 } else {
506- RenderableWornArmours.Add(( EnumCharacterDressType )slotId, itemSlot.Itemstack.Item);
480+ targetPlayer.RenderableWornArmours.Add(( EnumCharacterDressType )slotId, itemSlot.Itemstack.Item);
507481 }
508482 }
509483 }