Ostriv

Started by Asid, April 17, 2018, 03:55:15 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Asid

Alpha 5 patch 9 hotfix 55
Mon, May 11, 2026



Here I'm gonna touch a subject of an explosion of complexity in case of adding another kind of freedom for a player. In the previous post I mentioned a new feature for some of the free-form buildings which will have this freedom.


In Alpha 5 some buildings could be given any form as long as it has 4 sides and stays convex. Getting rid of that limitation sounds as simple as just adding more points, but in reality a lot of optimizations and code simplifications relied on that. Convex shapes math is much more simple than concave.
Take pavement for example, as it's the simplest case. Graphically it is straightforward: you generate a quad of two triangles, render them to texture map and use this map in terrain fragment shader to apply cobblestone texture where needed. To support more advanced concave polygonal forms you only need to add actual triangulation (converting the polygon to a set of triangles usable by GPU) to the mix and proceed the same as before.
But then it gets a bit more complicated. Buildings can be selected by the player and need to look selected. Previously you relied on a simple check in a fragment shader which did a nice rounded outline on the ground around the building based on 4 points you supply.



But performing that check for a complex polygon with arbitrary number of sides in fragment shader quickly becomes a performance disaster, especially on lower-end GPUs.
So now you need to provide an alternative selection which relies on a separate set of triangles for transparent fill and elevation-adjusted strips for edges. You even add circles on each point to imitate rounding. It may even look almost as good as the original:



Also it turns out that your picking system relied on convex shapes to determine on which building the player clicked. It is actually related to the system which checks if a building the player is trying to place is overlapping with any of the other buildings. So the whole thing needs to be refactored to support concave shapes too. Once you did that you notice the new code is not so fast due to more complex checks, so you add bounding boxes for each shape and first check bounding boxes (cheaper test) before checking polygons.
But that still isn't the hard part. Since pavement in Ostriv is not just painted, but built part-by-part, we also need construction workers to walk from stone stack position to each point inside the area. It was quite simple with 4-sided convex shapes: you generate a grid of points and stack is connected directly to each one of them with a straight line, reducing load on pathfinding system (there can be hundreds of grid points). With concave shapes there's no guarantee that the line is not obstructed by some other building. So now you need to add a micro-level pathfinding for pavement construction.
Did I mention those little flags around construction site? Previously they we generated as a convex hull around building. This obviously needs to be changed too.
I'm not even sure I remembered everything, but you get the idea of how much more work a simple task of adding a few more points to the shape can create.
Now looking forward to working on the house yards next.

Meanwhile, here's what we have now:

Added/changed:
  • Can now hold Shift to order all carts/ploughs/wagons/etc.
  • Minor UI changes
  • The church will now keep records of all christenings, marriages and burials




  • The town hall will keep records of arrival and departure of citizens

Fixed:
  • The crops gone invisible in December if not harvested
  • Supply options numbers didn't save on lost focus
  • Supply sources "Add" button didn't show after deleting a source
  • Stores and market stalls didn't quite work well with specified supply sources
  • "Replant automatically" was always on, no matter the setting
  • Crash related to fences and blocked way
  • Wrongfully exhausted soil on new field in some cases
  • Stone stack wasn't visible during pavement construction
  • Mouse cursors could reset while dragging animals or vehicles
  • Treasury stats didn't update buttons' tooltips properly

I stand against Racism, Bigotry and Bullying