本文整理汇总了C++中SDL_SwapLE32函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_SwapLE32函数的具体用法?C++ SDL_SwapLE32怎么用?C++ SDL_SwapLE32使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_SwapLE32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catch
void CSndHandler::add_file(std::string fname, bool important /*= true*/)
{
boost::iostreams::mapped_file_source *mfile = NULL;
try
{
mfile = CMediaHandler::add_file(fname, important);
}
catch(...)
{
return;
}
const char *data = mfile->data();
unsigned int numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]);
struct soundEntry *se = (struct soundEntry *)&data[4];
for (unsigned int i=0; i<numFiles; i++, se++)
{
Entry entry;
entry.name = se->filename;
entry.offset = SDL_SwapLE32(se->offset);
entry.size = SDL_SwapLE32(se->size);
entry.data = mfile->data() + entry.offset;
entries.push_back(entry);
fimap[entry.name] = i;
}
}
示例2: _amount
/**
* Creates a CAT file stream. A CAT file starts with an index of the
* offset and size of every file contained within. Each file consists
* of a filename followed by its contents.
* @param path Full path to CAT file.
*/
CatFile::CatFile(const char *path) : std::ifstream(path, std::ios::in | std::ios::binary), _amount(0), _offset(0), _size(0)
{
if (!this)
return;
// Get amount of files
read((char*)&_amount, sizeof(_amount));
_amount = (unsigned int)SDL_SwapLE32(_amount);
_amount /= 2 * sizeof(_amount);
// Get object offsets
seekg(0, std::ios::beg);
_offset = new unsigned int[_amount];
_size = new unsigned int[_amount];
for (unsigned int i = 0; i < _amount; ++i)
{
read((char*)&_offset[i], sizeof(*_offset));
_offset[i] = (unsigned int)SDL_SwapLE32(_offset[i]);
read((char*)&_size[i], sizeof(*_size));
_size[i] = (unsigned int)SDL_SwapLE32(_size[i]);
}
}
示例3: create_SDL_Surface
SDL_Surface* create_SDL_Surface(rgb* image)
// Steal *image's data to create an SDL_Surface.
//
// DELETES image!!!
{
assert(image->m_pitch < 65536); // SDL_Surface only uses Uint16 for pitch!!!
SDL_Surface* s = SDL_CreateRGBSurfaceFrom(image->m_data,
image->m_width, image->m_height, 24, image->m_pitch,
SDL_SwapLE32(0x0FF),
SDL_SwapLE32(0x0FF00),
SDL_SwapLE32(0x0FF0000),
0);
// s owns *image's data now -- invalidate *image.
image->m_data = 0;
image->m_height = 0;
image->m_width = 0;
image->m_pitch = 0;
delete image;
assert(s->pixels);
assert(s->format->BytesPerPixel == 3);
assert(s->format->BitsPerPixel == 24);
return s;
}
示例4: 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);
}
示例5: 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);
}
示例6: getNetworkAngleInt
NetworkAngleInt getNetworkAngleInt() const
{
NetworkAngleInt netangle;
netangle.angle_int = SDL_SwapLE32(angle_int);
netangle.grain = SDL_SwapLE32(grain);
netangle.angle_limit = SDL_SwapLE32(angle_limit);
return netangle;
}
示例7: zoomSurface2X_32bit
/**
* Optimized 8 bit zoomer for resizing by a factor of 2. Doesn't flip.
* 32-bit version for sad old x86 chips which run out of registers
* with the 64-bit version.
* Used internally by _zoomSurfaceY() below.
* source and dest. widths must be multiples of 4 bytes for 32-bit access
*/
static int zoomSurface2X_32bit(SDL_Surface *src, SDL_Surface *dst)
{
Uint32 dataSrc;
Uint32 dataDst;
Uint8 *pixelSrc = (Uint8*)src->pixels;
Uint8 *pixelDstRow = (Uint8*)dst->pixels;
int sx, sy;
static bool proclaimed = false;
if (!proclaimed)
{
proclaimed = true;
Log(LOG_INFO) << "Using 32-bit 2X zoom routine.";
}
for (sy = 0; sy < src->h; ++sy, pixelDstRow += dst->pitch*2)
{
Uint32 *pixelDst = (Uint32*)pixelDstRow;
Uint32 *pixelDst2 = (Uint32*)(pixelDstRow + dst->pitch);
for (sx = 0; sx < src->w; sx += 4, pixelSrc += 4)
{
dataSrc = *((Uint32*) pixelSrc);
// boo
dataSrc = SDL_SwapLE32(dataSrc);
dataDst = SDL_SwapLE32( (dataSrc & 0xFF) | ((dataSrc & 0xFFFF) << 8) |
((dataSrc & 0xFF00) << 16) );
*pixelDst = dataDst;
*pixelDst2 = dataDst;
pixelDst++; // forward 4 bytes!
pixelDst2++;
dataSrc >>= 16;
dataDst = SDL_SwapLE32( (dataSrc & 0xFF) | ((dataSrc & 0xFFFF) << 8) |
((dataSrc & 0xFF00) << 16) );
*pixelDst = dataDst;
*pixelDst2 = dataDst;
pixelDst++; // forward 4 bytes!
pixelDst2++;
}
}
return 0;
}
示例8: assert
void Layer::generateXML(std::string &result) const {
result = mrt::format_string("\t<layer name=\"%s\" width=\"%d\" height=\"%d\"%s>\n", mrt::XMLParser::escape(name).c_str(), _w, _h, visible?"":" visible=\"0\"");
if (!properties.empty()) {
result += "\t\t<properties>\n";
for(PropertyMap::const_iterator i = properties.begin(); i != properties.end(); ++i) {
result += mrt::format_string("\t\t\t<property name=\"%s\" value=\"%s\"/>\n", mrt::XMLParser::escape(i->first).c_str(), mrt::XMLParser::escape(i->second).c_str());
}
result += "\t\t</properties>\n";
}
result += "\t\t<data encoding=\"base64\" compression=\"gzip\">\n\t\t\t";
{
mrt::Chunk zipped_data, data;
data = _data;
size_t n = data.get_size() / 4;
assert((int)n == (_w * _h));
//convert all stuff.
Uint32 *p = (Uint32 *)data.get_ptr();
for(size_t i = 0; i < n; ++i) {
Uint32 x = SDL_SwapLE32(*p);
*p++ = x;
}
mrt::ZStream::compress(zipped_data, data, true, 9);
std::string base64;
mrt::Base64::encode(base64, zipped_data);
result += base64;
}
result += "\n\t\t</data>\n";
result += "\t</layer>\n";
}
示例9: SDL_ReadLE32
Uint32 SDL_ReadLE32 (SDL_RWops *src)
{
Uint32 value;
SDL_RWread(src, &value, (sizeof value), 1);
return(SDL_SwapLE32(value));
}
示例10: el_read_int
int el_read_int(el_file_ptr file, int *i)
{
if (file->current + sizeof(int) > file->end)
return 0;
#ifdef EL_FORCE_ALIGNED_READ
{
int tmp;
memcpy(&tmp, file->current, sizeof(int));
*i = SDL_SwapLE32(tmp);
}
#else
*i = SDL_SwapLE32(*((int*)file->current));
#endif
file->current += sizeof(int);
return 1;
}
示例11: 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;
}
示例12: read_le32
/* Better than SDL_ReadLE32, since you can detect i/o errors... */
static __inline__ int read_le32(SDL_RWops *rw, Uint32 *ui32)
{
int rc = SDL_RWread(rw, ui32, sizeof (Uint32), 1);
BAIL_IF_MACRO(rc != 1, ERR_IO_ERROR, 0);
*ui32 = SDL_SwapLE32(*ui32);
return(1);
} /* read_le32 */
示例13: state_2d_object
// for future expansion
void state_2d_object (Uint8 state, const void *ptr, int len)
{
const Uint32 *id_ptr = ptr;
// first look for the override to process ALL objects
if (len < sizeof(*id_ptr) ){
int i;
for (i = 0; i < MAX_OBJ_2D; i++)
{
if (obj_2d_list[i]){
obj_2d_list[i]->state= state;
}
}
} else {
int idx = 0;
while(len >= sizeof(*id_ptr)){
Uint32 obj_id = SDL_SwapLE32(id_ptr[idx]);
if(obj_id < MAX_OBJ_2D && obj_2d_list[obj_id])
obj_2d_list[obj_id]->state= state;
idx++;
len -= sizeof (*id_ptr);
}
}
}
示例14: 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();
}
}
示例15: SDL_ReadLE32
Uint32
SDL_ReadLE32(SDL_RWops * src)
{
Uint32 value = 0;
SDL_RWread(src, &value, sizeof (value), 1);
return SDL_SwapLE32(value);
}