示例#1
0
/** Deletes a camera
 * @param[in]   _pstCamera      Camera to delete
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxCamera_Delete(orxCAMERA *_pstCamera)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;

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

  /* Not referenced? */
  if(orxStructure_GetRefCounter(_pstCamera) == 0)
  {
    /* Removes frame reference */
    orxStructure_DecreaseCounter(_pstCamera->pstFrame);

    /* Deletes frame*/
    orxFrame_Delete(_pstCamera->pstFrame);

    /* Is referenced? */
    if(orxStructure_TestFlags(_pstCamera, orxCAMERA_KU32_FLAG_REFERENCED) != orxFALSE)
    {
      /* Removes it from reference table */
      orxHashTable_Remove(sstCamera.pstReferenceTable, orxString_ToCRC(_pstCamera->zReference));
    }

    /* Has reference? */
    if(_pstCamera->zReference != orxNULL)
    {
      /* Unprotects it */
      orxConfig_ProtectSection(_pstCamera->zReference, orxFALSE);
    }

    /* Deletes structure */
    orxStructure_Delete(_pstCamera);
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Cannot delete camera while it is still referenced.");

    /* Referenced by others */
    eResult = orxSTATUS_FAILURE;
  }

  /* Done! */
  return eResult;
}
示例#2
0
/** Deletes a graphic
 * @param[in]   _pstGraphic     Graphic to delete
 */
orxSTATUS orxFASTCALL orxGraphic_Delete(orxGRAPHIC *_pstGraphic)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;

  /* Checks */
  orxASSERT(sstGraphic.u32Flags & orxGRAPHIC_KU32_STATIC_FLAG_READY);
  orxSTRUCTURE_ASSERT(_pstGraphic);

  /* Decreases counter */
  orxStructure_DecreaseCounter(_pstGraphic);

  /* Not referenced? */
  if(orxStructure_GetRefCounter(_pstGraphic) == 0)
  {
    /* Cleans data */
    orxGraphic_SetData(_pstGraphic, orxNULL);

    /* Has reference? */
    if(_pstGraphic->zReference != orxNULL)
    {
      /* Unprotects it */
      orxConfig_ProtectSection(_pstGraphic->zReference, orxFALSE);
    }

    /* Deletes structure */
    orxStructure_Delete(_pstGraphic);
  }
  else
  {
    /* Referenced by others */
    eResult = orxSTATUS_FAILURE;
  }

  /* Done! */
  return eResult;
}
示例#3
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;
}
示例#4
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;
}
示例#5
0
文件: orxClock.c 项目: enobayram/orx
/** Deletes a clock
 * @param[in]   _pstClock                             Concerned clock
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxClock_Delete(orxCLOCK *_pstClock)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;

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

  /* Decreases counter */
  orxStructure_DecreaseCounter(_pstClock);

  /* Not referenced? */
  if(orxStructure_GetRefCounter(_pstClock) == 0)
  {
    /* Not locked? */
    if(!orxStructure_TestFlags(_pstClock, orxCLOCK_KU32_FLAG_UPDATE_LOCK))
    {
      orxCLOCK_TIMER_STORAGE *pstTimerStorage;

      /* For all stored timers */
      for(pstTimerStorage = (orxCLOCK_TIMER_STORAGE *)orxLinkList_GetFirst(&(_pstClock->stTimerList));
          pstTimerStorage != orxNULL;
          pstTimerStorage = (orxCLOCK_TIMER_STORAGE *)orxLinkList_GetFirst(&(_pstClock->stTimerList)))
      {
        /* Removes it */
        orxLinkList_Remove(&(pstTimerStorage->stNode));

        /* Deletes it */
        orxBank_Free(sstClock.pstTimerBank, pstTimerStorage);
      }

      /* Deletes function bank */
      orxBank_Delete(_pstClock->pstFunctionBank);

      /* Is referenced? */
      if(orxStructure_TestFlags(_pstClock, orxCLOCK_KU32_FLAG_REFERENCED))
      {
        /* Removes it from reference table */
        orxHashTable_Remove(sstClock.pstReferenceTable, orxString_ToCRC(_pstClock->zReference));
      }

      /* Has reference? */
      if(_pstClock->zReference != orxNULL)
      {
        /* Unprotects it */
        orxConfig_ProtectSection(_pstClock->zReference, orxFALSE);
      }

      /* Deletes clock */
      orxStructure_Delete(_pstClock);
    }
    else
    {
      /* Increases counter */
      orxStructure_IncreaseCounter(_pstClock);

      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Can't delete clock <%s> as it's currently locked for processing!", orxStructure_TestFlags(_pstClock, orxCLOCK_KU32_FLAG_REFERENCED) ? _pstClock->zReference : orxSTRING_EMPTY);

      /* Updates result */
      eResult = orxSTATUS_FAILURE;
    }
  }
  else
  {
    /* Referenced by others */
    eResult = orxSTATUS_FAILURE;
  }

  /* Done! */
  return eResult;
}
示例#6
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;
}