1342Fermer1344
Kevin KoflerLe 31/12/2015 à 01:04
Folco (./1329) :
Voici un bout de mon code du moment : // Create the button texture (transparent) and set it as render target m_Texture = SDL_CreateTexture(Game::get()->renderer(), px, SDL_TEXTUREACCESS_TARGET, width, height); if (m_Texture == nullptr) { throw Exception(ERROR_SDL_STR); } if (SDL_SetTextureBlendMode(m_Texture, SDL_BLENDMODE_BLEND) != 0) { cleanup(); throw Exception(ERROR_SDL_STR); } if (SDL_SetRenderDrawColor(Game::get()->renderer(), 0, 0, 0, 0) != 0) { cleanup(); throw Exception(ERROR_SDL_STR); } if (SDL_RenderClear(Game::get()->renderer()) != 0) { cleanup(); throw Exception(ERROR_SDL_STR); } if (SDL_SetRenderTarget(Game::get()->renderer(), m_Texture) != 0) { cleanup(); throw Exception(ERROR_SDL_STR); }Comme vous le voyez, on a 5 lignes de code utiles pour une vingtaine de lignes de vérification. Au début, ça va, puis ça facilite bien le débogage. Mais à un moment ça devient pénible à lire (sans parler du fait que ce n'est pas beau embarrassed).Comment s'y prendre pour alléger les choses ?
Personnellement, je mettrais: // Create the button texture (transparent) and set it as render target m_Texture = SDL_CreateTexture(Game::get()->renderer(), px, SDL_TEXTUREACCESS_TARGET, width, height); if (m_Texture == nullptr) throw Exception(ERROR_SDL_STR); if (SDL_SetTextureBlendMode(m_Texture, SDL_BLENDMODE_BLEND) != 0) { error: cleanup(); throw Exception(ERROR_SDL_STR); } if (SDL_SetRenderDrawColor(Game::get()->renderer(), 0, 0, 0, 0) != 0) goto error; if (SDL_RenderClear(Game::get()->renderer()) != 0) goto error; if (SDL_SetRenderTarget(Game::get()->renderer(), m_Texture) != 0) goto error;voire: // Create the button texture (transparent) and set it as render target m_Texture = SDL_CreateTexture(Game::get()->renderer(), px, SDL_TEXTUREACCESS_TARGET, width, height); if (m_Texture == nullptr) { throw_exception: throw Exception(ERROR_SDL_STR); } if (SDL_SetTextureBlendMode(m_Texture, SDL_BLENDMODE_BLEND) != 0) { error: cleanup(); goto throw_exception; } if (SDL_SetRenderDrawColor(Game::get()->renderer(), 0, 0, 0, 0) != 0) goto error; if (SDL_RenderClear(Game::get()->renderer()) != 0) goto error; if (SDL_SetRenderTarget(Game::get()->renderer(), m_Texture) != 0) goto error;