예제 #1
0
void FFLineMoveStrategy::ReadConfiguration()
{
	if(orxConfig_HasSection(LINE_MOVE_SECTION) == orxSTATUS_SUCCESS)
	{
		orxConfig_PushSection(LINE_MOVE_SECTION);
		orxVECTOR t;
		orxConfig_GetVector(START_POSITION_VALUE,&t);
		_startPosition = t;
		orxConfig_GetVector(FINISH_POSITION_VALUE,&t);
		_finishPosition = t;
		_speed = orxConfig_GetFloat(SPEED_MOVE_VALUE);
		const orxCHAR* axis =  orxConfig_GetString(MOVE_AXIS_VALUE);
		if(orxString_Compare(axis,AXIS_X) == 0)
			_direction = MD_X;
		else if(orxString_Compare(axis,AXIS_Y) == 0)
			_direction = MD_Y;
		else if(orxString_Compare(axis,AXIS_XY) == 0)
			_direction = MD_XY;

		const orxCHAR* repeat = orxConfig_GetString(REPEAT_VALUE);
		if(orxString_Compare(repeat,REPEAT_TOLEFT) == 0)
			_repeat =  RD_TOLEFT;
		else if(orxString_Compare(repeat,REPEAT_TORIGHT) == 0)
			_repeat = RD_TORIGHT;
		else if(orxString_Compare(repeat,REPEAT_HBOTH) == 0)
		{
			_repeat = RD_BOTH;
			if(_startPosition._x > _finishPosition._x)
				_helperDir =  RD_TOLEFT;
			else
			{
				//orxVECTOR temp = _finishPosition;
				//_finishPosition =_startPosition;
				//_startPosition = temp;
				_helperDir = RD_TORIGHT;
			}
		}
		else if(orxString_Compare(repeat,REPEAT_TODOWN) == 0)
			_repeat = RD_TODOWN;
		else if(orxString_Compare(repeat,REPEAT_TOUP) == 0)
			_repeat = RD_TOUP;
		else if(orxString_Compare(repeat,REPEAT_VBOTH) == 0)
		{
			_repeat = RD_BOTH;
			if(_startPosition._y > _finishPosition._y)
				_helperDir =  RD_TOUP;
			else
			{
				/*orxVECTOR temp = _finishPosition;
				_finishPosition =_startPosition;
				_startPosition = temp;*/
				_helperDir = RD_TODOWN;
			}
		}

		
	}
}
예제 #2
0
파일: 11_Spawner.c 프로젝트: gfphoenix/orx
/** Loads configuration
 */
static orxINLINE orxSTATUS LoadConfig()
{
  orxVIEWPORT  *pstViewport;
  orxSTATUS     eResult = orxSTATUS_FAILURE;

  /* Deletes our scene */
  if(pstScene)
  {
    orxObject_Delete(pstScene);
    pstScene = orxNULL;
  }

  /* For all the viewports */
  while((pstViewport = orxVIEWPORT(orxStructure_GetFirst(orxSTRUCTURE_ID_VIEWPORT))) != orxNULL)
  {
    /* Deletes it */
    orxViewport_Delete(pstViewport);
  }

  /* Clears all config data */
  orxConfig_Clear();

  /* Loads main config and selects tutorial section */
  orxConfig_Load(orxConfig_GetMainFileName());
  orxConfig_SelectSection("Tutorial");

  /* Is current ID valid? */
  if(ss32ConfigID < orxConfig_GetListCounter("ConfigList"))
  {
    const orxSTRING zConfigFile;

    /* Gets config file */
    zConfigFile = orxConfig_GetListString("ConfigList", ss32ConfigID);

    /* Can load it? */
    if((eResult = orxConfig_Load(zConfigFile)) != orxSTATUS_FAILURE)
    {
      orxS32 i;

      /* Pushes tutorial section */
      orxConfig_PushSection("Tutorial");

      /* For all defined viewports */
      for(i = 0; i < orxConfig_GetListCounter("ViewportList"); i++)
      {
        /* Creates it */
        orxViewport_CreateFromConfig(orxConfig_GetListString("ViewportList", i));
      }

      /* Creates our scene */
      pstScene = orxObject_CreateFromConfig("Scene");
    }
  }

  /* Done! */
  return eResult;
}
예제 #3
0
파일: orxText.c 프로젝트: enobayram/orx
/** Creates a text from config
 * @param[in]   _zConfigID    Config ID
 * @return      orxTEXT / orxNULL
 */
orxTEXT *orxFASTCALL orxText_CreateFromConfig(const orxSTRING _zConfigID)
{
  orxTEXT *pstResult;

  /* Checks */
  orxASSERT(sstText.u32Flags & orxTEXT_KU32_STATIC_FLAG_READY);
  orxASSERT((_zConfigID != orxNULL) && (_zConfigID != orxSTRING_EMPTY));

  /* Pushes section */
  if((orxConfig_HasSection(_zConfigID) != orxFALSE)
  && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE))
  {
    /* Creates text */
    pstResult = orxText_Create();

    /* Valid? */
    if(pstResult != orxNULL)
    {
      /* Stores its reference key */
      pstResult->zReference = orxString_Store(orxConfig_GetCurrentSection());

      /* Processes its config data */
      if(orxText_ProcessConfigData(pstResult) == orxSTATUS_FAILURE)
      {
        /* Logs message */
        orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't process config data for text <%s>.", _zConfigID);

        /* Deletes it */
        orxText_Delete(pstResult);

        /* Updates result */
        pstResult = orxNULL;
      }
    }

    /* Pops previous section */
    orxConfig_PopSection();
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't find config section named (%s).", _zConfigID);

    /* Updates result */
    pstResult = orxNULL;
  }

  /* Done! */
  return pstResult;
}
예제 #4
0
파일: orxBounce.c 프로젝트: enobayram/orx
/** Updates trail
 */
static void orxFASTCALL orxBounce_UpdateTrail(const orxCLOCK_INFO *_pstClockInfo, void *_pContext)
{
  orxU32    i;
  orxVECTOR vMousePos;

  /* Gets mouse position */
  orxMouse_GetPosition(&vMousePos);

  /* Updates trail timer */
  sfTrailTimer -= _pstClockInfo->fDT;

  /* Should add new segment? */
  if(sfTrailTimer <= orxFLOAT_0)
  {
    /* Pushes bounce section */
    orxConfig_PushSection("Bounce");

    /* Resets trail timer */
    sfTrailTimer = orxConfig_GetFloat("TrailTimer");

    /* Adds it to the trail */
    orxVector_Copy(&savTrailPointList[su32TrailIndex], &vMousePos);

    /* Gets its speed */
    orxConfig_GetVector("TrailSpeed", &savTrailSpeedList[su32TrailIndex]);

    /* Pops config section */
    orxConfig_PopSection();

    /* Updates trail index */
    su32TrailIndex = (su32TrailIndex + 1) % TRAIL_POINT_NUMBER;
  }
  else
  {
    /* Keeps last created point on pos */
    orxVector_Copy(&savTrailPointList[(su32TrailIndex == 0) ? TRAIL_POINT_NUMBER - 1 : su32TrailIndex - 1], &vMousePos);
  }

  /* For all segments */
  for(i = 0; i < TRAIL_POINT_NUMBER; i++)
  {
    orxVECTOR vTemp;

    /* Updates its position */
    orxVector_Add(&savTrailPointList[i], &savTrailPointList[i], orxVector_Mulf(&vTemp, &savTrailSpeedList[i], _pstClockInfo->fDT));
  }
}
예제 #5
0
파일: orxText.c 프로젝트: enobayram/orx
/** Gets corresponding locale key
 * @param[in]   _pstText    Concerned text
 * @param[in]   _zProperty  Property to get
 * @return      orxSTRING / orxNULL
 */
static orxINLINE const orxSTRING orxText_GetLocaleKey(const orxTEXT *_pstText, const orxSTRING _zProperty)
{
  const orxSTRING zResult = orxNULL;

  /* Checks */
  orxSTRUCTURE_ASSERT(_pstText);

  /* Has reference? */
  if(_pstText->zReference != orxNULL)
  {
    const orxSTRING zString;

    /* Pushes its section */
    orxConfig_PushSection(_pstText->zReference);

    /* Gets its string */
    zString = orxConfig_GetString(_zProperty);

    /* Valid? */
    if(zString != orxNULL)
    {
      /* Begins with locale marker? */
      if((*zString == orxTEXT_KC_LOCALE_MARKER) && (*(zString + 1) != orxTEXT_KC_LOCALE_MARKER))
      {
        /* Updates result */
        zResult = zString + 1;
      }
    }

    /* Pops config section */
    orxConfig_PopSection();
  }

  /* Done! */
  return zResult;
}
예제 #6
0
파일: orxText.c 프로젝트: enobayram/orx
static orxSTATUS orxFASTCALL orxText_ProcessConfigData(orxTEXT *_pstText)
{
  const orxSTRING zString;
  const orxSTRING zName;
  orxSTATUS       eResult = orxSTATUS_FAILURE;

  /* Pushes its config section */
  orxConfig_PushSection(_pstText->zReference);

  /* Gets font name */
  zName = orxConfig_GetString(orxTEXT_KZ_CONFIG_FONT);

  /* Begins with locale marker? */
  if(*zName == orxTEXT_KC_LOCALE_MARKER)
  {
    /* Gets its locale value */
    zName = (*(zName + 1) == orxTEXT_KC_LOCALE_MARKER) ? zName + 1 : orxLocale_GetString(zName + 1);
  }

  /* Valid? */
  if((zName != orxNULL) && (zName != orxSTRING_EMPTY))
  {
    orxFONT *pstFont;

    /* Creates font */
    pstFont = orxFont_CreateFromConfig(zName);

    /* Valid? */
    if(pstFont != orxNULL)
    {
      /* Stores it */
      if(orxText_SetFont(_pstText, pstFont) != orxSTATUS_FAILURE)
      {
        /* Sets its owner */
        orxStructure_SetOwner(pstFont, _pstText);

        /* Updates flags */
        orxStructure_SetFlags(_pstText, orxTEXT_KU32_FLAG_INTERNAL, orxTEXT_KU32_FLAG_NONE);
      }
      else
      {
        /* Logs message */
        orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't set font (%s) for text (%s).", zName, _pstText->zReference);

        /* Sets default font */
        orxText_SetFont(_pstText, orxFONT(orxFont_GetDefaultFont()));
      }
    }
    else
    {
      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't create font (%s) for text (%s).", zName, _pstText->zReference);

      /* Sets default font */
      orxText_SetFont(_pstText, orxFONT(orxFont_GetDefaultFont()));
    }
  }
  else
  {
    /* Sets default font */
    orxText_SetFont(_pstText, orxFONT(orxFont_GetDefaultFont()));
  }

  /* Gets its string */
  zString = orxConfig_GetString(orxTEXT_KZ_CONFIG_STRING);

  /* Begins with locale marker? */
  if(*zString == orxTEXT_KC_LOCALE_MARKER)
  {
    /* Stores its locale value */
    eResult = orxText_SetString(_pstText, (*(zString + 1) == orxTEXT_KC_LOCALE_MARKER) ? zString + 1 : orxLocale_GetString(zString + 1));
  }
  else
  {
    /* Stores raw text */
    eResult = orxText_SetString(_pstText, zString);
  }

  /* Pops config section */
  orxConfig_PopSection();

  /* Done! */
  return eResult;
}
예제 #7
0
extern "C" void orxAndroid_PumpEvents()
{
  int ident;
  int events;

  while ((ident=ALooper_pollAll(isInteractible() || sstAndroid.bDestroyRequested == orxTRUE ? 0 : -1, NULL, &events, NULL)) >= 0)
  {
    if(ident == LOOPER_ID_MAIN)
    {
      int8_t cmd = app_read_cmd();

      if(cmd == APP_CMD_PAUSE) {
        LOGI("APP_CMD_PAUSE");
        sstAndroid.bPaused = orxTRUE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_BACKGROUND);
      }
      if(cmd == APP_CMD_RESUME) {
        LOGI("APP_CMD_RESUME");
        sstAndroid.bPaused = orxFALSE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOREGROUND);
      }
      if(cmd == APP_CMD_SURFACE_DESTROYED) {
        LOGI("APP_CMD_SURFACE_DESTROYED");
        pthread_cond_broadcast(&sstAndroid.cond);

        sstAndroid.fSurfaceScale = orxFLOAT_0;
        orxEVENT_SEND(orxANDROID_EVENT_TYPE_SURFACE, orxANDROID_EVENT_SURFACE_DESTROYED, orxNULL, orxNULL, orxNULL);

        pthread_mutex_lock(&sstAndroid.mutex);
        if(sstAndroid.window != NULL)
        {
          ANativeWindow_release(sstAndroid.window);
          sstAndroid.window = NULL;
        }
        pthread_cond_broadcast(&sstAndroid.cond);
        pthread_mutex_unlock(&sstAndroid.mutex);
      }
      if(cmd == APP_CMD_SURFACE_CHANGED) {
        LOGI("APP_CMD_SURFACE_CHANGED");
        orxANDROID_SURFACE_CHANGED_EVENT stSurfaceChangedEvent;
        stSurfaceChangedEvent.u32Width = sstAndroid.u32SurfaceWidth;
        stSurfaceChangedEvent.u32Height = sstAndroid.u32SurfaceHeight;
        sstAndroid.fSurfaceScale = orxFLOAT_0;
        orxEVENT_SEND(orxANDROID_EVENT_TYPE_SURFACE, orxANDROID_EVENT_SURFACE_CHANGED, orxNULL, orxNULL, &stSurfaceChangedEvent);
      }
      if(cmd == APP_CMD_SURFACE_CREATED) {
        LOGI("APP_CMD_SURFACE_CREATED");
        pthread_mutex_lock(&sstAndroid.mutex);
        sstAndroid.window = sstAndroid.pendingWindow;
        pthread_cond_broadcast(&sstAndroid.cond);
        pthread_mutex_unlock(&sstAndroid.mutex);

        orxEVENT_SEND(orxANDROID_EVENT_TYPE_SURFACE, orxANDROID_EVENT_SURFACE_CREATED, orxNULL, orxNULL, orxNULL);
      }
      if(cmd == APP_CMD_QUIT) {
        LOGI("APP_CMD_QUIT");
        sstAndroid.bDestroyRequested = orxTRUE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_CLOSE);
      }
      if(cmd == APP_CMD_FOCUS_GAINED) {
        LOGI("APP_CMD_FOCUS_GAINED");
        sstAndroid.bHasFocus = orxTRUE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOCUS_GAINED);
      }
      if(cmd == APP_CMD_FOCUS_LOST) {
        LOGI("APP_CMD_FOCUS_LOST");
        sstAndroid.bHasFocus = orxFALSE;
        orxEvent_SendShort(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_FOCUS_LOST);
      }
    }

    if(ident == LOOPER_ID_SENSOR)
    {
      orxEvent_SendShort(orxANDROID_EVENT_TYPE_ACCELERATE, 0);
    }

    if(ident == LOOPER_ID_KEY_EVENT)
    {
      orxANDROID_KEY_EVENT stKeyEvent;

      if (read(sstAndroid.pipeKeyEvent[0], &stKeyEvent, sizeof(stKeyEvent)) == sizeof(stKeyEvent))
      {
        orxEVENT_SEND(orxANDROID_EVENT_TYPE_KEYBOARD, 0, orxNULL, orxNULL, &stKeyEvent);
      } else {
        LOGE("No data on command pipe!");
      }
    }

    if(ident == LOOPER_ID_TOUCH_EVENT)
    {
      orxANDROID_TOUCH_EVENT stTouchEvent;

      if (read(sstAndroid.pipeTouchEvent[0], &stTouchEvent, sizeof(stTouchEvent)) == sizeof(stTouchEvent))
      {
        orxSYSTEM_EVENT_PAYLOAD stPayload;

        if(sstAndroid.fSurfaceScale == orxFLOAT_0)
        {
          orxConfig_PushSection(KZ_CONFIG_ANDROID);
          sstAndroid.fSurfaceScale = orxConfig_GetFloat(KZ_CONFIG_SURFACE_SCALE);
          orxConfig_PopSection();
        }

        /* Inits event's payload */
        orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
        stPayload.stTouch.fPressure = orxFLOAT_0;
        stPayload.stTouch.fX = sstAndroid.fSurfaceScale * stTouchEvent.fX;
        stPayload.stTouch.fY = sstAndroid.fSurfaceScale * stTouchEvent.fY;
        stPayload.stTouch.u32ID = stTouchEvent.u32ID;

        switch(stTouchEvent.u32Action)
        {
        case 0: // MotionEvent.ACTION_DOWN
        case 5: // MotionEvent.ACTION_POINTER_DOWN
          orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_BEGIN, orxNULL, orxNULL, &stPayload);
          break;
        case 1: // MotionEvent.ACTION_UP
        case 6: // MotionEvent.ACTION_POINTER_UP
          orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_END, orxNULL, orxNULL, &stPayload);
          break;
        case 2: // MotionEvent.ACTION_MOVE
          orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_MOVE, orxNULL, orxNULL, &stPayload);
          break;
        }
      } else {
        LOGE("No data on command pipe!");
      }
    }

    if(ident == LOOPER_ID_JOYSTICK_EVENT)
    {
      orxANDROID_JOYSTICK_EVENT stJoystickEvent;

      if (read(sstAndroid.pipeJoystickEvent[0], &stJoystickEvent, sizeof(stJoystickEvent)) == sizeof(stJoystickEvent))
      {
        orxEVENT_SEND(orxANDROID_EVENT_TYPE_JOYSTICK, 0, orxNULL, orxNULL, &stJoystickEvent);
      } else {
        LOGE("No data on command pipe!");
      }
    }
  }
}
예제 #8
0
/** Computes next screenshot index
 * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
static orxINLINE orxSTATUS orxScreenshot_ComputeIndex()
{
  const orxSTRING zDirectory;
  const orxSTRING zBaseName;
  const orxSTRING zExtension;
  orxU32    u32Digits;
  orxSTATUS eResult = orxSTATUS_SUCCESS;

  /* Checks */
  orxASSERT(sstScreenshot.u32Flags & orxSCREENSHOT_KU32_STATIC_FLAG_READY)

  /* Uses default directory, base name, extension & digits */
  zDirectory  = orxSCREENSHOT_KZ_DEFAULT_DIRECTORY_NAME;
  zBaseName   = orxSCREENSHOT_KZ_DEFAULT_BASE_NAME;
  zExtension  = orxSCREENSHOT_KZ_DEFAULT_EXTENSION;
  u32Digits   = orxSCREENSHOT_KU32_DEFAULT_DIGITS;

  /* Pushes section */
  if((orxConfig_HasSection(orxSCREENSHOT_KZ_CONFIG_SECTION) != orxFALSE)
  && (orxConfig_PushSection(orxSCREENSHOT_KZ_CONFIG_SECTION) != orxSTATUS_FAILURE))
  {
    const orxSTRING zValue;
    orxU32          u32Value;

    /* Gets directory name */
    zValue = orxConfig_GetString(orxSCREENSHOT_KZ_CONFIG_DIRECTORY);

    /* Valid? */
    if((zValue != orxNULL) && (zValue != orxSTRING_EMPTY))
    {
      /* Stores it */
      zDirectory = zValue;
    }

    /* Gets screenshot base name */
    zValue = orxConfig_GetString(orxSCREENSHOT_KZ_CONFIG_BASE_NAME);

    /* Valid? */
    if((zValue != orxNULL) && (zValue != orxSTRING_EMPTY))
    {
      /* Stores it */
      zBaseName = zValue;
    }

    /* Gets screenshot extension */
    zValue = orxConfig_GetString(orxSCREENSHOT_KZ_CONFIG_EXTENSION);

    /* Valid? */
    if((zValue != orxNULL) && (zValue != orxSTRING_EMPTY))
    {
      /* Stores it */
      zExtension = zValue;
    }

    /* Gets digit number */
    if((u32Value = orxConfig_GetU32(orxSCREENSHOT_KZ_CONFIG_DIGITS)) > 0)
    {
      /* Stores it */
      u32Digits = u32Value;
    }

    /* Pops previous section */
    orxConfig_PopSection();
  }

  /* Valid? */
  if(orxFile_Exists(zDirectory) != orxFALSE)
  {
    do
    {
      /* Gets file to find name */
      orxString_NPrint(sstScreenshot.acScreenshotBuffer, orxSCREENSHOT_KU32_BUFFER_SIZE - 1, "%s/%s%0*d.%s", zDirectory, zBaseName, u32Digits, sstScreenshot.u32ScreenshotIndex + 1, zExtension);

      /* Updates screenshot index */
      sstScreenshot.u32ScreenshotIndex++;
    }
    /* Till not found */
    while(orxFile_Exists(sstScreenshot.acScreenshotBuffer) != orxFALSE);
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_SCREENSHOT, "Invalid directory [%s]. Please create it to enable screenshots.", zDirectory);

    /* Can't find folder */
    eResult = orxSTATUS_FAILURE;
  }

  /* Done! */
  return eResult;
}
예제 #9
0
파일: orxClock.c 프로젝트: enobayram/orx
/** Creates a clock from config
 * @param[in]   _zConfigID    Config ID
 * @ return orxCLOCK / orxNULL
 */
orxCLOCK *orxFASTCALL orxClock_CreateFromConfig(const orxSTRING _zConfigID)
{
  orxCLOCK *pstResult;

  /* Checks */
  orxASSERT(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY);

  /* Search for clock */
  pstResult = orxClock_Get(_zConfigID);

  /* Found? */
  if(pstResult != orxNULL)
  {
    /* Increases counter */
    orxStructure_IncreaseCounter(pstResult);
  }
  else
  {
    /* Pushes section */
    if((orxConfig_HasSection(_zConfigID) != orxFALSE)
    && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE))
    {
      orxFLOAT fFrequency;

      /* Gets its frequency */
      fFrequency = orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_FREQUENCY);

      /* Creates clock */
      pstResult = orxClock_Create((fFrequency > orxFLOAT_0) ? orxFLOAT_1 / fFrequency : orxFLOAT_0, orxCLOCK_TYPE_USER);

      /* Valid? */
      if(pstResult != orxNULL)
      {
        /* Has a modifier? */
        if(orxConfig_HasValue(orxCLOCK_KZ_CONFIG_MODIFIER_TYPE) != orxFALSE)
        {
          orxFLOAT fModifierValue;

          /* Gets its value */
          fModifierValue = orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_MODIFIER_VALUE);

          /* Valid? */
          if(fModifierValue > orxFLOAT_0)
          {
            const orxSTRING   zModifierType;
            orxCLOCK_MOD_TYPE eModifierType;

            /* Gets modifier type */
            zModifierType = orxConfig_GetString(orxCLOCK_KZ_CONFIG_MODIFIER_TYPE);

            /* Capped? */
            if(orxString_ICompare(zModifierType, orxCLOCK_KZ_MODIFIER_CAPPED) == 0)
            {
              /* Updates modifier value */
              fModifierValue = orxFLOAT_1 / fModifierValue;

              /* Updates modifier type */
              eModifierType = orxCLOCK_MOD_TYPE_MAXED;
            }
            /* Fixed? */
            else if(orxString_ICompare(zModifierType, orxCLOCK_KZ_MODIFIER_FIXED) == 0)
            {
              /* Updates modifier value */
              fModifierValue = orxFLOAT_1 / fModifierValue;

              /* Updates modifier type */
              eModifierType = orxCLOCK_MOD_TYPE_FIXED;
            }
            /* Multiply? */
            else if(orxString_ICompare(zModifierType, orxCLOCK_KZ_MODIFIER_MULTIPLY) == 0)
            {
              /* Updates modifier type */
              eModifierType = orxCLOCK_MOD_TYPE_MULTIPLY;
            }
            /* None */
            else
            {
              /* Updates modifier type */
              eModifierType = orxCLOCK_MOD_TYPE_NONE;
            }

            /* Updates clock */
            orxClock_SetModifier(pstResult, eModifierType, fModifierValue);
          }
        }

        /* Stores its reference key */
        pstResult->zReference = orxConfig_GetCurrentSection();

        /* Protects it */
        orxConfig_ProtectSection(pstResult->zReference, orxTRUE);

        /* Adds it to reference table */
        orxHashTable_Add(sstClock.pstReferenceTable, orxString_ToCRC(pstResult->zReference), pstResult);

        /* Updates status flags */
        orxStructure_SetFlags(pstResult, orxCLOCK_KU32_FLAG_REFERENCED, orxCLOCK_KU32_FLAG_NONE);
      }

      /* Pops previous section */
      orxConfig_PopSection();
    }
    else
    {
      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Cannot find config section named (%s).", _zConfigID);

      /* Updates result */
      pstResult = orxNULL;
    }
  }

  /* Done! */
  return pstResult;
}
예제 #10
0
파일: orxTimeLine.c 프로젝트: gfphoenix/orx
/** Adds a track
 */
static orxINLINE orxTIMELINE_TRACK *orxTimeLine_CreateTrack(const orxSTRING _zTrackID)
{
  orxTIMELINE_TRACK *pstResult = orxNULL;

  /* Pushes section */
  if((orxConfig_HasSection(_zTrackID) != orxFALSE)
  && (orxConfig_PushSection(_zTrackID) != orxSTATUS_FAILURE))
  {
    orxU32 u32KeyCounter;

    /* Gets number of keys */
    u32KeyCounter = orxConfig_GetKeyCounter();

    /* Valid? */
    if(u32KeyCounter > 0)
    {
      orxU32 u32EventCounter = 0, i;

#ifdef __orxMSVC__

      orxFLOAT *afTimeList = (orxFLOAT *)alloca(u32KeyCounter * sizeof(orxFLOAT));

#else /* __orxMSVC__ */

      orxFLOAT afTimeList[u32KeyCounter];

#endif /* __orxMSVC__ */

      /* For all time entries */
      for(i = 0; i < u32KeyCounter; i++)
      {
        /* Inits it */
        afTimeList[i] = orxFLOAT_MAX;
      }

      /* For all config keys */
      for(i = 0; i < u32KeyCounter; i++)
      {
        const orxSTRING zKey;
        orxFLOAT        fTime;

        /* Gets it */
        zKey = orxConfig_GetKey(i);

        /* Is a valid time stamp? */
        if((orxString_ToFloat(zKey, &fTime, orxNULL) != orxSTATUS_FAILURE)
        && (fTime >= orxFLOAT_0))
        {
          /* Stores it */
          afTimeList[i] = fTime;

          /* Updates event counter */
          u32EventCounter += orxConfig_GetListCounter(zKey);
        }
        else
        {
          /* Not keep in cache, immediate nor loop? */
          if((orxString_Compare(orxTIMELINE_KZ_CONFIG_KEEP_IN_CACHE, zKey) != 0)
          && (orxString_Compare(orxTIMELINE_KZ_CONFIG_IMMEDIATE, zKey) != 0)
          && (orxString_Compare(orxTIMELINE_KZ_CONFIG_LOOP, zKey) != 0))
          {
            /* Logs message */
            orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "TimeLine track [%s]: ignoring invalid key (%s).", _zTrackID, zKey);
          }
        }
      }

      /* Allocates track */
      pstResult = (orxTIMELINE_TRACK *)orxMemory_Allocate(sizeof(orxTIMELINE_TRACK) + (u32EventCounter * sizeof(orxTIMELINE_TRACK_EVENT)), orxMEMORY_TYPE_MAIN);

      /* Valid? */
      if(pstResult != orxNULL)
      {
        /* Stores its ID */
        pstResult->u32ID = orxString_GetID(orxConfig_GetCurrentSection());

        /* Adds it to reference table */
        if(orxHashTable_Set(sstTimeLine.pstTrackTable, pstResult->u32ID, pstResult) != orxSTATUS_FAILURE)
        {
          orxU32 u32EventIndex, u32Flags = orxTIMELINE_TRACK_KU32_FLAG_NONE;

          /* For all events */
          for(u32EventIndex = 0; u32EventIndex < u32EventCounter;)
          {
            const orxSTRING zKey;
            orxFLOAT        fTime;
            orxU32          u32KeyIndex, u32ListCounter;

            /* Finds time to add next */
            for(fTime = orxFLOAT_MAX, u32KeyIndex = orxU32_UNDEFINED, i = 0; i < u32KeyCounter; i++)
            {
              /* Is sooner? */
              if(afTimeList[i] < fTime)
              {
                /* Stores it */
                fTime       = afTimeList[i];
                u32KeyIndex = i;
              }
            }

            /* Checks */
            orxASSERT(u32KeyIndex != orxU32_UNDEFINED);

            /* Gets corresponding key */
            zKey = orxConfig_GetKey(u32KeyIndex);

            /* For all events */
            for(i = 0, u32ListCounter = orxConfig_GetListCounter(zKey);
                i < u32ListCounter;
                i++, u32EventIndex++)
            {
              /* Checks */
              orxASSERT(u32EventIndex < u32EventCounter);

              /* Stores event */
              pstResult->astEventList[u32EventIndex].fTimeStamp = fTime;
              pstResult->astEventList[u32EventIndex].zEventText = orxString_Store(orxConfig_GetListString(zKey, i));
            }

            /* Clears time entry */
            afTimeList[u32KeyIndex] = orxFLOAT_MAX;
          }

          /* Stores its reference */
          pstResult->zReference = orxString_GetFromID(pstResult->u32ID);

          /* Updates track counters */
          pstResult->u32RefCounter    = 1;
          pstResult->u32EventCounter  = u32EventCounter;

          /* Should keep in cache? */
          if(orxConfig_GetBool(orxTIMELINE_KZ_CONFIG_KEEP_IN_CACHE) != orxFALSE)
          {
            /* Increases its reference counter to keep it in cache table */
            pstResult->u32RefCounter++;

            /* Updates flags */
            u32Flags |= orxTIMELINE_TRACK_KU32_FLAG_CACHED;
          }

          /* Should loop? */
          if(orxConfig_GetBool(orxTIMELINE_KZ_CONFIG_LOOP) != orxFALSE)
          {
            /* Updates flags */
            u32Flags |= orxTIMELINE_TRACK_KU32_FLAG_LOOP;
          }

          /* Is immediate? */
          if(orxConfig_GetBool(orxTIMELINE_KZ_CONFIG_IMMEDIATE) != orxFALSE)
          {
            /* Updates flags */
            u32Flags |= orxTIMELINE_TRACK_KU32_FLAG_IMMEDIATE;
          }

          /* Stores flags */
          pstResult->u32Flags = u32Flags;
        }
        else
        {
          /* Logs message */
          orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Failed to add track to hashtable.");

          /* Deletes it */
          orxMemory_Free(pstResult);

          /* Updates result */
          pstResult = orxNULL;
        }
      }
      else
      {
        /* Logs message */
        orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Couldn't create TimeLine track [%s]: memory allocation failure.", _zTrackID);
      }
    }
    else
    {
      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Couldn't create TimeLine track [%s]: config section is empty.", _zTrackID);
    }

    /* Pops previous section */
    orxConfig_PopSection();
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Couldn't create TimeLine track [%s]: config section not found.", _zTrackID);
  }

  /* Done! */
  return pstResult;
}
예제 #11
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();
}
예제 #12
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;
}
예제 #13
0
파일: orxJoystick.c 프로젝트: enobayram/orx
orxSTATUS orxFASTCALL orxJoystick_Android_Init()
{
  orxSTATUS eResult = orxSTATUS_FAILURE;

  /* Wasn't already initialized? */
  if (!(sstJoystick.u32Flags & orxJOYSTICK_KU32_STATIC_FLAG_READY))
  {
    /* Cleans static controller */
    orxMemory_Zero(&sstJoystick, sizeof(orxJOYSTICK_STATIC));

    orxConfig_PushSection(KZ_CONFIG_ANDROID);

    sstJoystick.s32ScreenRotation = -1;
    sstJoystick.bAccelerometerEnabled = orxFALSE;
    sstJoystick.bUseJoystick = orxConfig_GetBool(KZ_CONFIG_USE_JOYSTICK);

    if(sstJoystick.bUseJoystick == orxTRUE)
    {
      orxAndroid_JNI_GetDeviceIds(sstJoystick.au32DeviceIds);
      orxEvent_AddHandler(orxANDROID_EVENT_TYPE_JOYSTICK, orxJoystick_Android_JoystickEventHandler);
    }
    else
    {
      sstJoystick.sensorManager = ASensorManager_getInstance();
      sstJoystick.accelerometerSensor = ASensorManager_getDefaultSensor(sstJoystick.sensorManager, ASENSOR_TYPE_ACCELEROMETER);

      if(sstJoystick.accelerometerSensor != NULL)
      {
        /* Adds our Accelerometer event handlers */
        if ((eResult = orxEvent_AddHandler(orxEVENT_TYPE_SYSTEM, orxJoystick_Android_AccelerometerEventHandler)) != orxSTATUS_FAILURE)
        {
          if ((eResult = orxEvent_AddHandler(orxANDROID_EVENT_TYPE_ACCELERATE, orxJoystick_Android_AccelerometerEventHandler)) != orxSTATUS_FAILURE)
          {
            if ((eResult = orxEvent_AddHandler(orxANDROID_EVENT_TYPE_SURFACE, orxJoystick_Android_AccelerometerEventHandler)) != orxSTATUS_FAILURE)
            {
              ALooper* looper = ALooper_forThread();
              sstJoystick.sensorEventQueue = ASensorManager_createEventQueue(sstJoystick.sensorManager, looper, LOOPER_ID_SENSOR, NULL, NULL);

              if(orxConfig_HasValue(KZ_CONFIG_ACCELEROMETER_FREQUENCY))
              {
                sstJoystick.u32Frequency = orxConfig_GetU32(KZ_CONFIG_ACCELEROMETER_FREQUENCY);
              }
              else
              { /* enable acceleromter with default rate */
                sstJoystick.u32Frequency = 60;
              }

              /* enable sensor */
              enableSensorManager();
            }
          }
        }
      }
    }

    orxConfig_PopSection();

    /* Updates status */
    sstJoystick.u32Flags |= orxJOYSTICK_KU32_STATIC_FLAG_READY;
  }

  /* Done! */
  return eResult;
}
예제 #14
0
orxSTATUS orxFASTCALL orxDisplay_SDL_Init()
{
  orxSTATUS eResult;

  /* Was not already initialized? */
  if(!(sstDisplay.u32Flags & orxDISPLAY_KU32_STATIC_FLAG_READY))
  {
    /* Cleans static controller */
    orxMemory_Zero(&sstDisplay, sizeof(orxDISPLAY_STATIC));

    /* Is SDL partly initialized? */
    if(SDL_WasInit(SDL_INIT_EVERYTHING) != 0)
    {
      /* Inits the video subsystem */
      eResult = (SDL_InitSubSystem(SDL_INIT_VIDEO) == 0) ? orxSTATUS_SUCCESS : orxSTATUS_FAILURE;
    }
    else
    {
      /* Inits SDL with video */
      eResult = (SDL_Init(SDL_INIT_VIDEO) == 0) ? orxSTATUS_SUCCESS : orxSTATUS_FAILURE;
    }

    /* Valid? */
    if(eResult != orxSTATUS_FAILURE)
    {
#ifdef __orxGP2X__

      /* Inits display using config values? */
      sstDisplay.pstScreen = SDL_SetVideoMode(orxDISPLAY_KU32_SCREEN_WIDTH, orxDISPLAY_KU32_SCREEN_HEIGHT, orxDISPLAY_KU32_SCREEN_DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT);

      /* Stores values */
      sstDisplay.fScreenWidth   = orxU2F(orxDISPLAY_KU32_SCREEN_WIDTH);
      sstDisplay.fScreenHeight  = orxU2F(orxDISPLAY_KU32_SCREEN_HEIGHT);

#else /* __orxGP2X__ */

      {
        orxU32 u32ConfigWidth, u32ConfigHeight, u32ConfigDepth, u32Flags;

        /* Gets resolution from config */
        orxConfig_PushSection(orxDISPLAY_KZ_CONFIG_SECTION);
        u32ConfigWidth  = orxConfig_GetU32(orxDISPLAY_KZ_CONFIG_WIDTH);
        u32ConfigHeight = orxConfig_GetU32(orxDISPLAY_KZ_CONFIG_HEIGHT);
        u32ConfigDepth  = orxConfig_GetU32(orxDISPLAY_KZ_CONFIG_DEPTH);

        /* Full screen? */
        if(orxConfig_GetBool(orxDISPLAY_KZ_CONFIG_FULLSCREEN) != orxFALSE)
        {
          /* Updates flags */
          u32Flags = SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
        }
        else
        {
          /* Updates flags */
          u32Flags = SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;
        }

        /* Inits display using config values? */
        if((sstDisplay.pstScreen = SDL_SetVideoMode(u32ConfigWidth, u32ConfigHeight, u32ConfigDepth, u32Flags)) == orxNULL)
        {
          /* Inits display using default parameters */
          sstDisplay.pstScreen = SDL_SetVideoMode(orxDISPLAY_KU32_SCREEN_WIDTH, orxDISPLAY_KU32_SCREEN_HEIGHT, orxDISPLAY_KU32_SCREEN_DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT);

          /* Stores values */
          sstDisplay.fScreenWidth   = orxU2F(orxDISPLAY_KU32_SCREEN_WIDTH);
          sstDisplay.fScreenHeight  = orxU2F(orxDISPLAY_KU32_SCREEN_HEIGHT);
        }
        else
        {
          /* Stores values */
          sstDisplay.fScreenWidth   = orxU2F(u32ConfigWidth);
          sstDisplay.fScreenHeight  = orxU2F(u32ConfigHeight);
        }

        /* Pops config section */
        orxConfig_PopSection();
      }

#endif /* __orxGP2X__ */

      /* Updates result ? */
      eResult = (sstDisplay.pstScreen != NULL) ? orxSTATUS_SUCCESS : orxSTATUS_FAILURE;

      /* Valid? */
      if(eResult != orxSTATUS_FAILURE)
      {
        orxCLOCK *pstClock;

        /* Gets clock */
        pstClock = orxClock_FindFirst(orx2F(-1.0f), orxCLOCK_TYPE_CORE);

        /* Valid? */
        if(pstClock != orxNULL)
        {
          /* Registers event update function */
          eResult = orxClock_Register(pstClock, orxDisplay_SDL_EventUpdate, orxNULL, orxMODULE_ID_DISPLAY, orxCLOCK_PRIORITY_HIGHEST);
        }

        /* Decoration? */
        if((orxConfig_HasValue(orxDISPLAY_KZ_CONFIG_DECORATION) == orxFALSE)
        || (orxConfig_GetBool(orxDISPLAY_KZ_CONFIG_DECORATION) != orxFALSE))
        {
          /* Logs message */
          orxLOG("This plugin can't remove window decorations.");
        }

        /* Has VSync value? */
        if(orxConfig_HasValue(orxDISPLAY_KZ_CONFIG_VSYNC) != orxFALSE)
        {
          /* Logs message */
          orxLOG("This plugin can't handle vsync.");
        }

        /* Updates its title */
        SDL_WM_SetCaption(orxConfig_GetString(orxDISPLAY_KZ_CONFIG_TITLE), orxNULL);

        /* Sets module as ready */
        sstDisplay.u32Flags = orxDISPLAY_KU32_STATIC_FLAG_READY;
      }
    }
  }

  /* Done! */
  return eResult;
}
예제 #15
0
/** Creates a graphic from config
 * @param[in]   _zConfigID            Config ID
 * @ return orxGRAPHIC / orxNULL
 */
orxGRAPHIC *orxFASTCALL orxGraphic_CreateFromConfig(const orxSTRING _zConfigID)
{
  orxGRAPHIC *pstResult;

  /* Checks */
  orxASSERT(sstGraphic.u32Flags & orxGRAPHIC_KU32_STATIC_FLAG_READY);
  orxASSERT((_zConfigID != orxNULL) && (_zConfigID != orxSTRING_EMPTY));

  /* Pushes section */
  if((orxConfig_HasSection(_zConfigID) != orxFALSE)
  && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE))
  {
    /* Creates graphic */
    pstResult = orxGraphic_Create();

    /* Valid? */
    if(pstResult != orxNULL)
    {
      const orxSTRING zName;
      orxU32          u32Flags = orxGRAPHIC_KU32_FLAG_NONE;

      /* Gets texture name */
      zName = orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_TEXTURE_NAME);

      /* Valid? */
      if((zName != orxNULL) && (zName != orxSTRING_EMPTY))
      {
        orxTEXTURE *pstTexture;

        /* Creates texture */
        pstTexture = orxTexture_CreateFromFile(zName);

        /* Valid? */
        if(pstTexture != orxNULL)
        {
          /* Links it */
          if(orxGraphic_SetData(pstResult, (orxSTRUCTURE *)pstTexture) != orxSTATUS_FAILURE)
          {
            orxVECTOR vTextureSize;

            /* Updates its owner */
            orxStructure_SetOwner(pstTexture, pstResult);

            /* Inits default 2D flags */
            u32Flags = orxGRAPHIC_KU32_FLAG_INTERNAL | orxGRAPHIC_KU32_FLAG_2D;

            /* Has size? */
            if(orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_TEXTURE_SIZE, &vTextureSize) != orxNULL)
            {
              orxVECTOR vTextureOrigin;

              /* Has origin? */
              if(orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_TEXTURE_ORIGIN, &vTextureOrigin) != orxNULL)
              {
                /* Stores them */
                pstResult->fLeft    = vTextureOrigin.fX;
                pstResult->fTop     = vTextureOrigin.fY;
                pstResult->fWidth   = vTextureSize.fX;
                pstResult->fHeight  = vTextureSize.fY;
              }
              /* Has corner? */
              else if(orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_TEXTURE_CORNER, &vTextureOrigin) != orxNULL)
              {
                /* Stores them */
                pstResult->fLeft    = vTextureOrigin.fX;
                pstResult->fTop     = vTextureOrigin.fY;
                pstResult->fWidth   = vTextureSize.fX;
                pstResult->fHeight  = vTextureSize.fY;
              }
              else
              {
                /* Updates size */
                orxGraphic_UpdateSize(pstResult);
              }
            }
            else
            {
              /* Updates size */
              orxGraphic_UpdateSize(pstResult);
            }
          }
          else
          {
            /* Logs message */
            orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't link texture (%s) data to graphic (%s).", zName, _zConfigID);

            /* Deletes structures */
            orxTexture_Delete(pstTexture);
          }
        }
      }

      /* Still no data? */
      if(pstResult->pstData == orxNULL)
      {
        /* Gets text name */
        zName = orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_TEXT_NAME);

        /* Valid? */
        if((zName != orxNULL) && (zName != orxSTRING_EMPTY))
        {
          orxTEXT *pstText;

          /* Creates text */
          pstText = orxText_CreateFromConfig(zName);

          /* Valid? */
          if(pstText != orxNULL)
          {
            /* Links it */
            if(orxGraphic_SetData(pstResult, (orxSTRUCTURE *)pstText) != orxSTATUS_FAILURE)
            {
              /* Sets its owner */
              orxStructure_SetOwner(pstText, pstResult);

              /* Inits default text flags */
              u32Flags = orxGRAPHIC_KU32_FLAG_INTERNAL | orxGRAPHIC_KU32_FLAG_TEXT;

              /* Updates size */
              orxGraphic_UpdateSize(pstResult);
            }
            else
            {
              /* Logs message */
              orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't link text (%s) data to graphic (%s).", zName, _zConfigID);

              /* Deletes structures */
              orxText_Delete(pstText);
            }
          }
        }
      }

      /* Has data? */
      if(pstResult->pstData != orxNULL)
      {
        const orxSTRING zFlipping;
        orxVECTOR       vPivot;

        /* Gets pivot value */
        if(orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_PIVOT, &vPivot) != orxNULL)
        {
          /* Updates it */
          orxGraphic_SetPivot(pstResult, &vPivot);
        }
        /* Has relative pivot point? */
        else if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_PIVOT) != orxFALSE)
        {
          orxCHAR   acBuffer[64];
          orxSTRING zRelativePos;
          orxU32    u32AlignmentFlags = orxGRAPHIC_KU32_FLAG_ALIGN_CENTER;

          /* Gets lower case value */
          acBuffer[sizeof(acBuffer) - 1] = orxCHAR_NULL;
          zRelativePos = orxString_LowerCase(orxString_NCopy(acBuffer, orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_PIVOT), sizeof(acBuffer) - 1));

          /* Left? */
          if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_LEFT_PIVOT) != orxNULL)
          {
            /* Updates alignment flags */
            u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_LEFT;
          }
          /* Right? */
          else if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_RIGHT_PIVOT) != orxNULL)
          {
            /* Updates alignment flags */
            u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_RIGHT;
          }

          /* Top? */
          if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_TOP_PIVOT) != orxNULL)
          {
            /* Updates alignment flags */
            u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_TOP;
          }
          /* Bottom? */
          else if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_BOTTOM_PIVOT) != orxNULL)
          {
            /* Updates alignment flags */
            u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_BOTTOM;
          }

          /* Truncate? */
          if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_TRUNCATE_PIVOT) != orxNULL)
          {
            /* Updates alignment flags */
            u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_TRUNCATE;
          }
          /* Round? */
          else if(orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_ROUND_PIVOT) != orxNULL)
          {
            /* Updates alignment flags */
            u32AlignmentFlags |= orxGRAPHIC_KU32_FLAG_ALIGN_ROUND;
          }

          /* Valid? */
          if((u32AlignmentFlags != orxGRAPHIC_KU32_FLAG_ALIGN_CENTER)
          || (orxString_SearchString(zRelativePos, orxGRAPHIC_KZ_CENTERED_PIVOT) != orxNULL))
          {
            /* Applies it */
            orxGraphic_SetRelativePivot(pstResult, u32AlignmentFlags);
          }
        }

        /* Gets flipping value */
        zFlipping = orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_FLIP);

        /* X flipping? */
        if(orxString_ICompare(zFlipping, orxGRAPHIC_KZ_X) == 0)
        {
          /* Updates frame flags */
          u32Flags |= orxGRAPHIC_KU32_FLAG_FLIP_X;
        }
        /* Y flipping? */
        else if(orxString_ICompare(zFlipping, orxGRAPHIC_KZ_Y) == 0)
        {
          /* Updates frame flags */
          u32Flags |= orxGRAPHIC_KU32_FLAG_FLIP_Y;
        }
        /* Both flipping? */
        else if(orxString_ICompare(zFlipping, orxGRAPHIC_KZ_BOTH) == 0)
        {
          /* Updates frame flags */
          u32Flags |= orxGRAPHIC_KU32_FLAG_FLIP_X | orxGRAPHIC_KU32_FLAG_FLIP_Y;
        }

        /* Has color? */
        if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_COLOR) != orxFALSE)
        {
          orxVECTOR vColor;

          /* Gets its value */
          orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_COLOR, &vColor);

          /* Normalizes and applies it */
          orxVector_Mulf(&(pstResult->stColor.vRGB), &vColor, orxCOLOR_NORMALIZER);

          /* Updates status */
          orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE);
        }
        /* Has RGB values? */
        else if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_RGB) != orxFALSE)
        {
          /* Gets its value */
          orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_RGB, &(pstResult->stColor.vRGB));

          /* Updates status */
          orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE);
        }
        /* Has HSL values? */
        else if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_HSL) != orxFALSE)
        {
          /* Gets its value */
          orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_HSL, &(pstResult->stColor.vHSL));

          /* Stores its RGB equivalent */
          orxColor_FromHSLToRGB(&(pstResult->stColor), &(pstResult->stColor));

          /* Updates status */
          orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE);
        }
        /* Has HSV values? */
        else if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_HSV) != orxFALSE)
        {
          /* Gets its value */
          orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_HSV, &(pstResult->stColor.vHSV));

          /* Stores its RGB equivalent */
          orxColor_FromHSVToRGB(&(pstResult->stColor), &(pstResult->stColor));

          /* Updates status */
          orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE);
        }

        /* Has alpha? */
        if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_ALPHA) != orxFALSE)
        {
          /* Applies it */
          orxColor_SetAlpha(&(pstResult->stColor), orxConfig_GetFloat(orxGRAPHIC_KZ_CONFIG_ALPHA));

          /* Updates status */
          orxStructure_SetFlags(pstResult, orxGRAPHIC_KU32_FLAG_HAS_COLOR, orxGRAPHIC_KU32_FLAG_NONE);
        }

        /* Should repeat? */
        if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_REPEAT) != orxFALSE)
        {
          orxVECTOR vRepeat;

          /* Gets its value */
          orxConfig_GetVector(orxGRAPHIC_KZ_CONFIG_REPEAT, &vRepeat);

          /* Stores it */
          orxGraphic_SetRepeat(pstResult, vRepeat.fX, vRepeat.fY);
        }

        /* Has smoothing value? */
        if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_SMOOTHING) != orxFALSE)
        {
          /* Updates flags */
          u32Flags |= (orxConfig_GetBool(orxGRAPHIC_KZ_CONFIG_SMOOTHING) != orxFALSE) ? orxGRAPHIC_KU32_FLAG_SMOOTHING_ON : orxGRAPHIC_KU32_FLAG_SMOOTHING_OFF;
        }

        /* Has blend mode? */
        if(orxConfig_HasValue(orxGRAPHIC_KZ_CONFIG_BLEND_MODE) != orxFALSE)
        {
          const orxSTRING       zBlendMode;
          orxDISPLAY_BLEND_MODE eBlendMode;

          /* Gets blend mode value */
          zBlendMode = orxConfig_GetString(orxGRAPHIC_KZ_CONFIG_BLEND_MODE);
          eBlendMode = orxDisplay_GetBlendModeFromString(zBlendMode);

          /* Depending on blend mode */
          switch(eBlendMode)
          {
            case orxDISPLAY_BLEND_MODE_ALPHA:
            {
              /* Updates flags */
              u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_ALPHA;

              break;
            }

            case orxDISPLAY_BLEND_MODE_MULTIPLY:
            {
              /* Updates flags */
              u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_MULTIPLY;

              break;
            }

            case orxDISPLAY_BLEND_MODE_ADD:
            {
              /* Updates flags */
              u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_ADD;

              break;
            }

            case orxDISPLAY_BLEND_MODE_PREMUL:
            {
              /* Updates flags */
              u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_PREMUL;

              break;
            }

            default:
            {
            }
          }
        }
        else
        {
          /* Defaults to alpha */
          u32Flags |= orxGRAPHIC_KU32_FLAG_BLEND_MODE_ALPHA;
        }

        /* Stores its reference key */
        pstResult->zReference = orxConfig_GetCurrentSection();

        /* Protects it */
        orxConfig_ProtectSection(pstResult->zReference, orxTRUE);

        /* Updates status flags */
        orxStructure_SetFlags(pstResult, u32Flags, orxGRAPHIC_KU32_FLAG_NONE);
      }
      else
      {
        /* Logs message */
        orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't get text or texture for graphic (%s).", _zConfigID);

        /* Deletes structures */
        orxGraphic_Delete(pstResult);

        /* Updates result */
        pstResult = orxNULL;
      }
    }

    /* Pops previous section */
    orxConfig_PopSection();
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_DISPLAY, "Couldn't find config section named (%s).", _zConfigID);

    /* Updates result */
    pstResult = orxNULL;
  }

  /* Done! */
  return pstResult;
}
예제 #16
0
/** Loads a plugin using OS common library extension + release/debug suffixes
 * @param[in] _zPluginFileName  The complete path of the plugin file, without its library extension
 * @param[in] _zPluginName      The name that the plugin will be given in the plugin list
 * @return The plugin handle on success, orxHANDLE_UNDEFINED on failure
 */
orxHANDLE orxFASTCALL orxPlugin_LoadUsingExt(const orxSTRING _zPluginFileName, const orxSTRING _zPluginName)
{
  orxHANDLE hResult = orxHANDLE_UNDEFINED;

#ifdef __orxPLUGIN_DYNAMIC__

  orxCHAR zFileName[256];

#ifdef __orxDEBUG__

  orxSTRING zDebugSuffix;

  /* Pushes section */
  orxConfig_PushSection(orxPLUGIN_KZ_CONFIG_SECTION);

#endif /* __ orxDEBUG__ */

  /* Checks */
  orxASSERT(sstPlugin.u32Flags & orxPLUGIN_KU32_STATIC_FLAG_READY);
  orxASSERT(_zPluginFileName != orxNULL);
  orxASSERT(orxString_GetLength(_zPluginFileName) + orxMAX(orxString_GetLength(orxConfig_GetString(orxPLUGIN_KZ_CONFIG_DEBUG_SUFFIX)), orxString_GetLength(orxPLUGIN_KZ_DEFAULT_DEBUG_SUFFIX)) < 252);
  orxASSERT(_zPluginName != orxNULL);

  /* Inits buffer */
  zFileName[sizeof(zFileName) - 1] = orxCHAR_NULL;

#ifdef __orxDEBUG__

  /* Gets debug suffix */
  zDebugSuffix = (orxSTRING)((orxConfig_HasValue(orxPLUGIN_KZ_CONFIG_DEBUG_SUFFIX) != orxFALSE) ? orxConfig_GetString(orxPLUGIN_KZ_CONFIG_DEBUG_SUFFIX) : orxPLUGIN_KZ_DEFAULT_DEBUG_SUFFIX);

  /* Gets complete name */
  orxString_NPrint(zFileName, sizeof(zFileName) - 1, "%s%s.%s", _zPluginFileName, zDebugSuffix, szPluginLibraryExt);

  /* Loads it */
  hResult = orxPlugin_Load(zFileName, _zPluginName);

  /* Not valid? */
  if(hResult == orxHANDLE_UNDEFINED)
  {

#endif /* __orxDEBUG__ */

  /* Gets complete name */
  orxString_NPrint(zFileName, sizeof(zFileName) - 1, "%s.%s", _zPluginFileName, szPluginLibraryExt);

  /* Loads it */
  hResult = orxPlugin_Load(zFileName, _zPluginName);

#ifdef __orxDEBUG__

  }

  /* Pops previous section */
  orxConfig_PopSection();

#endif /* __orxDEBUG__ */

#else /* __orxPLUGIN_DYNAMIC__ */

  /* Logs message */
  orxDEBUG_PRINT(orxDEBUG_LEVEL_PLUGIN, "Ignoring function call: this version of orx has been compiled without dynamic plugin support.");

#endif /* __orxPLUGIN_DYNAMIC__ */

  /* Done! */
  return hResult;
}
예제 #17
0
파일: orxMouse.c 프로젝트: enobayram/orx
orxSTATUS orxFASTCALL orxMouse_GLFW_Init()
{
  orxSTATUS eResult = orxSTATUS_FAILURE;

  /* Was already initialized. */
  if(!(sstMouse.u32Flags & orxMOUSE_KU32_STATIC_FLAG_READY))
  {
    /* Cleans static controller */
    orxMemory_Zero(&sstMouse, sizeof(orxMOUSE_STATIC));

    /* Is GLFW window opened? */
    if(glfwGetWindowParam(GLFW_OPENED) != GL_FALSE)
    {
      orxCLOCK *pstClock;

      /* Gets core clock */
      pstClock = orxClock_FindFirst(orx2F(-1.0f), orxCLOCK_TYPE_CORE);

      /* Valid? */
      if(pstClock != orxNULL)
      {
        /* Registers update function */
        eResult = orxClock_Register(pstClock, orxMouse_GLFW_Update, orxNULL, orxMODULE_ID_MOUSE, orxCLOCK_PRIORITY_HIGHER);

        /* Success? */
        if(eResult != orxSTATUS_FAILURE)
        {
          /* Registers clean function */
          eResult = orxClock_Register(pstClock, orxMouse_GLFW_Clean, orxNULL, orxMODULE_ID_MOUSE, orxCLOCK_PRIORITY_LOWER);
        }
        else
        {
          /* Unregisters update function */
          orxClock_Unregister(pstClock, orxMouse_GLFW_Update);
        }
      }

      /* Success? */
      if(eResult != orxSTATUS_FAILURE)
      {
        /* Updates status */
        sstMouse.u32Flags |= orxMOUSE_KU32_STATIC_FLAG_READY;

        /* Adds event handler */
        orxEvent_AddHandler(orxEVENT_TYPE_DISPLAY, orxMouse_GLFW_EventHandler);

        /* Registers mouse position callback */
        glfwSetMousePosCallback(orxMouse_GLFW_MousePositionCallback);

        /* Registers mouse wheel callback */
        glfwSetMouseWheelCallback(orxMouse_GLFW_MouseWheelCallback);

        /* Pushes config section */
        orxConfig_PushSection(orxMOUSE_KZ_CONFIG_SECTION);

        /* Has show cursor value? */
        if(orxConfig_HasValue(orxMOUSE_KZ_CONFIG_SHOW_CURSOR) != orxFALSE)
        {
          /* Updates cursor status */
          orxMouse_GLFW_ShowCursor(orxConfig_GetBool(orxMOUSE_KZ_CONFIG_SHOW_CURSOR));
        }

        /* Pops config section */
        orxConfig_PopSection();
      }
    }
  }

  /* Done! */
  return eResult;
}
예제 #18
0
/** Creates a camera from config
 * @param[in]   _zConfigID    Config ID
 * @ return orxCAMERA / orxNULL
 */
orxCAMERA *orxFASTCALL orxCamera_CreateFromConfig(const orxSTRING _zConfigID)
{
  orxCAMERA *pstResult;

  /* Checks */
  orxASSERT(sstCamera.u32Flags & orxCAMERA_KU32_STATIC_FLAG_READY);

  /* Search for camera */
  pstResult = orxCamera_Get(_zConfigID);

  /* Not already created? */
  if(pstResult == orxNULL)
  {
    /* Pushes section */
    if((orxConfig_HasSection(_zConfigID) != orxFALSE)
    && (orxConfig_PushSection(_zConfigID) != orxSTATUS_FAILURE))
    {
      /* Creates 2D default camera */
      pstResult = orxCamera_Create(orxCAMERA_KU32_FLAG_2D);

      /* Valid? */
      if(pstResult != orxNULL)
      {
        orxVECTOR vPosition;
        orxFLOAT  fNear, fFar, fWidth, fHeight;

        /* Gets frustum info */
        fNear   = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_NEAR);
        fFar    = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_FAR);
        fWidth  = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_WIDTH);
        fHeight = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_FRUSTUM_HEIGHT);

        /* Applies it */
        orxCamera_SetFrustum(pstResult, fWidth, fHeight, fNear, fFar);

        /* Has zoom? */
        if(orxConfig_HasValue(orxCAMERA_KZ_CONFIG_ZOOM) != orxFALSE)
        {
          orxFLOAT fZoom;

          /* Gets config zoom */
          fZoom = orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_ZOOM);

          /* Valid? */
          if(fZoom > orxFLOAT_0)
          {
            /* Applies it */
            orxCamera_SetZoom(pstResult, fZoom);
          }
        }

        /* Has a position? */
        if(orxConfig_GetVector(orxCAMERA_KZ_CONFIG_POSITION, &vPosition) != orxNULL)
        {
          /* Updates camera position */
          orxCamera_SetPosition(pstResult, &vPosition);
        }

        /* Updates object rotation */
        orxCamera_SetRotation(pstResult, orxMATH_KF_DEG_TO_RAD * orxConfig_GetFloat(orxCAMERA_KZ_CONFIG_ROTATION));

        /* Stores its reference key */
        pstResult->zReference = orxConfig_GetCurrentSection();

        /* Protects it */
        orxConfig_ProtectSection(pstResult->zReference, orxTRUE);

        /* Adds it to reference table */
        orxHashTable_Add(sstCamera.pstReferenceTable, orxString_ToCRC(pstResult->zReference), pstResult);

        /* Updates status flags */
        orxStructure_SetFlags(pstResult, orxCAMERA_KU32_FLAG_REFERENCED, orxCAMERA_KU32_FLAG_NONE);
      }

      /* Pops previous section */
      orxConfig_PopSection();
    }
    else
    {
      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Cannot find config section named (%s).", _zConfigID);

      /* Updates result */
      pstResult = orxNULL;
    }
  }

  /* Done! */
  return pstResult;
}
예제 #19
0
파일: orxClock.c 프로젝트: enobayram/orx
/** Inits clock module
 * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxClock_Init()
{
  orxSTATUS eResult = orxSTATUS_FAILURE;

  /* Not already Initialized? */
  if(!(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY))
  {
    /* Registers structure type */
    eResult = orxSTRUCTURE_REGISTER(CLOCK, orxSTRUCTURE_STORAGE_TYPE_LINKLIST, orxMEMORY_TYPE_MAIN, orxCLOCK_KU32_BANK_SIZE, orxNULL);

    /* Successful? */
    if(eResult != orxSTATUS_FAILURE)
    {
      /* Cleans control structure */
      orxMemory_Zero(&sstClock, sizeof(orxCLOCK_STATIC));

      /* Creates timer bank */
      sstClock.pstTimerBank = orxBank_Create(orxCLOCK_KU32_TIMER_BANK_SIZE, sizeof(orxCLOCK_TIMER_STORAGE), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN);

      /* Valid? */
      if(sstClock.pstTimerBank != orxNULL)
      {
        /* Creates reference table */
        sstClock.pstReferenceTable = orxHashTable_Create(orxCLOCK_KU32_REFERENCE_TABLE_SIZE, orxHASHTABLE_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN);

        /* Valid? */
        if(sstClock.pstReferenceTable != orxNULL)
        {
          orxCLOCK *pstClock;

          /* No mod type by default */
          sstClock.eModType = orxCLOCK_MOD_TYPE_NONE;

          /* Gets init time */
          sstClock.dTime  = orxSystem_GetTime();

          /* Inits Flags */
          sstClock.u32Flags = orxCLOCK_KU32_STATIC_FLAG_READY;

          /* Gets main clock tick size */
          orxConfig_PushSection(orxCLOCK_KZ_CONFIG_SECTION);
          sstClock.fMainClockTickSize = (orxConfig_HasValue(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY) && orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY) > orxFLOAT_0) ? (orxFLOAT_1 / orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY)) : orxFLOAT_0;
          orxConfig_PopSection();

          /* Creates default full speed core clock */
          pstClock = orxClock_Create(sstClock.fMainClockTickSize, orxCLOCK_TYPE_CORE);

          /* Success? */
          if(pstClock != orxNULL)
          {
            /* Sets it as its own owner */
            orxStructure_SetOwner(pstClock, pstClock);

            /* Updates result */
            eResult = orxSTATUS_SUCCESS;
          }
          else
          {
            /* Updates result */
            eResult = orxSTATUS_FAILURE;
          }
        }
        else
        {
          /* Deletes timer bank */
          orxBank_Delete(sstClock.pstTimerBank);
          sstClock.pstTimerBank = orxNULL;

          /* Updates result */
          eResult = orxSTATUS_FAILURE;
        }
      }
      else
      {
        /* Logs message */
        orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Failed creating clock bank.");

        /* Clock bank not created */
        eResult = orxSTATUS_FAILURE;
      }
    }
    else
    {
      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Failed to register link list structure.");
    }
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Tried to initialize clock module when it was already initialized.");

    /* Already initialized */
    eResult = orxSTATUS_SUCCESS;
  }

  /* Done! */
  return eResult;
}