Some stuff
This commit is contained in:
@ -37,6 +37,7 @@ namespace RageCoop.Client
|
|||||||
DiagnosticMenu.Opening+=(sender, e) =>
|
DiagnosticMenu.Opening+=(sender, e) =>
|
||||||
{
|
{
|
||||||
DiagnosticMenu.Clear();
|
DiagnosticMenu.Clear();
|
||||||
|
DiagnosticMenu.Add(new NativeItem("EntityPool", EntityPool.DumpDebug()));
|
||||||
foreach (var pair in Debug.TimeStamps)
|
foreach (var pair in Debug.TimeStamps)
|
||||||
{
|
{
|
||||||
DiagnosticMenu.Add(new NativeItem(pair.Key.ToString(), pair.Value.ToString(), pair.Value.ToString()));
|
DiagnosticMenu.Add(new NativeItem(pair.Key.ToString(), pair.Value.ToString(), pair.Value.ToString()));
|
||||||
|
@ -133,6 +133,7 @@
|
|||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<Compile Include="Sync\Entities\SyncedProjectile.cs" />
|
<Compile Include="Sync\Entities\SyncedProjectile.cs" />
|
||||||
<Compile Include="Sync\EntityPool.cs" />
|
<Compile Include="Sync\EntityPool.cs" />
|
||||||
|
<Compile Include="Sync\EventArgs\ProjectileShotEventArgs.cs" />
|
||||||
<Compile Include="Sync\SyncEvents.cs" />
|
<Compile Include="Sync\SyncEvents.cs" />
|
||||||
<Compile Include="Sync\Entities\SyncedEntity.cs" />
|
<Compile Include="Sync\Entities\SyncedEntity.cs" />
|
||||||
<Compile Include="Sync\Entities\SyncedVehicle.cs" />
|
<Compile Include="Sync\Entities\SyncedVehicle.cs" />
|
||||||
|
@ -427,7 +427,7 @@ namespace RageCoop.Client
|
|||||||
MainPed.Task.Climb();
|
MainPed.Task.Climb();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateOnFootPosition(true, true, false);
|
SmoothTransition();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -514,7 +514,7 @@ namespace RageCoop.Client
|
|||||||
MainPed.Task.PlayAnimation(_currentAnimation[0], _currentAnimation[1], 8f, -1, AnimationFlags.AllowRotation | AnimationFlags.UpperBodyOnly);
|
MainPed.Task.PlayAnimation(_currentAnimation[0], _currentAnimation[1], 8f, -1, AnimationFlags.AllowRotation | AnimationFlags.UpperBodyOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateOnFootPosition();
|
SmoothTransition();
|
||||||
}
|
}
|
||||||
else if (_currentAnimation[1] == "reload_aim")
|
else if (_currentAnimation[1] == "reload_aim")
|
||||||
{
|
{
|
||||||
@ -671,56 +671,6 @@ namespace RageCoop.Client
|
|||||||
SmoothTransition();
|
SmoothTransition();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateOnFootPosition(bool updatePosition = true, bool updateRotation = true, bool updateVelocity = true)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
ulong time = Util.GetTickCount64();
|
|
||||||
|
|
||||||
if (StuckDetection)
|
|
||||||
{
|
|
||||||
if (time - LastStuckTime >= 500)
|
|
||||||
{
|
|
||||||
StuckDetection = false;
|
|
||||||
|
|
||||||
if (Character.Position.DistanceTo(Position) > 5f)
|
|
||||||
{
|
|
||||||
Character.PositionNoOffset = Position;
|
|
||||||
Character.Rotation = Rotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (time - LastStuckTime >= 500)
|
|
||||||
{
|
|
||||||
if (Character.Position.DistanceTo(Position) > 5f)
|
|
||||||
{
|
|
||||||
StuckDetection = true;
|
|
||||||
LastStuckTime = time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (updatePosition)
|
|
||||||
{
|
|
||||||
MainPed.PositionNoOffset = Position;
|
|
||||||
/*
|
|
||||||
float lerpValue = (int)((Latency * 1000 / 2) + (Networking.Latency * 1000 / 2)) * 2 / 50000f;
|
|
||||||
|
|
||||||
Vector2 biDimensionalPos = Vector2.Lerp(new Vector2(Character.Position.X, Character.Position.Y), new Vector2(Position.X + (Velocity.X / 5), Position.Y + (Velocity.Y / 5)), lerpValue);
|
|
||||||
float zPos = Util.Lerp(Character.Position.Z, Position.Z, 0.1f);
|
|
||||||
Character.PositionNoOffset = new Vector3(biDimensionalPos.X, biDimensionalPos.Y, zPos);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateRotation)
|
|
||||||
{
|
|
||||||
// You can find the ToQuaternion() for Rotation inside the VectorExtensions
|
|
||||||
MainPed.Quaternion = Rotation.ToQuaternion();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updateVelocity)
|
|
||||||
{
|
|
||||||
MainPed.Velocity = Velocity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void SmoothTransition()
|
private void SmoothTransition()
|
||||||
{
|
{
|
||||||
var localRagdoll = MainPed.IsRagdoll;
|
var localRagdoll = MainPed.IsRagdoll;
|
||||||
|
@ -5,14 +5,17 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GTA;
|
using GTA;
|
||||||
|
|
||||||
namespace RageCoop.Client.Sync.Entities
|
namespace RageCoop.Client
|
||||||
{
|
{
|
||||||
internal class SyncedProjectile:SyncedEntity
|
internal class SyncedProjectile:SyncedEntity
|
||||||
{
|
{
|
||||||
public bool Exploded { get; set; } = false;
|
public bool Exploded { get; set; } = false;
|
||||||
public Projectile MainProjectile { get; set; }
|
public Projectile MainProjectile { get; set; }
|
||||||
|
public int ShooterID { get; set; }
|
||||||
public WeaponHash Hash { get; set; }
|
public WeaponHash Hash { get; set; }
|
||||||
private WeaponAsset Asset;
|
private WeaponAsset Asset { get; set; }
|
||||||
|
private bool _creatingProjectile{ get;set; }=false;
|
||||||
|
private ulong _projectileShotTime { get;set; }
|
||||||
public override void Update()
|
public override void Update()
|
||||||
{
|
{
|
||||||
// Check if all data avalible
|
// Check if all data avalible
|
||||||
@ -20,10 +23,18 @@ namespace RageCoop.Client.Sync.Entities
|
|||||||
|
|
||||||
// Skip update if no new sync message has arrived.
|
// Skip update if no new sync message has arrived.
|
||||||
if (!NeedUpdate)
|
if (!NeedUpdate)
|
||||||
|
{ return; }
|
||||||
|
|
||||||
|
if (_creatingProjectile) { return; }
|
||||||
|
|
||||||
|
if (MainProjectile == null || !MainProjectile.Exists())
|
||||||
{
|
{
|
||||||
|
CreateProjectile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
MainProjectile.Position=Position+Velocity*Networking.Latency;
|
||||||
|
MainProjectile.Velocity=Velocity;
|
||||||
|
MainProjectile.Rotation=Rotation;
|
||||||
if (Exploded)
|
if (Exploded)
|
||||||
{
|
{
|
||||||
if (Exploded)
|
if (Exploded)
|
||||||
@ -35,23 +46,35 @@ namespace RageCoop.Client.Sync.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (MainProjectile != null && MainProjectile.Exists())
|
|
||||||
{
|
|
||||||
MainProjectile.Position=Position+Velocity*Networking.Latency;
|
|
||||||
MainProjectile.Velocity=Velocity;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CreateProjectile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateProjectile()
|
private void CreateProjectile()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
Asset=new WeaponAsset(Hash);
|
||||||
|
if (!Asset.IsLoaded) { Asset.Request(); }
|
||||||
|
World.ShootBullet(Position,Position+Velocity,EntityPool.GetPedByID(ShooterID)?.MainPed,Asset,0,Velocity.Length());
|
||||||
|
_projectileShotTime=Main.Ticked;
|
||||||
|
_creatingProjectile=true;
|
||||||
|
|
||||||
|
EventHandler<ProjectileShotEventArgs> checker = null;
|
||||||
|
checker= (sender, e) =>
|
||||||
|
{
|
||||||
|
if (Main.Ticked<=_projectileShotTime+1)
|
||||||
|
{
|
||||||
|
if (e.Projectile.WeaponHash==Hash)
|
||||||
|
{
|
||||||
|
MainProjectile=e.Projectile;
|
||||||
|
_creatingProjectile=false;
|
||||||
|
SyncEvents.OnProjectileShot-=checker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_creatingProjectile=false;
|
||||||
|
SyncEvents.OnProjectileShot-=checker;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
SyncEvents.OnProjectileShot+=checker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,29 +144,6 @@ namespace RageCoop.Client
|
|||||||
MainVehicle.Position=Position;
|
MainVehicle.Position=Position;
|
||||||
MainVehicle.Velocity=Velocity;
|
MainVehicle.Velocity=Velocity;
|
||||||
}
|
}
|
||||||
#region OBSOLETE
|
|
||||||
// Good enough for now, but we need to create a better sync
|
|
||||||
/*
|
|
||||||
float dist = Position.DistanceTo(MainVehicle.Position);
|
|
||||||
Vector3 f = 5*dist * (Position+Velocity*0.06f - (MainVehicle.Position+MainVehicle.Velocity*delay));
|
|
||||||
|
|
||||||
if (dist < 5f)
|
|
||||||
{
|
|
||||||
// Precised calibration
|
|
||||||
if (Velocity.Length()<0.05) { f*=10f; }
|
|
||||||
else if (dist<1)
|
|
||||||
{
|
|
||||||
// Avoid vibration
|
|
||||||
f+=(Velocity-MainVehicle.Velocity);
|
|
||||||
}
|
|
||||||
MainVehicle.ApplyForce(f);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MainVehicle.PositionNoOffset = Position;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
Vector3 r = GetCalibrationRotation();
|
Vector3 r = GetCalibrationRotation();
|
||||||
if (r.Length() < 20f)
|
if (r.Length() < 20f)
|
||||||
{
|
{
|
||||||
|
@ -66,7 +66,6 @@ namespace RageCoop.Client
|
|||||||
if (player.MainPed!=p)
|
if (player.MainPed!=p)
|
||||||
{
|
{
|
||||||
// Player model changed
|
// Player model changed
|
||||||
|
|
||||||
player.MainPed = p;
|
player.MainPed = p;
|
||||||
|
|
||||||
// Remove it from Handle_Characters
|
// Remove it from Handle_Characters
|
||||||
@ -74,6 +73,7 @@ namespace RageCoop.Client
|
|||||||
if (pairs.Any())
|
if (pairs.Any())
|
||||||
{
|
{
|
||||||
var pair=pairs.First();
|
var pair=pairs.First();
|
||||||
|
|
||||||
// Re-add
|
// Re-add
|
||||||
Handle_Peds.Remove(pair.Key);
|
Handle_Peds.Remove(pair.Key);
|
||||||
if (Handle_Peds.ContainsKey(p.Handle))
|
if (Handle_Peds.ContainsKey(p.Handle))
|
||||||
@ -192,6 +192,8 @@ namespace RageCoop.Client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static bool Exists(int id)
|
public static bool Exists(int id)
|
||||||
{
|
{
|
||||||
return ID_Peds.ContainsKey(id) || ID_Vehicles.ContainsKey(id);
|
return ID_Peds.ContainsKey(id) || ID_Vehicles.ContainsKey(id);
|
||||||
@ -355,5 +357,14 @@ namespace RageCoop.Client
|
|||||||
Function.Call(Hash.SET_PED_POPULATION_BUDGET, b); // 0 - 3
|
Function.Call(Hash.SET_PED_POPULATION_BUDGET, b); // 0 - 3
|
||||||
Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, b); // 0 - 3
|
Function.Call(Hash.SET_VEHICLE_POPULATION_BUDGET, b); // 0 - 3
|
||||||
}
|
}
|
||||||
|
public static string DumpDebug()
|
||||||
|
{
|
||||||
|
string s= "";
|
||||||
|
s+="\nID_Peds: "+ID_Peds.Count;
|
||||||
|
s+="\nHandle_Peds: "+Handle_Peds.Count;
|
||||||
|
s+="\nID_Vehicles: "+ID_Vehicles.Count;
|
||||||
|
s+="\nHandle_Vehicles: "+Handle_Vehicles.Count;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
Client/Sync/EventArgs/ProjectileShotEventArgs.cs
Normal file
14
Client/Sync/EventArgs/ProjectileShotEventArgs.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using GTA;
|
||||||
|
|
||||||
|
namespace RageCoop.Client
|
||||||
|
{
|
||||||
|
internal class ProjectileShotEventArgs:EventArgs
|
||||||
|
{
|
||||||
|
public bool IsMine { get; set; }
|
||||||
|
public Projectile Projectile { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,17 @@ using System.Threading;
|
|||||||
namespace RageCoop.Client {
|
namespace RageCoop.Client {
|
||||||
internal static class SyncEvents
|
internal static class SyncEvents
|
||||||
{
|
{
|
||||||
|
public static event EventHandler<ProjectileShotEventArgs> OnProjectileShot;
|
||||||
|
|
||||||
|
static SyncEvents() {
|
||||||
|
OnProjectileShot+=(s, e) =>
|
||||||
|
{
|
||||||
|
if (e.IsMine)
|
||||||
|
{
|
||||||
|
TriggerProjectileShot(e.Projectile);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
#region TRIGGER
|
#region TRIGGER
|
||||||
public static void TriggerPedKilled(SyncedPed victim)
|
public static void TriggerPedKilled(SyncedPed victim)
|
||||||
{
|
{
|
||||||
@ -267,12 +278,28 @@ namespace RageCoop.Client {
|
|||||||
_projectileShot=false;
|
_projectileShot=false;
|
||||||
foreach (Projectile p in projectiles)
|
foreach (Projectile p in projectiles)
|
||||||
{
|
{
|
||||||
var owner = p.Owner.GetSyncEntity();
|
var owner = p.Owner?.GetSyncEntity();
|
||||||
if ((!lastProjectiles.Contains(p)) && (owner!=null) && owner.IsMine)
|
if (!lastProjectiles.Contains(p))
|
||||||
|
{
|
||||||
|
if((owner!=null) && owner.IsMine)
|
||||||
{
|
{
|
||||||
TriggerProjectileShot(p);
|
|
||||||
_projectileShot=true;
|
_projectileShot=true;
|
||||||
|
OnProjectileShot?.Invoke(null, new ProjectileShotEventArgs()
|
||||||
|
{
|
||||||
|
Projectile=p,
|
||||||
|
IsMine=true
|
||||||
|
}) ;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OnProjectileShot?.Invoke(null, new ProjectileShotEventArgs()
|
||||||
|
{
|
||||||
|
Projectile=p,
|
||||||
|
IsMine=false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastProjectiles=projectiles;
|
lastProjectiles=projectiles;
|
||||||
|
Reference in New Issue
Block a user