1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00
planetblupi/src/misc.cpp

126 lines
2.4 KiB
C++
Raw Normal View History

2017-01-21 17:27:46 +01:00
// misc.cpp
//
2017-02-10 23:03:33 +01:00
#include <SDL2/SDL_log.h>
#include <SDL2/SDL_mouse.h>
2017-02-11 19:31:30 +01:00
#include <algorithm>
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>
2017-02-11 21:43:47 +01:00
#ifdef _WIN32
2017-02-10 00:14:28 +01:00
#include <direct.h>
2017-02-11 21:43:47 +01:00
#define mkdir(a, b) _mkdir(a)
#else /* _WIN32 */
#include <sys/stat.h>
#endif /*! _WIN32 */
2017-02-11 18:10:32 +01:00
#include "misc.h"
2017-02-10 00:14:28 +01:00
#include "blupi.h"
2017-01-21 17:27:46 +01:00
#include "def.h"
// Variables globales
extern bool g_bFullScreen; // false si mode de test
extern Sint32 g_mouseType;
2017-01-21 17:27:46 +01:00
// Affiche un message de debug.
void OutputDebug (const char *pMessage)
2017-01-21 17:27:46 +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)
2017-01-21 17:27:46 +01:00
{
POINT pos;
2017-01-21 17:27:46 +01:00
pos.x = LOWORD (lParam); // horizontal position of cursor
pos.y = HIWORD (lParam); // vertical position of cursor
2017-01-21 17:27:46 +01:00
// if ( !g_bFullScreen )
// {
// pos.y -= GetSystemMetrics(SM_CYCAPTION);
// }
2017-01-21 17:27:46 +01:00
return pos;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// R�initialise le g�n�rateur al�atoire.
2017-01-21 17:27:46 +01:00
void InitRandom()
{
srand (1);
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Retourne un nombre al�atoire compris entre
2017-01-21 17:27:46 +01:00
// deux bornes (inclues).
Sint32 Random (Sint32 min, Sint32 max)
2017-01-21 17:27:46 +01:00
{
Sint32 n;
2017-02-10 23:03:33 +01:00
n = rand();
n = min + (n % (max - min + 1));
2017-01-21 17:27:46 +01:00
return (Sint32)n;
2017-01-21 17:27:46 +01:00
}
std::string GetLocale ()
{
return gettext ("en");
}
2017-01-21 17:27:46 +01:00
// Retourne le nom de dossier en cours.
std::string GetBaseDir()
2017-01-21 17:27:46 +01:00
{
static std::string basePath;
if (!basePath.size())
{
auto sdlBasePath = SDL_GetBasePath();
sdlBasePath[strlen (sdlBasePath) - 1] = '\0';
basePath = sdlBasePath;
std::replace (basePath.begin(), basePath.end(), '\\', '/');
basePath = basePath.substr (0, basePath.find_last_of ("//") + 1);
SDL_free (sdlBasePath);
}
return basePath + "share/planetblupi/";
2017-01-21 17:27:46 +01:00
}
// Ajoute le chemin permettant de lire un fichier
// utilisateur.
void AddUserPath (char *pFilename)
2017-01-21 17:27:46 +01:00
{
char *temp;
char *pText;
size_t pos;
char last;
temp = SDL_GetPrefPath ("Epsitec SA", "Planet Blupi");
std::string path = temp;
pText = strstr (pFilename, "/");
if (pText != nullptr)
{
pos = path.size() + (pText - pFilename) + 1;
path += pFilename;
last = path[pos];
path[pos] = 0;
mkdir (path.c_str(), 755);
path[pos] = last;
}
else
path += pFilename;
strcpy (pFilename, path.c_str());
SDL_free (temp);
2017-01-21 17:27:46 +01:00
}