- put common POSIX system code to a separate file

# Conflicts:
#	src/posix/sdl/i_system.cpp

# Conflicts:
#	src/posix/cocoa/i_system.mm
#	src/posix/sdl/i_system.cpp
This commit is contained in:
alexey.lysiuk 2020-01-26 10:49:20 +02:00 committed by drfrag
parent b8395e5b59
commit 3b89c2fd34
4 changed files with 161 additions and 290 deletions

View file

@ -485,7 +485,8 @@ set( PLAT_WIN32_SOURCES
win32/win32gliface.cpp win32/win32gliface.cpp
win32/win32video.cpp ) win32/win32video.cpp )
set( PLAT_POSIX_SOURCES set( PLAT_POSIX_SOURCES
posix/i_steam.cpp ) posix/i_steam.cpp
posix/i_system_posix.cpp )
set( PLAT_SDL_SOURCES set( PLAT_SDL_SOURCES
posix/sdl/crashcatcher.c posix/sdl/crashcatcher.c
posix/sdl/hardware.cpp posix/sdl/hardware.cpp

View file

@ -33,41 +33,16 @@
#include "i_common.h" #include "i_common.h"
#include <fnmatch.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include "d_protocol.h"
#include "doomdef.h"
#include "doomerrors.h"
#include "doomstat.h"
#include "g_game.h"
#include "gameconfigfile.h"
#include "i_sound.h"
#include "i_system.h" #include "i_system.h"
#include "st_console.h" #include "st_console.h"
#include "v_text.h" #include "v_text.h"
#include "x86.h"
#include "cmdlib.h"
void I_Tactile(int /*on*/, int /*off*/, int /*total*/)
{
}
ticcmd_t* I_BaseTiccmd()
{
static ticcmd_t emptycmd;
return &emptycmd;
}
double PerfToSec, PerfToMillisec; double PerfToSec, PerfToMillisec;
static void CalculateCPUSpeed() void CalculateCPUSpeed()
{ {
long long frequency; long long frequency;
size_t size = sizeof frequency; size_t size = sizeof frequency;
@ -84,17 +59,6 @@ static void CalculateCPUSpeed()
} }
} }
void I_Init(void)
{
CheckCPUID(&CPU);
CalculateCPUSpeed();
DumpCPUInfo(&CPU);
}
void I_SetIWADInfo()
{
}
void I_DebugPrint(const char *cp) void I_DebugPrint(const char *cp)
{ {
@ -174,90 +138,6 @@ int I_PickIWad(WadStuff* const wads, const int numwads, const bool showwin, cons
} }
bool I_WriteIniFailed()
{
printf("The config file %s could not be saved:\n%s\n", GameConfig->GetPathName(), strerror(errno));
return false; // return true to retry
}
static const char *pattern;
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1080
static int matchfile(struct dirent *ent)
#else
static int matchfile(const struct dirent *ent)
#endif
{
return fnmatch(pattern, ent->d_name, FNM_NOESCAPE) == 0;
}
void* I_FindFirst(const char* const filespec, findstate_t* const fileinfo)
{
FString dir;
const char* const slash = strrchr(filespec, '/');
if (slash)
{
pattern = slash+1;
dir = FString(filespec, slash - filespec + 1);
}
else
{
pattern = filespec;
dir = ".";
}
fileinfo->current = 0;
fileinfo->count = scandir(dir.GetChars(), &fileinfo->namelist, matchfile, alphasort);
if (fileinfo->count > 0)
{
return fileinfo;
}
return (void*)-1;
}
int I_FindNext(void* const handle, findstate_t* const fileinfo)
{
findstate_t* const state = static_cast<findstate_t*>(handle);
if (state->current < fileinfo->count)
{
return ++state->current < fileinfo->count ? 0 : -1;
}
return -1;
}
int I_FindClose(void* const handle)
{
findstate_t* const state = static_cast<findstate_t*>(handle);
if (handle != (void*)-1 && state->count > 0)
{
for (int i = 0; i < state->count; ++i)
{
free(state->namelist[i]);
}
free(state->namelist);
state->namelist = NULL;
state->count = 0;
}
return 0;
}
int I_FindAttr(findstate_t* const fileinfo)
{
dirent* const ent = fileinfo->namelist[fileinfo->current];
return (ent->d_type & DT_DIR) ? FA_DIREC : 0;
}
void I_PutInClipboard(const char* const string) void I_PutInClipboard(const char* const string)
{ {
NSPasteboard* const pasteBoard = [NSPasteboard generalPasteboard]; NSPasteboard* const pasteBoard = [NSPasteboard generalPasteboard];
@ -289,11 +169,3 @@ unsigned int I_MakeRNGSeed()
{ {
return static_cast<unsigned int>(arc4random()); return static_cast<unsigned int>(arc4random());
} }
TArray<FString> I_GetGogPaths()
{
// GOG's Doom games are Windows only at the moment
return TArray<FString>();
}

View file

@ -0,0 +1,153 @@
//-----------------------------------------------------------------------------
//
// Copyright 1993-1996 id Software
// Copyright 1999-2016 Randy Heit
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/
//
//-----------------------------------------------------------------------------
//
#include <stdio.h>
#include <errno.h>
#include <fnmatch.h>
#ifdef __APPLE__
#include <AvailabilityMacros.h>
#endif // __APPLE__
#include "d_protocol.h"
#include "i_system.h"
#include "gameconfigfile.h"
#include "x86.h"
void I_Tactile(int /*on*/, int /*off*/, int /*total*/)
{
}
static ticcmd_t emptycmd;
ticcmd_t *I_BaseTiccmd()
{
return &emptycmd;
}
//
// I_Init
//
void I_Init()
{
extern void CalculateCPUSpeed();
CheckCPUID(&CPU);
CalculateCPUSpeed();
DumpCPUInfo(&CPU);
}
void I_SetIWADInfo()
{
}
bool I_WriteIniFailed()
{
printf("The config file %s could not be saved:\n%s\n", GameConfig->GetPathName(), strerror(errno));
return false; // return true to retry
}
static const char *pattern;
#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED < 1080
static int matchfile(struct dirent *ent)
#else
static int matchfile(const struct dirent *ent)
#endif
{
return fnmatch(pattern, ent->d_name, FNM_NOESCAPE) == 0;
}
void *I_FindFirst(const char *const filespec, findstate_t *const fileinfo)
{
FString dir;
const char *const slash = strrchr(filespec, '/');
if (slash)
{
pattern = slash + 1;
dir = FString(filespec, slash - filespec + 1);
}
else
{
pattern = filespec;
dir = ".";
}
fileinfo->current = 0;
fileinfo->count = scandir(dir.GetChars(), &fileinfo->namelist, matchfile, alphasort);
if (fileinfo->count > 0)
{
return fileinfo;
}
return (void *)-1;
}
int I_FindNext(void *const handle, findstate_t *const fileinfo)
{
findstate_t *const state = static_cast<findstate_t *>(handle);
if (state->current < fileinfo->count)
{
return ++state->current < fileinfo->count ? 0 : -1;
}
return -1;
}
int I_FindClose(void *const handle)
{
findstate_t *const state = static_cast<findstate_t *>(handle);
if (handle != (void *)-1 && state->count > 0)
{
for (int i = 0; i < state->count; ++i)
{
free(state->namelist[i]);
}
free(state->namelist);
state->namelist = nullptr;
state->count = 0;
}
return 0;
}
int I_FindAttr(findstate_t *const fileinfo)
{
dirent *const ent = fileinfo->namelist[fileinfo->current];
return (ent->d_type & DT_DIR) ? FA_DIREC : 0;
}
TArray<FString> I_GetGogPaths()
{
// GOG's Doom games are Windows only at the moment
return TArray<FString>();
}

View file

@ -19,60 +19,17 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// //
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fnmatch.h>
#include <unistd.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <time.h>
#include <unistd.h>
#include <SDL.h> #include <SDL.h>
#include "doomerrors.h" #include "d_main.h"
#include <math.h> #include "i_system.h"
#include "doomtype.h"
#include "doomstat.h"
#include "version.h" #include "version.h"
#include "doomdef.h"
#include "cmdlib.h"
#include "m_argv.h"
#include "m_misc.h"
#include "i_video.h"
#include "i_sound.h"
#include "i_music.h"
#include "x86.h" #include "x86.h"
#include "d_main.h"
#include "d_net.h"
#include "g_game.h"
#include "i_system.h"
#include "c_dispatch.h"
#include "templates.h"
#include "v_palette.h"
#include "textures.h"
#include "bitmap.h"
#include "stats.h"
#include "hardware.h"
#include "gameconfigfile.h"
#include "m_fixed.h"
#include "g_level.h"
extern "C"
{
double SecondsPerCycle = 1e-8;
double CyclesPerSecond = 1e8;
}
#ifndef NO_GTK #ifndef NO_GTK
bool I_GtkAvailable (); bool I_GtkAvailable ();
@ -84,38 +41,9 @@ int I_PickIWad_Cocoa (WadStuff *wads, int numwads, bool showwin, int defaultiwad
double PerfToSec, PerfToMillisec; double PerfToSec, PerfToMillisec;
void I_Tactile (int /*on*/, int /*off*/, int /*total*/)
{
}
ticcmd_t emptycmd;
ticcmd_t *I_BaseTiccmd(void)
{
return &emptycmd;
}
void I_BeginRead(void)
{
}
void I_EndRead(void)
{
}
//
// I_Init
//
void I_Init (void)
{
CheckCPUID (&CPU);
DumpCPUInfo (&CPU);
}
// //
// I_Error // I_Error
// //
extern FILE *Logfile;
#ifdef __APPLE__ #ifdef __APPLE__
void Mac_I_FatalError(const char* errortext); void Mac_I_FatalError(const char* errortext);
@ -164,11 +92,9 @@ void I_ShowFatalError(const char *message)
#else #else
// ??? // ???
#endif #endif
} }
void CalculateCPUSpeed()
void I_SetIWADInfo ()
{ {
} }
@ -295,80 +221,6 @@ int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad)
return i-1; return i-1;
} }
bool I_WriteIniFailed ()
{
printf ("The config file %s could not be saved:\n%s\n", GameConfig->GetPathName(), strerror(errno));
return false;
// return true to retry
}
static const char *pattern;
#if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED < 1080
static int matchfile (struct dirent *ent)
#else
static int matchfile (const struct dirent *ent)
#endif
{
return fnmatch (pattern, ent->d_name, FNM_NOESCAPE) == 0;
}
void *I_FindFirst (const char *filespec, findstate_t *fileinfo)
{
FString dir;
const char *slash = strrchr (filespec, '/');
if (slash)
{
pattern = slash+1;
dir = FString(filespec, slash-filespec+1);
}
else
{
pattern = filespec;
dir = ".";
}
fileinfo->current = 0;
fileinfo->count = scandir (dir.GetChars(), &fileinfo->namelist,
matchfile, alphasort);
if (fileinfo->count > 0)
{
return fileinfo;
}
return (void*)-1;
}
int I_FindNext (void *handle, findstate_t *fileinfo)
{
findstate_t *state = (findstate_t *)handle;
if (state->current < fileinfo->count)
{
return ++state->current < fileinfo->count ? 0 : -1;
}
return -1;
}
int I_FindClose (void *handle)
{
findstate_t *state = (findstate_t *)handle;
if (handle != (void*)-1 && state->count > 0)
{
for(int i = 0;i < state->count;++i)
free (state->namelist[i]);
state->count = 0;
free (state->namelist);
state->namelist = NULL;
}
return 0;
}
int I_FindAttr(findstate_t* const fileinfo)
{
dirent* const ent = fileinfo->namelist[fileinfo->current];
return (ent->d_type & DT_DIR) ? FA_DIREC : 0;
}
void I_PutInClipboard (const char *str) void I_PutInClipboard (const char *str)
{ {
SDL_SetClipboardText(str); SDL_SetClipboardText(str);
@ -406,10 +258,3 @@ unsigned int I_MakeRNGSeed()
} }
return seed; return seed;
} }
TArray<FString> I_GetGogPaths()
{
// GOG's Doom games are Windows only at the moment
return TArray<FString>();
}