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

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

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions core/assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
@@ -1438,10 +1438,8 @@ rules.title.unit = Units
rules.title.experimental = Experimental
rules.title.environment = Environment
rules.title.teams = Teams
rules.title.light = Lighting
rules.title.planet = Planet
rules.lighting = Lighting
rules.lighting.unitlight = Unit Lighting
rules.fog = Fog of War
rules.invasions = Enemy Sector Invasions
rules.legacylaunchpads = Legacy Launch Pad Mechanics
48 changes: 17 additions & 31 deletions core/src/mindustry/core/Renderer.java
Original file line number Diff line number Diff line change
@@ -320,37 +320,6 @@ public void draw(){
}
}

//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 void draw(){
});
}

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);
5 changes: 0 additions & 5 deletions core/src/mindustry/editor/MapObjectivesDialog.java
Original file line number Diff line number Diff line change
@@ -302,11 +302,6 @@ cont, name, new TypeInfo(int.class),
}).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)));
95 changes: 26 additions & 69 deletions core/src/mindustry/game/MapMarkers.java
Original file line number Diff line number Diff line change
@@ -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,72 +49,24 @@ public boolean has(int id){
}

public int size(){
return map.size;
return all.size;
}

public void write(DataOutput stream) throws IOException{
JsonIO.writeBytes(map, ObjectiveMarker.class, (DataOutputStream)stream);
}

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;
}
}

public interface MarkerSetter{
void set(ObjectiveMarker marker, int index);
}

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);
}
all.add(entry.value);
entry.value.arrayIndex = all.size - 1;
}
}

private void remove(Seq<ObjectiveMarker> markers, int index, MarkerSetter setter){
if(index != -1){
setter.set(markers.peek(), index);
markers.remove(index);
}
@Override
public Iterator<ObjectiveMarker> iterator(){
return all.iterator();
}

}
86 changes: 13 additions & 73 deletions core/src/mindustry/game/MapObjectives.java
Original file line number Diff line number Diff line change
@@ -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,31 +620,27 @@ public String text(){

/** 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. */
protected float drawLayer = Layer.overlayUI;

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 void draw(float scaleFactor){
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 void draw(float scaleFactor){
Fill.arc(pos.x, pos.y, radius * scaleFactor, (startAngle - endAngle) / 360f, rotation + endAngle, sides);
}
}

Draw.reset();
}

@Override
@@ -1051,11 +1043,6 @@ public void draw(float scaleFactor){
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 @@ private void setUv(int i, double u, double v){

}

/** 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 @@ private static void lookupRegion(String name, TextureRegion out){
@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)
2 changes: 0 additions & 2 deletions core/src/mindustry/game/Rules.java
Original file line number Diff line number Diff line change
@@ -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. */
10 changes: 6 additions & 4 deletions core/src/mindustry/graphics/MinimapRenderer.java
Original file line number Diff line number Diff line change
@@ -262,15 +262,17 @@ public void drawEntities(float x, float y, float w, float h, float scaling, bool
//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);
}
1 change: 0 additions & 1 deletion core/src/mindustry/logic/LExecutor.java
Original file line number Diff line number Diff line change
@@ -1548,7 +1548,6 @@ public void run(LExecutor exec){
}
}
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 -> {
1 change: 0 additions & 1 deletion core/src/mindustry/logic/LMarkerControl.java
Original file line number Diff line number Diff line change
@@ -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"),
1 change: 0 additions & 1 deletion core/src/mindustry/logic/LogicRule.java
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ public enum LogicRule{
lighting,
canGameOver,
ambientLight,
unitLight,
solarMultiplier,
dragMultiplier,
ban,
2 changes: 1 addition & 1 deletion core/src/mindustry/type/UnitType.java
Original file line number Diff line number Diff line change
@@ -1547,7 +1547,7 @@ public Color cellColor(Unit unit){
}

public void drawLight(Unit unit){
if(lightRadius > 0 && state.rules.unitLight){
if(lightRadius > 0){
Drawf.light(unit.x, unit.y, lightRadius, lightColor, lightOpacity);
}
}
11 changes: 5 additions & 6 deletions core/src/mindustry/ui/dialogs/CustomRulesDialog.java
Original file line number Diff line number Diff line change
@@ -221,11 +221,6 @@ void setup(){

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 @@ void setup(){
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)){