Misol and Cari had a lovechild!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Misol and Cari had a lovechild!

#16 Post by aGerman » 03 May 2017 14:37

misol101 wrote:Do you have any antivirus software running?

Yes. Although switching off Avira didn't make any difference.

misol101 wrote:Could you try one more thing?

I did. Only without cmdgfx "" knW9 it runs smoothly.

Don't worry. I'm virtually certain my slow "couch toy" netbook is the culprit. It's good enough for doing some home office, a little programming, internet surfing, ... But it's definitely not a gaming computer (what I'm not even intersted in :wink: ). It's most likely a bad device for running such programs.

Steffen

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Misol and Cari had a lovechild!

#17 Post by ShadowThief » 03 May 2017 16:00

I don't think that's it; my i5-6600K and NVIDIA GTX 980 should have no problem rendering the images.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Misol and Cari had a lovechild!

#18 Post by misol101 » 04 May 2017 04:59

ShadowThief wrote:I don't think that's it; my i5-6600K and NVIDIA GTX 980 should have no problem rendering the images.


Agreed. Actually, what these tests show is that the major culprit here is the startup time of the executable file. It's not the timing calculations or the rendering that's the problem but the startup time overhead of running the executable at all. It seems that after Win 7, this startup cost is much higher.

The only thing this line (cmdgfx "" knW9) actually does is 1) Check for key presses 2) Make sure that the maximum screen refresh rate is 1000/9=111 FPS. The rendering is all done elsewhere. But what happens is that just starting the exe takes much more than 9 ms to begin with.

So atleast it has been shown that removing this line, you can get a smooth result also on Win10, when running with the server. The problem is I can no longer check for key presses and there is no control over the refresh rate (so on fast machines it might run too fast)

Possible solutions:
1. Find a way to decrease the startup cost of the executable. Not sure how, different compiler perhaps...? Or write a separate exe that does only the two things needed (would probably still be faster if written in assembler, see (2) )
2. Use Aacinis GetKey program to get the key presses. This has considerably lower startup cost than my exe, due to no linked libraries and less overhead because it's written in assembler. It's still not as fast as running without that line, but it is an improvement at least. Problem is though, that then I still cannot control the refresh rate accurately. (Aacini, can you please write a program which does both? :mrgreen: ). I *might* be able to wing it myself, but it's been many years since I touched assembler.
3. Remove the line, and let the server do both the key reading and the time synch. This has various problems: the server needs to communicate the key read back to the script. Currently it can be done by writing to a file, but in the worst case key presses may be lost. Also, I found that with a SSD drive, writing a file every frame is pretty slow itself. But anyway, perhaps with enough tinkering, this will be the best solution, especially in this kind of program where reading keys is not important or vital

I'll get started on an entirely server-based version of this demo... this will probably add further problems, but let's see :)

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Misol and Cari had a lovechild!

#19 Post by misol101 » 05 May 2017 17:54

Hi, I need your help with some testing again :)

After some tests I could conclude that GetKey was actually only marginally faster than cmdgfx for startup cost (but cmdgfx_gdi was slower, due to linking with the GDI library). So basically my approach 1 and 2 were out the window.

I haven't touched the demo yet, but I made a new server.bat and modified cmdgfx_gdi.exe. The server is now supposed to do both key reading and timing. See attached file!

I'd be happy if you could put these two files in the same folder as before and run server.bat, again for approximately 10 seconds, then note the number in the bottom. (and of course, note if it seems to run smoothly). You could also try decreasing the W value on line 5 to e.g. 0 and see what value you get for 10 seconds.

Keys are ENTER, Space, p, f, m, Escape.

Thanks a lot!
Attachments
newserver.zip
New server bat/cmdgfx_gdi. Put in same folder
(89.38 KiB) Downloaded 378 times

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Misol and Cari had a lovechild!

#20 Post by Aacini » 05 May 2017 18:03

misol101 wrote:
. . .

Possible solutions:
1. Find a way to decrease the startup cost of the executable. Not sure how, different compiler perhaps...? Or write a separate exe that does only the two things needed (would probably still be faster if written in assembler, see (2) )
2. Use Aacinis GetKey program to get the key presses. This has considerably lower startup cost than my exe, due to no linked libraries and less overhead because it's written in assembler. It's still not as fast as running without that line, but it is an improvement at least. Problem is though, that then I still cannot control the refresh rate accurately. (Aacini, can you please write a program which does both? :mrgreen: ). I *might* be able to wing it myself, but it's been many years since I touched assembler.

. . .


I willingly could do that. :D However, if you want a faster response from me, you should post the C++ code you want I translate into assembler. I am currently very busy, so I can't do any research, but a direct C to assembler translation is something much simpler...

Antonio

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Misol and Cari had a lovechild!

#21 Post by misol101 » 05 May 2017 18:16

Aacini wrote:I willingly could do that. :D However, if you want a faster response from me, you should post the C++ code you want I translate into assembler. I am currently very busy, so I can't do any research, but a direct C to assembler translation is something much simpler...

Ok, cool! I just posted an update a few minutes before you (strange that we posted almost simultaneously), which basically says that I chose my option 3 for now, so there is less of a need for this utility than I previously thought. Still it would be nice to have, so if you have the time, here's the C code for that tool (GetTickCount does not give the needed precision for timing at the ms level, that's why QueryPerformanceCounter is used if available):

EDIT: I think the program could be sped up if there was no writing to file, but I do need to save milliseconds_now between runs. The registry perhaps is faster? Or is there another way?

EDIT2: Would it be possible to make the executable a COM rather than an EXE? From what I remember COM files have less startup cost than EXE's, and startup cost is the main problem here it seems.

EDIT2.2 It seems it's not possible to make 32 bit COM files. My hopes were up because windows\System32 actually contains a few com files (e.g. mode.com), but apparently they are just renamed exe files called .com for legacy reasons


Code: Select all

#include <stdio.h>
#include <conio.h>
#include <windows.h>

long long milliseconds_now(void) {
   static LARGE_INTEGER s_frequency;
   static BOOL s_use_qpc;

   s_use_qpc = QueryPerformanceFrequency(&s_frequency);
   if (s_use_qpc) {
      LARGE_INTEGER now;
      QueryPerformanceCounter(&now);
      return (1000LL * now.QuadPart) / s_frequency.QuadPart;
   } else {
      return GetTickCount();
   }
}

void process_waiting(int waitTime) {

   if (waitTime > 0) {
      long long sT;
      
      FILE *fp = fopen("CGXMS.dat", "r");

      if (fp != NULL) {
         fscanf(fp, "%lld", &sT);
         fclose(fp);
         if (milliseconds_now() >= sT)
            while (milliseconds_now() < sT + waitTime) ;
      }
      
      fp = fopen("CGXMS.dat", "w");
      if (fp != NULL) {
         fprintf(fp, "%lld", milliseconds_now());
         fclose(fp);
      }
   }
}

int main(int argc, char *argv[]) {
   int waitTime = 0, retVal = 0;
      
   if (argc > 1) {
      waitTime = atoi(argv[1]);
   }
   
   if (kbhit()) {
      int k = getch();
      if (k == 224 || k == 0) k = 256 + getch();
      retVal = k;
   }

   process_waiting(waitTime);
   
   return retVal;
}
Last edited by misol101 on 07 May 2017 01:29, edited 6 times in total.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Misol and Cari had a lovechild!

#22 Post by misol101 » 05 May 2017 18:18

Just a little note to (primarily) ShadowThief and aGerman: don't miss my new post 3 posts above this one about new tests for Win10 (if you have the time to help out) :mrgreen:

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Misol and Cari had a lovechild!

#23 Post by aGerman » 06 May 2017 06:11

misol101 wrote:I'd be happy if you could put these two files in the same folder as before and run server.bat, again for approximately 10 seconds, then note the number in the bottom. (and of course, note if it seems to run smoothly). You could also try decreasing the W value on line 5 to e.g. 0 and see what value you get for 10 seconds.

It's ~500 (looks smooth as expected). Changing to W0 doesn't make any difference though.

Steffen

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Misol and Cari had a lovechild!

#24 Post by misol101 » 06 May 2017 08:26

aGerman wrote:It's ~500 (looks smooth as expected). Changing to W0 doesn't make any difference though.


Ok, thanks! Not quite as much of a change as I would have hoped, but still a clear improvement.

I'm expecting (hoping) that ShadowThief with his faster computer will get at least 800 or more.

(I get around 800 with W13 and around 2000 with W0)
Last edited by misol101 on 08 May 2017 03:17, edited 1 time in total.

ShadowThief
Expert
Posts: 1160
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Misol and Cari had a lovechild!

#25 Post by ShadowThief » 06 May 2017 08:59

I'm seeing just shy of 800 with W13 and just over 2700 with W0

But yeah, everything looks awesome

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Misol and Cari had a lovechild!

#26 Post by misol101 » 06 May 2017 10:44

Excellent!

So the kaleidoscope effect is sorted then.

For some of the other effects (the ones using the cmdgfx "block" operation with math expressions), I get significantly lower FPS when running with a server. It's confusing.

I'm putting my hope in Aacini to sort that out with a quick little executable ;)

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Misol and Cari had a lovechild!

#27 Post by einstein1969 » 08 May 2017 08:43

hi misol101,

the server version its very good. On my old celeron i get 50 FPS (the demo version get 15 FPS). Awesome work!


Einstein1969

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Misol and Cari had a lovechild!

#28 Post by misol101 » 08 May 2017 09:45

Hi einstein1969,
thanks! Which Windows version are you running?

It's a good thing I found out about this Windows10 debacle when releasing this. On my Win7 machine all my cmdgfx graphic scripts run at 70+ FPS. Little did I know that most people running those scripts (I guess most ppl nowadays run Win8 or Win10) were getting horrible frame rates :) The server solution takes care of some of those issues at least

einstein1969
Expert
Posts: 941
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Misol and Cari had a lovechild!

#29 Post by einstein1969 » 08 May 2017 11:03

I'm running Windows 7 32bit on 2Ghz Celeron

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Misol and Cari had a lovechild!

#30 Post by misol101 » 08 May 2017 11:10

Really... haha. Hmmm... Well, there goes my Win7 theory. My machine must be some kind of fluke.

Well, server it is, then :)

Post Reply