1. C++ / Говнокод #14458

    +20

    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
    Ini ini(m_serviceProvider);
            if( ini.load( gameInputStream ) == false )
            {
                LOGGER_ERROR(m_serviceProvider)("StartupConfigLoader::loadGame_ Invalid load game settings '%s'"
                    , _gameIniPath.c_str()
                    );
    
                return false;
            }
    
        IniUtil::getIniValue( ini, "Project", "Name", _settings.projectName, m_serviceProvider );
        IniUtil::getIniValue( ini, "Project", "Company", _settings.companyName, m_serviceProvider );
        IniUtil::getIniValue( ini, "Project", "Codename", _settings.applicationSettings.projectCodename, m_serviceProvider );
        IniUtil::getIniValue( ini, "Project", "Version", _settings.applicationSettings.projectVersion, m_serviceProvider );
        IniUtil::getIniValue( ini, "Locale", "Default", _settings.defaultLocale, m_serviceProvider );
        IniUtil::getIniValue( ini, "Game", "ContentResolution", _settings.applicationSettings.contentResolution, m_serviceProvider );     
        IniUtil::getIniValue( ini, "Game", "FixedContentResolution", _settings.applicationSettings.fixedContentResolution, m_serviceProvider );
        IniUtil::getIniValue( ini, "Game", "PersonalityModule", _settings.personalityModule, m_serviceProvider );
        IniUtil::getIniValue( ini, "Game", "AlreadyRunning", _settings.alreadyRunning, m_serviceProvider );
        IniUtil::getIniValue( ini, "Game", "WindowModeCheck", _settings.applicationSettings.windowModeCheck, m_serviceProvider );
        IniUtil::getIniValue( ini, "Window", "Size", _settings.applicationSettings.windowResolution, m_serviceProvider );
        IniUtil::getIniValue( ini, "Window", "Bits", _settings.applicationSettings.bits, m_serviceProvider );
        IniUtil::getIniValue( ini, "Window", "Fullscreen", _settings.applicationSettings.fullscreen, m_serviceProvider );
            IniUtil::getIniValue( ini, "Window", "MaxFPS", _settings.maxfps, m_serviceProvider );
        IniUtil::getIniValue( ini, "Window", "VSync", _settings.applicationSettings.vsync, m_serviceProvider );

    Это оттуда уже другой. Они все сговорились что-ли? Ынтерпрайз головного мозга.
    PS: boost::property_map не осилил.

    LispGovno, 31 Января 2014

    Комментарии (76)
  2. C++ / Говнокод #14456

    +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
    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
    struct ServiceProvider1
    {
      ServiceProvider1(Service2& service1, Service3& service2, Service3& service3, Service4& service4, Service5& service5):
        service1(service1),
        service2(service2),
        service3(service3),
        service4(service4),
        service5(service5),
     {}
    
      fun<Service1> service1;//fun - функциональный объект (operator() перегружен), хранящий ссылку на сервис, чтобы не писать кроме членов ещё и две функции - константную и не константную.
      fun<Service2> service2;
      fun<Service3> service3;
      fun<Service4> service4;
      fun<Service5> service5;
    };
    
    class Service1
    {
    public:
      template<class ServiceProvider> 
      Service1(ServiceProvider serviceProvider):
        service2(serviceProvider.service2()),//Ссылки на сервисы получаем.
        service3(serviceProvider.service3()),
        myMember1(serviceProvider),//эти мемберы сами внутри воспользуются провайдерами зависимостей
        myMember2(serviceProvider),
        myMember3(),
        myMember4(myServiceProviderGeter<ServiceProvider>()),//Этому мембору понадобились новые зависимости, часть тех, что хранятся в ServiceProvider, а часть новых среди членов Service1.
        myMember5(myServiceProviderGeter<ServiceProvider>())
        myMember6(myServiceProviderGeter<ServiceProvider>())
      {}
      ...
    private:
      template<class BaseServiceProvider>
      struct MyServiceProvider: BaseServiceProvider
        {
           MyServiceProvider(BaseServiceProvider baseServiceProvider, Service6& service6, Service7& service7):
             BaseServiceProvider(baseServiceProvider),
             service6(service6),
             service7(service7)
           {}
           
           fun<Service6> service6;
           fun<Service7> service7;
        };
    
      template<class BaseServiceProvider> MyServiceProvider<BaseServiceProvider> myServiceProviderGeter(BaseServiceProvider baseServiceProvider) const
      {
        return MyServiceProvider<BaseServiceProvider>(baseServiceProvider, this->myMember2, this->myMember3);
      }
    };
    ...
    ServiceProvider1 sp(...);
    Servive1 service1(sp);
    Service8 service8(sp);
    Service9 service9(sp);
    ...

    оттуда

    LispGovno, 31 Января 2014

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

    +76

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    try {
        IntToStr(pageid);
    }
    catch (...) {
        pageid = 0;
    }

    А вдруг?

    bormand, 31 Января 2014

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

    +10

    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
    align.h: 
    #pragma once
    #include "stdint.h"
    namespace tblib 
    {
      template <typename T>
      struct check_align
      {
        uint8_t c;
        T t;
        check_align();
        check_align(const check_align&);
        check_align&operator=(const check_align&);
      };
    
      template <typename T>
      struct align_value
      {
        enum { value = sizeof(check_align<T>)-sizeof(T) };
      };
    
      template <int N>
      struct align_by_size;
    
      template <> 
      struct align_by_size<1> { uint8_t guts; };
    
      template <> 
      struct align_by_size<2> { uint16_t  guts; };
    
      template <> 
      struct align_by_size<4> { uint32_t guts; };
    
      template <> 
      struct align_by_size<8> { uint64_t guts; };
    
      template <typename T>
      struct align
      {
        align_by_size<align_value<T>::value> guts;
      };
    };
     класс массива (начало), файл tbarr.h: 
    #pragma once
    
    #include "stdint.h"
    #include "assert.h"
    #include <algorithm>
    #include "tbslice.h"
    #include "align.h"
    
    // FUCK THE EXCEPTIONS
    
    template <typename T>
    void construct (T* first, T* last) {
      while (first!=last)  {
        new(first) T;
        ++first;
      }
    }
    
    template <typename T>
    void destroy (T* first, T* last)  {
      while (last!=first)  {
        --last;
        last->~T();
      }
    }
    
    namespace tblib
    {  
      template <typename T, int N>
      class base_array
      {
        union
        {
          uint8_t memory [sizeof(T[N])];
          align<T> aligner;
        };
      public :

    мой выравниватель
    намного красивее бустовского, не так ли?

    TarasB, 27 Января 2014

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

    +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
    struct Vector2f{float x, y;};
    struct Vector3f{float x, y, z;};
    struct Tensor3f{float xx, xy, xz, yy, yz, zz;};
    struct Matrix3x3f{float data[9];};
    struct Space2
    {
      typedef Vector2f Vector;
    };
    struct Space3
    {
      typedef Vector3f Vector;
    };
    
    
    template<typename Space>
    struct ParticleSystem
    {
      template<typename T>
      struct ParticleData{};
    
      template<> 
      struct ParticleData<Space2>
      {
        float orientation;
        float invInertia;
      };
    
      template<> 
      struct ParticleData<Space3>
      {
        typename Matrix3x3f orientation;
        typename Tensor3f inertiaTensor;
      };
    
      struct Particle : public ParticleData<Space>
      {
        typename Space::Vector pos, velocity;
      };
    
      template<typename T>
      void DumpParticle(){}
    
      template<>
      void DumpParticle<Space2>()
      {
        printf("%f %f", particles[0].orientation, particles[0].invInertia);
      }
    
      template<>
      void DumpParticle<Space3>()
      {
        printf("%f %f", particles[0].orientation.data[0], particles[0].inertia.xx);
      }
      
      void DumpParticles()
      {
        DumpParticle<Space>();
      }
      std::vector<Particle> particles;
    };

    Хочу объединить трехмерный и двухмерный движок.

    LispGovno, 26 Января 2014

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

    +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
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    #include <iostream>
    using namespace std;
    
        void enable_misalignment_access_check(){
          cout<<"begin "<<__FUNCTION__<<endl;
          __asm__(
            "pushf\n"
            "orl $(1<<18),(%esp)\n"
            "popf\n"
          );
          cout<<"end "<<__FUNCTION__<<endl;
        }
    
    void alignedAccess(volatile unsigned char foo[])
    {
      cout<<"begin "<<__FUNCTION__<<endl;
      volatile int t = *(int *)(foo);
      cout<<"end "<<__FUNCTION__<<endl;
    }
    
    void unalignedAccess(volatile unsigned char foo[])
    {
      cout<<"begin "<<__FUNCTION__<<endl;
      volatile int t = *(int *)(foo+1);
      cout<<"end "<<__FUNCTION__<<endl;
    }
    
    unsigned char foo[] = { 1, 2, 3, 4, 5, 6 };
    
    int main(void)
    {
        alignedAccess(foo);
        unalignedAccess(foo);
        enable_misalignment_access_check();
        alignedAccess(foo);
        unalignedAccess(foo);
        return 0;
    }

    http://codepad.org/D6b5asES

    begin alignedAccess end alignedAccess 
    begin unalignedAccess end unalignedAccess
    begin enable_misalignment_access_check end enable_misalignment_access_check
    begin alignedAccess end alignedAccess
    begin unalignedAccess
    Bus error

    LispGovno, 26 Января 2014

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

    +19

    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
    template<class T>
    class smartest_ptr
    {
    std::unique_ptr<T> m_p;
    std::array<char, sizeof(T)> m_data; // массив размером с объект
    public:
    void New() {m_p = new(&m_data) T();}
    operator ->() {return m_p;}
    };
    
    // никакого выделения памяти из кучи!
    smartest_ptr<CFoo> pFoo; // типа nullptr
    // pFoo->Method(); - нельзя, nullptr
    pFoo.New();
    pFoo->FooMethod();
    pFoo->AnotherMeth();

    -- Чип и ДейлКрестовики спешат на помощь тем у кого медленная куча.
    -- Откуда спешат?
    -- Оттуда.

    LispGovno, 26 Января 2014

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

    +11

    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
    #define EDGE_EDGE_TEST(V0,U0,U1)                      \
    	Bx=U0[i0]-U1[i0];                                   \
    	By=U0[i1]-U1[i1];                                   \
    	Cx=V0[i0]-U0[i0];                                   \
    	Cy=V0[i1]-U0[i1];                                   \
    	f=Ay*Bx-Ax*By;                                      \
    	d=By*Cx-Bx*Cy;                                      \
    	if((f>0 && d>=0 && d<=f) || (f<0 && d<=0 && d>=f))  \
    {                                                   \
    	e=Ax*Cy-Ay*Cx;                                    \
    	if(f>0)                                           \
    {                                                 \
    	if(e>=0 && e<=f) return 1;                      \
    	}                                                 \
    	else                                              \
    {                                                 \
    	if(e<=0 && e>=f) return 1;                      \
    	}                                                 \
    	}
    
    #define POINT_IN_TRI(V0,U0,U1,U2)           \
    {                                           \
    	double a,b,c,d0,d1,d2;                     \
    	/* is T1 completly inside T2? */          \
    	/* check if V0 is inside tri(U0,U1,U2) */ \
    	a=U1[i1]-U0[i1];                          \
    	b=-(U1[i0]-U0[i0]);                       \
    	c=-a*U0[i0]-b*U0[i1];                     \
    	d0=a*V0[i0]+b*V0[i1]+c;                   \
    	\
    	a=U2[i1]-U1[i1];                          \
    	b=-(U2[i0]-U1[i0]);                       \
    	c=-a*U1[i0]-b*U1[i1];                     \
    	d1=a*V0[i0]+b*V0[i1]+c;                   \
    	\
    	a=U0[i1]-U2[i1];                          \
    	b=-(U0[i0]-U2[i0]);                       \
    	c=-a*U2[i0]-b*U2[i1];                     \
    	d2=a*V0[i0]+b*V0[i1]+c;                   \
    	if(d0*d1>0.0)                             \
    {                                         \
    	if(d0*d2>0.0) return 1;                 \
    	}                                         \
    	}
    
    #define NEWCOMPUTE_INTERVALS(VV0,VV1,VV2,D0,D1,D2,D0D1,D0D2,A,B,C,X0,X1) \
    { \
    	if(D0D1>0.0f) \
    { \
    	/* here we know that D0D2<=0.0 */ \
    	/* that is D0, D1 are on the same side, D2 on the other or on the plane */ \
    	A=VV2; B=(VV0-VV2)*D2; C=(VV1-VV2)*D2; X0=D2-D0; X1=D2-D1; \
    	} \
    	else if(D0D2>0.0f)\
    { \
    	/* here we know that d0d1<=0.0 */ \
    	A=VV1; B=(VV0-VV1)*D1; C=(VV2-VV1)*D1; X0=D1-D0; X1=D1-D2; \
    	} \
    	else if(D1*D2>0.0f || D0!=0.0f) \
    { \
    	/* here we know that d0d1<=0.0 or that D0!=0.0 */ \
    	A=VV0; B=(VV1-VV0)*D0; C=(VV2-VV0)*D0; X0=D0-D1; X1=D0-D2; \
    	} \
    	else if(D1!=0.0f) \
    { \
    	A=VV1; B=(VV0-VV1)*D1; C=(VV2-VV1)*D1; X0=D1-D0; X1=D1-D2; \
    	} \
    	else if(D2!=0.0f) \
    { \
    	A=VV2; B=(VV0-VV2)*D2; C=(VV1-VV2)*D2; X0=D2-D0; X1=D2-D1; \
    	} \
    	else \
    { \
    	/* triangles are coplanar */ \
    	return coplanar_tri_tri(N1,V0,V1,V2,U0,U1,U2); \
    	} \
    	}

    Макросы макросики. Inline? Нет, не слышал.

    Abbath, 25 Января 2014

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

    +9

    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
    #include <iostream>
    #include <iterator>
    #include <algorithm>
    #include <array>
    #include <memory>
    using namespace std;
    
    template<size_t N1, size_t N2, class T1, class T2,
    class T = typename common_type<T1, T2>::type>
    T (*concatCArray(const T1(&arr1)[N1], const T2(&arr2)[N2]))[N1+N2]{
      const auto result = (T(*)[N1+N2]) new T[N1+N2];
      copy(arr2, end(arr2), copy(arr1, end(arr1), *result));
      return result;
    }
    template<std::size_t N, class T>
    void viewCArrayPtr(T (*arr)[N]){
      copy(*arr, end(*arr), ostream_iterator<T>(cout, " "));
    }
    template<size_t N1, size_t N2, class T1, class T2,
    class T = typename remove_const<typename common_type<T1, T2>::type>::type>
    array<T, N1+N2> concatArray(const array<T1, N1> &arr1, const array<T2, N2> &arr2){
      array<T, N1+N2> result;
      copy(begin(arr2), end(arr2), copy(begin(arr1), end(arr1), result.begin()));
      return result;
    }
    template<std::size_t N, class T>
    void viewArray(const array<T, N> arr){
      copy(begin(arr), end(arr), ostream_iterator<T>(cout, " "));
    }
    
    int main() {
      int arr1[]{0,1,2,3}, arr2[]{4,5,6};
      auto ca = concatCArray(arr1, arr2);
      unique_ptr<int[]> safe(*ca);
      viewCArrayPtr(ca);
      cout<<endl;
      array<float, 2> a {1,2.5};
      array<int, 3> b{3, 4, 5};
      viewArray(concatArray(a, b));
      return 0;
    }

    От туда.
    http://ideone.com/3KjycI

    LispGovno, 22 Января 2014

    Комментарии (15)
  10. C++ / Говнокод #14397

    +4

    1. 1
    2. 2
    3. 3
    namespace std
    {
      template<class T, class T2> class common_type<::std::shared_ptr<T>, ::std::shared_ptr<T2> >: public ::std::common_type<T, T2>{};

    LispGovno, 22 Января 2014

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