Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit/AppGameKit Studio Showcase / Full 3D city tech demo in AGK

Author
Message
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 2nd Nov 2022 22:25 Edited at: 27th Nov 2022 23:54
Hi all.

Having given up on my last project, I decided to start a new one to see how AppGameKit could actually handle a full 3D city scenario. This is mainly after taking some time away to go and play with unreal, and as nice as it was I found doing something as simple as creating a building that the player could walk into through enterable doors was overly difficult, and I wanted to see how AppGameKit could handle it. This is a hobby project, not working towards a specific game, and if I can figure out an easy way to do it I will make it open source for all at some point.

For now however I used the World Builder to create a simepl city scene, use this to build path mapping data, get some NPCs to navigate around the world, and .....create fully functional, script based, openable doors!!

So far this about 6 hours of work ripping apart my old game engine, chucking in pathmapping and a 1st person mode, and testing - the models (except one I am building) are all free assets, and it look rubbish just now.



To come next:
* sort a pathmapping glitch where hollow buildings do not generate blocked tiles in the middle
* create an internal scene for the flat with furniture, and link it to trigger objects so that the internal scene loads in and drops out seamlessly as the player approaches it or leaves
* shrink the pathmap to make it more accurate and make it manually editable
* create sidewalks to allow NPCs to be set to prefer to walk on them
* re-impliment threaed pathmapping to remove the hitch when an NPC path maps
* impliment nodes to make actual destinations
* make NPCs vanish beyond a certain distance to the player, and replace with new ones moving towards them
* explore idea of removing the need to raycasting every update to the ground by "knowing" fixed heights where possible
* make pedestrains navigate around each other

For the future
* hugely expand the city and impliment LoD to see just how large it can become
* .....cars?
* convert pathmapping to T2 for speed
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 3rd Nov 2022 03:57
Pretty neat exercise and review of AGK's comparative capabilities. There are some things tools like this have an edge with, simplicity in that kind of layout construction is one of them.

The shadows might require the use of a shader with more custom projection/depth and source placement to achieve proper behavior. Or maybe bake them for a temporary placeholder in the meantime.
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 3rd Nov 2022 14:42
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Nov 2022 19:29 Edited at: 3rd Nov 2022 21:26
Exceptional work. Well done!
I found with a shadow map of 2048x2048 and SetShadowRange() set to a small a distance as possible you could get good quality shadows

I attached some road stuff. Straight, T and intersection. Let me know if you want a turn

Attachments

Login to view attachments
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 7th Nov 2022 18:32
Thanks everyone.

On the shadows, what I mean is point shadows are really just an essential now.....a 3D engine that can only do sun based shadows is ridiculous. Janbo produced one I think, but it was incredibly complex. It's frustrating, I coded one in T2 using a tutorial, but you needed vertex info that AppGameKit doesn't pass over.

Thanks Blink0k for the roads. I've spent the last two evenings upgrading the editor to allow you to draw pathmaps, and split them into passable, impassable, road and sidewalk. I may use the models, but the issue for now is placement and scaling. The editor has snapping but you always end up with a flickering sliver or a glitchy overlap. Plus individual chunks cause multiple draw calls, which AppGameKit is a bit slow at for my liking.

So I'm building a system to procedurally create roads based off of the drawn pathmaps that are a single object, and this a single draw call. It means that even complex roads will have almost no performance hit.

The immediate goal is to have pedestrians prioritise walking on sidewalks, and crossing roads only at crossings or where the have to in straight lines.

I'm also working on pedestrian generation using nodes, which I think will enable similar functionality to traffic. Essentially, if I have a street block, I will create a node at each corner, then the facility to link each node to up to four others. When generating a pedestrian, this lets me pick a node near the players maximum draw distance, but then choose randomly from the nodes connected to it, and generate the new NPC along that line, stopping bunching.

My hunch is that traffic is the same. So I'll build a node at every turn or junction, then link it to only the one moving forward in the direction I want, with options at junctions. This means that traffic will follow roads, but handle junctions correctly with minimum pathmapping and raycasting needed. I can then scale this so that vehicles "link" to one in front of them, and draw a set distance behind in the distance so that no pathmapping or ray casting is needed, speeding it up. From testing, you can only get away with about 300 raycasts per frame before it's a real bottle neck.

Or at least, that's how I think traffic and seamless pedestrian generation that doesn't pop out of nowhere will work. It may change.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 8th Nov 2022 22:34
So that took longer than I would like, but that's the world editor updated to allow manual painting of the path map, and code added to procedurally generate a road as a single object using memblocks - a simple road going through the buildings had no impact on frame rates.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 10th Nov 2022 21:59
Quick update video.

Now the World Editor has been udpated to include the pathmaps, you can design and edit them and then it procedurally generates the roads, crossing and sidewalks based on the pathmap. I need to get it to sort the white lines in the middle of the road, but that's no important for now. The roads and sidewalks are all procedurally generated using memblocks, so they are one single object so there is very little delay in draw calls, and the frame rate is basically not affected. The next step is to put this into the game engine, then have multiple NPCs walk around using the sidewalks and crossings whereever possible, and not on the roads.

Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Nov 2022 00:21
Slowly making progress on seeing how far AppGameKit can go with a 3D city - we now have 50 pedestrains navigating around the world block using pavements and crossings.

Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Nov 2022 00:52 Edited at: 13th Nov 2022 00:53
Quick update - now added "threaded" pathmapping over multiple frames, so that stutter when a complex route was being calculated in gone.

Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 13th Nov 2022 01:25
looking good, Santman.

if i could reserve a small shop @ the corner of 1st and Main St, i'd like to open up a Barber shop.

based on the denizens, i'd be Mayor in no time!
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Nov 2022 15:06
Lol.....not a problem, reasonable rates due monthly.

Yeah, there's some major hair going on! I hope it's evident that I'm better at coding than I am at modelling, though I am getting better with blender.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 13th Nov 2022 19:02
Impressive stuff, as always from you

Saw this post ... you still need help with that?
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Nov 2022 19:58
Hey.

I never solved that particular issue, but I got around what I needed by using a memblock, which is probably faster anyway.
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 13th Nov 2022 20:33
String returns use mem pointers so they probably comparable if not faster without the extra AppGameKit function calls to access the memblock, but if you got a system that works for you then all good.

I am guessing with a memblock system you can return more complex data structures anyway so might be a good way to go, I will have to look into that at some point.
Open Source plugins
Cl - DnD Plugin
Buy Me A Coffee
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Nov 2022 22:28
Yeah, it's for the pathmapping, so I effectively need to pass a large number of integers to and from the DLL.....and various other times. I assumed sending them as a string would be best, but actually the memblocks make it quite easy, just tough to organise.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 14th Nov 2022 13:09
So if I may say something about it.
The problem mentioned in the thread is quite simple. When you receive strings it is the same as with integer or float parameters they only have to be declared with const char*.
As return value it's a bit different when returning strings, they have to be created by AppGameKit first with agk::CreateString. Then the string is filled with memcpy or strcpy.

In your case with path finding which I think is used cyclically often. Is it the way you do it now, via memblocks, the better choice. I would even reserve a fixed memblockID for the plugin.
So that a constant data exchange between C/C++ and AGK-Basic happens.

For smaller arrays and/or structures that are used now and then. You could also return them as JSON strings. These can then be parsed in AGK-Basic simply with the ToJSON or FromJSON.

That's how I handle it

About your city project - I find it totally exciting and is an excellent work of you. There's a lot of work and know-how behind it. I'm curious to see where the road will still lead.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 15th Nov 2022 12:23
Hi MadBit.

Yeah, the pathmapping is very cyclical, but is now actually spread over multiple frames so that there is no lag. I need to look at that as the FPS is timer controlled, and designed to give more time to the texture streaming in the background when available, but that is now clashing with the pathmapping, so I need to give the pathmapping priority over it as it will finish in far fewer frames. The actual framerate I get is around 400, so the dip below 60fps is frustrating....I need a better timer there.

What is it about the roads you are intrigued by? Do you mean traffic? If so I have thoughts on how to deal with this that I am pretty sure will work, but happy to hear any thoughts.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 15th Nov 2022 14:20
Oh, sorry, I didn't mean where your paths in your project lead, but what your project will become in the future.
When I formulated the sentence, I didn't think that it could be misunderstood. Sorry.

With your timer thing, I have to try something. If that works, it might help you.
But I'll let you know when I've checked it out.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 17th Nov 2022 22:00 Edited at: 17th Nov 2022 22:02
So I have now tested it out. The result is not really surprising.
But it is nice to have a comparison.
The aim was to create a background stream.
Three images with different sizes (256x256,1024x1024 and 2048x2048) are filled with random colours in the background at the same time.

First version is a pure AppGameKit solution.
Second version is the same approach as a plugin.
Third version is a multithreaded solution.

I don't know how far your solution matches mine nor if the speed is comparable.
The values on my PC are as follows.

AGK solution: 50-60 FPS, All three images (256,1024 and 2048) are updated approx. 1.6 times per second.
Plugin solution: approx. 2500 FPS, All three images (256,1024 and 2048) are updated approx. 18.5 times per second.
Muiltithread solution: Fluctuates between 3000 and 4000 FPS.
256x256 image is updated approx. 510 times per second.
1024x1024 image is updated approx. 59 times per second.
2048x2048 image is updated approx. 16.6 times per second.

In the attachment you will find the executable project.

Here is the code.
If you can use some of it, feel free to help yourself.
If you have any questions about the code, feel free to ask.


Plugin-Code
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.

Attachments

Login to view attachments
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 20th Nov 2022 23:16
Hi MadBit.

Thanks for the code - I'm sure a load of people will find it useful. I am already using a variant pretty close to that, though in my case spread over multiple frames - that's the clash I am getting: both my texture streaming and pathmapping are designed to be threadedacross multiple frames, but in different projects so as yet I have not optimised them to work together. The method is simple - each frame each process, if needed, has a minimum amount of milisecodns to run to ensure they always work regardless of frame rates, however where spare capacity exists between frames they can use that time to finish. The problem was when one set of code used all the "spare" frame time before the other batch of code got to run, so it then used its minimum and the lag appeared.

I actually mix two types of streaming - small images I do on a byte by byte basis using memblocks as files, the other I take larger images and break them down into multiple small memblock files, with each chunk of images loading in subsequent frames and then combining back together. It;all T1 code so far, but in one of my earlier tech demos I loaded about 3.5 gb of texture data as I moved around a worl in something like two seconds using the second method, so it can be fast.

I'm just about to upload a new video showing node based NPC generation and pathmapping, which has largely fixed the issue as pathmapping is now much faster, and all still in T1 - once I put it to T2 it will be lightning and unlikely to nee dmore than one frame anyway.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 20th Nov 2022 23:21 Edited at: 20th Nov 2022 23:24
So as noted above, a quick new video.

This one uses "node" based pathmapping, What this effectively means is that I altered my editor to allow me to create nodes along sidewalks, which I can then interconnect to create a web of nodes. The game engine now uses this to generate NPCs in a more natural way and far more controlled (they don;t generate bunched up, and only generate on side walks), and it makes pathmapping much faster and smoother - you can see the difference between last week and this week in the video below, with 100 NPCs active. It also gets rid of a niggle when NPCs decide to generate out of bounds and the pathmapping code had an issue.

This method should, now I have it working for pedestrains, work as well for cars, but will come with a much simpler and therefor faster algorythm....which means I should be able to get 50+ pedestrians and 75+ cars moving no problem at all.

As always, this is all running in T1....though I do plan to move the pathmapping and AI to T2 soon to get that speed boost.

Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 21st Nov 2022 00:54
This is very cool, And i am very surprised on how well appgamekit handels it all so well.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 21st Nov 2022 16:06
I've built a modified node system for traffic, and I've turned my thoughts to a new issue; traffic lights.

My current thinking is two fold;
I could encode certain nodes (at junctions etc) to be traffic lights, and try to handle this programmatically

It, is I can use collision shapes. Each car already has to raycast forward anyway, so I am thinking I could build two models for all junctions, using crossing pathmap squares as a guide. As my to roads only support grids, I need only two cycles: left and right, then up and down. These need to oppose each other.

What I am thinking is to make the two models of faces only, then have one at ground level when that light is "red" and the other below ground. When lights swap, I reverse this.

This means that cars will naturally stop when lights are red, and go on green. By flipping faces towards sidewalks, the exact same process would work for pedestrians to stop them crossing at green lights

Anyone have other thoughts?
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 27th Nov 2022 23:52
So here's a simple problem, that has me stumped.

I have an NPC walking to a way point, and want to then move them to the next in line. Simple. However, I can't work out a quick way to get the angular change to make it smooth.

So for example, as it walks towards a marker, it has a Y angle of 90. The next marker means it has to adjust its Y angle to 125 to walk towards it. So I can take the current angle, then the dest angle......but how do I quickly and without a performance hit, work out which way the NPC shod start rotating?

It becomes very difficult as soon as you cross the zero or 360 degree points as AppGameKit doesn't wrap.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 28th Nov 2022 08:43
I have not tested this now. But the angle and the direction should be theoretically so to calculate:
Assuming that both angles are between 0 and 360.
delta_angle = target_angle-current_angle
delta_angle > 180 ? -> delta_angle=delta_angle -360

The soft movement should be realizable via the tween commands.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 28th Nov 2022 13:45
Yeah, I've used tween commands before, but I need control. So for example, a car turning a corner may need to stop moving if it detects an impact, so I'd need to stop the tween. Then when it moves again, I need to start the tween again but not necessarily at the same speed.

I'll look at it, but the challenge I have is working out quickly WHICH way to turn the NPC to get to the target angle.
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 28th Nov 2022 20:32 Edited at: 29th Nov 2022 15:44
One approach is you can measure the angle difference between the object you are rotating and the point you want to turn to. This can be done by a basic angle comparison. Then offset the result to determine if you need to turn left or right. From there, step the rate based on the framerate (the 'fradjust#' variable in the example below, set to 1.0 to just apply a fixed rate to test with). Check limits, then apply the rotation differences to the turning object's current angles.

Here is some example code (for simplicity, I'm using a hidden guide object as 'GuideObject' and 'MyObject' being the one you want to turn) and a function you can use for a wrapvalue. This routine works on both X and Y, but will stay focused on Y if the turning object and destination are on the same vertical plane.



And here is a wrapvalue function you can use to keep angles within 0-360 degrees.

MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 29th Nov 2022 06:33
Good example.

The wrapvalue can be a bit simplefied.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Donations are always welcome.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 29th Nov 2022 21:48 Edited at: 29th Nov 2022 21:49
Thanks guys, that's working great to get me the direction to turn.

The full code isn't needed, as I actually just needed to get the direction then angle, the actual turning is then based off of the distance that the turn is away, and is done elsewhere.

I have now got traffic lights and basic traffic flow working OK, but it keeps jamming up. Turns out the logic for traffic lights is complex. Take for example a T Junction as shown in screen shot 1. Here there is a car who wants to follow arrow marked 3 to turn the corner. however there are cars also coming down the roads marked with arrows 1 and 2. Currently as soon as the traffic light changes, the car on arrow 3 will move, but if the road is busy all teh cars will detect each other and essentially freezze.

I think what I need to do is create a junction "node" with linked raycasting nodes that acts liek eyes - see screen 2. What this means is that if the car detects a junction node in front of it, it queries the junction node, which updates alternatively on frames by raycasting into oncoming traffic in both directions, and then stores a value of 0 for "it's all clear" and 1 for "I can see something coming". If the car querying the junction node gets a return of 1, it knows not to move. If it gets a zero, then it knows to move.

This gets even more tricky at a cross roads: you can have two cars sitting opposite each other, but both wanting to turn into the same destination road. Now I have to add, I think, code which basically says "if you are turnking left you have priority over cars turning right".....however the challenge is how to work out HOW MANY cars are opposite and how long to wait. I suspect the answer is a similar look ahead node system to the above, however this is now increasing the number of ray casts alot, and it's starting to get quite slow.

The cars are already fairly effecient, and check collissions against only cars and traffic lights, and check the relative X and Z distance so that it only casts a ray to cars which are conceiveably close enough to hit. The last stage is to create two simple planes in front of and behind the cars and turn off collission for the models to reduce the number of vertices that need to be checked for car to car collissions. However with about 40 cars navigating a simple street kayout that is already turning into 180+ raycasts per frame. I can split this down over 3-4 frames, but if I have to add in the above it becomes REALLY processor heavy.

Pedestrains were, apparently, quite easy to compared to cars.

Attachments

Login to view attachments
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 1st Dec 2022 09:11 Edited at: 1st Dec 2022 09:19
Hi Santman, nice project.
My 2 cents might not be worth 1 cent but I'll say it anyway.

A different system for the cars might work faster if it could work at all.
What if you had all the work being done in something like a 2d array? Like a map in the array.
All the car locations and movement and checking etc.
Then all the cars just have to try to smoothly copy whats going on in the array.
IDK... might work but would need a big rebuild.
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 1st Dec 2022 20:26
Hi ando.

All cents are worthwhile. Very soon I am going to upload it so anyone can have a bash at anything - but the entire road network already works off of a grid that is a map in memory, so that wouldn;t be that big a change. However in the future I plan to make bending and even up hill roads and things like an overpass, that the nodes make perfect. I.e. the roads do not need to be connected to any kind of map to work.

I implimented the watcher node system in teh editor last night, I am just about to impliment hte AI to make that work....but I had an idea on how to make them faster by having them only cast rays when activated by a vehicle. So lets see how that goes.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 1st Dec 2022 23:22
I managed to get the watcher system intergrated into the AI, and prodcued a little video to show how this works. Bare with me as the traffic lights, which were working fine, have started glitching but I think that's the angle of the cars now hitting the reverse of the traffic lights due to me increasing the size of the sphere cast - they were working flawlessly before. The next udpate, which will have cars smoothly turning, will fix this.

SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 3rd Dec 2022 00:12
Very nice progress! Interesting approaches and clever solutions.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Dec 2022 12:31
Thanks SFSW.

That problem solving, "how could that be possible" aspect is what I like most about coding. The biggest challenge here is that everything I want to do something new, I first have to build it into the editor, and that takes 4 or 5 times longer than the game code.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Dec 2022 12:40 Edited at: 3rd Dec 2022 12:51
So last night I fired up GTA V to refresh my memory, and to pay more attention to the cars.

The first thing that hit me was how few pedestrians the game actually had, there's hardly any compared to cars, and a good many aren't doing anything. It does have a lot of cars, but actually I think now, with hindsight, I can see genuine logic errors on roads that the game does a remarkable job of hiding them as "part of GTA" ... for example, cars changing lanes and hitting another for no apparent reason.

Now I recall an interview with Ubisoft and AC Unity, where they detailed up to 1,100 NPCs were handled at any one time.

In either case, GTA's cars or ACs NPCs, theres no way all those raycasts are being done every frame, multiple per entity.

So I guess, it runs on a schedule: on frame 1 raycast the ground, on frame 2 raycast forward, on frame 3 raycast whatever else, repeat the cycle. Cars in particular with realistic suspensions are a challenge; mine have 4 independent wheels, which means each tire needs to raycast down separately to the body. First thought is that obviously you do this only when a car is within a certain distance to the camera, and then only when they are "wild" - i.e. not driving on a smooth, mathematically predictable road surface.

I also assume that for pedestrians, you would split the crowd into groups and do only so many per frame, and for ground height just store the height the NPC should be at, and tween towards this each frame to make movement smoother.

Has anyone else thought about this, and how to handle hundreds of raycasts per frame? Anyone have other thoughts?
Virtual Nomad
Moderator
18
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 3rd Dec 2022 14:23
have you considered Bullet3D? with that, i gotta believe most games have a detail level of a given map with a simplified physics layer doing all the work. see ando's vehicle example.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Dec 2022 16:13
The attached screen grab from ANDO's demo is pretty much why I don't want to use physics in AGK...

I did my own 3D car before, and it worked fine save for the fact it needed 4 ray casts per frame. Fine for the player, not so much for dozens of AI cars....



This is actually still built into the editor, but I have no goal to add a player drivable car. So what I need is a faster solution to the above to allow the NPC cars to
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 3rd Dec 2022 18:54 Edited at: 3rd Dec 2022 20:38
Quote: "Has anyone else thought about this, and how to handle hundreds of raycasts per frame? Anyone have other thoughts?"


Raycasts can be quite quick, but problems surface in AGK/S with things like nested loops and redundant operations. So one recommendation I would have is to restrict just how many operations you do per loop by cycling through them at a low step rate for proximity checks, then increase the rate on a per entity basis for more precision as range gets closer. I do this a lot in my work to try and keep performance high. For one quick example, the wrapvalue function I provided above uses an 'else' statement to then only perform any operation once. In the second example in the following post, although simplified from a coding standpoint, you'll notice that two operations will be performed any time the number is negative. So that effectively causes one redundant operation in addition to the one you need every time the angle value is negative. Doesn't sound like much, until you iterate something like that thousands or even tens of thousands of time. If I do that with those two function examples in a loop a thousand times, the framerate drops from 2800 to 2500 whenever the double operation occurs. That's a loss of about 10% with just one function call performing one operation many times. Sprinkle behavior like that all over your codebase and you'll generally find major reductions in potential performance. Add similar repeated/duplicated operations in loops and it just gets worse.

So in addition to minimizing raw operation count and as a way to achieve that, what I'd also recommend is figuring out a way to run only one proximity check (either one range or one raycast) per frame to check the distance for only one entity at a time. Then when you have an entity get close enough, start polling the collision/raycast operation every frame for that entity as may be needed (so switching from only one entity per frame to every frame per every individual entity that needs the full speed checks). This way, you might only have 3-5 cars or something running frequent checks while the rest are passively checking in a stepping cycle. It will take a lot of tuning and tweaking to get the range values correct (will be based on the speed of the entities and scaling of your 3D scene) and adapted to whatever target minimum framerate you need things to work at. And in some cases (say very low framerates like <10 or something or high number of entities) you may have to increase the steps to 2 or 3 to make sure you get through all entities in time so none are missed with a low framerate and/or high number of entites. This can result in major performance improvements, depending on the number of entities and operations involved.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th Dec 2022 11:16
I remember the last Project through much of its development stages which was pretty solid for what it did nearing the completion.

You solved some hard problems with that one.

This program looks great too, best of luck with it
PK
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 15th Dec 2022 22:05
@Fubarpk, you mean the island one? Yeah, I got that pretty close to being a working game, and actually running around chopping down trees and building stuff was quite good fun. However like all things I can't really produce the vast amount of 3D assests I needed. In the end I spent about £100 buying some, which was fine....until another commercial game came out with very similar gameplay and they had very clearly bought from the same artist! So I shelved that one. Lol.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 15th Dec 2022 22:05
So creating a working road system is a little bit harder than I first thought, and I've not had too much time to work on this, but here's a quick progress udpate that should now result in a semi fucntional road system being possible. This adds watchers to specific destination node connections, so that we can impliment a simple right of way for traffic turning across other traffic.

SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 15th Dec 2022 23:54
Nice! You can see that even when your raycasts spike over 70+, you're still at a consistent 152-154 FPS or so, which tells me any performance losses are related more to the added rendering load rather than however many additional raycasts are getting executed. And that is definitely the preferred way for things to operate (held back by GPU/rendering performance more so than coded hinderances).

Small recommendation while this is still early. Unless your trucks are going to have 4-wheel steering, I'd recommend changing their pivot point to the back axle. That way, they'll appear to steer with the front wheels leading the back wheels rather than all four rotating around the center of the truck.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 10th Feb 2023 15:59
Been a while since I did any work on my open world city test, but today I updated the internal scene loading system to be....not just internal.

It can now load as many individual scenes in realtime as you want, so completely open world building internals, for example, are possible with seamless transitions. I can also now set up complex external "detailed areas" anywhere in the world, that load and unload either as the player comes within a certain distance, or enters a specified zone.

SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 10th Feb 2023 19:01
Nice work! Definitely helps for performance optimization.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 3rd Apr 2023 17:25
Quick update on the 3D world - now the engine fully supports multiple scenes with multipole mesh objects, each with unique textures all supported bythe streaming.

Not much to go now until I'm "done" as much ass I want to be, and will make this all public (somehow!).

James H
16
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 3rd Apr 2023 19:18
Very nice, been following this a while, blows my tiny mind - keep it up
Win 10 Home 64, Intel(R) Core(TM) i5-10300H, 8GB DDR4, NVidia GeForce GTX 1650 4GB GDDR6
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 3rd Apr 2023 20:41
Very nice indeed. Cool to watch the textures fade in like that
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 4th Apr 2023 16:34
Hmmmm.....is there an easy way to determine which MESH in an object has bit hit with the casting commands?

in the shop, the walls, floor, exterior etc can all be altered in terms of their texture, I am going to make it so that the player can actively change these, clean them etc. However as the entire shop is one mesh, there is currently no way to tell which editable surface they are hitting.

I am thinking that there needs be some form of toggle which puts the player into editing mode, and at this point I need to create a bunch of new objects form the meshes that make up the shop, turn off collission for the main shop object, turn on collission for each of the new temporary objects, and that way I can detect which surface or editable area within the main object is being collided with. When "editing mode is left, the temp objects are erased and the texture attributes for the meshes in the original object are udpated. The other option is a massive amount of maths and vertice checks to see which mesh contains a vertice closest to or overlapping the 3d raycast point of impact, which seems MUCH harder to me.

Any thoughts?
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 5th Apr 2023 17:17
There isn't an easy way per se, other than to build mesh entities individually as you describe. I use a custom limb system I wrote to perform such operations (among other requirements that a limb framework provides). But if you're working with a single mesh that is square/rectangle in shape, you can also probably just retrieve the contact point via GetObjectRayCastX/Y/Z() and then measure that point relative to wall positions to determine which wall it hit.
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 5th Apr 2023 17:55
Using something like milkshape3d, can you load the shop model, select a part like a wall then regroup and apply the texture.
Do that for all the parts you want as a separate mesh then save it. Would that be the easy way to split the mesh up?
BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.

Login to post a reply

Server time is: 2024-04-19 00:46:34
Your offset time is: 2024-04-19 00:46:34