Page 1 of 1

Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-16 03:15
by serfma
As the title suggests, I am setting curTime = host.timer_getWallTime() in a while loop and checking against that time for an if statement. Is it bad to call "host.timer_getWallTime()" so rapidly? I'm new to python in general and am trying to create a basic timer that would call a function every X serconds.

BF2 Time - BF2 Technical Information Wiki is what I used to grab the time.

Object Reference - BF2 Technical Information Wiki Also saw this but I haven't seen an example using one of these timers to get a general idea of how they work. (Such as setting it to trigger a function at X seconds)

EDIT:

Never mind, I realize now that bf2.Timer's first parameter can be/is a function reference. Got it!

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-16 06:45
by rPoXoTauJIo
Yey, one of those rare python dudes! :)

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-16 21:03
by serfma
rPoXoTauJIo wrote:Yey, one of those rare python dudes! :)
What do you mean? :o

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-16 21:39
by Mats391
Just as a sidenote: Never do what you initially thought with the while-loop and checking for timer. That is called busy-waiting and is a real performance killer. Pretty much every programming language has some sort of timer built in that works through sending notifications only when needed rather than blocking the CPU with your while-loop.

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-16 21:53
by serfma
'[R-DEV wrote:Mats391;2091592']Just as a sidenote: Never do what you initially thought with the while-loop and checking for timer. That is called busy-waiting and is a real performance killer. Pretty much every programming language has some sort of timer built in that works through sending notifications only when needed rather than blocking the CPU with your while-loop.
Yep, I assumed it was bad to do once I realized it crashed the server instantly. :> Thank you though! Every little bit helps. :)

I'm mainly used to lua with GMod but decided to try Python and already have learned why people hate it, but it's incredibly fun. :p

E:
While I'm at it, how would you recommend setting player-specific vars? Doing a little warning system and checking against how many warnings they've received before warning again or going to killing them. (Prior to 20v20, heavy assets)

Maybe a dictionary of warns where key is the playerID?

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-17 04:58
by rPoXoTauJIo
Cookbook:Changing Objects At Runtime - BF2 Technical Information Wiki ;)
You can add a property to playerobject rather than do a dict that may go out of sync. Not to mention that due to engine playerobject stays and being associated even if player reconnects. Maybe it can stay even for multiple rounds as python doesn't reset automatically between them, but i can't remember if i tested that.

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-17 07:09
by serfma
rPoXoTauJIo wrote:Cookbook:Changing Objects At Runtime - BF2 Technical Information Wiki ;)
You can add a property to playerobject rather than do a dict that may go out of sync. Not to mention that due to engine playerobject stays and being associated even if player reconnects. Maybe it can stay even for multiple rounds as python doesn't reset automatically between them, but i can't remember if i tested that.
Ooh okay. When you say out-of-sync you're meaning between rounds, correct? That's very useful information though! It's only a simple warning system for when a player enters a vehicle prior to 20v20 (heavy assets) and after 2 warns, it'll kill them, so there's no worries about between rounds. I used a dict (ex. warns[player.getName()]) to store the warns temporarily.

I wasn't sure and wasn't willing of testing whether playerObject.var would work since I'm going through a clan administrator to update the file then restart the server so I could test 1 small change. On that note; How would I be able to test code locally?

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-17 08:51
by rPoXoTauJIo
serfma wrote:Ooh okay. When you say out-of-sync you're meaning between rounds, correct?
No, just random, cause DICE :)
serfma wrote:I used a dict (ex. warns[player.getName()]) to store the warns temporarily.
You can do this in any way, i just recommened another one, seems more "pythonic" for me :)
serfma wrote: I wasn't sure and wasn't willing of testing whether playerObject.var would work since I'm going through a clan administrator to update the file then restart the server so I could test 1 small change. On that note; How would I be able to test code locally?
There's few ways to do it.
I'm usually just include chathandler and some debug caller i.e. "test1" would do something, then "test2" would do something else, gib output to file\chat(NEVER call chatmessages in chathandler->infinite loop). With enabled 'rcon debug' you'll usually get error ouput in game messages. Then use local dedi.
Other way to do it is to implement mock bf2 and host objects/modules and test script without using game at all, doing only final tests.

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-20 19:26
by serfma
rPoXoTauJIo wrote:No, just random, cause DICE :)

You can do this in any way, i just recommened another one, seems more "pythonic" for me :)

There's few ways to do it.
I'm usually just include chathandler and some debug caller i.e. "test1" would do something, then "test2" would do something else, gib output to file\chat(NEVER call chatmessages in chathandler->infinite loop). With enabled 'rcon debug' you'll usually get error ouput in game messages. Then use local dedi.
Other way to do it is to implement mock bf2 and host objects/modules and test script without using game at all, doing only final tests.
Local dedi; As in booting PR up and creating a local game or is there somewhere within the client files to host a local dedi server? Also, where would I place any files I'm wanting to run? I'm not sure where PR automatically runs files in certain folders.

Mock BF2? That seems pretty awesome. As in being able to mock a player entering a vehicle then leaving it without even having to start PR? That'd help a lot with cutting the time down of having to load a map each time I'm needing to test something new or as small as a print. (Not sure if there's any auto-refreshing, such as saving a file can result in that file being read and run without a restart)

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-20 20:08
by rPoXoTauJIo
serfma wrote:Local dedi; As in booting PR up and creating a local game or is there somewhere within the client files to host a local dedi server? Also, where would I place any files I'm wanting to run? I'm not sure where PR automatically runs files in certain folders.
Well, i did not found any official? dedi guides?, so i guess have to quote my own post :)
serfma wrote:Mock BF2? That seems pretty awesome. As in being able to mock a player entering a vehicle then leaving it without even having to start PR? That'd help a lot with cutting the time down of having to load a map each time I'm needing to test something new or as small as a print.
In terms of bf2, that's practically means writing whole "host" module and creating your own "virtual world" in python. I'm still working on this.
serfma wrote:Not sure if there's any auto-refreshing, such as saving a file can result in that file being read and run without a restart
There's none, unless you're running debug executable which is pretty old version(1.3 smth)m while we're currently using 1.5 as base.

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-20 20:34
by serfma
rPoXoTauJIo wrote:Well, i did not found any official? dedi guides?, so i guess have to quote my own post :)

In terms of bf2, that's practically means writing whole "host" module and creating your own "virtual world" in python. I'm still working on this.

There's none, unless you're running debug executable which is pretty old version(1.3 smth)m while we're currently using 1.5 as base.
Thank you so much! :)

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-20 21:00
by Eskil_swe

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-20 21:20
by serfma
Also...is it against the server license if a server admin gave me the files for RealityAdmin so that I could do modifications to it? No one has, I'm just asking so if it's safe to, I can get my hands on it instead of making a version myself. :p

E:
I might have misunderstood about the RealityAdmin part. There's an "extendedRA.py" (RealityAdmin Extended by [R-DEV]piepieonline) and I was told it's dependency, RealityAdmin, was only obtainable through a server license, however it seems to be included by default with PR. Am I correct?

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-20 22:25
by rPoXoTauJIo
PR(both client and server) contains only compiled python scripts.
Unfortunately, you're either have to mock(make 'fake' modules\objects) 'realityadmin' or develop in a way 'make script&include some debug-start game-verify-GOTO 10 until working'.

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-21 00:42
by serfma
Perfect!
rPoXoTauJIo wrote:PR(both client and server) contains only compiled python scripts.
Unfortunately, you're either have to mock(make 'fake' modules\objects) 'realityadmin' or develop in a way 'make script&include some debug-start game-verify-GOTO 10 until working'.

You misunderstood what I meant. :) I am brand new to coding for PR and the step that I was missing was pretty much step 1 of: Big Picture - BF2 Technical Information Wiki where /Battlefield 2 Server/admin/ calls __init__ which you then import <file> and <file>.init(). Basically wasn't sure how to load my script, but I got it! :>

In addition, after setting up this dedi server it appears I am incapable of requesting kits + sprinting is much quicker (akin to BF2 vanilla sprinting) so does this mean I did something incorrect or because I do not have the full server files? Server-window does show "Mod: pr" so I assume it's working correctly. :p

Re: Is host.timer_getWallTime() resource intensive to use in a loop?

Posted: 2015-08-21 06:24
by rPoXoTauJIo
serfma wrote: You misunderstood what I meant. :) I am brand new to coding for PR and the step that I was missing was pretty much step 1 of: Big Picture - BF2 Technical Information Wiki where /Battlefield 2 Server/admin/ calls __init__ which you then import <file> and <file>.init(). Basically wasn't sure how to load my script, but I got it! :>
Ahhhh. Yeah. Avoid importing custom scripts like that unless it's some complicated ones like prism working in 'update()' loop.
Proper way to import scripts in pr is to place them in mods/pr/python/game/, and init them in mods/pr/python/game/__init__.py after PR inits.
serfma wrote: In addition, after setting up this dedi server it appears I am incapable of requesting kits + sprinting is much quicker (akin to BF2 vanilla sprinting) so does this mean I did something incorrect or because I do not have the full server files? Server-window does show "Mod: pr" so I assume it's working correctly. :p
Idk about sprinting, that's really something that depends on server executable(cause PR uses custom ones).

But kit requests is something spooky. Seems like some of your python files is broken on a server installment(realityconfig_local.py?). Can you test if other things working? I.e. kit recruiments to vehicles, deployables?