Esempio n. 1
0
__EXPORT void stm32_spi2select(FAR struct spi_dev_s *dev, enum spi_dev_e devid, bool selected)
{
	/* SPI select is active low, so write !selected to select the device */

	int sel = (int) devid;

	if (devid == SPIDEV_FLASH) {
		sel = PX4_SPIDEV_MEMORY;
	}

	ASSERT(PX4_SPI_BUS_ID(sel) == PX4_SPI_BUS_MEMORY);

	/* Making sure the other peripherals are not selected */

	for (int cs = 0;  arraySize(spi2selects_gpio) > 1 && cs < arraySize(spi2selects_gpio); cs++) {
		if (spi2selects_gpio[cs] != 0) {
			stm32_gpiowrite(spi2selects_gpio[cs], 1);
		}
	}

	uint32_t gpio = spi2selects_gpio[PX4_SPI_DEV_ID(sel)];

	if (gpio) {
		stm32_gpiowrite(gpio, !selected);
	}
}
Esempio n. 2
0
void code2binary(string code, string binary) {
  char d[10], comp[100], j[10];
  string dcode, ccode, jcode;
  if (code[0]=='@') { // A 指令: @number || @symbol
    int address;
    int match = sscanf(code, "@%d", &address);
    if (match == 1)
      decimal2binary(address, binary);
    else {
      char symbol[100];
      match = sscanf(code, "@%s", symbol);
      int* addrPtr = lookup(symbol, symTable, symTop);
      assert(addrPtr != NULL);
      address = *addrPtr;
      decimal2binary(address, binary);
    }
  } else { // C 指令: d = comp;j
    if (strchr(code, '=') != NULL) {
      sscanf(code, "%[^=]=%s", d, comp);
      dcode = lookup(d, dMap, arraySize(dMap));
      ccode = lookup(comp, cMap, arraySize(cMap));
      sprintf(binary, "111%s%s000", ccode, dcode);
    } else {
      sscanf(code, "%[^;];%s", comp, j);
      ccode = lookup(comp, cMap, arraySize(cMap));
      jcode = lookup(j, jMap, arraySize(jMap));
      sprintf(binary, "111%s000%s", ccode, jcode);      
    }
  }
}
Esempio n. 3
0
void log_print_(int level, int line, const char *func, const char *file, const char *msg, ...)
{
       char _buffer[MAX_DEBUG_MESSAGE_LENGTH];
        static char * levels[] = {
                "",
                "LOG  ",
                "DEBUG",
                "WARN ",
                "ERROR",
                "PANIC",
        };
        va_list args;
        va_start(args, msg);
        file = file ? strrchr(file,'/') + 1 : "";
        int trunc = snprintf(_buffer, arraySize(_buffer), "%010lu:<%s> %s %s(%d):", GetSystem1MsTick(), levels[level], func, file, line);
        if (debug_output_)
        {
            debug_output_(_buffer);
          if (trunc > arraySize(_buffer))
          {
              debug_output_("...");
          }
        }
        trunc = vsnprintf(_buffer,arraySize(_buffer), msg, args);
        if (debug_output_)
        {
          debug_output_(_buffer);
          if (trunc > arraySize(_buffer))
          {
              debug_output_("...");
          }
          debug_output_("\r\n");
        }
}
Esempio n. 4
0
__EXPORT void board_spi_reset(int ms)
{
	/* disable SPI bus */
	for (int cs = 0;  arraySize(spi1selects_gpio) > 1 && cs < arraySize(spi1selects_gpio); cs++) {
		if (spi1selects_gpio[cs] != 0) {
			stm32_configgpio(_PIN_OFF(spi1selects_gpio[cs]));
		}
	}

	stm32_configgpio(GPIO_SPI1_SCK_OFF);
	stm32_configgpio(GPIO_SPI1_MISO_OFF);
	stm32_configgpio(GPIO_SPI1_MOSI_OFF);


#if BOARD_USE_DRDY
	stm32_configgpio(GPIO_DRDY_OFF_ICM20689_DRDY1);
	stm32_configgpio(GPIO_DRDY_OFF_BMI055_DRDY2_GYRO);
	stm32_configgpio(GPIO_DRDY_OFF_BMI055_DRDY3_ACC);
	stm32_configgpio(GPIO_DRDY_OFF_ICM20602_DRDY4);
	stm32_configgpio(GPIO_DRDY_OFF_BMI055_DRDY5_GYRO);
	stm32_configgpio(GPIO_DRDY_OFF_BMI055_DRDY6_ACC);
#endif
	/* set the sensor rail off */
	stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 0);

	/* wait for the sensor rail to reach GND */
	usleep(ms * 1000);
	warnx("reset done, %d ms", ms);

	/* re-enable power */

	/* switch the sensor rail back on */
	stm32_gpiowrite(GPIO_VDD_3V3_SENSORS_EN, 1);

	/* wait a bit before starting SPI, different times didn't influence results */
	usleep(100);

	/* reconfigure the SPI pins */
	for (int cs = 0;  arraySize(spi1selects_gpio) > 1 && cs < arraySize(spi1selects_gpio); cs++) {
		if (spi1selects_gpio[cs] != 0) {
			stm32_configgpio(spi1selects_gpio[cs]);
		}
	}

	stm32_configgpio(GPIO_SPI1_SCK);
	stm32_configgpio(GPIO_SPI1_MISO);
	stm32_configgpio(GPIO_SPI1_MOSI);

#if BOARD_USE_DRDY
	stm32_configgpio(GPIO_ICM20689_DRDY1);
	stm32_configgpio(GPIO_BMI055_DRDY2_GYRO);
	stm32_configgpio(GPIO_BMI055_DRDY3_ACC);
	stm32_configgpio(GPIO_ICM20602_DRDY4);
	stm32_configgpio(GPIO_BMI055_DRDY5_GYRO);
	stm32_configgpio(GPIO_BMI055_DRDY6_ACC);
#endif

}
Esempio n. 5
0
void CDraw::drawKeySignature(int key)
{
    const int sharpLookUpRight[] = { 4, 1, 5, 2,-1, 3, 0};
    const int sharpLookUpLeft[]  = { 2,-1, 3, 0,-3, 1,-2};
    const int flatLookUpRight[]  = { 0, 3,-1, 2,-2, 1,-3};
    const int flatLookUpLeft[]   = {-2, 1,-3, 0,-4,-1,-5};
    const int gapX = 11;
    CStavePos pos;
    size_t i;

    if (key == NOT_USED)
        return;

    i = 0;
    while (key != 0 )
    {
        if (key > 0)
        {
            if (i < arraySize(sharpLookUpRight))
            {
                drColour ((m_displayHand != PB_PART_left) ? Cfg::noteColour() : Cfg::noteColourDim());
                pos = CStavePos(PB_PART_right, sharpLookUpRight[i]);
                drawSymbol( CSymbol(PB_SYMBOL_sharp, pos), Cfg::keySignatureX() + gapX*i );
            }
            if (i < arraySize(sharpLookUpLeft))
            {
                drColour ((m_displayHand != PB_PART_right) ? Cfg::noteColour() : Cfg::noteColourDim());
                pos = CStavePos(PB_PART_left, sharpLookUpLeft[i]);
                drawSymbol( CSymbol(PB_SYMBOL_sharp, pos), Cfg::keySignatureX() + gapX*i );
            }
            key--;
        }
        else
        {
            if (i < arraySize(flatLookUpRight))
            {
                drColour ((m_displayHand != PB_PART_left) ? Cfg::noteColour() : Cfg::noteColourDim());
                pos = CStavePos(PB_PART_right, flatLookUpRight[i]);
                drawSymbol( CSymbol(PB_SYMBOL_flat, pos), Cfg::keySignatureX() + gapX*i );
            }
            if (i < arraySize(flatLookUpLeft))
            {
                drColour ((m_displayHand != PB_PART_right) ? Cfg::noteColour() : Cfg::noteColourDim());
                pos = CStavePos(PB_PART_left, flatLookUpLeft[i]);
                drawSymbol( CSymbol(PB_SYMBOL_flat, pos), Cfg::keySignatureX() + gapX*i );
            }

            key++;
        }
        i++;
    }
}
Esempio n. 6
0
//Konwersja tablicy charów na tablicę intów
int *charArrayToIntArray(char *array)
{

	int *intArray = malloc(arraySize(array) * sizeof(int));

	int temp = 0;

	for (int i = 0; i <= arraySize(array) - 1; i++)
	{
		intArray[i] = array[i] - 48;
		temp++;
	}

	return intArray;
}
Esempio n. 7
0
/*
 * A helper function that changes the privilages for users who are lower in the hierckiee and have a higher permission
 * example: TA - RW, Student RW => change TA to R will result in Student also becoming R; but not the Instructor
 *
 */
void checkChangesForInstructor(int** array, char* temp_user_group, int num_users, SYSUSER *tempUser, int temp_group_num, int num_files, char* temp_file_name, SYSFILE *tempFile, int num_perm, SYSPERM *tempPerm, int temp_user_perm){

    int i,x,j,k;
    
    if(strcmp(temp_user_group, "Instructors") == 0){
        for (i = 0; i < num_users; i++){
            if(strcmp("TAs", tempUser[i].group) == 0){
                for (j=0; j < num_files; j++){
                    if (strcmp(temp_file_name, tempFile[j].label) == 0){
                        for(k=0; k < num_perm; k++){
                            if(tempPerm[k].permission > temp_user_perm){
                                array[i][j] = temp_user_perm;
                                for(x=0; x<= arraySize(tempUser[i].group_num)+1; x++){
                                    checkChangesForTA(array, tempUser[i].group, num_users, tempUser, tempUser[i].group_num[x], num_files, tempFile[j].label, tempFile, num_perm, tempPerm, temp_user_perm);

                                }
                            }
                        }
                    }
                }
            }
        }
    }else
        checkChangesForTA(array, temp_user_group, num_users, tempUser, temp_group_num, num_files, temp_file_name, tempFile, num_perm, tempPerm, temp_user_perm);

}
Esempio n. 8
0
// Write characters
void display_text(char text[], int row)
{
	int size = arraySize(text);
	if(size > 16)
	{
		for(int index = 1; index < 3; index++)
		{
			lcd_setLine(index);
			for (int i = 0; i < 16; i++)
			{
				lcd_writeChar((unsigned char)text[i]);
			}
		}
	}
	else
	{
		lcd_setLine(row);
		for (int i = 0; i < 16; i++) {
			lcd_writeChar(text[i]);
		}
	}




}
Esempio n. 9
0
template <typename T> void Mpris::getEnumStringsAndSize(const char ***strings, int *size)
{
    if (is_same<T, Mpris::LoopStatus>::value) {
        *strings = loopStatusStrings;
        *size = arraySize(loopStatusStrings);
    } else if (is_same<T, Mpris::PlaybackStatus>::value) {
        *strings = playbackStatusStrings;
        *size = arraySize(playbackStatusStrings);
    } else if (is_same<T, Mpris::Metadata>::value) {
        *strings = metadataStrings;
        *size = arraySize(metadataStrings);
    } else {
        *strings = 0;
        *size = 0;
    }
}
Esempio n. 10
0
void timer_free(bl_timer_id id)
{
	DEBUGASSERT(id >= 0 && id < arraySize(timers));
	irqstate_t s = enter_critical_section();
	memset(&timers[id], 0, sizeof(timers[id]));
	leave_critical_section(s);
}
/**
 * @brief  The handler for Interrupt that is generated when CC3000 brings the
 IRQ line low.
 * @param  None
 * @retval None
 */
void SPI_EXTI_IntHandler(void)
{
	//Pending is cleared in first level of ISR handler
	if (!tSLInformation.ReadWlanInterruptPin())
	{
	    switch(sSpiInformation.ulSpiState)
	    {
	    case eSPI_STATE_POWERUP:
	        sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED;
	      break;
            case eSPI_STATE_IDLE:
                if (try_acquire_spi_bus(BUS_OWNER_CC3000)) {
                    SetState(eSPI_STATE_READ_IRQ, eAssert);
                    SpiIO(eRead, sSpiInformation.pRxPacket, arraySize(spi_readCommand), FALSE);
                } else {
                    SetState(eSPI_STATE_READ_PREP_IRQ, eNone);
                    WARN("CC3000 cannot lock bus - scheduling later (owner=%d)", current_bus_owner());
                }
		break;
            case eSPI_STATE_WRITE_WAIT_IRQ:
              sSpiInformation.ulSpiState = eSPI_STATE_WRITE_PROCEED;
              break;
            default:
              break;
	    }
	}
}
Esempio n. 12
0
static int format_fault_file_name(struct timespec *ts, char *buffer, unsigned int maxsz)
{
	char fmtbuff[ TIME_FMT_LEN + 1];
	int ret = -EINVAL;

	if (buffer) {

		ret = -ENOMEM;
		unsigned int plen = LOG_PATH_BASE_LEN;

		if (maxsz >= LOG_PATH_LEN) {
			strncpy(buffer, LOG_PATH_BASE, plen);
			maxsz -= plen;
			int rv = format_fault_time(TIME_FMT, ts, fmtbuff, arraySize(fmtbuff));

			if (rv == OK) {
				int n = snprintf(&buffer[plen], maxsz , LOG_NAME_FMT, fmtbuff);

				if (n == (int) LOG_NAME_LEN + TIME_FMT_LEN) {
					ret = OK;
				}
			}
		}
	}

	return ret;
}
Esempio n. 13
0
	void Door::changeState(DoorState target) {
		DoorState result = m_state;

		for(int n = 0; n < arraySize(s_transitions); n++)
			if(s_transitions[n].current == m_state && s_transitions[n].target == target) {
				result = s_transitions[n].result;
				break;
			}
		if(result == m_state)
			return;

		FBox bbox = computeBBox(result);
		bbox.min += float3(1.1f, 0.1f, 1.1f);
		bbox.max -= float3(1.1f, 0.1f, 1.1f);

		bool is_colliding = (bool)findAny(bbox + pos(), {Flags::entity | Flags::colliding, ref()});

		if(is_colliding && classId() == DoorClassId::rotating && m_state == DoorState::closed && target == DoorState::opened_in) {
			target = DoorState::opened_out;
			result = DoorState::opening_out;
			bbox = computeBBox(result);
			is_colliding = (bool)findAny(bbox + pos(), {Flags::entity | Flags::colliding, ref()});
		}
		if(!is_colliding) {
			m_bbox = bbox;
			m_state = result;
			m_update_anim = true;
		}
	}
Esempio n. 14
0
KOKKOS_INLINE_FUNCTION index_t
BasicTensor<T, Order>::index (Indices... indices) const {
  // Bounds check in debug mode
  index_t ret = detail::power_series(dim_, indices...);
  assert((ret >= 0) && (ret < arraySize()));
  return ret;
}
Esempio n. 15
0
int
led_pwm_servo_init(void)
{
	/* do basic timer initialisation first */
	for (unsigned i = 0; i < arraySize(led_pwm_timers); i++) {
		io_timer_init_timer(i);
	}

	/* now init channels */
	for (unsigned i = 0; i < arraySize(led_pwm_channels); i++) {
		led_pwm_channel_init(i);
	}

	led_pwm_servo_arm(true);
	return OK;
}
Esempio n. 16
0
__EXPORT void led_init(void)
{
	/* Configure LED1-2 GPIOs for output */
	for (size_t l = 0; l < arraySize(g_ledmap); l++) {
		stm32_configgpio(g_ledmap[l]);
	}
}
Esempio n. 17
0
void CameraInterfaceGPIO::setup()
{
	for (unsigned i = 0; i < arraySize(_pins); i++) {
		px4_arch_configgpio(_gpios[_pins[i]]);
		px4_arch_gpiowrite(_gpios[_pins[i]], !_polarity);
	}
}
Esempio n. 18
0
void CrazyhouseBoard::generateMovesForPiece(QVarLengthArray<Move>& moves,
					    int pieceType,
					    int square) const
{
	// Generate drops
	if (square == 0)
	{
		const int size = arraySize();
		const int maxRank = height() - 2;
		for (int i = 0; i < size; i++)
		{
			Piece tmp = pieceAt(i);
			if (!tmp.isEmpty())
				continue;
			if (pieceType == Pawn)
			{
				Square sq(chessSquare(i));
				if (sq.rank() < 1 || sq.rank() > maxRank)
					continue;
			}

			moves.append(Move(0, i, pieceType));
		}
	}
	else
		WesternBoard::generateMovesForPiece(moves, pieceType, square);
}
Esempio n. 19
0
void CPiano::addSavedChord(CMidiEvent midiNote, CChord chord)
{
    int key = midiNote.note();

    for (unsigned int i = 0; i < arraySize(m_savedChordLookUp); i++)
    {
        if (midiNote.type() == MIDI_NOTE_ON)
        {
            if (m_savedChordLookUp[i].pitchKey == 0 )
            {
                m_savedChordLookUp[i].pitchKey = key;
                m_savedChordLookUp[i].savedNoteOffChord = chord;

                return;
            }
        }
        else if (midiNote.type() == MIDI_NOTE_OFF)
        {
            if (m_savedChordLookUp[i].pitchKey == key )
            {
                m_savedChordLookUp[i].pitchKey = 0;
                return;
            }
        }
    }
    m_savedChordLookUp[0].savedNoteOffChord = chord;
}
Esempio n. 20
0
void CPiano::addNoteNameItem(float posY, int pitch, int type)
{
    noteNameItem_t  noteNameItem;
    int i;

    if (m_noteNameListLength >= arraySize(m_noteNameList))
        return;

    noteNameItem.posY = noteNameItem.posYOriginal = posY;
    noteNameItem.type = type;
    noteNameItem.pitch = pitch;

    // Sort the entries low to high
    for (i = m_noteNameListLength - 1; i >= 0; i--)
    {
        if (m_noteNameList[i].pitch <= pitch)
            break;
        // move the previous entry up one position
        m_noteNameList[i+1] = m_noteNameList[i];
    }
    if (m_noteNameList[i].pitch == pitch)
        return; // ignore duplicates
    m_noteNameList[i+1] = noteNameItem;
    m_noteNameListLength++;
    spaceNoteNames();
}
Esempio n. 21
0
	void ThinkingEntity::handleOrder(EntityEvent event, const EntityEventParams &params) {
		if(!m_order)
			return;

		static ThinkingEntity::HandleFunc handlers[] = {
			&ThinkingEntity::handleOrderWrapper<IdleOrder>,
			&ThinkingEntity::handleOrderWrapper<LookAtOrder>,
			&ThinkingEntity::handleOrderWrapper<MoveOrder>,
			&ThinkingEntity::handleOrderWrapper<TrackOrder>,
			&ThinkingEntity::handleOrderWrapper<AttackOrder>,
			&ThinkingEntity::handleOrderWrapper<ChangeStanceOrder>,
			&ThinkingEntity::handleOrderWrapper<InteractOrder>,
			&ThinkingEntity::handleOrderWrapper<DropItemOrder>,
			&ThinkingEntity::handleOrderWrapper<EquipItemOrder>,
			&ThinkingEntity::handleOrderWrapper<UnequipItemOrder>,
			&ThinkingEntity::handleOrderWrapper<TransferItemOrder>,
			&ThinkingEntity::handleOrderWrapper<GetHitOrder>,
			&ThinkingEntity::handleOrderWrapper<DieOrder>
		};
		static_assert(arraySize(handlers) == count<OrderTypeId>(),
				      "Not all order classes are handled in ThinkingEntity::handleOrder");

		if(!m_order->isFinished())
			if(!(this->*handlers[(int)m_order->typeId()])(m_order.get(), event, params))
				m_order->finish();
	}
Esempio n. 22
0
	World::World(string map_name, Mode mode)
		:m_mode(mode), m_last_anim_frame_time(0.0), m_last_time(0.0), m_time_delta(0.0), m_current_time(0.0),
		m_anim_frame(0), m_tile_map(m_level.tile_map), m_entity_map(m_level.entity_map), m_replicator(nullptr) {

		ASSERT(!map_name.empty());
		string file_name = format("data/maps/%s", map_name.c_str());
		m_level.load(file_name.c_str());
		for(int n = 0; n < m_tile_map.size(); n++) {
			//TODO: leave them and use them
			if(m_tile_map[n].ptr->isInvisible())
				m_tile_map.remove(n);
		}

		for(int n = 0; n < m_entity_map.size(); n++) {
			auto &obj = m_entity_map[n];
			if(obj.ptr)
				obj.ptr->hook(this, n);
		}

		int agent_sizes[] = { 2, 3, 4, 7 };
		for(int n = 0; n < arraySize(agent_sizes); n++)
			m_navi_maps.emplace_back(agent_sizes[n]);

//		m_tile_map.printInfo();
		m_map_name = map_name;
		updateNaviMap(true);
	}
Esempio n. 23
0
void CameraInterface::get_pins()
{

	// Get parameter handle
	_p_pin = param_find("TRIG_PINS");

	int pin_list;
	param_get(_p_pin, &pin_list);

	// Set all pins as invalid
	for (unsigned i = 0; i < arraySize(_pins); i++) {
		_pins[i] = -1;
	}

	// Convert number to individual channels
	unsigned i = 0;
	int single_pin;

	while ((single_pin = pin_list % 10)) {

		_pins[i] = single_pin - 1;

		if (_pins[i] < 0) {
			_pins[i] = -1;
		}

		pin_list /= 10;
		i++;
	}

}
template <typename F> void for_all_pwm_pins(F callback)
{
	for (uint8_t i = 0; i<arraySize(pwm_pins); i++)
	{
		callback(pwm_pins[i]);
	}
}
Esempio n. 25
0
void sexyFillScreen(const ShaderState &ss, const View& view, uint color0, uint color1, float alpha)
{
    if (alpha < epsilon || (color0 == 0 && color1 == 0))
        return;

    glDepthMask(GL_FALSE);
    glDisable(GL_DEPTH_TEST);
    const float2 ws = 1.2f * view.sizePoints;
    const float2 ps = -0.1f * view.sizePoints;
    const float t = globals.renderTime / 20.f;
    const uint a = ALPHAF(alpha);

    // 1 2
    // 0 3
    const VertexPosColor v[] = {
        VertexPosColor(ps,  a|rgb2bgr(lerpXXX(color0, color1, unorm_sin(t)))),
        VertexPosColor(ps + justY(ws), a|rgb2bgr(lerpXXX(color0, color1, unorm_sin(3.f * t)))),
        VertexPosColor(ps + ws,        a|rgb2bgr(lerpXXX(color0, color1, unorm_sin(5.f * t)))),
        VertexPosColor(ps + justX(ws), a|rgb2bgr(lerpXXX(color0, color1, unorm_sin(7.f * t)))),
    };
    static const uint i[] = {0, 1, 2, 0, 2, 3};
    DrawElements(ShaderColorDither::instance(), ss, GL_TRIANGLES, v, i, arraySize(i));

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
}    
Esempio n. 26
0
static int  write_stack(bool inValid, int winsize, uint32_t wtopaddr,
			uint32_t topaddr, uint32_t spaddr, uint32_t botaddr,
			char *sp_name, char *buffer, int max, int infd, int outfd)
{
	char marker[30];
	stack_word_t stack[32];
	int ret = OK;

	int n = snprintf(buffer, max, "%s memory region, stack pointer lies %s stack\n",
			 sp_name, (inValid ? "outside of" : "within"));

	if (n != write(outfd, buffer, n)) {

		ret = -EIO;

	} else {

		while (winsize > 0 && ret == OK) {
			int chunk = read_stack(infd, stack, arraySize(stack));

			if (chunk <= 0) {
				ret = -EIO;

			} else {
				winsize -= chunk;

				for (int i = 0; i < chunk; i++) {
					if (wtopaddr == topaddr) {
						strncpy(marker, "<-- ", sizeof(marker));
						strncat(marker, sp_name, sizeof(marker));
						strncat(marker, " top", sizeof(marker));

					} else if (wtopaddr == spaddr) {
						strncpy(marker, "<-- ", sizeof(marker));
						strncat(marker, sp_name, sizeof(marker));

					} else if (wtopaddr == botaddr) {
						strncpy(marker, "<-- ", sizeof(marker));
						strncat(marker, sp_name, sizeof(marker));
						strncat(marker, " bottom", sizeof(marker));

					} else {
						marker[0] = '\0';
					}

					n = snprintf(buffer, max, "0x%08x 0x%08x%s\n", wtopaddr, stack[i], marker);

					if (n != write(outfd, buffer, n)) {
						ret = -EIO;
					}

					wtopaddr--;
				}
			}
		}
	}

	return ret;
}
Esempio n. 27
0
	void ActorArmourProto::initAnims() {
		ASSERT(sprite);
		ASSERT(sprite->size() <= invalid_id - 1);

		std::map<string, int> name_map;
		for(int n = 0; n < sprite->size(); n++)
			name_map.emplace(toLower((*sprite)[n].name), n);

		char text[256];

		for(int d = 0; d < DeathId::count; d++) {
			snprintf(text, sizeof(text), "death%s", s_death_names[d]);
			auto it = name_map.find(text);
			m_death_idx[d] = it == name_map.end()? invalid_id : it->second;
		}

		for(int w = 0; w < WeaponClass::count; w++)
			for(int a = 0; a < AttackMode::count; a++)
				for(int s = 0; s < Stance::count; s++) {
					const char *attack_mode =	a == AttackMode::punch? "one" :
												a == AttackMode::kick? "two" : AttackMode::toString(a);

					snprintf(text, sizeof(text), "%sattack%s%s", Stance::toString(s), WeaponClass::toString(w), attack_mode);
					auto it = name_map.find(text);
					m_attack_idx[w][a][s] = it == name_map.end()? invalid_id : it->second;
				//	if(it != name_map.end())
				//		printf("%s: %s\n", text, m_attack_idx[w][a][s] == 255? "NOT FOUND" : "OK");
				}

		for(int a = 0; a < Action::count; a++)
			for(int s = 0; s < Stance::count; s++) {
				if(Action::isNormal(a)) {
					for(int w = 0; w < WeaponClass::count; w++) {
						snprintf(text, sizeof(text), "%s%s%s", Stance::toString(s), s_normal_names[a],
									w == WeaponClass::unarmed? "" : WeaponClass::toString(w));
						auto it = name_map.find(text);
						m_normal_idx[a][s][w] = it == name_map.end()? invalid_id : it->second;
					//	printf("%s: %s\n", text, m_normal_idx[a][s][w] == 255? "NOT FOUND" : "OK");
					}
				}
				else if(Action::isSimple(a)) {
					snprintf(text, sizeof(text), "%s%s", Stance::toString(s), s_simple_names[a - Action::_simple][s]);
					auto it = name_map.find(text);
					m_simple_idx[a - Action::_simple][s] = it == name_map.end()? invalid_id : it->second;
				}
			}

		for(int c = 0; c < arraySize(m_climb_idx); c++) {
			auto it = name_map.find(s_climb_names[c]);
			m_climb_idx[c] = it == name_map.end()? invalid_id : it->second;
		}

		for(int w = 0; w < WeaponClass::count; w++)
			for(int s = Stance::prone; s <= Stance::crouch; s++)
			if(m_normal_idx[Action::walk][s][w] == invalid_id)
				m_normal_idx[Action::walk][s][w] = m_normal_idx[Action::walk][s][0];

		ASSERT(animId(Action::idle, Stance::stand, WeaponClass::unarmed) != -1);
	}
Esempio n. 28
0
void CPiano::clear()
{
    m_goodChord.clear();
    m_badChord.clear();
    noteNameListClear();
    for (unsigned int i = 0; i < arraySize(m_savedChordLookUp); i++)
        m_savedChordLookUp[i].pitchKey = 0;
}
Esempio n. 29
0
int arraySizeName(char *name)
{
	pgxc_ctl_var *var;

	if ((var = find_var(name)) == NULL)
		return -1;
	return(arraySize(var));
}
Esempio n. 30
0
inline ALEScreen::ALEScreen(const ALEScreen &rhs):
  m_rows(rhs.m_rows),
  m_columns(rhs.m_columns),
  m_pixels(new pixel_t[m_rows * m_columns]) {

  // Copy data over
  memcpy(m_pixels.get(), rhs.m_pixels.get(), arraySize());
}