|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Thunder_Bird Cheater Reputation: 0
Joined: 27 Apr 2018 Posts: 33 Location: pakistan
|
Posted: Thu Sep 09, 2021 11:15 pm Post subject: how does events work? how to optimize timer? |
|
|
I'd like to know how events are so optimized, as far as I understand events are handled using a timer, I am maybe wrong, if so how do they work, how does the CPU know that an event has occured? there must be timer sitting there with a code which keeps checking if an event(for example OnButtonClick) is triggered. But unlike the timers which I write in LUA script, they dont eat CPU at all. so is there a different logic behind timers? if yes, can I use it instead of timers?
and I use timer with interval of 1ms(its my requirement) and it rekts CPU so is there a way to optimize timers, if yes I'd like to know.
this may be the wrong section for this question but kthx.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Fri Sep 10, 2021 1:36 am Post subject: |
|
|
What do you mean by "event"? Like a button press?
Basic idea:
- The hardware (e.g. mouse) issues an interrupt signal to let the processor know something happened
- The kernel handles the interrupt, figures out what "event" it is (e.g. mouse click), and sends information about that event to the window manager (if relevant)
- The window manager figures out what window receives that event and sends it to the process responsible for that window
- The process then somehow handles it via whatever UI library it's using
Use Wikipedia for more information.
You didn't explain what you're doing in much detail. Post the OnTimer function here.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Fri Sep 10, 2021 1:46 am Post subject: |
|
|
An example of the CE reading events is the "autorun" folder thread.
On the other hand; I think Lua and a lot of scripting triggers come from Windows' built-in reading code.
If the code reading and execution scheduler is on Windows, it's likely that you'll see the CPU differently anyway.
Windows can hide this spike in its own timer code or reflect it as a CPU to the program you're running.
On the other hand, for CPU optimization in CE (Lua), you can wrap "collectgarbage('collect')" in the scheduler code.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Fri Sep 10, 2021 6:34 am Post subject: |
|
|
createTimer uses windows timers. their accuracy isn't that high, a 1 ms timer will run about as often as a 10 ms timer)
you can use a thread for more controlled timings (though still slightly bottlenecked)
e.g
Code: |
function createFasterTimer(interval,callback)
local controller={}
if type(callback)~='function' then error('parameter 2 of createFasterTimer must be a function') end
controller.Enabled=true
createThread(function()
while controller.Enabled do
sleep(interval)
synchronize(callback)
end
end)
return controller
end
local counter=0
ft=createFasterTimer(1,function()
counter=counter+1
print("tick "..counter)
end)
createTimer(1000,function()
ft.Enabled=false
ft=nil
print("done")
end)
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Thunder_Bird Cheater Reputation: 0
Joined: 27 Apr 2018 Posts: 33 Location: pakistan
|
Posted: Wed Sep 15, 2021 7:59 am Post subject: |
|
|
ParkourPenguin wrote: | What do you mean by "event"? Like a button press?
Basic idea:
- The hardware (e.g. mouse) issues an interrupt signal to let the processor know something happened
- The kernel handles the interrupt, figures out what "event" it is (e.g. mouse click), and sends information about that event to the window manager (if relevant)
- The window manager figures out what window receives that event and sends it to the process responsible for that window
- The process then somehow handles it via whatever UI library it's using
Use Wikipedia for more information.
You didn't explain what you're doing in much detail. Post the OnTimer function here. |
No, im not talking about hardware events, im taking about GUI objects event, like OnButtonClick events etc, maybe what im saying doesnt make sense so sorry if you don't understand xd and thanks .
ByTransient wrote: | An example of the CE reading events is the "autorun" folder thread.
On the other hand; I think Lua and a lot of scripting triggers come from Windows' built-in reading code.
If the code reading and execution scheduler is on Windows, it's likely that you'll see the CPU differently anyway.
Windows can hide this spike in its own timer code or reflect it as a CPU to the program you're running.
On the other hand, for CPU optimization in CE (Lua), you can wrap "collectgarbage('collect')" in the scheduler code. |
Thanks.
Dark Byte wrote: | createTimer uses windows timers. their accuracy isn't that high, a 1 ms timer will run about as often as a 10 ms timer)
you can use a thread for more controlled timings (though still slightly bottlenecked)
e.g
Code: |
function createFasterTimer(interval,callback)
local controller={}
if type(callback)~='function' then error('parameter 2 of createFasterTimer must be a function') end
controller.Enabled=true
createThread(function()
while controller.Enabled do
sleep(interval)
synchronize(callback)
end
end)
return controller
end
local counter=0
ft=createFasterTimer(1,function()
counter=counter+1
print("tick "..counter)
end)
createTimer(1000,function()
ft.Enabled=false
ft=nil
print("done")
end)
|
|
This helped, Thanks a lot.
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|