No more waiting

Today I’ve been adding a bunch of finishing touches, squashing bugs, and writing documentation and tutorials. Almost everything I wanted to have done by release is done. I couldn’t figure out the vehicle velocity improvement I mentioned earlier so I’m leaving that for later. Player structures don’t seem to store a pointer or object index to what vehicle they’re in.

When I say no more waiting, I’m also referring to busy waiting. I think I finally solved a problem that has been around for quite some time–the program would randomly start hogging the CPU and slowing down itself and the game, even though everything was running smoothly beforehand. I figured it had to do with my aimbot thread. The aimbot needs to keep following a target independently of the AI system. It aims, waits 10 ms, then continues. However, when you want to pause the aimbot then the execution of the thread needs to go somewhere. To avoid creating a new thread every time the AI was started again, I simply looped while a “paused” flag was true. I noticed this took up a lot of my CPU usage, so I added a sleep(150) to the loop which took the CPU usage down but didn’t get rid of the problem completely.

I learned this kind of waiting is called busy waiting and should be avoided because it doesn’t play nice with multithreaded applications. I felt it was kind of hacky from the start anyway. I now use a timer and catch its tick events to trigger the aiming code. I’m not sure how the timer works internally, but I haven’t had the problem since.

Oh, and the bot can type chat messages now. It’ll actually type out entire multi-line files for you in case you want to tell a hundred “Confucius say” jokes to the other players in the server (I may or may not have done this). You can also script it out fairly well by using the $ character, which causes GuiltySpark to wait a second before continuing the message. What’s great is that the chat FID expects numbers for file names and there’s a random number data source. This means you can have the bot select a random message by fiddling with the postfix expression.

Anyway, release soon.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s