1. Список говнокодов пользователя jangolare

    Всего: 27

  2. C++ / Говнокод #20930

    +458

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    tinyxml2::XMLDocument doc;
        doc.Parse(xhtml.c_str());//парсируем до конца
    
        tinyxml2::XMLElement* xml_element =
            doc.FirstChildElement("html")->FirstChildElement("body")->FirstChildElement("div")->
                NextSiblingElement("div")->NextSiblingElement("div")->FirstChildElement("div")->
                    NextSiblingElement("div")->FirstChildElement("div")->NextSiblingElement("div")->
                        FirstChildElement("div")->FirstChildElement("div")->NextSiblingElement("div")->
                            FirstChildElement("form");

    jangolare, 23 Августа 2016

    Комментарии (18)
  3. C++ / Говнокод #20485

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    template<typename V>
            constexpr Vector(V&& x, V&& y, V&& z) noexcept(std::is_lvalue_reference<V>::value ?
                    std::is_nothrow_move_constructible<V>::value  :
                    std::is_nothrow_copy_constructible<V>::value) :
                data{std::forward<V>(x), std::forward<V>(y), std::forward<V>(z)} {}

    jangolare, 07 Августа 2016

    Комментарии (17)
  4. C++ / Говнокод #20295

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    std::deque<std::pair<int, int>> Pathing::findPath(int sx, int sy, int fx, int fy) const
    {
        std::list<Node> openNodes;
        std::list<Node> closeNodes;
    
        const Node startNode{nullptr, sx, sy, 0, 0, 0};
        openNodes.push_back(startNode);
    
        auto cells = gameMap->getCells();
    
        auto findNode = [](auto&& list, int x, int y)
        {
            return std::find_if(std::begin(std::forward<decltype(list)>(list)),
                                std::end(std::forward<decltype(list)>(list)),
                    [x, y](auto n) {return n.x == x && n.y == y;});
        };
    
        auto isNodeInList = [findNode](auto&& list, int x, int y)
        {
            return findNode(std::forward<decltype(list)>(list), x, y) != list.cend();
        };
    
        auto processNode = [&](auto iterCurrentNode, int x, int y)
        {
            const auto nx = iterCurrentNode->x + x;
            const auto ny = iterCurrentNode->y + y;
    
            if (cells[nx][ny].passable && !isNodeInList(closeNodes, nx, ny))
            {
                const auto G = iterCurrentNode->G + (x && y ? 14 : 10);
                const auto H = (std::abs(fx - nx) + std::abs(fy - ny)) * 10;
                const auto F = G + H;
    
                auto node = findNode(openNodes, nx, ny);
    
                if (node == openNodes.cend())
                {
                    openNodes.push_back({&(*iterCurrentNode), nx, ny, G, H, F});
    
                    if (nx == fx && ny == fy)
                        return true;
                }
                else
                {
                    if (G < node->G)
                    {
                        node->parent = &(*iterCurrentNode);
                        node->G = G;
                        node->H = H;
                        node->F = F;
                    }
                }
            }
    
            return false;
        };
    
        while (!openNodes.empty())
        {
            auto iterMinF = std::min_element(openNodes.cbegin(), openNodes.cend(),
                    [](auto n1, auto n2) {return n1.F < n2.F;});
    
            closeNodes.push_back(*iterMinF);
            auto iter = closeNodes.insert(closeNodes.cend(), *iterMinF);
    
            openNodes.erase(iterMinF);
    
            if (processNode(iter,  1,  0) ||
                processNode(iter,  1,  1) ||
                processNode(iter,  0,  1) ||
                processNode(iter, -1,  1) ||
                processNode(iter, -1,  0) ||
                processNode(iter, -1, -1) ||
                processNode(iter,  0, -1) ||
                processNode(iter,  1, -1))
                break;
        }
    
        auto finalNode = findNode(openNodes, fx, fy);
        if (finalNode == openNodes.cend())
            return {};
    
        std::deque<std::pair<int, int>> route{{finalNode->x, finalNode->y}};
        const Node* temp = finalNode->parent;
    
        while (temp)
        {
            route.push_front({temp->x, temp->y});
            temp = temp->parent;
        }
    
        return route;
    }

    jangolare, 30 Июня 2016

    Комментарии (0)
  5. C++ / Говнокод #20279

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    GUIButton::GUIButton(ResourceManager& resourceManager, const Renderer& renderer,
            const Config& config, std::string name, Action action,
            int x, int y, int width, int height) :
        GUIButton{std::move(name), std::move(action),
            resourceManager.load<Font>("font_button_" + name,
                    config.findValue<std::string>("button", "font"),
                    config.findValue<int>("button", "font_size")),
            resourceManager.load<TextureAtlas>("atlas_button", resourceManager, renderer,
                    Config{config.findValue<std::string>("button", "atlas_config")}), x, y, width, height}
    {
    }

    jangolare, 27 Июня 2016

    Комментарии (3)
  6. C++ / Говнокод #20231

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    void Canvas::drawText(const char* text, SDL_Color sdlColor, int x, int y) const noexcept
    {
        if (!font)
            throw std::runtime_error{"TTF_Font* is null"};
    
        SDL_Surface* const sdlSurface =
            ::TTF_RenderText_Solid(const_cast<TTF_Font*>(font->getTtfFont()), text, sdlColor);
        if (!sdlSurface)
            throw std::runtime_error{"SDL_Surface* is null"};
    
        SDL_Texture* const sdlTexture =
            ::SDL_CreateTextureFromSurface(const_cast<SDL_Renderer*>(renderer->getSdlRenderer()), sdlSurface);
        if (!sdlTexture)
            throw std::runtime_error{"SDL_Texture* is null"};
    
        const SDL_Rect srcrect{0, 0, sdlSurface->w, sdlSurface->h};
        const SDL_Rect dstrect{x, y, sdlSurface->w, sdlSurface->h};
    
        ::SDL_FreeSurface(sdlSurface);
    
        ::SDL_RenderCopy(const_cast<SDL_Renderer*>(renderer->getSdlRenderer()), sdlTexture,
                &srcrect, &dstrect);
        ::SDL_DestroyTexture(sdlTexture);
    }

    jangolare, 19 Июня 2016

    Комментарии (41)
  7. C++ / Говнокод #19840

    −3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    namespace raytracing
    {
        struct Scene::Implementation
        {
            std::vector<std::unique_ptr<RenderObject>> renderObjects;
            std::vector<Light> lights;
            Camera camera;
        };
    }
    
    Scene::Scene() :
        implementation{std::make_unique<Implementation>()}
    {
    }
    
    void Scene::insertObject(RenderObject* renderObject) noexcept
    {
        implementation->renderObjects.push_back(std::unique_ptr<RenderObject>{renderObject});
    }
    
    const RenderObject* Scene::getIntersectedObject(Ray ray, vec3f* intersectionPoint) const noexcept
    {
        const auto& renderObjects = implementation->renderObjects;
    
        if (renderObjects.empty())
            return nullptr;
    
        struct IntersectionData
        {
            const RenderObject* renderObject;
            float t;
            bool isIntersect;
            vec3f intersectionPoint;
        } temp{};
    
        for (decltype(implementation->renderObjects)::const_iterator iter = renderObjects.cbegin();
                iter != renderObjects.cend(); ++iter)
        {
            IntersectionData intersectionData;
    
            intersectionData.renderObject = (*iter).get();
            intersectionData.isIntersect = (*iter)->isIntersect(ray, intersectionData.t,
                    &intersectionData.intersectionPoint);
    
            if (intersectionData.isIntersect)
            {
                if (temp.isIntersect)
                {
                    if (temp.t > intersectionData.t)
                        temp   = intersectionData;
                }
                else
                    temp = intersectionData;
            }
        }
    
        if (intersectionPoint)
            *intersectionPoint = temp.intersectionPoint;
    
        return temp.renderObject;
    }
    
    namespace raytracing
    {
        struct Renderer::Implementation
        {
            vec3f trace(const Scene& scene, Ray ray) const noexcept
            {
                vec3f intersectionPoint;
                const RenderObject* const renderObject = scene.getIntersectedObject(ray, &intersectionPoint);
    
                vec3f color{};
    
                if (!renderObject)
                    return color;
    
                for (Light l : scene.getLights())
                {
                    const Ray lightRay{intersectionPoint, (l.position - intersectionPoint).normalize()};
    
                    float brightness = renderObject->getNormal(intersectionPoint).dot(lightRay.direction);
                    if (brightness < 0.0F)
                        brightness = 0.0F;
    
                    color += renderObject->getColor(intersectionPoint) * 255.0F * brightness;
                }
    
                return color;
            }
        }
    }

    Сумеете ли вы найти ошибку?

    jangolare, 18 Апреля 2016

    Комментарии (88)
  8. C++ / Говнокод #19813

    +3

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    constexpr Vector(Vector&& vector) noexcept :
                x(vector.x), y(vector.y), z(vector.z)
            {
                vector.x = vector.y = vector.z = T();
            }
    
            constexpr Vector& operator=(Vector&& vector) noexcept
            {
                if (this == &vector)
                    return *this;
    
                x = vector.x;
                y = vector.y;
                z = vector.z;
    
                vector.x = vector.y = vector.z = T();
    
                return *this;
            }

    jangolare, 13 Апреля 2016

    Комментарии (6)
  9. C++ / Говнокод #19767

    +4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    constexpr Fraction operator+(const Fraction& fraction) const noexcept
        {
            const Fraction max_fraction_by_denominator{denominator > fraction.denominator ? *this : fraction};
            const Fraction min_fraction_by_denominator{denominator < fraction.denominator ? *this : fraction};
            const bool is_sim_denominator = max_fraction_by_denominator.denominator %
                                            min_fraction_by_denominator.denominator == 0;
            int sim_denominator = is_sim_denominator ?
                max_fraction_by_denominator.denominator : (max_fraction_by_denominator.denominator *
                min_fraction_by_denominator.denominator);
            const int nominator1 = is_sim_denominator ? (min_fraction_by_denominator.nominator *
                max_fraction_by_denominator.denominator / min_fraction_by_denominator.denominator) :
                min_fraction_by_denominator.nominator * max_fraction_by_denominator.denominator;
            const int nominator2 = is_sim_denominator ? max_fraction_by_denominator.nominator :
                max_fraction_by_denominator.nominator * min_fraction_by_denominator.denominator;
            int nominators_sum = nominator1 + nominator2;
            int while_parts_sum = while_part + fraction.while_part;
    
            while (nominators_sum >= sim_denominator)
            {
                nominators_sum -= sim_denominator;
                ++while_parts_sum;
            }
    
            if (!nominators_sum)
                sim_denominator = 0;
    
            return {while_parts_sum, nominators_sum, sim_denominator};
        }

    jangolare, 06 Апреля 2016

    Комментарии (6)
  10. Java / Говнокод #18985

    −37

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    import src.engine.running.RunningManager;
    import src.engine.SimpleProgram;
    import src.engine.action.ActionListener;
    import src.engine.action.ActionManager;
    import src.engine.action.ActionTool;
    import src.engine.running.MatrixOrtho;
    import src.engine.render.GraphicManager;
    import src.engine.render.GraphicTool;
    import src.engine.render.ObjectRender;
    import src.engine.util.TextureLoader;
    import src.engine.util.Timer;
    
    //...
        @Override
        public void initialize()
        {
            // Манажеры.
            RunningManager running = new RunningManager();
            MatrixOrtho matrixOrtho = new MatrixOrtho();
            ActionManager action = new ActionManager();
            GraphicManager graphic = new GraphicManager();
    
            // Игровые объедки.
            Quad quad = new Quad();
    
            // настройка и создание...
    
            // ...дислея...
            running.createDisplay(800, 600, "SimpleProgram");
            // ...матрицы...
            running.setMatrix(matrixOrtho);
            // ...актион манажера...
            running.createActionManager(action);
            // ...кграпхик манажера.
            running.createGraphicManager(graphic);
    
            // добавить в список обновления события и графики игрового объекта "Quad".
            action.addActionListener(quad);
            graphic.addObjectRender(quad);
    
            // Манажер упргратейдет всех.
            running.update(30);
        }
    //...

    jangolare, 07 Ноября 2015

    Комментарии (5)
  11. C++ / Говнокод #18636

    +5

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    float data1[16];
    float data2[16];
    
    for (unsigned i = 0; i < 4; ++i)
        for (unsigned j = 0; j < 4; ++j)
            *(data1 + 4 * i + j) = *(data2 + 4 * i + j);

    jangolare, 26 Августа 2015

    Комментарии (53)