beyond-all-reason / spring

A powerful free cross-platform RTS game engine
https://beyond-all-reason.github.io/spring/
Other
178 stars 95 forks source link

Add a synced interface to read images #1561

Open sprunk opened 1 week ago

sprunk commented 1 week ago

User story

Reading an image has many use cases that would be useful in synced.

In particular, the engine currently implements game design via the metalmap being part of the map format. Making it possible to read resource distribution from a raw image would let us decouple it. Mappers would probably be happy as well.

Request & implementation remarks

Add a synced interface to read a pixel from an image file, i.e.

local r, g, b, a = Spring.ReadPixel(img, x, y)

I am not specifying what the img param should be because there are caveats:

12345swordy commented 1 week ago

Wouldn't be better to load all images from the map or the game and put it into a lua table for easy access?

sprunk commented 1 week ago

Access how? You could convert it into a 2d lua table so it's image[x][z] = {r, g, b, a} but that sounds like it would have pretty terrible perf and memory overhead. But sure, maybe there could be a Spring.ReadImageAsLuaTable("path") -> table.

12345swordy commented 1 week ago

Access it by having it load up when the game starts and close it when the game close.

sprunk commented 1 week ago

That would be bad, you'd load up a ton of garbage that you might use once and not need anymore afterwards.