Jump to content
Final Calibur

[Snippet] Asynchronous Camera API

Recommended Posts

Update: ACamera was updated on 1/11/2016. Please check the updated source if you don't have it.
 
Hello everybody,
 
So @wastedbro and I were talking and we thought it would be a good idea to make an Asynchronous Camera API for all to use. 
 
Pretty much this is used so that the bot can move the camera and do actions at the same time (such as moving the camera and walking, or moving the camera and clicking on something).
 
Not only does this simulate human behavior better, but it also alleviates the actual execution of moving the camera from the script.
 
Without further ado, here it is (50% credit to @wastedbro):
 
Methods for you to use:

  • setAngle(int angle)
  • setRotation(int rotation)
  • turnToTile(Positionable tile)

If you are simply trying to get the camera rotation or angle, use the standard TriBot Camera API for that.
 
How to use the API in your script:

  • Create a new ACamera object in your script, like so:

    • private ACamera aCamera = new ACamera(this);
  • Use the ACamera object just as you would the normal Camera API. Example:

    • aCamera.turnToTile(tile);

Note: The turnToTile method works very effectively, but the algorithm is far from refined and 100% accurate. Feel free to change it yourself, and share it with the rest of us if you would like!

FOR USERS WHO USE WORTHY'S NODE FRAMEWORK:


You can also change the Node class from this:



import org.tribot.script.Script;/** * The node framework base class. *  * @author Worthy from TriBot * */public abstract class Node {			/**	 *	This will execute the node. Essentially a "process()" method.	 */	public abstract void execute();	/**	 *	Will return whether or not the Node should execute	 * 		 * 	@[member="Return"] true if the node should execute. False if otherwise	 */	public abstract boolean validate();	}

to this:

import org.tribot.script.Script;/** * The node framework base class. *  * @author Worthy from TriBot * */public abstract class Node {	protected ACamera aCamera;        public Node(ACamera aCamera)        {            this.aCamera = aCamera;        }		/**	 *	This will execute the node. Essentially a "process()" method.	 */	public abstract void execute();	/**	 *	Will return whether or not the Node should execute	 * 		 * 	@[member="Return"] true if the node should execute. False if otherwise	 */	public abstract boolean validate();	}

By doing this, you would simply have to make an ACamera object in your main script class, and then pass it in each of your node constructors when you add them to the ArrayList in the beginning of your script. Example:

Collections.addAll(nodes, new WorldHop(aCamera), new OpenShop(aCamera), new SellItems(aCamera));

 To use the ACamera in any of your nodes, simply call:

this.aCamera


Get the code here

Edited by Final Calibur
  • Like 3

Share this post


Link to post
Share on other sites

The point of this class is to allow camera movement to be as fluid as it would be in the hands of an actual human.,

 

For example, currently there is no way to move the camera up/down AND side-to-side at the same time. This is a very common human behavior and this class allows it.

 

Also, this class is suppose to let scripters make their script click NPCs/Objects while the camera is moving, another common human behavior that is impossible with the standard API.

  • Like 1

Share this post


Link to post
Share on other sites

What's wrong with using conditions? .-. I'll admit that your method is more efficient though.

 

The problem with using conditions is that camera movement is executed in a serial fashion, as its on the same thread. As @wastedbro said, this means that there is no way to execute any action at the same exact time as moving the camera (even changing the rotation and angle at the same time).

 

This system remedies that problem, as both camera rotation and camera angle are handled on their own separate threads. You simply make the call to update the camera, and the separate threads handle the actual execution. This allows your script to do actions at the same time as moving the camera.  :D

 

I hope I answered your question sufficiently. 

Edited by Final Calibur

Share this post


Link to post
Share on other sites

Not to be rude, but shouldn't this be called synchronous camera? asynchronous means not at the same time, and for the purposes of this class, you want mouse movements and camera movements happening fluidly at the same time, yes?

 

It is asynchronous in relation to the flow of execution. Take a look at this, and also this, for a better explanation.

Share this post


Link to post
Share on other sites

Looking at the definitions of the words, those links are incorrect.

 

The issue is that you're looking at it in the wrong context.

 

As explained in the links (which are correct, by the way), execution is asynchronous in terms of "not using the same clock". I would urge you to go back and thoroughly re-read the stackoverflow link in particular, in which the comments on the top answer address your particular issue clearly and concisely.

 

If you need further explanation, do a quick google search on synchronous vs asynchronous execution. Any of the links should be able to help you understand the context.

 

In essence it's simply semantics, so I'm not going to discuss this further.

Edited by Final Calibur

Share this post


Link to post
Share on other sites

The issue is that you're looking at it in the wrong context.

 

As explained in the links (which are correct, by the way), execution is asynchronous in terms of "not using the same clock". I would urge you to go back and thoroughly re-read the stackoverflow link in particular, in which the comments on the top answer address your particular issue clearly and concisely.

 

If you need further explanation, do a quick google search on synchronous vs asynchronous execution. Any of the links should be able to help you understand the context.

 

In essence it's simply semantics, so I'm not going to discuss this further.

I must not understand the words then. To me, synchrony means happening at the same time, while asynchrony means not happening at the same time.

Share this post


Link to post
Share on other sites
Posted (edited)

Now to update my scripts to use this.... Very useful and I always cringe when my bot just sits there rotating the camera up/down THEN side to side THEN performs the action I want it to. 

@Encoded

Could you possibly help be add this to the TASK interface from your task framework tutorial? I am not quite sure how to modify it to work with constructors, since interfaces do not support constructors.

Edited by Jerminater

Share this post


Link to post
Share on other sites
4 hours ago, Jerminater said:

Now to update my scripts to use this.... Very useful and I always cringe when my bot just sits there rotating the camera up/down THEN side to side THEN performs the action I want it to. 

@Encoded

Could you possibly help be add this to the TASK interface from your task framework tutorial? I am not quite sure how to modify it to work with constructors, since interfaces do not support constructors.

You use the constructor of the class that implements the interface.

Share this post


Link to post
Share on other sites
5 minutes ago, Encoded said:

You use the constructor of the class that implements the interface.

Yes, I can do that I know. Is this the only way to do it? In OP's post, he showed how to do it with Worthy's node framework so that you just have to reference this.aCamera.xxx to use the snippet.

Doing it to the class that implements the interface is not too bad I guess. I have several scripts and classes so going through each one is a long task. Easier to just change it in one place.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Our picks

    • This release will:

      Add LG support for Runelite


      Fix NPCChat issues


      Fix a bug where the camera angle setter would just hold down a key for 5 seconds (the timeout)


      Slightly adjust the rotation via keys to be more accurate


      Add the ability for asynchronous camera movement via keys


      Make Camera rotation via mouse more fluid, with more antiban, and work much better in resizable mode


      Add a "Camera#setCamera" method, allowing the rotation and angle to be set in parallel


      Increase the likelihood of using the mouse for camera movements


      Add support for adjusting the camera to positionable entities (Positionable#adjustCameraTo)



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Thanks
        • Like
      • 36 replies
    • This update will:

      Allow for clicking through the chat box when possible (Thanks @Todd)


      Fix Combat#selectIndex (Thanks @Encoded)


      Ensure worlds stay sorted and added a check to avoid misclicks in the in-game world hopper (Thanks @erickho123)


      Fix out-dated Options API interface indices (Thanks @Todd)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Like
      • 12 replies
    • This release will:

      Fix login bot after today's game update (Thanks @JoeDezzy1)


      Fix latest in-game world hopping issues (Thanks @erickho123)


      Compact Settings UI and set location relative to TRiBot (Thanks @JoeDezzy1)


      Fix an older implementation of GrandExchange#getWindowState (Thanks @JoeDezzy1)


      Improve the preformance of NPCChat by only searching in certain interface parents (Thanks @JoeDezzy1)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      LG support for RuneLite


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Thanks
        • Like
      • 16 replies
    • This release will:

      Fix bytecode manipulation in order to prevent the modification of parameters within the Filter and Condition classes themselves (thanks @wastedbro)


      Fix NPE caused by non-null value in GE API (thanks @erickho123)


      Add and fix equals methods for api2007.types (thanks @JoeDezzy1)


      Modify Mouse#leaveGame to make the mouse leave the game from top, left, right, or bottom (thanks @erickho123)


      Add Entrana area to Ships API (thanks @erickho123)


      Fix raid prayers index/settings in Prayer API (thanks @erickho123)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Like
      • 29 replies
    • This update will:

      Implement better canvas locking/synchronization mechanism


      Fix small Login API bug


      Remove the requirement for xbooting Java classes


      Use ExecutorService to perform canvas work in parallel


      Add "Account Management" game tab to GameTab API (thanks @Encoded)


      Fix NPCChat#getMessage (thanks @Encoded )


      Fix NPCChat#selectOption (thanks @Encoded )


      Fix Banking API after today's update (thanks @Encoded )


      Fix in-game world hopper after today's update (thanks @Encoded )



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Thanks
        • Like
      • 38 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×