ID:132449
 
This is a link to a test project I just made, to see if BYOND could handle a simple rotating wireframe object.
Credit goes to jt_vectors for the actual math behind it.
Basically, there are a set of vectors pointing to the vertices of a cube, and there is a list of which of the vertices have a line through them.
The vertices and line points are shown as 2x2 pixels. There are 8 line points forming the lines between the specified vertices.

On my computer, it runs perfectly fine for a few seconds while the CPU usage builds until it finally freezes and crashes. (See how long your computer will last!)
I'd like to see a similar project that runs faster and longer.

Why does BYOND have to be so slow at computing these basic calculations? Is it really that slow?

From what I could tell, the visual updates of the cube's rotation actually continues longer than when input of the client is successfully received from the server(ran locally of course).
Not sure what this could mean, or if it has anything to do with this.

Why so slow?
Are you using any icon processes?

Are you reusing the points or recreating them for each frame? What about jt_vectors' objects?

Have you tried profiling it?

What about commenting out all the code relating to the display of the cube, and just running the calculations alone?
In response to DarkCampainger
DarkCampainger wrote:
Are you using any icon processes?
None in that example, but since then I gave the vertices a unique color, and cached that icon. This is clearly not the issue.

Are you reusing the points or recreating them for each frame? What about jt_vectors' objects?

The procs in jt_vectors pretty much automatically create new /coordinate or /vector objects in all of its calculations.
They should be being garbage collected.

Have you tried profiling it?
From before Dream Seeker decided to freeze(and yet the cube kept spinning!):
                         Profile results (average time)
Proc Name Self CPU Total CPU Real Time Calls
---------------------------- --------- --------- --------- ---------
/model_display/proc/display 0.028 0.031 0.031 202
/mob/proc/show_model 0.016 0.016 0.016 202
/mob/proc/rotate_model 0.000 0.000 0.000 202
/proc/get_pixel 0.000 0.000 0.000 21008
/coordinate/proc/VectorTo 0.000 0.000 0.000 2424
/vector/proc/Scale 0.000 0.000 0.000 2424
/vector/proc/RotateX 0.000 0.000 0.000 1616
/coordinate/proc/AddVector 0.000 0.000 0.000 25856
/vector/proc/RotateY 0.000 0.000 0.000 1616
/vector/proc/Magnitude 0.000 0.000 0.000 2424
/vector/proc/Copy 0.000 0.000 0.000 1616
/vector/proc/RotateZ 0.000 0.000 0.000 1616
/vector/New 0.000 0.000 0.000 11312
/coordinate/New 0.000 0.000 0.000 25856
/coordinate/proc/CoordinateX 0.000 0.000 0.000 30704
/vector/proc/ComponentX 0.000 0.000 0.000 40400
/vector/proc/SetComponentZ 0.000 0.000 0.000 16160
/vector/proc/ComponentY 0.000 0.000 0.000 40400
/vector/proc/SetComponentY 0.000 0.000 0.000 16160
/vector/proc/ComponentZ 0.000 0.000 0.000 40400
/coordinate/proc/CoordinateZ 0.000 0.000 0.000 30704
/coordinate/proc/CoordinateY 0.000 0.000 0.000 30704
/vector/proc/SetComponentX 0.000 0.000 0.000 16160
/mob/Stat 0.000 0.000 0.000 25


What about commenting out all the code relating to the display of the cube, and just running the calculations alone?
The calculations have my world.cpu to be around 5-7.

To display each point, I add it to the overlays of its loc. (Points are /image objects)
What I find interesting though, is that if I just add the point to client.images instead of any overlays, the CPU is reduced a ton and doesn't gradually climb.
                         Profile results (average time)
Proc Name Self CPU Total CPU Real Time Calls
---------------------------- --------- --------- --------- ---------
/model_display/proc/display 0.001 0.006 0.006 200
/mob/proc/show_model 0.000 0.000 0.000 200
/mob/proc/rotate_model 0.000 0.000 0.000 200
/proc/get_pixel 0.000 0.000 0.000 40000
/coordinate/proc/AddVector 0.000 0.000 0.000 44800
/coordinate/proc/VectorTo 0.000 0.000 0.000 2400
/vector/proc/RotateY 0.000 0.000 0.000 1600
/vector/proc/RotateX 0.000 0.000 0.000 1600
/vector/proc/Scale 0.000 0.000 0.000 2400
/vector/proc/Magnitude 0.000 0.000 0.000 2400
/vector/proc/RotateZ 0.000 0.000 0.000 1600
/coordinate/New 0.000 0.000 0.000 44800
/vector/New 0.000 0.000 0.000 11200
/vector/proc/Copy 0.000 0.000 0.000 1600
/vector/proc/SetComponentX 0.000 0.000 0.000 16000
/vector/proc/SetComponentY 0.000 0.000 0.000 16000
/coordinate/proc/CoordinateX 0.000 0.000 0.000 49600
/vector/proc/SetComponentZ 0.000 0.000 0.000 16000
/vector/proc/ComponentY 0.000 0.000 0.000 59200
/coordinate/proc/CoordinateY 0.000 0.000 0.000 49600
/coordinate/proc/CoordinateZ 0.000 0.000 0.000 49600
/vector/proc/ComponentZ 0.000 0.000 0.000 59200
/vector/proc/ComponentX 0.000 0.000 0.000 59200
/mob/Stat 0.000 0.000 0.000 25


I still don't know why using overlays would cause the CPU to climb up into Dream Seeker-freezing levels.
I still wonder why although Dream Seeker is frozen, the cube still rotates and the screen updates.
In response to Kaiochao
Can you add a rotate x amount of times verb to your demo?
In response to Chowder
I've added rotate verbs.

For some reason, using a loop for macros("while key in keys_down", using a macro for the keypress and key+up) causes the CPU to grow while a button is pressed.
Removing that and letting BYOND use its usual key+rep macro system makes apparently lets the CPU calm down before repeating.

Also, I've added a couple things for visual.. appeal. After a while of rotating and caching certain things, it runs pretty nicely at not-too-big size. Why not?
Runs fine for me, I don't see what the problem is.
Kaiochao wrote:
Why does BYOND have to be so slow at computing these basic calculations? Is it really that slow?

It's not so basic. If you try to run any game in Software mode (meaning CPU will handle graphics, and GPU will idle) nearly all games will lag (games which were created in "GPU era").

Back in Counter Strike or Half Life 1 times, GPUs and CPUs were similar in performance, so it hardly made any difference. But something like Warcraft 3 most likely won't run on CPU anymore.
Because 3D transforms shouldn't be done by doing a number of seperate floating-point multiplies with a number of throwaway objects created, in a VM-language.

Usually if you want to do this kind of thing you learn matrix maths - see things like http://en.wikipedia.org/wiki/3D_projection for a basic grounding.
In response to SuperAntx
SuperAntx wrote:
Runs fine for me, I don't see what the problem is.

Did you try growing it?
In response to Falacy
Yeah, until I guess one of the points went out of bounds and it crashed. Other than that it seemed to expand, contract, and rotate just fine.
In response to SuperAntx
Works fine for me at default size, but making it bigger makes it lag