void GUIWindow::postUpdate() { //Check size and positioning before drawing strech if (!checkBit(state, GUIRECT_SCALED)) updateScale(); if (!checkBit(state, GUIRECT_POSITIONED)) updatePosition(); strech->postUpdate(); GUIRectangleContainer::postUpdate(); header->postUpdate(); exit->postUpdate(); }
void System::getStandardProcessorExtensions() { #if ! defined(G3D_OSX) || defined(G3D_OSX_INTEL) if (! m_hasCPUID) { return; } uint32 eaxreg = 0, ebxreg = 0, ecxreg = 0, features = 0; cpuid(CPUID_PROCESSOR_FEATURES, eaxreg, ebxreg, ecxreg, features); # define checkBit(var, bit) ((var & (1 << bit)) ? true : false) m_hasRDTSC = checkBit(features, 4); m_hasMMX = checkBit(features, 23); m_hasSSE = checkBit(features, 25); m_hasSSE2 = checkBit(features, 26); // Bit 28 is HTT; not checked by G3D m_hasSSE3 = checkBit(ecxreg, 0); if (m_highestCPUIDFunction >= CPUID_EXTENDED_FEATURES) { cpuid(CPUID_EXTENDED_FEATURES, eaxreg, ebxreg, ecxreg, features); m_hasAMDMMX = checkBit(features, 22); // Only on AMD m_has3DNOW = checkBit(features, 31); // Only on AMD m_has3DNOW2 = checkBit(features, 30); // Only on AMD } else { m_hasAMDMMX = false; m_has3DNOW = false; m_has3DNOW2 = false; } # undef checkBit #endif }
void SAXParser::processElement() { Element element; // C.3.3 If the optional component attributes is present, then the bit '1' (presence) is appended to the bit stream; // otherwise, the bit '0' (absence) is appended. bool hasAttributes = checkBit(_b, 2) != 0; // C.3.4 If the optional component namespace-attributes is present, it is encoded as described in the three // following subclauses. // C.3.4.1 The four bits '1110' (presence) and the two bits '00' (padding) are appended to the bit stream. // check for namespace attributes if((_b & Constants::ELEMENT_NAMESPACE_ATTRIBUTES_MASK) == Constants::ELEMENT_NAMESPACE_ATTRIBUTES_FLAG) { throw std::runtime_error("No namespace support yet"); } // C.3.5 The value of the component qualified-name is encoded as described in C.18. getQualifiedNameOrIndex3(element._qualifiedName); if(hasAttributes) processAttributes(); _contentHandler->startElement(_vocab, element, _attributes); _attributes.clear(); while(!_terminated) { _b = static_cast<unsigned char>(_stream->get()); if(!checkBit(_b, 1)) { // 0 padding announcing element processElement(); } else if((_b & Constants::TWO_BITS) == Constants::ELEMENT_CHARACTER_CHUNK) { processCharacterChunk(); } else if (_b == Constants::TERMINATOR_SINGLE || _b == Constants::TERMINATOR_DOUBLE) { _terminated = true; _doubleTerminated = _b == Constants::TERMINATOR_DOUBLE; } else throw std::runtime_error("message.decodingEIIs"); } _contentHandler->endElement(_vocab, element); _terminated = _doubleTerminated; _doubleTerminated = false; }
int unweightedUndirected::checkBit(int r, int c) /* return the value (0 or 1) of the bit in row r and column c without changing the values of any bits (including those being tested). */ { if (c > r) return checkBit(c, r); else if (c == r) return main_diagonal; else return (bool)(*matrix)[t(r)+c]; }
int getStringAsInt(const std::string& string) { int8_t stringState = 0; int intValue = 0; for (unsigned i = 0; i < string.size(); i++) { if (string[i] >= '0' && string[i] <= '9') {//Add numerical value { intValue *= 10; intValue += int(string[i] - 48); } } else if (string[i] == '-') { if (checkBit(stringState, 1)) {//Second '-' character, return return 0.0f; } enableBit(stringState, 1);//Negative } else if (string[i] == '.' || string[i] == ',') { if (checkBit(stringState, 2)) {//Second ',/.' character, return return 0.0f; } enableBit(stringState, 2);//Begin decimal part } else {//Character is unknown return 0.0f; } } //negate if needed if (checkBit(stringState, 1)) intValue *= -1; return intValue; }
void unweightedUndirected::print() /* should output the array one full row at a time of 0's and 1's. Note that both, including the triangular array, should be output as a sz x sz array on the screen. (It's okay if lines too long for the screen wrap.) */ { for (int row = 0; row < size; row++) { for (int col = 0; col < size; col++) std::cout << checkBit(row, col) << " "; std::cout << std::endl; } }
uint16_t analogRead(uint8_t ch) { uint16_t value; ADMUX = adcSetting | ch; // Set the desired channel sbi(ADCSRA,ADSC); // Start conversion while(checkBit(ADCSRA,ADSC)); // Wait for conversion value = ADCL; value += ADCH << 8; // Read the result return value; // Return value }
Node eccMul(BigNum k, Node P, BigNum a, BigNum b, BigNum p){ int i; Node ret; initNode(&ret); u_int32_t num = checkBit(k, k.bits - 1); if(num == 1){ ret = copyNode(P); } // else ret = (0, 0) for(i = k.bits - 2; i >= 0; i--){ ret = eccAdd(ret, ret, a, b, p); // get e[i] num = checkBit(k, i); if(num == 1){ ret = eccAdd(ret, P, a, b, p); } } return ret; }
void SAXParser::processDocument() { _contentHandler->startDocument(); processDocumentProperties(); // Process children while(!_terminated) { _b = static_cast<unsigned char>(_stream->get()); if(!checkBit(_b, 1)) { // 0 padding announcing element processElement(); } } _contentHandler->endDocument(); }
/////////////////////// // IO SERVICE THREAD // void Game::receiveHandlerTCP(const boost::system::error_code& error, std::size_t bytes) { //Handle data sent by the server size_t offset = 0;//Byte offset from buffer begin do { offset += 1; switch (packet::PacketType(receiveBufferTCP[offset - 1])) { default: case packet::invalid: spehs::console::error(__FUNCTION__" invalid packet type!"); break; case packet::enterID: { std::lock_guard<std::recursive_mutex> IDLockGuardMutex(idMutex); memcpy(&ID, &receiveBufferTCP[offset], sizeof(sizeof(ID))); offset += sizeof(CLIENT_ID_TYPE); } break; case packet::createObj: { std::lock_guard<std::recursive_mutex> objectLockGuardMutex(objectMutex); unsigned count; memcpy(&count, &receiveBufferTCP[offset], sizeof(unsigned)); offset += sizeof(unsigned); for (unsigned i = 0; i < count; i++) { newObjects.push_back(ObjectData()); memcpy(&newObjects.back(), &receiveBufferTCP[offset], sizeof(ObjectData)); offset += sizeof(ObjectData); } } break; } } while (offset < bytes); //Start receiving again if (checkBit(state, GAME_EXIT_BIT)) socketTCP.async_receive( boost::asio::buffer(receiveBufferTCP), boost::bind(&Game::receiveHandlerTCP, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); }
void interrupt ISR(void) { //Turn ON/OFF RC3 in order to indicate //that an interrupt occured //useful for debugging if(checkBit(ShadowPortC,3)>0){ SetBitReg(Reg_PORTC,3,LOW); } else{ SetBitReg(Reg_PORTC,3,HIGH); } //UART interrupt if(RCIF && RCIE){ UART_Interrupt(); return; } }
void SAXParser::processAttributes() { do { _b = static_cast<unsigned char>(_stream->get()); if (!checkBit(_b,1)) { FI::Attribute attribute; getAttribute(attribute); _attributes.push_back(attribute); } else if (_b == Constants::TERMINATOR_SINGLE || _b == Constants::TERMINATOR_DOUBLE) { _terminated = true; _doubleTerminated = _b == Constants::TERMINATOR_DOUBLE; } else throw std::runtime_error("message.decodingAIIs"); } while(!_terminated); _terminated = _doubleTerminated; _doubleTerminated = false; }
void GUIWindow::update() { //Clicking within window -> gaining focus //if (checkState(GUIRECT_ENABLED_BIT) && !isFocused() && isOpen() && inputManager->isKeyPressed(MOUSE_BUTTON_LEFT) && (strech->updateMouseHover() || getMouseHover())) //gainFocus(); //Run update in all members GUIRectangleContainer::update(); header->update(); exit->update(); strech->update(); if (strech->getMouseHover()) { enableBit(state, GUIRECT_MOUSE_HOVER); enableBit(state, GUIRECT_MOUSE_HOVER_CONTAINER); } ////DRAGGING //Handle previous frame dragging if (checkState(GUIRECT_DRAGGING_BIT) && inputManager->isKeyDown(MOUSE_BUTTON_LEFT)) translate(inputManager->getMouseMovementX(), inputManager->getMouseMovementY()); //Set dragging boolean if (checkState(GUIRECT_ENABLED_BIT) && !checkState(GUIRECT_DRAGGING_BIT) && header->getMouseHover() && inputManager->isKeyPressed(MOUSE_BUTTON_LEFT)) enableState(GUIRECT_DRAGGING_BIT);//Begin dragging else if (checkState(GUIRECT_DRAGGING_BIT) && !inputManager->isKeyDown(MOUSE_BUTTON_LEFT)) {//Stop dragging #ifdef DOCK_BORDER //Check docking if (inputManager->getMouseX() < DOCK_BORDER) {//Dock left setSize(minSize.x, applicationData->getWindowHeight() - upBorder - downBorder - header->getHeight() - 2 * strechWidth); setPositionLocal(strechWidth + leftBorder, strechWidth + downBorder); } else if (inputManager->getMouseX() > applicationData->getWindowWidth() - DOCK_BORDER) {//Dock right setSize(minSize.x, applicationData->getWindowHeight() - upBorder - downBorder - header->getWidth() - 2 * strechWidth); setPositionLocal(applicationData->getWindowWidth() - size.x - strechWidth - rightBorder, strechWidth + downBorder); } if (inputManager->getMouseY() < DOCK_BORDER) {//Dock down setSize(applicationData->getWindowWidth() - 2 * strechWidth - leftBorder - rightBorder, minSize.y); setPositionLocal(strechWidth + leftBorder, strechWidth + downBorder); } else if (inputManager->getMouseY() > applicationData->getWindowHeight() - DOCK_BORDER) {//Dock up setSize(applicationData->getWindowWidth() - 2 * strechWidth - leftBorder - rightBorder, minSize.y); setPositionLocal(strechWidth + leftBorder, applicationData->getWindowHeight() - header->getHeight() - strechWidth - size.y - upBorder); } #endif limitWithinMainWindow(); disableState(GUIRECT_DRAGGING_BIT); } ////STRECHING //Handle previous frame strech if (checkState(GUIRECT_STRECHING_BIT) && inputManager->isKeyDown(MOUSE_BUTTON_LEFT)) { //Take record of current dimensions float w = size.x; float h = size.y; bool breakFromStrech = false; //Check horizontal strech movement if (checkBit(strechState, STRECH_STATE_HORIZONTAL)) { //Check if mouse has crossed over to the opposite side of the window -> break from strech if (checkBit(strechState, STRECH_STATE_W)) {//Strech began from left side of the window if (inputManager->getMouseX() > getXGlobal() + size.x / 2.0f) breakFromStrech = true; } else {//Strech began from the right side of the window if (inputManager->getMouseX() < getXGlobal() + size.x / 2.0f) breakFromStrech = true; } //Strech window based on mouse movement if (!breakFromStrech) { if (inputManager->getMouseX() > position.x + size.x / 2.0f) { w += inputManager->getMouseMovementX(); } else { w -= inputManager->getMouseMovementX(); if (abs(size.x - minSize.x) > 0.01f) translate(inputManager->getMouseMovementX(), 0); } } } //Check vertical strech movement if (!breakFromStrech && checkBit(strechState, STRECH_STATE_VERTICAL)) { //Check if mouse has crossed over to the opposite side of the window -> break from strech if (checkBit(strechState, STRECH_STATE_N)) {//Strech began from upper side of the window if (inputManager->getMouseY() < getYGlobal() + size.y / 2.0f + header->getHeight() / 2.0f) breakFromStrech = true; } else {//Strech began from the lower side of the window if (inputManager->getMouseY() > getYGlobal() + size.y / 2.0f + header->getHeight() / 2.0f) breakFromStrech = true; } //Strech window based on mouse movement if (!breakFromStrech) { if (inputManager->getMouseY() > position.y + size.y / 2.0f) { h += inputManager->getMouseMovementY(); } else { h -= inputManager->getMouseMovement().y; if (abs(size.y - minSize.y) > 0.01f) translate(0, inputManager->getMouseMovementY()); } } } //Set size to the calculated dimensions setSize(w, h); //position within main application window limitWithinMainWindow(); } //Handle strech state bit if (checkState(GUIRECT_ENABLED_BIT) && !checkState(GUIRECT_STRECHING_BIT) && inputManager->isKeyPressed(MOUSE_BUTTON_LEFT) && mouseOverStrechArea()) {//Begin streching ////Define state variables enableState(GUIRECT_STRECHING_BIT); strechState = 0; //Horizontal if (inputManager->getMouseX() < getXGlobal() + size.x * STRECH_CORNER_PERCENTAGE) { //Enable horizontal streching enableBit(strechState, STRECH_STATE_HORIZONTAL); //Take record that the streching began from the western side of the window enableBit(strechState, STRECH_STATE_W); } else if (inputManager->getMouseX() > getXGlobal() + size.x * (1.0 - STRECH_CORNER_PERCENTAGE)) { //Enable horizontal streching enableBit(strechState, STRECH_STATE_HORIZONTAL); //Take record that the streching began from the eastern side of the window enableBit(strechState, STRECH_STATE_E); } //Vertical if (inputManager->getMouseY() < getYGlobal() + size.y * STRECH_CORNER_PERCENTAGE) { //Enable vertical streching enableBit(strechState, STRECH_STATE_VERTICAL); //Take record that the streching began from the southern side of the window enableBit(strechState, STRECH_STATE_S); } else if (inputManager->getMouseY() > getYGlobal() + size.y * (1.0 - STRECH_CORNER_PERCENTAGE)) { //Enable vertical streching enableBit(strechState, STRECH_STATE_VERTICAL); //Take record that the streching began from the northern side of the window enableBit(strechState, STRECH_STATE_N); } } else if (checkState(GUIRECT_STRECHING_BIT) && (!checkState(GUIRECT_ENABLED_BIT) || !inputManager->isKeyDown(MOUSE_BUTTON_LEFT))) {//Conditions not met to continue streching, set to false disableState(GUIRECT_STRECHING_BIT); strechState = 0; } ////Header double clicking //Timer decrease if (doubleClickTimer > 0) doubleClickTimer -= time::getDeltaTimeAsMilliseconds(); //Check header double click if (checkState(GUIRECT_ENABLED_BIT) && inputManager->isKeyPressed(MOUSE_BUTTON_LEFT) && header->getMouseHover()) {//Header has been clicked if (doubleClickTimer > 0) {//Header double click detected disableState(GUIRECT_DRAGGING_BIT); if (size == minSize) {//Set to full window //Set size according to application data's window dimensions setSize(applicationData->getWindowWidth() - rightBorder - leftBorder, applicationData->getWindowHeight() - upBorder - downBorder - header->getHeight()); setPositionLocal(0, 0); //Position window so that it won't go out of the application window limitWithinMainWindow(); } else {//Set to min size //Take record of the window's old center position so that resized window can be nicely centered at the same position glm::vec2 oldCenterPos(getXGlobal() + size.x / 2.0f, getYGlobal() + size.y / 2.0f); //Rezise to min size setSize(minSize); //Reposition relative to old center position (recorded earlier) setPositionLocal(oldCenterPos.x - size.x / 2.0f, oldCenterPos.y - size.y / 2.0f); //Position window so that it won't go out of the application window limitWithinMainWindow(); } } else doubleClickTimer = DOUBLE_CLICK_TIME; } //Check exit button if (checkState(GUIRECT_ENABLED_BIT) && inputManager->isKeyPressed(MOUSE_BUTTON_LEFT) && exit->getMouseHover()) close(); }
int main() { initShadowRegisters(); TRISC = 0; //RC0 as Output PIN //TRISC1 = 0; //Clear Analog Inputs and make pins digital pins ANSEL=0b00000001;//set RA0 as analog pin ANSELH=0; IRCF0 = 0b111;//set prescaler UART_Init(); UART_writeString("Startup ... done\n"); //ADC //Select ADC conversion clock Frc ADCON1bits.ADCS = 0b111; //Configure voltage reference using VDD ADCON0bits.VCFG = 0; //Select ADC input channel (RA0/AN0) ADCON0bits.CHS = 0; //Select result format right justified //right=1 is good when using all 10 bits the two bytes can be concatenated //easily into an integer //left=0 is good when using the 8 most significant bits ADCON0bits.ADFM = 1; //Turn on ADC module ADCON0bits.ADON = 1; while(1) { //--------------------------------------------- //Blink LED on RC0 and RC1 SetBitReg(Reg_PORTC,0,HIGH); SetBitReg(Reg_PORTC,1,LOW); __delay_ms(100); // 100ms Delay SetBitReg(Reg_PORTC,0,LOW); SetBitReg(Reg_PORTC,1,HIGH); __delay_ms(100); // 100ms Delay //--------------------------------------------- //--------------------------------------------- //UART communication while(UART_DataAvailable()>0){ //char a=UART_ReadByte(); //UART_writeByte(a); //UART_writeByte('\n'); UART_writeNumber(UART_DataAvailable()); UART_writeByte('\n'); UART_writeString(UART_ReadString()); UART_writeByte('\n'); } if(UART_DataAvailable()<0){ UART_writeString("Data Lost Reset UART\n"); UART_Reset(); } //Print a Register // UART_writeBitPattern(ANSELH); // UART_writeByte('\n'); //--------------------------------------------- //--------------------------------------------- //Read ADC Get_Inputs(); unsigned int ADC_Value=0; ADC_Value=ADRESH<<8 | ADRESL; UART_writeNumber(ADC_Value); UART_writeByte('\n'); if(checkBit(ShadowPortC,1)>0) SetBitReg(Reg_PORTC,2,HIGH); //--------------------------------------------- } return 0; }
//TSP 본체 int travel(int start, const int W[][13], int P[][4096], int b[], int D[][MAX_BINT]){ //반복 변수 int i, j, k; //D가 되는 개수 변수, 주소 변수 int cnt=0, index=0; //부분집합을 표현하는 비트 int bitS=0; //임시 D값 저장 배열, 임시 최단 거리 주소 저장 배열 int temp[12]={MAX,MAX,MAX,MAX,MAX,MAX,MAX,MAX,MAX,MAX,MAX,MAX}, indexP[12]={0,}; //출발점 제외한 나머지 거리에서 도착점까지 최단 경로 저장 for(i=1;i<=CITYCOUNT;++i) if(i!=start) D[i][0]=W[i][start]; //부분집합 1~10개의 경우 계산 for(k=1;k<=CITYCOUNT-2;++k){ //개수에 맞는 최초부분집합 계산 bitS=0; for(j=0;j<=k;++j){ b[j]=1; bitS |= (int)pow(2.0, j); } b[start-1]=0; bitS ^= (int)pow(2.0, start-1); while(1){ for(j=1;j<=CITYCOUNT;++j){ //부분집합 A, 출발점에 포함되면 넘어감 if((bitS & (1<<(j-1)))>0) continue; //A인 경우에 D행렬, P행렬의 일부 계산 for(i=1, cnt=0;cnt<k;++i){ if((bitS & (1<<(i-1)))>0){ temp[cnt]=W[j][i]+D[i][bitS^(1<<i)]; indexP[cnt]=i; ++cnt; } } D[j][bitS]=minD(temp, cnt, &index); P[j][bitS]=indexP[index]; } //비트수 검사하여 개수 맞으면 계속 진행, 범위 초과시 종료 while(1){ ++bitS; //범위 초과시 반복 종료 if(bitS>4095) break; //개수 일치 시 반복 종료 else if(checkBit(bitS)==k) break; } //범위 초과 시 구문 종료 if(bitS>4095) break; } } //출발 제외한 나머지 경로 거칠 때 경우 계산 bitS=4095; bitS^=(int)pow(2.0, start-1); for(i=1, cnt=0;cnt<CITYCOUNT-1;++i){ if((bitS & (1<<(i-1)))>0){ temp[cnt]=W[start][i]+D[i][bitS^(1<<j)]; indexP[cnt]=i; ++cnt; } } D[start][bitS]=minD(temp,cnt,&index); P[start][bitS]=indexP[index]; return D[start][bitS]; }
void Game::run() { //Connect TCP bool success = false; do { try { serverEndpointTCP = *resolverTCP.resolve(queryTCP); socketTCP.open(boost::asio::ip::tcp::v4()); socketTCP.connect(serverEndpointTCP); //Send enter packet to server boost::array<unsigned char, 1> enterPacket = { packet::enter }; socketTCP.send(boost::asio::buffer(enterPacket)); socketTCP.send(boost::asio::buffer(enterPacket)); socketTCP.send(boost::asio::buffer(enterPacket)); //Wait for receiving return data size_t bytes = socketTCP.receive(boost::asio::buffer(receiveBufferTCP)); boost::system::error_code e; receiveHandlerTCP(e, bytes); success = true; } catch (std::exception& e) { std::cout << "\n" << e.what(); } } while (!success); //Connect UDP success = false; do { try { serverEndpointUDP = *resolverUDP.resolve(queryUDP); socketUDP.open(boost::asio::ip::udp::v4()); socketUDP.connect(serverEndpointUDP); boost::array<unsigned char, sizeof(CLIENT_ID_TYPE) + sizeof(packet::PacketType)> enterUDP; enterUDP[0] = packet::enterUdpEndpoint; memcpy(&enterUDP[sizeof(packet::PacketType)], &ID, sizeof(ID)); socketUDP.send(boost::asio::buffer(enterUDP)); socketUDP.receive(boost::asio::buffer(enterUDP));//Wait for server response success = true; } catch (std::exception& e) { std::cout << "\n" << e.what(); } } while (!success); std::thread ioServiceThread(boost::bind(&boost::asio::io_service::run, &ioService)); while (!checkBit(state, GAME_EXIT_BIT)) { mainWindow->clearBuffer(); spehs::beginFPS(); //Update spehs::console::update(); inputManager->update(); update(); //Render render(); spehs::console::render(); spehs::endFPS(); spehs::drawFPS(); mainWindow->swapBuffers(); if (inputManager->isKeyDown(KEYBOARD_Q)) enableBit(state, GAME_EXIT_BIT); } //Notify server exitGame(); ioServiceThread.join(); }