BEpingboost.c

From FrâG^.WIKI

Jump to: navigation, search
Error creating thumbnail: convert: unable to open image `/mnt/data/www/wiki.fragaholics.de/htdocs/images/7/78/Server.png': @ error/blob.c/OpenBlob/2498.
convert: unable to open file `/mnt/data/www/wiki.fragaholics.de/htdocs/images/7/78/Server.png' @ error/png.c/ReadPNGImage/3072.
convert: missing an image filename `/mnt/data/www/wiki.fragaholics.de/htdocs/images/thumb/7/78/Server.png/100px-Server.png' @ error/convert.c/ConvertImageCommand/2970.
Error creating thumbnail: convert: unable to open image `/mnt/data/www/wiki.fragaholics.de/htdocs/images/7/78/Server.png': @ error/blob.c/OpenBlob/2498.
convert: unable to open file `/mnt/data/www/wiki.fragaholics.de/htdocs/images/7/78/Server.png' @ error/png.c/ReadPNGImage/3072.
convert: missing an image filename `/mnt/data/www/wiki.fragaholics.de/htdocs/images/thumb/7/78/Server.png/100px-Server.png' @ error/convert.c/ConvertImageCommand/2970.
This article is related to game servers.

The following C code is a small 'hack' to break the intrinsic limit to 1000 fps for srcds-based servers. Some notes how to compile and use it are written in the head comment. For using it inside a screen session, see below. It has been tested with CS:S and DOD:S. It will not work with hlds-based servers, because their game play will run faster if they run at more than 1000 fps.

Please note: This code is provided for testing purposes only. There is no good reason to run a game server with more than 1000 fps. The quality will not increase, it might even decrease. Feel free to do anything what you like with it (unless it violates GPL), but you have been warned.

You can download the compiled library here: http://pool.beta-centauri.de/libBEpingboost.so.1.0.1

BEpingboost.c

/******************************************************************************************************************/
/*                                                                                                                */
/*  BEpingboost.c - Allow fps > 1000 for CS:S                                                                     */
/*                                                                                                                */
/*  Copyright (c) BehaartesEtwas at fragaholics.de 2008-2009                                                      */
/*                                                                                                                */
/*  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/>.                                         */
/*                                                                                                                */
/******************************************************************************************************************/
/*                                                                                                                */
/*  Last Change:                                                                                                  */
#define VERSION "2009-12-22/1"
/*                                                                                                                */
/*  Compile with:                                                                                                 */
/*   gcc -m32 -c -fPIC BEpingboost.c -o BEpingboost.o                                                             */
/*   gcc -m32 -shared -Wl,-soname,libBEpingboost.so.1 -lrt -lm -o libBEpingboost.so.1.0.1 BEpingboost.o           */
/*                                                                                                                */
/*  Run your server with:                                                                                         */
/*   LD_PRELOAD=/path/to/libBEpingboost.so.1.0.1 FPS=4000 ./srcds_run +fps_max 0 <your-options-here>              */
/*                                                                                                                */
/******************************************************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <errno.h>
#include <signal.h>
#include <math.h>

static int init = 0;
static struct timespec reg;
static int nframes = 0;

void usleep(unsigned long usec) {
//
// Catch other usleeps
//
  if(usec == 0) return;
  if(usec != 1000) {
    struct timespec reg, rem;
    reg.tv_sec  = 0;
    reg.tv_nsec = 1000*usec;
    while(!nanosleep(&reg,&rem) && errno == EINTR) {
      reg.tv_sec = 0;
      reg.tv_nsec = rem.tv_nsec-1000;
    }
    return;
  }
//
// This is the fps relevant case
//
  if(!init) {
    nframes++;
    if(nframes < 2000) {
      reg.tv_sec  = 0;
      reg.tv_nsec = 1000000;
      nanosleep(&reg,NULL);
      return;
    }
    nframes = 0;
    init = 1;
//
    int nfps;
    char *envvar;
    envvar = getenv("FPS");
    if(envvar) {
      nfps = atoi(envvar);
    }
    else {
      nfps = 2000;
    }
//
    reg.tv_sec  = 0;
    reg.tv_nsec = 1000000000 / nfps;
//
    printf("**********************************************************************\n");
    printf(" BEpingboost Copyright (C) 2009 BehaartesEtwas at fragaholics.de\n");
    printf(" This program comes with ABSOLUTELY NO WARRANTY.\n");
    printf(" This is free software, and you are welcome to redistribute it\n");
    printf(" under certain conditions.\n");
    printf(" Released under GPLv3 license.\n");
    printf("\n");
    printf(" Version: %s\n",VERSION);
    printf(" Initialized with %d fps nominal\n",nfps);
    printf("**********************************************************************\n");
  }
//
// Do the sleep
//
  nanosleep(&reg,NULL);
}

LD_PRELOAD with screen

The most of you like me are running hl2 servers in a detached screentab by starting it like screen -S name ./srcds_run gameparameters Using this startcommand with LD_PRELOAD does not work. What works is to start a script that includes the LD_PRELOAD and works as a relay for the scrds_run startparamters. Here is a script that does this. Add it to the folder where your srcds_run is. And run it instead of the scrds_run:

#!/bin/bash 
#clear
# LD_PRELOAD Script
# to get LD_PRELOAD working with sceen 
# by Terrorkarotte 

LD_PRELOAD=/path/to/libBEpingboost.so.1.0.1 FPS=4000 ./srcds_run $@ 

Enter the folder of the srcds_run and create a new file srcds_tk

nano srcds_tk

paste the code into the editor close it and change the chmod of the file:

chmod +x srcds_tk

Now change srcds_run to srcds_tk in your startscripts and have fun!

Personal tools