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

Visualize capture regions on the map #39

Open
veger opened this issue Jun 26, 2023 · 25 comments
Open

Visualize capture regions on the map #39

veger opened this issue Jun 26, 2023 · 25 comments
Assignees
Labels
blocked-api Blocked by missing functionality in Factorio API enhancement New feature or request

Comments

@veger
Copy link
Owner

veger commented Jun 26, 2023

From https://mods.factorio.com/mod/TLBE/discussion/6498a5ed070072bbaa7d044c

map visualisation of capture regions - I know we can't draw rectangles onto the map, but perhaps we can use bookmarks or something to demarcate the rectangle being captured, and when panning, the target rectangle

@veger veger added the enhancement New feature or request label Jun 26, 2023
@veger
Copy link
Owner Author

veger commented Jun 26, 2023

I do not have any experience with the map API/possibilities

Drawing on the map would be nicest, but alternatively markers could be used to show the area(s). Although I have no idea how clear this would be and how much performance degradation it takes (updating only once in a while might counter performance issues)

I guess some experiment/test needs to be done, to make this request more clear and to see what is feasible

@drdozer
Copy link
Contributor

drdozer commented Jun 26, 2023

There is no API to render extra shapes onto the map. I have no idea the performance of adding and removing map markers, so as you say, this would need testing. It would be possible to use corner marker icons as the map icons though I think. It would mean shipping those icons with the mod.

@drdozer
Copy link
Contributor

drdozer commented Jun 26, 2023

I've made a start on this. I can put down a map marker at the centerPos position on the map, and it tracks about as you would expect. How do I calculate the bounding box from the centerPos and other numbers in the camera? I am guessing I need to use the zoom somehow? And possibly the width and height?

@drdozer
Copy link
Contributor

drdozer commented Jun 26, 2023

image

This is just a proof of concept. The box width and height are hard-coded, and I would need to replace the labels rendering the box with icons, but it basically works. As I walk about or build things, the box moves as expected.

@veger
Copy link
Owner Author

veger commented Jun 26, 2023

Trackers have a size object, which is calculated into a zoom for the Camera (as factorio API requires zoom) here https://github.com/veger/TLBE/blob/master/scripts/camera.lua#L167

I guess if you reverse this you can calculate size again (where centerPos is the middle of the area defined by the size).
Alternatively, we could store size and calculate zoom on each screenshot that is taken (or both are kept), but that requires to modify the transition code, as it goes from one zoom factor to another.

@drdozer
Copy link
Contributor

drdozer commented Jun 27, 2023

Is this the code I should be getting inspiration from?

function Camera.zoom(camera, tracker)
    -- Calculate desired zoom
    local zoomX = camera.width / (tileSize * tracker.size.x)
    local zoomY = camera.height / (tileSize * tracker.size.y)
    return math.min(zoomX, zoomY, maxZoom)
end

If I'm following this, the values have the following units:

tileSize: pixels per tile
tracker.size.{x,y}: tile
camera.{width,height}: pixel
zoomX,zoomY: dimensionless

So I think to calculate my boundary in tiles I use:

local width = zoom / (tileSize * camera.width)
local height = zoom / (tileSize * camera.height)

The logic in the zoom method seems to clip the captured region. So if the region was very long and thin, it would cap the zoom to capture the height, and if it was very tall and narrow, it would cap the zoom to capture the width. Is this the intended behaviour? It may explain why I was having difficulty with some captures where I thought it would be maximal over the bookmarks I set for corners. If we are reworking the rectangles and zoom logic, perhaps this return value could become:

    return math.min(
      math.max(zoomX, zoomY),
      maxZoom)

But perhaps I have misunderstood the zoom and got it inverted in my head. Bigger zooms show fewer tiles, right?

@drdozer
Copy link
Contributor

drdozer commented Jun 27, 2023

See #48

@veger
Copy link
Owner Author

veger commented Jun 27, 2023

I'll be merging #46 soon, which adds the transitionData object in the camera. This object has the start and end positions/zoom factors. So I guess it makes sense to use that info.

It also adds more info on the fields (in an attempt to start documenting the code)

The logic in the zoom method seems to clip the captured region

More to extend the captured region, I guess. So it will contain at the least the intended area of the tracker. With a perfect ratio zoomX and zoomY are equal. Otherwise the smallest zoom factor is picked (smaller zoom is bigger area screenshotted) making sure that the screenshots indeed contain the tracker area.

@drdozer
Copy link
Contributor

drdozer commented Jun 27, 2023 via email

@veger
Copy link
Owner Author

veger commented Jun 27, 2023

I believe it is possible to change the tint of sprints? No idea whether this is possible for map tags... If so it would be nice to have different colors for the different areas on the map?

@drdozer
Copy link
Contributor

drdozer commented Jun 27, 2023 via email

@drdozer
Copy link
Contributor

drdozer commented Jun 27, 2023

image

Tints implemented for 'corners' icons.

@drdozer
Copy link
Contributor

drdozer commented Jun 27, 2023

note to self - the current code crashes if used with an old save with an old mod, as the camera doesn't have the new field for the tags - it just needs a nil check added, not an upgrade script, but if I don't document the issue I will forget it

@veger
Copy link
Owner Author

veger commented Jun 27, 2023

Note that there is already a migration script setup for the 'paused camera issue' fix and enable/disable the 'take screenshot' button: https://github.com/veger/TLBE/blob/master/migrations/tlbe.1.4.5.lua

It will be run for existing games when the current changes are released

@drdozer
Copy link
Contributor

drdozer commented Jun 27, 2023

OK, I'll hook into that then as the code will be less scruffy that way.

@drdozer
Copy link
Contributor

drdozer commented Jun 28, 2023

As far as I can tell this is now fully implemented against master. It renders an off-white box for the capture region, and a green box for the target region during transitions.

@veger
Copy link
Owner Author

veger commented Jun 28, 2023

I'll take a look at your PR in the evening (in a few hours)

@veger
Copy link
Owner Author

veger commented Jun 29, 2023

#48 is merged, tt will be available in the next release

@drdozer
Copy link
Contributor

drdozer commented Jul 3, 2023

I've used this for a few hours now, and imho it is a really useful feature.

@veger
Copy link
Owner Author

veger commented Jul 3, 2023

Agreed! When I read your request, I was wondering why I didn't think of it before 😄
It sounded (and is as we now see) a very valuable addition

@veger
Copy link
Owner Author

veger commented Jul 4, 2023

I just stumbled upon this mod: https://mods.factorio.com/mod/eradicators-screenshot-maker

It might be nice to show the camera/transition areas on screen/in-game? It would show that you are leaving the area with the player character or something? 🤔

Maybe enable alt-mode drawing, so the rectangles won't end up in the screenshots, or we hide them before taking a screenshot? 🤔

@drdozer
Copy link
Contributor

drdozer commented Jul 31, 2023

I just stumbled upon this mod: https://mods.factorio.com/mod/eradicators-screenshot-maker

I think this uses the LuaRendering API, which I discovered today via this mod :D I think it allows rendering into the game window but not onto the map view. Seeking clarification from discord.

We could use these APIs to render in-game rectangles for the cameras in-world. But as you say, we'd then have to juggle if these are visible in screenshot somehow.

@drdozer
Copy link
Contributor

drdozer commented Jul 31, 2023

Rendering to map may possibly be added in future. Mark as "when WUBE update their APIs" and park?

@veger veger added the blocked-api Blocked by missing functionality in Factorio API label Jul 31, 2023
@veger
Copy link
Owner Author

veger commented Jul 31, 2023

Rendering to map would be nice, to the game/screen I have my strong doubts.

parking until API supports such a functionality seems a good solution

@veger
Copy link
Owner Author

veger commented Aug 1, 2023

Capture regions with map markers is available in release v1.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked-api Blocked by missing functionality in Factorio API enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants