Revert "Allow markers to be used as light sources (#9733)" (#10490)

This reverts commit 8626082068.
This commit is contained in:
Anuken
2025-02-10 14:24:46 -05:00
committed by GitHub
parent a3987fde71
commit 7a6222aa18
12 changed files with 68 additions and 196 deletions

View File

@@ -320,37 +320,6 @@ public class Renderer implements ApplicationListener{
}
}
//draw objective markers
float scaleFactor = 4f / renderer.getDisplayScale();
state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers){
if(marker.world != -1){
marker.draw(marker.autoscale ? scaleFactor : 1);
}
}
});
for(var marker : state.markers.worldMarkers){
marker.draw(marker.autoscale ? scaleFactor : 1);
}
Draw.reset();
lights.add(() -> {
state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers){
if(marker.light != -1){
marker.drawLight(marker.autoscale ? scaleFactor : 1);
}
}
});
for(var marker : state.markers.lightMarkers){
marker.drawLight(marker.autoscale ? scaleFactor : 1);
}
Draw.reset();
});
if(state.rules.lighting && drawLight){
Draw.draw(Layer.light, lights::draw);
}
@@ -384,6 +353,23 @@ public class Renderer implements ApplicationListener{
});
}
float scaleFactor = 4f / renderer.getDisplayScale();
//draw objective markers
state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers){
if(marker.world){
marker.draw(marker.autoscale ? scaleFactor : 1);
}
}
});
for(var marker : state.markers){
if(marker.world){
marker.draw(marker.autoscale ? scaleFactor : 1);
}
}
Draw.reset();
Draw.draw(Layer.overlayUI, overlays::drawTop);

View File

@@ -302,11 +302,6 @@ public class MapObjectivesDialog extends BaseDialog{
}).growX().fillY();
});
setInterpreter(IndexBool.class, int.class, (cont, name, type, field, remover, indexer, get, set) -> {
getInterpreter(Boolean.class).build(cont, name, type, field, remover, indexer, () -> get.get() != -1, v -> set.get(v ? +1 : -1));
});
// Special data structure interpreters.
// Instantiate default `Seq`s with a reflectively allocated array.
setProvider(Seq.class, (type, cons) -> cons.get(new Seq<>(type.element.raw)));

View File

@@ -1,37 +1,42 @@
package mindustry.game;
import arc.func.*;
import arc.struct.*;
import arc.util.*;
import mindustry.game.MapObjectives.*;
import mindustry.io.*;
import java.io.*;
import java.util.*;
public class MapMarkers{
public class MapMarkers implements Iterable<ObjectiveMarker>{
/** Maps marker unique ID to marker. */
private IntMap<ObjectiveMarker> map = new IntMap<>();
public Seq<ObjectiveMarker> worldMarkers = new Seq<>(false);
public Seq<ObjectiveMarker> mapMarkers = new Seq<>(false);
public Seq<ObjectiveMarker> lightMarkers = new Seq<>(false);
/** Sequential list of markers. This allows for faster iteration than a map. */
private Seq<ObjectiveMarker> all = new Seq<>(false);
public void add(int id, ObjectiveMarker marker){
if(marker == null) return;
var prev = map.put(id, marker);
setMarker(worldMarkers, marker, prev, m -> m.world, (m, i) -> m.world = i);
setMarker(mapMarkers, marker, prev, m -> m.minimap, (m, i) -> m.minimap = i);
setMarker(lightMarkers, marker, prev, m -> m.light, (m, i) -> m.light = i);
var prev = map.put(id, marker);
if(prev != null){
all.set(prev.arrayIndex, marker);
}else{
all.add(marker);
marker.arrayIndex = all.size - 1;
}
}
public void remove(int id){
var prev = map.remove(id);
if(prev != null){
remove(worldMarkers, prev.world, (m, i) -> m.world = i);
remove(mapMarkers, prev.minimap, (m, i) -> m.minimap = i);
remove(lightMarkers, prev.light, (m, i) -> m.light = i);
if(all.size > prev.arrayIndex + 1){ //there needs to be something above the index to replace it with
all.remove(prev.arrayIndex);
//update its index
all.get(prev.arrayIndex).arrayIndex = prev.arrayIndex;
}else{
//no sense updating the index of the replaced element when it was not replaced
all.remove(prev.arrayIndex);
}
}
}
@@ -44,7 +49,7 @@ public class MapMarkers{
}
public int size(){
return map.size;
return all.size;
}
public void write(DataOutput stream) throws IOException{
@@ -52,64 +57,16 @@ public class MapMarkers{
}
public void read(DataInput stream) throws IOException{
worldMarkers.clear();
mapMarkers.clear();
lightMarkers.clear();
all.clear();
map = JsonIO.readBytes(IntMap.class, ObjectiveMarker.class, (DataInputStream)stream);
for(var entry : map.entries()){
var marker = entry.value;
if(marker.world != -1) marker.world = worldMarkers.add(marker).size - 1;
if(marker.minimap != -1) marker.minimap = mapMarkers.add(marker).size - 1;
if(marker.light != -1) marker.light = lightMarkers.add(marker).size - 1;
all.add(entry.value);
entry.value.arrayIndex = all.size - 1;
}
}
public interface MarkerSetter{
void set(ObjectiveMarker marker, int index);
@Override
public Iterator<ObjectiveMarker> iterator(){
return all.iterator();
}
public void updateMarker(Seq<ObjectiveMarker> markers, ObjectiveMarker marker, boolean visible, Intf<ObjectiveMarker> getter, MarkerSetter setter){
if((getter.get(marker) != -1) == visible) return; // nothing to change
if(!visible){
setter.set(markers.peek(), getter.get(marker));
markers.remove(getter.get(marker));
setter.set(marker, -1);
}else{
setter.set(marker, markers.size);
markers.add(marker);
}
}
private void setMarker(Seq<ObjectiveMarker> markers, ObjectiveMarker curr, ObjectiveMarker prev, Intf<ObjectiveMarker> getter, MarkerSetter setter){
int currIndex = getter.get(curr);
if(prev != null && getter.get(prev) != -1){
int prevIndex = getter.get(prev);
if(currIndex != -1){
// both markers visible, replace previous with current
setter.set(curr, prevIndex);
markers.set(prevIndex, curr);
}else{
// previous marker visible but not current
setter.set(markers.peek(), prevIndex);
markers.remove(prevIndex);
}
}else{
if(currIndex != -1){
setter.set(curr, markers.size);
markers.add(curr);
}
}
}
private void remove(Seq<ObjectiveMarker> markers, int index, MarkerSetter setter){
if(index != -1){
setter.set(markers.peek(), index);
markers.remove(index);
}
}
}

View File

@@ -65,8 +65,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
TextMarker::new,
LineMarker::new,
TextureMarker::new,
QuadMarker::new,
LightMarker::new
QuadMarker::new
);
registerLegacyMarker("Minimap", PointMarker::new);
@@ -621,12 +620,13 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
/** Marker used for drawing various content to indicate something along with an objective. Mostly used as UI overlay. */
public static abstract class ObjectiveMarker{
/** Whether to display marker in the world. Do not modify directly if added, use control() instead. */
public @IndexBool int world = 1;
/** Whether to display marker on the minimap. Do not modify directly if added, use control() instead. */
public @IndexBool int minimap = -1;
/** Whether to use the marker as light. Do not modify directly if added, use control() instead. */
public @IndexBool int light = -1;
/** Internal use only! Do not access. */
public transient int arrayIndex;
/** Whether to display marker in the world. */
public boolean world = true;
/** Whether to display marker on minimap. */
public boolean minimap = false;
/** Whether to scale marker corresponding to player's zoom level. */
public boolean autoscale = false;
/** On which z-sorting layer is marker drawn. */
@@ -634,18 +634,13 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public void draw(float scaleFactor){}
public void drawLight(float scaleFactor){
draw(scaleFactor);
}
/** Control marker with world processor code. Ignores NaN (null) values. */
public void control(LMarkerControl type, double p1, double p2, double p3){
if(Double.isNaN(p1)) return;
switch(type){
case world -> state.markers.updateMarker(state.markers.worldMarkers, this, !Mathf.equal((float)p1, 0f), m -> m.world, (m, i) -> m.world = i);
case minimap -> state.markers.updateMarker(state.markers.mapMarkers, this, !Mathf.equal((float)p1, 0f), m -> m.minimap, (m, i) -> m.minimap = i);
case light -> state.markers.updateMarker(state.markers.lightMarkers, this, !Mathf.equal((float)p1, 0f), m -> m.light, (m, i) -> m.light = i);
case world -> world = !Mathf.equal((float)p1, 0f);
case minimap -> minimap = !Mathf.equal((float)p1, 0f);
case autoscale -> autoscale = !Mathf.equal((float)p1, 0f);
case drawLayer -> drawLayer = (float)p1;
}
@@ -847,13 +842,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
Draw.z(drawLayer);
Lines.stroke(Scl.scl((1f - fin) * stroke + 0.1f), color);
Lines.circle(pos.x, pos.y, rad * fin);
}
@Override
public void drawLight(float scaleFactor){
float rad = radius * tilesize * scaleFactor;
renderer.lights.add(pos.x, pos.y, radius, color, color.a);
Draw.reset();
}
@Override
@@ -911,6 +901,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
Fill.arc(pos.x, pos.y, radius * scaleFactor, (startAngle - endAngle) / 360f, rotation + endAngle, sides);
}
}
Draw.reset();
}
@Override
@@ -1051,11 +1043,6 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
Lines.line(pos.x, pos.y, color1, endPos.x, endPos.y, color2);
}
@Override
public void drawLight(float scaleFactor){
renderer.lights.line(pos.x, pos.y, endPos.x, endPos.y, stroke, color1, color1.a);
}
@Override
public void control(LMarkerControl type, double p1, double p2, double p3){
super.control(type, p1, p2, p3);
@@ -1260,48 +1247,6 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
}
/** Displays a single point light. */
public static class LightMarker extends PosMarker{
public float radius = 5f;
public Color color = Color.valueOf("ffd37f");
public LightMarker(int x, int y){
this.pos.set(x, y);
}
public LightMarker(int x, int y, Color color){
this.pos.set(x, y);
this.color = color;
}
public LightMarker(int x, int y, float radius, Color color){
this.pos.set(x, y);
this.radius = radius;
this.color = color;
}
public LightMarker(){}
@Override
public void drawLight(float scaleFactor){
float rad = radius * tilesize * scaleFactor;
renderer.lights.add(pos.x, pos.y, radius, color, color.a);
}
@Override
public void control(LMarkerControl type, double p1, double p2, double p3){
super.control(type, p1, p2, p3);
if(!Double.isNaN(p1)){
switch(type){
case radius -> radius = (float)p1;
case color -> color.fromDouble(p1);
}
}
}
}
private static void lookupRegion(String name, TextureRegion out){
TextureRegion region = Core.atlas.find(name);
if(region.found()){
@@ -1330,11 +1275,6 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Retention(RUNTIME)
public @interface Vertices{}
/** For {@code int}; treats it as a boolean with -1 for false and any other value for true (defaulting to 1) */
@Target(FIELD)
@Retention(RUNTIME)
public @interface IndexBool{}
/** For {@code byte}; treats it as a world label flag. */
@Target(FIELD)
@Retention(RUNTIME)

View File

@@ -180,8 +180,6 @@ public class Rules{
public boolean lighting = false;
/** Ambient light color, used when lighting is enabled. */
public Color ambientLight = new Color(0.01f, 0.01f, 0.04f, 0.99f);
/** Whether units produce light when lighting is enabled. */
public boolean unitLight = true;
/** team of the player by default. */
public Team defaultTeam = Team.sharded;
/** team of the enemy in waves/sectors. */

View File

@@ -262,15 +262,17 @@ public class MinimapRenderer{
//TODO autoscale markers
state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers){
if(marker.minimap != -1){
if(marker.minimap){
marker.draw(1);
}
}
});
for(var marker : state.markers.mapMarkers){
marker.draw(1);
for(var marker : state.markers){
if(marker.minimap){
marker.draw(1);
}
}
Draw.reset();
Draw.trans(Tmp.m2);
}

View File

@@ -1548,7 +1548,6 @@ public class LExecutor{
}
}
case ambientLight -> state.rules.ambientLight.fromDouble(value.num());
case unitLight -> state.rules.unitLight = value.bool();
case solarMultiplier -> state.rules.solarMultiplier = Math.max(value.numf(), 0f);
case dragMultiplier -> state.rules.dragMultiplier = Math.max(value.numf(), 0f);
case ban -> {

View File

@@ -4,7 +4,6 @@ public enum LMarkerControl{
remove,
world("true/false"),
minimap("true/false"),
light("true/false"),
autoscale("true/false"),
pos("x", "y"),
endPos("x", "y"),

View File

@@ -15,7 +15,6 @@ public enum LogicRule{
lighting,
canGameOver,
ambientLight,
unitLight,
solarMultiplier,
dragMultiplier,
ban,

View File

@@ -1547,7 +1547,7 @@ public class UnitType extends UnlockableContent implements Senseable{
}
public void drawLight(Unit unit){
if(lightRadius > 0 && state.rules.unitLight){
if(lightRadius > 0){
Drawf.light(unit.x, unit.y, lightRadius, lightColor, lightOpacity);
}
}

View File

@@ -221,11 +221,6 @@ public class CustomRulesDialog extends BaseDialog{
number("@rules.solarmultiplier", f -> rules.solarMultiplier = f, () -> rules.solarMultiplier);
if(Core.bundle.get("rules.weather").toLowerCase().contains(ruleSearch)){
current.button("@rules.weather", this::weatherDialog).width(250f).left().row();
}
category("light");
if(Core.bundle.get("rules.ambientlight").toLowerCase().contains(ruleSearch)){
current.button(b -> {
b.left();
@@ -237,7 +232,11 @@ public class CustomRulesDialog extends BaseDialog{
b.add("@rules.ambientlight");
}, () -> ui.picker.show(rules.ambientLight, rules.ambientLight::set)).left().width(250f).row();
}
check("@rules.lighting.unitlight", b -> rules.unitLight = b, () -> rules.unitLight);
if(Core.bundle.get("rules.weather").toLowerCase().contains(ruleSearch)){
current.button("@rules.weather", this::weatherDialog).width(250f).left().row();
}
category("planet");
if(Core.bundle.get("rules.title.planet").toLowerCase().contains(ruleSearch)){