You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
303 lines
8.4 KiB
303 lines
8.4 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
namespace DisComputer
|
|
{
|
|
public class IIICommandUnitSet : MonoBehaviour
|
|
{
|
|
|
|
|
|
[Header("指令集配置表")]
|
|
public List<IIICmdConfig> cmd_configs;
|
|
|
|
//已选配置表
|
|
private List<IIICmdConfig> cmd_sel_configs;
|
|
|
|
|
|
[Header("联合指令集")]
|
|
public List<ComboomItem> comboomItems;
|
|
|
|
[Header("下一个指令单元")]
|
|
public IIIRegUnit nextUnit;
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动命令
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
public void Command()
|
|
{
|
|
CommandData data = VonNeumann.data;
|
|
RewindRunedCommandArrow();
|
|
ComboomItem item = comboomItems[VonNeumann.CommandIndex];
|
|
item.CommandAct(data, () =>
|
|
{
|
|
nextUnit.Active();
|
|
});
|
|
|
|
}
|
|
|
|
public void Command(Action finish)
|
|
{
|
|
CommandData data = VonNeumann.data;
|
|
RewindRunedCommandArrow();
|
|
ComboomItem item = comboomItems[VonNeumann.CommandIndex];
|
|
item.ClearMask();
|
|
item.CommandAct(data, () =>
|
|
{
|
|
nextUnit.Active();
|
|
finish?.Invoke();
|
|
});
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 启动模糊指令
|
|
/// </summary>
|
|
public void ShakeCommands(Action finish = null)
|
|
{
|
|
StartCoroutine(ProressShakeMask(finish));
|
|
|
|
}
|
|
|
|
IEnumerator ProressShakeMask(Action finish = null)
|
|
{
|
|
for (int i = 0; i < VonNeumann.data.ActCommandList.Count; i++)
|
|
{
|
|
comboomItems[i].MaskShake();
|
|
comboomItems[i].SetCommandVal(VonNeumann.data.ActCommandList[i]);
|
|
yield return new WaitForSeconds(0.2f);
|
|
}
|
|
|
|
finish?.Invoke();
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 重置已使用过箭头
|
|
/// </summary>
|
|
void RewindRunedCommandArrow()
|
|
{
|
|
for (int i = 0; i < comboomItems.Count; i++)
|
|
{
|
|
if (i <= VonNeumann.CommandIndex)
|
|
{
|
|
comboomItems[i].progressArrow.SetArrowZero();
|
|
;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 复原
|
|
/// </summary>
|
|
public void RewindCommand()
|
|
{
|
|
foreach (var item in comboomItems)
|
|
{
|
|
item.Rewind(0);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 设置指令
|
|
/// </summary>
|
|
public void SetCmdConfigs()
|
|
{
|
|
cmd_sel_configs = new List<IIICmdConfig>();
|
|
string cmd_str = VonNeumann.data.command.ToString().ToLower();
|
|
|
|
List<IIICmdConfig> temp_configs = new List<IIICmdConfig>();
|
|
|
|
List<IIICmdConfig> cmd_list = new List<IIICmdConfig>();
|
|
|
|
IIICmdConfig select_config = null;
|
|
int select_index = 0;
|
|
for (int i = 0;i< cmd_configs.Count; i++)
|
|
{
|
|
if (cmd_configs[i].code_str.Contains(cmd_str))
|
|
{
|
|
select_config = cmd_configs[i];
|
|
select_index = i;
|
|
|
|
}else
|
|
{
|
|
temp_configs.Add(cmd_configs[i]);
|
|
}
|
|
}
|
|
|
|
List<int> randomList = LzFramework.FuncTools.CreateRanArrVal(temp_configs.Count, 3);
|
|
|
|
for(int j = 0;j < randomList.Count; j++)
|
|
{
|
|
cmd_list.Add(temp_configs[randomList[j]]);
|
|
}
|
|
|
|
cmd_list.Add(select_config);
|
|
|
|
List<int> temp_Temp_list = LzFramework.FuncTools.CreateRanArrVal(4, 4);
|
|
|
|
|
|
int start_add = UnityEngine.Random.Range(0,10);
|
|
for(int i = 0;i< temp_Temp_list.Count; i++)
|
|
{
|
|
IIICmdConfig iIICmd = cmd_list[temp_Temp_list[i]];
|
|
iIICmd.add_str = IIINonNeumannControll.Instance.GetMemAdd(start_add.ToString());
|
|
cmd_sel_configs.Add(iIICmd);
|
|
comboomItems[i].AddressAct(false,iIICmd.add_str);
|
|
comboomItems[i].SetCommandVal(iIICmd.code_str);
|
|
if (iIICmd == select_config)
|
|
{
|
|
Debug.LogFormat("当前指令提示内容为{0} {1}", iIICmd.add_str,iIICmd.code_str);
|
|
VonNeumann.cmdTipInfo = iIICmd.add_str + " " + iIICmd.code_str;
|
|
VonNeumann.curpRegIndex = start_add;
|
|
|
|
MatchVonNeuData.pRegIndex = start_add;
|
|
|
|
VonNeumann.CommandIndex = i;
|
|
comboomItems[i].SetCommandVal(iIICmd.code_str,true);
|
|
comboomItems[i].AddressAct(true,iIICmd.add_str);
|
|
VonNeumann.cmdConfig = iIICmd;
|
|
|
|
//解析要匹对数据
|
|
AnalysisAnswer(iIICmd);
|
|
}
|
|
|
|
|
|
start_add++;
|
|
Debug.LogFormat(">>>>>>>>>>>>> cmd lisd add {0} cmd name {1}", iIICmd.add_str, iIICmd.code_str);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取跳转指令下标
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int GetMatchCmdIndex()
|
|
{
|
|
for(int i = 0;i< cmd_sel_configs.Count; i++)
|
|
{
|
|
if(VonNeumann.data.mem == cmd_sel_configs[i].add_str)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return 4;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 解析匹配数据
|
|
/// </summary>
|
|
void AnalysisAnswer(IIICmdConfig config)
|
|
{
|
|
MatchVonNeuData.pRegIndex = int.Parse(config.add_str);
|
|
|
|
string[] tempArr = config.code_str.Split(' ');
|
|
|
|
if (VonNeumann.data.command == CommandType.Mov2)
|
|
{
|
|
MatchVonNeuData.mem = int.Parse(tempArr[1]);
|
|
MatchVonNeuData.rexIndex = int.Parse(tempArr[2]);
|
|
|
|
if (MatchVonNeuData.mem == 100)
|
|
{
|
|
VonNeumann.movMemIndex = 0;
|
|
}
|
|
else
|
|
{
|
|
VonNeumann.movMemIndex = 1;
|
|
}
|
|
|
|
|
|
} else if (VonNeumann.data.command == CommandType.Mov1)
|
|
{
|
|
MatchVonNeuData.rexIndex = int.Parse(tempArr[1]);
|
|
MatchVonNeuData.mem = int.Parse(tempArr[2]);
|
|
|
|
if (MatchVonNeuData.mem == 100)
|
|
{
|
|
VonNeumann.movMemIndex = 0;
|
|
}
|
|
else
|
|
{
|
|
VonNeumann.movMemIndex = 1;
|
|
}
|
|
}
|
|
else if(VonNeumann.data.command == CommandType.Mov3)
|
|
{
|
|
MatchVonNeuData.rexIndex = int.Parse(tempArr[1]);
|
|
}
|
|
else if (VonNeumann.data.command == CommandType.Add ||
|
|
VonNeumann.data.command == CommandType.Div ||
|
|
VonNeumann.data.command == CommandType.Mul ||
|
|
VonNeumann.data.command == CommandType.Sub ||
|
|
VonNeumann.data.command == CommandType.Operator)
|
|
{
|
|
MatchVonNeuData.op01Index = int.Parse(tempArr[1]);
|
|
MatchVonNeuData.op02Index = int.Parse(tempArr[2]);
|
|
}
|
|
else if(VonNeumann.data.command == CommandType.In ||
|
|
VonNeumann.data.command == CommandType.Out)
|
|
{
|
|
MatchVonNeuData.rexIndex = int.Parse(tempArr[1]);
|
|
}
|
|
else if(VonNeumann.data.command == CommandType.Jz)
|
|
{
|
|
MatchVonNeuData.rexIndex = int.Parse(tempArr[1]);
|
|
MatchVonNeuData.mem = int.Parse(tempArr[2]);
|
|
}
|
|
else if(VonNeumann.data.command == CommandType.Jmp)
|
|
{
|
|
MatchVonNeuData.mem = int.Parse(tempArr[1]);
|
|
}
|
|
|
|
|
|
|
|
Debug.LogFormat("解析完成后数据如下 pRegIndex {0} rexIndex {1} mem {2} op01Index {3} op02Index {4}"
|
|
, MatchVonNeuData.pRegIndex, MatchVonNeuData.rexIndex, MatchVonNeuData.mem, MatchVonNeuData.op01Index, MatchVonNeuData.op02Index);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
[Serializable]
|
|
public class IIICmdConfig
|
|
{
|
|
public string add_str;
|
|
|
|
public string code_str;
|
|
}
|
|
}
|
|
|