Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Help with a bot
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic Printable version
 View previous topic  public bot commands Post :: Post Makin a .dll  View next topic  
Author Message
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Wed Aug 17, 2005 3:24 am    Post subject: Reply to topic Reply with quote

Ok, how to get a Mervbot plugin to call a function every 101 ms ?
I guess you would have to create a timer (and a thread?) to do that, can someone give me an example of that?
_________________
Nickname: Maverick (I changed my name!)
TWCore developer | Subspace statistics
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Wed Aug 17, 2005 11:40 am    Post subject: Reply to topic Reply with quote

I'd just change the EVENT_Tick in the core to occur every 0.1 second (like powerbot's tick does).
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Thu Aug 18, 2005 3:37 pm    Post subject: Reply to topic Reply with quote

Guess that is another solution to the problem, but it would be making mervbot custom then. Hmmm, custom mervbot for my plugin icon_smile.gif
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
xor eax
Novice


Joined: Jun 01 2005
Posts: 93
Location: Spain
Offline

PostPosted: Thu Aug 18, 2005 10:14 pm    Post subject: Reply to topic Reply with quote

I think you should use SetTimer function

Code: Show/Hide


//To start the timer:

    UINT hTimer;
    hTimer = SetTimer(NULL,0,101,TimerProc);

// (101 is the timer interval (milliseconds))
// (TimerProc is the callback that will be called when interval expires)

---------------------------------------------------------

//To stop the timer:

    KillTimer(NULL,hTimer);

---------------------------------------------------------

//The callback function

VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
   //Put your code here
   // ...

   return;
}

Back to top
View users profile Send private message Add User to Ignore List Send email
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Fri Aug 19, 2005 6:24 am    Post subject: Reply to topic Reply with quote

Thanks I will try that.
grav_update.gif
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Fri Aug 19, 2005 8:06 am    Post subject: Reply to topic Reply with quote

Submit any core changes to catid to merge into the main build. icon_wink.gif I saw SOS posted his version of Merv, but doesn't it need .NET?
_________________
Performance is often the art of cheating carefully. - James Gosling
Back to top
View users profile Send private message Add User to Ignore List
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Fri Aug 19, 2005 10:08 am    Post subject: Reply to topic Reply with quote

xor eax, what should be the name of the CALLBACK TimerProc() function be if I want it to be part of the botInfo:: class ? Or isn't that possible?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Fri Aug 19, 2005 1:58 pm    Post subject: Reply to topic Reply with quote

I remember going through this. You can have a static function with an extra parameter 'this' to call the member function you want.
Code: Show/Hide
class DirClient
{
protected:
   void OnDisconnected(void *clos);

   static void OnDisconnected_(void *self, void *clos);
};

...
   net->SetDisconnectFunc(OnDisconnected_, (void*)this, NULL);
...

void DirClient::OnDisconnected(void *clos)
{
...
}

void DirClient::OnDisconnected_(void *self_, void *clos)
{
   DirClient *self = (DirClient*)self_;
   self->OnDisconnected(clos);
}
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Aug 19, 2005 3:46 pm    Post subject: Reply to topic Reply with quote

I'm curious. Without a message loop, how exactly does the timer notification get to your code? A separate thread? In that case, wouldn't you have to mess around with mutex's?
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
xor eax
Novice


Joined: Jun 01 2005
Posts: 93
Location: Spain
Offline

PostPosted: Fri Aug 19, 2005 5:11 pm    Post subject: Reply to topic Reply with quote

Maverick wrote:
what should be the name of the CALLBACK TimerProc() function be if I want it to be part of the botInfo:: class ? Or isn't that possible?

TimerProc does not need to be a class member, but Smong and others know MERV and C++ much better than me, lets see what the experts say...

Cyan~Fire wrote:
Without a message loop, how exactly does the timer notification get to your code?

This is taken from the Win32API help file, SetTimer function:

"When you specify a TimerProc callback function, the DispatchMessage function simply calls the callback function instead of the window procedure. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProc instead of processing WM_TIMER."

One way or the other it needs a message loop.
Back to top
View users profile Send private message Add User to Ignore List Send email
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Fri Aug 19, 2005 5:15 pm    Post subject: Reply to topic Reply with quote

Smong, how do I make that extra parameter 'this' use with the code xor eax posted?

Cyan~Fire thats more or less the problem I am having (was said on another forum about settimer and non-static functions)
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Aug 19, 2005 5:25 pm    Post subject: Reply to topic Reply with quote

Using Win API SetTimer() to handle bot timers is not good.
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Fri Aug 19, 2005 5:29 pm    Post subject: Reply to topic Reply with quote

Does pbot have separate timers or just really fast ticking?
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Aug 19, 2005 9:34 pm    Post subject: Reply to topic Reply with quote

He said once before the pbot defines a timer interface for its plugins. This is something I will add to MERVBot, if I ever finish.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
xsp0rtsfanx
Seasoned Helper


Age:36
Gender:Gender:Male
Joined: Dec 27 2004
Posts: 168
Location: California
Offline

PostPosted: Sat Aug 20, 2005 12:38 am    Post subject: Reply to topic Reply with quote

i'm glad my topic started helping out with something for mervbot although i got lost when people starting posting code lol
Back to top
View users profile Send private message Add User to Ignore List MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Aug 20, 2005 2:32 am    Post subject: Reply to topic Reply with quote

Pbot has a 100ms tick event and a programmable timer event (with 100ms granularity). Even if there are 20 bots, each with 20 modules, each with 20 timers going (8000!), there's no overhead. I keep timers in a linked list sorted by trigger time, and only have to check the top one. Try calling Win API SetTimer() 8000 times.
Back to top
View users profile Send private message Add User to Ignore List
Cerium
Server Help Squatter


Age:42
Gender:Gender:Male
Joined: Mar 05 2005
Posts: 807
Location: I will stab you.
Offline

PostPosted: Sat Aug 20, 2005 6:19 am    Post subject: Reply to topic Reply with quote

Single threaded?
_________________
There are 7 user(s) ignoring me right now.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Sat Aug 20, 2005 7:17 am    Post subject: Reply to topic Reply with quote

Doubtful.
Back to top
View users profile Send private message Add User to Ignore List
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Aug 20, 2005 9:57 am    Post subject: Reply to topic Reply with quote

Each bot is a single thread. Each thread manages its own timer list in the core.
Back to top
View users profile Send private message Add User to Ignore List
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Sat Aug 20, 2005 10:48 am    Post subject: Reply to topic Reply with quote

Whats the solution for mervbot then?
Mervbot has a tick event, which goes once every second. for the rest nothing that can be really used to spec areas on a map reliable.

I need something like a timer to make function being called every 101 ms. But with a timer I have problems with non-static functions etc.

Is there a solution to making timers work in Mervbot or do I have to make a custom mervbot to have the tick event go every 101 ms?



(Can a mod split this topic into noisySpectator entitled topic please?)
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
xor eax
Novice


Joined: Jun 01 2005
Posts: 93
Location: Spain
Offline

PostPosted: Sat Aug 20, 2005 11:03 am    Post subject: Reply to topic Reply with quote

So using 1 timer is not good because 8000 timers are an overhead?

Who is talking about calling SetTimer 8000 times? Not Maverick, not Smong, not me.

All I'm saying is that what Maverick wants can be done using SetTimer. And I haven't heard any good argument of yours against that.

Do you think a single timer per bot supose a significant overhead?

How is pbot handling the timer event? Is it using a timer or a... wheelchair?

How you're fabulous theory applies to Maverick's needs?

(and yes, Cerium, it can be single threaded, it simply does not depend on the thread model)
Back to top
View users profile Send private message Add User to Ignore List Send email
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Aug 20, 2005 11:17 am    Post subject: Reply to topic Reply with quote

Obviously my example was hyperbole. My point is that when coding, you consider scaleability. Don't do a "one time hack" that will end up being the foundation of something much more widely used.

Also, why exactly 101ms? Do you realize that, depending on the operating system, the resolution of the system timers could be as high as 16ms? Under Windows, if you are running in a worker thread (ie not a message loop), you can potentially use the multimedia timer or the high-res timer to get 1ms or even 1us accuracy. However, polling those timers has its own overhead.
Back to top
View users profile Send private message Add User to Ignore List
Maverick
broken record


Age:40
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Sat Aug 20, 2005 5:29 pm    Post subject: Reply to topic Reply with quote

I don't care it has to be 101 ms, at least faster then the current EVENT_Tick of Mervbot.

icon_confused.gif

I guess I am going to continue building my bot based on noisyspectator :/
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Guest



Offline

PostPosted: Sun Aug 21, 2005 12:00 pm    Post subject: Reply to topic Reply with quote

Mav, you want the bot to spec players one by one, if I understood well.

And I guess 101 msecs is the minimum time you must wait to assure that 1 position packet at least will be received from each player.

You want a non-static function to be triggered every X milliseconds... Why don't you call the non-static function from the TimerProc function?

Anyway, I think it can be done without a timer:
Why don't you make it so when a position packet arrives from the expected player then the bot switches to next player?

-You put the bot to spec the next player in list.
-When its correspondent position packet arrives the bot switches to next player.
-If a player goes to spec or leave the arena it is removed from the list of players being speced by the bot. And if the bot was specing him it switches to next player. When a player enter it is added to the list... etc.

Well... sorry Mav, I'm trying to help but maybe is better not to try it if I can't do it properly...
Back to top
xor eax
Novice


Joined: Jun 01 2005
Posts: 93
Location: Spain
Offline

PostPosted: Sun Aug 21, 2005 12:02 pm    Post subject: Reply to topic Reply with quote

the guest is me
Back to top
View users profile Send private message Add User to Ignore List Send email
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can 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 can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 258 page(s) served in previous 5 minutes.

phpBB Created this page in 0.594796 seconds : 49 queries executed (80.4%): GZIP compression disabled