Mythruna
March 28, 2024, 09:25:48 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Problem setting player's position.  (Read 7162 times)
Michael
Donators
Hero Member
***
Posts: 2166



View Profile
« on: April 11, 2015, 09:16:00 AM »

I've been working on a script for setting the player's location to where they last logged off for single player (like on a multi-player server). I've been able to find things and do stuff, but it has about a 50% success rate.

I've been tracing everything to see if there's an issue in something somewhere, and since last night I was expecting a multi-threading issue, but that's not the case.

I've traced it to here, that finally calls the position setting (this is in case you don't really remember how it was last programmed):
Code:
this.client.initialize();
this.client.start();

the this.client.initialize() calls the original setLocation to set the position to 512, 512, 80:
Code:
setLocation(512.5F, 512.5F, 80.0F);

Then, it will call the this.client.start(); method, and it will publish the playerJoined event, nearing the end of the method (and that should be where I come in. Smiley )

After all of that, I made sure things are set up properly and such, and here is a screenshot of an unsuccessful set position:



The debug messages should be clear. THe first line is the current position, which was the one that was manually set; the Last location is the one loaded from the file, and what I tried setting the player's location to.

Now for my code, if you feel it's necessary:

Code:
// This here was a test to see if there was a threading issue.
// If this were to be a Vector3f with positions of 0 on all axis,
// it would verify this thought.
Vector3f currentPos = gameClient.getLocation()
if (currentPos == null) currentPos = new Vector3f(0f, 0f, 0f)
console.echo(currentPos.x + ", " + currentPos.y + ", " + currentPos.z)

Vector3f pos = Manager.location // gets the Last Location.
if (pos != null) {
console.echo("setting position")
console.echo(pos.x + "," + pos.y + "," + pos.z)
        // Position set.
gameClient.setLocation(pos.x, pos.y, pos.z)
}
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #1 on: April 11, 2015, 11:14:19 AM »

Not sure what's going on... but threading shouldn't be an issue because all such commands are run by the same thread and should be inline with the game loop.

Note: you should be able to use setLocation() and getLocation() directly instead of hitting gameClient.  It won't fix your problem but knowing about those is better for writing scripts that would work in both single player and multiplayer.

It's likely that in single player something is coming along and resetting the position when the game starts and it is overriding your setting.  There is a weird dance that the code does with gameClient.setLocation() with respect to the background game thread and stuff... and it doesn't really know that you are already on the right thread.

If that's the case then you might be able to queue it up to run in the next game loop pass.  Something like:
systems.simulation.addCommand(new mythruna.sim.SimCommand() {
    public void execute( GameSimulation sim, long time, long delta ) {
        // Do the stuff
    }
};

The stuff in execute() will be run in the game loop on the next pass.

If that doesn't fix it then it's because it can't ever work... but since I have single player /tp command for debugging it must work at some point.

Camera to player movement handling is 1000x different in the new engine as it's all handled by the physics engine.  So on the one hand, warping will be even trickier in that case... but on the other hand it will be identical in multiplayer and single player at least.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!