当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_SwapLE16函数代码示例

本文整理汇总了C++中SDL_SwapLE16函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_SwapLE16函数的具体用法?C++ SDL_SwapLE16怎么用?C++ SDL_SwapLE16使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_SwapLE16函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: add_mines_from_list

void add_mines_from_list (const Uint8 *data)
{
	Uint16 mines_no;
	int i;
	int mine_x, mine_y, mine_type, my_offset;
	float x, y, z;
	int obj_3d_id, mine_id;

	mines_no = data[0];

	if (mines_no > NUM_MINES)
	{
		return;		// Something nasty happened
	}
	
	for (i = 0; i < mines_no; i++)
	{
		my_offset = i * 6 + 1;
		mine_x = SDL_SwapLE16(*((Uint16 *)(data + my_offset)));
		mine_y = SDL_SwapLE16(*((Uint16 *)(data + my_offset + 2)));
		mine_id = *((Uint8 *)(data + my_offset + 4));
		mine_type = *((Uint8 *)(data + my_offset + 5));
		if (mine_id >= NUM_MINES)
		{
			continue;
		}
		// Now, get the Z position
		if (mine_y * tile_map_size_x * 6 + mine_x > tile_map_size_x * tile_map_size_y * 6 * 6)
		{
			// Warn about this error!
			LOG_ERROR("A mine was located OUTSIDE the map!\n");
			continue;
		}
		
		z = -2.2f + height_map[mine_y * tile_map_size_x * 6 + mine_x] * 0.2f;
		// Convert from height values to meters
		x = (float)mine_x / 2;
		y = (float)mine_y / 2;
		// Center the object
		x = x + 0.25f;
		y = y + 0.25f;
	
		// Now, find the place into the mines list, so we can destroy the mine properly
		if (mine_list[mine_id].obj_3d_id != -1)
		{
			char buf[256];

			// Oops, slot already taken!
			safe_snprintf(buf, sizeof(buf), "Oops, trying to add an existing mine! id=%d\n", mine_id);
			LOG_ERROR(buf);
			return;
		}

		obj_3d_id = add_e3d(get_mine_e3d(mine_type), x, y, z, 0, 0, 0, 1, 0, 1.0f, 1.0f, 1.0f, 1);
		mine_list[mine_id].x = mine_x;
		mine_list[mine_id].y = mine_y;
		mine_list[mine_id].type = mine_type;
		mine_list[mine_id].obj_3d_id = obj_3d_id;
	}
}
开发者ID:csiga,项目名称:Eternal-Lands,代码行数:60,代码来源:mines.c

示例2: WAVFormat_Update

/**
 * Update WAV file with current samples
 */
void WAVFormat_Update(Sint16 pSamples[][2], int Index, int Length)
{
	Sint16 sample[2];
	int i;

	if (bRecordingWav)
	{
		/* Output, better if did in two section if wrap */
		for(i = 0; i < Length; i++)
		{
			/* Convert sample to little endian */
			sample[0] = SDL_SwapLE16(pSamples[(Index+i)%MIXBUFFER_SIZE][0]);
			sample[1] = SDL_SwapLE16(pSamples[(Index+i)%MIXBUFFER_SIZE][1]);
			/* And store */
			if (fwrite(&sample, sizeof(sample), 1, WavFileHndl) != 1)
			{
				perror("WAVFormat_Update");
				WAVFormat_CloseFile();
				return;
			}
		}

		/* Add samples to wav file length counter */
		nWavOutputBytes += Length * 4;
	}
}
开发者ID:itomato,项目名称:Previous,代码行数:29,代码来源:wavFormat.c

示例3: InitMS_ADPCM

static int InitMS_ADPCM(WaveFMT *format)
{
	Uint8 *rogue_feel;
	Uint16 extra_info;
	int i;

	/* Set the rogue pointer to the MS_ADPCM specific data */
	MS_ADPCM_state.wavefmt.encoding = SDL_SwapLE16(format->encoding);
	MS_ADPCM_state.wavefmt.channels = SDL_SwapLE16(format->channels);
	MS_ADPCM_state.wavefmt.frequency = SDL_SwapLE32(format->frequency);
	MS_ADPCM_state.wavefmt.byterate = SDL_SwapLE32(format->byterate);
	MS_ADPCM_state.wavefmt.blockalign = SDL_SwapLE16(format->blockalign);
	MS_ADPCM_state.wavefmt.bitspersample =
					 SDL_SwapLE16(format->bitspersample);
	rogue_feel = (Uint8 *)format+sizeof(*format);
	if ( sizeof(*format) == 16 ) {
		extra_info = ((rogue_feel[1]<<8)|rogue_feel[0]);
		rogue_feel += sizeof(Uint16);
	}
	MS_ADPCM_state.wSamplesPerBlock = ((rogue_feel[1]<<8)|rogue_feel[0]);
	rogue_feel += sizeof(Uint16);
	MS_ADPCM_state.wNumCoef = ((rogue_feel[1]<<8)|rogue_feel[0]);
	rogue_feel += sizeof(Uint16);
	if ( MS_ADPCM_state.wNumCoef != 7 ) {
		SDL_SetError("Unknown set of MS_ADPCM coefficients");
		return(-1);
	}
	for ( i=0; i<MS_ADPCM_state.wNumCoef; ++i ) {
		MS_ADPCM_state.aCoeff[i][0] = ((rogue_feel[1]<<8)|rogue_feel[0]);
		rogue_feel += sizeof(Uint16);
		MS_ADPCM_state.aCoeff[i][1] = ((rogue_feel[1]<<8)|rogue_feel[0]);
		rogue_feel += sizeof(Uint16);
	}
	return(0);
}
开发者ID:OS2World,项目名称:LIB-SDL,代码行数:35,代码来源:SDL_wave.c

示例4: swapEndianness

static void swapEndianness(WavFMT *wavfmt)
{
	wavfmt->Encoding = SDL_SwapLE16(wavfmt->Encoding);
	wavfmt->Channels = SDL_SwapLE16(wavfmt->Channels);
	wavfmt->Frequency = SDL_SwapLE32(wavfmt->Frequency);
	wavfmt->ByteRate = SDL_SwapLE32(wavfmt->ByteRate);
	wavfmt->SampleSize = SDL_SwapLE16(wavfmt->SampleSize);
	wavfmt->BitsPerSample = SDL_SwapLE16(wavfmt->BitsPerSample);
}
开发者ID:stefanhendriks,项目名称:stratagus,代码行数:9,代码来源:wav.cpp

示例5: read_server_book

void read_server_book (const char *data, int len)
{
	char buffer[8192];
	book *b;
	page *p;
	int l = SDL_SwapLE16(*((Uint16*)(data+4)));
	int idx;

	if ( l >= sizeof (buffer) ) // Safer
		l = sizeof (buffer) - 1;
	memcpy (buffer, data+6, l);
	buffer[l] = '\0';
	
	b = get_book (SDL_SwapLE16 (*((Uint16*)(data+1))));
	if (b == NULL)
		b = create_book (buffer, data[0], SDL_SwapLE16 (*((Uint16*)(data+1))));

	b->server_pages = data[3];
	b->have_server_pages++;

	p=add_page(b);//Will create a page if pages is not found.

	idx = l + 6;
	while (idx <= len)
	{
		l = SDL_SwapLE16 (*((Uint16*)(&data[idx+1])));
		if ( l >= sizeof (buffer) ) // Safer.
			l = sizeof (buffer) - 1;
		memcpy (buffer, &data[idx+3], l);
		buffer[l]=0;

		switch (data[idx])
		{
			case _TEXT:
				p=add_str_to_page(buffer,_TEXT,b,p);
				break;
			case _AUTHOR:
				p=add_str_to_page(buffer,_AUTHOR,b,p);
				break;
			case _TITLE:
				p=add_str_to_page(buffer,_TITLE,b,p);
				break;
			case _IMAGE:
				p=add_image_from_server(buffer, b, p);
				break;
			case _PAGE:
				//p=add_page(b);
				break;
		}
		idx += l + 3;
	}

	b->active_page += b->pages_to_scroll;
	b->pages_to_scroll = 0;
	
	if (b) display_book_window (b); // Otherwise there's no point...
}
开发者ID:sorlok,项目名称:Eternal-Lands,代码行数:57,代码来源:books.c

示例6: IsJoystick

static int
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
{
    struct input_id inpid;
    Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);

#if !SDL_USE_LIBUDEV
    /* When udev is enabled we only get joystick devices here, so there's no need to test them */
    unsigned long evbit[NBITS(EV_MAX)] = { 0 };
    unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
    unsigned long absbit[NBITS(ABS_MAX)] = { 0 };

    if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
        (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
        (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
        return (0);
    }

    if (!(test_bit(EV_KEY, evbit) && test_bit(EV_ABS, evbit) &&
          test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) {
        return 0;
    }
#endif

    if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
        return 0;
    }

    if (ioctl(fd, EVIOCGID, &inpid) < 0) {
        return 0;
    }

#ifdef DEBUG_JOYSTICK
    printf("Joystick: %s, bustype = %d, vendor = 0x%x, product = 0x%x, version = %d\n", namebuf, inpid.bustype, inpid.vendor, inpid.product, inpid.version);
#endif

    SDL_memset(guid->data, 0, sizeof(guid->data));

    /* We only need 16 bits for each of these; space them out to fill 128. */
    /* Byteswap so devices get same GUID on little/big endian platforms. */
    *(guid16++) = SDL_SwapLE16(inpid.bustype);
    *(guid16++) = 0;

    if (inpid.vendor && inpid.product && inpid.version) {
        *(guid16++) = SDL_SwapLE16(inpid.vendor);
        *(guid16++) = 0;
        *(guid16++) = SDL_SwapLE16(inpid.product);
        *(guid16++) = 0;
        *(guid16++) = SDL_SwapLE16(inpid.version);
        *(guid16++) = 0;
    } else {
        SDL_strlcpy((char*)guid16, namebuf, sizeof(guid->data) - 4);
    }

    return 1;
}
开发者ID:03050903,项目名称:Torque3D,代码行数:56,代码来源:SDL_sysjoystick.c

示例7: SDL_RWseek

IndexedTextFile::IndexedTextFile(SDL_RWops* rwop, bool bDecode) {

	if(rwop == NULL) {
	    throw std::invalid_argument("IndexedTextFile:IndexedTextFile(): rwop == NULL!");
	}

	int indexedTextFilesize = SDL_RWseek(rwop,0,SEEK_END);
	if(indexedTextFilesize <= 0) {
        throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Cannot determine size of this file!");
	}

	if(indexedTextFilesize < 2) {
        throw std::runtime_error("IndexedTextFile:IndexedTextFile(): No valid indexed textfile: File too small!");
	}

	if(SDL_RWseek(rwop,0,SEEK_SET) != 0) {
        throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Seeking in this indexed textfile failed!");
	}

	unsigned char* pFiledata;
	if( (pFiledata = (unsigned char*) malloc(indexedTextFilesize)) == NULL) {
        throw std::bad_alloc();
	}

	if(SDL_RWread(rwop, pFiledata, indexedTextFilesize, 1) != 1) {
	    free(pFiledata);
        throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Reading this indexed textfile failed!");
	}

	int numIndexedStrings = (SDL_SwapLE16(((Uint16*) pFiledata)[0]))/2 - 1;

	Uint16* pIndex = (Uint16*) pFiledata;
	for(int i=0; i <= numIndexedStrings; i++) {
		pIndex[i] = SDL_SwapLE16(pIndex[i]);
	}

    try {
        for(int i=0; i < numIndexedStrings; i++) {
            std::string text((const char*) (pFiledata+pIndex[i]));

            if(bDecode) {
                indexedStrings.push_back(convertCP850ToISO8859_1(decodeString(text)));
            } else {
                indexedStrings.push_back( convertCP850ToISO8859_1(text) );
            }
        }
    } catch(std::exception&) {
        delete [] pFiledata;
        throw;
    }

	free(pFiledata);
}
开发者ID:binarycrusader,项目名称:dunelegacy,代码行数:53,代码来源:IndexedTextFile.cpp

示例8: imgFile

/**
 * Loads the contents of an X-Com SPK image file into
 * the surface. SPK files are compressed with a custom
 * algorithm since they're usually full-screen images.
 * @param filename Filename of the SPK image.
 * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#SPK
 */
void Surface::loadSpk(const std::string &filename)
{
	// Load file and put pixels in surface
	std::ifstream imgFile (filename.c_str(), std::ios::in | std::ios::binary);
	if (!imgFile)
	{
		throw Exception(filename + " not found");
	}

	// Lock the surface
	lock();

	Uint16 flag;
	Uint8 value;
	int x = 0, y = 0;

	while (imgFile.read((char*)&flag, sizeof(flag)))
	{
		flag = SDL_SwapLE16(flag);
	
		if (flag == 65535)
		{
			imgFile.read((char*)&flag, sizeof(flag));
			flag = SDL_SwapLE16(flag);
			
			for (int i = 0; i < flag * 2; ++i)
			{
				setPixelIterative(&x, &y, 0);
			}
		}
		else if (flag == 65534)
		{
			imgFile.read((char*)&flag, sizeof(flag));
			flag = SDL_SwapLE16(flag);
			
			for (int i = 0; i < flag * 2; ++i)
			{
				imgFile.read((char*)&value, 1);
				setPixelIterative(&x, &y, value);
			}
		}
	}

	// Unlock the surface
	unlock();

	imgFile.close();
}
开发者ID:Scarberian,项目名称:OpenXcom,代码行数:55,代码来源:Surface.cpp

示例9: print_items

void print_items(void)
{
	int i;
	actor *me;

	me = get_our_actor();
	if (me)
		if(me->fighting)
		{
			LOG_TO_CONSOLE(c_red1, "You can't do this during combat!");
			return;
		}
	
	/* request the description for each item */
	number_to_print = next_item_to_print = 0;
	printing_category = selected_category;
	for (i = 0; i < no_storage && i < STORAGE_ITEMS_SIZE; i++)
	{
		if (storage_items[i].quantity)
		{		
			Uint8 str[3];
			print_quanities[number_to_print++] = storage_items[i].quantity;
			str[0]=LOOK_AT_STORAGE_ITEM;
			*((Uint16*)(str+1))=SDL_SwapLE16(storage_items[i].pos);
			my_tcp_send(my_socket, str, 3);
		}
	}
}
开发者ID:bobbylovin26,项目名称:Eternal-Lands,代码行数:28,代码来源:storage.c

示例10: read_le16

/* Better than SDL_ReadLE16, since you can detect i/o errors... */
static __inline__ int read_le16(SDL_RWops *rw, Uint16 *ui16)
{
    int rc = SDL_RWread(rw, ui16, sizeof (Uint16), 1);
    BAIL_IF_MACRO(rc != 1, ERR_IO_ERROR, 0);
    *ui16 = SDL_SwapLE16(*ui16);
    return(1);
} /* read_le16 */
开发者ID:BPaden,项目名称:garglk,代码行数:8,代码来源:wav.c

示例11: open_book

void open_book(int id)
{
	book *b=get_book(id);

	if(!b) {
		char str[5];
		
		str[0]=SEND_BOOK;
		*((Uint16*)(str+1))=SDL_SwapLE16((Uint16)id);
		*((Uint16*)(str+3))=SDL_SwapLE16(0);

		my_tcp_send(my_socket, (Uint8*)str, 5);
	} else {
		display_book_window(b);
	}
}
开发者ID:sorlok,项目名称:Eternal-Lands,代码行数:16,代码来源:books.c

示例12: SDL_ReadLE16

Uint16 SDL_ReadLE16 (SDL_RWops *src)
{
    Uint16 value;

    SDL_RWread(src, &value, (sizeof value), 1);
    return(SDL_SwapLE16(value));
}
开发者ID:RDCH106,项目名称:n64oid,代码行数:7,代码来源:SDL_rwops.c

示例13: memset

void LANGameFinderAndAnnouncer::announceGame() {

	ENetAddress destinationAddress;
	destinationAddress.host = ENET_HOST_BROADCAST;
	destinationAddress.port = LANGAME_ANNOUNCER_PORT;

	NetworkPacket_AnnounceGame announcePacket;
	memset(&announcePacket, 0, sizeof(NetworkPacket_AnnounceGame));

	announcePacket.magicNumber = SDL_SwapLE32(LANGAME_ANNOUNCER_MAGICNUMBER);
	announcePacket.type = NETWORKPACKET_ANNOUNCEGAME;
	strncpy(announcePacket.serverName, serverName.c_str(), LANGAME_ANNOUNCER_MAXGAMENAMESIZE);
	strncpy(announcePacket.serverVersion, VERSIONSTRING, LANGAME_ANNOUNCER_MAXGAMEVERSIONSIZE);
	announcePacket.serverPort = SDL_SwapLE16(serverPort);
	strncpy(announcePacket.mapName, mapName.c_str(), LANGAME_ANNOUNCER_MAXMAPNAMESIZE);
    announcePacket.numPlayers = numPlayers;
    announcePacket.maxPlayers = maxPlayers;

	ENetBuffer enetBuffer;
	enetBuffer.data = &announcePacket;
	enetBuffer.dataLength = sizeof(NetworkPacket_AnnounceGame);
	int err = enet_socket_send(announceSocket, &destinationAddress, &enetBuffer, 1);
	if(err==0) {
		// blocked
	} else if(err < 0) {
		throw std::runtime_error("LANGameFinderAndAnnouncer: Announcing failed!");
	} else {
		lastAnnounce = SDL_GetTicks();
	}
}
开发者ID:binarycrusader,项目名称:dunelegacy,代码行数:30,代码来源:LANGameFinderAndAnnouncer.cpp

示例14: efwrite

// endian-swapping fwrite
size_t efwrite( void *buffer, size_t size, size_t num, FILE *stream )
{
	void *swap_buffer;
	
	switch (size)
	{
		case 2:
			swap_buffer = malloc(size * num);
			for (size_t i = 0; i < num; i++)
				((Uint16 *)swap_buffer)[i] = SDL_SwapLE16(((Uint16 *)buffer)[i]);
			break;
		case 4:
			swap_buffer = malloc(size * num);
			for (size_t i = 0; i < num; i++)
				((Uint32 *)swap_buffer)[i] = SDL_SwapLE32(((Uint32 *)buffer)[i]);
			break;
		case 8:
			swap_buffer = malloc(size * num);
			for (size_t i = 0; i < num; i++)
				((Uint64 *)swap_buffer)[i] = SDL_SwapLE64(((Uint64 *)buffer)[i]);
			break;
		default:
			swap_buffer = buffer;
			break;
	}
	
	size_t f = fwrite(swap_buffer, size, num, stream);
	
	if (swap_buffer != buffer)
		free(swap_buffer);
	
	return f;
}
开发者ID:Malkierian,项目名称:OpenTyrianWP,代码行数:34,代码来源:file.c

示例15: blit_sprite2_filter

// does not clip on left or right edges of surface
void blit_sprite2_filter( SDL_Surface *surface, int x, int y, Sprite2_array sprite2s, unsigned int index, Uint8 filter )
{
	assert(surface->format->BitsPerPixel == 8);
	Uint8 *             pixels =    (Uint8 *)surface->pixels + (y * surface->pitch) + x;
	const Uint8 * const pixels_ll = (Uint8 *)surface->pixels,  // lower limit
	            * const pixels_ul = (Uint8 *)surface->pixels + (surface->h * surface->pitch);  // upper limit
	
	const Uint8 *data = sprite2s.data + SDL_SwapLE16(((Uint16 *)sprite2s.data)[index - 1]);
	
	for (; *data != 0x0f; ++data)
	{
		pixels += *data & 0x0f;                   // second nibble: transparent pixel count
		unsigned int count = (*data & 0xf0) >> 4; // first nibble: opaque pixel count
		
		if (count == 0) // move to next pixel row
		{
			pixels += VGAScreen->pitch - 12;
		}
		else
		{
			while (count--)
			{
				++data;
				
				if (pixels >= pixels_ul)
					return;
				if (pixels >= pixels_ll)
					*pixels = filter | (*data & 0x0f);
				
				++pixels;
			}
		}
	}
}
开发者ID:carstene1ns,项目名称:opentyrian-wii,代码行数:35,代码来源:sprite.c


注:本文中的SDL_SwapLE16函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。