| 2780 | } |
| 2781 | |
| 2782 | void cHardwareExperimental::PromoterTerminate(cAvidaContext& ctx) |
| 2783 | { |
| 2784 | // Optionally, |
| 2785 | // Reset the thread. |
| 2786 | if (m_world->GetConfig().TERMINATION_RESETS.Get()) |
| 2787 | { |
| 2788 | m_threads[m_cur_thread].Reset(this, m_threads[m_cur_thread].GetID()); |
| 2789 | |
| 2790 | //Setting this makes it harder to do things. You have to be modular. |
| 2791 | m_organism->GetOrgInterface().ResetInputs(ctx); // Re-randomize the inputs this organism sees |
| 2792 | m_organism->ClearInput(); // Also clear their input buffers, or they can still claim |
| 2793 | // rewards for numbers no longer in their environment! |
| 2794 | } |
| 2795 | |
| 2796 | // Reset our count |
| 2797 | m_threads[m_cur_thread].ResetPromoterInstExecuted(); |
| 2798 | m_advance_ip = false; |
| 2799 | const int promoter_reg_used = rDX; // register to put chosen promoter code in, default to DX |
| 2800 | |
| 2801 | |
| 2802 | // @DMB - should the promoter index and offset be stored in cLocalThread to allow multiple threads? |
| 2803 | |
| 2804 | // Search for an active promoter |
| 2805 | int start_offset = m_promoter_offset; |
| 2806 | int start_index = m_promoter_index; |
| 2807 | |
| 2808 | |
| 2809 | bool no_promoter_found = true; |
| 2810 | if (m_promoters.GetSize() > 0) { |
| 2811 | const int promoter_exe_length = m_world->GetConfig().PROMOTER_EXE_LENGTH.Get(); |
| 2812 | const int promoter_code_size = m_world->GetConfig().PROMOTER_CODE_SIZE.Get(); |
| 2813 | const int promoter_exe_threshold = m_world->GetConfig().PROMOTER_EXE_THRESHOLD.Get(); |
| 2814 | |
| 2815 | while (true) { |
| 2816 | // If the next promoter is active, then break out |
| 2817 | |
| 2818 | // Move promoter index, rolling over if necessary |
| 2819 | m_promoter_index++; |
| 2820 | |
| 2821 | if (m_promoter_index == m_promoters.GetSize()) { |
| 2822 | m_promoter_index = 0; |
| 2823 | |
| 2824 | // Move offset, rolling over when there are not enough bits before we would have to wrap around left |
| 2825 | m_promoter_offset += promoter_exe_length; |
| 2826 | if (m_promoter_offset + promoter_exe_length > promoter_code_size) m_promoter_offset = 0; |
| 2827 | } |
| 2828 | |
| 2829 | |
| 2830 | int count = 0; |
| 2831 | unsigned int code = m_promoters[m_promoter_index].GetRegulatedBitCode(); |
| 2832 | for (int i = 0; i < promoter_exe_length; i++) { |
| 2833 | // @DMB - changed the following to avoid integer division. We should only ever need to circle around once |
| 2834 | //int offset = (m_promoter_offset + i) % promoter_code_size; |
| 2835 | int offset = m_promoter_offset + i; |
| 2836 | if (offset >= promoter_code_size) offset -= promoter_code_size; |
| 2837 | int state = code >> offset; |
| 2838 | count += (state & 1); |
| 2839 | } |
nothing calls this directly
no test coverage detected