View Issue Details

IDProjectCategoryView StatusLast Update
0009523New Feature Requests[All Projects] Generalpublic2018-09-30 14:28
ReporterarranTunaAssigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionopen 
Summary0009523: [Request] onClientElement[Enter/Leave]Screen
Description

I recently noticed that by disabling collisions on peds that weren't on screen I was able to improve FPS a lot and I have that on a 1000ms timer checking isElementOnScreen. I tried this for players too but in onClientPreRender to avoid any desync, however the performance impact of checking isElementOnScreen in onClientPreRender was as much as a performance drop as disabling collisions was as a boost.

If onClientElementEnterScreen and onClientElementLeaveScreen existed it would allow for things like described above to be much more effective as well as other things that are constantly updating things for nearby elements such as bone attach.

TagsNo tags attached.

Users sponsoring this issue
Sponsors List Total Sponsorship = EUR 10

2017-01-10 15:58: arranTuna (EUR 10)
Users sponsoring this issue (Total Sponsorship = EUR 10)

Activities

einheit-101

2017-01-10 23:53

reporter   ~~0025613

What CPU do you have when checking isElementOnScreen onClientPreRender consumes such an amount of performance?
I dont even use that function, gonna try that lol

Kenix

2017-01-11 01:12

updater   ~~0025614

Last edited: 2017-01-11 01:13

View 2 revisions

Myabe try getElementMatrix (with getElementBoudingBox offsets ) & getCameraMatrix + some calculations and check it.

drifterCZ

2017-01-11 08:21

viewer   ~~0025615

Last edited: 2017-01-11 08:22

View 2 revisions

shouldnt that be handled by mta internaly, if it really has so great impact? maybe together with some setting in mtaserver.conf for it?
I dont say this event isn't a good idea

arranTuna

2017-01-11 12:14

manager   ~~0025616

@einheit-101: I have an i5-4670K and can play GTA V on very high settings with 50 to 60 FPS. Yet on an empty MTA server that had about 40 peds streamed off screen in I was getting 75 FPS but with their collisions disabled (1000ms timer) it went up to more like 85 FPS. If there were actual players and vehicles around like in a busy place with 40 players FPS could drop as low as 40 FPS. The CPU eater in MTA seems to be GTA SA's collision processing as even removing objects can improve FPS. Though I can't be sure without: https://bugs.mtasa.com/view.php?id=9510

einheit-101

2017-01-11 12:21

reporter   ~~0025617

The fps drop significantly but the CPU is not even close to 100% usage, clearly a game fault

codylewiz

2017-01-15 02:49

viewer   ~~0025621

Last edited: 2017-01-15 02:55

View 5 revisions

MTA can not use 100% of cpu because SA is a single core game.

Also have you tried onClientElementStreamOut and onClientElementStreamIn?
It may disable collisions a bit later then you're aiming for but it'd at least partially help from my knowledge.

Heck you could probably do the same thing for vehicles; and it'd help quite a bit.

einheit-101

2017-01-15 15:07

reporter   ~~0025626

Even 1 core is not reaching 100% usage for me. But before my GPU was the limit mostly, I need to do new research now

arranTuna

2017-01-15 19:55

manager   ~~0025628

@codylewiz element stream in/out is useless as when something is streamed out it has no collisions as that is the whole point of streaming.

@einheit-101 it does indeed seem that FPS drops before CPU usage of the core even reaches 100% which is probably down to something in GTA SA that sleeps the process for a while but I remember from many many years ago ccw did a memory hack that hugely improved FPS by disabling something like a GTA SA sleep setting. Perhaps there is still something like this that makes FPS lower than it should be.

ccw

2017-01-15 20:12

administrator   ~~0025629

Please provide an example resource showing low FPS and CPU usage

arranTuna

2017-01-16 13:05

manager   ~~0025630

@ccw While trying to create a test resource I have noticed something very strange. When FPS is max 32 the CPU usage of gta_sa.exe is 0 and then every few seconds it shoots up to 20 (quad core) then goes back down again, I've got it windowed looking at both MTA and task manager:

Second 1: 11%
Second 2: 20%
Second 3: 13%
Second 4: 4%
Second 5 to 10: 0%

I can't see how it can possibly use as little as 0% but then the same game can then use 20%.

Now I've set max FPS to 60 and the CPU usage is continuous 5 to 9%.

Max FPS on 100 CPU usage increases to 14 to 16%.

Max FPS on 25 CPU usage is 4 to 6%.

The moment it's set back to default of 32 the CPU usage goes completely different.

I have found that creating 50 peds will drop FPS but gta_sa.exe isn't maxed out on a core, though it almost is. Test that creates specific ped amounts easily (/ped amount) and shows FPS on screen resource attached. Also there's an image in there that shows how changing max FPS can change CPU usage so much.

StifflersMom

2017-01-16 16:04

updater   ~~0025631

Last edited: 2017-01-16 16:28

View 2 revisions

Just a notice to the funny 32fps thing:
I tried 32fps on our test server with our resources running:
http://imgur.com/a/oPWNA

This is ONLY with 32 fps. Not with 31 and not with 33 ...

Tried with 63 and 64 fps. Guess, what :)
http://imgur.com/a/aGAQJ

einheit-101

2017-01-17 13:49

reporter   ~~0025632

Last edited: 2017-01-17 13:50

View 2 revisions

I can confirm there is something wrong with collision calculation.
While running on battery i get 81 fps max and each PED costs ~1 fps.
With 55 PEDs i have 30 fps left. Disabling PED collision gives me 81 fps with 55 PEDs again...

This code below seems to work fine so far, i get 81 fps while peds are OFF SCREEN and 30 when they are ON SCREEN, that means isElementOnScreen consumes 0 CPU:

function onRender()
for i, v in pairs(getElementsByType("ped")) do
if isElementStreamedIn(v) then
if isElementOnScreen(v) then
setElementCollisionsEnabled(v, true)
else
setElementCollisionsEnabled(v, false)
end
end
end
addEventHandler("onClientPreRender", root, onRender)

arranTuna

2017-01-17 21:24

manager   ~~0025633

@StifflersMom I just tried 96 max FPS too and that's like 64 and 32, interesting. It's so weird to think that setting max FPS to 32, 64 or 96 can make the CPU usage of the process completely different.

@einheit-101 I've tested the onClientPreRender and actually yeah, there is a performance improvement even when using onClientPreRender, this event would still be useful though.

Issue History

Date Modified Username Field Change