BerryBots forums

It is currently Tue Jul 27, 2021 2:55 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Mar 28, 2013 9:30 pm 
Offline
Site Admin
User avatar

Joined: Sat Nov 17, 2012 5:03 am
Posts: 88
Doh! Cool, nice work! :) I'll take a look in a couple hours.

FYI - Lua uses garbage collection, so I shouldn't have to manually clear anything. I turn off the GC during each call to user code, because I hit a strange issue with GC happening in the middle of a call from user Lua code to the BerryBots API (in C). But it's re-enabled between turns, so it should still happen in general.

I'll try to figure out what's going on and let you know. Thanks for the bug report and code!

Btw, you're on Windows, right? (Not sure it matters, but it might.)


Top
 Profile  
 
PostPosted: Thu Mar 28, 2013 10:03 pm 
Offline
Site Admin
User avatar

Joined: Sat Nov 17, 2012 5:03 am
Posts: 88
Wow, that memory blows up super quickly!

I guess my turning off the GC is causing it to never get run for this bot. After removing that, it works fine (though yes, very slow :-)). So I need to leave the GC alone, or manually initiate GC between turns. I did this as a workaround to a problem I found while running Snail, but I'm not hitting it now, so maybe I don't need it.

I'll build a test version for you later (~2 hours from now), if you wouldn't mind trying it to confirm that it fixes the problem on your system. Windows, right?


Top
 Profile  
 
PostPosted: Thu Mar 28, 2013 10:54 pm 
Offline
Site Admin
User avatar

Joined: Sat Nov 17, 2012 5:03 am
Posts: 88
Ok, if I'm remembering right and you are on Windows, give this a shot: BerryBots v1.1.3-rc1 for Windows

Your code is running fine for me with that version on Mac and Windows.

One thing I see that you could optimize is that you can check gfx:enabled() before running your graphics code. The drawLine function calls atan2 and sqrt, which are both pretty costly. (I'm not sure it's the main thing slowing you down, though.)


Top
 Profile  
 
PostPosted: Fri Mar 29, 2013 12:23 pm 
Offline
Site Admin
User avatar

Joined: Sat Nov 17, 2012 5:03 am
Posts: 88
Ok, I see what's going on. I have a hard limit of 4096 of each type of graphic. If you look at the drawLine in "wouldHitWall", that's being called NUM_SLICES * TICKS_OUT * number of wallLines every tick, which is a lot.

Once you reach the limit, new lines won't get added, and this happens before the old ones are cleared. So it's fluctuating between 4096 and 0 lines every other tick.

So I think...
  • You shouldn't draw every wall in wouldHitWall. =) The bot sped up a lot after removing that too. (You can draw each wall once outside of that main loop if you want, for the same effect)
  • It should behave more gracefully when adding lines above the limit, like replacing old ones instead of ignoring new ones. And clearing old ones at start of a new tick instead of before drawing.
  • This limit should be in the docs somewhere. And I can raise it if needed, but I wanted some limit. I thought "who's going to want to draw 4096 lines anyway!" :-)


Top
 Profile  
 
PostPosted: Mon Apr 01, 2013 3:35 pm 
Offline
Site Admin
User avatar

Joined: Sat Nov 17, 2012 5:03 am
Posts: 88
You're not bugging me - BerryBots is what I do for fun, not my day job. :-)

FYI both these issues are addressed in v1.1.3, which I posted yesterday. The GC fix is there. The 4096 limit is noted in the API docs, you'll see the first 4096 lines/etc each tick instead of flickering, and it prints a message to the output console the first time you hit the limit. (It also makes the ship name red in the dock, as it does for any unread errors.)

Cheers,


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group