• Content count

  • Joined

  • Last visited

Community Reputation

163 Neutral

About xiajia

  • Rank
  1. Well, not just GUI, can also be some game elements. Of course, if GUI can also.For all the elements interact with  the user in the game are far-fetched called UI ? ^.^ Then taking GUI as an example to illustrate the problem. For example a calculator (this is just an example), there are a lot of button. If the calculator can "switch" between the common and scientific type, and can "minimize", "maximize"......and so on. What I mean by "Action" is used to describe the process of these changes. Of course you can through some simple variables to describe the action,  but when these movements became a lot, Variable to describe becomes very messy.
  2. there are a lot of "action"s in a game. some are simple,e.g. the disappearance of a buttom. and some are complicated.e.g.the disappearance of a button array. Is there a way to abstract the "action", making it the reuse and modification easy? e.g.The convergence of the interface elements .Combination of elements of the game action , if the package is suitable , you can make the action more delicate and rich .
  3. about color mix

    Thanks for Paradigm Shifter and Crusable, i get a lot of tips.I have found a good method based on CMYK. Although there are still some problems, but has almost.
  4. about color mix

    Description of the problem are as follows: the first color1(c1) RGB value is rgb1, the second color2(c2) RGB value is rgb2, How to calculate the RGB(rgb3) of the color3(c3) mixed with c1 and c2,the mixing ratio is x: y. For example:red and green 1:1 mixture is yellow, red and black 1:1 mixture is dark red.
  5. about OpenMP

    I am the beginner of OpenMP.the code below:   #include "windows.h" #include "math.h" #include <omp.h> #include <iostream> int main(void) {     double t1 = omp_get_wtime( );     for(int i = 0;i < 8;i ++)     {         float a = 0;         for(int j = 0;j < 10000000;j++)         {             a += sqrtf(j);         }     }     double t2 = omp_get_wtime( );     std::cout<<"time: "<<t2 - t1<<std::endl; #pragma omp parallel for     for(int i = 0;i < 8;i ++)     {         float a = 0;         for(int j = 0;j < 10000000;j++)         {             a += sqrtf(j);         }     }     t1 = omp_get_wtime( );     std::cout<<"time: "<<t1 - t2<<std::endl;     system("pause");     return 0; }   when i release with VS2010,and run,there is no upgrade!In some cases , it will decline.i don't know Y?
  6. about "delete" and "delete []"

    use smart pointer or use reference counting can solve this problem.
  7. about "delete" and "delete []"

    I have yet to learn the knowledge of design patterns, I learned the factory pattern to do some more in-depth discussion.
  8. about "delete" and "delete []"

    do you mean call ‘new’ at the constructor?This is just one case.Not always the case.
  9. about "delete" and "delete []"

    about the semicolon after the tempClassA,it is a small accident. the main function is added later.The compiler will not complain if not coupled.
  10. about "delete" and "delete []"

    I think "make the destructor public" is better than "add XDELETE as a friend to class MostlyPrivate",
  11. about "delete" and "delete []"

    compiling with VS2005, error C2248:'tempClass<T>::~tempClass' : cannot access private member declared in class 'tempClass<T>' line 4: delete p;
  12. about "delete" and "delete []"

    template<typename T> void XDELETE(T *&p) { delete p; p = NULL; } template<class T> class tempClassA; template<class T> class tempClass { private: friend tempClassA<T>; T * m_p; tempClass() :m_p(NULL) { } ~tempClass() { XDELETE(m_p); } }; template<class T> class tempClassA { public: tempClassA() :m_a(new tempClass<T>()) { } ~tempClassA() { XDELETE(m_a); } private: tempClass<T> * m_a; }; int main() { tempClassA<int> a; return 0; } compile error. 
  13. about "delete" and "delete []"

    thanks for Brother Bob,Cornstalks and rip-off.These recommendations so refreshing for me.I should solve the problem instead of ducking the issue about double delete.     Not "macro higher efficiency than function"?
  14. about "delete" and "delete []"

    Thank you very much for your advice. about 2:it's true that "delete" already checks if the pointer is "NULL".(I do not know whether all compilers are like this. But vs2005 is indeed the case.) but "delete" not set the pointer to "NULL"   int *p = new int[100]; delete []p; delete []p; // this is a runtime error The actual situation may be more complicated than this. about 3:Linked content is very good (yet not try to use), but I've seen about "boost::scoped_ptr","boost::shared_ptr","boost::scoped_array","boost::shared_array","boost::weak_ptr","boost:: intrusive_ptr:, so be a bit confusing to me.
  15. about "delete" and "delete []"

    Well, with a specific example to illustrate.Smart pointers.The general method is as follows:     #define XDELETE(p) { if (p != NULL) { delete p; p = NULL; } } template<class T> class _XSmartP; template<class T> class _XBackP  {  private:    friend _XSmartP<T>;     T *m_p;    size_t m_counter;    _XBackP(T *p)   :m_p(p)   ,m_counter(1)     {    printf("_XBackP constructor called!\n");     }     ~_XBackP()     {         XDELETE(m_p);    printf( "_XBackP distructor called!\n");     }  };   template<class T> class _XSmartP  {  public:     _XSmartP(T *p) :m_backP(new _XBackP<T>(p))    {    printf("_XSmartP constructor called ! use = %d\n",m_backP->m_counter);    }      _XSmartP(const _XSmartP& temp)   :m_backP(temp.m_backP)    { ++m_backP->m_counter;      printf("_XSmartP copy constructor called ! use = %d\n",m_backP->m_counter);    }       _XSmartP<T>& operator=(const _XSmartP<T>&temp)  {    if(this == &temp) return *this;   ++temp.m_backP->m_counter;    if(--m_backP->m_counter == 0)    {    XDELETE(m_backP);   }   m_backP = temp.m_backP;   return *this;   }        ~_XSmartP()     {    printf("_XSmartP distructor called ! use = %d\n",m_backP->m_counter);   if(--m_backP->m_counter == 0)    {    XDELETE(m_backP);   }    }      T *getPtr() const     {         return m_backP->m_p;     }      T getVal() const     {         return *m_backP->m_p; }     void setVal(T val)     {         *m_backP->m_p = val;     }  private:     _XBackP<T> *m_backP; };    if use as follow:     _XSmartP<int> temp(new int[20]); it will cause errors because of "delete" to "new[]".If you want to avoid this problem, you need to define a similar structure for the array.However, this will have a lot of duplicate code.Is there a way to do it to the best of both worlds?