void CLayerTiles::Shift(int Direction) { switch(Direction) { case 1: { // left for(int y = 0; y < m_Height; ++y) mem_move(&m_pTiles[y*m_Width], &m_pTiles[y*m_Width+1], (m_Width-1)*sizeof(CTile)); } break; case 2: { // right for(int y = 0; y < m_Height; ++y) mem_move(&m_pTiles[y*m_Width+1], &m_pTiles[y*m_Width], (m_Width-1)*sizeof(CTile)); } break; case 4: { // up for(int y = 0; y < m_Height-1; ++y) mem_copy(&m_pTiles[y*m_Width], &m_pTiles[(y+1)*m_Width], m_Width*sizeof(CTile)); } break; case 8: { // down for(int y = m_Height-1; y > 0; --y) mem_copy(&m_pTiles[y*m_Width], &m_pTiles[(y-1)*m_Width], m_Width*sizeof(CTile)); } } }
void CSounds::OnRender() { // check for sound initialisation if(m_WaitForSoundJob) { if(m_pSoundJob->Status() == IJob::STATE_DONE) m_WaitForSoundJob = false; else return; } // set listener pos Sound()->SetListenerPos(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y); // update volume float NewMapSoundVol = g_Config.m_SndMapSoundVolume/100.0f; if(NewMapSoundVol != m_MapSoundVolume) { m_MapSoundVolume = NewMapSoundVol; Sound()->SetChannel(CSounds::CHN_MAPSOUND, m_MapSoundVolume, 1.0f); } // play sound from queue if(m_QueuePos > 0) { int64 Now = time_get(); if(m_QueueWaitTime <= Now) { Play(m_aQueue[0].m_Channel, m_aQueue[0].m_SetId, 1.0f); m_QueueWaitTime = Now+time_freq()*3/10; // wait 300ms before playing the next one if(--m_QueuePos > 0) mem_move(m_aQueue, m_aQueue+1, m_QueuePos*sizeof(QueueEntry)); } } }
void CSounds::OnRender() { // check for sound initialisation if(m_WaitForSoundJob) { if(m_SoundJob.Status() == CJob::STATE_DONE) m_WaitForSoundJob = false; else return; } // set listner pos Sound()->SetListenerPos(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y); // play sound from queue if(m_QueuePos > 0) { int64 Now = time_get(); if(m_QueueWaitTime <= Now) { Play(m_aQueue[0].m_Channel, m_aQueue[0].m_SetId, 1.0f); m_QueueWaitTime = Now+time_freq()*3/10; // wait 300ms before playing the next one if(--m_QueuePos > 0) mem_move(m_aQueue, m_aQueue+1, m_QueuePos*sizeof(QueueEntry)); } } }
void CFriends::RemoveFriend(int Index) { if(Index >= 0 && Index < m_NumFriends) { mem_move(&m_aFriends[Index], &m_aFriends[Index+1], sizeof(CFriendInfo)*(m_NumFriends-(Index+1))); --m_NumFriends; } return; }
void CFriends::RemoveFriend(int Index) { CALLSTACK_ADD(); if(Index >= 0 && Index < m_NumFriends) { mem_move(&m_aFriends[Index], &m_aFriends[Index+1], sizeof(CFriendInfo)*(m_NumFriends-(Index+1))); --m_NumFriends; } }
void math_memory_copy(byte *dest, size_t dest_size, const byte *src, size_t src_size) { size_t size = MIN(dest_size, src_size); mem_move(dest, src, size); if (dest_size > size) { mem_set(dest + size, 0, dest_size - size); } }
/*-------------- void matrix_mult() -------------- Inputs: struct matrix *a struct matrix *b Returns: a*b -> b */ void matrix_mult(struct matrix *a, struct matrix *b) { if(a->cols != b->rows) { return; } struct matrix *answer = new_matrix(a->cols,a->cols); int i,j,k; for(i=0; i<a->cols; i++) { for(j=0; j<b->rows; j++) { for(k=0; k<a->cols; k++) { answer->m[i][j] = a->m[j][k] * b->m[k][i]; } } } mem_move(b,a->rows); copy_matrix(tmp,b); free_matrix(tmp); }
void CServerBrowser::RemoveFavorite(const NETADDR &Addr) { int i; CServerEntry *pEntry; for(i = 0; i < m_NumFavoriteServers; i++) { if(net_addr_comp(&Addr, &m_aFavoriteServers[i]) == 0) { mem_move(&m_aFavoriteServers[i], &m_aFavoriteServers[i+1], sizeof(NETADDR)*(m_NumFavoriteServers-(i+1))); m_NumFavoriteServers--; pEntry = Find(Addr); if(pEntry) pEntry->m_Info.m_Favorite = 0; return; } } }
void CFileCollection::AddEntry(int64 Timestamp) { if(m_NumTimestamps == 0) { // empty list m_aTimestamps[m_NumTimestamps++] = Timestamp; } else { // remove old file if(m_NumTimestamps >= m_MaxEntries) { if(m_aFileDesc[0] == '\0') // consider an empty file desc as a wild card { m_Remove = m_aTimestamps[0]; m_pStorage->ListDirectory(IStorage::TYPE_SAVE, m_aPath, RemoveCallback, this); } else { char aBuf[512]; char aTimestring[TIMESTAMP_LENGTH]; BuildTimestring(m_aTimestamps[0], aTimestring); str_format(aBuf, sizeof(aBuf), "%s/%s_%s%s", m_aPath, m_aFileDesc, aTimestring, m_aFileExt); m_pStorage->RemoveFile(aBuf, IStorage::TYPE_SAVE); } } // add entry to the sorted list if(m_aTimestamps[0] > Timestamp) { // first entry if(m_NumTimestamps < m_MaxEntries) { mem_move(m_aTimestamps+1, m_aTimestamps, m_NumTimestamps*sizeof(int64)); m_aTimestamps[0] = Timestamp; ++m_NumTimestamps; } } else if(m_aTimestamps[m_NumTimestamps-1] <= Timestamp) { // last entry if(m_NumTimestamps == m_MaxEntries) { mem_move(m_aTimestamps, m_aTimestamps+1, (m_NumTimestamps-1)*sizeof(int64)); m_aTimestamps[m_NumTimestamps-1] = Timestamp; } else m_aTimestamps[m_NumTimestamps++] = Timestamp; } else { // middle entry int Left = 0, Right = m_NumTimestamps-1; while(Right-Left > 1) { int Mid = (Left+Right)/2; if(m_aTimestamps[Mid] > Timestamp) Right = Mid; else Left = Mid; } if(m_NumTimestamps == m_MaxEntries) { mem_move(m_aTimestamps, m_aTimestamps+1, (Right-1)*sizeof(int64)); m_aTimestamps[Right-1] = Timestamp; } else { mem_move(m_aTimestamps+Right+1, m_aTimestamps+Right, (m_NumTimestamps-Right)*sizeof(int64)); m_aTimestamps[Right] = Timestamp; ++m_NumTimestamps; } } } }
int CConsoleNetConnection::Recv(char *pLine, int MaxLength) { if(State() == NET_CONNSTATE_ONLINE) { if(m_BufferOffset) { // find message start int StartOffset = 0; while(m_aBuffer[StartOffset] == '\r' || m_aBuffer[StartOffset] == '\n') { // detect clients line ending format if(!m_LineEndingDetected) { m_aLineEnding[0] = m_aBuffer[StartOffset]; if(StartOffset+1 < m_BufferOffset && (m_aBuffer[StartOffset+1] == '\r' || m_aBuffer[StartOffset+1] == '\n') && m_aBuffer[StartOffset] != m_aBuffer[StartOffset+1]) m_aLineEnding[1] = m_aBuffer[StartOffset+1]; m_LineEndingDetected = true; } if(++StartOffset >= m_BufferOffset) { m_BufferOffset = 0; return 0; } } // find message end int EndOffset = StartOffset; while(m_aBuffer[EndOffset] != '\r' && m_aBuffer[EndOffset] != '\n') { if(++EndOffset >= m_BufferOffset) { if(StartOffset > 0) { mem_move(m_aBuffer, m_aBuffer+StartOffset, m_BufferOffset-StartOffset); m_BufferOffset -= StartOffset; } return 0; } } // extract message and update buffer if(MaxLength-1 < EndOffset-StartOffset) { if(StartOffset > 0) { mem_move(m_aBuffer, m_aBuffer+StartOffset, m_BufferOffset-StartOffset); m_BufferOffset -= StartOffset; } return 0; } mem_copy(pLine, m_aBuffer+StartOffset, EndOffset-StartOffset); pLine[EndOffset-StartOffset] = 0; str_sanitize_cc(pLine); mem_move(m_aBuffer, m_aBuffer+EndOffset, m_BufferOffset-EndOffset); m_BufferOffset -= EndOffset; return 1; } } return 0; }
bool CLineInput::Manipulate(IInput::CEvent Event, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr) { int NumChars = *pNumCharsPtr; int CursorPos = *pCursorPosPtr; int Len = *pStrLenPtr; bool Changes = false; if(CursorPos > Len) CursorPos = Len; if(Event.m_Flags&IInput::FLAG_TEXT) { // gather string stats int CharCount = 0; int CharSize = 0; while(Event.m_aText[CharSize]) { int NewCharSize = str_utf8_forward(Event.m_aText, CharSize); if(NewCharSize != CharSize) { ++CharCount; CharSize = NewCharSize; } } // add new string if(CharCount) { if(Len+CharSize < StrMaxSize && CursorPos+CharSize < StrMaxSize && NumChars+CharCount < StrMaxChars) { mem_move(pStr + CursorPos + CharSize, pStr + CursorPos, Len-CursorPos+1); // +1 == null term for(int i = 0; i < CharSize; i++) pStr[CursorPos+i] = Event.m_aText[i]; CursorPos += CharSize; Len += CharSize; NumChars += CharCount; Changes = true; } } } if(Event.m_Flags&IInput::FLAG_PRESS) { int Key = Event.m_Key; if(Key == KEY_BACKSPACE && CursorPos > 0) { int NewCursorPos = str_utf8_rewind(pStr, CursorPos); int CharSize = CursorPos-NewCursorPos; mem_move(pStr+NewCursorPos, pStr+CursorPos, Len - NewCursorPos - CharSize + 1); // +1 == null term CursorPos = NewCursorPos; Len -= CharSize; if(CharSize > 0) --NumChars; Changes = true; } else if(Key == KEY_DELETE && CursorPos < Len) { int p = str_utf8_forward(pStr, CursorPos); int CharSize = p-CursorPos; mem_move(pStr + CursorPos, pStr + CursorPos + CharSize, Len - CursorPos - CharSize + 1); // +1 == null term Len -= CharSize; if(CharSize > 0) --NumChars; Changes = true; } else if(Key == KEY_LEFT && CursorPos > 0) CursorPos = str_utf8_rewind(pStr, CursorPos); else if(Key == KEY_RIGHT && CursorPos < Len) CursorPos = str_utf8_forward(pStr, CursorPos); else if(Key == KEY_HOME) CursorPos = 0; else if(Key == KEY_END) CursorPos = Len; } *pNumCharsPtr = NumChars; *pCursorPosPtr = CursorPos; *pStrLenPtr = Len; return Changes; }
/**************** * transform n*64 bytes */ static void transform (md5_context_t ctx, t_uchar * data) { t_uint32 correct_words[16]; t_uint32 A = ctx->A; t_uint32 B = ctx->B; t_uint32 C = ctx->C; t_uint32 D = ctx->D; t_uint32 * cwp = correct_words; #if MACHINE_IS_BIGENDIAN { int i; t_uchar * p2; t_uchar * p1; i = 0; p1 = data; p2 = (t_uchar*)correct_words; while (i < 16) { p2[3] = *p1++; p2[2] = *p1++; p2[1] = *p1++; p2[0] = *p1++; ++i; p2 += 4; } } #else mem_move ((t_uchar *)correct_words, (t_uchar *)data, (size_t)64); #endif /* Rotate a 32 bit integer by n bytes */ #define rol(x,n) ( ((x) << (n)) | ((x) >> (32-(n))) ) #define OP(a, b, c, d, s, T) \ do \ { \ a += FF (b, c, d) + (*cwp++) + T; \ a = rol(a, s); \ a += b; \ } \ while (0) /* Before we start, one word about the strange constants. * They are defined in RFC 1321 as * * T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 */ /* Round 1. */ OP (A, B, C, D, 7, 0xd76aa478); OP (D, A, B, C, 12, 0xe8c7b756); OP (C, D, A, B, 17, 0x242070db); OP (B, C, D, A, 22, 0xc1bdceee); OP (A, B, C, D, 7, 0xf57c0faf); OP (D, A, B, C, 12, 0x4787c62a); OP (C, D, A, B, 17, 0xa8304613); OP (B, C, D, A, 22, 0xfd469501); OP (A, B, C, D, 7, 0x698098d8); OP (D, A, B, C, 12, 0x8b44f7af); OP (C, D, A, B, 17, 0xffff5bb1); OP (B, C, D, A, 22, 0x895cd7be); OP (A, B, C, D, 7, 0x6b901122); OP (D, A, B, C, 12, 0xfd987193); OP (C, D, A, B, 17, 0xa679438e); OP (B, C, D, A, 22, 0x49b40821); #undef OP #define OP(f, a, b, c, d, k, s, T) \ do \ { \ a += f (b, c, d) + correct_words[k] + T; \ a = rol(a, s); \ a += b; \ } \ while (0) /* Round 2. */ OP (FG, A, B, C, D, 1, 5, 0xf61e2562); OP (FG, D, A, B, C, 6, 9, 0xc040b340); OP (FG, C, D, A, B, 11, 14, 0x265e5a51); OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa); OP (FG, A, B, C, D, 5, 5, 0xd62f105d); OP (FG, D, A, B, C, 10, 9, 0x02441453); OP (FG, C, D, A, B, 15, 14, 0xd8a1e681); OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8); OP (FG, A, B, C, D, 9, 5, 0x21e1cde6); OP (FG, D, A, B, C, 14, 9, 0xc33707d6); OP (FG, C, D, A, B, 3, 14, 0xf4d50d87); OP (FG, B, C, D, A, 8, 20, 0x455a14ed); OP (FG, A, B, C, D, 13, 5, 0xa9e3e905); OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8); OP (FG, C, D, A, B, 7, 14, 0x676f02d9); OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a); /* Round 3. */ OP (FH, A, B, C, D, 5, 4, 0xfffa3942); OP (FH, D, A, B, C, 8, 11, 0x8771f681); OP (FH, C, D, A, B, 11, 16, 0x6d9d6122); OP (FH, B, C, D, A, 14, 23, 0xfde5380c); OP (FH, A, B, C, D, 1, 4, 0xa4beea44); OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9); OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60); OP (FH, B, C, D, A, 10, 23, 0xbebfbc70); OP (FH, A, B, C, D, 13, 4, 0x289b7ec6); OP (FH, D, A, B, C, 0, 11, 0xeaa127fa); OP (FH, C, D, A, B, 3, 16, 0xd4ef3085); OP (FH, B, C, D, A, 6, 23, 0x04881d05); OP (FH, A, B, C, D, 9, 4, 0xd9d4d039); OP (FH, D, A, B, C, 12, 11, 0xe6db99e5); OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8); OP (FH, B, C, D, A, 2, 23, 0xc4ac5665); /* Round 4. */ OP (FI, A, B, C, D, 0, 6, 0xf4292244); OP (FI, D, A, B, C, 7, 10, 0x432aff97); OP (FI, C, D, A, B, 14, 15, 0xab9423a7); OP (FI, B, C, D, A, 5, 21, 0xfc93a039); OP (FI, A, B, C, D, 12, 6, 0x655b59c3); OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92); OP (FI, C, D, A, B, 10, 15, 0xffeff47d); OP (FI, B, C, D, A, 1, 21, 0x85845dd1); OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f); OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0); OP (FI, C, D, A, B, 6, 15, 0xa3014314); OP (FI, B, C, D, A, 13, 21, 0x4e0811a1); OP (FI, A, B, C, D, 4, 6, 0xf7537e82); OP (FI, D, A, B, C, 11, 10, 0xbd3af235); OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb); OP (FI, B, C, D, A, 9, 21, 0xeb86d391); /* Put checksum in context given as argument. */ ctx->A += A; ctx->B += B; ctx->C += C; ctx->D += D; }
bool CLineInput::Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int *pStrLenPtr, int *pCursorPosPtr) { int CursorPos = *pCursorPosPtr; int Len = *pStrLenPtr; bool Changes = false; if(CursorPos > Len) CursorPos = Len; int Code = e.m_Unicode; int k = e.m_Key; // 127 is produced on Mac OS X and corresponds to the delete key if (!(Code >= 0 && Code < 32) && Code != 127) { char Tmp[8]; int CharSize = str_utf8_encode(Tmp, Code); if (Len < StrMaxSize - CharSize && CursorPos < StrMaxSize - CharSize) { mem_move(pStr + CursorPos + CharSize, pStr + CursorPos, Len-CursorPos+1); // +1 == null term for(int i = 0; i < CharSize; i++) pStr[CursorPos+i] = Tmp[i]; CursorPos += CharSize; Len += CharSize; Changes = true; } } if(e.m_Flags&IInput::FLAG_PRESS) { // backspace, ctrl+backspace, ctrl+w if ((k == KEY_BACKSPACE || (k == KEY_w && e.GetKeyMods()&(KEYMOD_LCTRL|KEYMOD_RCTRL))) && CursorPos > 0) { int NewCursorPos; if(e.GetKeyMods()&(KEYMOD_LCTRL|KEYMOD_RCTRL)) NewCursorPos = str_skip_word_backward(pStr, CursorPos); else NewCursorPos = str_utf8_rewind(pStr, CursorPos); int CharSize = CursorPos-NewCursorPos; mem_move(pStr+NewCursorPos, pStr+CursorPos, Len - NewCursorPos - CharSize + 1); // +1 == null term CursorPos = NewCursorPos; Len -= CharSize; Changes = true; } // ctrl+u else if(k == KEY_u && e.GetKeyMods()&(KEYMOD_LCTRL|KEYMOD_RCTRL)) { mem_move(pStr, pStr+CursorPos, Len - CursorPos + 1); // +1 == null term Len -= CursorPos; CursorPos = 0; Changes = true; } else if (k == KEY_DELETE && CursorPos < Len) { int p = str_utf8_forward(pStr, CursorPos); int CharSize = p-CursorPos; mem_move(pStr + CursorPos, pStr + CursorPos + CharSize, Len - CursorPos - CharSize + 1); // +1 == null term Len -= CharSize; Changes = true; } else if (k == KEY_LEFT && CursorPos > 0) { if(e.GetKeyMods()&(KEYMOD_LCTRL|KEYMOD_RCTRL)) CursorPos = str_skip_word_backward(pStr, CursorPos); else CursorPos = str_utf8_rewind(pStr, CursorPos); } else if (k == KEY_RIGHT && CursorPos < Len) { if(e.GetKeyMods()&(KEYMOD_LCTRL|KEYMOD_RCTRL)) CursorPos = str_skip_word_forward(pStr, CursorPos); else CursorPos = str_utf8_forward(pStr, CursorPos); } else if (k == KEY_HOME) CursorPos = 0; else if (k == KEY_END) CursorPos = Len; // ctrl+v -- paste else if(k == KEY_v && e.GetKeyMods()&(KEYMOD_LCTRL|KEYMOD_RCTRL)) { char aBuf[MAX_SIZE]; str_copy(aBuf, pStr + CursorPos, sizeof(aBuf)); int size = get_clipboard_data(pStr + CursorPos, MAX_SIZE - CursorPos); if(size >= 0 && size < MAX_SIZE - CursorPos) // success { CursorPos += size; Len += size; str_copy(pStr + CursorPos, aBuf, MAX_SIZE - CursorPos); } Changes = true; } } *pCursorPosPtr = CursorPos; *pStrLenPtr = Len; return Changes; }
void CServerBrowserFavorites::RemoveFavoriteEntry(int Index) { mem_move(&m_aFavoriteServers[Index], &m_aFavoriteServers[Index+1], sizeof(CFavoriteServer)*(m_NumFavoriteServers-(Index+1))); m_NumFavoriteServers--; }
bool CLineInput::Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int *pStrLenPtr, int *pCursorPosPtr) { int CursorPos = *pCursorPosPtr; int Len = *pStrLenPtr; bool Changes = false; if(CursorPos > Len) CursorPos = Len; int Code = e.m_Unicode; int k = e.m_Key; // 127 is produced on Mac OS X and corresponds to the delete key if (!(Code >= 0 && Code < 32) && Code != 127) { char Tmp[8]; int CharSize = str_utf8_encode(Tmp, Code); if (Len < StrMaxSize - CharSize && CursorPos < StrMaxSize - CharSize) { mem_move(pStr + CursorPos + CharSize, pStr + CursorPos, Len - CursorPos + CharSize); for(int i = 0; i < CharSize; i++) pStr[CursorPos+i] = Tmp[i]; CursorPos += CharSize; Len += CharSize; Changes = true; } } if(e.m_Flags&IInput::FLAG_PRESS) { if (k == KEY_BACKSPACE && CursorPos > 0) { int NewCursorPos = str_utf8_rewind(pStr, CursorPos); int CharSize = CursorPos-NewCursorPos; mem_move(pStr+NewCursorPos, pStr+CursorPos, Len - NewCursorPos - CharSize + 1); // +1 == null term CursorPos = NewCursorPos; Len -= CharSize; Changes = true; } else if (k == KEY_DELETE && CursorPos < Len) { int p = str_utf8_forward(pStr, CursorPos); int CharSize = p-CursorPos; mem_move(pStr + CursorPos, pStr + CursorPos + CharSize, Len - CursorPos - CharSize + 1); // +1 == null term Len -= CharSize; Changes = true; } else if (k == KEY_LEFT && CursorPos > 0) CursorPos = str_utf8_rewind(pStr, CursorPos); else if (k == KEY_RIGHT && CursorPos < Len) CursorPos = str_utf8_forward(pStr, CursorPos); else if (k == KEY_HOME) CursorPos = 0; else if (k == KEY_END) CursorPos = Len; } *pCursorPosPtr = CursorPos; *pStrLenPtr = Len; return Changes; }