0 votes

I'm trying to make simple AI for my godot game.

There is my sources:

I'm using GDScript for quick development, I will replace critical parts by C++ code (but I need to find what parts are critical)

I have few questions:
1. Where is the performance bottle neck?
2. Is this approach good? Is it good architecture for godot project? Any comments?
3. Do I have stability problems (memory leaks, memory fragmentation)?
4. Can I modify GOAP part to increase it performance?
5. What part should be rewritten?

in Engine by (246 points)

1 Answer

0 votes

I found that performance problems caused by this function of pathfinding:

# When called, this method pops the next node off the PQ and examines all
# its edges. The method returns an enumerated value (target_found,
# target_not_found, search_incomplete) indicating the status of the search
func CycleOnce() -> int:
    # if the PQ is empty the target has not been found
    if PQ.empty():
        return TargetNotFound

    # get lowest cost node from the queue
    var NextClosestNode : int = PQ.Pop()

    # put the node on the SPT
    shortestPathTree[NextClosestNode] = searchFrontier[NextClosestNode]

    # if the target has been found exit
    if NextClosestNode == target:
        return TargetFound

    # now to test all the edges attached to this node
    var edges : Dictionary = graph.GetEdgesTo(NextClosestNode)
    for edge_key in edges.keys():
        var edge = edges[edge_key]
        # calculate the heuristic cost from this node to the target (H)                       
        var HCost : float = heuristic.Calculate(graph, target, edge.to) 

        # calculate the 'real' cost to this node from the source (G)
        var GCost : float = gCosts[NextClosestNode] + edge.cost

        # if the node has not been added to the frontier, add it and update
        # the G and F costs
        if (searchFrontier[edge.to] == null):
            fCosts[edge.to] = GCost + HCost
            gCosts[edge.to] = GCost


            searchFrontier[edge.to] = edge

        # if this node is already on the frontier but the cost to get here
        # is cheaper than has been found previously, update the node
        # costs and frontier accordingly.
        elif ((GCost < gCosts[edge.to]) and (shortestPathTree[edge.to] == null)):
            fCosts[edge.to] = GCost + HCost
            gCosts[edge.to] = GCost


            searchFrontier[edge.to] = edge

    # there are still nodes to explore
    return SearchIncomplete

It created a lot of objects and doesn't remove it. What is wrong here?

by (246 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.