/*! \file oslib.h
    \brief Main DevsLib Library file based on Oslib .
*/

#ifndef _OSLIB_H_
#define _OSLIB_H_

#ifdef PSP
	#include <pspkernel.h>
	#include <pspdisplay.h>
	#include <pspdebug.h>
#else
	#define _CRT_SECURE_NO_DEPRECATE
	#include "emu.h"
	//#include "utility/psputility.h"
#endif
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#ifdef PSP
	#include <pspctrl.h>
	#include <psputility.h>
	#include <pspgu.h>
	#include <psppower.h>
	#include <pspiofilemgr.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif


/** @defgroup main

	Main Devslib section based on Oslib.
	@{
*/

/** @defgroup main_general General

	Contains general routines to initialize and terminate the library.
	@{
*/

/** OSLib version */
#define OSL_VERSION "DEVSLIB 1.0.0"
/** Initializes the library. The options for the flags parameters are for advanced users only, let it to zero if you're beginning.

	\param flags
		Can be formed of one or more of the values from the #OSL_INITFLAGS enumeration (ORed together).
*/
extern void oslInit(int flags);

/** Flags for oslInit. */
enum OSL_INITFLAGS	{
	OSL_IF_USEOWNCALLBACKS=1,						//!< Does not set up the standard callbacks. You'll have to provide them by yourself as shown in almost all PSPSDK samples.
	OSL_IF_NOVBLANKIRQ=2,							//!< Does not reserve the VBLANK IRQ. You should set up your own VBL handler, which should call oslVblankNextFrame() if osl_vblankCounterActive is TRUE, else oslSyncFrame(Ex) will not work properly.
};

/** Exits the application immediately, returning to the XMB (PSP main menu) or to the calling application (e.g. IRShell).
*/
extern void oslQuit();

/** Sets the "no fail" mode. In this mode, if OSLib can't load a file (for example an image) it will display a gentleful message indicating to the user the name of the missing file, and quit immediately.

\code
//Our objects (will be loaded)
OSL_IMAGE *img;
OSL_FONT *font;
OSL_SOUND *sound;

//Initialize OSLib
oslInit(0);
//Set-up drawing on a 5650 (16-bit) screen
oslInitGfx(OSL_PF_5650, 1);
//Enable the no-fail feature
oslSetQuitOnLoadFailure(1);

//An error will be displayed if any of these files could not be loaded properly.
image = oslLoadImageFilePNG("test.png", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_5551);
font = oslLoadFontFile("font.oft");
sound = oslLoadSoundFileWAV("noise.wav", OSL_FMT_NONE);

//Here, we are sure everything is okay, we don't even need checking if they are NULL.
oslSetFont(font);
oslDrawImage(img);
oslPlaySound(sound, 0);
\endcode */
#define oslSetQuitOnLoadFailure(enabled)				(osl_noFail = (enabled))

/** Sets the function to call in case of failure to load something. Default displays a message box.

\code
//Our own function called when a loading has failed
void MyNoFailCallback(const char *filename, u32 reserved)		{
	//Display an error
	myDisplayMessage("Unable to locate the following file: %s\nPlease reinstall the application.", filename);
	//Always quit because we can't continue without these precious files
	oslQuit();
}

//Set-up no-fail.
oslSetQuitOnLoadFailure(1);
oslSetQuitOnLoadFailureCallback(MyNoFailCallback);
//This function will call MyNoFailCallback  because the specified file doesn't exist
oslLoadImageFileJPG("void:/notexisting.xyz", OSL_IN_RAM, OSL_PF_4BIT);
\endcode
*/
#define oslSetQuitOnLoadFailureCallback(function)		(osl_noFailCallback = function)

/** Sets an exit callback. This function is executed when the user chooses "Exit" from the HOME menu. By default, all what OSLib does is set osl_quit to True, so that you
know that you should quit (all your game loops should watch out for osl_quit). A typical but dirty callback may be to force quitting immediately using oslQuit. Example:

\code
int myExitCallback(int arg1, int arg2, void *common)
{
	oslQuit();
	return 0;
}

void main()			{
	oslSetExitCallback(myExitCallback);
	while(1);
}
\endcode */
#define oslSetExitCallback(function)					(osl_exitCallback = function)


//Don't access these
extern int osl_noFail;
extern void (*osl_noFailCallback)(const char *filename, u32 reserved);
extern void oslHandleLoadNoFailError(const char *filename);

/** @} */ // end of main_general


/** @defgroup main_sync Synchronization

	Contains routines for synchronizing your game.
	@{
*/

/** Sets the current fix frameskipping value.
	\param val
		1 = enables auto frameskip
		2 or more: enables fixed skipping (val-1 frames out of val are skipped)
*/
#define oslSetFrameskip(val) (osl_frameskip = val)
/** Sets the maximum frameskip value. If you set a too high value, the game may become unusable when lagging, if you set a too low value, frameskip is no more useful.
*/
#define oslSetMaxFrameskip(val) (osl_maxFrameskip = val)
/** Sets the VSync parameter.
	\param val
		0: Automatic VSync (enabled if the game is not lagging).
		1: VSync always enabled.
		+4: If you add 4, with a frameskip > 1, synchronizes to the wanted framerate, e.g. 2 -> 30 fps (DON'T USE THIS ANYMORE)
		+0: Else, fixes the minimum frameskip (e.g. 2: the game will run at 60 fps, 30 images per second, that is one frame out of two is skipped)
		+8: Alternative synchronization method without VSync
		+16: Do not swap buffers. Handy if you want temporary to "disable double buffering".
*/
#define oslSetVSync(val) (osl_vsyncEnabled = val)
/** Synchronization. Call it to the end of a frame. A frame is one step when animating your game. The PSP LCD refreshes at 60 images per second (and thus, you'll have to generate 60 frames per second).
	This function uses the frameskip & vsync parameters defined above.
	\return
		A boolean value indicating if you're in late.

	Note: When you're indicated to be in late, you should skip the rendering to speed up things, else your game will slow down. Usually the whole render is surrounded by a "if (!skip)" block, and when
	skip is true, the render is completely skipped. Skip is the return value from oslSyncFrame.
	
	Here is the structure of an automatically frameskipped program:
\code
//This variable holds whether a frame should be skipped or not
int skip = 0;
//Enable frameskipping, 0 frame out of 1 is skipped by default (60 fps)
oslSetFrameskip(1);
//But skip a maximum of 3 frames out of 4, else the game seems very laggy
oslSetMaxFrameskip(4);

//Our main loop
while(1)		{
	//If skip is 1, then we should skip rendering to speed up things
	if (!skip)		{
		//Begin drawing
		oslStartDrawing();
		//We can now draw as much as we want
		oslDrawFillRect(0, 0, 100, 100, RGBA(0, 0, 255, 128));
		oslDrawString(0, 0, "Hello!");
		//We have now finished with drawing
		oslEndDrawing();
	}

	//End of a frame
	oslEndFrame();
	//Synchronize to ensure the game runs at 60 fps
	skip = oslSyncFrame();
}
\endcode
*/
#define oslSyncFrame()	oslSyncFrameEx(osl_frameskip,osl_maxFrameskip,osl_vsyncEnabled)

/** Call this function when a frame has ended, just before a call to oslSyncFrame or oslWaitVSync or anything.
\b Important: If you are calling this function, you do not need to call #oslAudioVSync anymore. Newer programs should always call #oslEndFrame instead. */
extern void oslEndFrame();


/** This variable is set to TRUE to indicate the application should exit (happens when the user pressed HOME and selected Yes). You should always keep an eye on this variable, clean up everything and
then quit when this variable has become TRUE. */
extern int osl_quit;

//Document these
extern int osl_standByUnpermitted;
extern int (*osl_powerCallback)(int, int, void*);
extern int (*osl_exitCallback)(int, int, void*);
extern int osl_vblInterruptNumber;									//Numéro de l'interruption VBLANK utilisée

//Don't access these
extern int osl_maxFrameskip, osl_vsyncEnabled, osl_frameskip;
extern volatile int osl_vblCount, osl_vblCallCount, osl_vblankCounterActive, osl_skip;
extern volatile int osl_currentFrameRate;

/** Same as oslSyncFrame but with all parameters set in one call. This method is a bit cleaner because the other one stores parameters in global variables and oslSyncFrame calls oslSyncFrameEx with them
as arguments. */
extern int oslSyncFrameEx(int frameskip, int max_frameskip, int vsync);

/** Sets the framerate for oslSyncFrame(Ex). This can be any value from 1 to 60. For example, use 50 to simulate a PAL (european) game. */
extern inline void oslSetFramerate(int framerate)		{
	if (framerate <= 60)
		osl_currentFrameRate = framerate;
}

/** Waits for the VSync (60 times per second), synchronizing your game. This is a simplier and less efficient method than oslSyncFrame. */
extern void oslWaitVSync();

/** @} */ // end of main_sync


/** @defgroup main_memory Memory

	Contains routines about memory (cache, copy, etc.).
	@{
*/

/** Copies data using the internal DMAC. Should be faster than a memcpy, but requires that data to be copied is no more in the cache, so usually you should issue a oslUncacheData on the source and
destination addresses else very strange bugs may happen. */
extern int sceDmacMemcpy(void *dest, const void *source, unsigned int size);				//Copie DMA
/** Same as sceDmacMemcpy. */
extern int sceDmacTryMemcpy(void *dest, const void *source, unsigned int size);
/** Does a memset using the 64-bit capabilities of the CPU. Faster than memcpy. */
extern void oslFasterMemset(u64 *dst, u64 *src, u32 length);

/** This routine will make sure that the data will no more reside in the CPU cache. The CPU does automatically put data in cache when you want to read or write to it, making subsequent accesses faster
(because the cache is way faster than conventional RAM). The problem is that if the GE (graphic processor) for example wants to access it, it will read the real memory, and thus if some data is still
sitting in the cache (not written to actual RAM yet) the GE will get incorrect data, making it crash or display corrupt graphics.

To avoid problems, you can either bypass the cache by writting to uncached addresses (oslGetUncachedPtr) or by flushing the data from cache before sending them to the GE (or DMA). This function,
oslUncacheData, will flush the actual data from cache, writing it to real memory. This does take some time so don't abuse and call it only when necessary.

	\param data
		Adress of the memory area to flush.
	\param size
		Size (in bytes) of the area.

Uncaching should be done after you've accessed raw image / palette / something contents. This includes oslSetImagePixel and accesses to the raw image data pointed to by OSL_IMAGE::data.

Note: There are specific functions to uncache palettes and images, simplier to use. You should rather use them instead.
*/
#define oslUncacheData(data,size)		sceKernelDcacheWritebackInvalidateRange(data, size);

/** Returns a pointer to an uncached address. In this case, cache will be bypassed and you'll not have to call oslUncache[something] after modifying data. However performance is usually worse and caching
is a good thing, so do it if you know what you are doing.

Important: NEVER mix cached and uncached addresses when accessing somewhere. Either always access them as cached or unached. If you mix them some weird bugs may appear
because you could for example write directly in memory bypassing the cache, but some data is still sitting in the cache. So, once the cache is full, data will be flushed and written to the memory, replacing the
data you wrote in an uncached way. You will not understand why your data gets corrupted, and as this will maybe happen seconds later in special circumstances, so it will be impossible to detect or
debug. */
#define oslGetUncachedPtr(adr)			((void*)((int)(adr)|0x40000000))
/** Get a pointer to cached data. Same remark as above. */
#define oslGetCachedPtr(adr)			((void*)((int)(adr)&(~0x40000000)))

#ifdef PSP
	/** Flushes the whole cache. This is slow, absolutely avoid it! Use oslUncacheData instead if possible. */
	extern inline void oslFlushDataCache();
#else
	extern void oslFlushDataCache();
#endif

/** Allocates a memory block, ensuring it is aligned.
	\param 1
		Alignment in bytes
	\param 2
		Size of the block
*/
void *memalign(size_t, size_t);

/** Structure for the return value of oslGetRamStatus. */
typedef struct		{
	int maxAvailable;					//!< Maximum available memory
	int maxBlockSize;					//!< Maximum linear memory available
} OSL_MEMSTATUS;

/** Gets info about currently available memory in main RAM. The return value is a #OSL_MEMSTATUS
structure which contains info about available memory.

Example:
\code
	//You can either store the result to a structure and access its members
	OSL_MEMSTATUS ram = oslGetRamStatus();
	oslDebug("%i bytes available", ram.maxAvailable);

	//Or directly use the return value from the function, like this
	oslDebug("%i bytes available", oslGetRamStatus().maxAvailable);
\endcode

\b Note: About the example above, just notice that each call to oslGetRamStatus costs a lot of time, so if you need to
retrieve several results (e.g. both maxAvailable and maxBlockSize) you should not use the second method as it will need two
calls to oslGetRamStatus. */
OSL_MEMSTATUS oslGetRamStatus();

/** @} */ // end of main_memory


/** @defgroup main_maths Maths

	Main OSLib section. Contains the main routines to initialize and terminate the library.
	@{
*/

/** Returns the absolute value of a number (that is, the positive part of the number).

\code
//Prints 2
oslPrintf("%i", oslAbs(2));
//Prints 2 as well (the minus sign is ignored in an absolute value)
oslPrintf("%i", oslAbs(-2));
\endcode */
#define oslAbs(x)					(((x)<0)?(-(x)):(x))

/** Returns the smallest value between the two. */
#define oslMin(x, y)				(((x)<(y))?(x):(y))
/** Returns the greatest value between the two.

\code
//Move the object 1 pixel to the left but make sure it will never go beyond the left corner of the screen.
posX = oslMax(posX - 1, 0);
\endcode */
#define oslMax(x, y)				(((x)>(y))?(x):(y))
/** Returns a value clamped between a minimum and maximum.

\code
int addColor(int colValue, int addValue)			{
	//We add addValue to colValue, but we must check the color component is always between 0 and 255.
	colValue = oslMinMax(colValue + addValue, 0, 255);
	return colValue;
}
\endcode */
#define oslMinMax(x, min, max)		((x) < (max) ? ((x) > (min) ? (x) : (min)) : (max))

/** Returns the number of objects in an array.

\code
OSL_VIRTUALFILENAME ram_files[] =		{
	{"ram:/file1.jpg", (void*)file1_jpg, file1_jpg_size, &VF_MEMORY},
	{"ram:/file2.png", (void*)file2_png, file2_png_size, &VF_MEMORY},
};

//This will display 2, as 2 elements are contained in the table ram_files.
oslPrintf("%i", oslNumberof(ram_files));
\endcode */
#define oslNumberof(n)				(sizeof(n)/sizeof(*(n)))

/** Calculates the sine of an angle in degrees multiplicated by a radius. Returns the result as a float. oslSin and oslCos use the VFPU to compute the result, and thus it's very fast and very precise.
	\param angle
		Angle in degrees (360° means a full circle)
	\param dist
		Radius of the circle
	\return
		sin(angle * PI / 180) * dist

\code
//Character coordinates
float cX, cY;
//Character speed
float cSpeed;
//Character angle
float cAngle;

//Move the character depending on its instant speed and angle
cX += oslCos(cAngle, cSpeed);
//In mathematics, positive y coordinates are directed upwards, in informatics it's directed
//downwards, as if we were writing on a sheet of paper, so we need to substract the sine.
cY -= oslSin(cAngle, cSpeed);
\endcode
*/
extern float oslSin(float angle, float dist);
/** Calculates the cosine of an angle in degrees multiplicated by a radius. Returns the result as a float.
	\param angle
		Angle in degrees (360° means a full circle)
	\param dist
		Radius of the circle
	\return
		cos(angle * PI / 180) * dist
*/
extern float oslCos(float angle, float dist);

/** Returns the sine of an angle in degrees (0 to 360) multiplicated by an integer radius. Returns the result as an integer. These routines use a precalculated lookup table to compute the result.
Don't think oslSini and oslCosi are much faster than oslSin and oslCos, it's not the case.

\code
//This code draws a line in a circle which has a radius of 20 pixels. You can play with the angle to move the line.
int angle = 40, radius = 20;
//Draw our line. Same remark as for oslSin applies.
oslDrawLine(240, 136, 240 + oslCosi(angle, radius), 136 - oslSini(angle, radius));
\endcode */
extern int oslSini(int angle, int dist);
/** Returns the cosine of an angle in degrees (0 to 360) multiplicated by an integer radius. Returns the result as an integer. */
extern int oslCosi(int angle, int dist);

/** Returns the next (upper) power of two of a number.

\code
//Prints 256, as 256 = 2^8 (2^7 = 128, too low).
oslPrintf("%i", oslGetNextPower2(200);
\endcode */
extern int oslGetNextPower2(int val);

//Don't access these!
//extern float osl_fsinus[361];
//extern float osl_fcosinus[361];
extern int osl_isinus[361];
extern int osl_icosinus[361];
extern void oslSetupFTrigo();

/** @} */ // end of main_maths

/** @defgroup main_debug Debug console

	Debugging features.
	@{
*/
#ifdef PSP
	/** Prints formatted text to the current position of the cursor. The format system is the same as printf (you can find the description in every good C tutorial or documentation). */
	#define oslPrintf(format...)		({ char __str[1000]; sprintf(__str , ##format); oslConsolePrint(__str); })
	/** Prints formatted text at a specific position on the screen.
\code
//Display the value of a variable on the top-left screen corner
oslPrintf_xy(0, 0, "Frame: %i", frameNumber);
\endcode */
	#define oslPrintf_xy(x,y, str, format...)		({			osl_consolePosX=x, osl_consolePosY=y;		\
																oslPrintf(str,##format); })
#else
	#define oslPrintf(...)		{ char __str[1000]; sprintf(__str , __VA_ARGS__); oslConsolePrint(__str); }
	#define oslPrintf_xy(x,y, ...)		{			osl_consolePosX=x, osl_consolePosY=y;		\
																oslPrintf(__VA_ARGS__); }
#endif

/** Clears the screen (to black) and resets the cursor to the top-left corner of the screen.

\code
oslCls();
oslPrintf("Welcome...\n");
\endcode */
#define oslCls()				 	(oslClearScreen(0), oslMoveTo(0,0))
/** Moves the cursor to a place on the screen. The x, y coordinates are indicated in terms of characters (by default 8x8 pixels, but depends on the current font). */
#define oslMoveTo(x,y)				(osl_consolePosX=x*osl_curFont->charWidths['0'], osl_consolePosY=y*osl_curFont->charHeight)

/** @} */ // end of main_debug


/** @defgroup main_misc Miscellaneous

	Miscellaneous.
	@{
*/
/** Does a benchmark action.
	\param startend
		- OSL_BENCH_INIT: Initialize the benchmark (done at beginning by OSLib)
		- OSL_BENCH_START: Start the measure from here
		- OSL_BENCH_END: End of a benchmark
		- OSL_BENCH_GET: Get the value (milliseconds between the call to start and end
		- OSL_BENCH_DISPLAY: Avoid
	\param slot
		0-3: User slots
		4-7: System slots (4 contains the CPU load in percent if you multiply its value by 6 and divide by 1000)
	
	\return
		The time elapsed between start and end in microseconds.
*/		
extern int oslBenchmarkTestEx(int startend, int slot);			//Permet de choisir un slot (0-3: user, 4:7: system)
/** Same as oslBenchmarkTestEx but does a mean of 20 samples before returning a value. */
extern int oslMeanBenchmarkTestEx(int startend, int slot);		//Benchmark système sur une moyenne de 20 échantillons
/** Does a benchmark in the slot 0. Easier for testing. */
extern inline int oslBenchmarkTest(int startend)		{
	return oslBenchmarkTestEx(startend, 0);
}
/** Displays the system benchmark results on the top-left corner of the screen. Useful for debugging: you know that if the first number approaches or exceeds 16.6 then your game has insufficient performance (for 60 fps). */
extern void oslSysBenchmarkDisplay();

//Undocumented
enum {OSL_BENCH_INIT=0, OSL_BENCH_START, OSL_BENCH_END, OSL_BENCH_GET, OSL_BENCH_GET_LAST, OSL_BENCH_DISPLAY};
#define OSL_BENCH_SLOTS 8
#define OSL_BENCH_SAMPLES 20

#ifndef PSP
	extern void Debug(const char *format, ...);
#endif
extern void oslVblankInterrupt(int sub, void *parg);


extern int oslShowSplashScreen1();
extern int oslShowSplashScreen2(char *file);
extern int oslShowSplashScreen3(char *Background,char *file, char *star);
extern int oslShowSplashScreen4(char *Background);
extern int oslShowSplashScreen5(char *Background,char *mask);

/** Shows one of the predefined splash screens in OldSchool Library.
	\param splashType
		- 1: Shows the OldSchool Library logo. This logo is not very long and can constitute a great introduction to a game. It can be skipped with cross, circle or start buttons.
		- 2: Shows the neoflash logo. Requires and uses the following file: "logo/neoflash.png".

	\return
		1 in case of success, 0 otherwise.

	Call this function just after having initialized OSLib.

	\code
int main(void)
{
	//Init oslib.
	oslInit(0);
	oslInitGfx(OSL_PF_8888, 1);

	//Show our splash screen
	oslShowSplashScreen(1);

	//Begin our game
	[...]
\endcode

	\b Warning: This function tries to load images files located on your memory stick. It will do nothing if they are not present. But if your application is running in kernel mode and you are
	creating an user thread, your thread will not have a default running directory, making this function to always fail! You should always set a working folder (e.g. with sceIoChdir) before calling this
	functions!

	These files can be found in the Resource folder of your OSLib distribution.
*/
extern inline int oslShowSplashScreen(int splashType)		{
	if (splashType == 1)
		return oslShowSplashScreen1();
	else if (splashType == 2)
		return oslShowSplashScreen2("logo/fond2.png");
	else if (splashType == 3)
		return oslShowSplashScreen3("logo/fond.png","logo/texte.png", "logo/etoile.png");
	else if (splashType == 4)
		return oslShowSplashScreen4("logo/PSP_Logo.png");
	else if (splashType == 5)
		return oslShowSplashScreen5("logo/fond2.png","logo/objectif.png");
	return 0;
}

extern inline int oslShowNeoflashLogo()		{
	return oslShowSplashScreen(2);
}

#ifdef PSP
	#define OSL_UVRAM_BASE ((u8*)0x04000000)
#else
	extern u8 *OSL_UVRAM_BASE;
	#define alloca _alloca
//	void *_alloca(size_t size);
#endif
#define OSL_UVRAM_SIZE	(2 << 20)
#define OSL_UVRAM_END	((u8*)((u32)OSL_UVRAM_BASE + OSL_UVRAM_SIZE))

/** @} */ // end of main_misc


/** @} */ // end of main


// *** Console SONY ***
/*#define oslCls()								pspDebugScreenClear()
#define oslPrintf(str, format...)				pspDebugScreenPrintf(str,##format)
#define oslMoveTo(x,y)							pspDebugScreenSetXY(x,y)
#define oslPrintf_xy(x,y, str, format...)		({			oslMoveTo(x,y);		\
															oslPrintf(str,##format); })*/



#include "vfpu.h"
#include "vram_mgr.h"
#include "VirtualFile.h"
#include "drawing.h"
#include "map.h"
#include "text.h"
#include "messagebox.h"
#include "keys.h"
#include "audio.h"
#include "bgm.h"
//#include "dialog.h"


	

/** @defgroup others

	other functions unclassed
	@{
*/


extern int oslLog;

/** oslib sqrt */
extern int oslSqrt(unsigned int n);
/** synchronization of the image, sound and the end of the drawing */
extern void oslSynchronization();
/** Random with a limit Max */
extern int oslRandom( int max );

/** Loading the management of the virtual keyboard */
extern void oslKeyboardLoad(const int newX, const int newY,char *file);
/**display screen keyboard */
extern char * oslKeyboardDraw();

/**makes a log system*/
extern void oslLogSystem(int value);

/**Remove the keyboard virtual of memory*/
extern void osl_DelKeyboard2();
/** Loading the management of the virtual keyboard 2 */
extern void oslKeyboardLoad2(char *Keyboard1,char *Keyboard2, char *Cursor,int X, int Y);
/**display screen keyboard 2 */
extern char * oslKeyboard2Draw(void);

/**Test presence of a file and if present returns 1*/
extern bool oslTestFile(char * file);
/**Add a comment or information in a log file*/
extern void oslAddLog(char * file,char * Text);

#ifdef PSP
	/** log information in text file , The format system is the same as printf... */
	#define oslLogFile(file,format...)		({ char __str[1000]; sprintf(__str , ##format); oslAddLog(file,__str); })
#else
	#define oslLogFile(file,...)		{ char __str[1000]; sprintf(__str , __VA_ARGS__); oslAddLog(file,__str); }
#endif


/**initialization textures for the message box*/
extern void oslInitMessageBoxSkin();

/** drawing a file explorer (not working for the moment) */
extern int oslExplorerBox(const char *title, unsigned int flags);

/** initializes the cursor (not yet functional) */
extern void oslInitCursor();
extern void oslDrawCursor(int x,int y);

/** Define NULL has a value of 0. */
#ifndef NULL
#define NULL 0
#endif

/** Define FALSE has a value of 0. */
#ifndef FALSE
#define FALSE 0
#endif

/** Define TRUE has a value of 1. */
#ifndef TRUE
#define TRUE  !FALSE
#endif


#define boolean int

#define pointer void *


#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

#define MIN3(a,b,c) MIN(MIN(a,b),MIN(b,c))
#define MAX3(a,b,c) MAX(MAX(a,b),MAX(b,c))

#define ABS(a)   ((a >= 0)?(a):-(a))

/** @} */ // end of others


//----------animation--------

/** @defgroup animation

	Management annimation sprites
	@{
*/


typedef struct	{
	int position; //position player. example: UP / DOWN / LEFT / RIGHT / JUMP 
	int anim_possition;  // for animation shows the current possition the annimation
	int temp_animation; // for animation
	int animation; //Number of annimation for the object
	int width;  // Width X of the size of a sprite for animation
	int height; //height of animation
	int speed; // speed of animation
	int BonusTime; // time for a bonus
	int line; //nunber of line for animation
	int templine; //information temp of line actual

	int reverse; //reverse animation

	int left, right ,up, down,sens;
	bool flipv, fliph, Active;

} OSL_ANIM;


/**
* \struct OSL_OBJECT
* \brief Used for animation objects and for collisions
*
* OSL_OBJECT structure for the management of objects for animation and collision
*/
typedef struct    OSL_OBJECT{

	OSL_IMAGE *sprite ;/*!< Sprite has used for the objet */

    OSL_ANIM Animation;/*!< use animation structure*/

	//temp variable.
	int Etat_objet;

} OSL_OBJECT; 



/*-------------------------------------------------------------------------*/
/**
  @brief    effect of a mirror image
  @param    img Sprite has reversed
  @param    flipType flipType 0  = filp horizontal / flipType = 1 flip vertical

draws a picture and a mirror effect Horizontal or vertical.
 */
/*--------------------------------------------------------------------------*/
extern void oslDrawImageSimpleFlip(OSL_IMAGE *img, int flipType);

/*-------------------------------------------------------------------------*/
/**
  @brief    Create a Object
  @param    Image Image for make a animation
  @param    startFrameY Start position for animation
  @param    animation Number of frame for animation
  @param    width Width of a sprite for a Frame
  @param    height height of a sprite for a Frame
  @param    speed Speed for annimation (From the first frame to last)
  @return   Return an Object created and therefore usable 

This feature allows you to Created an Object to use for several things: 
   (Simple animation, character, Collision ...)
 */
/*--------------------------------------------------------------------------*/

extern OSL_OBJECT *oslCreateSprite(OSL_IMAGE *Image,int startFrameY,int animation ,int width,int height,int speed );

/*-------------------------------------------------------------------------*/
/**
  @brief    Animation for an Object
  @param    Obj Object to Anime 

 This feature allows an object of animated frame by frame, taking into account the speed and all parameters
 */
/*--------------------------------------------------------------------------*/
extern void oslAnimSprite(OSL_OBJECT* Obj);


/*-------------------------------------------------------------------------*/
/**
  @brief    Change the maximum number of frame of an object animation
  @param    Obj Object pointer
  @param    animation Change the maximum number of frame of the animation

  This function allow to changer the maximum number of frame of an object animation
 */
/*--------------------------------------------------------------------------*/
extern void oslSetAnimFrameMax(OSL_OBJECT* Obj,int animation);



/*-------------------------------------------------------------------------*/
/**
  @brief    Stop the animation on a precise frame
  @param    Obj Object pointer
  @param    Poss Position of the object (Serie d'annimation au niveau de la height)
  @param    animation Index of the frame where we want to stop

  This function permit to stop an animation on a precise frame
 */
/*--------------------------------------------------------------------------*/
extern void oslSetAnimFrameBreak(OSL_OBJECT* Obj,int Poss,int animation);



/*-------------------------------------------------------------------------*/
/**
  @brief    Change the position of an object
  @param    Obj Object pointer
  @param    Poss New position of the object (possition = ligne concernet)

  This function permit to change the position of the object (left, right, jump, fire, ...)
 */
/*--------------------------------------------------------------------------*/
extern void oslChangePosition(OSL_OBJECT* Obj, int Poss);


/*-------------------------------------------------------------------------*/
/**
  @brief    Mirror effect on an object
  @param    Obj Object pointer

  Activate the mirror effect (horizontal flip) on a sprite for the current animation (it's perfect for the left/right animation)
 */
/*--------------------------------------------------------------------------*/
extern void oslSetFliphOn(OSL_OBJECT* Obj);

/*-------------------------------------------------------------------------*/
/**
  @brief    Cancel the mirror effect of an animation
  @param    Obj Object pointer

  This function cancel the mirror effect of an animation
 */
/*--------------------------------------------------------------------------*/
extern void oslSetFliphOff(OSL_OBJECT* Obj);

/*-------------------------------------------------------------------------*/
/**
  @brief    Animate an object
  @param    Obj Object to animate or to draw

  This function draw the sprite and animate it if it's necessary
 */
/*--------------------------------------------------------------------------*/
extern void oslDrawImageAnime(OSL_OBJECT* Obj);


/*-------------------------------------------------------------------------*/
/**
  @brief    Activate an animation
  @param    Obj Object pointer

  This function activate the animation of the animation of the object
 */
/*--------------------------------------------------------------------------*/
extern void oslAnimationPlay(OSL_OBJECT* Obj);

/*-------------------------------------------------------------------------*/
/**
  @brief    Stop the animation
  @param    Obj Object pointer

  This function stop the animation of an object
 */
/*--------------------------------------------------------------------------*/
extern void oslAnimationStop(OSL_OBJECT* Obj);

/*-------------------------------------------------------------------------*/
/**
  @brief    Make a reset on the current animation
  @param    Obj Object pointer

  This function reset the current animation (frame 0)
 */
/*--------------------------------------------------------------------------*/
extern void oslResetPosition(OSL_OBJECT* Obj);

/*-------------------------------------------------------------------------*/
/**
  @brief    Change the parameters of an object already initialized
  @param    Obj Objetc pointer
  @param    animation Number of frame of the animation
  @param    width Width of the sprite for a frame
  @param    height Height of the sprite for a frame
  @param    speed Speed for the animation (from the first frame to the last)

  This function change the parameters of an object already initialized
 */
/*--------------------------------------------------------------------------*/
extern void oslSetAnimation(OSL_OBJECT* Obj,int animation ,int width,int height,int speed );

/*-------------------------------------------------------------------------*/
/**
  @brief    Delete an object
  @param    Obj Object pointer


  This function delete an object (free the memory)
 */
/*--------------------------------------------------------------------------*/
extern void oslDeleteAnnimation(OSL_OBJECT* Obj);



/** @} */ // end of animation



//-----Collision----------


/** @defgroup collision

	Management of several systems of collision
	@{
*/

/*-------------------------------------------------------------------------*/
/**
  @brief    Collision with a bouding box algorithm
  @param    img1 First sprite to compare
  @param    img1posX Position X of the first sprite
  @param    img1posY Position Y of the first sprite
  @param    img2 Second sprite to compare
  @param    img2posX Position X of the second sprite
  @param    img2posY Position Y of the second sprite

 Check if there is a collision between two sprites
 bounding box algorithm
 */
/*--------------------------------------------------------------------------*/
extern int oslCollImage(OSL_IMAGE *img1,float img1posX, float img1posY, OSL_IMAGE *img2, float img2posX, float img2posY );

 /*-------------------------------------------------------------------------*/
/**
 @brief    Collision with a bouding box algorithm
 @param    img1 First sprite to compare
 @param    img1posX Position X of the first sprite
 @param    img1posY Position Y of the first sprite
 @param    img2 Second sprite to compare
 @param    img2posX Position X of the second sprite
 @param    img2posY Position Y of the second sprite
  @param    Rayon Raduis which grow or reduce for the collision
 
 Check is there is a collision in a raduis of X pixel between the two sprites
 Usefull for example for a collision of perimeter to give new instruction
algorithme bounding box
 */
/*--------------------------------------------------------------------------*/
extern int oslCollImageOffset(OSL_IMAGE *img1,float img1posX, float img1posY, OSL_IMAGE *img2, float img2posX, float img2posY , float Rayon);


/*-------------------------------------------------------------------------*/
/**
  @brief    Collision with a bounding box algorithm controller
  @param    sprite1 Object1 to compare
  @param    sprite1 Object2 to compare
  @param    Gauche Check if there is a collision by the left side
  @param    Droite Check if there is a collision by the right side
  @param    Haut Check if there is a collision by the upper side
  @param    Bas Check if there is a collision by the down side
 
 Check if there is a collision between two sprites in all directions
 Usefull in several cases ;
 - management of the part which is touched in a mario-like game (going by the upper side, the ennemy is dead)
 - for the collision with a safe in a RPG game (going by the down to open the safe)
 
algorithme bounding box
 */
/*--------------------------------------------------------------------------*/
extern int oslCollObjectSens(OSL_OBJECT* sprite1,OSL_OBJECT* sprite2,int left,int right,int up,int down );


/*-------------------------------------------------------------------------*/
/**
 @brief    Collision with a bounding box algorithm controller
 @param    sprite1 Object1 to compare
 @param    sprite1 Object2 to compare

Check if there is a collision between two Devslib object
algorithme bounding box
 */
/*--------------------------------------------------------------------------*/
extern int oslCollObject(OSL_OBJECT* sprite1,OSL_OBJECT* sprite2 );


/*-------------------------------------------------------------------------*/
/**
  @brief    Collision by circle
  @param    x1 Center X of the first circle
  @param    y1 Center Y of the first circle
  @param    r1 Radius of the first circle
 @param    x2 Center X of the second circle
 @param    y2 Center Y of the second circle
 @param    r2 Radius of the second circle
  @param    offset Distance between the two circles


Check if there is an intersection between the two circles
algorithme bounding Cercle

circle1 : center (x1,y1) with radius r1
circle2 : center (x2,y2) with radius r2
(the offset is the distance between the two circle)
 */
/*--------------------------------------------------------------------------*/
extern int oslCollCircle(int x1 , int y1 , int r1 ,int x2 , int y2 , int r2 , int offset);


/*-------------------------------------------------------------------------*/
/**
 @brief    Collision by circle with images
 @param    x1 Center X of the first circle
 @param    y1 Center Y of the first circle
 @param    a First image
 @param    x2 Center X of the second circle
 @param    y2 Center Y of the second circle
 @param    b Second image
 @param    offset Distance between the two circles

Intersection between the two circles with the utilisation of images
Don't forget that the radius depends on the width and the height of the image
 */
/*--------------------------------------------------------------------------*/
extern int oslCollSpriteCircle(OSL_IMAGE *a , int x1 , int y1 , OSL_IMAGE *b , int x2 , int y2 , int offset);


/*-------------------------------------------------------------------------*/
/**
  @brief    Collision by circle with objects
  @param    sprite1 sprite of the first object
  @param    sprite2 sprite of the second object
  @param    offset Distance between the two circle

 Intersection between the two circles with the utilisation of objects
 Don't forget that the radius depends on the width and the height of the image
 */
/*--------------------------------------------------------------------------*/
extern int oslCollObjectCircle(OSL_OBJECT* sprite1,OSL_OBJECT* sprite2 ,int offset);

 /*-------------------------------------------------------------------------*/
/**
  @brief    Collision by bounding box algorith
  @param    img1 First sprite to compare
  @param    img1posX Position X of the first sprite
  @param    img1posY Position Y of the first sprite
  @param    img2 Second sprite to compare
  @param    img2posX Position X of the second sprite
  @param    img2posY Position Y of the second sprite
  @param    Rayon Radius which grow of reduse the collision zone

Check if a collision occurs in a radion of X pixels between two sprites
 Usefull for example for a detection of perimeter to give new instructions
algorithme bounding box
 */
/*--------------------------------------------------------------------------*/
extern int oslCollObjetOffset(OSL_OBJECT* sprite1, OSL_OBJECT* sprite2 , float Rayon);


 /*-------------------------------------------------------------------------*/
/**
  @brief    Collision by bounding box algorithm
  @param    img1 First sprite to compare
  @param    img1posX Position X of the first sprite
  @param    img1posY Position Y of the first sprite
  @param    img2 Second sprite to compare
  @param    img2posX Position X of the second sprite
  @param    img2posY Position Y of the second sprite
  @param    Rayon Radius which grows or reduces for the collision

 Check if a collision occurs in a radius of X pixels between the two sprites
 Usefull for example for a detection of perimeter to give new instructions
algorithme bounding box
 */
/*--------------------------------------------------------------------------*/
extern int oslCollObjetImageOffset(OSL_OBJECT* sprite1, OSL_IMAGE *img2, float img2posX, float img2posY , float Rayon);



/** @} */ // end of collision



//-------EFFET FX--------

/** @defgroup effect

	Management of several effects, masks or others things ....
	@{
*/



/**
 * \struct OSL_EFFECT
 * \brief Use for the management of the special effect
 *
 * OSL_EFFECT is a structure for the management of the different special effects and masks
 * Not detailled because it's not necessary to modify any value, the functions permit to modify everything directly
 */
typedef struct {
 int tile;
 int type;
 int speed;
 int tempo;
 OSL_IMAGE *Image;
 int moin,plus;
 int width,height;
 int active;// for the mask, if 1 the mask is active

 
 unsigned int tempsAB;
 unsigned int tempsBA;
 unsigned int compteur;
 int from;
 int to;
 int nbLoops;
 int currentLoop;
 bool aToB;

 unsigned int duree;
 unsigned int dureemini;
 bool direction;

 unsigned short ZoomX;
 unsigned short unZoomX;
 unsigned short ZoomY;
 unsigned short unZoomY;
 bool growing;

} OSL_EFFECT;



/*-------------------------------------------------------------------------*/
/**
  @brief    Reset the parameters to reuse the cube animation
  @param    FX Pointer on an OSL_EFFECT object

Reset the parameters to reuse the cube animation
 */
/*--------------------------------------------------------------------------*/
extern void oslResetEffect(OSL_EFFECT *FX);

/*-------------------------------------------------------------------------*/
/**
  @brief    Initialized an effect : division of an image in cubes
  @param    file Image file for the animation
  @param    width width of the animation (ex : 480)
  @param    height height of the animation (ex : 272)
  @param    type Direction of the animation (0 = down or 1 = right)
  @param    speed Speed of the animation
  @param    tile Size of the tile for the effect
  @return   an OSL_EFFECT object

Declare and initialize an effect : division of an image in cubes
 */
/*--------------------------------------------------------------------------*/
extern OSL_EFFECT *oslLoadCubeEffect(char *file,int Largeur,int height,int type, int vitesse, int tile);

/*-------------------------------------------------------------------------*/
/**
  @brief    Draw the image for the cube animation 
  @param    FX Pointer on an OSL_EFFECT object

Draw the image for the cube animation
 */
/*--------------------------------------------------------------------------*/
extern void oslLogoDrawTiles(OSL_EFFECT *FX);

/*-------------------------------------------------------------------------*/
/**
  @brief    Active the effect of division in cubes
  @param    FX pointer on an object OSL_EFFECT

Active the effect of division in cubes
 */
/*--------------------------------------------------------------------------*/
extern void oslActiveCubeFX(OSL_EFFECT *FX);

/*-------------------------------------------------------------------------*/
/**
  @brief    Initialize an effect to use a mask
  @param    file File to use for the mask (load internallyn just give the path and the file)fichier)

Initialize an effect to use a mask
 */
/*--------------------------------------------------------------------------*/
extern OSL_EFFECT *oslLoadMaskEffect(char *file);

/*-------------------------------------------------------------------------*/
/**
  @brief    Update the effect for the masks
  @param    FX pointer to an OSL_EFFECT object

Update the effect for the masks
 */
/*--------------------------------------------------------------------------*/
extern void oslUpdateMaskEffect(OSL_EFFECT *fx);

/*-------------------------------------------------------------------------*/
/**
  @brief    Draw the effect for the masks
  @param    FX Pointer to an OSL_EFFECT object

Draw the effect for the masks
 */
/*--------------------------------------------------------------------------*/
extern void oslDrawMaskEffect(OSL_EFFECT *fx);

/*-------------------------------------------------------------------------*/
/**
  @brief    Set the direction of the animation, growing or reducing
  @param    FX Pointer to an OSL_EFFECT object
  @param    plus The animation goes from the interior to the exterior by growing
  @param    moin The animation goes from the exterior to the interior by reducing

 Set the direction of the animation, growing or reducing
 */
/*--------------------------------------------------------------------------*/
extern void oslActiveEffect(OSL_EFFECT *fx,int plus, int moin);

/*-------------------------------------------------------------------------*/
/**
  @brief    Delete an effect in memory
  @param    FX pointer to an OSL_EFFECT object

Delete an effect in memory
 */
/*--------------------------------------------------------------------------*/
extern void oslDeleteEffect(OSL_EFFECT *FX);

/*-------------------------------------------------------------------------*/
/**
  @brief    Do a fade in effect

Do a fade in effect with the current image (everything is done internally)
 */
/*--------------------------------------------------------------------------*/
extern void oslFadeInEffect();


/*-------------------------------------------------------------------------*/
/**
  @brief    faire un masque en carrer en dur
  @param    color Indique la couleur du masque 

faire un masque en carrer en dur qui part de l'exterrieur ver l'interrieur
 */
/*--------------------------------------------------------------------------*/
extern void oslDrawRectangleMaskEffect(OSL_COLOR color);


/*-------------------------------------------------------------------------*/
/**
  @brief    Make an effect with a lot of small cubes
  @param    tailleX Width of the cubes
  @param    TailleY Height of the cubes
  @param    color Color of the mask

Make a mask with a lot of small cubes (from the left to the right)
 */
/*--------------------------------------------------------------------------*/
extern void oslDrawCubeMaskEffect(int tailleX,int TailleY ,OSL_COLOR color);


/** @} */ // end of effect


#include "chipmunk/chipmunk.h"



//----------INIPARSER--------------

/** @defgroup Ini Parseur

	Gestion des fichier INI
	@{
*/


typedef struct _dictionary_ {
	int				n ;		/** Number of entries in dictionary */
	int				size ;	/** Storage size */
	char 		**	val ;	/** List of string values */
	char 		**  key ;	/** List of string keys */
	unsigned	 *	hash ;	/** List of hash values for keys */
} dictionary ;

/*-------------------------------------------------------------------------*/
/**
  @brief	Compute the hash key for a string.
  @param	key		Character string to use for key.
  @return	1 unsigned int on at least 32 bits.

  This hash function has been taken from an Article in Dr Dobbs Journal.
  This is normally a collision-free function, distributing keys evenly.
  The key is stored anyway in the struct so that collision can be avoided
  by comparing the key itself in last resort.
 */
/*--------------------------------------------------------------------------*/
extern unsigned dictionary_hash(char * key);

/*-------------------------------------------------------------------------*/
/**
  @brief	Create a new dictionary object.
  @param	size	Optional initial size of the dictionary.
  @return	1 newly allocated dictionary objet.

  This function allocates a new dictionary object of given size and returns
  it. If you do not know in advance (roughly) the number of entries in the
  dictionary, give size=0.
 */
/*--------------------------------------------------------------------------*/
extern dictionary * dictionary_new(int size);

/*-------------------------------------------------------------------------*/
/**
  @brief	Delete a dictionary object
  @param	d	dictionary object to deallocate.
  @return	void

  Deallocate a dictionary object and all memory associated to it.
 */
/*--------------------------------------------------------------------------*/
extern void dictionary_del(dictionary * vd);

/*-------------------------------------------------------------------------*/
/**
  @brief	Get a value from a dictionary.
  @param	d		dictionary object to search.
  @param	key		Key to look for in the dictionary.
  @param    def     Default value to return if key not found.
  @return	1 pointer to internally allocated character string.

  This function locates a key in a dictionary and returns a pointer to its
  value, or the passed 'def' pointer if no such key can be found in
  dictionary. The returned character pointer points to data internal to the
  dictionary object, you should not try to free it or modify it.
 */
/*--------------------------------------------------------------------------*/
extern char * dictionary_get(dictionary * d, char * key, char * def);

/*-------------------------------------------------------------------------*/
/**
  @brief    Set a value in a dictionary.
  @param    d       dictionary object to modify.
  @param    key     Key to modify or add.
  @param    val     Value to add.
  @return   int     0 if Ok, anything else otherwise

  If the given key is found in the dictionary, the associated value is
  replaced by the provided one. If the key cannot be found in the
  dictionary, it is added to it.

  It is Ok to provide a NULL value for val, but NULL values for the dictionary
  or the key are considered as errors: the function will return immediately
  in such a case.

  Notice that if you dictionary_set a variable to NULL, a call to
  dictionary_get will return a NULL value: the variable will be found, and
  its value (NULL) is returned. In other words, setting the variable
  content to NULL is equivalent to deleting the variable from the
  dictionary. It is not possible (in this implementation) to have a key in
  the dictionary without value.

  This function returns non-zero in case of failure.
 */
/*--------------------------------------------------------------------------*/
extern int dictionary_set(dictionary * vd, char * key, char * val);

/*-------------------------------------------------------------------------*/
/**
  @brief	Delete a key in a dictionary
  @param	d		dictionary object to modify.
  @param	key		Key to remove.
  @return   void

  This function deletes a key in a dictionary. Nothing is done if the
  key cannot be found.
 */
/*--------------------------------------------------------------------------*/
extern void dictionary_unset(dictionary * d, char * key);

/*-------------------------------------------------------------------------*/
/**
  @brief	Dump a dictionary to an opened file pointer.
  @param	d	Dictionary to dump
  @param	f	Opened file pointer.
  @return	void

  Dumps a dictionary onto an opened file pointer. Key pairs are printed out
  as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as
  output file pointers.
 */
/*--------------------------------------------------------------------------*/
extern void dictionary_dump(dictionary * d, FILE * out);


#define iniparser_getstr(d, k)  iniparser_getstring(d, k, NULL)
#define iniparser_setstr        iniparser_set


/*-------------------------------------------------------------------------*/
/**
  @brief    Get number of sections in a dictionary
  @param    d   Dictionary to examine
  @return   int Number of sections found in dictionary

  This function returns the number of sections found in a dictionary.
  The test to recognize sections is done on the string stored in the
  dictionary: a section name is given as "section" whereas a key is
  stored as "section:key", thus the test looks for entries that do not
  contain a colon.

  This clearly fails in the case a section name contains a colon, but
  this should simply be avoided.

  This function returns -1 in case of error.
 */
/*--------------------------------------------------------------------------*/
extern int iniparser_getnsec(dictionary * d);

/*-------------------------------------------------------------------------*/
/**
  @brief    Get name for section n in a dictionary.
  @param    d   Dictionary to examine
  @param    n   Section number (from 0 to nsec-1).
  @return   Pointer to char string

  This function locates the n-th section in a dictionary and returns
  its name as a pointer to a string statically allocated inside the
  dictionary. Do not free or modify the returned string!

  This function returns NULL in case of error.
 */
/*--------------------------------------------------------------------------*/
extern char * iniparser_getsecname(dictionary * d, int n);


/*-------------------------------------------------------------------------*/
/**
  @brief    Save a dictionary to a loadable ini file
  @param    d   Dictionary to dump
  @param    f   Opened file pointer to dump to
  @return   void

  This function dumps a given dictionary into a loadable ini file.
  It is Ok to specify @c stderr or @c stdout as output files.
 */
/*--------------------------------------------------------------------------*/
extern void iniparser_dump_ini(dictionary * d, FILE * f);

/*-------------------------------------------------------------------------*/
/**
  @brief    Dump a dictionary to an opened file pointer.
  @param    d   Dictionary to dump.
  @param    f   Opened file pointer to dump to.
  @return   void

  This function prints out the contents of a dictionary, one element by
  line, onto the provided file pointer. It is OK to specify @c stderr
  or @c stdout as output files. This function is meant for debugging
  purposes mostly.
 */
/*--------------------------------------------------------------------------*/
extern void iniparser_dump(dictionary * d, FILE * f);


/*-------------------------------------------------------------------------*/
/**
  @brief    Get the string associated to a key
  @param    d       Dictionary to search
  @param    key     Key string to look for
  @param    def     Default value to return if key not found.
  @return   pointer to statically allocated character string

  This function queries a dictionary for a key. A key as read from an
  ini file is given as "section:key". If the key cannot be found,
  the pointer passed as 'def' is returned.
  The returned char pointer is pointing to a string allocated in
  the dictionary, do not free or modify it.
 */
/*--------------------------------------------------------------------------*/
extern char * iniparser_getstring(dictionary * d, const char * key, char * def);

/*-------------------------------------------------------------------------*/
/**
  @brief    Get the string associated to a key, convert to an int
  @param    d Dictionary to search
  @param    key Key string to look for
  @param    notfound Value to return in case of error
  @return   integer

  This function queries a dictionary for a key. A key as read from an
  ini file is given as "section:key". If the key cannot be found,
  the notfound value is returned.

  Supported values for integers include the usual C notation
  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
  are supported. Examples:

  "42"      ->  42
  "042"     ->  34 (octal -> decimal)
  "0x42"    ->  66 (hexa  -> decimal)

  Warning: the conversion may overflow in various ways. Conversion is
  totally outsourced to strtol(), see the associated man page for overflow
  handling.

  Credits: Thanks to A. Becker for suggesting strtol()
 */
/*--------------------------------------------------------------------------*/
extern int iniparser_getint(dictionary * d, const char * key, int notfound);

/*-------------------------------------------------------------------------*/
/**
  @brief    Get the string associated to a key, convert to an int
  @param    d Dictionary to search
  @param    key Key string to look for
  @param    notfound Value to return in case of error
  @return   integer

  This function queries a dictionary for a key. A key as read from an
  ini file is given as "section:key". If the key cannot be found,
  the notfound value is returned.

  Supported values for integers include the usual C notation
  so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
  are supported. Examples:

  "42"      ->  42
  "042"     ->  34 (octal -> decimal)
  "0x42"    ->  66 (hexa  -> decimal)

  Warning: the conversion may overflow in various ways. Conversion is
  totally outsourced to strtol(), see the associated man page for overflow
  handling.

  Credits: Thanks to A. Becker for suggesting strtol()
 */
/*--------------------------------------------------------------------------*/
extern double iniparser_getdouble(dictionary * d, char * key, double notfound);

/*-------------------------------------------------------------------------*/
/**
  @brief    Get the string associated to a key, convert to a boolean
  @param    d Dictionary to search
  @param    key Key string to look for
  @param    notfound Value to return in case of error
  @return   integer

  This function queries a dictionary for a key. A key as read from an
  ini file is given as "section:key". If the key cannot be found,
  the notfound value is returned.

  A true boolean is found if one of the following is matched:

  - A string starting with 'y'
  - A string starting with 'Y'
  - A string starting with 't'
  - A string starting with 'T'
  - A string starting with '1'

  A false boolean is found if one of the following is matched:

  - A string starting with 'n'
  - A string starting with 'N'
  - A string starting with 'f'
  - A string starting with 'F'
  - A string starting with '0'

  The notfound value returned if no boolean is identified, does not
  necessarily have to be 0 or 1.
 */
/*--------------------------------------------------------------------------*/
extern int iniparser_getboolean(dictionary * d, const char * key, int notfound);

/*-------------------------------------------------------------------------*/
/**
  @brief    Set an entry in a dictionary.
  @param    ini     Dictionary to modify.
  @param    entry   Entry to modify (entry name)
  @param    val     New value to associate to the entry.
  @return   int 0 if Ok, -1 otherwise.

  If the given entry can be found in the dictionary, it is modified to
  contain the provided value. If it cannot be found, -1 is returned.
  It is Ok to set val to NULL.
 */
/*--------------------------------------------------------------------------*/
extern int iniparser_set(dictionary * ini, char * entry, char * val);


/*-------------------------------------------------------------------------*/
/**
  @brief    Delete an entry in a dictionary
  @param    ini     Dictionary to modify
  @param    entry   Entry to delete (entry name)
  @return   void

  If the given entry can be found, it is deleted from the dictionary.
 */
/*--------------------------------------------------------------------------*/
extern void iniparser_unset(dictionary * ini, char * entry);

/*-------------------------------------------------------------------------*/
/**
  @brief    Finds out if a given entry exists in a dictionary
  @param    ini     Dictionary to search
  @param    entry   Name of the entry to look for
  @return   integer 1 if entry exists, 0 otherwise

  Finds out if a given entry exists in the dictionary. Since sections
  are stored as keys with NULL associated values, this is the only way
  of querying for the presence of sections in a dictionary.
 */
/*--------------------------------------------------------------------------*/
extern int iniparser_find_entry(dictionary * ini, char * entry) ;

/*-------------------------------------------------------------------------*/
/**
  @brief    Parse an ini file and return an allocated dictionary object
  @param    ininame Name of the ini file to read.
  @return   Pointer to newly allocated dictionary

  This is the parser for ini files. This function is called, providing
  the name of the file to be read. It returns a dictionary object that
  should not be accessed directly, but through accessor functions
  instead.

  The returned dictionary must be freed using iniparser_freedict().
 */
/*--------------------------------------------------------------------------*/
extern dictionary * iniparser_load(const char * ininame);


/*-------------------------------------------------------------------------*/
/**
  @brief    Free all memory associated to an ini dictionary
  @param    d Dictionary to free
  @return   void

  Free all memory associated to an ini dictionary.
  It is mandatory to call this function before the dictionary object
  gets out of the current context.
 */
/*--------------------------------------------------------------------------*/
extern void iniparser_freedict(dictionary * d);


/** @} */ // end of Ini Parseur


//---------PARTICULE--------


/** @defgroup Particle

	Management of several systems of particles
	@{
*/


#define cGfxParticleSet		4
#define MaxParticles	600
#define cGfxParticleState	4



typedef struct PARTICLE
{
	int	x[ cGfxParticleSet ];//poss x
	int	y[ cGfxParticleSet ];//poss y
	int	dx[ cGfxParticleSet ];//distance x
	int	dy[ cGfxParticleSet ];//distance y
	int sx[ cGfxParticleSet ];//direction y
	int sy[ cGfxParticleSet ];//direction y
	int	status;


} PARTICLE;



/**
 * \struct OSL_PARTICLES
 * \brief Use for the management of particles
 *
 * OSL_PARTICLES is a structure for the management of particles
 * It's not detailled because it's not necessary to touch at any value, the functions permit to modify everything directly
 */

typedef struct OSL_PARTICLES
{

PARTICLE	particle[ MaxParticles ];
OSL_IMAGE		*Images[ cGfxParticleState ];

int life;//	50
int Speed;//	30 //30
int speed_Mini;//	10
int Graviter;//	4

} OSL_PARTICLES;



/*-------------------------------------------------------------------------*/
/**
  @brief    Free the memory of the particle system
  @param    Fichier File choosen for the particles image

Initialize a particle system with the form :
OSL_PARTICLES *toto = DevsInitParticule("file1.png");
 */
/*--------------------------------------------------------------------------*/
extern OSL_PARTICLES *oslLoadParticles(char *Fichier);


/*-------------------------------------------------------------------------*/
/**
  @brief    Update the movement of the particle system
  @param    Part Pointer to the particle system choosen

Update the movement of the particle system
 */
/*--------------------------------------------------------------------------*/
extern void oslUpdateParticles(OSL_PARTICLES *Part);


/*-------------------------------------------------------------------------*/
/**
  @brief    Initialize a particle system
  @param    Part Pointer on the particle system choosen
  @param    duree Duration of the particle's life
  @param    vitesse Maximum speed of the particles
  @param    Graviter Gravity for the particles
  @param    vitessemini Minimum speed of the particles

Initialize the parameters of a particle system
 */
/*--------------------------------------------------------------------------*/
extern void oslInitParticles(OSL_PARTICLES *Part,int time,int speed,int Graviter,int speedmin);

/*-------------------------------------------------------------------------*/
/**
  @brief    Add particles
  @param    Part Pointer on the particle system choosen
  @param    x Position X
  @param    y Position Y

Add particules
 */
/*--------------------------------------------------------------------------*/
extern void oslNewParticles(OSL_PARTICLES *Part, int x, int y );

/*-------------------------------------------------------------------------*/
/**
  @brief    Render of the particle system
  @param    Part Pointer on the particle system

Render of the particle system
 */
/*--------------------------------------------------------------------------*/
extern void oslRenderParticles(OSL_PARTICLES *Part);

/*-------------------------------------------------------------------------*/
/**
  @brief    Free the memory of the particle system
  @param    Part Pointer on the particle system

Free the memory of the particle system
 */
/*--------------------------------------------------------------------------*/
extern void oslDeleteParticles(OSL_PARTICLES *Part);

/*-------------------------------------------------------------------------*/
/**
  @brief    Change the direction X of the particles
  @param    Part Pointer on the particle system chossen
  @param    x New direction X of the particles

Change the direction X of the particles
 */
/*--------------------------------------------------------------------------*/
extern void oslMoveXParticles( OSL_PARTICLES *Part,int x);


/*-------------------------------------------------------------------------*/
/**
 @brief    Change the direction Y of the particles
 @param    Part Pointer on the particle system chossen
 @param    y New direction Y of the particles
 
 Change the direction Y of the particles
 */
/*--------------------------------------------------------------------------*/
extern void oslMoveYParticles( OSL_PARTICLES *Part,int y );


/** @} */ // end of particle



/** @defgroup menu Circle

	Functions to make several different presentation menu for the PSP
	@{
*/


/**
 * \struct OSL_CIRCLE_MENU
 * \brief Use for the management of menu
 *
 * OSL_CIRCLE_MENU is a structure for the management of the menu
 * Not detailled because it's not necessary to touch to anything, functions permit to modify everything directly
 */
typedef struct {
 
	int AlphaMenu; /*!< alpha celon l'eloignement */
	int AngleVoullue; /*!< angle desirer pour la rotation */
	int nbIcones; /*!< nb d'image dans le cercle */
	int SelectionEncour ; /*!< Ou en et la possition du menu par defaut doit ETRE A 0 */
	OSL_IMAGE *Image; /*!< Image pour le menu */
	int sizeX; /*!< dimantion d'une Icone en X */
	int sizeY; /*!<  dimantion d'une Icone en Y */
	int Eloignement; /*!< Eloignement de menu par rapport a la possition d'origine */
	int test_angle; /*!<  */
	int X; /*!< Possition du menu en X */
	int Y; /*!< Possition du menu en Y */
	int LargeurAnimX; /*!< eloignement de l'annimation entre les icones sur la largeur */
	int LargeurAnimY; /*!< eloignement de l'annimation entre les icones sur la Hauteur */

} OSL_CIRCLE_MENU;


/*-------------------------------------------------------------------------*/
/**
  @brief    Move the icons in the choosen direction
  @param    MenuS Pointer on the menu
  @param    sens Direction : 1 = left and 0 = right
 
Move the icons ih the choosen direction
 */
/*--------------------------------------------------------------------------*/
extern void oslMenuMoveIcons(OSL_CIRCLE_MENU *MenuS,int sens);

/*-------------------------------------------------------------------------*/
/**
  @brief    Draw the menu
  @param    MenuS Pointer of the menu
 
Draw the menu
 */
/*--------------------------------------------------------------------------*/
extern void oslMenuUpdateIcons(OSL_CIRCLE_MENU *MenuS);



/*-------------------------------------------------------------------------*/
/**
  @brief    Return the position on the menu
  @param    MenuS Pointer of the menu
  @return   Current position on the menu
 
Return the current position on the menu ( it can be usefull lol)
 */
/*--------------------------------------------------------------------------*/
extern int oslMenuReturnIconPosition(OSL_CIRCLE_MENU *MenuS);


/*-------------------------------------------------------------------------*/
/**
  @brief    Draw the menu
  @param    MenuS Pointer of the menu
  @param    angle Angle of the menu
  @param    Eloignement Distance of the menu
 
 Draw the menu
 */
/*--------------------------------------------------------------------------*/
extern void oslMenuDrawIcons(OSL_CIRCLE_MENU *MenuS,int angle, int Eloignement);


/*-------------------------------------------------------------------------*/
/**
  @brief    Create a "circle" menu
  @param    nbIcones Number of icons
  @param    Eloignement Distance of the menu
  @param    SelectionEncour Index of the first icon selected
  @param    sizeX sizeY are the width and the height of an icon
  @param    X Y are the position of the menu
  @param    LargeurAnimX Distance between the icons (width between opposite icons in X)
  @param    LargeurAnimY Distance between the icons (height between opposite icons in Y)

Initialize a new menu with the "circle" effect
 */
/*--------------------------------------------------------------------------*/
extern OSL_CIRCLE_MENU *oslCreateCircleMenu(char *file, int nbIcones, int Eloignement, int SelectionEncour,int sizeX,int sizeY,int X, int Y,int LargeurAnimX, int LargeurAnimY);

/*-------------------------------------------------------------------------*/
/**
  @brief    Free the memory of a "circle" menu
  @param    MenuS Pointer on the menu to delete

Delete the effect for a "circle" menu (free the memory)
 */
/*--------------------------------------------------------------------------*/
extern void oslDeleteCircleMenu(OSL_CIRCLE_MENU *MenuS);



/** @} */ // end of menu Circle

#ifdef __cplusplus
}
#endif

#endif
