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

Add event on SA world map loaded #1578

Open
Lpsd opened this issue Jul 24, 2020 · 3 comments
Open

Add event on SA world map loaded #1578

Lpsd opened this issue Jul 24, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@Lpsd
Copy link
Member

Lpsd commented Jul 24, 2020

There's currently no way to know if the SA world map has loaded.

Upon a client first launching the game and connecting to a server, if the server sets the camera position to look anywhere on the map (and fades in the camera) it may take a few seconds for models to be loaded/displayed.

iirc (confirmation needed) all SA map models are loaded when first connecting to a server, and they'll remain "loaded" even when disconnecting and joining another server. If that's the case, we'd need a function to know whether the SA world has loaded, and an event (such as onWorldMapLoaded) to know when they've loaded.

Proposed usage:

addEventHandler("onPlayerJoin", root, function()
	local player = source

	-- Make sure the camera is faded out
	fadeCamera(player, false, 0)
	
	-- Set camera matrix
	setCameraMatrix(player, 50, 50, 75, 0, 0, 0)
	
	-- Check if SA world map loaded, if not then bind event.
	if (not isWorldMapLoaded()) then
		addEventHandler("onWorldMapLoaded", root, function()
			-- SA world map loaded, fade the camera in
			fadeCamera(player, true)
		end)
	end
end)
@Lpsd Lpsd added the enhancement New feature or request label Jul 24, 2020
@qaisjp
Copy link
Contributor

qaisjp commented Jul 25, 2020

Hmm. Would this event fire when you teleport for away and the world around your new position needs to stream in? I know the freeroam resource does some trickery to ensure that you don't fall through the ground when you teleport far away.

@Lpsd
Copy link
Member Author

Lpsd commented Jul 25, 2020

This function/event shouldn't be attached to collision, it's to check if all original SA world model data has loaded, which happens shortly after connecting to a server for the first time (see CModelInfoSA::IsLoaded). Therefore, this event would only fire once.

Further usage context: you want to show part of the SA map when a client joins your server, but it looks bad when the world models slowly load in - with the proposed function/event you'd be able to ensure all world models are fully loaded before fading the camera in.

When you load MTA and connect to a server for the first time - MTA has to load all SA world model data, the speed of which depends on client hardware (could possibly take 10+ seconds). Obviously, models that haven't been loaded yet will not be visible.

Once all SA world models have loaded, you can travel from point A to point B (which can be as far as you like) then back to point A, and the model should be instantly visible (at least that's what I found from my testing).

You can disconnect from the server and connect to another server - SA world models should still be instantly visible (as their data is already loaded).

I've uploaded a camera resource which includes a test script to replicate this (https://github.com/Lpsd/CameraManager)

  1. Start a local server with this resource
  2. Launch the MTA client and connect to your local server. You'll notice world objects loading in as the camera moves around the map.
  3. Restart the resource and notice how all models are instantly visible even when moving thousands of units away, then back again.

@tederis
Copy link
Collaborator

tederis commented Jul 25, 2020

It's not necessarily occurs just first time. It's highly depends on your PC configuration and streaming setup. Every time an object loads the game checks is there enough space for it. Otherwise others will be immediately unloaded until enough amount of free space reached. So for some PC configurations the same model will requires a loading twice and more times.

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

No branches or pull requests

3 participants