Optimize this further?

video soon.


import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    own.localLinearVelocity.y=own.localLinearVelocity.  y+(own.localLinearVelocity.x*.5)
    
    scene=bge.logic.getCurrentScene()
    if 'init' not in own:
        L=[]
        for objects in scene.objects:
            if 'Animus' in objects:
                if objects.name!=own.name:
                    L+=[objects]
        own['init']=L            
    else:
        I = own['init']        
        for objects in I:
            if objects.name!=own.name:
                x=own.getVectTo(objects)
                own.applyForce((x[1]*(3.14*x[0])))
                
main()



Attachments

Emergant.blend (612 KB)

What aspect do you want to improve?
(size, execution speed, readability, consistency …)

Size
If it is size, it is simple:

Just remove:


def main():

main()

These two lines serve no purpose, do not add any value to the code and have no meaning.

Readability:
Rather than calling a list “init”, choose a name that tells the reader what it contains or what it is good for. Just now you are the only one who knows that.

General
What is this code supposed to do?

Stuff like this

But I need it as lean as possible so I can pack as much craziness as possible.

import bge



def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    own.localLinearVelocity.y=own.localLinearVelocity.y+(own.localLinearVelocity.x*.5)
    
    scene=bge.logic.getCurrentScene()
    if 'init' not in own:
        L=[]
        for objects in scene.objects:
            if 'Animus' in objects:
                if objects.name!=own.name:
                    L+=[objects]
        own['init']=L            
    else:
        I = own['init']        
        for objects in I:
            if objects.name!=own.name:
                x=own.getVectTo(objects)
                own.applyForce((x[1]*(3.14*x[0])))
                own.applyForce((0,own['Animus']*.05,own['Animus']*.01-(x[0]*.125)),1)
main()



What do you mean with “lean”?
What do you man with craziness? As far as I know this is an attribute of human minds not of code.

well for one, I just noticed that I was filtering the same thing two times… lol

if objects.name!=own.name:


import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    own.localLinearVelocity.y=own.localLinearVelocity.y+(own.localLinearVelocity.x*.5)
    
    scene=bge.logic.getCurrentScene()
    if 'init' not in own:
        L=[]
        for objects in scene.objects:
            if 'Animus' in objects:
                if objects.name!=own.name:
                    L+=[objects]
        own['init']=L            
    else:
        I = own['init']        
        for objects in I:
                x=own.getVectTo(objects)
                own.applyForce((x[1]*(3.14*x[0])))
                own.applyForce((0,own['Animus']*.05,own['Animus']*.01-(x[0]*.125)),1)
main()



Why you do “objects.name!=own.name”.

Beside the fact that “objects” refers to a single object rather than a container with objects (es the name implies), the code seems to make no real sense.

Either object is the owner -> then you can check “object is owner”
Or you created copies of the owner. But I wonder why you would do that. I wonder why you think you need to pack craziness with the owner. It better does that with the other objects, not with itself [“Animus” not in owner].

Btw. what is the name of the owner?
What is the owner supposed to do?

The owner applies rotations using a logic sequencer, and forces(acceleration)

it also is “gravitatied” to the other “spinnerets?” by this code, (the further apart they get the stronger “gravity” is)

this keeps them in the camera and causes odd “synchronicity”

see the triangles?

they are adding objects (a single polygon wire)

So you mean the owner is
A) the center of gravity
B) the controller applying forces to the other objects?

Then he acts as attractor.

The question is if it makes sense that he attracts itself? If not, do not configure it to be one.

Now we have a name for all of that: Attracting

so you can get rid if the senseless main() and call it attract()

Further you have different purposes in your code:


def attract():
   moveOwnerAround() # this does not belong to attract and is questionable
   attractAnimusObjectsToOwner()

Why is the owner moved around?

[Edit]
attractAnimusObjectsToOwner has several purposes too:


def attractAnimusObjectsToOwner():
   animusObjects = findAnimusObjects()
   attractToOwner( animusObjects )

Why are you doing the “if” statement every time? Wouldn’t it be faster to split the first half off into an initialization script, thus promising that “init” will already exist?

Good call,

this is more optimized … but is a bit more hard to read…:stuck_out_tongue:

import bge
def main():
    own=bge.logic.getCurrentController().owner;v=own.localLinearVelocity;v.y=v.y+(v[0]*.5)
    if 'not horse in house' not in own:
        radar, dracula = [], own.scene.objects
        for vampires in dracula:
            if 'Animus' in vampires and vampires.name!=own.name:
                radar+=[vampires]
        own['init'],own['not horse in house']=radar,-1*-1*1*-1
    for bodybuilding in own['init']  :
        horse=own.getVectTo(bodybuilding)
        own.applyForce((horse[1]*(3.14*horse[0])))
main()


I’m not sure, Vampires and Dracula are fast, but unicorns are faster I am told, and can run in the daytime.


for The_Hell_Of_It in Reno:
     while 'booze' in The_Hell_Of_It:
        For items in Resturant_Menu:
            if items['Grease']>.10
                order=order+[items]

you continue to write wrong names…


for item in resturant_menu::
   if item['Grease'] > 0.10:
       orders.append(item)



[not >items<]

for number in numbers:
for letter in letters:
for obj in scene.objects:
for example in examples:
:wink:


import bge




def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner


    
    own.localLinearVelocity.y=own.localLinearVelocity.y+(own.localLinearVelocity.x*.5)
    own.localLinearVelocity.x*=(.5)
    
    scene=bge.logic.getCurrentScene()
    if 'init' not in own:
        L=[]
        for objects in scene.objects:
            if 'Animus' in objects:
                if objects.name!=own.name:
                    L+=[objects]
        own['init']=L            
    else:
        own.applyForce((0,(own['Animus']*.25*own['Animus']),-15+(own['Animus']*.5)),1)
        I = own['init']        
        for objects in I:
            if objects.name!=own.name:
                x=own.getVectTo(objects)
                own.applyForce((x[1]*(3.14*x[0])))
                
                
main()




Not optimized any more currently

Attachments

UrgentEmergant .blend (972 KB)

you had a example of (extreme …10FPS) lag not due from python .

just comment main in this way:

#main()

to skip python and you see

what video card you rocking? I get 20 fps stable (I set it that way)

I can’t run the .blend and OBS at HD though
(screencapping takes some cpu%)

GEFORCE 8400 GSbut not seem a problem of GPU, in texture mode give crash (is my pc that is problematic) in wireframe mode anyway the logic that is incredibly high, all other params seem normals… FPS stable at 10 FPSthe problem is probably:A) numbers os object to highB) add and destroy a lot of object each frame is a operation heavy

yeah,I played with it to get as much as could, and keep it stable,

it will need to be “tuned in” to what your pc can handle,

it’s adding 1000’s of objects, that add objects… that have logic :smiley:

spindles -Gravity script etc - and logic

“Pixels” - logic and 1 more object

“Pixels 2” logic

now “gravitation” is built over time, and not so “instant” when Animus rolls from 60->0