Is host.timer_getWallTime() resource intensive to use in a loop?
-
serfma
- Posts: 121
- Joined: 2010-11-12 01:10
Is host.timer_getWallTime() resource intensive to use in a loop?
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!
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!
Last edited by serfma on 2015-08-16 03:49, edited 1 time in total.
-
rPoXoTauJIo
- PR:BF2 Developer
- Posts: 1979
- Joined: 2011-07-20 10:02
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
Yey, one of those rare python dudes! 

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.
Time to give up and respawn.
-
serfma
- Posts: 121
- Joined: 2010-11-12 01:10
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
What do you mean?rPoXoTauJIo wrote:Yey, one of those rare python dudes!![]()
- Mats391
- PR:BF2 Lead Developer
- Posts: 7643
- Joined: 2010-08-06 18:06
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
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.

Mineral: TIL that Wire-guided missiles actually use wire
-
serfma
- Posts: 121
- Joined: 2010-11-12 01:10
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
Yep, I assumed it was bad to do once I realized it crashed the server instantly. :> Thank you though! Every little bit helps.'[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.
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.
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?
Last edited by serfma on 2015-08-16 22:00, edited 1 time in total.
-
rPoXoTauJIo
- PR:BF2 Developer
- Posts: 1979
- Joined: 2011-07-20 10:02
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
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.
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.
Last edited by rPoXoTauJIo on 2015-08-17 06:20, edited 1 time in total.

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.
Time to give up and respawn.
-
serfma
- Posts: 121
- Joined: 2010-11-12 01:10
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
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.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.
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?
-
rPoXoTauJIo
- PR:BF2 Developer
- Posts: 1979
- Joined: 2011-07-20 10:02
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
No, just random, cause DICEserfma wrote:Ooh okay. When you say out-of-sync you're meaning between rounds, correct?
You can do this in any way, i just recommened another one, seems more "pythonic" for meserfma wrote:I used a dict (ex. warns[player.getName()]) to store the warns temporarily.
There's few ways to do it.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?
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.

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.
Time to give up and respawn.
-
serfma
- Posts: 121
- Joined: 2010-11-12 01:10
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
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.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.
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)
-
rPoXoTauJIo
- PR:BF2 Developer
- Posts: 1979
- Joined: 2011-07-20 10:02
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
Well, i did not found any official? dedi guides?, so i guess have to quote my own postserfma 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.
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: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.
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.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

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.
Time to give up and respawn.
-
serfma
- Posts: 121
- Joined: 2010-11-12 01:10
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
Thank you so much!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.
-
Eskil_swe
- PR:BF2 QA Tester
- Posts: 64
- Joined: 2012-06-05 13:42
-
serfma
- Posts: 121
- Joined: 2010-11-12 01:10
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
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. 
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?
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?
Last edited by serfma on 2015-08-20 22:11, edited 1 time in total.
-
rPoXoTauJIo
- PR:BF2 Developer
- Posts: 1979
- Joined: 2011-07-20 10:02
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
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'.
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'.

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.
Time to give up and respawn.
-
serfma
- Posts: 121
- Joined: 2010-11-12 01:10
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
Perfect!Eskil_swe wrote:One way to reload at run time Cookbook:Reloading modules at runtime - BF2 Technical Information Wiki
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.
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.
Last edited by serfma on 2015-08-21 01:31, edited 1 time in total.
-
rPoXoTauJIo
- PR:BF2 Developer
- Posts: 1979
- Joined: 2011-07-20 10:02
Re: Is host.timer_getWallTime() resource intensive to use in a loop?
Ahhhh. Yeah. Avoid importing custom scripts like that unless it's some complicated ones like prism working in 'update()' loop.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! :>
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.
Idk about sprinting, that's really something that depends on server executable(cause PR uses custom ones).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.![]()
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?

assetruler69: I've seen things you smurfs wouldn't believe. Apaches on the Kashan. I watched burned down tank hulls after the launch of the single TOW. All those moments will be lost in time, like tears in rain.
Time to give up and respawn.
