Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • STJr/SRB2
  • Sryder/SRB2
  • wolfy852/SRB2
  • Alpha2244/SRB2
  • Inuyasha/SRB2
  • yoshibot/SRB2
  • TehRealSalt/SRB2
  • PrisimaTF/SRB2
  • Hatninja/SRB2
  • SteelT/SRB2
  • james/SRB2
  • ShaderWraith/SRB2
  • SinnamonLat/SRB2
  • mazmazz_/SRB2
  • filpAM/SRB2
  • chaoloveicemdboy/SRB2
  • Whooa21/SRB2
  • Machturne/SRB2
  • Golden/SRB2
  • Tatsuru/SRB2
  • Snu/SRB2
  • Zwip-Zwap_Zapony/SRB2
  • fickleheart/SRB2
  • alphaRexJames/SRB2
  • JJK/SRB2
  • diskpoppy/SRB2
  • Hannu_Hanhi/SRB2
  • ZipperQR/SRB2
  • kays/SRB2
  • spherallic/SRB2
  • Zippy_Zolton/SRB2
  • namiishere/SRB2
  • Ors/SRB2
  • SMS_Alfredo/SRB2
  • sonic_edge/SRB2
  • lavla/SRB2
  • ashi/SRB2
  • X.organic/SRB2
  • Fafabis/SRB2
  • Meziu/SRB2
  • v-rob/SRB2
  • tertu/SRB2
  • bitten2up/SRB2
  • flarn2006/SRB2
  • Krabs/SRB2
  • clairebun/SRB2
  • Lactozilla/SRB2
  • thehackstack/SRB2
  • Spice/SRB2
  • win8linux/SRB2
  • JohnFrostFox/SRB2
  • talktoneon726/SRB2
  • Wane/SRB2
  • Lamibe/SRB2
  • spectrumuk2/srb-2
  • nerdyminer18/srb-2
  • 256nil/SRB2
  • ARJr/SRB2
  • Alam/SRB2
  • Zenya/srb-2-marathon-demos
  • Acelite/srb-2-archivedmodifications
  • MIDIMan/SRB2
  • Lach/SRB2
  • Frostiikin/bounce-tweaks
  • Jaden/SRB2
  • Tyron/SRB2
  • Astronight/SRB2
  • Mari0shi06/SRB2
  • aiire/SRB2
  • Galactice/SRB2
  • srb2-ports/srb2-dreamcast
  • sdasdas/SRB2
  • chreas/srb-2-vr
  • StarManiaKG/the-story-of-sinically-rocketing-and-botching-the-2nd
  • LoganAir/SRB2
  • NepDisk/srb-2
  • alufolie91/SRB2
  • Felicia.iso/SRB2
  • twi/SRB2
  • BarrelsOFun/SRB2
  • Speed2411/SRB2
  • Leather_Realms/SRB2
  • Ayemar/SRB2
  • Acelite/SRB2
  • VladDoc/SRB2
  • kaldrum/model-features
  • strawberryfox417/SRB2
  • Lugent/SRB2
  • Jisk/SRB2
  • Rem/SRB2
  • Refrag/SRB2
  • Henry_3230/srb-3230
  • TehPuertoRicanSpartan2/tprs-srb2
  • Leminn/srb-2-marathon-stuff
  • chromaticpipe2/SRB2
  • MiguelGustavo15/SRB2
  • Maru/srb-2-tests
  • SilicDev/SRB2
  • UnmatchedBracket/SRB2
  • HybridDog/SRB2
  • xordspar0/SRB2
  • jsjhbewfhh/SRB2
  • Fancy2209/SRB2
  • Lorsoen/SRB2
  • shindoukin/SRB2
  • GamerOfDays/SRB2
  • Craftyawesome/SRB2
  • tenshi-tensai-tennoji/SRB2
  • Scarfdudebalder/SRB2
  • luigi-budd/srb-2-fix-interplag-lockon
  • mskluesner/SRB2
  • johnpetersa19/SRB2
  • Pheazant/SRB2
  • chromaticpipe2/srb2classic
  • romoney5/SRB2
  • PAS/SRB2Classic
  • BlueStaggo/SRB2
117 results
Select Git revision
Show changes
Commits on Source (4)
#!/bin/bash -e
#!/usr/local/bin/bash -e
path="."
if [ x"$1" != x ]; then
path="$1"
......
......@@ -36,11 +36,15 @@ extern UINT8 keyboard_started;
/** \brief The I_GetFreeMem function
\param total total memory in the system
\return total memory in the system (in bytes)
*/
size_t I_GetTotalMem(void);
/** \brief The I_GetFreeMem function
\return free memory in the system
\return free memory in the system (in bytes)
*/
UINT32 I_GetFreeMem(UINT32 *total);
size_t I_GetFreeMem(void);
/** \brief Called by D_SRB2Loop, returns current time in tics.
*/
......
......@@ -45,6 +45,7 @@ set(SRB2_SDL2_SOURCES
ogl_sdl.c
${SRB2_SDL2_SOUNDIMPL}
memstats.c
)
set(SRB2_SDL2_HEADERS
......
......@@ -51,9 +51,9 @@ endif
#
ifdef FREEBSD
OPTS+=-DLINUX -DFREEBSD -I/usr/X11R6/include
SDL_CONFIG?=sdl11-config
SDL_CONFIG?=sdl2-config
LDFLAGS+=-L/usr/X11R6/lib
LIBS+=-lipx -lkvm
LIBS+=-lkvm
endif
#
......
......@@ -118,6 +118,8 @@ endif
endif
endif
OBJS+=$(OBJDIR)/memstats.o
CFLAGS+=$(SDL_CFLAGS)
LIBS:=$(SDL_LDFLAGS) $(LIBS)
ifdef STATIC
......
......@@ -84,8 +84,6 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T);
#else
#include <sys/param.h>
#include <sys/mount.h>
/*For meminfo*/
#include <sys/types.h>
#ifdef FREEBSD
#include <kvm.h>
#endif
......@@ -199,6 +197,8 @@ static char returnWadPath[256];
#include "../byteptr.h"
#endif
#include "memstats.h"
/** \brief The JoyReset function
\param JoySet Joystick info to reset
......@@ -2940,156 +2940,14 @@ const char *I_LocateWad(void)
return waddir;
}
#ifdef __linux__
#define MEMINFO_FILE "/proc/meminfo"
#define MEMTOTAL "MemTotal:"
#define MEMAVAILABLE "MemAvailable:"
#define MEMFREE "MemFree:"
#define CACHED "Cached:"
#define BUFFERS "Buffers:"
#define SHMEM "Shmem:"
/* Parse the contents of /proc/meminfo (in buf), return value of "name"
* (example: MemTotal) */
static long get_entry(const char* name, const char* buf)
size_t I_GetTotalMem(void)
{
long val;
char* hit = strstr(buf, name);
if (hit == NULL) {
return -1;
}
errno = 0;
val = strtol(hit + strlen(name), NULL, 10);
if (errno != 0) {
CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno));
return -1;
}
return val;
return GetTotalSysMem();
}
#endif
// quick fix for compil
UINT32 I_GetFreeMem(UINT32 *total)
size_t I_GetFreeMem(void)
{
#ifdef FREEBSD
struct vmmeter sum;
kvm_t *kd;
struct nlist namelist[] =
{
#define X_SUM 0
{"_cnt"},
{NULL}
};
if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open")) == NULL)
{
if (total)
*total = 0L;
return 0;
}
if (kvm_nlist(kd, namelist) != 0)
{
kvm_close (kd);
if (total)
*total = 0L;
return 0;
}
if (kvm_read(kd, namelist[X_SUM].n_value, &sum,
sizeof (sum)) != sizeof (sum))
{
kvm_close(kd);
if (total)
*total = 0L;
return 0;
}
kvm_close(kd);
if (total)
*total = sum.v_page_count * sum.v_page_size;
return sum.v_free_count * sum.v_page_size;
#elif defined (SOLARIS)
/* Just guess */
if (total)
*total = 32 << 20;
return 32 << 20;
#elif defined (_WIN32)
MEMORYSTATUS info;
info.dwLength = sizeof (MEMORYSTATUS);
GlobalMemoryStatus( &info );
if (total)
*total = (UINT32)info.dwTotalPhys;
return (UINT32)info.dwAvailPhys;
#elif defined (__linux__)
/* Linux */
char buf[1024];
char *memTag;
UINT32 freeKBytes;
UINT32 totalKBytes;
INT32 n;
INT32 meminfo_fd = -1;
long Cached;
long MemFree;
long Buffers;
long Shmem;
long MemAvailable = -1;
meminfo_fd = open(MEMINFO_FILE, O_RDONLY);
n = read(meminfo_fd, buf, 1023);
close(meminfo_fd);
if (n < 0)
{
// Error
if (total)
*total = 0L;
return 0;
}
buf[n] = '\0';
if ((memTag = strstr(buf, MEMTOTAL)) == NULL)
{
// Error
if (total)
*total = 0L;
return 0;
}
memTag += sizeof (MEMTOTAL);
totalKBytes = atoi(memTag);
if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL)
{
Cached = get_entry(CACHED, buf);
MemFree = get_entry(MEMFREE, buf);
Buffers = get_entry(BUFFERS, buf);
Shmem = get_entry(SHMEM, buf);
MemAvailable = Cached + MemFree + Buffers - Shmem;
if (MemAvailable == -1)
{
// Error
if (total)
*total = 0L;
return 0;
}
freeKBytes = MemAvailable;
}
else
{
memTag += sizeof (MEMAVAILABLE);
freeKBytes = atoi(memTag);
}
if (total)
*total = totalKBytes << 10;
return freeKBytes << 10;
#else
// Guess 48 MB.
if (total)
*total = 48<<20;
return 48<<20;
#endif
return GetFreeSysMem();
}
const CPUInfoFlags *I_CPUInfo(void)
......
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2014-2020 by Sonic Team Junior
// Copyright (C) 2020 by Victor "SteelT" Fuentes
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file memstats.c
/// \brief Functions to get system memory information.
#include <stdio.h>
#ifndef errno
#include <errno.h>
#endif
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef __linux__
#include <sys/types.h>
#define MEMINFO_FILE "/proc/meminfo"
#endif
#include "memstats.h"
#ifdef __linux__
ssize_t numread;
int meminfo_fd = -1;
long Cached;
long MemFree;
long Buffers;
long Shmem;
long MemAvailable = -1;
char procbuf[1024];
/* Parse the contents of /proc/meminfo (in buf), return value of "name"
* (example: MemTotal) */
static long linux_get_entry(const char* name, const char* buf)
{
char *memTag;
size_t totalKBytes;
long val;
char* hit = strstr(buf, name);
if (hit == NULL) {
return -1;
}
errno = 0;
val = strtol(hit + strlen(name), NULL, 10);
if (errno != 0) {
CONS_Debug(DBG_MEMORY, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno));
return -1;
}
return val;
}
static size_t linux_get_totalmem(void)
{
size_t totalKB;
char *memTag;
#define MEMTOTAL "MemTotal:"
meminfo_fd = open(MEMINFO_FILE, O_RDONLY);
numread = read(meminfo_fd, buf, 1023);
close(meminfo_fd);
if (numread < 0)
{
// Error
return 0;
}
procbuf[numread] = '\0';
if ((memTag = strstr(buf, MEMTOTAL)) == NULL)
{
// Error
return 0;
}
memTag += sizeof (MEMTOTAL);
totalKB = atoi(memTag);
return totalKB << 10;
}
static size_t linux_get_freemem(void)
{
char *memTag;
long Cached;
long MemFree;
long Buffers;
long Shmem;
long MemAvailable = -1;
size_t freeKB;
#define MEMAVAILABLE "MemAvailable:"
#define MEMFREE "MemFree:"
#define CACHED "Cached:"
#define BUFFERS "Buffers:"
#define SHMEM "Shmem:"
meminfo_fd = open(MEMINFO_FILE, O_RDONLY);
numread = read(meminfo_fd, buf, 1023);
close(meminfo_fd);
if (numread < 0)
{
// Error
return 0;
}
procbuf[numread] = '\0';
/* Kernel is too old to support MEMAVAILABLE
so get values using old calculation
*/
if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL)
{
Cached = get_entry(CACHED, buf);
MemFree = get_entry(MEMFREE, buf);
Buffers = get_entry(BUFFERS, buf);
Shmem = get_entry(SHMEM, buf);
MemAvailable = Cached + MemFree + Buffers - Shmem;
if (MemAvailable == -1)
{
// Error
return 0;
}
freeKB = MemAvailable;
}
else
{
memTag += sizeof(MEMAVAILABLE);
freeKB = atoi(memTag);
}
return freeKB << 10;
}
#endif
#ifdef _WIN32
static size_t win_get_totalmem(void)
{
MEMORYSTATUS info;
info.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&info);
return info.dwTotalPhys;
}
static size_t win_get_freemem(void)
{
MEMORYSTATUS info;
info.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus(&info);
return info.dwAvailPhys;;
}
#endif
size_t GetTotalSysMem(void)
{
#ifdef __linux__
return linux_get_totalmem();
#endif
#ifdef _WIN32
return win_get_totalmem();
#endif
/* Guess 48 MB. */
return 48<<20;
}
size_t GetFreeSysMem(void)
{
#ifdef __linux__
return linux_get_freemem();
#endif
#ifdef _WIN32
return win_get_freemem();
#endif
/* Guess 48 MB. */
return 48<<20;
}
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 2014-2020 by Sonic Team Junior
// Copyright (C) 2020 by Victor "SteelT" Fuentes
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file memstats.h
/// \brief Functions to get system memory information.
#ifndef __MEMSTATS_H__
#define __MEMSTATS_H__
size_t GetTotalSysMem(void);
size_t GetFreeSysMem(void);
#endif
......@@ -29,7 +29,7 @@
#include "doomstat.h"
#include "r_patch.h"
#include "r_picformats.h"
#include "i_system.h" // I_GetFreeMem
#include "i_system.h" // I_GetFreeMem, I_GetTotalMem
#include "i_video.h" // rendermode
#include "z_zone.h"
#include "m_misc.h" // M_Memcpy
......@@ -106,14 +106,16 @@ static void Command_Memdump_f(void);
*/
void Z_Init(void)
{
UINT32 total, memfree;
size_t memtotal, memfree;
memset(&head, 0x00, sizeof(head));
head.next = head.prev = &head;
memfree = I_GetFreeMem(&total)>>20;
CONS_Printf("System memory: %uMB - Free: %uMB\n", total>>20, memfree);
memtotal = I_GetTotalMem();
memfree = I_GetFreeMem();
CONS_Printf("System memory: %sMB - Free: %sMB\n", sizeu1(memtotal>>20), sizeu2(memfree>>20));
// Note: This allocates memory. Watch out.
COM_AddCommand("memfree", Command_Memfree_f);
......@@ -791,7 +793,7 @@ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag)
*/
static void Command_Memfree_f(void)
{
UINT32 freebytes, totalbytes;
size_t freebytes, totalbytes;
Z_CheckHeap(-1);
CONS_Printf("\x82%s", M_GetText("Memory Info\n"));
......@@ -823,9 +825,10 @@ static void Command_Memfree_f(void)
#endif
CONS_Printf("\x82%s", M_GetText("System Memory Info\n"));
freebytes = I_GetFreeMem(&totalbytes);
CONS_Printf(M_GetText(" Total physical memory: %7u KB\n"), totalbytes>>10);
CONS_Printf(M_GetText("Available physical memory: %7u KB\n"), freebytes>>10);
totalbytes = I_GetTotalMem();
freebytes = I_GetFreeMem();
CONS_Printf(M_GetText(" Total physical memory: %7s KB\n"), sizeu1(totalbytes>>10));
CONS_Printf(M_GetText("Available physical memory: %7s KB\n"), sizeu2(freebytes>>10));
}
#ifdef ZDEBUG
......