use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class AbstractTileTest method testGetSelectBounds.
@Test
public void testGetSelectBounds() {
FakeWorld world = FakeWorld.newWorld("TestGetSelectBounds");
world.setBlock(0, 0, 0, block);
Tile tile = ((Tile) world.getTileEntity(0, 0, 0));
Cube cube = tile.getSelectBounds();
assertTrue(cube != null);
//TODO add check to ensure cube size and values are good
}
use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class RadioMap method updateCache.
/**
* Updates the list of receivers for this sender.
* <p>
* Make sure if you call this you clear your
* cache when the sender is no longer valid
* use {@link TileEntity#invalidate()}
* or {@link Entity#setDead()} to
* clear the cache.
* <p>
* As well make sure to call this method
* every so often. As the cache is not maintained
* often or quickly. It is only updated
* when receives are added or removed. So
* if the sender's range changes this method
* needs to be called.
* <p>
* Make sure to not call this method often
* as its a high CPU task.
*
* @param sender - object that needs to
* have receivers cache. Needs
* to have a valid {@link IRadioWaveSender#getRadioSenderRange()}
* value in order to be cached.
*/
public void updateCache(IRadioWaveSender sender) {
//Clear cache value
sender_to_receivers_cache.remove(sender);
Cube range = sender.getRadioSenderRange();
if (range != null) {
sender_to_receivers_cache.put(sender, getReceiversInRange(range, sender instanceof IRadioWaveReceiver ? (IRadioWaveReceiver) sender : (IRadioWaveReceiver) null));
}
}
use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class RadioMap method update.
/**
* Called to update data about the receiver. Used
* when the receiver's range changes.
*
* @param receiver
*/
public void update(IRadioWaveReceiver receiver) {
if (!receive_to_range.containsKey(receiver) || receive_to_range.get(receiver) == null || receive_to_range.get(receiver).equals(receiver.getRadioReceiverRange())) {
Cube range = receiver.getRadioReceiverRange();
if (range != null) {
updateChunkCache(receiver, range);
updateSenderCache(receiver, range);
}
}
}
use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class RadioMap method popMessage.
/**
* Called to send a message over the network
*
* @param sender - object that sent the message
* @param hz - frequency of the message
* @param header - descriptive header of the message, mainly an ID system
* @param data - data being sent in the message
*/
public void popMessage(IRadioWaveSender sender, float hz, String header, Object[] data) {
//Cache for senders that know they will be active
if (sender_to_receivers_cache.containsKey(sender)) {
for (IRadioWaveReceiver receiver : sender_to_receivers_cache.get(sender)) {
receiver.receiveRadioWave(hz, sender, header, data);
}
return;
}
//Receivers that have full map range, used for legacy systems mainly
for (IRadioWaveReceiver receiver : fullMapRangeReceives) {
receiver.receiveRadioWave(hz, sender, header, data);
}
//Slow way to update receives with messages
Cube range = sender.getRadioSenderRange();
if (range != null) {
//Use simpler method if the range of number of entries is small
if (//20 chunks
receive_to_chunks.size() < 200 || range.getSizeX() > 320 || range.getSizeY() > 320) {
for (IRadioWaveReceiver receiver : receive_to_chunks.keySet()) {
if (receiver != null && receiver != sender) {
Cube receiverRange = receiver.getRadioReceiverRange();
if (range.doesOverlap(receiverRange) || receiverRange.doesOverlap(range)) {
receiver.receiveRadioWave(hz, sender, header, data);
}
}
}
} else //Complex method only used if number of receive is very high, e.g. is faster~ish than the above method
{
List<ChunkCoordIntPair> coords = range.getChunkCoords();
List<IRadioWaveReceiver> receivers = new ArrayList();
for (ChunkCoordIntPair pair : coords) {
List<IRadioWaveReceiver> l = chunk_to_entities.get(pair);
if (l != null && l.size() > 0) {
for (IRadioWaveReceiver r : l) {
if (r != null && r != sender && !receivers.contains(r)) {
receivers.add(r);
}
}
}
}
for (IRadioWaveReceiver receiver : receivers) {
receiver.receiveRadioWave(hz, sender, header, data);
}
}
}
}
use of com.builtbroken.mc.imp.transform.region.Cube in project Engine by VoltzEngine-Project.
the class RadioMap method add.
public boolean add(IRadioWaveReceiver receiver) {
Cube range = receiver.getRadioReceiverRange();
if (range != null) {
if (range == RadioRegistry.INFINITE) {
if (!fullMapRangeReceives.contains(receiver)) {
fullMapRangeReceives.add(receiver);
}
return true;
}
if (!receive_to_chunks.containsKey(receiver)) {
updateChunkCache(receiver, range);
updateSenderCache(receiver, range);
return true;
}
}
return false;
}
Aggregations