Editor bugfixes / Arbitrary map resizing

This commit is contained in:
Anuken
2020-06-18 14:24:22 -04:00
parent ae47f37b27
commit d38abe95f9
8 changed files with 45 additions and 53 deletions

View File

@@ -190,7 +190,7 @@ project(":desktop"){
implementation arcModule("natives:natives-box2d-desktop") implementation arcModule("natives:natives-box2d-desktop")
implementation arcModule("natives:natives-desktop") implementation arcModule("natives:natives-desktop")
implementation arcModule("natives:natives-freetype-desktop") implementation arcModule("natives:natives-freetype-desktop")
implementation arcModule("extensions:discord") implementation 'com.github.MinnDevelopment:java-discord-rpc:v2.0.1'
if(debugged()) implementation project(":debug") if(debugged()) implementation project(":debug")

View File

@@ -128,33 +128,35 @@ public class Pathfinder implements Runnable{
if(net.client()) return; if(net.client()) return;
try{ try{
queue.run(); if(state.isPlaying()){
queue.run();
//total update time no longer than maxUpdate //total update time no longer than maxUpdate
for(Flowfield data : threadList){ for(Flowfield data : threadList){
updateFrontier(data, maxUpdate / threadList.size); updateFrontier(data, maxUpdate / threadList.size);
//remove flowfields that have 'timed out' so they can be garbage collected and no longer waste space //remove flowfields that have 'timed out' so they can be garbage collected and no longer waste space
if(data.target.refreshRate() > 0 && Time.timeSinceMillis(data.lastUpdateTime) > fieldTimeout){ if(data.target.refreshRate() > 0 && Time.timeSinceMillis(data.lastUpdateTime) > fieldTimeout){
//make sure it doesn't get removed twice //make sure it doesn't get removed twice
data.lastUpdateTime = Time.millis(); data.lastUpdateTime = Time.millis();
Team team = data.team; Team team = data.team;
Core.app.post(() -> { Core.app.post(() -> {
//remove its used state //remove its used state
if(fieldMap[team.uid] != null){ if(fieldMap[team.uid] != null){
fieldMap[team.uid].remove(data.target); fieldMap[team.uid].remove(data.target);
fieldMapUsed[team.uid].remove(data.target); fieldMapUsed[team.uid].remove(data.target);
} }
//remove from main thread list //remove from main thread list
mainList.remove(data); mainList.remove(data);
}); });
queue.post(() -> { queue.post(() -> {
//remove from this thread list with a delay //remove from this thread list with a delay
threadList.remove(data); threadList.remove(data);
}); });
}
} }
} }

View File

@@ -132,10 +132,10 @@ public class Logic implements ApplicationListener{
if(!state.isCampaign()){ if(!state.isCampaign()){
for(TeamData team : state.teams.getActive()){ for(TeamData team : state.teams.getActive()){
if(team.hasCore()){ if(team.hasCore()){
Tilec entity = team.core(); TileEntity entity = team.core();
entity.items().clear(); entity.items.clear();
for(ItemStack stack : state.rules.loadout){ for(ItemStack stack : state.rules.loadout){
entity.items().add(stack.item, stack.amount); entity.items.add(stack.item, stack.amount);
} }
} }
} }

View File

@@ -2,8 +2,10 @@ package mindustry.editor;
import arc.func.*; import arc.func.*;
import arc.math.*; import arc.math.*;
import arc.scene.ui.TextField.*;
import arc.scene.ui.layout.*; import arc.scene.ui.layout.*;
import mindustry.gen.*; import arc.util.*;
import mindustry.*;
import mindustry.ui.dialogs.*; import mindustry.ui.dialogs.*;
public class MapResizeDialog extends BaseDialog{ public class MapResizeDialog extends BaseDialog{
@@ -22,21 +24,12 @@ public class MapResizeDialog extends BaseDialog{
for(boolean w : Mathf.booleans){ for(boolean w : Mathf.booleans){
table.add(w ? "$width" : "$height").padRight(8f); table.add(w ? "$width" : "$height").padRight(8f);
table.defaults().height(60f).padTop(8); table.defaults().height(60f).padTop(8);
table.button("<", () -> {
if(w)
width = move(width, -1);
else
height = move(height, -1);
}).size(60f);
table.table(Tex.button, t -> t.label(() -> (w ? width : height) + "")).width(200); Vars.platform.addDialog(table.field((w ? width : height) + "", TextFieldFilter.digitsOnly, value -> {
int val = Integer.parseInt(value);
if(w) width = val; else height = val;
}).valid(value -> Strings.canParsePostiveInt(value) && Integer.parseInt(value) <= maxSize && Integer.parseInt(value) >= minSize).get());
table.button(">", () -> {
if(w)
width = move(width, 1);
else
height = move(height, 1);
}).size(60f);
table.row(); table.row();
} }
cont.row(); cont.row();
@@ -51,8 +44,4 @@ public class MapResizeDialog extends BaseDialog{
hide(); hide();
}); });
} }
static int move(int value, int direction){
return Mathf.clamp((value / increment + direction) * increment, minSize, maxSize);
}
} }

View File

@@ -133,7 +133,7 @@ public class MinimapRenderer implements Disposable{
} }
public void update(Tile tile){ public void update(Tile tile){
if(world.isGenerating()) return; if(world.isGenerating() || !state.isGame()) return;
int color = colorFor(world.tile(tile.x, tile.y)); int color = colorFor(world.tile(tile.x, tile.y));
pixmap.draw(tile.x, pixmap.getHeight() - 1 - tile.y, color); pixmap.draw(tile.x, pixmap.getHeight() - 1 - tile.y, color);

View File

@@ -94,8 +94,10 @@ public class Sector{
return (normal.dot(light) + 1f) / 2f; return (normal.dot(light) + 1f) / 2f;
} }
/** @return the sector size, in tiles */
public int getSize(){ public int getSize(){
return (int)(rect.radius * 3200); int res = (int)(rect.radius * 3200);
return res % 2 == 0 ? res : res + 1;
} }
//TODO implement //TODO implement

View File

@@ -4,8 +4,6 @@ import arc.*;
import arc.Files.*; import arc.Files.*;
import arc.backend.sdl.*; import arc.backend.sdl.*;
import arc.backend.sdl.jni.*; import arc.backend.sdl.jni.*;
import arc.discord.*;
import arc.discord.DiscordRPC.*;
import arc.files.*; import arc.files.*;
import arc.func.*; import arc.func.*;
import arc.math.*; import arc.math.*;
@@ -13,6 +11,7 @@ import arc.struct.*;
import arc.util.*; import arc.util.*;
import arc.util.async.*; import arc.util.async.*;
import arc.util.serialization.*; import arc.util.serialization.*;
import club.minnced.discord.rpc.*;
import com.codedisaster.steamworks.*; import com.codedisaster.steamworks.*;
import mindustry.*; import mindustry.*;
import mindustry.core.*; import mindustry.core.*;
@@ -32,7 +31,8 @@ import static mindustry.Vars.*;
public class DesktopLauncher extends ClientLauncher{ public class DesktopLauncher extends ClientLauncher{
public final static String discordID = "610508934456934412"; public final static String discordID = "610508934456934412";
boolean useDiscord = OS.is64Bit && !OS.hasProp("nodiscord"), loadError = false; //discord RPC is only enabled on linux right now
boolean useDiscord = OS.is64Bit && !OS.isARM && !OS.hasProp("nodiscord"), loadError = false;
Throwable steamError; Throwable steamError;
public static void main(String[] arg){ public static void main(String[] arg){
@@ -58,9 +58,9 @@ public class DesktopLauncher extends ClientLauncher{
if(useDiscord){ if(useDiscord){
try{ try{
DiscordRPC.initialize(discordID, true, "1127400"); DiscordRPC.INSTANCE.Discord_Initialize(discordID, null, true, "1127400");
Log.info("Initialized Discord rich presence."); Log.info("Initialized Discord rich presence.");
Runtime.getRuntime().addShutdownHook(new Thread(DiscordRPC::shutdown)); Runtime.getRuntime().addShutdownHook(new Thread(DiscordRPC.INSTANCE::Discord_Shutdown));
}catch(Throwable t){ }catch(Throwable t){
useDiscord = false; useDiscord = false;
Log.err("Failed to initialize discord.", t); Log.err("Failed to initialize discord.", t);
@@ -282,7 +282,7 @@ public class DesktopLauncher extends ClientLauncher{
presence.largeImageKey = "logo"; presence.largeImageKey = "logo";
DiscordRPC.updatePresence(presence); DiscordRPC.INSTANCE.Discord_UpdatePresence(presence);
} }
if(steam){ if(steam){

View File

@@ -36,7 +36,6 @@ if(!hasProperty("release")){
':Arc:extensions:box2d', ':Arc:extensions:box2d',
':Arc:extensions:g3d', ':Arc:extensions:g3d',
':Arc:extensions:fx', ':Arc:extensions:fx',
':Arc:extensions:discord',
':Arc:natives', ':Arc:natives',
':Arc:natives:natives-desktop', ':Arc:natives:natives-desktop',
':Arc:natives:natives-android', ':Arc:natives:natives-android',