diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-10-21 11:58:38 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-10-21 11:58:38 +0400 |
commit | d599b643b7a1882ea79851e334d7ed133f362bb3 (patch) | |
tree | 4e4640c1b2e7cc82d9db81dbd98a39777dcbce7c /source/gameengine/GameLogic | |
parent | f3ece5a108db0bdbefb4663ef4ebd9a7e039e263 (diff) |
style cleanup: bge, switch statements mostly.
also left bmesh decimator on in previous commit.
Diffstat (limited to 'source/gameengine/GameLogic')
4 files changed, 133 insertions, 135 deletions
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp index efe76c3eb46..21619d8c63f 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp @@ -89,8 +89,7 @@ void SCA_Joystick::HandleEvents(void) SCA_Joystick::m_instance[i]->OnNothing(&sdl_event); } - while(SDL_PollEvent(&sdl_event)) - { + while (SDL_PollEvent(&sdl_event)) { /* Note! m_instance[sdl_event.jaxis.which] * will segfault if over JOYINDEX_MAX, not too nice but what are the chances? */ @@ -100,28 +99,27 @@ void SCA_Joystick::HandleEvents(void) /* Note!, if you manage to press and release a button within 1 logic tick * it wont work as it should */ - switch(sdl_event.type) - { - case SDL_JOYAXISMOTION: - SCA_Joystick::m_instance[sdl_event.jaxis.which]->OnAxisMotion(&sdl_event); - break; - case SDL_JOYHATMOTION: - SCA_Joystick::m_instance[sdl_event.jhat.which]->OnHatMotion(&sdl_event); - break; - case SDL_JOYBUTTONUP: - SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonUp(&sdl_event); - break; - case SDL_JOYBUTTONDOWN: - SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonDown(&sdl_event); - break; + switch (sdl_event.type) { + case SDL_JOYAXISMOTION: + SCA_Joystick::m_instance[sdl_event.jaxis.which]->OnAxisMotion(&sdl_event); + break; + case SDL_JOYHATMOTION: + SCA_Joystick::m_instance[sdl_event.jhat.which]->OnHatMotion(&sdl_event); + break; + case SDL_JOYBUTTONUP: + SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonUp(&sdl_event); + break; + case SDL_JOYBUTTONDOWN: + SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonDown(&sdl_event); + break; #if 0 /* Not used yet */ - case SDL_JOYBALLMOTION: - SCA_Joystick::m_instance[sdl_event.jball.which]->OnBallMotion(&sdl_event); - break; + case SDL_JOYBALLMOTION: + SCA_Joystick::m_instance[sdl_event.jball.which]->OnBallMotion(&sdl_event); + break; #endif - default: - printf("SCA_Joystick::HandleEvents, Unknown SDL event, this should not happen\n"); - break; + default: + printf("SCA_Joystick::HandleEvents, Unknown SDL event, this should not happen\n"); + break; } } } diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp index 7e9a4bc903c..b4e461a9c2b 100644 --- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp @@ -113,21 +113,21 @@ bool SCA_JoystickSensor::Evaluate() return false; m_reset = false; - switch(m_joymode) - { - case KX_JOYSENSORMODE_AXIS: + + switch (m_joymode) { + case KX_JOYSENSORMODE_AXIS: { - /* what is what! - m_axisf == JOYAXIS_RIGHT, JOYAXIS_UP, JOYAXIS_DOWN, JOYAXIS_LEFT - m_axisf == 1 == up - m_axisf == 2 == left - m_axisf == 3 == down - - numberof== m_axis (1-4), range is half of JOYAXIS_MAX since - it assumes the axis joysticks are axis parirs (0,1), (2,3), etc - also note that this starts at 1 where functions its used - with expect a zero index. - */ + /* what is what! + * m_axisf == JOYAXIS_RIGHT, JOYAXIS_UP, JOYAXIS_DOWN, JOYAXIS_LEFT + * m_axisf == 1 == up + * m_axisf == 2 == left + * m_axisf == 3 == down + * + * numberof== m_axis (1-4), range is half of JOYAXIS_MAX since + * it assumes the axis joysticks are axis parirs (0,1), (2,3), etc + * also note that this starts at 1 where functions its used + * with expect a zero index. + */ if (!js->IsTrigAxis() && !reset) /* No events from SDL? - don't bother */ return false; @@ -159,7 +159,7 @@ bool SCA_JoystickSensor::Evaluate() } break; } - case KX_JOYSENSORMODE_AXIS_SINGLE: + case KX_JOYSENSORMODE_AXIS_SINGLE: { /* Like KX_JOYSENSORMODE_AXIS but don't pair up axis */ if (!js->IsTrigAxis() && !reset) /* No events from SDL? - don't bother */ @@ -179,12 +179,12 @@ bool SCA_JoystickSensor::Evaluate() } break; } - - case KX_JOYSENSORMODE_BUTTON: + + case KX_JOYSENSORMODE_BUTTON: { - /* what is what! - m_button = the actual button in question - */ + /* what is what! + * m_button = the actual button in question + */ if (!js->IsTrigButton() && !reset) /* No events from SDL? - don't bother */ return false; @@ -200,12 +200,12 @@ bool SCA_JoystickSensor::Evaluate() } break; } - case KX_JOYSENSORMODE_HAT: + case KX_JOYSENSORMODE_HAT: { - /* what is what! - numberof = m_hat -- max 4 - direction= m_hatf -- max 12 - */ + /* what is what! + * numberof = m_hat -- max 4 + * direction= m_hatf -- max 12 + */ if (!js->IsTrigHat() && !reset) /* No events from SDL? - don't bother */ return false; @@ -222,18 +222,19 @@ bool SCA_JoystickSensor::Evaluate() } break; } - /* test for ball anyone ?*/ - default: - printf("Error invalid switch statement\n"); - break; + /* test for ball anyone ?*/ + default: + printf("Error invalid switch statement\n"); + break; } - /* if not all events are enabled, only send a positive pulse when + /* if not all events are enabled, only send a positive pulse when * the button state changes */ if (!m_bAllEvents) { if (m_istrig_prev == m_istrig) { result = false; - } else { + } + else { m_istrig_prev = m_istrig; } } @@ -353,7 +354,7 @@ PyObject *SCA_JoystickSensor::pyattr_get_axis_values(void *self_v, const KX_PYAT int axis_index= joy->GetNumberOfAxes(); PyObject *list= PyList_New(axis_index); - while(axis_index--) { + while (axis_index--) { PyList_SET_ITEM(list, axis_index, PyLong_FromSsize_t(joy->GetAxisPosition(axis_index))); } @@ -381,7 +382,7 @@ PyObject *SCA_JoystickSensor::pyattr_get_hat_values(void *self_v, const KX_PYATT int hat_index= joy->GetNumberOfHats(); PyObject *list= PyList_New(hat_index); - while(hat_index--) { + while (hat_index--) { PyList_SET_ITEM(list, hat_index, PyLong_FromSsize_t(joy->GetHat(hat_index))); } diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp index 9a2dd9bdd57..64bcae9f6d7 100644 --- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp +++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp @@ -225,37 +225,37 @@ bool SCA_KeyboardSensor::Evaluate() */ if (m_qual > 0) { const SCA_InputEvent & qualevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) m_qual); - switch(qualevent.m_status) { - case SCA_InputEvent::KX_NO_INPUTSTATUS: - qual = false; - break; - case SCA_InputEvent::KX_JUSTRELEASED: - qual_change = true; - qual = false; - break; - case SCA_InputEvent::KX_JUSTACTIVATED: - qual_change = true; - case SCA_InputEvent::KX_ACTIVE: - /* do nothing */ - break; + switch (qualevent.m_status) { + case SCA_InputEvent::KX_NO_INPUTSTATUS: + qual = false; + break; + case SCA_InputEvent::KX_JUSTRELEASED: + qual_change = true; + qual = false; + break; + case SCA_InputEvent::KX_JUSTACTIVATED: + qual_change = true; + case SCA_InputEvent::KX_ACTIVE: + /* do nothing */ + break; } } if (m_qual2 > 0 && qual==true) { const SCA_InputEvent & qualevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) m_qual2); /* copy of above */ - switch(qualevent.m_status) { - case SCA_InputEvent::KX_NO_INPUTSTATUS: - qual = false; - break; - case SCA_InputEvent::KX_JUSTRELEASED: - qual_change = true; - qual = false; - break; - case SCA_InputEvent::KX_JUSTACTIVATED: - qual_change = true; - case SCA_InputEvent::KX_ACTIVE: - /* do nothing */ - break; + switch (qualevent.m_status) { + case SCA_InputEvent::KX_NO_INPUTSTATUS: + qual = false; + break; + case SCA_InputEvent::KX_JUSTRELEASED: + qual_change = true; + qual = false; + break; + case SCA_InputEvent::KX_JUSTACTIVATED: + qual_change = true; + case SCA_InputEvent::KX_ACTIVE: + /* do nothing */ + break; } } /* done reading qualifiers */ diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp index 7dbbbb2a0d9..f857d59b121 100644 --- a/source/gameengine/GameLogic/SCA_PythonController.cpp +++ b/source/gameengine/GameLogic/SCA_PythonController.cpp @@ -376,64 +376,63 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr) PyObject *excdict= NULL; PyObject *resultobj= NULL; - switch(m_mode) { - case SCA_PYEXEC_SCRIPT: - { - if (m_bModified) - if (Compile()==false) // sets m_bModified to false + switch (m_mode) { + case SCA_PYEXEC_SCRIPT: + { + if (m_bModified) + if (Compile()==false) // sets m_bModified to false + return; + if (!m_bytecode) return; - if (!m_bytecode) - return; - - /* - * This part here with excdict is a temporary patch - * to avoid python/gameengine crashes when python - * inadvertently holds references to game objects - * in global variables. - * - * The idea is always make a fresh dictionary, and - * destroy it right after it is used to make sure - * python won't hold any gameobject references. - * - * Note that the PyDict_Clear _is_ necessary before - * the Py_DECREF() because it is possible for the - * variables inside the dictionary to hold references - * to the dictionary (ie. generate a cycle), so we - * break it by hand, then DECREF (which in this case - * should always ensure excdict is cleared). - */ - - excdict= PyDict_Copy(m_pythondictionary); - - resultobj = PyEval_EvalCode((PyObject *)m_bytecode, excdict, excdict); - - /* PyRun_SimpleString(m_scriptText.Ptr()); */ - break; - } - case SCA_PYEXEC_MODULE: - { - if (m_bModified || m_debug) - if (Import()==false) // sets m_bModified to false + + /* + * This part here with excdict is a temporary patch + * to avoid python/gameengine crashes when python + * inadvertently holds references to game objects + * in global variables. + * + * The idea is always make a fresh dictionary, and + * destroy it right after it is used to make sure + * python won't hold any gameobject references. + * + * Note that the PyDict_Clear _is_ necessary before + * the Py_DECREF() because it is possible for the + * variables inside the dictionary to hold references + * to the dictionary (ie. generate a cycle), so we + * break it by hand, then DECREF (which in this case + * should always ensure excdict is cleared). + */ + + excdict= PyDict_Copy(m_pythondictionary); + + resultobj = PyEval_EvalCode((PyObject *)m_bytecode, excdict, excdict); + + /* PyRun_SimpleString(m_scriptText.Ptr()); */ + break; + } + case SCA_PYEXEC_MODULE: + { + if (m_bModified || m_debug) + if (Import()==false) // sets m_bModified to false + return; + if (!m_function) return; - if (!m_function) - return; - - PyObject *args= NULL; - - if (m_function_argc==1) { - args = PyTuple_New(1); - PyTuple_SET_ITEM(args, 0, GetProxy()); + + PyObject *args= NULL; + + if (m_function_argc==1) { + args = PyTuple_New(1); + PyTuple_SET_ITEM(args, 0, GetProxy()); + } + + resultobj = PyObject_CallObject(m_function, args); + Py_XDECREF(args); + break; } - - resultobj = PyObject_CallObject(m_function, args); - Py_XDECREF(args); - break; - } - + } /* end switch */ - - - + + /* Free the return value and print the error */ if (resultobj) Py_DECREF(resultobj); |