Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua API for buildings #3274

Merged
merged 23 commits into from
Feb 29, 2024

Conversation

TheNormalnij
Copy link
Contributor

@TheNormalnij TheNormalnij commented Dec 18, 2023

Fixes #450, #2755, #1921

API:

element-building createBuilding(number modelId, float x, float, y, float z, float rx, float ry, float rz [,  number interior = 0])

@TheNormalnij
Copy link
Contributor Author

image

@tederis
Copy link
Collaborator

tederis commented Dec 18, 2023

I think Euler angles should be used instead of quaternions. Quaternions are less intuitive and will be a nightmare for the most of beginners. Or maybe there should be an enbedded function for the Euler <-> Quaternion conversion. In addition, it would be easier to move previously created maps on createBuilding without an effort.

@TheNormalnij
Copy link
Contributor Author

I think Euler angles should be used instead of quaternions. Quaternions are less intuitive and will be a nightmare for the most of beginners. Or maybe there should be an enbedded function for the Euler <-> Quaternion conversion. In addition, it would be easier to move previously created maps on createBuilding without an effort.

Yes, i think so. I didn't found euler to quaternion functions.

@TheNormalnij TheNormalnij marked this pull request as ready for review December 18, 2023 20:54
Shared/mods/deathmatch/logic/Utils.h Outdated Show resolved Hide resolved
Client/game_sa/CPoolsSA.cpp Outdated Show resolved Hide resolved
Client/game_sa/CFileLoaderSA.cpp Outdated Show resolved Hide resolved
@Zangomangu
Copy link
Contributor

We're going from euler, to quaternion, to matrix now
Could we also please allow skipping euler ?

element-building createBuilding(number modelId, float x, float, y, float z, float rx, float ry, float rz, float rw [, number interior = 0])

If rw is nil interpret as Euler otherwise quaternion

@TheNormalnij
Copy link
Contributor Author

Could we also please allow skipping euler ?

We can add quaternion -> euler utility function

@Zangomangu
Copy link
Contributor

Well the point would be to get rid of that conversion altogether (where some euler angles are problematic) since the GTA function accepts a quaternion.

But i'm not too steadfast on it, since it can be worked around by setting matrix.
I can see the point where scripters are used to euler angles and we want to keep it similar.

@StrixG StrixG added the enhancement New feature or request label Dec 21, 2023
Client/game_sa/CFileLoaderSA.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/CClientBuilding.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/CClientBuilding.h Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/CClientBuildingManager.h Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/Utils.h Outdated Show resolved Hide resolved
Client/game_sa/CPoolsSA.cpp Outdated Show resolved Hide resolved
Client/mods/deathmatch/logic/CClientManager.h Outdated Show resolved Hide resolved
Shared/mods/deathmatch/logic/Utils.h Outdated Show resolved Hide resolved
@tederis
Copy link
Collaborator

tederis commented Dec 25, 2023

createBuilding function must check if modelId argument is actually a building model. It can be done by looking at usDynamicIndex field: auto modelInfo = pGame->GetModelInfo(modelId); if (modelInfo->GetInterface()->usDynamicIndex != 0xffff) return nullptr;

Otherwise GTA will create a dummy object instead of a building and this type of object will never be deleted. You can check what will happened if create a building with model ID 3797.

@tederis
Copy link
Collaborator

tederis commented Dec 25, 2023

I also noticed that shadows and grass are still on the map even after a resource restart. But they disappear after the respawn(I guess shadows and grass are spawned once after the building creation).

@tederis
Copy link
Collaborator

tederis commented Dec 25, 2023

There also a problem with the rotation. When you spawn an object and a building with the same coordinates and the same rotation, their actual transformation differs.

mta-screen_2023-12-25_16-05-51

@TheNormalnij
Copy link
Contributor Author

also noticed that shadows and grass are still on the map even after a resource restart. But they disappear after the respawn(I guess shadows and grass are spawned once after the building creation).

This can be fixed manually via setWorldSpecialPropertyEnabled('randomfoliage', false).

@TheNormalnij
Copy link
Contributor Author

There also a problem with the rotation. When you spawn an object and a building with the same coordinates and the same rotation, their actual transformation differs.

Fixed

@tederis
Copy link
Collaborator

tederis commented Dec 25, 2023

also noticed that shadows and grass are still on the map even after a resource restart. But they disappear after the respawn(I guess shadows and grass are spawned once after the building creation).

This can be fixed manually via setWorldSpecialPropertyEnabled('randomfoliage', false).

This disables the grass no doubt. But what if I want to keep grass on the default SA objects? And what about the shadows?
mta-screen_2023-12-25_19-29-14

@tederis
Copy link
Collaborator

tederis commented Dec 25, 2023

also noticed that shadows and grass are still on the map even after a resource restart. But they disappear after the respawn(I guess shadows and grass are spawned once after the building creation).

This can be fixed manually via setWorldSpecialPropertyEnabled('randomfoliage', false).

This disables the grass no doubt. But what if I want to keep grass on the default SA objects? And what about the shadows? mta-screen_2023-12-25_19-29-14

My opinion is that we should restream(reload or recreate) grass and shadows somehow at each change in the buildings. Or even better leave a mark that grass(and shadows) should be recreated and do it in the next frame to eliminate tons of excessive calculations.

@TheNormalnij
Copy link
Contributor Author

My opinion is we should restream grass and shadows somehow at each change in the buildings.

It causes performance degradation when you have significant amount of buildings. I prefer additional restreamShadows function.

@tederis
Copy link
Collaborator

tederis commented Dec 25, 2023

My opinion is we should restream grass and shadows somehow at each change in the buildings.

It causes performance degradation when you have significant amount of buildings. I prefer additional restreamShadows function.

See my additions to the comment: Or even better leave a mark that grass(and shadows) should be recreated and do it in the next frame to eliminate tons of excessive calculations. In my opinion a deletion procedure should leave the game as it was before the building creation. It should be by default. But function restreamShadows can be added as well.

Client/game_sa/CPoolsSA.cpp Outdated Show resolved Hide resolved
Client/game_sa/CFileLoaderSA.cpp Outdated Show resolved Hide resolved
@Zangomangu
Copy link
Contributor

Nice work on this pr
Getting 30 % less cpu usage with createBuilding over createObject

@Zangomangu
Copy link
Contributor

#1921 is also fixed with this PR

@tederis
Copy link
Collaborator

tederis commented Dec 28, 2023

There are still problems with the rotation(it doesn't match the rotation that objects created via createObject have). I believe that this is an important point because most of the players will use buildings as a substitute for objects.
mta-screen_2023-12-28_12-02-21

@TheNormalnij
Copy link
Contributor Author

Oh. rx between 90 and 270 is broken

@TheNormalnij
Copy link
Contributor Author

I think there is no more issues with rotation

Copy link
Collaborator

@tederis tederis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is mature enough to be merged I think. Problems related to grass and shadows(see my comments above) can be addressed in the next PRs. LODs can also be implemented in future commits.

Copy link
Contributor

@Zangomangu Zangomangu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with tederis

@BenhurPaz
Copy link

Merge this!

@MrSol0
Copy link

MrSol0 commented Feb 23, 2024

I come here to add my voice with the previous people and say please merge this ASAP as we need it in our upcoming project.

@Lpsd Lpsd merged commit 81242ed into multitheftauto:master Feb 29, 2024
6 checks passed
MTABot pushed a commit that referenced this pull request Feb 29, 2024
@Einheit-101
Copy link

What about:
-LOD Distance (How far can we see buildings? Infinite draw distance like in MTA:Eir?)
-Shaders - should we be able to restrict shaders to buildings?
-Can buildings be altered with setElementPosition and other functions?

@TheNormalnij
Copy link
Contributor Author

-LOD Distance (How far can we see buildings? (Infinite draw distance, like in MTA:Eir?)

Draw distance is limited by GTA SA only. Buildings have equal draw distance with SA world world elements.

-Shaders - should we be able to restrict shaders to buildings?

I think only global shaders work. Personally, i don't prioritize shaders over dynamic pool size / LODs / dynamic map box.

-Can buildings be altered with setElementPosition and other functions?

setPostion / setRotation / setMatrix functions work, but they are expensive. I suggest not use them

@TheNormalnij TheNormalnij deleted the TheNormalnij/createBuilding branch April 2, 2024 18:21
@Dutchman101
Copy link
Member

@TheNormalnij https://wiki.multitheftauto.com/wiki/CreateBuilding doesn't exist 2 weeks after merge, please add it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Created objects don't reflect lights / shadows
9 participants