Author Topic: Patch for FPS Limit for Megaglest 3.5.2  (Read 930 times)

SnEptUne

  • Swordman
  • *
  • Posts: 17
    • View Profile
Patch for FPS Limit for Megaglest 3.5.2
« on: 5 September 2011, 16:01:47 »
Hi people,

Here's the patch for limiting megaglest's FPS, since it would otherwise burn up my CPU.

Since I don't know how to attach file, I will just paste the content of the patch:
Code: [Select]
--- ./source/glest_game/main/main.cpp.orig      2011-09-05 11:52:33.232676996 -0400
+++ ./source/glest_game/main/main.cpp   2011-07-16 13:47:35.716676997 -0400
@@ -2999,8 +2999,16 @@

                //time_t lastTextureLoadEvent = time(NULL);
                //main loop
+               int interval = 1;
                while(Window::handleEvent()) {
                        program->loop();
+                       if (program->getFPS() > 1) {
+                               if (interval == 1) interval = (1000000.00 / ((double) program->getFPS()));
+                               usleep(interval);
+                       }
+                       else if (program->getFPS() == 0) {
+                               usleep(30000);
+                       }
                        // Because OpenGL really doesn't do multi-threading well
 //                     if(difftime(time(NULL),lastTextureLoadEvent) >= 3) {
 //                             lastTextureLoadEvent = time(NULL);
--- ./source/glest_game/main/program.cpp.orig   2011-09-05 11:52:43.845676996 -0400
+++ ./source/glest_game/main/program.cpp        2011-07-16 10:34:26.323676997 -0400
@@ -575,13 +575,17 @@
        if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
 }

+int Program::getFPS(){
+       return freq;
+}
+
 void Program::setDisplaySettings(){

        Config &config= Config::getInstance();

-       if(!config.getBool("Windowed")) {
+       freq = config.getInt("RefreshFrequency");

-               int freq= config.getInt("RefreshFrequency");
+       if(!config.getBool("Windowed")) {
                int colorBits= config.getInt("ColorBits");
                int screenWidth= config.getInt("ScreenWidth");
                int screenHeight= config.getInt("ScreenHeight");
--- ./source/glest_game/main/program.h.orig     2011-09-05 11:52:50.115676996 -0400
+++ ./source/glest_game/main/program.h  2011-07-16 08:50:46.762676996 -0400
@@ -139,6 +139,7 @@

     GraphicMessageBox msgBox;
     int skipRenderFrameCount;
+    int freq;

 public:
     Program();
@@ -151,6 +152,7 @@
        void initServer(WindowGl *window,bool autostart=false,bool openNetworkSlots=false);
        void initClient(WindowGl *window, const Ip &serverIp);
        void initScenario(WindowGl *window, string autoloadScenarioName);
+       int getFPS();

        //main
     void keyDown(char key);


uncle

  • Guest
Re: Patch for FPS Limit for Megaglest 3.5.2
« Reply #1 on: 5 September 2011, 16:55:31 »
How can install it? Where should I paste this code?

tomreyn

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 2,764
    • View Profile
    • MegaGlest - the free and open source cross platform 3D real-time strategy game
Re: Patch for FPS Limit for Megaglest 3.5.2
« Reply #2 on: 5 September 2011, 17:13:40 »
This is a 'patch' or 'unified diff', produced by the GNU diff application. It requires a source code tree and the GNU patch application, followed by recompiling, to apply it.

Unless this tells you much, your best bet is to wait what softcoder and titi think about it and whether they consider the purpose of the patch and its quality sufficient for adding it to MegaGlest. If they do, it may be included in future MegaGlest builds starting with the next stable (and possibly development/alpha/beta) release.
atibox: Ryzen 1800X (8 cores @3.6GHz), 32 GB RAM, MSI Radeon RX 580 Gaming X 8G, PCI subsystem ID [1462:3417], (Radeon RX 580 chipset, POLARIS10) @3440x1440; latest stable Ubuntu release, (open source) radeon (amdgpu) / mesa video driver
atibox (old): Core2Quad Q9400 (4 cores @2.66GHz), 8 GB RAM, XFX HD-467X-DDF2, PCI subsystem ID [1682:2931], (Radeon HD 4670, RV730 XT) @1680x1050; latest stable Ubuntu release, (open source) radeon / mesa video driver
notebook: HP envy13d020ng
internet access: VDSL2+

· · · How YOU can contribute to MG · Latest development snapshot · How to build yourself · Megapack techtree · Currently hosted MG games · · ·

will

  • Golem
  • ******
  • Posts: 783
    • View Profile
Re: Patch for FPS Limit for Megaglest 3.5.2
« Reply #3 on: 5 September 2011, 18:06:09 »
Here's the patch for limiting megaglest's FPS, since it would otherwise burn up my CPU.

I'm trying to understand the problem this is solving;  something like your patch may indeed be useful to you.

What spec CPU and GPU do you have?

What OS do you use?

What FPS do you currently have?  (You can show this in-game using the ? key)

roflcopter

  • Guest
Re: Patch for FPS Limit for Megaglest 3.5.2
« Reply #4 on: 5 September 2011, 20:56:33 »
I'm trying to understand the problem this is solving;  something like your patch may indeed be useful to you.

What spec CPU and GPU do you have?

What OS do you use?

What FPS do you currently have?  (You can show this in-game using the ? key)
Indeed, I thought the FPS was amply self-limiting.