コード例 #1
0
ファイル: orxTest.c プロジェクト: iar-wain/orx-test
static orxSTATUS orxFASTCALL EventHandler(const orxEVENT *_pstEvent)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;

  /* Colliding? */
  if(_pstEvent->eID == orxPHYSICS_EVENT_CONTACT_ADD)
  {
    /* Adds bump FX on both objects */
    orxObject_AddUniqueFX(orxOBJECT(_pstEvent->hSender), "Bump");
    orxObject_AddUniqueFX(orxOBJECT(_pstEvent->hRecipient), "Bump");

    /* Adds bip sound on one of them */
    orxObject_AddSound(orxOBJECT(_pstEvent->hSender), "Bip");
  }

  /* Done! */
  return eResult;
}
コード例 #2
0
ファイル: orxBounce.c プロジェクト: enobayram/orx
/** Update callback
 */
static void orxFASTCALL orxBounce_Update(const orxCLOCK_INFO *_pstClockInfo, void *_pstContext)
{
  orxVECTOR vMousePos;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("Bounce_Update");

  if((sbRecord == orxFALSE) && (orxInput_IsActive("Record") != orxFALSE))
  {
    /* Starts recording with default settings */
    orxSound_StartRecording("orxSoundRecording.wav", orxFALSE, 0, 0);

    /* Updates status */
    sbRecord = orxTRUE;
  }

  if(orxInput_IsActive("ToggleTrail") && (orxInput_HasNewStatus("ToggleTrail")))
  {
    /* Toggles trail rendering */
    orxConfig_PushSection("Bounce");
    orxConfig_SetBool("DisplayTrail", !orxConfig_GetBool("DisplayTrail"));
    orxConfig_PopSection();
  }

  if(orxInput_IsActive("ToggleProfiler") && orxInput_HasNewStatus("ToggleProfiler"))
  {
    /* Toggles profiler rendering */
    orxConfig_PushSection(orxRENDER_KZ_CONFIG_SECTION);
    orxConfig_SetBool(orxRENDER_KZ_CONFIG_SHOW_PROFILER, !orxConfig_GetBool(orxRENDER_KZ_CONFIG_SHOW_PROFILER));
    orxConfig_PopSection();
  }

  if(orxInput_IsActive("PreviousResolution") && orxInput_HasNewStatus("PreviousResolution"))
  {
    /* Updates video mode index */
    su32VideoModeIndex = (su32VideoModeIndex == 0) ? orxDisplay_GetVideoModeCounter() - 1 : su32VideoModeIndex - 1;

    /* Applies it */
    orxBounce_ApplyCurrentVideoMode();
  }
  else if(orxInput_IsActive("NextResolution") && orxInput_HasNewStatus("NextResolution"))
  {
    /* Updates video mode index */
    su32VideoModeIndex = (su32VideoModeIndex >= orxDisplay_GetVideoModeCounter() - 1) ? 0 : su32VideoModeIndex + 1;

    /* Applies it */
    orxBounce_ApplyCurrentVideoMode();
  }
  if(orxInput_IsActive("ToggleFullScreen") && orxInput_HasNewStatus("ToggleFullScreen"))
  {
    /* Toggles full screen display */
    orxDisplay_SetFullScreen(!orxDisplay_IsFullScreen());
  }

  /* Pushes config section */
  orxConfig_PushSection("Bounce");

  /* Updates shader values */
  sfShaderPhase    += orxConfig_GetFloat("ShaderPhaseSpeed") * _pstClockInfo->fDT;
  sfShaderFrequency = orxConfig_GetFloat("ShaderMaxFrequency") * orxMath_Sin(orxConfig_GetFloat("ShaderFrequencySpeed") * _pstClockInfo->fTime);
  sfShaderAmplitude = orxConfig_GetFloat("ShaderMaxAmplitude") * orxMath_Sin(orxConfig_GetFloat("ShaderAmplitudeSpeed") * _pstClockInfo->fTime);

  /* Updates color time */
  sfColorTime -= _pstClockInfo->fDT;

  /* Should update color */
  if(sfColorTime <= orxFLOAT_0)
  {
    orxConfig_PushSection("BounceShader");
    orxConfig_GetVector("color", &svColor);
    orxConfig_PopSection();

    sfColorTime += orx2F(3.0f);
  }

  /* Gets mouse world position */
  orxRender_GetWorldPosition(&vMousePos, orxNULL, orxMouse_GetPosition(&vMousePos));

  /* Updates position */
  vMousePos.fZ += orx2F(0.5f);

  /* Has ball spawner? */
  if(spoBallSpawner != orxNULL)
  {
    /* Updates its position */
    orxSpawner_SetPosition(spoBallSpawner, &vMousePos);
  }

  /* Spawning */
  if(orxInput_IsActive("Spawn"))
  {
    /* Spawns one ball */
    orxSpawner_Spawn(spoBallSpawner, 1);
  }
  /* Picking? */
  else if(orxInput_IsActive("Pick"))
  {
    orxOBJECT *pstObject;

    /* Updates mouse position */
    vMousePos.fZ -= orx2F(0.1f);

    /* Picks object under mouse */
    pstObject = orxObject_Pick(&vMousePos, orxU32_UNDEFINED);

    /* Found? */
    if(pstObject)
    {
      /* Adds FX */
      orxObject_AddUniqueFX(pstObject, "Pick");
    }
  }

  /* Pops config section */
  orxConfig_PopSection();

  /* Toggle shader? */
  if(orxInput_IsActive("ToggleShader") && (orxInput_HasNewStatus("ToggleShader")))
  {
    /* Toggles shader status */
    sbShaderEnabled = !sbShaderEnabled;
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();
}
コード例 #3
0
ファイル: orxBounce.c プロジェクト: enobayram/orx
/** Bounce event handler
 * @param[in]   _pstEvent                     Sent event
 * @return      orxSTATUS_SUCCESS if handled / orxSTATUS_FAILURE otherwise
 */
static orxSTATUS orxFASTCALL orxBounce_EventHandler(const orxEVENT *_pstEvent)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("Bounce_EventHandler");

  /* Checks */
  orxASSERT((_pstEvent->eType == orxEVENT_TYPE_PHYSICS)
         || (_pstEvent->eType == orxEVENT_TYPE_INPUT)
         || (_pstEvent->eType == orxEVENT_TYPE_SHADER)
         || (_pstEvent->eType == orxEVENT_TYPE_SOUND)
         || (_pstEvent->eType == orxEVENT_TYPE_DISPLAY)
         || (_pstEvent->eType == orxEVENT_TYPE_TIMELINE)
         || (_pstEvent->eType == orxEVENT_TYPE_RENDER));

  /* Depending on event type */
  switch(_pstEvent->eType)
  {
    /* Input */
    case orxEVENT_TYPE_INPUT:
    {
      /* Not a set selection and console not enabled? */
      if((_pstEvent->eID != orxINPUT_EVENT_SELECT_SET) && (orxConsole_IsEnabled() == orxFALSE))
      {
        orxINPUT_EVENT_PAYLOAD *pstPayload;

        /* Gets event payload */
        pstPayload = (orxINPUT_EVENT_PAYLOAD *)_pstEvent->pstPayload;

        /* Has a multi-input info? */
        if(pstPayload->aeType[1] != orxINPUT_TYPE_NONE)
        {
          /* Logs info */
          orxLOG("[%s::%s] is %s (%s/v=%g + %s/v=%g)", pstPayload->zSetName, pstPayload->zInputName, (_pstEvent->eID == orxINPUT_EVENT_ON) ? "ON " : "OFF", orxInput_GetBindingName(pstPayload->aeType[0], pstPayload->aeID[0], pstPayload->aeMode[0]), pstPayload->afValue[0], orxInput_GetBindingName(pstPayload->aeType[1], pstPayload->aeID[1], pstPayload->aeMode[1]), pstPayload->afValue[1]);
        }
        else
        {
          /* Logs info */
          orxLOG("[%s::%s] is %s (%s/v=%g)", pstPayload->zSetName, pstPayload->zInputName, (_pstEvent->eID == orxINPUT_EVENT_ON) ? "ON " : "OFF", orxInput_GetBindingName(pstPayload->aeType[0], pstPayload->aeID[0], pstPayload->aeMode[0]), pstPayload->afValue[0]);
        }
      }

      break;
    }

    /* Physics */
    case orxEVENT_TYPE_PHYSICS:
    {
      /* Colliding? */
      if(_pstEvent->eID == orxPHYSICS_EVENT_CONTACT_ADD)
      {
        /* Adds bump FX on both objects */
        orxObject_AddUniqueFX(orxOBJECT(_pstEvent->hSender), "Bump");
        orxObject_AddUniqueFX(orxOBJECT(_pstEvent->hRecipient), "Bump");
      }

      break;
    }

    /* Shader */
    case orxEVENT_TYPE_SHADER:
    {
      orxSHADER_EVENT_PAYLOAD *pstPayload;

      /* Profiles */
      orxPROFILER_PUSH_MARKER("Bounce_EventHandler_Shader");

      /* Checks */
      orxASSERT(_pstEvent->eID == orxSHADER_EVENT_SET_PARAM);

      /* Gets its payload */
      pstPayload = (orxSHADER_EVENT_PAYLOAD *)_pstEvent->pstPayload;

      /* Enabled? */
      if(!orxString_Compare(pstPayload->zParamName, "enabled"))
      {
        /* Updates its value */
        pstPayload->fValue = (sbShaderEnabled != orxFALSE) ? orxFLOAT_1 : orxFLOAT_0;
      }
      /* Phase? */
      else if(!orxString_Compare(pstPayload->zParamName, "phase"))
      {
        /* Updates its value */
        pstPayload->fValue = sfShaderPhase;
      }
      else if(!orxString_Compare(pstPayload->zParamName, "color"))
      {
        orxVector_Copy(&pstPayload->vValue, &svColor);
      }
      /* Frequency? */
      else if(!orxString_Compare(pstPayload->zParamName, "frequency"))
      {
        /* Updates its value */
        pstPayload->fValue = sfShaderFrequency;
      }
      /* Amplitude? */
      else if(!orxString_Compare(pstPayload->zParamName, "amplitude"))
      {
        /* Updates its value */
        pstPayload->fValue = sfShaderAmplitude;
      }

      /* Profiles */
      orxPROFILER_POP_MARKER();

      break;
    }

    /* Sound */
    case orxEVENT_TYPE_SOUND:
    {
      /* Recording packet? */
      if(_pstEvent->eID == orxSOUND_EVENT_RECORDING_PACKET)
      {
        orxSOUND_EVENT_PAYLOAD *pstPayload;

        /* Gets event payload */
        pstPayload = (orxSOUND_EVENT_PAYLOAD *)_pstEvent->pstPayload;

        /* Is recording input active? */
        if(orxInput_IsActive("Record") != orxFALSE)
        {
          orxU32 i;

          /* For all samples */
          for(i = 0; i < pstPayload->stStream.stPacket.u32SampleNumber / 2; i++)
          {
            /* Shorten the packets by half */
            pstPayload->stStream.stPacket.as16SampleList[i] = pstPayload->stStream.stPacket.as16SampleList[i * 2];
          }

          /* Updates sample number */
          pstPayload->stStream.stPacket.u32SampleNumber = pstPayload->stStream.stPacket.u32SampleNumber / 2;

          /* Asks for writing it */
          pstPayload->stStream.stPacket.bDiscard = orxFALSE;
        }
        else
        {
          /* Asks for not writing it */
          pstPayload->stStream.stPacket.bDiscard = orxTRUE;
        }
      }

      break;
    }

    /* Display */
    case orxEVENT_TYPE_DISPLAY:
    {
      /* New video mode? */
      if(_pstEvent->eID == orxDISPLAY_EVENT_SET_VIDEO_MODE)
      {
        orxDISPLAY_EVENT_PAYLOAD *pstPayload;
        orxCHAR                   acBuffer[1024];

        /* Gets payload */
        pstPayload = (orxDISPLAY_EVENT_PAYLOAD *)_pstEvent->pstPayload;

        /* Updates title string */
        orxConfig_PushSection("Bounce");
        orxString_NPrint(acBuffer, sizeof(acBuffer) - 1, "%s (%dx%d)", orxConfig_GetString("Title"), pstPayload->stVideoMode.u32Width, pstPayload->stVideoMode.u32Height);
        acBuffer[sizeof(acBuffer) - 1] = orxCHAR_NULL;
        orxConfig_PopSection();

        /* Updates display module config content */
        orxConfig_PushSection(orxDISPLAY_KZ_CONFIG_SECTION);
        orxConfig_SetString(orxDISPLAY_KZ_CONFIG_TITLE, acBuffer);
        orxConfig_PopSection();

        /* Updates window */
        orxDisplay_SetVideoMode(orxNULL);
      }

      break;
    }

    /* TimeLine */
    case orxEVENT_TYPE_TIMELINE:
    {
      /* New event triggered? */
      if(_pstEvent->eID == orxTIMELINE_EVENT_TRIGGER)
      {
        orxTIMELINE_EVENT_PAYLOAD *pstPayload;

        /* Gets event payload */
        pstPayload = (orxTIMELINE_EVENT_PAYLOAD *)_pstEvent->pstPayload;

        /* Logs info */
        orxLOG("[%s::%s::%s] has been triggered", orxObject_GetName(orxOBJECT(_pstEvent->hSender)), pstPayload->zTrackName, pstPayload->zEvent);
      }

      break;
    }

    /* Render */
    case orxEVENT_TYPE_RENDER:
    {
      /* Object start? */
      if(_pstEvent->eID == orxRENDER_EVENT_OBJECT_START)
      {
        /* Is walls? */
        if(orxOBJECT(_pstEvent->hSender) == spstWalls)
        {
          /* Pushes config section */
          orxConfig_PushSection("Bounce");

          /* Should display trail */
          if(orxConfig_GetBool("DisplayTrail"))
          {
            /* Draws trail */
            orxBounce_DisplayTrail(orxTexture_GetBitmap(orxTEXTURE(orxGraphic_GetData(orxOBJECT_GET_STRUCTURE(orxOBJECT(_pstEvent->hSender), GRAPHIC)))));
          }

          /* Pops config section */
          orxConfig_PopSection();

          /* Updates result */
          eResult = orxSTATUS_FAILURE;
        }
      }

      break;
    }

    default:
    {
      break;
    }
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return eResult;
}