// **********************************************************************************
// * "inifile.c"																	*
// * Written by :	Carlos Torres													*
// * Tabulations :	4 char															*
// **********************************************************************************

// **********************************************************************************
//																	Included files

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#include "SCR.h"

#include "a3x_glob.h"
#include "makeanim.h"
#include "l_global_v6.h"

// **********************************************************************************
//								SCRIPT FORMAT
// **********************************************************************************
#define KEY_UNCOMPRESS		"Uncompactable"
#define KEY_PRECISION		"Precision"
#define KEY_DEFAULT_EPS		"DefaultPrecision"

// ********************************************************************************** fn_eFamilyCallBack
//								FAMILY CALLBACK
// **********************************************************************************
SCR_tde_Anl_ReturnValue	fn_eFamilyCallBack(	SCR_tdst_File_Description	*_p_stFile,
												char						*_p_szName,
												char						*_ap_SzParam[],
												SCR_tde_Anl_Action			_eAction ) {

	if	(_eAction == SCR_EA_Anl_BeginSection) {
		// Nothing to do
	}
	else if	(_eAction == SCR_EA_Anl_Entry) {
		// force uncompress for that family
		if	(!stricmp(_p_szName,KEY_UNCOMPRESS) ) {
			bCompactTbl = FALSE;
		}

		// set default precision for all anim
		else if	(!stricmp(_p_szName,KEY_DEFAULT_EPS) ) {
			int i;
			SEB_xReal xPrecision;

			// check and set epsilon
			xPrecision = ReadDouble(0);
			if ((xPrecision > 0) && (xPrecision < 0.1)) {
				xDefaultEps = xPrecision;
				for (i=0;i<g_uwTotalNumOfAnim;i++)
					xPrecision(&stAnims[i])	= xDefaultEps;
			}
			else {
				fprintf(ErrorFile,"Bad Default epsilon specify in %s file %f\n",MAKEANIM_OPTIONS_FILE,xPrecision,_ap_SzParam[0]);
			}
		}

		// set specific precision for each anim
		else if	(!stricmp(_p_szName,KEY_PRECISION) ) {
			int i;
			tdstAnimInfo * p_stCurrAnim=stAnims;

			// search the anim
			for (i=0;i<g_uwTotalNumOfAnim;i++,p_stCurrAnim++) {
				// find the good anim
				if (!stricmp(szAnimName(p_stCurrAnim),_ap_SzParam[0])) {
					SEB_xReal xPrecision;

					// check and set epsilon
					xPrecision = ReadDouble(1);
					if ((xPrecision > 0) && (xPrecision < 0.1))
						xPrecision(p_stCurrAnim) = xPrecision;
					else {
						fprintf(ErrorFile,"Bad epsilon specify in %s file %f for anim %s\n",MAKEANIM_OPTIONS_FILE,xPrecision,_ap_SzParam[0]);
					}
					break;
				}
			}
		}
		 else {
			fprintf( ErrorFile, "Unknown field in %s File (%s)\n",MAKEANIM_OPTIONS_FILE,_p_szName);
		}
	}

	else if	(_eAction == SCR_EA_Anl_EndSection) {	
		// Nothing to do
	}

	return	SCR_ERV_Anl_NormalReturn;
}



// ********************************************************************************** fn_v_IniFileInit
// 
// **********************************************************************************
void fn_v_IniFileInit(char * szFamilyName) {
	// Register CallBack for the family to load
	SCR_fn_v_RdL0_RegisterCallback(szFamilyName,fn_eFamilyCallBack,SCR_CRC_c_RdL0_ForSection);
}



// **********************************************************************************

