diff options
author | Tyler Arehart <tarehart@gmail.com> | 2019-10-02 22:40:43 -0700 |
---|---|---|
committer | Tyler Arehart <tarehart@gmail.com> | 2019-10-02 22:40:43 -0700 |
commit | 3d4ccfeb5f306679ea574e9daa76c0d4521783a0 (patch) | |
tree | 77d27113dc7e35e969d71d18f67f29b9ebaf9420 | |
parent | d5fd2c0588941f6c18117e771ee5110365d75298 (diff) |
Adding blocking FreshPacket functions to the interface dll to minimize latency and simplify tick logic.fresh-master
20 files changed, 189 insertions, 43 deletions
diff --git a/build.gradle b/build.gradle index 29168cc6..9b23d480 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ dependencies { } project.setGroup('org.rlbot.commons') -project.setVersion('1.9.0') +project.setVersion('1.9.1') def pythonRoot = './src/main/python/' diff --git a/src/main/cpp/RLBotInterface/CMakeLists.txt b/src/main/cpp/RLBotInterface/CMakeLists.txt index c89318e9..5d09bfe6 100644 --- a/src/main/cpp/RLBotInterface/CMakeLists.txt +++ b/src/main/cpp/RLBotInterface/CMakeLists.txt @@ -22,9 +22,9 @@ file(GLOB_RECURSE rlbotmessages_sources ${CMAKE_CURRENT_SOURCE_DIR}/src/RLBotMe add_library(RLBotMessages STATIC ${rlbotmessages_sources}) target_include_directories(RLBotMessages PRIVATE - src/RLBotMessages - ${rlbot_generated} - ${flatbuffers} + src/RLBotMessages + ${rlbot_generated} + ${flatbuffers} ${Boost_INCLUDE_DIRS}) target_link_libraries(RLBotMessages ${Boost_LIBRARIES}) target_compile_features(RLBotMessages PRIVATE cxx_std_17) @@ -40,8 +40,8 @@ add_library(RLBotInterface SHARED ${rlbotinterface_sources}) target_include_directories(RLBotInterface PRIVATE src/RLBotInterface src/RLBotMessages - ${rlbot_generated} - ${flatbuffers} + ${rlbot_generated} + ${flatbuffers} ${Boost_INCLUDE_DIRS}) if (UNIX) @@ -61,8 +61,8 @@ add_executable(RLBot ${rlbot_sources} ${rlu_sources}) target_include_directories(RLBot PRIVATE src/RLBot src/RLBotMessages - ${rlbot_generated} - ${flatbuffers} + ${rlbot_generated} + ${flatbuffers} ${Boost_INCLUDE_DIRS} ${rlu_include}) @@ -77,14 +77,18 @@ target_compile_features(RLBot PRIVATE cxx_std_17) if (WIN32) # Set target version to windows xp. This should in theory work as a minimum supported platform. target_compile_definitions(RLBot PRIVATE _WIN32_WINNT=0x501) + + add_custom_command(TARGET RLBotMessages + PRE_BUILD + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}\\src\\RLBotMessages\\generate-flatbuffers.bat ) endif() # ---- InterfaceTester ---- file(GLOB_RECURSE interfacetester_sources ${CMAKE_CURRENT_SOURCE_DIR}/src/InterfaceTester/*.?pp) add_executable(InterfaceTester ${interfacetester_sources}) -target_include_directories(InterfaceTester PRIVATE - src/InterfaceTester +target_include_directories(InterfaceTester PRIVATE + src/InterfaceTester src/RLBotInterface src/RLBotMessages) @@ -94,4 +98,4 @@ else (UNIX) target_link_libraries(InterfaceTester RLBotInterface) endif (UNIX) -target_compile_features(InterfaceTester PRIVATE cxx_std_17)
\ No newline at end of file +target_compile_features(InterfaceTester PRIVATE cxx_std_17) diff --git a/src/main/cpp/RLBotInterface/src/RLBotInterface/GameFunctions/GamePacket.cpp b/src/main/cpp/RLBotInterface/src/RLBotInterface/GameFunctions/GamePacket.cpp index cbb5c72f..0cacef4c 100644 --- a/src/main/cpp/RLBotInterface/src/RLBotInterface/GameFunctions/GamePacket.cpp +++ b/src/main/cpp/RLBotInterface/src/RLBotInterface/GameFunctions/GamePacket.cpp @@ -1,3 +1,4 @@ +#include <thread> #include <DebugHelper.hpp> #include "GamePacket.hpp" @@ -11,6 +12,9 @@ namespace GameFunctions BoostUtilities::SharedMemReader* pFlatTickMem = nullptr; BoostUtilities::SharedMemReader* pPhysicsTickMem = nullptr; BoostUtilities::SharedMemReader* pMatchSettingsReader = nullptr; + BoostUtilities::SharedByteReader* pFrameCountReader = nullptr; + + static std::map<int, char> frame_counts; ByteBuffer MakeEmptyBuffer() { @@ -26,6 +30,7 @@ namespace GameFunctions pFlatTickMem = new BoostUtilities::SharedMemReader(BoostConstants::GameDataFlatName); pPhysicsTickMem = new BoostUtilities::SharedMemReader(BoostConstants::PhysicsTickFlatName); pMatchSettingsReader = new BoostUtilities::SharedMemReader(BoostConstants::MatchSettingsName); + pFrameCountReader = new BoostUtilities::SharedByteReader(BoostConstants::FrameCountName); } void Uninitialize_GamePacket() @@ -111,4 +116,49 @@ namespace GameFunctions } return pMatchSettingsReader->fetchData(); } + + extern "C" DLL_EXPORT char RLBOT_CORE_API GetFrameCount() + { + if (!pFrameCountReader) + { + return 0; + } + return pFrameCountReader->fetchByte(); + } + + static const int sleep_microseconds = 500; + + void waitForFrame(int timeoutMillis, int key) + { + auto start = std::chrono::system_clock::now(); + for (int i = 0; i < timeoutMillis * 1000 / sleep_microseconds; i++) { + int frameCount = GetFrameCount(); + if (frameCount != frame_counts[key]) + { + frame_counts[key] = frameCount; + break; + } + auto now = std::chrono::system_clock::now(); + std::chrono::duration<double> diff = now - start; + if (diff.count() * 1000 > timeoutMillis) + { + // Sometimes sleep_for takes longer than expected, and also GetFrameCount() + // takes a little time. Use the system clock to properly respect the timeout. + break; + } + std::this_thread::sleep_for(std::chrono::microseconds(sleep_microseconds)); + } + } + + extern "C" DLL_EXPORT ByteBuffer RLBOT_CORE_API FreshLiveDataPacketFlatbuffer(int timeoutMillis, int key) + { + waitForFrame(timeoutMillis, key); + return UpdateLiveDataPacketFlatbuffer(); + } + + extern "C" DLL_EXPORT RLBotCoreStatus RLBOT_CORE_API FreshLiveDataPacket(LiveDataPacket* pLiveData, int timeoutMillis, int key) + { + waitForFrame(timeoutMillis, key); + return UpdateLiveDataPacket(pLiveData); + } }
\ No newline at end of file diff --git a/src/main/cpp/RLBotInterface/src/RLBotInterface/GameFunctions/GamePacket.hpp b/src/main/cpp/RLBotInterface/src/RLBotInterface/GameFunctions/GamePacket.hpp index 6c3a03b7..4bdfee82 100644 --- a/src/main/cpp/RLBotInterface/src/RLBotInterface/GameFunctions/GamePacket.hpp +++ b/src/main/cpp/RLBotInterface/src/RLBotInterface/GameFunctions/GamePacket.hpp @@ -21,10 +21,13 @@ extern "C" DLL_EXPORT ByteBuffer RLBOT_CORE_API UpdateFieldInfoFlatbuffer(); DLL_EXPORT RLBotCoreStatus RLBOT_CORE_API UpdateFieldInfo(FieldInfo* pFieldInfo); DLL_EXPORT ByteBuffer RLBOT_CORE_API UpdateLiveDataPacketFlatbuffer(); + DLL_EXPORT ByteBuffer RLBOT_CORE_API FreshLiveDataPacketFlatbuffer(int timeoutMillis, int key); DLL_EXPORT RLBotCoreStatus RLBOT_CORE_API UpdateLiveDataPacket(LiveDataPacket* pLiveData); + DLL_EXPORT RLBotCoreStatus RLBOT_CORE_API FreshLiveDataPacket(LiveDataPacket* pLiveData, int timeoutMillis, int key); DLL_EXPORT ByteBuffer RLBOT_CORE_API UpdateRigidBodyTickFlatbuffer(); DLL_EXPORT RLBotCoreStatus RLBOT_CORE_API UpdateRigidBodyTick(RigidBodyTick* rigidBodyTick); DLL_EXPORT ByteBuffer RLBOT_CORE_API GetMatchSettings(); + DLL_EXPORT char RLBOT_CORE_API GetFrameCount(); } #ifdef __cplusplus diff --git a/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostConstants.cpp b/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostConstants.cpp index eb2c2f9b..03c04f81 100644 --- a/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostConstants.cpp +++ b/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostConstants.cpp @@ -39,6 +39,9 @@ namespace BoostConstants // Reading the match settings back out const char* MatchSettingsName = "matchSettings"; + // Location to store the number of frames processed by RLBot + const char* FrameCountName = "frameCount"; + std::string buildSharedMemName(const char* baseName) { std::string name(baseName); name.append("-SharedMem"); diff --git a/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostConstants.hpp b/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostConstants.hpp index c1089952..a09c371b 100644 --- a/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostConstants.hpp +++ b/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostConstants.hpp @@ -36,6 +36,9 @@ namespace BoostConstants // Reading the match settings back out extern const char* MatchSettingsName; + // Location to store the number of frames processed by RLBot + extern const char* FrameCountName; + std::string buildSharedMemName(const char* baseName); std::string buildMutexName(const char* baseName); }; diff --git a/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostUtilities.cpp b/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostUtilities.cpp index 27ca5841..43132de4 100644 --- a/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostUtilities.cpp +++ b/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostUtilities.cpp @@ -116,4 +116,54 @@ namespace BoostUtilities return RLBotCoreStatus::Success; } + SharedByteReader::SharedByteReader(const char* name) + { + // The intermediate variables in this function are necessary for some reason. + std::string sharedMemName = BoostConstants::buildSharedMemName(name); + const char* sharedMemChar = sharedMemName.c_str(); + pSharedMem = new boost::interprocess::shared_memory_object(boost::interprocess::open_only, sharedMemChar, boost::interprocess::read_only); + } + + char SharedByteReader::fetchByte() + { + boost::interprocess::offset_t size; + pSharedMem->get_size(size); + + if (size == 0) + { + // Bail out early because mapped_region will freak out if size is zero. + return 0; + } + + boost::interprocess::mapped_region region(*pSharedMem, boost::interprocess::read_only); + unsigned char *buffer = new unsigned char[1]; + memcpy(buffer, region.get_address(), 1); + return buffer[0]; + } + + SharedByteWriter::SharedByteWriter(const char* name) + { + // The intermediate variables in this function are necessary for some reason. + + pMemName = name; + + std::string sharedMemName = BoostConstants::buildSharedMemName(name); + const char* sharedMemChar = sharedMemName.c_str(); + boost::interprocess::shared_memory_object::remove(sharedMemChar); + pSharedMem = new boost::interprocess::shared_memory_object(boost::interprocess::create_only, sharedMemChar, boost::interprocess::read_write); + pSharedMem->truncate(1); + } + + SharedByteWriter::~SharedByteWriter() + { + boost::interprocess::shared_memory_object::remove(pSharedMem->get_name()); + } + + void SharedByteWriter::writeByte(char data) + { + char dataArr[] = { data }; + boost::interprocess::mapped_region region(*pSharedMem, boost::interprocess::read_write); + std::memcpy(region.get_address(), dataArr, 1); + } + } diff --git a/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostUtilities.hpp b/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostUtilities.hpp index cdd65d70..cb315d59 100644 --- a/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostUtilities.hpp +++ b/src/main/cpp/RLBotInterface/src/RLBotMessages/BoostUtilities/BoostUtilities.hpp @@ -58,6 +58,28 @@ namespace BoostUtilities ~SharedMemWriter(); void writeData(void* pAddress, int size); }; + + class SharedByteReader + { + private: + boost::interprocess::shared_memory_object* pSharedMem; + + public: + SharedByteReader(const char* pName); + char fetchByte(); + }; + + class SharedByteWriter + { + private: + boost::interprocess::shared_memory_object* pSharedMem; + const char* pMemName; + + public: + SharedByteWriter(const char* pName); + ~SharedByteWriter(); + void writeByte(char data); + }; } #endif
\ No newline at end of file diff --git a/src/main/java/rlbot/cppinterop/RLBotDll.java b/src/main/java/rlbot/cppinterop/RLBotDll.java index fb5c849c..6648115a 100644 --- a/src/main/java/rlbot/cppinterop/RLBotDll.java +++ b/src/main/java/rlbot/cppinterop/RLBotDll.java @@ -32,6 +32,7 @@ public class RLBotDll { private static final String DLL_NAME_SANS_EXTENSION_32 = "RLBot_Core_Interface_32"; private static native ByteBufferStruct UpdateLiveDataPacketFlatbuffer(); + private static native ByteBufferStruct FreshLiveDataPacketFlatbuffer(int timeoutMillis, int key); private static native int UpdatePlayerInputFlatbuffer(Pointer ptr, int size); private static native ByteBufferStruct UpdateFieldInfoFlatbuffer(); private static native int RenderGroup(Pointer ptr, int size); @@ -121,7 +122,7 @@ public class RLBotDll { */ public static GameTickPacket getFlatbufferPacket() throws RLBotInterfaceException { try { - final ByteBufferStruct struct = UpdateLiveDataPacketFlatbuffer(); + final ByteBufferStruct struct = FreshLiveDataPacketFlatbuffer(1000, 0); if (struct.size < 4) { throw new RLBotInterfaceException("Flatbuffer packet is too small, match is probably not running!"); } diff --git a/src/main/java/rlbot/gamestate/DesiredVector3.java b/src/main/java/rlbot/gamestate/DesiredVector3.java index 31c07497..ec655b88 100644 --- a/src/main/java/rlbot/gamestate/DesiredVector3.java +++ b/src/main/java/rlbot/gamestate/DesiredVector3.java @@ -23,12 +23,12 @@ public class DesiredVector3 { public Float getX() { return x; } - + /** * @returns {@code true} If x is not null. */ public boolean hasX() { - return x != null + return x != null; } public DesiredVector3 withX(Float x) { @@ -39,12 +39,12 @@ public class DesiredVector3 { public Float getY() { return y; } - + /** * @returns {@code true} If y is not null. */ public boolean hasY() { - return y != null + return y != null; } public DesiredVector3 withY(Float y) { @@ -55,12 +55,12 @@ public class DesiredVector3 { public Float getZ() { return z; } - + /** * @returns {@code true} If z is not null. */ public boolean hasZ() { - return z != null + return z != null; } public DesiredVector3 withZ(Float z) { diff --git a/src/main/java/rlbot/manager/BotManager.java b/src/main/java/rlbot/manager/BotManager.java index c355e518..1dc4d8a8 100644 --- a/src/main/java/rlbot/manager/BotManager.java +++ b/src/main/java/rlbot/manager/BotManager.java @@ -6,6 +6,8 @@ import rlbot.cppinterop.RLBotDll; import rlbot.flat.GameTickPacket; import java.io.IOException; +import java.time.Duration; +import java.time.Instant; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -89,20 +91,15 @@ public class BotManager { while (keepRunning) { try { + Instant before = Instant.now(); latestPacket = RLBotDll.getFlatbufferPacket(); + System.out.println(Duration.between(before, Instant.now()).toMillis()); synchronized (dinnerBell) { dinnerBell.notifyAll(); } } catch (IOException e) { e.printStackTrace(); } - - try { - // Fetch the latest game tick packet at 60 Hz. - Thread.sleep(16); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } } } diff --git a/src/main/java/rlbot/render/Renderer.java b/src/main/java/rlbot/render/Renderer.java index 3cd193fd..ef39dd89 100644 --- a/src/main/java/rlbot/render/Renderer.java +++ b/src/main/java/rlbot/render/Renderer.java @@ -72,6 +72,8 @@ public abstract class Renderer { /** * Draws a line in screen coordinates. + * + * @deprecated We unfortunately don't support 2d lines anymore! */ public void drawLine2d(java.awt.Color color, Point start, Point end) { @@ -106,6 +108,8 @@ public abstract class Renderer { /** * Draws a 2D line which starts at screen coordinates and ends at a 3D coordinate. + * + * @deprecated We unfortunately don't support 2d3d lines anymore! */ public void drawLine2d3d(java.awt.Color color, Point start, rlbot.vector.Vector3 end) { @@ -122,6 +126,8 @@ public abstract class Renderer { } /** + * WARNING: setting filled=false no longer works! + * * This draws a 2D rectangle in screen coordinates. * @param upperLeft The upper left corner of the rectangle. * @param width in pixels. @@ -145,6 +151,8 @@ public abstract class Renderer { } /** + * WARNING: setting filled=false no longer works! + * * This draws a 2D rectangle at a 3D-tracked position. * @param upperLeft The upper left corner of the rectangle. * @param width in pixels. @@ -156,6 +164,8 @@ public abstract class Renderer { } /** + * WARNING: setting filled=false no longer works! + * * This draws a 2D rectangle at a 3D-tracked position. * @param position The center of the rectangle. * @param width in pixels. diff --git a/src/main/python/rlbot/botmanager/bot_manager.py b/src/main/python/rlbot/botmanager/bot_manager.py index e84b1d2a..4d183769 100644 --- a/src/main/python/rlbot/botmanager/bot_manager.py +++ b/src/main/python/rlbot/botmanager/bot_manager.py @@ -19,7 +19,7 @@ from rlbot.utils.structures.game_interface import GameInterface from rlbot.utils.structures.game_status import RLBotCoreStatus from rlbot.utils.structures.quick_chats import send_quick_chat_flat -GAME_TICK_PACKET_POLLS_PER_SECOND = 120 # 2*60. https://en.wikipedia.org/wiki/Nyquist_rate +MAX_POLLS_PER_SECOND = 125 # Slightly higher than 120hz. The dll will sleep till the packet is fresh. MAX_AGENT_CALL_PERIOD = timedelta(seconds=1.0 / 30) # Minimum call rate when paused. REFRESH_IN_PROGRESS = 1 REFRESH_NOT_IN_PROGRESS = 0 @@ -174,7 +174,7 @@ class BotManager: self.prepare_for_run() # Create Ratelimiter - rate_limit = rate_limiter.RateLimiter(GAME_TICK_PACKET_POLLS_PER_SECOND) + rate_limit = rate_limiter.RateLimiter(MAX_POLLS_PER_SECOND) last_tick_game_time = 0 # What the tick time of the last observed tick was last_call_real_time = datetime.now() # When we last called the Agent frame_urgency = 0 # If the bot is getting called more than its preferred max rate, urgency will go negative. diff --git a/src/main/python/rlbot/botmanager/bot_manager_struct.py b/src/main/python/rlbot/botmanager/bot_manager_struct.py index 11ea3618..9868dd5a 100644 --- a/src/main/python/rlbot/botmanager/bot_manager_struct.py +++ b/src/main/python/rlbot/botmanager/bot_manager_struct.py @@ -63,7 +63,7 @@ class BotManagerStruct(BotManager): return self.game_tick_packet.game_info.seconds_elapsed def pull_data_from_game(self): - self.game_interface.update_live_data_packet(self.game_tick_packet) + self.game_interface.fresh_live_data_packet(self.game_tick_packet, 500, 0) def get_ball_prediction_struct(self): return self.game_interface.update_ball_prediction(self.ball_prediction) diff --git a/src/main/python/rlbot/dll/RLBot.exe b/src/main/python/rlbot/dll/RLBot.exe Binary files differindex 3a8896be..2aec028b 100644 --- a/src/main/python/rlbot/dll/RLBot.exe +++ b/src/main/python/rlbot/dll/RLBot.exe diff --git a/src/main/python/rlbot/dll/RLBot_Core_Interface.dll b/src/main/python/rlbot/dll/RLBot_Core_Interface.dll Binary files differindex 1ba68329..ea264439 100644 --- a/src/main/python/rlbot/dll/RLBot_Core_Interface.dll +++ b/src/main/python/rlbot/dll/RLBot_Core_Interface.dll diff --git a/src/main/python/rlbot/dll/RLBot_Core_Interface_32.dll b/src/main/python/rlbot/dll/RLBot_Core_Interface_32.dll Binary files differindex c58d62a2..9d84a8fa 100644 --- a/src/main/python/rlbot/dll/RLBot_Core_Interface_32.dll +++ b/src/main/python/rlbot/dll/RLBot_Core_Interface_32.dll diff --git a/src/main/python/rlbot/messages/__init__.py b/src/main/python/rlbot/messages/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/main/python/rlbot/messages/__init__.py diff --git a/src/main/python/rlbot/utils/structures/game_interface.py b/src/main/python/rlbot/utils/structures/game_interface.py index 708265e6..96436e4c 100644 --- a/src/main/python/rlbot/utils/structures/game_interface.py +++ b/src/main/python/rlbot/utils/structures/game_interface.py @@ -133,6 +133,14 @@ class GameInterface: func.argtypes = [] func.restype = ByteBuffer + func = self.game.GetFrameCount + func.argtypes = [] + func.restype = ctypes.c_char + + func = self.game.FreshLiveDataPacket + func.argtypes = [ctypes.POINTER(GameTickPacket), ctypes.c_int, ctypes.c_int] + func.restype = ctypes.c_int + self.renderer.setup_function_types(self.game) self.logger.debug('game interface functions are setup') @@ -145,6 +153,11 @@ class GameInterface: self.game_status(None, rlbot_status) return game_tick_packet + def fresh_live_data_packet(self, game_tick_packet: GameTickPacket, timeout_millis: int, key: int): + rlbot_status = self.game.FreshLiveDataPacket(game_tick_packet, timeout_millis, key) + self.game_status(None, rlbot_status) + return game_tick_packet + def update_field_info_packet(self, field_info_packet: FieldInfoPacket): rlbot_status = self.game.UpdateFieldInfo(field_info_packet) self.game_status(None, rlbot_status) @@ -332,3 +345,7 @@ class GameInterface: self.game.Free(byte_buffer.ptr) # Avoid a memory leak self.game_status(None, RLBotCoreStatus.Success) return MatchSettingsPacket.GetRootAsMatchSettings(proto_string, 0) + + def get_frame_count(self) -> int: + frame_count = self.game.GetFrameCount() + return int.from_bytes(frame_count, "little") diff --git a/src/test/java/rlbot/SampleBot.java b/src/test/java/rlbot/SampleBot.java index 74214348..888fc668 100644 --- a/src/test/java/rlbot/SampleBot.java +++ b/src/test/java/rlbot/SampleBot.java @@ -13,30 +13,20 @@ import rlbot.input.DropshotTile; import rlbot.input.FieldInfoManager; import rlbot.manager.BotLoopRenderer; import rlbot.output.ControlsOutput; -import rlbot.render.NamedRenderer; import rlbot.render.Renderer; import rlbot.vec.Vector2; -import java.awt.*; import java.awt.Color; import java.io.IOException; public class SampleBot extends BaseBot { - private final NamedRenderer triangleRenderer; private FieldInfoManager fieldInfoManager = new FieldInfoManager(); public SampleBot(int playerIndex, int team) { super(playerIndex, team); System.out.println("Constructed sample bot " + playerIndex); - - triangleRenderer = new NamedRenderer("Triangle" + playerIndex); - triangleRenderer.startPacket(); - triangleRenderer.drawLine2d(Color.cyan, new Point(50, 50), new Point(20, 80)); - triangleRenderer.drawLine2d(Color.cyan, new Point(20, 80), new Point(80, 80)); - triangleRenderer.drawLine2d(Color.cyan, new Point(50, 50), new Point(80, 80)); - triangleRenderer.finishAndSend(); } private ControlsOutput processInput(DataPacket input) { @@ -93,10 +83,6 @@ public class SampleBot extends BaseBot { e.printStackTrace(); } - if (input.ball.position.z > 1000) { - triangleRenderer.eraseFromScreen(); - } - try { final BallPrediction ballPrediction = RLBotDll.getBallPrediction(); @@ -110,7 +96,7 @@ public class SampleBot extends BaseBot { return new ControlsOutput() .withSteer(steer) .withThrottle(1) - .withUseItem(steer > 0); + .withUseItem(myCar.velocity.y > 0); } @Override |