83 lines
2.2 KiB
C#
83 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
namespace ServerBase;
|
|
|
|
public class EntityRecorder
|
|
{
|
|
private readonly EntityBase m_owner;
|
|
|
|
private readonly ConcurrentDictionary<object, NormalDeltaRecorder> m_normal_delta_recorders = new();
|
|
|
|
public EntityRecorder(EntityBase owner)
|
|
{
|
|
m_owner = owner;
|
|
}
|
|
|
|
public void applyDeltaCounter(object entityDeltaType, double deltaCount, double totalCount)
|
|
{
|
|
var add_recorder = delegate (object deltaType)
|
|
{
|
|
return new NormalDeltaRecorder(entityDeltaType, deltaCount, totalCount);
|
|
};
|
|
|
|
var update_recorder = delegate (object key, NormalDeltaRecorder value)
|
|
{
|
|
value.incDeltaCount(deltaCount);
|
|
value.setTotalCount(totalCount);
|
|
|
|
return value;
|
|
};
|
|
|
|
m_normal_delta_recorders.AddOrUpdate(entityDeltaType, add_recorder, update_recorder);
|
|
}
|
|
|
|
public NormalDeltaRecorder? findDeltaCounter(object deltaType)
|
|
{
|
|
m_normal_delta_recorders.TryGetValue(deltaType, out var found_delta_counter);
|
|
return found_delta_counter;
|
|
}
|
|
|
|
public void reset()
|
|
{
|
|
m_normal_delta_recorders.Clear();
|
|
}
|
|
}
|
|
|
|
public class NormalDeltaRecorder
|
|
{
|
|
private object m_entity_delta_type;
|
|
|
|
private double m_delta_count;
|
|
private double m_total_count;
|
|
|
|
public NormalDeltaRecorder(object deltaType, double deltaCount, double totalCount)
|
|
{
|
|
m_entity_delta_type = deltaType;
|
|
m_delta_count = deltaCount;
|
|
m_total_count = totalCount;
|
|
}
|
|
|
|
public void setDeltaCount(double deltaCount) => m_delta_count = deltaCount;
|
|
public double getDeltaCount() => m_delta_count;
|
|
|
|
public void incDeltaCount(double deltaCount) => m_delta_count += deltaCount;
|
|
public void decDeltaCount(double deltaCount) => m_delta_count -= deltaCount;
|
|
|
|
public void setTotalCount(double totalCount) => m_total_count = totalCount;
|
|
public double getTotalCount() => m_total_count;
|
|
|
|
|
|
|
|
public object getEntityDeltaType() => m_entity_delta_type;
|
|
}
|