BAM Request: Quicker way to get BAM ObjectInfo from reference

madmrmax

Weeeeeee
Site Supporters
Joined
Sep 21, 2017
Messages
462
Solutions
1
Reaction score
237
Points
55
Favorite Pinball Machine
Indiana Jones (Williams)
Right now, for named objects where I want to retrieve the "Z" position, I have to get the ObjectInfo's Position. The only way to do this is to use FindObject to get the ObjectInfo, even though I already have a reference to the object.

C#:
AddDebugText "z = " & xBAM.FindObject(xobj.Name).Position.Z

Maybe this call is very fast, but when I use it inside of something like NewtonPhysicsTick I'm a bit concerned.

@ravarcade is there better generic way this can be done? Either
  1. Add new xBAM.ObjectInfo("objectName") - function can be used to get FP ObjectInfo from object name.
  2. Have an "Ext" extension for every FP object type which can be used to get the ObjectInfo.
Perhaps you might instead say that xBAM.FindObject("objectname") is very fast and not a true "find".

thanks!
-mark
 
Hi,

xBAM.FindObject("objectname") is not terrible slow, but inside NewtonPhysicsTick it may add significant time.

If you search always for same object, just store it in global variable.
Code:
Dim objectx : Set objectx  = xBAM.FindObject("objectname")

Sub NewtonPhysicsTick()
  AddDebugText objectx.Position.Z
End Sub

Another slow step in process is lookup for physics state in physics engine.
This is done only once per physics frame, so if you check few params (Position X/Y/Z, Rotation, Velocity) of same object it is done once per physics frame.

Last slow step is my fault (low quality code) in BAM.
If in script there is line, like x.Position, x.Rotation BAM creates vbscript object with 3 fields inside (x,y,z). This is memory allocation. VBScript will later delete that object. This is waste of time and i will check if it can be avoided this weekend.

I will also do some benchmarks to check best way to improve performance.

btw: what type of objects you check in NewtonPhysicsTick ?
 
Hi,

xBAM.FindObject("objectname") is not terrible slow, but inside NewtonPhysicsTick it may add significant time.

If you search always for same object, just store it in global variable.
Code:
Dim objectx : Set objectx  = xBAM.FindObject("objectname")

Sub NewtonPhysicsTick()
  AddDebugText objectx.Position.Z
End Sub

Another slow step in process is lookup for physics state in physics engine.
This is done only once per physics frame, so if you check few params (Position X/Y/Z, Rotation, Velocity) of same object it is done once per physics frame.

Last slow step is my fault (low quality code) in BAM.
If in script there is line, like x.Position, x.Rotation BAM creates vbscript object with 3 fields inside (x,y,z). This is memory allocation. VBScript will later delete that object. This is waste of time and i will check if it can be avoided this weekend.

I will also do some benchmarks to check best way to improve performance.

btw: what type of objects you check in NewtonPhysicsTick ?
Thanks Rafal!

I think I design my script too much like I'm designing frameworks where one component (mirror ball tracker) doesn't know about the other. I do design variable caching, but I only do it inside the component.

I started using ObjectInfo since it seemed like the best way to get the height of a FP object (without jumping through object reference such as a what surface or playfield a FP object might be connected to)

Currently I don't think I'll have to do a FindObject(name) call inside the NewtonTick method, which is a relief. It should only happen in a timer event (200ms delay)
 
Last edited:
Benchmark results before BAM code optimalization:
Code:
Sub NewtonPhysicsTick()
  AddDebugText xBAM.FindObject("RightFlipper").Position.X
  AddDebugText xBAM.FindObject("RightFlipper").Position.Y
  AddDebugText xBAM.FindObject("RightFlipper").Position.Z
End Sub
One execution: ~25.7us. So, with physics engine running 256x per second it eats 6.58ms (or 0.658% of cp time)
Code:
Dim rf : Set rf = xBAM.FindObject("RightFlipper")

Sub NewtonPhysicsTick()
  AddDebugText rf.Position.X
  AddDebugText rf.Position.Y
  AddDebugText rf.Position.Z
End Sub
One execution: ~17.0us. So, with physics engine running 256x per second it eats 4.35ms (or 0.44% of cp time)

So, if you avoid calling xBAM.FindObject("objectNem") 3x times in NewtonPhysicsTick you save littlebit of time.

One more soultion, when you store in variable position:
Code:
Dim rf : Set rf = xBAM.FindObject("RightFlipper")

Sub NewtonPhysicsTick()
  Dim pos : Set pos = rf.Postion
  AddDebugText pos.X
  AddDebugText pos.Y
  AddDebugText pos.Z
End Sub

One execution: ~15.1us. So, with physics engine running 256x per second it eats 3.86ms (or 0.39% of cp time)

Tests on Ryzen 5800x running ~4.35GHz with RAM at 3200MHz

I also checked if removing new com object creation helps: Not much... It saves about 1us. Not much.
 
Last edited:
General chit-chat
Help Users
You can interact with the ChatGPT Bot in any Chat Room and there is a dedicated room. The command is /ai followed by a space and then your ? or inquiry.
ie: /ai What is a EM Pinball Machine?
  • No one is chatting at the moment.
  • Chat Bot Mibs Chat Bot Mibs:
    MedievilMadness has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Pinbalbilly has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    flipjuice has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    apollo2000 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Gmelo1 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    jose49 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    darcel has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    cocopops has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Nightvoice has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    drew1 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Cicero Silva has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    manstein has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    1000 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Destruck62 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    WeadlyDeapon has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    SaixXemnas has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Gege has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Fatmeatball has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    titomajo has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    daveseawater has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    rockin ray has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    Citron68 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    hammerpower has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    max37170 has left the room.
  • Chat Bot Mibs Chat Bot Mibs:
    OZZOLO has left the room.
      Chat Bot Mibs Chat Bot Mibs: OZZOLO has left the room.
      Back
      Top