Ignore:
Timestamp:
Aug 20, 2012, 11:21:01 PM (11 years ago)
Author:
touky
Message:

Small physic refactor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Physics/Include/LolPhysics.h

    r1768 r1782  
    321321
    322322private:
     323
    323324        friend class EasyPhysic;
     325        friend class EasyCharacterController;
    324326        friend class EasyConstraint;
    325327
     328        enum eEasyPhysicType
     329        {
     330                EEPT_Dynamic,
     331                EEPT_Static,
     332                EEPT_Ghost,
     333                EEPT_CollisionObject,
     334                EEPT_CharacterController,
     335
     336                EEPT_MAX
     337        };
     338
     339        //m_owner_simulation
    326340        //Adds the given EasyPhysic to the correct list.
    327         void AddToDynamic(EasyPhysic* NewEPDynamic)     { m_dynamic_list << NewEPDynamic; }
    328         void AddToStatic(EasyPhysic* NewEPStatic)       { m_static_list << NewEPStatic; }
    329         void AddToGhost(EasyPhysic* NewEPGhost)         { m_ghost_list << NewEPGhost; }
    330         void AddToConstraint(EasyConstraint* NewEC)     { m_constraint_list     << NewEC; }
     341        void ObjectRegistration(bool AddObject, EasyPhysic* NewEP, eEasyPhysicType CurType)
     342        {
     343                Array<EasyPhysic*>* SearchList = NULL;
     344                switch(CurType)
     345                {
     346                        case EEPT_Dynamic:
     347                        {
     348                                SearchList = &m_dynamic_list;
     349                                break;
     350                        }
     351                        case EEPT_Static:
     352                        {
     353                                SearchList = &m_static_list;
     354                                break;
     355                        }
     356                        case EEPT_Ghost:
     357                        {
     358                                SearchList = &m_ghost_list;
     359                                break;
     360                        }
     361                        case EEPT_CollisionObject:
     362                        {
     363                                SearchList = &m_collision_object_list;
     364                                break;
     365                        }
     366                        case EEPT_CharacterController:
     367                        {
     368                                SearchList = &m_character_controller_list;
     369                                break;
     370                        }
     371                }
     372
     373                if (AddObject)
     374                {
     375                        NewEP->m_owner_simulation = this;
     376                        (*SearchList) << NewEP;
     377                }
     378                else
     379                {
     380                        NewEP->m_owner_simulation = NULL;
     381                        for (int i = 0; i < SearchList->Count(); ++i)
     382                        {
     383                                if ((*SearchList)[i] == NewEP)
     384                                {
     385                                        SearchList->Remove(i--);
     386                                        break;
     387                                }
     388                        }
     389                }
     390        }
     391        void ObjectRegistration(bool AddObject, EasyConstraint* NewEC)
     392        {
     393                Array<EasyConstraint*>* SearchList = NULL;
     394                SearchList = &m_constraint_list;
     395
     396                if (AddObject)
     397                {
     398                        NewEC->m_owner_simulation = this;
     399                        (*SearchList) << NewEC;
     400                }
     401                else
     402                {
     403                        NewEC->m_owner_simulation = NULL;
     404                        for (int i = 0; i < SearchList->Count(); ++i)
     405                        {
     406                                if ((*SearchList)[i] == NewEC)
     407                                {
     408                                        SearchList->Remove(i--);
     409                                        break;
     410                                }
     411                        }
     412                }
     413        }
    331414
    332415        //Easy Physics body List
     
    334417        Array<EasyPhysic*>                                              m_static_list;
    335418        Array<EasyPhysic*>                                              m_ghost_list;
     419        Array<EasyPhysic*>                                              m_collision_object_list;
     420        Array<EasyPhysic*>                                              m_character_controller_list;
    336421        Array<EasyConstraint*>                                  m_constraint_list;
    337422
Note: See TracChangeset for help on using the changeset viewer.