HeartBeat-Delay()-Wait()-Sleep()-Demos
Posted: 07 Mar 2016 09:49
Hi to all,
This thread is a for DEMOS of my HearBeat engine that emulate the WAIT()/DELAY()/SLEEP() functions whit no use of CPU (passive wait). With this code is possible control the CPU usage and the time.
It is possible create a more complex application/game.
HeartBeat_simple.cmd:
DEMO
This code is only a VERY simple demo with 16-18FPS that use ONLY 10-20% CPU on monocore.
This use the HeartBeat core version 0.1
EDIT: I have achieved about 25FPS with 25%CPU usage changing the line
to
Einstein1969
This thread is a for DEMOS of my HearBeat engine that emulate the WAIT()/DELAY()/SLEEP() functions whit no use of CPU (passive wait). With this code is possible control the CPU usage and the time.
It is possible create a more complex application/game.
HeartBeat_simple.cmd:
Code: Select all
:::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: Heartbeat 0.2 By Einstein1969
::
:: Tested on Windows 7 32bit monocore @2Ghz
::
:: ver. 0.2 2016-03-11
:: - Add fast start.
:: - Add second set/P for bypass the problem of set/P that split
:: the input line of PING | FIND in 2 parts.
:: TODO: detect split of set/P and use the appropriate code.
::
:: ver. 0.1 2014-july
:: - Initial version
@echo off
setlocal EnableDelayedExpansion
rem Multithread dispatcher
if not "%1"=="" goto :%1
rem choose a HB parameter %1 to sature/stabilize the beat.
rem choice a HB parameter %2 to distribuite the beat at fast start.
rem choose the RICEVER parameter for achieve the minimum delay. Es. 20 is 20cs is 5FPS.
rem Use this for using HIGH priority processing and achieve more precision.
rem START "HB" /B /HIGH cmd /c "%~f0" HB 28 10 | find "TTL" | START "RICEVER" /B /HIGH cmd /c "%~f0" RICEVER 20
rem Example for 3 centisecond about 32FPS
"%~f0" HB 32 10 | find "TTL" | "%~f0" RICEVER 3
pause>nul
exit /b
:HB
for /L %%N in (0,1,%2) do (
pathping -n -q 1 -p %3 127.0.0.1 >nul
start "HBPING" /B ping -n %2 127.0.0.1
)
for /L %%N in (0) do (
ping -n 2 127.0.0.1 >nul
start "HBPING" /B ping -n %2 127.0.0.1
)
exit /b
:RICEVER
for /L %%N in (0) do (
set/p =
set/p =
set /a "t=1!time:~6,2!!time:~9,2!-10000, dt=t-(oldt+0), dt+=(dt>>31)&6000" >NUL
if !dt! geq %2 (
rem do work
set/p ".=!dt! "<nul
set /a oldt=t >NUL
)
)
exit/b
DEMO
This code is only a VERY simple demo with 16-18FPS that use ONLY 10-20% CPU on monocore.
This use the HeartBeat core version 0.1
Code: Select all
@echo off
setlocal EnableDelayedExpansion
if not "%1"=="" goto :%1
mode 64,60
"%~f0" HB 60 1010 | find "128" | "%~f0" MAIN 5
pause>nul
exit /b
:HB
for /L %%N in (0) do (
rem pathping -n -q 1 -p %3 127.0.0.1 >nul
ping -n 2 127.0.0.1 >nul
start "HBPING" /B ping -n %2 127.0.0.1
)
exit /b
:MAIN
set /a cols=62, lines=49
set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
set "SIN(x)=(a=(x)%%62832, c=(a>>31|1)*a, t=((c-47125)>>31)+1, a-=t*((a>>31|1)*62832) + ^^^!t*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), %_SIN%)"
set "_SIN="
For /L %%l in (1,1,%cols%) do set "_empty=!_empty! "
set "g=.@"
set /a R=20, Angle=0, _dx=cols/2, _dy=lines/2, _1=10000
for /L %%n in (0) do (
set/p "_HB="
set /a "t1=1!time:~6,2!!time:~9,2!-10000, dt=t1-oldt, dt+=(dt>>31)&6000" >NUL
if !dt! geq %2 (
cls
For /L %%l in (5,1,%lines%) do echo( !L%%l!
if !random:~-1! equ 0 For /L %%l in (5,1,%lines%) do set "L%%l="
set /A "s1=%SIN(x):x=Angle%, c1=%SIN(x):x=15708-Angle%, Angle-=5*31416/180"
For /L %%P in (0,4,!R!) do (
set /A "a=(R-%%P)*s1/_1+%_dx%, b=(R-%%P)*c1/_1+5+%_dy%"
if not defined L!b! set "L!b!=%_empty%"
For /F "tokens=1-3" %%x in ("!a! !b! 1") do (
set "c=!L%%y:~%%x!"
set "L%%y=!L%%y:~0,%%x!!g:~%%z,1!!c:~1!"
)
)
set/p ".=!dt! "<nul
%= Frame counter =%
Set /A F+=1
%= Calculate FPS every 4 seconds=%
if !F! geq !\! call :calc_FPS
set /a oldt=t1 >NUL
)
)
exit/b
:Calc_FPS
set /a "dT1=1!time:~-5,-3!!time:~-2!-(t0f+0), dT1+=(dT1>>31) & 6000, fps=(F-old\)*100*100 / dT1, t0f=(t0f+0)+dT1, old\=F, \+=4*fps/100"
Title Fps:!fps:~0,-2!.!fps:~-2! #!F!
set dT1=
exit/b
EDIT: I have achieved about 25FPS with 25%CPU usage changing the line
Code: Select all
"%~f0" HB 60 1010 | find "128" | "%~f0" MAIN 5
to
Code: Select all
"%~f0" HB 60 1010 | find "128" | "%~f0" MAIN 3
Einstein1969