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:

      Fix key event handling issue


      Fix other event handling issue


      Fix RSServer hook


      Update world hopper to have it use OCR, thanks to Todd


      Use proper disposal of old Graphics objects


      Reformat code


      Rearrange code


      Organize code imports


      Apply around 8000 automated code refactorings


      Make preparations for Java 9


      Fix 11 various bugs


      Add more reliable debugging support


      Fix mouseEntered/Exited event dispatching bug


      Fix minimap walking bug where it opens the map


      Fix broken hooks for today's game update
        • Thanks
        • Like
      • 87 replies
    • This update will:

      Fix GE inventory item positioning bug


      Fix broken object hooks
        • Like
      • 27 replies
    • This release will:

      Fix some ClosedChannelException bug


      Fix bug in RSObject#getAllTiles


      Add game tab support for "Kourend Favour"
        • Like
      • 15 replies
    • This release will:

      Fix Settings UI placement bug


      Fix game object location bug


      Fix small layout bug making the client shift up and down


      Fix client crashing bug where loading the client with a small display area will cause the client to crash


      Fix annoying Linux bug relating to painting events and peers


      Fix settings saving bug where settings are saved to disk more often than they should


      Fix RSInterface#isBeingDrawn bug affecting a limited amount of people


      Drop Java 1.7 bytecode version for 1.8


      Important: Since the downloadable RS client uses Java 7, it will no longer be compatible with Looking Glass. To make up for this, we will add support for using other clients such as RuneLite (at a later date).


      This change was necessary to allow us to use Java 8 syntax. It also paves the way for Java 9/10/11 support.
        • Like
      • 40 replies
    • This update will:

      Fix the RSMenuNode bug which also fixes the bug with bank opening


      Fix the incorrect object positions bug


      Fix and re-enable the LG Objects API Accelerator


      Fix the RSObject#getAllTiles bug
        • Like
      • 22 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×