using System;
using JNGame.Sync.Frame;
using UnityEngine;
namespace JNGame.Sync.State
{
///
/// 状态同步 [服务器]
/// 服务器负责逻辑层执行并且推送信息到数据层
/// 注:服务器可以有视图层 一般用于debug 发布后没必要有视图层
///
public class JNSStateServerService : JNSyncDefaultService
{
//累计待处理时间
protected int dtTime;
//服务器每帧时间
public override int DeltaTime => 1000 / 15;
//是否开始
private bool _isStart = false;
public bool IsStart => _isStart;
public override bool IsStartGame => _isStart;
public override void Initialize()
{
base.Initialize();
_isStart = true;
}
public override void Execute()
{
#if (!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR)
if (paused) return;
#endif
if (!IsStart) return;
base.Execute();
dtTime += TickTime;
if (DeltaTime <= dtTime)
{
dtTime -= DeltaTime;
//执行逻辑
OnRunSimulate();
}
}
///
/// 运行逻辑
///
protected virtual void OnRunSimulate()
{
Simulate();
}
}
}