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

118 lines
1.9 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-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>
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
2017-01-21 17:27:46 +01:00
extern int g_mouseType;
// Affiche un message de debug.
2017-02-11 18:33:40 +01:00
void OutputDebug(const char *pMessage)
2017-01-21 17:27:46 +01:00
{
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;
2017-02-10 23:03:33 +01:00
pos.x = LOWORD(lParam); // horizontal position of cursor
2017-01-21 17:27:46 +01:00
pos.y = HIWORD(lParam); // vertical position of cursor
// if ( !g_bFullScreen )
// {
// pos.y -= GetSystemMetrics(SM_CYCAPTION);
// }
return pos;
}
2017-02-10 23:03:33 +01:00
// R<>initialise le g<>n<EFBFBD>rateur al<61>atoire.
2017-01-21 17:27:46 +01:00
void InitRandom()
{
srand(1);
}
2017-02-10 23:03:33 +01:00
// Retourne un nombre al<61>atoire compris entre
2017-01-21 17:27:46 +01:00
// deux bornes (inclues).
int Random(int min, int max)
{
long n;
2017-02-10 23:03:33 +01:00
2017-01-21 17:27:46 +01:00
n = rand();
n = min+(n%(max-min+1));
return (int)n;
}
// Retourne le nom de dossier en cours.
2017-02-11 18:10:32 +01:00
std::string GetBaseDir ()
2017-01-21 17:27:46 +01:00
{
2017-02-11 18:10:32 +01:00
char *sdlBasePath = nullptr;
static std::string basePath;
2017-01-21 17:27:46 +01:00
2017-02-11 18:10:32 +01:00
if (!basePath.size ())
2017-01-21 17:27:46 +01:00
{
2017-02-11 18:10:32 +01:00
sdlBasePath = SDL_GetBasePath ();
sdlBasePath[strlen (sdlBasePath) - 1] = '\0';
2017-01-21 17:27:46 +01:00
}
2017-02-11 18:10:32 +01:00
std::string path = sdlBasePath;
path = path.substr (0, path.find_last_of ("\\/") + 1);
if (sdlBasePath)
SDL_free (sdlBasePath);
2017-02-10 00:14:28 +01:00
2017-02-11 18:10:32 +01:00
return path;
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;
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
}