void procTransfer() { // generator output for (int i = 0; i < generic[0].tempGenericUpdateOps.Length; ++i) { if (generic[0].tempGenericUpdateOps[i] != 0) { GeneratorData gen = generators[i]; CanTakeState cts = headStates[gen.tailArrayIdx]; // check if this generator has space at its end? if (tubes[cts.tailIdx].hasSpace(gen.itemId)) { tubes[cts.tailIdx].push(gen.itemId); // consume a unit of resource. //Debug.LogFormat("generator {0} makes one at {1}", i, elapsedTime); gen.pop(); generators[i] = gen; } else { Debug.LogFormat("generator {0} got blocked.", i); gen.block(); generators[i] = gen; } } } // tubes output for (int i = 0; i < arrayLength; ++i) { if (updateTubesJob.outputOps[i] != 0) { CanTakeState cts = headStates[tubes[i].tailArrayIdx]; TubeData srcTube = tubes[i]; if (cts.tailType == CTS_Tube) // tube { if (tubes[cts.tailIdx].hasSpace(srcTube.itemId)) { srcTube.pop(); tubes[cts.tailIdx].push(srcTube.itemId); Debug.LogFormat("{0} Tube {1} pops into {2}.", elapsedTime, i, cts.tailIdx); cts = headStates[srcTube.headArrayIdx]; cts.invokeUnblock(); } else { Debug.LogFormat("{0} Tube {1} blocked", elapsedTime, i); srcTube.block(); } } else if (cts.tailType == CTS_Converter) // converter { ConverterData conv = converters[cts.tailIdx]; if (conv.hasSpace(srcTube.itemId)) { srcTube.pop(); if (converters[cts.tailIdx].push(srcTube.itemId)) { Debug.LogFormat("{0} Tube {1} pops into converter {2}.", elapsedTime, i, cts.tailIdx); cts = headStates[srcTube.tailArrayIdx]; cts.invokeUnblock(); } } else { srcTube.block(); Debug.LogFormat("{0} Tube {1} got blocked by converter {2}.", elapsedTime, i, cts.tailIdx); } //Debug.LogFormat("{0} converter @ {1}, {2}", elapsedTime, conv.srcCurrent[0], conv.srcCurrent[1]); } else if (cts.tailType == CTS_Consumer) // consumer { ConsumerData consData = consumers[cts.tailIdx]; consData.attemptToTake(srcTube.itemId); srcTube.pop(); consumers[cts.tailIdx] = consData; Debug.LogFormat("{0} Tube {1} pops into consumer {2}.", elapsedTime, i, cts.tailIdx); cts = headStates[srcTube.headArrayIdx]; cts.invokeUnblock(); } tubes[i] = srcTube; } } // converter output for (int i = 0; i < generic[1].tempGenericUpdateOps.Length; ++i) { if (generic[1].tempGenericUpdateOps[i] != 0) { CanTakeState cts = headStates[converters[i].tailArrayIdx]; ConverterData conv = converters[i]; // check if this converter has space at its end? if (cts.tailType == CTS_Tube) // the end entity of this converter is a tube { if (tubes[cts.tailIdx].hasSpace(conv.targetId)) { Debug.Log("converter out!"); tubes[cts.tailIdx].push(conv.targetId); //headStates[conv.headArrayIdx].invokeUnblock(); Debug.LogFormat("{0} converter {1} pops into tube {2}.", elapsedTime, i, cts.tailIdx); } else { //head_cts Debug.LogFormat("{0} converter {1} got blocked by tube {2}.", elapsedTime, i, cts.tailIdx); } } else if (cts.tailType == CTS_Converter) // converter { Debug.LogFormat("{0} converter {1} pops into converter {2}.", elapsedTime, i, cts.tailIdx); } if (conv.allMet()) { converters[i].startUpdate(); headStates[conv.headArrayIdx].invokeUnblock(); } } } sampler.End(); }
void debugTube() { // generator for (int i = 0; i < generic[0].tempGenericUpdateOps.Length; ++i) { if (generic[0].tempGenericUpdateOps[i] != 0) { GeneratorData gen = generators[i]; CanTakeState cts = headStates[gen.tailArrayIdx]; // check if this generator has space at its end? if (tubes[cts.tailIdx].hasSpace(gen.itemId)) { tubes[cts.tailIdx].push(gen.itemId); // consume a unit of resource. gen.pop(); generators[i] = gen; } else { gen.block(); } } } for (int i = 0; i < arrayLength; ++i) { int op = updateTubesJob.outputOps[i]; if (op != 0) { TubeData srcTube = tubes[i]; if (endState_Open) { srcTube.pop(); CanTakeState cts = headStates[srcTube.headArrayIdx]; cts.invokeUnblock(); } else { srcTube.block(); } //CanTakeState cts = endStates[tubes[i].idxInEndStateArray]; //if (cts.type == 0) // tube //{ // if (tubes[cts.idx].hasSpace(srcTube.itemId)) { // srcTube.pop(); // tubes[cts.idx].push(srcTube.itemId); // // consume a unit of resource. // } // else { // srcTube.saturate(); // } //} //else if (cts.type == 1) // converter //{ // ConverterData conv = converters[cts.idx]; // if (conv.hasSpace(srcTube.itemId)) { // srcTube.pop(); // conv.push(srcTube.itemId); // converters[cts.idx] = conv; // } // else { // srcTube.saturate(); // } //} //else if (cts.type == 2) { // consumer // ConsumerData consData = consumers[cts.idx]; // consData.attemptToTake(srcTube.itemId); // srcTube.pop(); // consumers[cts.idx] = consData; //} tubes[i] = srcTube; } } if (prevEndState0 != endState_Open) { if (endState_Open) { tubes[0].unblock(); CanTakeState cts = headStates[tubes[0].headArrayIdx]; cts.invokeUnblock(); } prevEndState0 = endState_Open; } }