2017-01-21 17:27:46 +01:00
|
|
|
|
// misc.cpp
|
|
|
|
|
//
|
|
|
|
|
|
2017-02-10 00:14:28 +01:00
|
|
|
|
#include <SDL_log.h>
|
2017-01-23 00:21:33 +01:00
|
|
|
|
#include <SDL_mouse.h>
|
2017-01-21 17:27:46 +01:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2017-02-10 00:14:28 +01:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <direct.h>
|
|
|
|
|
#include "blupi.h"
|
2017-01-21 17:27:46 +01:00
|
|
|
|
#include "def.h"
|
|
|
|
|
|
|
|
|
|
// Variables globales
|
|
|
|
|
|
2017-01-22 00:10:12 +01:00
|
|
|
|
extern bool g_bFullScreen; // false si mode de test
|
2017-01-21 17:27:46 +01:00
|
|
|
|
extern int g_mouseType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Affiche un message de debug.
|
|
|
|
|
|
|
|
|
|
void OutputDebug(char *pMessage)
|
|
|
|
|
{
|
2017-02-10 00:14:28 +01:00
|
|
|
|
SDL_LogDebug (SDL_LOG_CATEGORY_APPLICATION, "%s", pMessage);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Conversion de la position de la souris.
|
|
|
|
|
|
|
|
|
|
POINT ConvLongToPos(LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
POINT pos;
|
|
|
|
|
|
|
|
|
|
pos.x = LOWORD(lParam); // horizontal position of cursor
|
|
|
|
|
pos.y = HIWORD(lParam); // vertical position of cursor
|
|
|
|
|
|
|
|
|
|
// if ( !g_bFullScreen )
|
|
|
|
|
// {
|
|
|
|
|
// pos.y -= GetSystemMetrics(SM_CYCAPTION);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// R<>initialise le g<>n<EFBFBD>rateur al<61>atoire.
|
|
|
|
|
|
|
|
|
|
void InitRandom()
|
|
|
|
|
{
|
|
|
|
|
srand(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Retourne un nombre al<61>atoire compris entre
|
|
|
|
|
// deux bornes (inclues).
|
|
|
|
|
|
|
|
|
|
int Random(int min, int max)
|
|
|
|
|
{
|
|
|
|
|
long n;
|
|
|
|
|
|
|
|
|
|
n = rand();
|
|
|
|
|
n = min+(n%(max-min+1));
|
|
|
|
|
|
|
|
|
|
return (int)n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Retourne le nom de dossier en cours.
|
|
|
|
|
|
2017-01-22 00:26:57 +01:00
|
|
|
|
void GetCurrentDir(char *pName, size_t lg)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-02-10 00:14:28 +01:00
|
|
|
|
char *basePath = SDL_GetBasePath ();
|
|
|
|
|
strncpy(pName, basePath, lg-1);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
pName[lg-1] = 0;
|
|
|
|
|
|
|
|
|
|
lg = strlen(pName);
|
2017-02-10 00:14:28 +01:00
|
|
|
|
if (lg == 0)
|
|
|
|
|
goto out;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
while ( lg > 0 )
|
|
|
|
|
{
|
|
|
|
|
lg --;
|
|
|
|
|
if ( pName[lg] == '\\' )
|
|
|
|
|
{
|
|
|
|
|
pName[lg+1] = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-10 00:14:28 +01:00
|
|
|
|
if ( lg > 6 && strcmp(pName+lg-6, "\\Debug\\") == 0 )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
pName[lg-5] = 0; // ignore le dossier \debug !
|
|
|
|
|
}
|
2017-02-10 00:14:28 +01:00
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
SDL_free (basePath);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ajoute le chemin permettant de lire un fichier
|
|
|
|
|
// utilisateur.
|
|
|
|
|
|
|
|
|
|
void AddUserPath(char *pFilename)
|
|
|
|
|
{
|
2017-02-10 00:14:28 +01:00
|
|
|
|
char *temp;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
char* pText;
|
2017-01-22 00:26:57 +01:00
|
|
|
|
size_t pos;
|
2017-01-21 17:27:46 +01:00
|
|
|
|
char last;
|
|
|
|
|
|
2017-02-10 00:14:28 +01:00
|
|
|
|
temp = SDL_GetPrefPath ("Epsitec SA", "Planet Blupi");
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
|
|
|
|
pText = strstr(pFilename, "\\");
|
2017-02-05 17:54:12 +01:00
|
|
|
|
if ( pText != nullptr )
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
|
|
|
|
pos = strlen(temp)+(pText-pFilename)+1;
|
|
|
|
|
strcat(temp, pFilename);
|
|
|
|
|
last = temp[pos];
|
|
|
|
|
temp[pos] = 0;
|
2017-02-10 00:14:28 +01:00
|
|
|
|
_mkdir (temp);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
temp[pos] = last;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strcat(temp, pFilename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strcpy(pFilename, temp);
|
2017-02-10 00:14:28 +01:00
|
|
|
|
SDL_free (temp);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|