psilocervine

but wife city is two words

56k warning


cohost (arknights)
cohost.org/arkmints

posts from @psilocervine tagged #programming

also: #software development, #coding

Over here I referenced how the best kinda code to reuse, rather than systems, are simple utilities, and I figured I'd go over that a bit more. For instance, having to write formulas over and over again Sucks Shit From an Ass. The first thing I ended up adding to my (extremely messy and in desperate need of cleanup) FaunaTools library was, as mentioned in that thread over there, a remap function

public float Remap(float input, float min1, float max1, float min2, float max2)
{
     return min2 + (input - min1) * (max2 - min2) / (max1 - min1);
}

I use this all the goddamn time. Like, there is not a single project I have gone "I do not need to remap a range here" with. Not once.

There's other stuff too. If you're getting into some geometry tests (less common, but I do it *often enough), one thing you'll find yourself doing is having to check if a point is within a triangle

public static bool TriangleContains(Triangle _triangle, Vector2 _testPoint)
{
	var area = Area(_triangle.lineA.pointA.position, _triangle.lineB.pointA.position, _triangle.lineC.pointA.position);

	var area1 = Area(_testPoint, _triangle.lineB.pointA.position, _triangle.lineC.pointA.position);
	var area2 = Area(_triangle.lineA.pointA.position, _testPoint, _triangle.lineC.pointA.position);
	var area3 = Area(_triangle.lineA.pointA.position, _triangle.lineB.pointA.position, _testPoint);

	return (area == area1 + area2 + area3);
}
public static float Area(Vector2 _pointA, Vector2 _pointB, Vector2 _pointC)
{
	var pointAX = _pointA.x;
	var pointAY = _pointA.y;

	var pointBX = _pointB.x;
	var pointBY = _pointB.y;

	var pointCX = _pointC.x;
	var pointCY = _pointC.y;

	return Mathf.Abs((pointAX * (pointBY - pointCY) + pointBX * (pointCY - pointAY) + pointCX * (pointAY - pointBY)) / 2.0f);
}

This ends up relying on testing the area of a triangle as well. There are easier ways to do this, I'm certain, but I'm pretty sure wherever I stole acquired this code from did it this way for a reason, and it's not like it's something where I'm gonna be doing it often enough to aggressively optimize it

The running pattern with all this stuff is that it's the kind of thing where the utility is extremely broad. Porting over an entire combat system or something like that with the hopes you can just modify it later is a nice idea, but I don't think I've ever actually encountered something like that where I wasn't just better off making a template project to fill out. ymmv, of course

But like... stick to simple shit. Stick to things where if it was already in the engine you'd end up going "oh thank fuck, it's just a thing I can do" rather than big complex operations. The bigger something is, the more likely it is you're going to spend more time trying to puzzle piece it into a new project