/* *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * SCR_Cxt.c * Contexts. * * Scripts, Beaudet Christophe *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* *================================================================================================= * Includes. *================================================================================================= */ #include #include "SCR.h" /* *================================================================================================= * Global variables. *================================================================================================= */ /* * Array of all contexts. */ SCR_tdst_DyAr_Description SCR_g_st_Cxt_Array; /* *================================================================================================= * Functions. *================================================================================================= */ /* *------------------------------------------------------------------------------------------------- * Init. *------------------------------------------------------------------------------------------------- */ void fn_v_Cxt_InitModule(void) { fn_v_DyAr_InitArray(&SCR_g_st_Cxt_Array); } /* *------------------------------------------------------------------------------------------------- * Close. *------------------------------------------------------------------------------------------------- */ void fn_v_Cxt_CloseModule(void) { SCR_M_DyAr_DeleteAllElementsStatic(SCR_tdst_Cxt_Description, &SCR_g_st_Cxt_Array, ;); } /*===============================================================================================*/ /* *------------------------------------------------------------------------------------------------- * To Add one open context. *------------------------------------------------------------------------------------------------- */ SCR_tdst_Cxt_Description *fnp_st_Cxt_Add(void) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ unsigned int uiPos; SCR_tdst_Cxt_Description *p_stContext; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* Add element */ SCR_M_DyAr_AddElementStatic(SCR_tdst_Cxt_Description, uiPos, p_stContext, SCR_g_st_Cxt_Array); /* Return result */ return p_stContext; } /* *------------------------------------------------------------------------------------------------- * To delete the last open context. * g_ui_Cxt_CurrentContext is decreased, but context is kept. *------------------------------------------------------------------------------------------------- */ void fn_v_Cxt_DeleteLast(void) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ SCR_M_Dbg_Assert_P(SCR_M_Cxt_GetCurrentContext() >= 0); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ SCR_g_st_Cxt_Array.d_stDynArray[SCR_M_Cxt_GetCurrentContext()].eState = SCR_EDAS_DyAr_Free; SCR_g_st_Cxt_Array.uiNumValues--; } /*===============================================================================================*/ /* *------------------------------------------------------------------------------------------------- * To compute a context with a specific offset. * If offset is out uiMaxValues, we force allocation of a new set of contexts. * If offset is out uiNumValues, we allocate it if it was not done before. * _iOffset : Offset to get. * Returns address of structure. *------------------------------------------------------------------------------------------------- */ SCR_tdst_Cxt_Description *fnp_st_Cxt_Compute(int _iOffset) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ int iLevel = SCR_M_Cxt_GetCurrentContext() + _iOffset; unsigned int uiMemo; SCR_tdst_Cxt_Description *p_stContext; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ SCR_M_Dbg_Assert_D(iLevel >= 0); /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* * To be sure that dynamic array is big enough. * Else we (re)allocate array until it is big enough to return the asked context. */ while(iLevel >= (int) SCR_g_st_Cxt_Array.uiMaxValues) { uiMemo = SCR_g_st_Cxt_Array.uiNumValues; SCR_g_st_Cxt_Array.uiNumValues = SCR_g_st_Cxt_Array.uiMaxValues; p_stContext = fnp_st_Cxt_Add(); SCR_g_st_Cxt_Array.d_stDynArray[SCR_g_st_Cxt_Array.uiNumValues].eState = SCR_EDAS_DyAr_Free; SCR_g_st_Cxt_Array.uiNumValues = uiMemo; } /* * To be sure that context has been allocated at the given position. */ if ( (iLevel >= (int) SCR_g_st_Cxt_Array.uiNumValues) && (SCR_g_st_Cxt_Array.d_stDynArray[iLevel].d_vElement == NULL) ) { fn_v_Mem_SetMode(0); SCR_M_Mem_AllocAndSet ( SCR_tdst_Cxt_Description, p_stContext, 1 ); SCR_g_st_Cxt_Array.d_stDynArray[iLevel].d_vElement = (void *) p_stContext; SCR_M_Dbg_UpdateSizeOf_P(SCR_tdst_Cxt_Description, p_stContext); } else { p_stContext = (SCR_tdst_Cxt_Description *) SCR_g_st_Cxt_Array.d_stDynArray[iLevel].d_vElement; } SCR_M_Dbg_AssertStruct_P(SCR_tdst_Cxt_Description, p_stContext); SCR_M_Dbg_Assert_P(SCR_g_st_Cxt_Array.d_stDynArray[iLevel].d_vElement != NULL); return p_stContext; }