Skip to content

Commit 1d7495d

Browse files
committed
Remove RenderTickets since thir main use can not easily be implemented reliably
1 parent daebd9a commit 1d7495d

File tree

5 files changed

+98
-106
lines changed

5 files changed

+98
-106
lines changed

src/main/java/de/bluecolored/bluemap/api/BlueMapAPI.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.ArrayList;
2828
import java.util.Collection;
2929
import java.util.Optional;
30+
import java.util.UUID;
3031

3132
import de.bluecolored.bluemap.api.renderer.BlueMapMap;
3233
import de.bluecolored.bluemap.api.renderer.BlueMapWorld;
@@ -44,16 +45,36 @@ public abstract class BlueMapAPI {
4445

4546
/**
4647
* Getter for all {@link BlueMapMap}s loaded by BlueMap.
47-
* @return an immutable collection of all loaded {@link BlueMapMap}s
48+
* @return an unmodifiable collection of all loaded {@link BlueMapMap}s
4849
*/
4950
public abstract Collection<BlueMapMap> getMaps();
5051

5152
/**
5253
* Getter for all {@link BlueMapWorld}s loaded by BlueMap.
53-
* @return an immutable collection of all loaded {@link BlueMapWorld}s
54+
* @return an unmodifiable collection of all loaded {@link BlueMapWorld}s
5455
*/
5556
public abstract Collection<BlueMapWorld> getWorlds();
5657

58+
/**
59+
* Getter for a {@link BlueMapWorld} loaded by BlueMap with the given {@link UUID}.
60+
*
61+
* <p><i>See the documentation of {@link BlueMapWorld#getUuid()} for more information about the nature of the worlds {@link UUID}s!</i></p>
62+
*
63+
* @see BlueMapWorld#getUuid()
64+
*
65+
* @param uuid the {@link UUID} of the world
66+
*
67+
* @return an {@link Optional} with the {@link BlueMapWorld} if it exists
68+
*/
69+
public abstract Optional<BlueMapWorld> getWorld(UUID uuid);
70+
71+
/**
72+
* Getter for a {@link BlueMapMap} loaded by BlueMap with the given id.
73+
* @param id the map id (equivalent to the id configured in BlueMap's config
74+
* @return an {@link Optional} with the {@link BlueMapMap} if it exists
75+
*/
76+
public abstract Optional<BlueMapMap> getMap(String id);
77+
5778
/**
5879
* Getter for the installed BlueMap version
5980
* @return the version-string
@@ -91,26 +112,30 @@ public static synchronized Optional<BlueMapAPI> getInstance() {
91112
* Used by BlueMap to register the API and call the listeners properly.
92113
* @param instance {@link BlueMapAPI}-instance
93114
*/
94-
static synchronized void registerInstance(BlueMapAPI instance) {
95-
if (BlueMapAPI.instance != null) throw new IllegalStateException("There already is an API instance registered!");
115+
protected static synchronized boolean registerInstance(BlueMapAPI instance) {
116+
if (BlueMapAPI.instance != null) return false;
96117

97118
BlueMapAPI.instance = instance;
98119

99120
for (BlueMapAPIListener listener : BlueMapAPI.listener) {
100121
listener.onEnable(BlueMapAPI.instance);
101122
}
123+
124+
return true;
102125
}
103126

104127
/**
105128
* Used by BlueMap to unregister the API and call the listeners properly.
106129
*/
107-
static synchronized void unregisterInstance() {
108-
if (BlueMapAPI.instance == null) throw new IllegalStateException("There is no API instance registered!");
130+
protected static synchronized boolean unregisterInstance(BlueMapAPI instance) {
131+
if (BlueMapAPI.instance != instance) return false;
109132

110133
for (BlueMapAPIListener listener : BlueMapAPI.listener) {
111134
listener.onDisable(BlueMapAPI.instance);
112135
}
113136

114137
BlueMapAPI.instance = null;
138+
139+
return true;
115140
}
116141
}

src/main/java/de/bluecolored/bluemap/api/renderer/BlueMapMap.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
import com.flowpowered.math.vector.Vector3d;
2929
import com.flowpowered.math.vector.Vector3i;
3030

31+
/**
32+
* This class represents a map that is rendered by BlueMap of a specific world ({@link BlueMapWorld}).
33+
* Each map belongs to a map configured in BlueMap's configuration file (in the <code>maps: []</code> list).
34+
*/
3135
public interface BlueMapMap {
3236

3337
/**

src/main/java/de/bluecolored/bluemap/api/renderer/BlueMapWorld.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,26 @@
2828
import java.util.Collection;
2929
import java.util.UUID;
3030

31+
/**
32+
* This class represents a world loaded by BlueMap.
33+
*/
3134
public interface BlueMapWorld {
3235

3336
/**
3437
* <p>Getter for the {@link UUID} of the world.</p>
3538
* <p>
36-
* The {@link UUID} of this world is <b>not</b> guaranteed to be consistent across reloads/restarts!
39+
* The {@link UUID}s of this worlds are <b>not</b> guaranteed to be consistent across reloads/restarts!
3740
* </p>
3841
* <p>
3942
* <b>Implementation notes:</b><br>
4043
* The used UUID highly depends on the implementation
4144
* <table>
42-
* <tr><th>Sponge</th><td>The UUID is equal to the returned UUID by World-Instances of the Sponge-API, so you can just use <code>spongeWorld.getUniqueId()</code><td><tr>
43-
* <tr><th>Bukkit</th><td>The UUID is equal to the returned UUID by World-Instances of the Bukkit-API, so you can just use <code>bukkitWorld.getUID()</code><td><tr>
45+
* <tr><th>Sponge</th><td>The UUID is equal to the returned UUID by world-instances of the Sponge-API, so you can just use <code>spongeWorld.getUniqueId()</code><td><tr>
46+
* <tr><th>Bukkit</th><td>The UUID is equal to the returned UUID by world-instances of the Bukkit-API, so you can just use <code>bukkitWorld.getUID()</code><td><tr>
4447
* <tr><th>Forge</th><td>The UUID is randomly generated, and changes on each reload/restart</code><td><tr>
4548
* <tr><th>CLI</th><td>The UUID is randomly generated, and changes on each reload/restart</code><td><tr>
4649
* </table>
50+
* </p>
4751
*
4852
* @return the {@link UUID} of the world
4953
*/
@@ -57,7 +61,7 @@ public interface BlueMapWorld {
5761

5862
/**
5963
* Getter for all {@link BlueMapMap}s for this world
60-
* @return a {@link Collection} of all {@link BlueMapMap}s for this world
64+
* @return an unmodifiable {@link Collection} of all {@link BlueMapMap}s for this world
6165
*/
6266
Collection<BlueMapMap> getMaps();
6367

src/main/java/de/bluecolored/bluemap/api/renderer/RenderTicket.java

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/main/java/de/bluecolored/bluemap/api/renderer/Renderer.java

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,89 +24,110 @@
2424
*/
2525
package de.bluecolored.bluemap.api.renderer;
2626

27-
import java.util.Collection;
28-
import java.util.HashSet;
2927
import java.util.UUID;
3028

3129
import com.flowpowered.math.vector.Vector2i;
3230
import com.flowpowered.math.vector.Vector3i;
3331

32+
/**
33+
* The {@link Renderer} is used to schedule tile-renders and process them on a number of different threads.
34+
*/
3435
public interface Renderer {
3536

3637
/**
37-
* Schedules the map-tile at this block position for all maps of this world and returns the created render-tickets.<br>
38-
* If there already is a render-ticket scheduled for a tile, the existing one is returned instead of creating a new one.
38+
* Schedules the render of the map-tile at this block position for all maps of this world.<br>
39+
* If there already is a render scheduled for one of the tiles, a second one will <b>not</b> be created.
3940
*
4041
* @param world the {@link UUID} of the {@link BlueMapWorld} to render
4142
* @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tiles will be rendered not only that block)
4243
*
43-
* @return a {@link Collection} of the scheduled {@link RenderTicket}s
44+
* @throws IllegalArgumentException if there is no world loaded with the provided {@link UUID}
4445
*/
45-
Collection<RenderTicket> render(UUID world, Vector3i blockPosition);
46+
void render(UUID world, Vector3i blockPosition);
4647

4748
/**
48-
* Schedules the map-tile at this block position for all maps of this world and returns the created render-tickets.<br>
49-
* If there already is a render-ticket scheduled for a tile, the existing one is returned instead of creating a new one.
49+
* Schedules the render of the map-tile at this block position for all maps of this world.<br>
50+
* If there already is a render scheduled for one of the tiles, a second one will <b>not</b> be created.
5051
*
5152
* @param world the {@link BlueMapWorld} to render
5253
* @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tiles will be rendered not only that block)
53-
*
54-
* @return a {@link Collection} of the scheduled {@link RenderTicket}s
5554
*/
56-
default Collection<RenderTicket> render(BlueMapWorld world, Vector3i blockPosition) {
57-
Collection<RenderTicket> tickets = new HashSet<>();
58-
55+
default void render(BlueMapWorld world, Vector3i blockPosition) {
5956
for (BlueMapMap map : world.getMaps()) {
60-
tickets.add(render(map, blockPosition));
57+
render(map, blockPosition);
6158
}
62-
63-
return tickets;
6459
}
6560

6661
/**
67-
* Schedules the map-tile at this block position and returns the created render-ticket.<br>
68-
* If there already is a render-ticket scheduled for that map-tile, the existing one is returned instead of creating a new one.
62+
* Schedules the render of the map-tile at this block position.<br>
63+
* If there already is a render scheduled for the tile, a second one will <b>not</b> be created.
6964
*
7065
* @param mapId the id of the {@link BlueMapMap} to render
7166
* @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tile will be rendered not only that block)
7267
*
7368
* @return the scheduled {@link RenderTicket}
69+
*
70+
* @throws IllegalArgumentException if there is no map loaded with the provided mapId
7471
*/
75-
RenderTicket render(String mapId, Vector3i blockPosition);
72+
void render(String mapId, Vector3i blockPosition);
7673

7774
/**
78-
* Schedules the map-tile at this block position and returns the created render-ticket.<br>
79-
* If there already is a render-ticket scheduled for that map-tile, the existing one is returned instead of creating a new one.
75+
* Schedules the render of map-tile at this block position and returns the created render-ticket.<br>
76+
* If there already is a render scheduled for the tile, a second one will <b>not</b> be created.
8077
*
8178
* @param map the {@link BlueMapMap}
8279
* @param blockPosition a {@link Vector3i} for the block-position to render (the whole map-tile will be rendered not only that block)
83-
*
84-
* @return the scheduled {@link RenderTicket}
8580
*/
86-
default RenderTicket render(BlueMapMap map, Vector3i blockPosition) {
87-
return render(map, map.posToTile(blockPosition));
81+
default void render(BlueMapMap map, Vector3i blockPosition) {
82+
render(map, map.posToTile(blockPosition));
8883
}
8984

9085
/**
91-
* Schedules the map-tile and returns the created render-ticket.<br>
92-
* If there already is a render-ticket scheduled for that map-tile, the existing one is returned instead of creating a new one.
86+
* Schedules the render of the map-tile.<br>
87+
* If there already is a render scheduled for the tile, a second one will <b>not</b> be created.
9388
*
9489
* @param mapId the id of the {@link BlueMapMap} to render
9590
* @param tile a {@link Vector2i} for the tile-position to render
9691
*
97-
* @return the scheduled {@link RenderTicket}
92+
* @throws IllegalArgumentException if there is no map loaded with the provided mapId
9893
*/
99-
RenderTicket render(String mapId, Vector2i tile);
94+
void render(String mapId, Vector2i tile);
10095

10196
/**
102-
* Schedules the map-tile and returns the created render-ticket.<br>
103-
* If there already is a render-ticket scheduled for that map-tile, the existing one is returned instead of creating a new one.
97+
* Schedules the render of the map-tile.<br>
98+
* If there already is a render scheduled for the tile, a second one will <b>not</b> be created.
10499
*
105100
* @param map the {@link BlueMapMap}
106101
* @param tile a {@link Vector2i} for the tile-position to render
107-
*
108-
* @return the scheduled {@link RenderTicket}
109102
*/
110-
RenderTicket render(BlueMapMap map, Vector2i tile);
103+
void render(BlueMapMap map, Vector2i tile);
104+
105+
/**
106+
* Getter for the current size of the render-queue.
107+
* @return the current size of the render-queue
108+
*/
109+
int renderQueueSize();
110+
111+
/**
112+
* Getter for the count of render threads.
113+
* @return the count of render threads
114+
*/
115+
int renderThreadCount();
116+
117+
/**
118+
* Whether this {@link Renderer} is currently running or paused.
119+
* @return <code>true</code> if this renderer is running
120+
*/
121+
boolean isRunning();
122+
123+
/**
124+
* Starts the renderer if it is not already running.
125+
*/
126+
void start();
127+
128+
/**
129+
* Pauses the renderer if it currently is running.
130+
*/
131+
void pause();
111132

112133
}

0 commit comments

Comments
 (0)