Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

Unity vs Unreal

Turjan

Arcane
Joined
Mar 31, 2008
Messages
5,047
Also, there are people who tried to make more efficient city simulation.
Introversion for example did some really impressing simulations, but finally cancelled it because they did not know what kind of game to make from it.
https://www.youtube.com/watch?v=FR9xI0GgrBY
This is cool, but it's a completely different goal. This is exactly the part that is not simulated in a game like CS or the Simcities. Designing and building a city is what constitutes your game, so you would not want to let the software do this part.
 

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
With "state info" you probably mean the route calculation? Most of those models probably walked from their home or their workplace/school/shop/leisure spot to a bus stop, drove to the station and are waiting for the train now. There will be more way segments later. They may also have used a car or a bike or walked directly. No idea how much memory such a way calculation takes. It cannot be too much given how many of them are out there.

That wouldn't be that expensive... They probably have a number of routes a model goes through based on the type and building placement coupled with some kind of shortest path algoithm based on street placement (cars probably do the same). The only dynamic variable that needs to be saved is "where is my starting node" which is probably their house and possibly a destination node if they each have unique locations to go to work.

Everything else is probably "what's the closest X to me and how do I get there"

This is very cheap to do and only really needs to be calculated based on game time when your actually viewing them. Child's play compared to the render time.

Of course I am guessing - haven't seen the code.
 

Turjan

Arcane
Joined
Mar 31, 2008
Messages
5,047
Of course I am guessing - haven't seen the code.
At least they use the fastest route, not the shortest. However, that's probably the same, as faster routes have longer segments, so the algorithm probably just counts lane segments. The whole route is calculated before the trip starts and usually only gets recalculated if there's a fire somewhere. I think the number how often the mode of transport is allowed to change is limited to three or so. They won't calculate this for more than 16k vehicles, and there are maximally 65k citizen instances, not all of which travel at the same time. Those vehicles and traveling citizens are always on the map.
 

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
At least they use the fastest route, not the shortest.

Uhhhmmm..?

I wasn't talking in generalities.. I literally meant Dijkstra's Shortest Path algorithm, shortest would mean fastest if you weight your nodes correctly. (To Factor for some destinations being faster even if they are farther)
Unity implements this through A* although writing your own can be done in a hour or so.

Each street would be a vertex and your nodes would be any point of interest for a given user.
The run time is trivial for such a low data set.
 

Turjan

Arcane
Joined
Mar 31, 2008
Messages
5,047
Uhhhmmm..?

I wasn't talking in generalities.. I literally meant Dijkstra's algorithm, shortest would also mean fastest if you weight your nodes correctly.
Well, I said the game uses segments. Anyway, as I don't know Unity, I was talking in general. All the Simcity games for example use literally "shortest". They just measure distance. Which is the reason why the traffic simulation is so shitty in them without mods.
 

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
Well, I said the game uses segments. Anyway, as I don't know Unity, I was talking in general. All the Simcity games for example use literally "shortest". They just measure distance. Which is the reason why the traffic simulation is so shitty in them without mods.

What do you mean the game uses Segments?

Anyway, as I don't know Unity, I was talking in general. All the Simcity games for example use literally "shortest"

The Algorithm I mentioned is used in almost every video game / networking system / gps calculation / artificial intelligence table / everything ever. It was published in 1959.. according to wiki?
It's literally the fastest algorithm we have for finding the shortest path between multiple nodes. This isn't a *~*~Unity~*~* thing.

Sim City will use the same algorithm. How they weight nodes or designed the game over top it is anyone's guess. I haven't played it.
 

Turjan

Arcane
Joined
Mar 31, 2008
Messages
5,047
What do you mean the game uses Segments?
All transport lanes are split into segments (maximally 32k). A faster road has longer segments. The game chooses the route with the fewest segments.
The Algorithm I mentioned is used in almost every video game / networking system / gps calculation / artificial intelligence table / everything ever. It was published in 1959.. according to wiki?
It's literally the fastest algorithm we have for finding the shortest path between multiple nodes. This isn't a *~*~Unity~*~* thing.
It may exist, but it is not used properly in most existing simulation games, because the CPU overhead is too high, given the number of active agents. Simcity 4 from 2003 got a proper calculation of a the fastest route with the NAM mod a few years after release. The SimCity game from 2013 never got one, it still uses just shortest distance without adjustment.
Sim City will use the same algorithm. How they weight nodes or designed the game over top it is anyone's guess. I haven't played it.
The SimCity games don't weight. They measure exact distance. If a tiny gravel road is one centimeter shorter than the motorway to the same destination, any SimCity game will choose the gravel road and not use the motorway.

Cities: Skylines also will probably never see a better traffic algorithm than what is used now as the calculation overhead is seen as too high. At least it's better than that of the SimCities. I would like to see that an emergency vehicle would at least switch to one of the five free lanes when it's stuck behind one car on the lane it calculated before it started, but alas, this will probably never happen.
 

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
All transport lanes are split into segments (maximally 32k). A faster road has longer segments. The game chooses the route with the fewest segments.

It may exist, but it is not used properly in most existing simulation games, because the CPU overhead is too high, given the number of active agents. Simcity 4 from 2003 got a proper calculation of a the fastest route with the NAM mod a few years after release. The SimCity game from 2013 never got one, it still uses just shortest distance without adjustment.

The SimCity games don't weight. They measure exact distance. If a tiny gravel road is one centimeter shorter than the motorway to the same destination, any SimCity game will choose the gravel road and not use the motorway. Cities: Skylines also will probably never see a better traffic algorithm than what is used now as the calculation overhead is seen as too high. At least it's better than that of the SimCities.

:retarded: WOW.. Are you just pulling this out of your ass as you go...?
 

Turjan

Arcane
Joined
Mar 31, 2008
Messages
5,047
:retarded: WOW.. Are you just pulling this out of your ass as you go...?
I can only state that you seem not to know any of the common city simulation games, otherwise you wouldn't react this way.

Computer games are adjusted to what runs on minimum spec computers the sales department has chosen. You should at least know that much. The devs of Cities: Skylines at least admitted that, although they tried proper traffic algorithms, they cannot use them as the game won't run on minimum specs then.
 
Last edited:

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
Computer games are adjusted to what runs on minimum spec computers the sales department has chosen.

No.. you're just full of shit and don't know what the hell your talking about.
I am going to format this post in the way I would when talking to Bester.

Proper Explanation: (Includes O-Notation for Execution Time)
Wipe that drool from your mouth and maybe learn something cool.

Hurpa Durpa Explanation:
Dijkstra's algorithm using a Fibonacci Heap (Aka a Tree Hierarchy for Nodes) executes at almost linear time for sample sizes in the millions.
That is.. even at a million nodes you would see no marginal performance loss in comparison to what it would take to navigate those nodes perfectly the first time.

Why you sound like an idiot.
That is the exact route anyone would go to support a shitty potato computer. (it's the fastest way to do exactly what we want)
Your out-the-ass theory of how TEH CITAY GAYME WORKS are just bullshit, go take a Data Structures class or retake grade 10 math.
 

Turjan

Arcane
Joined
Mar 31, 2008
Messages
5,047
No.. you're just full of shit and don't know what the hell your talking about.
I am going to format this post in the way I would when talking to Bester.
blahblah...
Well, so why don't SimCity games manage to calculate the fastest route then? Which is a fact.
 

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
Well, so why don't SimCity games manage to calculate the fastest route then? Which is a fact.

Who knows it's fucking EA - maybe they were too lazy to weight nodes / vertex's properly. They are still using the A* algorithm. (It's painfully obvious)
Not some magical segment theory shit you pulled out of your ass.

Several of my friends work at EA and they don't even like video games, EA just paid the most out of school and they got to move the USA.
I wouldn't be surprised at all.
 

Turjan

Arcane
Joined
Mar 31, 2008
Messages
5,047
Who knows it's fucking EA - maybe they were too lazy to weight nodes / vertex's properly.
Which is what I said and which shows who is the mouth breather here.

And to explain "segments" for the somewhat slow in mind: A segment is the piece between nodes (haha, who would have thought). I explained that the length of segments stands for speed. I think you will get the rest.
 

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
Which is what I said and which shows who is the mouth breather here.

Really? Oh well never mind then.. see I thought you said:

All transport lanes are split into segments (maximally 32k). A faster road has longer segments. The game chooses the route with the fewest segments.

It may exist, but it is not used properly in most existing simulation games, because the CPU overhead is too high, given the number of active agents.

First some weird shit about segments.. then said that weighted nodes makes the game too slow for bad computers.
Or in other words.. just bullshit opinions without knowing jack dick about anything.
 

Turjan

Arcane
Joined
Mar 31, 2008
Messages
5,047
Really? Oh well never mind then.. see I thought you said:

First some weird shit about segments.. then said that weighted nodes makes the game too slow for bad computers. Or in other words.. just bullshit opinions without knowing jack dick about anything.
You just fail at thinking, otherwise you would have grasped the concept of segments (the distance between vertices, also called that in the code). And regarding the calculation overhead, SimCity 4 didn't run well even on better computers on release. It's still somewhat taxing for computers today, 12 years later. They indeed cut the weighting because of performance reasons. A proper calculation of the fastest destination was added about 3 years later with a mod.

Regarding the approach in Cities Skylines: if you make the segments between vertices longer for a faster route, you can also keep things simple.

You may know your theory, but I guess you are lacking practical insight into the matter.
 
Last edited:

Hirato

Purse-Owner
Patron
Joined
Oct 16, 2010
Messages
3,959
Location
Australia
Codex 2012 Codex USB, 2014 Shadorwun: Hong Kong
I've implemented A* search (or was it B*? I forget) in a pretty unoptimal way, and I could easily calculate well over 20000 routes per frame while still getting over 200 FPS. (On a map with 4000 nodes, each with up to 6 links with neighbours, and each route had anywhere from 1 to 1000 steps between them)
The engine in its entirety is single threaded and I was using a pretty crappy CPU at the time I believe was clocked at 2.2GHz.
And my crappy implementation also included some smoothing passes so that route a -> b -> c would become a -> c if there was a direct link between a and c.

Even then, that's not very relevant, as Immortal said, you'd generally calculate the route once and then cache it in the entity, and this would basically be a list of around 10-100 nodes to visit in sequence.
I stored them in reverse order, so that the next entity to visit was at the end, which is great for performance since you just pop the last one off of the list without needing to shuffle the rest of it down, plus you can append any arbitrary nodes you want easily in case you ever want the entity to take a small detour to dodge projectiles among other things.
My shitty implementation also doesn't account for any environmental factors, like how busy a node is (can be done many ways, you might check how many entities is currently in a zone if you've the structures for it, or entities might +1 any routes they're currently using) or how quickly you can travel across it (you'd probably use this as a small multiplier against the distance so slow nodes get a lot less action), or any interactive objects that teleport things around.
So there's plenty of processing power to direct here for better calculations, and that's with my implementation's shittiness, which among other things calculates a score on every node before it attempts route calculation, has no recursive data structure to speedup worldspace lookup so I have to examine all the nodes when I want the closest one.
 

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
I stored them in reverse order, so that the next entity to visit was at the end, which is great for performance since you just pop the last one off of the list without needing to shuffle the rest of it down, plus you can append any arbitrary nodes you want easily in case you ever want the entity to take a small detour to dodge projectiles among other things.

Using an array list in reverse order as a stack?! - Oh look someone who has a brain.
I almost lost all hope for this thread.

Inane Shit

TL;DR - There is no negligible performance loss. I feel like I am repeating myself.
 
Last edited:

Destroid

Arcane
Joined
May 9, 2007
Messages
16,628
Location
Australia
I've implemented A* search (or was it B*? I forget) in a pretty unoptimal way, and I could easily calculate well over 20000 routes per frame while still getting over 200 FPS. (On a map with 4000 nodes, each with up to 6 links with neighbours, and each route had anywhere from 1 to 1000 steps between them)
The engine in its entirety is single threaded and I was using a pretty crappy CPU at the time I believe was clocked at 2.2GHz.
And my crappy implementation also included some smoothing passes so that route a -> b -> c would become a -> c if there was a direct link between a and c.

Even then, that's not very relevant, as Immortal said, you'd generally calculate the route once and then cache it in the entity, and this would basically be a list of around 10-100 nodes to visit in sequence.
I stored them in reverse order, so that the next entity to visit was at the end, which is great for performance since you just pop the last one off of the list without needing to shuffle the rest of it down, plus you can append any arbitrary nodes you want easily in case you ever want the entity to take a small detour to dodge projectiles among other things.
My shitty implementation also doesn't account for any environmental factors, like how busy a node is (can be done many ways, you might check how many entities is currently in a zone if you've the structures for it, or entities might +1 any routes they're currently using) or how quickly you can travel across it (you'd probably use this as a small multiplier against the distance so slow nodes get a lot less action), or any interactive objects that teleport things around.
So there's plenty of processing power to direct here for better calculations, and that's with my implementation's shittiness, which among other things calculates a score on every node before it attempts route calculation, has no recursive data structure to speedup worldspace lookup so I have to examine all the nodes when I want the closest one.

post code
 
Unwanted
Shitposter
Joined
Oct 5, 2014
Messages
3,390
Location
Nazi death cult center of jew medicine avoidance
Uhhhmmm..?

I wasn't talking in generalities.. I literally meant Dijkstra's Shortest Path algorithm, shortest would mean fastest if you weight your nodes correctly. (To Factor for some destinations being faster even if they are farther)
Unity implements this through A* although writing your own can be done in a hour or so.

Each street would be a vertex and your nodes would be any point of interest for a given user.
The run time is trivial for such a low data set.

:roll:

Those are two different algorithms. I've implemented both.

What do you mean the game uses Segments?



The Algorithm I mentioned is used in almost every video game / networking system / gps calculation / artificial intelligence table / everything ever. It was published in 1959.. according to wiki?
It's literally the fastest algorithm we have for finding the shortest path between multiple nodes. This isn't a *~*~Unity~*~* thing.

Sim City will use the same algorithm. How they weight nodes or designed the game over top it is anyone's guess. I haven't played it.

What do you mean what do you mean?

No.. you're just full of shit and don't know what the hell your talking about.
I am going to format this post in the way I would when talking to Bester.

Proper Explanation: (Includes O-Notation for Execution Time)
Wipe that drool from your mouth and maybe learn something cool.

Hurpa Durpa Explanation:
Dijkstra's algorithm using a Fibonacci Heap (Aka a Tree Hierarchy for Nodes) executes at almost linear time for sample sizes in the millions.
That is.. even at a million nodes you would see no marginal performance loss in comparison to what it would take to navigate those nodes perfectly the first time.

Why you sound like an idiot.
That is the exact route anyone would go to support a shitty potato computer. (it's the fastest way to do exactly what we want)
Your out-the-ass theory of how TEH CITAY GAYME WORKS are just bullshit, go take a Data Structures class or retake grade 10 math.

Get a grip on yourself, the edgy is overwhelming especially considering some of the dumb things you have said.

TL;DR - There is no negligible performance loss. I feel like I am repeating myself.

:roll:

You might actually be retarded.

What they are doing is obviously hierarchical A* so first the segments have A* performed on them to get the broad path, then the individual nodes in the segments.

I think you and Bester should get together and fanboi somewhere someone gives a shit.
 
Last edited:

Hirato

Purse-Owner
Patron
Joined
Oct 16, 2010
Messages
3,959
Location
Australia
Codex 2012 Codex USB, 2014 Shadorwun: Hong Kong
post code

Code:
struct waypoint
{
    waypoint *parent;
    vec o;
    vector<ushort> links;
    int score;

    waypoint() : parent(NULL), o(vec(0, 0, 0)), score(-1) {}
    waypoint(const vec &o) : parent(NULL), o(o), score(-1) {}
};

    void findroute(int from, int to, vector<ushort> &route)
    {
        if(!waypoints.length() || !waypoints.inrange(from) || !waypoints.inrange(to) || from == to)
            return;

        //determine scores
        loopv(waypoints)
        {
            waypoints[i].score = waypoints[i].o.dist(waypoints[to].o);
            waypoints[i].parent = NULL;
        }

        //recurse
        waypoint *cur = &waypoints[from],
                 *first = cur;

        while(true)
        {
            int lowest = -1;
            //try the "series of low scores" method
            loopv(cur->links)
            {
                waypoint &l = waypoints[cur->links[i]];
                if(cur->links[i] == to ||
                    ( !l.parent && &l != first &&
                        (lowest < 0 || l.score < waypoints[lowest].score) &&
                        (l.links.length() > 1 || (l.links.length() && !waypoints[l.links[0]].parent))
                    )
                )
                {
                    lowest = cur->links[i];
                }
            }

            if(lowest == -1 && cur == first)
                return;
            else if (lowest == -1)
            {
                cur = cur->parent;
            }
            else
            {
                waypoints[lowest].parent = cur;
                cur = &waypoints[lowest];
            }

            if(lowest == to)
                break;
        }

        //cur should still be the destination
        int i = route.length();
        while(true)
        {
            route.add(cur - waypoints.getbuf());

            if(cur == first)
                break;

            cur = cur->parent;
        }

        //now we optimise the route, we start at the back and check the latter nodes for common nodes
        //common nodes include unused nodes between two nodes in the route (a shortcut)
        //             as well as nodes which have a link to one of the nodes later in the vector
        ///just remember the vector is in reverse
        ///we also start at the end of the prior movement vector; we don't want to miss out critical destinations.

        for( ; i < route.length(); i++)
        {
            //don't bother checking i + 1
            for(int j = route.length() - 1; j > i + 1; j--)
            {
                waypoint &chk = waypoints[route[j]];

                //see if there are shortcuts available; take them!
                if(chk.links.find(route[i]) >= 0)
                {
                    route.remove(i + 1, j - i - 1);
                    break;
                }
                //see if a shortcut can be taken by using 1 intermediary node
                //we don't check for more
                if(i + 2 <= j)
                {
                    int found = -1;
                    loopvk(chk.links)
                    {
                        if(waypoints[chk.links[k]].links.find(route[i]) >= 0)
                        {
                            found = k;
                            break;
                        }
                    }
                    if(found >= 0)
                    {
                        route[i + 1] = chk.links[found];
                        route.remove(i + 2, j - i - 2);
                        break;
                    }
                }
            }
        }
    }
Entire file is here: https://github.com/Hirato/lamiae/blob/master/src/rpggame/waypoint.cpp go knock yourself out
 

Immortal

Arcane
In My Safe Space
Joined
Sep 13, 2014
Messages
5,062
Location
Safe Space - Don't Bulli
:roll:
Those are two different algorithms. I've implemented both.


I -said- Dijkstra was implemented in unity through A star
I didn't say they were the same, Dijkstra is a special case for A Star when the heuristics of a grouping of nodes is zero.
Are you that desperate to "prove me wrong" ? :bounce:

I wasn't talking in generalities.. I literally meant Dijkstra's Shortest Path algorithm, shortest would mean fastest if you weight your nodes correctly. (To Factor for some destinations being faster even if they are farther)
Unity implements this through A* although writing your own can be done in a hour or so.

Dijkstra was the base and A* was implemented on top for more intelligent navigation for a range of scenarios.
There are some edge cases or scenarios where A* falls short.

You would know that since you implemented them all.

Here's a cool video:


(I tried to make this post really un-edgy)
 
Last edited:

Keldryn

Arcane
Joined
Feb 25, 2005
Messages
1,053
Location
Vancouver, Canada
So to summarize this thread:

"Unity is shit."

"You're a retard."

"You're a retard and you don't know shit about programming."

"No, you're the one who doesn't know shit about programming. Retard."

Did I miss anything?
 

Stormcrowfleet

Aeon & Star Interactive
Developer
Joined
Sep 23, 2009
Messages
1,027
So to summarize this thread:

"Unity is shit."

"You're a retard."

"You're a retard and you don't know shit about programming."

"No, you're the one who doesn't know shit about programming. Retard."

Did I miss anything?

Thanks for summarizing it because I can't being lost in between the ''you're a retard''. I thought I would get nice information out of this thread but oh well...
 

Keldryn

Arcane
Joined
Feb 25, 2005
Messages
1,053
Location
Vancouver, Canada
Thanks for summarizing it because I can't being lost in between the ''you're a retard''. I thought I would get nice information out of this thread but oh well...

Unreal is ultimately a more powerful and better performing engine, but its graphical prowess is wasted unless you've got good enough artists to produce high quality assets.

If you're a hobbyist or a small indie team then Unity is the lesser evil. You'll be more productive and there is a large community of developers actively using Unity, so there is always someone who can answer a question. There is a lot of shit on the Asset Store, but there is also a lot of very high quality stuff -- and I'm not even talking about 3D model. Stuff like Bevavior Designer or Dialogue System are very solid and will save you a lot of time.

Yes, Unity is a resource hog and games made with it tend to run a lot slower than it seems they should. The way it manages third party assets sucks ass. Managed C# code will always run slower and use more memory than C++. It's the price you pay for accessibility and productivity.

I've worked with Unity, I've worked a bit with Unreal, I worked with the old Dungeon Siege engine, and I worked with two different proprietary engines at Rockstar. All game engines suck in their own special way. The scripting engine that I had to use for most of my time on Max Payne 3 didn't even have any support for callbacks or events -- there was no way at all for a script function to tell anything else that it had completed.

They're all shit. If you find a game engine that isn't, then you haven't spent enough time with it.
 
Last edited:

Stormcrowfleet

Aeon & Star Interactive
Developer
Joined
Sep 23, 2009
Messages
1,027
*Useful information*.

Well thanks for that. To be serious I read through the thread. With this kind of inside information it gives me yet another piece of the puzzle. All in all, it's interesting and I salute your input :salute:
 

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom