int main(int, char**) { // Two trival function calls to inline incrementX(); incrementX(); int a = 0; while (a < 5) { ++a; } // Something more interesting to inline for (; foo() < 7;) { x++; } int b = 0; while (b < 5) { ++b; } return 0; }
int Pacman::update(char gameboard[][28]) { int new_x = getNextX(); int new_y = getNextY(); boolean move = true; switch(gameboard[new_y][new_x]) { case 'd': case 'u': case '0': break; case '9': wrap(); break; case 'a': case 'c': case 'f': case 's': //die(); // :( default: move = false; break; } if(move) { incrementX(); incrementY(); } return gameboard[int(y)][int(x)]; }
Vec2 Text::measureString(const std::string& str) { float x = 0.0f; float y = 0.0f; Uint32 currentChar; Font::Character character; for (auto& c : str) { if (c == '\t') { incrementX(x, y, _font._base * 4.0f); continue; } else if (c == '\n') { y += getLineHeight(); x = 0.0f; continue; } currentChar = Uint32(c); auto charIt = _font._characters.find(currentChar); if (charIt != _font._characters.end()) { character = charIt->second; } else { incrementX(x, y, (float)_font._base); continue; } if (_lineWidth > 0 && x + character.xadvance >= _lineWidth) { x = 0.0f; y += getLineHeight(); } x += character.xadvance; } return Vec2(x, y + getLineHeight()); }
osg::Geometry* ShapeVisitor_VisualizerCreator::createGridGeometry( int size, int noOfLines, osg::Vec3f center ) { osg::Geometry* geom = new osg::Geometry(); osg::Vec3Array* positionsOfLines = new osg::Vec3Array; geom->setVertexArray( positionsOfLines ); // position of borders osg::Vec3f dif1( ( osg::Vec3f::value_type )( -size/2 ), ( osg::Vec3f::value_type )( size/2 ), -10 ); // top left osg::Vec3f dif2( ( osg::Vec3f::value_type )( -size/2 ), ( osg::Vec3f::value_type )( -size/2 ), -10 ); osg::Vec3f dif3( ( osg::Vec3f::value_type )( size/2 ), ( osg::Vec3f::value_type )( size/2 ), -10 ); // increment for creating points of mesh at border osg::Vec3f incrementX( ( osg::Vec3f::value_type )( size/noOfLines ), 0, 0 ); osg::Vec3f incrementY( 0, ( osg::Vec3f::value_type )( -size/noOfLines ), 0 ); // computing and saving positions of points at border of mesh for ( int i=0; i<2; i++ ) { osg::Vec3f base1 = center + dif1; osg::Vec3f base2 = center + dif2; // computing positions at x axis for ( int j=0; j<noOfLines; j++ ) { positionsOfLines->push_back( base1 + incrementX ); base1 += incrementX; positionsOfLines->push_back( base2 + incrementX + incrementY ); base2 += incrementX; } base1 = center + dif1; base2 = center + dif3; // computing positions at y axis for ( int j=0; j<noOfLines; j++ ) { positionsOfLines->push_back( base1 + incrementY ); base1 += incrementY; positionsOfLines->push_back( base2 + incrementY + incrementX ); base2 += incrementY; } // connecting two corresponding points at border of mesh for ( int k=0; k<noOfLines*4; k=k+2 ) { osg::DrawElementsUInt* line = new osg::DrawElementsUInt( osg::PrimitiveSet::LINES, 0 ); line->push_back( k ); line->push_back( k+1 ); geom->addPrimitiveSet( line ); } } return geom; }
void Hero::logic() { //logic if(currentKeyStates[SDL_SCANCODE_DOWN] == true && currentKeyStates[SDL_SCANCODE_UP] == false) { incrementY(1); } else if(currentKeyStates[SDL_SCANCODE_UP] == true && currentKeyStates[SDL_SCANCODE_DOWN] == false) { incrementY(-1); } if(currentKeyStates[SDL_SCANCODE_RIGHT] == true && currentKeyStates[SDL_SCANCODE_LEFT] == false) { incrementX(1); } else if(currentKeyStates[SDL_SCANCODE_LEFT] == true && currentKeyStates[SDL_SCANCODE_RIGHT] == false) { incrementX(-1); } if(currentKeyStates[SDL_SCANCODE_SPACE] == true) { //animation->load("herosad"); animation->start("herosad.png", getId()); } if(currentKeyStates[SDL_SCANCODE_Z]== true) { //SDL_Log("Z input detected"); animation->start("herosinks.png", getId()); } }
void Text::updateCharacters() { for (auto& character : _characters) { removeChild(character.get()); } _characters.clear(); int previousChar = 0; float x = 0.0f; float y = 0.0f; Uint32 currentChar; Font::Character character; for (Uint32 i = 0; i < _str.length(); ++i) { if (_str[i] == '\t') { incrementX(x, y, _font._base * 4.0f); continue; } else if (_str[i] == '\n') { y += getLineHeight(); x = 0.0f; continue; } currentChar = Uint32(_str[i]); auto charIt = _font._characters.find(currentChar); if (charIt != _font._characters.end()) { character = charIt->second; } else { incrementX(x, y, (float)_font._base); continue; } auto& page = _font._pages[character.page]; int kerning = 0; auto kernIt = character.kernings.find(previousChar); if (kernIt != character.kernings.end()) { kerning = kernIt->second; } if (_lineWidth > 0 && x + character.xadvance >= _lineWidth) { x = 0.0f; y += getLineHeight(); } float px = x + character.xoffset; float py = y + character.yoffset; if (_useKerning) { px += kerning; } auto charSprite = std::make_shared<Sprite>(); charSprite->getTexture() = *page; charSprite->setTextureRect((float)character.x, (float)character.y, (float)character.width, (float)character.height); charSprite->setPosition(px, py); charSprite->setColor(_color); charSprite->setTag(i); addChild(charSprite); _characters.push_back(charSprite); x += character.xadvance; previousChar = currentChar; } }
int main() { incrementX(); incrementX(); return x; }