Data Realms Fan Forums http://45.55.195.193/ |
|
Conveyors code optimization http://45.55.195.193/viewtopic.php?f=73&t=14859 |
Page 1 of 1 |
Author: | Gotcha! [ Fri May 22, 2009 8:22 am ] |
Post subject: | Conveyors code optimization |
Hi people, I am busy making/updating maps and love making use of lua modules to spice things up. However, when using too many conveyors it really slows down the map. Using 6 or more already seems too much on some maps, slowing the game down to a crawl. I wondered if it is possible for someone to optimize the conveyor lua code somehow so that it takes up less resources? (Aiming in the dark here.) |
Author: | mail2345 [ Fri May 22, 2009 9:26 am ] |
Post subject: | Re: Conveyors code optimization |
Simple: Don't carry items or particles. |
Author: | numgun [ Fri May 22, 2009 11:07 am ] |
Post subject: | Re: Conveyors code optimization |
This should do it. I removed every part where its supposed to affect items. Code: function Create(self) x = self; --Set the speed in pixels per frame at which to move the actors/items. self.speed = 2; end function Update(self) --Depending on the angle, the conveyor must push objects in a different direction. self.RotAngle is the angle, but it's in radians rather than degreees. So, we convert and then round it down. if (math.floor(math.deg(self.RotAngle)) == 270) then --Cycle through every actor on the level. for actor in MovableMan.Actors do --Check if the actor is within the conveyor's zone. if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0) then --Move the actor along at the speed defined in the create event. actor.Pos.X = actor.Pos.X + self.speed; --This decreases the effects of gravity to nearly none and allows for the up-and-down motion to be applied to center the actor. actor.Vel.Y = actor.Vel.Y - ((actor.Pos.Y - self.Pos.Y)) / 35; --This keeps the actor at a steady speed in the direction that the conveyor is pushing. actor.Vel.X = actor.Vel.X / 2; --This keeps the actor near the center of the module while still allowing the actor to leave the flow by using its jetpack. actor.Pos.Y = ((actor.Pos.Y * 24) + self.Pos.Y) / 25; end end --Repeat the last actions for all items in-game. --Continue through every other possible right angle. elseif (math.floor(math.deg(self.RotAngle)) == 0) then for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 25) and (actor.Pos.X <= self.Pos.X + 25) and (actor.Pos.Y >= self.Pos.Y - 24) and (actor.Pos.Y <= self.Pos.Y + 24) and (actor.PinStrength <= 0) then actor.Pos.Y = actor.Pos.Y - self.speed; actor.Vel.X = actor.Vel.X - ((actor.Pos.X - self.Pos.X)) / 35; actor.Vel.Y = actor.Vel.Y / 2; actor.Pos.X = ((actor.Pos.X * 24) + self.Pos.X) / 25; end end elseif (math.floor(math.deg(self.RotAngle)) == 90) then for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 24) and (actor.Pos.X <= self.Pos.X + 24) and (actor.Pos.Y >= self.Pos.Y - 25) and (actor.Pos.Y <= self.Pos.Y + 25) and (actor.PinStrength <= 0) then actor.Pos.X = actor.Pos.X - self.speed; actor.Vel.Y = actor.Vel.Y - ((actor.Pos.Y - self.Pos.Y)) / 35; actor.Vel.X = actor.Vel.X / 2; actor.Pos.Y = ((actor.Pos.Y * 24) + self.Pos.Y) / 25; end end elseif (math.floor(math.deg(self.RotAngle)) == 180) then for actor in MovableMan.Actors do if (actor.Pos.X >= self.Pos.X - 25) and (actor.Pos.X <= self.Pos.X + 25) and (actor.Pos.Y >= self.Pos.Y - 24) and (actor.Pos.Y <= self.Pos.Y + 24) and (actor.PinStrength <= 0) then actor.Pos.Y = actor.Pos.Y + self.speed; actor.Vel.X = actor.Vel.X - ((actor.Pos.X - self.Pos.X)) / 35; actor.Vel.Y = actor.Vel.Y / 2; actor.Pos.X = ((actor.Pos.X * 24) + self.Pos.X) / 25; end end end end |
Author: | Gotcha! [ Fri May 22, 2009 11:17 am ] |
Post subject: | Re: Conveyors code optimization |
Awesome. Thanks, both of you. |
Author: | alfie275 [ Fri May 22, 2009 1:13 pm ] |
Post subject: | Re: Conveyors code optimization |
Could just make them same width but taller for vertical or wider but same height for horizontal so you require less of them. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |