Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
code:
return new[]{
  ConnectionMask.Direction.North,
  ConnectionMask.Direction.East,
  ConnectionMask.Direction.South,
  ConnectionMask.Direction.West}[(int) Mathf.Clamp((x+135)/90, 0, 3)];
:v:

Adbot
ADBOT LOVES YOU

KillHour
Oct 28, 2007


TooMuchAbstraction posted:

code:
return new[]{
  ConnectionMask.Direction.North,
  ConnectionMask.Direction.East,
  ConnectionMask.Direction.South,
  ConnectionMask.Direction.West}[(int) Mathf.Clamp((x+135)/90, 0, 3)];
:v:

That would allocate an array every time it was called. Burst would throw a fit.

Edit: Since it's a flag enum (and already declared clockwise because I foresaw wanting to do something like this), you could do this:

code:
(ConnectionMask.Direction)pow(2, clamp((hitAngle+135)/90, 0, 3));
But nobody looking at that code would have any idea what it did, including me in a month.

KillHour fucked around with this message at 04:05 on May 21, 2020

KillHour
Oct 28, 2007


Code golf version, since it's already clamped to (-180, 180]:

(D)pow(2,((int)x+135)/90);

KillHour fucked around with this message at 04:23 on May 21, 2020

kaffo
Jun 20, 2017

If it's broken, it's probably my fault
Also the first version KillHour posted is drat nice and readable. I understood it in 5 seconds. I don't want to have to sit and stare at a single liner math equation from high school going "Hu so if it's under 135 x is equal to what?"
Personally I'll always sacrifice small performance gains for minor readability gains. Obviously if the performance gain is major then screw you, I'll write a comment :v:

dupersaurus
Aug 1, 2012

Futurism was an art movement where dudes were all 'CARS ARE COOL AND THE PAST IS FOR CHUMPS. LET'S DRAW SOME CARS.'

KillHour posted:

After working pretty much exclusively with JS for the last year for work (with some Python thrown in), I forgot how many good features C# has in newer releases.

code:
var hitConnection = hitAngle switch {
    var x when x < -135 => ConnectionMask.Direction.North,
    var x when x < -45  => ConnectionMask.Direction.East,
    var x when x < 45   => ConnectionMask.Direction.South,
    var x when x < 135  => ConnectionMask.Direction.West,
    _                   => ConnectionMask.Direction.North
};
:allears:

Ditto. I used a lot of ?. in my Sports 2 Jam

Now only if it could recognize the enum context

code:
ConnectionMask.Direction hitConnection = hitAngle switch {
    var x when x < -135 => .North,
    var x when x < -45  => .East,
    var x when x < 45   => .South,
    var x when x < 135  => .West,
    _                   => .North
};

KillHour
Oct 28, 2007


kaffo posted:

Also the first version KillHour posted is drat nice and readable. I understood it in 5 seconds. I don't want to have to sit and stare at a single liner math equation from high school going "Hu so if it's under 135 x is equal to what?"
Personally I'll always sacrifice small performance gains for minor readability gains. Obviously if the performance gain is major then screw you, I'll write a comment :v:

Switch statements are extremely performant, anyways.

Edit: Not as fast as the code golf version I posted - especially since I used the burst versions of the operations, which get turned into SIMD instructions - but much faster than heap-allocating an array and then immediately sending it off for garbage collection.

KillHour fucked around with this message at 14:03 on May 21, 2020

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

kaffo posted:

Also the first version KillHour posted is drat nice and readable. I understood it in 5 seconds. I don't want to have to sit and stare at a single liner math equation from high school going "Hu so if it's under 135 x is equal to what?"
Personally I'll always sacrifice small performance gains for minor readability gains. Obviously if the performance gain is major then screw you, I'll write a comment :v:

Yeah, I wasn't remotely suggesting that my version (or KillHour's responses to same) are superior. Just being silly.

kaffo
Jun 20, 2017

If it's broken, it's probably my fault

TooMuchAbstraction posted:

Yeah, I wasn't remotely suggesting that my version (or KillHour's responses to same) are superior. Just being silly.
Can I be silly too?
code:
enum Direction
{
    North = -135,
    East = -45,
    South = 45,
    West = 135
}

var hitConnection = Direction.North;
List<int> directionAngles = new List<int>((int[])Enum.GetValues(typeof(Direction)));
directionAngles.Sort();

foreach (int thisDirection in directionAngles) {
    if ( hitAngle < thisDirection ) {
        hitConnection = (Direction)thisDirection;
        break;
    }
}
Writing this made me want to cry ngl

KillHour
Oct 28, 2007


Oh my God I just punched my screen why

Whybird
Aug 2, 2009

Phaiston have long avoided the tightly competetive defence sector, but the IRDA Act 2052 has given us the freedom we need to bring out something really special.

https://team-robostar.itch.io/robostar


Nap Ghost

KillHour posted:

Oh my God I just punched my screen why

post ur angle code ppl
code:
public int facing(int choices) {
	float segmentSize = 360 / choices;
	return Mathf.RoundToInt (((_degrees + 360 ) / segmentSize)) % choices;
}

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:

nm i cant be arsed to fix it

taqueso fucked around with this message at 20:53 on May 21, 2020

xgalaxy
Jan 27, 2004
i write code

dupersaurus posted:

Ditto. I used a lot of ?. in my Sports 2 Jam

Now only if it could recognize the enum context

code:
ConnectionMask.Direction hitConnection = hitAngle switch {
    var x when x < -135 => .North,
    var x when x < -45  => .East,
    var x when x < 45   => .South,
    var x when x < 135  => .West,
    _                   => .North
};


Yes. I'd love for them to allow the short form enums. Languages like Swift and Zig do this and it is so nice.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

kaffo posted:

Writing this made me want to cry ngl
Java programmers are invading my codebase at work, and that's what it looks like. :(

KillHour
Oct 28, 2007


dupersaurus posted:

Ditto. I used a lot of ?. in my Sports 2 Jam

Now only if it could recognize the enum context

code:
ConnectionMask.Direction hitConnection = hitAngle switch {
    var x when x < -135 => .North,
    var x when x < -45  => .East,
    var x when x < 45   => .South,
    var x when x < 135  => .West,
    _                   => .North
};

It can. You just have to add it to the definitions.

code:
using static ConnectionMask.Direction;

...

var hitConnection = hitAngle switch {
    var x when x < -135 => North,
    var x when x < -45  => East,
    var x when x < 45   => South,
    var x when x < 135  => West,
    _                   => North
};

xgalaxy
Jan 27, 2004
i write code

KillHour posted:

It can. You just have to add it to the definitions.

code:
using static ConnectionMask.Direction;

...

var hitConnection = hitAngle switch {
    var x when x < -135 => North,
    var x when x < -45  => East,
    var x when x < 45   => South,
    var x when x < 135  => West,
    _                   => North
};

Thats not being context aware though and won't work well. You aren't going to statically namespace every enum you want to interact with and in the hypothetically scenario where two different enum types have the same names for their variants you won't be able to statically namespace one of them. I know it seems stupid to be complaining about something like this.. but a lot of people thought (and some still do) that var is stupid too. But it saves on typing, it saves and noise. And it is convenient.

xgalaxy fucked around with this message at 05:49 on May 22, 2020

KillHour
Oct 28, 2007


That's fair. I've seen proposals to add implicit assignment types (e.g., "Dictionary<int, int> myDict = new ();"), so it might happen.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I thought I knew a thing or two about C# yet here I am, trying to figure out how to get this manhole cover to fit back over the hole I'm crawling back into.

KillHour
Oct 28, 2007


Rocko Bonaparte posted:

I thought I knew a thing or two about C# yet here I am, trying to figure out how to get this manhole cover to fit back over the hole I'm crawling back into.

Don't worry, we're all furiously Googling poo poo as we go.

xgalaxy
Jan 27, 2004
i write code
I thought it was interesting and funny to discover that Minecraft Dungeons is made with Unreal Engine.
I would have thought they would have just built on the existing Minecraft C++ engine.

more falafel please
Feb 26, 2005

forums poster

xgalaxy posted:

I thought it was interesting and funny to discover that Minecraft Dungeons is made with Unreal Engine.
I would have thought they would have just built on the existing Minecraft C++ engine.

Unless you really need to reuse a lot of poo poo from a custom inhouse engine written by an incel it probably makes sense to start over in something that you don't have to spend half your development time hacking it up to make it work for your game

TIP
Mar 21, 2006

Your move, creep.



more falafel please posted:

Unless you really need to reuse a lot of poo poo from a custom inhouse engine written by an incel it probably makes sense to start over in something that you don't have to spend half your development time hacking it up to make it work for your game

I don't even play Minecraft, but I think that would be the Java version. Microsoft spent a bunch of money rewriting it in C++.

abraham linksys
Sep 6, 2010

:darksouls:
This is an extreme long shot, but if anyone here has experience with Bezier curves/splines, I've got a very long question over on Stack Overflow I'd love to get thoughts on https://stackoverflow.com/questions/61966340/how-can-i-build-a-3d-bezier-spline-out-of-predefined-2d-xz-segments-with-a-con

The tl;dr there is that I'm having a heck of a time turning a 2D "top-down" Bezier spline representing a big long track into a 3D spline with a constant rate of descent. I sent that to a friend and their first reaction was "oh just give up on a 3D spline and just turn that poo poo into a points of a 2D spline and then and linearly interpolate your descent over the list of points," which is both a totally reasonable thing to do and also totally feels like admitting defeat. I'm already using a quirky custom spline class wrapping my engine's built-in representation so that I can apply rotation to points along the splines, so maybe adding more behavior to that wouldn't be so bad, but it really feels like a 3D spline should work here.

I'm mostly having fun with splines, at least. There is a lot of decently readable material out there for how Beziers and splines work, just not very much about how procedural generation of pieces of a spline can work. Though there are a lot of loving paid Unity plugins for the latter, I guess because everyone wants to build endless runners.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Dunno about Bezier splines specifically, but in Unity the CinemachineSmoothPath component (part of Cinemachine of course, which is free) will fit a smooth curve through a set of waypoints and they can be 3D or 2D as you like. I'm pretty sure that if you use a continuous Y distance between waypoints then you'll get a fixed rate of descent, too.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

abraham linksys posted:

This is an extreme long shot, but if anyone here has experience with Bezier curves/splines, I've got a very long question over on Stack Overflow I'd love to get thoughts on https://stackoverflow.com/questions/61966340/how-can-i-build-a-3d-bezier-spline-out-of-predefined-2d-xz-segments-with-a-con

The tl;dr there is that I'm having a heck of a time turning a 2D "top-down" Bezier spline representing a big long track into a 3D spline with a constant rate of descent. I sent that to a friend and their first reaction was "oh just give up on a 3D spline and just turn that poo poo into a points of a 2D spline and then and linearly interpolate your descent over the list of points," which is both a totally reasonable thing to do and also totally feels like admitting defeat. I'm already using a quirky custom spline class wrapping my engine's built-in representation so that I can apply rotation to points along the splines, so maybe adding more behavior to that wouldn't be so bad, but it really feels like a 3D spline should work here.

I'm mostly having fun with splines, at least. There is a lot of decently readable material out there for how Beziers and splines work, just not very much about how procedural generation of pieces of a spline can work. Though there are a lot of loving paid Unity plugins for the latter, I guess because everyone wants to build endless runners.

Are you sure you want bezier curves instead of spherical arcs?

KillHour
Oct 28, 2007


abraham linksys posted:

This is an extreme long shot, but if anyone here has experience with Bezier curves/splines, I've got a very long question over on Stack Overflow I'd love to get thoughts on https://stackoverflow.com/questions/61966340/how-can-i-build-a-3d-bezier-spline-out-of-predefined-2d-xz-segments-with-a-con

The tl;dr there is that I'm having a heck of a time turning a 2D "top-down" Bezier spline representing a big long track into a 3D spline with a constant rate of descent. I sent that to a friend and their first reaction was "oh just give up on a 3D spline and just turn that poo poo into a points of a 2D spline and then and linearly interpolate your descent over the list of points," which is both a totally reasonable thing to do and also totally feels like admitting defeat. I'm already using a quirky custom spline class wrapping my engine's built-in representation so that I can apply rotation to points along the splines, so maybe adding more behavior to that wouldn't be so bad, but it really feels like a 3D spline should work here.

I'm mostly having fun with splines, at least. There is a lot of decently readable material out there for how Beziers and splines work, just not very much about how procedural generation of pieces of a spline can work. Though there are a lot of loving paid Unity plugins for the latter, I guess because everyone wants to build endless runners.

Your friend is correct that modifying the height of the output points directly is the way to go - it lets you change the descent rate dynamically and decouples it from the prefab pieces. It's just better design.

But if you're really determined, here you go. There's even JS code for the curves.

https://www.arc.id.au/HelixDrawing.html

leper khan posted:

Are you sure you want bezier curves instead of spherical arcs?

This wouldn't have a constant descent like a helix. At the start of the arc, the descent would be whatever angle, but after 90 degrees, it would be 0. You could approximate a helix with a bunch of them, but it would be pretty jagged.

KillHour fucked around with this message at 04:17 on May 23, 2020

abraham linksys
Sep 6, 2010

:darksouls:

KillHour posted:

Your friend is correct that modifying the height of the output points directly is the way to go - it lets you change the descent rate dynamically and decouples it from the prefab pieces. It's just better design.

But if you're really determined, here you go. There's even JS code for the curves.

https://www.arc.id.au/HelixDrawing.html

After taking the briefest of glances at your link and very quickly agreeing with you that the "proper" fix is overkill (mostly because I do not understand the math involved), I went with the output modification idea, and it looks great!

Here's how it's lookin' now: https://disco.zone/splines/2/

Three JS is pretty fun for these sorts of things, very easy to build out procedural geometry and stuff. Tons of debug tools like the camera I'm using there, too. I kinda wish I knew a good JS game engine that wrapped it. Will probably port my new logic back over to Godot to get back to the game I was making, but GDScript is just idiosyncratic enough to irk me.

KillHour
Oct 28, 2007


Lookin good. Maybe have the banking code keep the angle if the next piece turns in the same direction.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

more falafel please posted:

Unless you really need to reuse a lot of poo poo from a custom inhouse engine written by an incel it probably makes sense to start over in something that you don't have to spend half your development time hacking it up to make it work for your game
There's other stuff you can reuse too (i.e. gameplay systems), but it's mostly a function of how similar the game you're making is to the one you already made, and Minecraft Dungeons and Minecraft have almost nothing to do with each other aside from the art style.

more falafel please
Feb 26, 2005

forums poster

OneEightHundred posted:

There's other stuff you can reuse too (i.e. gameplay systems), but it's mostly a function of how similar the game you're making is to the one you already made, and Minecraft Dungeons and Minecraft have almost nothing to do with each other aside from the art style.

Yeah, this is my point. A company I used to work for tried to make a God of War/Batman-style action adventure game in their extremely custom fighting game engine and it was basically the worst idea

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

more falafel please posted:

Yeah, this is my point. A company I used to work for tried to make a God of War/Batman-style action adventure game in their extremely custom fighting game engine and it was basically the worst idea

If you want a similar example, Batman Forever was a fighting/platformer game made with the Mortal Kombat SNES engine. It is so terrible.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!

TooMuchAbstraction posted:

If you want a similar example, Batman Forever was a fighting/platformer game made with the Mortal Kombat SNES engine. It is so terrible.
I actually enjoyed that game but I was like 13 at the time, so...

Fun trivia: The Genesis version is different in various ways, some good, some bad. The best is that there are no "HOLD ON" loading screens, and some of the moves are different (Batman's electro pellet is much better).

The worst... since it uses fighting game inputs that normally assume "forward" and "back" are relative to a single opponent, things don't work well when there can be enemies on either side of you! You know how they say some inputs require holding the strafe button? There is no strafe button on Genesis because there aren't enough buttons, so any command that requires a "back" input only works if you're close enough to an enemy for it to lock your facing direction.

Naturally, Robin's long-range projectile input is For+For+Back+C

OneEightHundred fucked around with this message at 01:20 on May 24, 2020

Absurd Alhazred
Mar 27, 2010

by Athanatos

OneEightHundred posted:

I actually enjoyed that game but I was like 13 at the time, so...

Fun trivia: The Genesis version is different in various ways, some good, some bad. The best is that there are no "HOLD ON" loading screens, and some of the moves are different (Batman's electro pellet is much better).

The worst... since it uses fighting game inputs that normally assume "forward" and "back" are relative to a single opponent, things don't work well when there can be enemies on either side of you! You know how they say some inputs require holding the strafe button? There is no strafe button on Genesis because there aren't enough buttons, so any command that requires a "back" input (which includes Robin's main long-range projectile) only works if you're close enough to an enemy for it to lock your facing direction.

AKA emergent flanking. :v:

TIP
Mar 21, 2006

Your move, creep.



TooMuchAbstraction posted:

If you want a similar example, Batman Forever was a fighting/platformer game made with the Mortal Kombat SNES engine. It is so terrible.

Back in 2000 there was an FPS called Project IGI that was built on a flight simulator engine. It was pretty neat at the time because the maps and draw distances were huge compared to most other FPS.

https://m.youtube.com/watch?v=f_9LtmxDPiI

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
The only cases I know of where an insane engine choice worked out somewhat is Anachronox and God of War.

KillHour
Oct 28, 2007


Tip posted:

Back in 2000 there was an FPS called Project IGI that was built on a flight simulator engine. It was pretty neat at the time because the maps and draw distances were huge compared to most other FPS.

https://m.youtube.com/watch?v=f_9LtmxDPiI

That doesn't look half bad outside of the terrible animations and sound design. It seems technically competent, at least.

more falafel please
Feb 26, 2005

forums poster

Tip posted:

Back in 2000 there was an FPS called Project IGI that was built on a flight simulator engine. It was pretty neat at the time because the maps and draw distances were huge compared to most other FPS.

https://m.youtube.com/watch?v=f_9LtmxDPiI

NBA Ballers (and Ballers 2: Phenom and Ballers 3: Contractual ObligationChosen One) were built on a flight sim engine, with some wacky +Z down coordinate system.

Whybird
Aug 2, 2009

Phaiston have long avoided the tightly competetive defence sector, but the IRDA Act 2052 has given us the freedom we need to bring out something really special.

https://team-robostar.itch.io/robostar


Nap Ghost

OneEightHundred posted:

The only cases I know of where an insane engine choice worked out somewhat is Anachronox and God of War.

For a moment there I thought you were trying to say that God of War ran on the Anachronox engine. :psyduck:

abraham linksys
Sep 6, 2010

:darksouls:
another day, another long-winded question about splines:

So, I've now got a nice spline renderer that is able to build a whole lotta triangles to render, all great. I'm now thinking about, uh, whatever game I'd like to make with this.

The simplest kind of game to make would probably be something "Audiosurf-y," where movement is just following the spline as a path (with some offset). This was kinda my original plan, to make some sorta shooty or avoidance game with it. This would be relatively easy, and I already did some prototypes (sans fancier curve generation stuff) in Godot - the main missing piece here is that I haven't yet added a method for smooth traversal along my newly-height-adjusted spline, but I think that should be pretty easy to do with arc distance approximation between the generated points like any other curve.

One thing I am kinda curious about, though, is building some sort of more traditional racing game that actually uses the spline as a surface (given an extruded "track width" and set normals for turns etc.), rather than just a path. This would be something more like Impossible Road or just a generic driving game, where you race up and down the curve as a solid road and have to actually turn to follow it.

Now, I should note here my prototype is still just a Three JS thing, which is just a renderer; I don't yet have a physics engine or collision system at my disposal. That said, I'll almost certainly end up moving to Unity/Godot/something to do this, since god knows I don't want to reimplement physics and 3D collisions myself (there are a handful of JS options, but they're mostly like C++ libraries compiled to JS with questionable performance and API usability). So I'm not trying to find any specific concrete implementation of physics/collision yet, I'm just trying to think about it in the abstract.

So, how would I move my car on the surface of the spline? My initial thought was "well, I'm turning this curve into a series of points and triangle segments connecting them for rendering, why not use that logic to create some kind of collider"? In my head, it could maybe like... raycast the "car" forward (relative to the normal, so it can handle banked corners) and get a collision vector from whatever triangle it's intersecting with? But trying to Google this idea has shown me very few results, which makes me think it might be, uh, a bad idea.

I can't find a lot online about this, so I'm curious if anyone knows of general ways to do this (or topics I should be researching). The closest I've seen is that in Unity most people use a "MeshCollider" to generate a collider from their generated mesh. I think Godot has an equivalent of this, though the documentation for anything 3D in Godot is basically nonexistent, so I can't quite confirm this. I'm concerned one giant collider wouldn't be particularly performant, though, so I'm wondering if there's some sort of simpler decomposition that makes sense - I guess I could generate a "box collider" for every two triangles of my curve (with a slight bit of rounding as a result since the triangles are not actually parallel right triangles around corners? But I worry like smoothly passing over a bunch of potentially-overlapping colliders like that would be a tricky problem; reminds me of my difficulties getting tile-based 2D platformers to not stick characters on edges and stuff.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe
Yeah, you'd use a mesh collider (or a bunch of mesh colliders, one per section of the course) for this. For the overlap concern, you can have overlapping colliders rounded off at the ends, like this:



In other words, each collider goes one step past where it would normally end, but that step is recessed into the ground.

Adbot
ADBOT LOVES YOU

KillHour
Oct 28, 2007


Make a procedural version of SSX, complete with a :krad: 90's soundtrack.

Basically, this but snowboarding.

https://squidsquadgames.itch.io/tanuki-sunset

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply