Log in to reply
 

Can't figure out cause of delay in calculation/showing text



  • Video (step frame-by-frame to see what I'm talking about):
    https://a.safe.moe/o1DMC.mp4

    When the purple line (steering direction) is on the green line (velocity direction) the error (difference between these two, x-component of the vectors) should be 0, but it's not 0. Seems to lag 5 frames behind.

        Vector3 steeringVector = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(vehicle, 10.0f*-sin(currentSteeringAngle), 10.0f*cos(currentSteeringAngle), 0.0f);
        GRAPHICS::DRAW_LINE(pos.x, pos.y, pos.z, steeringVector.x, steeringVector.y, steeringVector.z, 255, 0, 255, 255);
        Vector3 relSteer = ENTITY::GET_OFFSET_FROM_ENTITY_GIVEN_WORLD_COORDS(vehicle, steeringVector.x, steeringVector.y, steeringVector.z);
        Vector3 relTarget = ENTITY::GET_OFFSET_FROM_ENTITY_GIVEN_WORLD_COORDS(vehicle, travel.x, travel.y, travel.z);
    
        showDebugInfo3D(steeringVector, { "* Steering" });
        showDebugInfo3D(travel, { "* Target" });
        float error = relSteer.x - relTarget.x;
        showText(0.1, 0.2, 1.0, "RelSteer:\t" + std::to_string(relSteer.x));
        showText(0.1, 0.3, 1.0, "RelTargt:\t" + std::to_string(relTarget.x));
        showText(0.1, 0.4, 1.0, "Error:\t" + std::to_string(error));
    

    Now the strange thing is, I'm drawing the boxes with labels and the lines in the same piece of code and I use the same numbers for these as for showText.

    There's not much special behind showText and showDebugInfo3D too:

    void showText(float x, float y, float scale, const std::string &text, int font, const Color &rgba, bool outline) {
    	UI::SET_TEXT_FONT(font);
    	UI::SET_TEXT_SCALE(scale, scale);
    	UI::SET_TEXT_COLOUR(rgba.R, rgba.G, rgba.B, rgba.A);
    	UI::SET_TEXT_WRAP(0.0, 1.0);
    	UI::SET_TEXT_CENTRE(0);
    	if (outline) UI::SET_TEXT_OUTLINE();
    	UI::BEGIN_TEXT_COMMAND_DISPLAY_TEXT("STRING");
    	UI::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME((char*)text.c_str());
    	UI::END_TEXT_COMMAND_DISPLAY_TEXT(x, y);
    }
    
    void showDebugInfo3D(Vector3 location, std::vector<std::string> textLines, Color backgroundColor) {
    	float height = 0.0125f;
    
    	GRAPHICS::SET_DRAW_ORIGIN(location.x, location.y, location.z, 0);
    	int i = 0;
    
    	float szX = 0.060f;
    	for (auto line : textLines) {
    		showText(0, 0 + height * i, 0.2f, line.c_str());
    		float currWidth = getStringWidth(line, 0.2f, 0);
    		if (currWidth > szX) {
    			szX = currWidth;
    		}
    		i++;
    	}
    
    	float szY = (height * i) + 0.02f;
    	GRAPHICS::DRAW_RECT(0.027f, (height * i) / 2.0f, szX, szY,
    						backgroundColor.R, backgroundColor.G, backgroundColor.B, backgroundColor.A);
    	GRAPHICS::CLEAR_DRAW_ORIGIN();
    }
    

    Is showText delayed, or am I looking at some other problem here? The result (error) is used to set steering wheel force.



  • I'm still not sure why it was like that, but now I used a simple PID class and it works without delay, somehow. (Kp = 1, Ki = Kd = 0). Variables and such are still the same.



  • @ikt This is just a guess but couldn't BEGIN_TEXT_COMMAND_DISPLAY_TEXT and END_TEXT_COMMAND_DISPLAY_TEXT be async operations, pretty much like the old AsyncMyMethodCaller.BeginInvoke and AsyncMyMethodCaller.EndInvoke? The screen coordinates are provided with the call to END_TEXT_COMMAND_DISPLAY_TEXT. So the display does not happen before that and I can imagine a delay between this and BEGIN_TEXT_COMMAND_DISPLAY_TEXT. Idk about the framerate you get but have you tried with minimized graphics settings? I am asking because this delay seems to be outside the scope of your code.
    Sorry for my bad English.



  • No idea really. FPS is solidly 60FPS.

    You can see pretty clearly that drawTexture is faster than the text stuff, so idk what'd be happening.



  • @ikt How much of a problem is this delay? From what I see this just affects the text display and in case you are waiting for matching angles between the steering vector and the velocity vector I'd suggest you add a tolerance range anyway because of rounding errors in float values. A reasonable amount needs some research though (precision vs wait cycles).



  • @Cyron43
    Not a problem any more since my second post. There's no lag between the calculations and force feedback signal. It was something else, probably, that caused the apparent delay.

    Text lagging behind isn't really a problem, but it is useful to note that thing happening in script, and thing being displayed is not 100% matching up.



  • @ikt said in Can't figure out cause of delay in calculation/showing text:

    @Cyron43 it is useful to note that thing happening in script, and thing being displayed is not 100% matching up.

    Yeah that's good to know. Also thanks for the ShowDebugInfo3D method (if you don't mind sharing). It might come in handy. :thumbsup_tone3:


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.