View unanswered posts | View active topics It is currently Sat Apr 27, 2024 11:37 am



Reply to topic  [ 5 posts ] 
 Conveyors code optimization 
Author Message
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post 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.)


Fri May 22, 2009 8:22 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Conveyors code optimization
Simple:

Don't carry items or particles.


Fri May 22, 2009 9:26 am
Profile

Joined: Sat Jan 13, 2007 11:04 pm
Posts: 2932
Reply with quote
Post 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


Fri May 22, 2009 11:07 am
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Conveyors code optimization
Awesome. Thanks, both of you. :wink:


Fri May 22, 2009 11:17 am
Profile

Joined: Sun May 18, 2008 7:49 am
Posts: 23
Reply with quote
Post 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.


Fri May 22, 2009 1:13 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users


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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.188s | 15 Queries | GZIP : Off ]