void BinaryWriter::WriteUInt16(unsigned short us) { CheckResize(sizeof(unsigned short)); //TODO: endian *(unsigned short*)(m_data+m_pos) = us; m_pos += sizeof(unsigned short); }
void BinaryWriter::WriteInt64(FdoInt64 ll) { CheckResize(sizeof(FdoInt64)); //TODO: endian *(FdoInt64*)(m_data+m_pos) = ll; m_pos += sizeof(FdoInt64); }
void BinaryWriter::WriteInt16(short s) { CheckResize(sizeof(short)); //TODO: endian *(short*)(m_data+m_pos) = s; m_pos += sizeof(short); }
//writes a byte array void BinaryWriter::WriteBytes(unsigned char* buf, int len) { CheckResize(len); memcpy(m_data + m_pos, buf, len); m_pos += len; }
void BinaryWriter::WriteDouble(double d) { CheckResize(sizeof(double)); //TODO: endian *(double*)(m_data+m_pos) = d; m_pos += sizeof(double); }
void BinaryWriter::WriteInt32(int i) { CheckResize(sizeof(int)); //TODO: endian *(int*)(m_data+m_pos) = i; m_pos += sizeof(int); }
void BinaryWriter::WriteUInt32(unsigned i) { CheckResize(sizeof(unsigned)); //TODO: endian *(unsigned*)(m_data+m_pos) = i; m_pos += sizeof(unsigned); }
void BinaryWriter::WriteString(const wchar_t* src) { unsigned srcLen = 0; //handle empty string if (src == NULL || (srcLen = (unsigned)wcslen(src)) == 0 ) { WriteInt32(0); return; } unsigned maxmbslen = srcLen * 4 + 1; if (m_strCacheLen < maxmbslen) { delete [] m_strCache; m_strCacheLen = maxmbslen; m_strCache = new char[maxmbslen]; } int actualLen = ut_utf8_from_unicode(src, srcLen, m_strCache, m_strCacheLen); _ASSERT(actualLen >= 0); actualLen += 1; //add 1 for null character CheckResize(actualLen + sizeof(unsigned)); //write string length (number of bytes, not characters!!!) WriteUInt32(actualLen); //write actual string content to the output memcpy(m_data + m_pos, m_strCache, actualLen); m_pos += actualLen; }
void BinaryWriter::WriteSingle(float f) { CheckResize(sizeof(float)); //TODO: endian *(float*)(m_data+m_pos) = f; m_pos += sizeof(float); }
void CGUIStaticText::Resize(float _sx, float _sy) { CheckResize(_sx,_sy); if(text) { text->Resize(_sx,_sy); SetSize(_sx,_sy); } // !@#$ viceradkovy text nepodporuje resize !!! }
void DrawGame(GameRenderer* g, World* world) { CheckResize(g, world); //Prepare to render to texture. SDL_SetRenderTarget(g->renderer, g->gameTexture); //Clear screen SDL_SetRenderDrawColor( g->renderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( g->renderer ); //Draw our grid //Resizing the background grid looks terrible. if(g->zoom >= 0) { DrawBackgroundGrid( g->renderer, g->screenGame.w, g->screenGame.h, &g->gridProps ); } DrawCells(g->renderer, &g->gridProps, world); SDL_RenderPresent( g->renderer ); //Now draw the rest of the screen SDL_SetRenderTarget(g->renderer, NULL); SDL_SetRenderDrawColor( g->renderer, 180, 180, 180, 255 ); SDL_RenderClear( g->renderer ); SDL_RenderCopy(g->renderer, g->gameTexture, NULL, &(g->screenGame)); //Draw the ring of greyed-out game areas around our game area, to represent world wrapping to the user. SDL_SetTextureColorMod(g->gameTexture, 240, 240, 240); int startX = g->screenGame.x - g->screenGame.w; int startY = g->screenGame.y - g->screenGame.h; SDL_Rect current; current.w = g->screenGame.w; current.h = g->screenGame.h; for(int iterX = 0; iterX < 3; ++iterX) { for(int iterY = 0; iterY < 3; ++iterY) { //Don't draw over primary game area. if( ! ((iterX == 1) && (iterY == 1))) { current.x = startX + (current.w * iterX); current.y = startY + (current.h * iterY); SDL_RenderCopy(g->renderer, g->gameTexture, NULL, ¤t); } } } SDL_SetTextureColorMod(g->gameTexture, 255, 255, 255); SDL_RenderPresent(g->renderer); }
int Engine::RunLoop() { // Create the context Context context; // Set the context renderer context.pRenderer = new Renderer(); // Init the engine if (!this->Initialize()) { return 0; } Logger::Log(_T("Engine Initialize succeded"), LOGTYPE_INFO, false); // Get a random number srand(GetTickCount()); // Set a new MSG to empty MSG msg = {}; // Change the Engine state m_EngineState = EngineState::Running; // Start the run loop while (msg.message != WM_QUIT && m_EngineState == EngineState::Running) { // Check if the user is trying to change the window size CheckResize(); // Check the message and remove the message from the queue if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } // Update and draw this->Update(context); this->Draw(context); } Logger::Log(_T("Ending program"), LOGTYPE_INFO, false); Logger::WriteLogFile(); // Shut down the engine if (!this->ShutDown()) { return 0; } // End the program with the msg param return (int)msg.wParam; }
void BinaryWriter::WriteRawString(const wchar_t* src) { int srcLen = 0; //handle null string if (src == NULL) { return; } //handle empty string -> write trailing 0 //NOTE: NOT the same as NULL. if ((srcLen = (unsigned)wcslen(src)) == 0) { WriteByte(0); return; } unsigned maxmbslen = srcLen * 4 + 1; if (m_strCacheLen < maxmbslen) { delete [] m_strCache; m_strCacheLen = maxmbslen; m_strCache = new char[maxmbslen]; } int actualLen = ut_utf8_from_unicode(src, srcLen, m_strCache, m_strCacheLen); _ASSERT(actualLen >= 0); actualLen += 1; //add 1 for null character CheckResize(actualLen + sizeof(int)); //RAW WRITE - do not write length, we know how to compute it from the //property offsets at the beginning of the data record /* //write string length (number of bytes, not characters!!!) WriteInt32(actualLen); */ //write actual string content to the output memcpy(m_data + m_pos, m_strCache, actualLen); m_pos += actualLen; }
void CGUILine::Resize(float _sx, float _sy) { float lsx, lsy; GetSize(lsx,lsy); CheckResize(_sx,_sy); if(lsy==1) { if(left_right) SetPoints(x,y,x+_sx-1,y); else SetPoints(x+_sx-1,y,x,y); //SetSize(_sx,0); }else if(lsx==1) { if(up_down) SetPoints(x,y,x,y+_sy-1); else SetPoints(x,y+_sy-1,x,y); //SetSize(0,_sy); }else if(up_down) { if(left_right) SetPoints(x,y,x+_sx-1,y+_sy-1); else SetPoints(x+_sx-1,y,x,y+_sy-1); //SetSize(_sx,_sy); }else if(!up_down) { if(left_right) SetPoints(x,y+_sy-1,x+_sx-1,y); else SetPoints(x+_sx-1,y+_sy-1,x,y); //SetSize(_sx,_sy); } }
RadixSort& RadixSort::Sort(const float* input2, uint32 nb) { // Checkings if(!input2 || !nb || nb&0x80000000) return *this; // Stats mTotalCalls++; const uint32* input = (const uint32*)input2; // Resize lists if needed CheckResize(nb); // Allocate histograms & offsets on the stack uint32 Histogram[256*4]; uint32* Link[256]; // Create histograms (counters). Counters for all passes are created in one run. // Pros: read input buffer once instead of four times // Cons: mHistogram is 4Kb instead of 1Kb // Floating-point values are always supposed to be signed values, so there's only one code path there. // Please note the floating point comparison needed for temporal coherence! Although the resulting asm code // is dreadful, this is surprisingly not such a performance hit - well, I suppose that's a big one on first // generation Pentiums....We can't make comparison on integer representations because, as Chris said, it just // wouldn't work with mixed positive/negative values.... { CREATE_HISTOGRAMS(float, input2); } // Radix sort, j is the pass number (0=LSB, 3=MSB) for(uint32 j=0;j<4;j++) { // Should we care about negative values? if(j!=3) { // Here we deal with positive values only CHECK_PASS_VALIDITY(j); if(PerformPass) { // Create offsets Link[0] = m_Ranks2; for(uint32 i=1;i<256;i++) Link[i] = Link[i-1] + CurCount[i-1]; // Perform Radix Sort const unsigned char* InputBytes = (const unsigned char*)input; InputBytes += BYTES_INC; if(INVALID_RANKS) { for(uint32 i=0;i<nb;i++) *Link[InputBytes[i<<2]]++ = i; VALIDATE_RANKS; } else { const uint32* Indices = m_Ranks; const uint32* IndicesEnd = &m_Ranks[nb]; while(Indices!=IndicesEnd) { const uint32 id = *Indices++; *Link[InputBytes[id<<2]]++ = id; } } // Swap pointers for next pass. Valid indices - the most recent ones - are in mRanks after the swap. uint32* Tmp = m_Ranks; m_Ranks = m_Ranks2; m_Ranks2 = Tmp; } } else { // This is a special case to correctly handle negative values CHECK_PASS_VALIDITY(j); if(PerformPass) { #ifdef KYLE_HUBERT_VERSION // From Kyle Hubert: Link[255] = m_Ranks2 + CurCount[255]; for(uint32 i=254;i>127;i--) Link[i] = Link[i+1] + CurCount[i]; Link[0] = Link[128] + CurCount[128]; for(uint32 i=1;i<128;i++) Link[i] = Link[i-1] + CurCount[i-1]; #else // Compute #negative values involved if needed uint32 NbNegativeValues = 0; // An efficient way to compute the number of negatives values we'll have to deal with is simply to sum the 128 // last values of the last histogram. Last histogram because that's the one for the Most Significant Byte, // responsible for the sign. 128 last values because the 128 first ones are related to positive numbers. // ### is that ok on Apple ?! const uint32* h3 = &Histogram[H3_OFFSET]; for(uint32 i=128;i<256;i++) NbNegativeValues += h3[i]; // 768 for last histogram, 128 for negative part // Create biased offsets, in order for negative numbers to be sorted as well Link[0] = &m_Ranks2[NbNegativeValues]; // First positive number takes place after the negative ones for(uint32 i=1;i<128;i++) Link[i] = Link[i-1] + CurCount[i-1]; // 1 to 128 for positive numbers // We must reverse the sorting order for negative numbers! Link[255] = m_Ranks2; for(uint32 i=0;i<127;i++) Link[254-i] = Link[255-i] + CurCount[255-i]; // Fixing the wrong order for negative values for(uint32 i=128;i<256;i++) Link[i] += CurCount[i]; // Fixing the wrong place for negative values #endif // Perform Radix Sort if(INVALID_RANKS) { for(uint32 i=0;i<nb;i++) { const uint32 Radix = input[i]>>24; // Radix byte, same as above. AND is useless here (uint32). // ### cmp to be killed. Not good. Later. if(Radix<128) *Link[Radix]++ = i; // Number is positive, same as above else *(--Link[Radix]) = i; // Number is negative, flip the sorting order } VALIDATE_RANKS; } else { for(uint32 i=0;i<nb;i++) { const uint32 Radix = input[m_Ranks[i]]>>24; // Radix byte, same as above. AND is useless here (uint32). // ### cmp to be killed. Not good. Later. if(Radix<128) *Link[Radix]++ = m_Ranks[i]; // Number is positive, same as above else *(--Link[Radix]) = m_Ranks[i]; // Number is negative, flip the sorting order } } // Swap pointers for next pass. Valid indices - the most recent ones - are in mRanks after the swap. uint32* Tmp = m_Ranks; m_Ranks = m_Ranks2; m_Ranks2 = Tmp; } else { // The pass is useless, yet we still have to reverse the order of current list if all values are negative. if(UniqueVal>=128) { if(INVALID_RANKS) { // ###Possible? for(uint32 i=0;i<nb;i++) m_Ranks2[i] = nb-i-1; VALIDATE_RANKS; } else { for(uint32 i=0;i<nb;i++) m_Ranks2[i] = m_Ranks[nb-i-1]; } // Swap pointers for next pass. Valid indices - the most recent ones - are in mRanks after the swap. uint32* Tmp = m_Ranks; m_Ranks = m_Ranks2; m_Ranks2 = Tmp; } } }
bool TopCanvas::CheckResize() { return CheckResize(GetNativeSize()); }
void BinaryWriter::WriteChar(char c) { CheckResize(sizeof(char)); *(m_data+m_pos) = c; m_pos += sizeof(char); }
void BinaryWriter::WriteByte(unsigned char b) { CheckResize(sizeof(unsigned char)); *(m_data+m_pos) = b; m_pos += sizeof(unsigned char); }
int TRI_InsertElementHashArrayMulti (TRI_hash_array_multi_t* array, TRI_index_search_value_t const* key, TRI_hash_index_element_multi_t* element, bool isRollback) { if (! CheckResize(array)) { return TRI_ERROR_OUT_OF_MEMORY; } uint64_t const n = array->_nrAlloc; uint64_t i, k; i = k = HashKey(array, key) % n; for (; i < n && array->_table[i]._document != nullptr && ! IsEqualKeyElement(array, key, &array->_table[i]); ++i); if (i == n) { for (i = 0; i < k && array->_table[i]._document != nullptr && ! IsEqualKeyElement(array, key, &array->_table[i]); ++i); } TRI_ASSERT_EXPENSIVE(i < n); TRI_hash_index_element_multi_t* arrayElement = &array->_table[i]; // ........................................................................... // If we found an element, return. While we allow duplicate entries in the // hash table, we do not allow duplicate elements. Elements would refer to the // (for example) an actual row in memory. This is different from the // TRI_InsertElementMultiArray function below where we only have keys to // differentiate between elements. // ........................................................................... bool found = (arrayElement->_document != nullptr); if (found) { if (isRollback) { if (arrayElement->_document == element->_document) { DestroyElement(array, element); return TRI_RESULT_ELEMENT_EXISTS; } auto current = arrayElement->_next; while (current != nullptr) { if (current->_document == element->_document) { DestroyElement(array, element); return TRI_RESULT_ELEMENT_EXISTS; } current = current->_next; } } auto ptr = GetFromFreelist(array); if (ptr == nullptr) { return TRI_ERROR_OUT_OF_MEMORY; } // link our element at the list head ptr->_document = element->_document; ptr->_subObjects = element->_subObjects; ptr->_next = arrayElement->_next; arrayElement->_next = ptr; // it is ok to destroy the element here, because we have copied its internal before! element->_subObjects = nullptr; DestroyElement(array, element); return TRI_ERROR_NO_ERROR; } TRI_ASSERT(arrayElement->_next == nullptr); // not found in list, now insert element->_next = nullptr; *arrayElement = *element; array->_nrUsed++; TRI_ASSERT(arrayElement->_next == nullptr); return TRI_ERROR_NO_ERROR; }
RadixSort& RadixSort::Sort(const uint32* input, uint32 nb, eRadixHint hint) { // Checkings if(!input || !nb || nb&0x80000000) return *this; // Stats mTotalCalls++; // Resize lists if needed CheckResize(nb); // Allocate histograms & offsets on the stack uint32 Histogram[256*4]; uint32* Link[256]; // Create histograms (counters). Counters for all passes are created in one run. // Pros: read input buffer once instead of four times // Cons: mHistogram is 4Kb instead of 1Kb // We must take care of signed/unsigned values for temporal coherence.... I just // have 2 code paths even if just a single opcode changes. Self-modifying code, someone? if(hint==RADIX_UNSIGNED) { CREATE_HISTOGRAMS(uint32, input); } else { CREATE_HISTOGRAMS(int32, input); } // Radix sort, j is the pass number (0=LSB, 3=MSB) for(uint32 j=0;j<4;j++) { CHECK_PASS_VALIDITY(j); // Sometimes the fourth (negative) pass is skipped because all numbers are negative and the MSB is 0xFF (for example). This is // not a problem, numbers are correctly sorted anyway. if(PerformPass) { // Should we care about negative values? if(j!=3 || hint==RADIX_UNSIGNED) { // Here we deal with positive values only // Create offsets Link[0] = m_Ranks2; for(uint32 i=1;i<256;i++) Link[i] = Link[i-1] + CurCount[i-1]; } else { // This is a special case to correctly handle negative integers. They're sorted in the right order but at the wrong place. #ifdef KYLE_HUBERT_VERSION // From Kyle Hubert: Link[128] = m_Ranks2; for(uint32 i=129;i<256;i++) Link[i] = Link[i-1] + CurCount[i-1]; Link[0] = Link[255] + CurCount[255]; for(uint32 i=1;i<128;i++) Link[i] = Link[i-1] + CurCount[i-1]; #else // Compute #negative values involved if needed uint32 NbNegativeValues = 0; if(hint==RADIX_SIGNED) { // An efficient way to compute the number of negatives values we'll have to deal with is simply to sum the 128 // last values of the last histogram. Last histogram because that's the one for the Most Significant Byte, // responsible for the sign. 128 last values because the 128 first ones are related to positive numbers. const uint32* h3 = &Histogram[H3_OFFSET]; for(uint32 i=128;i<256;i++) NbNegativeValues += h3[i]; // 768 for last histogram, 128 for negative part } // Create biased offsets, in order for negative numbers to be sorted as well Link[0] = &m_Ranks2[NbNegativeValues]; // First positive number takes place after the negative ones for(uint32 i=1;i<128;i++) Link[i] = Link[i-1] + CurCount[i-1]; // 1 to 128 for positive numbers // Fixing the wrong place for negative values Link[128] = m_Ranks2; for(uint32 i=129;i<256;i++) Link[i] = Link[i-1] + CurCount[i-1]; #endif } // Perform Radix Sort const unsigned char* InputBytes = (const unsigned char*)input; InputBytes += BYTES_INC; if(INVALID_RANKS) { for(uint32 i=0;i<nb;i++) *Link[InputBytes[i<<2]]++ = i; VALIDATE_RANKS; } else { const uint32* Indices = m_Ranks; const uint32* IndicesEnd = &m_Ranks[nb]; while(Indices!=IndicesEnd) { const uint32 id = *Indices++; *Link[InputBytes[id<<2]]++ = id; } } // Swap pointers for next pass. Valid indices - the most recent ones - are in mRanks after the swap. uint32* Tmp = m_Ranks; m_Ranks = m_Ranks2; m_Ranks2 = Tmp; } } return *this; }