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
taqueso
Mar 8, 2004


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

:pirate::hf::tinfoil:

sorry, too busy reimplementing custom wheels for my game, i'll try out that fancy csc stuff later

Adbot
ADBOT LOVES YOU

redleader
Aug 18, 2005

Engage according to operational parameters
i've always wondered how games are architected, since i figured anything with that much special cases and edge cases and global state and weird interactions must have some fairly decent ways to control complexity

turns out they just throw everything into global state and i'm just not cynical enough

taqueso
Mar 8, 2004


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

:pirate::hf::tinfoil:

realtalk UE4 is pretty well designed, they discourage global state though it is of course possible. It's open source so you can check it out, you have to make an epic account to access the repo for some reason

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

redleader posted:

i've always wondered how games are architected, since i figured anything with that much special cases and edge cases and global state and weird interactions must have some fairly decent ways to control complexity

turns out they just throw everything into global state and i'm just not cynical enough

sometimes yeah but there are much better ways to do it

Volguus
Mar 3, 2009

taqueso posted:

realtalk UE4 is pretty well designed, they discourage global state though it is of course possible. It's open source so you can check it out, you have to make an epic account to access the repo for some reason

Oh nice, that's interesting. I know nothing about games & game development (wrote a few tetris clones in my life) but I wrote an ImGUI based application last year because I needed quite a bit of graphics manipulation and I thought that it will be easier for me to just go full in rather than just use an OpenGL component in an Qt application (for example).
Well, yeah, I had to manage all that state by myself, and it was not fun. The application is working, is cool and I'm proud of what I've created, but I wouldn't go this route again. For someone coming from game development though, I presume it's quite straightforward and probably even desirable.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


https://twitter.com/vamchale/status/1215787244633628672

Bongo Bill
Jan 17, 2012

redleader posted:

i've always wondered how games are architected, since i figured anything with that much special cases and edge cases and global state and weird interactions must have some fairly decent ways to control complexity

turns out they just throw everything into global state and i'm just not cynical enough

Game devs can get by with "good enough" programming until it isn't good enough. But there are very sound patterns for architecting games, the most common of which is "entity-component-system."

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
the standard "modern" way of writing gameplay code involves handling the entire matrix of pairwise interactions explicitly, but having a ton of support / helper code to make standard cases easy, and it tends to be pretty clean

VikingofRock
Aug 24, 2008




Suspicious Dish posted:

the standard "modern" way of writing gameplay code involves handling the entire matrix of pairwise interactions explicitly, but having a ton of support / helper code to make standard cases easy, and it tends to be pretty clean

As someone who doesn't know much about games programming, is this effectively what an Entity Component System is?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
ECS is confusing, because it quickly became the name for two different patterns

The first should simply be called "component architecture", and it just means having a generic grab bag base actor class, called an "Entity", that you add "Components" to. these components might be tags like "Selectable" or "Enemy" or something which can tell different systems what kind of an actor it is, or it might have components with behavior like "SoundEmitter" or "CatAI" or "PhysicsObject". the idea behind this architecture is to work around the limitations of OOP-style single inheritance by splitting up behavior into a number of different composable things that your object can almost "inherit" from, with each one of those called "Components". this is the architecture behind Unity's GameObject and MonoBehavior.

it has nothing to do with ECS

ECS is really called "Entity-Component-Systems", and that last one is pluralized for a reason, because System here isn't describing the overall architecture, it's describing an actual object called a System

things are almost the same, except that Entity basically becomes nothing more than an integer ID, Components are nothing but data, and Systems are things that run over entities and components and update them.

basically, we split up the Component into a bunch of data, and a method that acts on that data. the idea behind this architecture is 1) parallelism, as in theory you can run a bunch of Systems in parallel, 2) performance through cache efficiency. Since Components are just structures in memory, you can have a giant array of them, and when your system runs, it updates each one in order, leading to a very cache efficient system, assuming there's no pointer chasing going on in your Data.

It was originally invented by Mike Acton and was part of his "data-oriented programming" push. This is the idea behind Unity's new "DOTS" projects (Data Oriented Technology Stack), like the C# Job System and the Burst compiler. Mike Acton actually works at Unity now, too.

taqueso
Mar 8, 2004


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

:pirate::hf::tinfoil:

ECS is really hot these days because (besides the data driven stuff which is cool on its own and the bigger benefit imo) it has good cache coherency and parallelizes well so performance is good on modern systems. Which I see dish touched on a little.

Athas
Aug 6, 2007

fuck that joker

This is not a semicolon, but a Greek question mark or something like that. Programming languages that permit Unicode symbols are pretty much vulnerable to the same kinds of vulnerabilities as typosquatting (Haskell particularly so, since you are allowed to define operators that consist solely of punctuation).

dick traceroute
Feb 24, 2010

Open the pod bay doors, Hal.
Grimey Drawer
So the horror is twitter's display of it?

Athas
Aug 6, 2007

fuck that joker
No, a Greek question mark looks visually the same as a semicolon in most fonts (as it's supposed to), but it's a different character with a different encoding and semantic meaning. It's like the difference between А (CYRILLIC CAPITAL LETTER A) and A (LATIN CAPITAL LETTER A).

lobsterminator
Oct 16, 2012




repiv posted:

The developer of classic indie game VVVVVV just released its source code to celebrate its 10 year anniversary

https://github.com/TerryCavanagh/VVVVVV/blob/master/desktop_version/src/Game.cpp

tag yourself i'm the 4000 line switch statement that appears to contain most of the gameplay logic

actually no i'm the build instructions urging you to only using debug builds because optimizations break the game

I've been writing a simple game project for my own amusement in C89 because I like retro computing and I'm keeping the door open to port it for Amiga and/or DOS. I'm not experienced in game programming so I often struggle with keeping the architecture sensible. Reading that code makes me feel like I could cut myself some slack in order to make progress easier. Even if I turn my brain off completely and hack away it would probably turn out more reasonable than that.

That's what I miss about my teenage years when I had that similar drive to do make something at any means I could. It's a lot better to have a shittily coded successful game than elegantly coded unfinished one.

NtotheTC
Dec 31, 2007


I know nothing about game programming. How much separation is there between things like the graphics engine and "gameplay" logic (i.e. shootmans = he loses 10hp)?

I have to believe that modern graphics engines or physics engines have some decent code behind them and aren't just a load of switch statements. Surely. Please?

QuarkJets
Sep 8, 2008

NtotheTC posted:

I know nothing about game programming. How much separation is there between things like the graphics engine and "gameplay" logic (i.e. shootmans = he loses 10hp)?

I have to believe that modern graphics engines or physics engines have some decent code behind them and aren't just a load of switch statements. Surely. Please?

There's a shitload of separation

but it's all just as bad

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Coming to it completely naively I would assume that if you care about writing maintainable code, what you do is to separate concerns like you would in many other types of app. So you have a model of the game world that is responsible for knowing things like how much HP a character has, and responds to events coming from (say) the physics engine to update the model. And then you have the display code that is informed of the current state of the world by the model.

But I have no experience with programming of any real-time game.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

lobsterminator posted:

I've been writing a simple game project for my own amusement in C89 because I like retro computing and I'm keeping the door open to port it for Amiga and/or DOS. I'm not experienced in game programming so I often struggle with keeping the architecture sensible. Reading that code makes me feel like I could cut myself some slack in order to make progress easier. Even if I turn my brain off completely and hack away it would probably turn out more reasonable than that.

That's what I miss about my teenage years when I had that similar drive to do make something at any means I could. It's a lot better to have a shittily coded successful game than elegantly coded unfinished one.

Sometimes there's even value in starting with lovely code first. It can help clarify where the abstractions should be, whereas you might wind up with leaks and anti-patterns if you start building the architecture without understanding the domain.

Bongo Bill
Jan 17, 2012

The main problem with bad code is that eventually it becomes extremely difficult to make further changes to. If you're motivated by the compulsion toward artistic expression, and you've got a relatively fixed finishing point, it's entirely possible that the point where you're overwhelmed by technical debt comes after the point where the game is released, even if you're an unsophisticated programmer.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

NtotheTC posted:

I know nothing about game programming. How much separation is there between things like the graphics engine and "gameplay" logic (i.e. shootmans = he loses 10hp)?

I have to believe that modern graphics engines or physics engines have some decent code behind them and aren't just a load of switch statements. Surely. Please?

Yeah, there tends to be a separation between core systems & gameplay. Physics engines are usually pretty terrible code though anyway, but I just have a strong bias against physics systems in general lol

Absurd Alhazred
Mar 27, 2010

by Athanatos

DaTroof posted:

Sometimes there's even value in starting with lovely code first. It can help clarify where the abstractions should be, whereas you might wind up with leaks and anti-patterns if you start building the architecture without understanding the domain.

Yeah, I'd say a good middle ground is to limit your scope, write lovely code for it until it works, then clean it up before it needs to play nice with anything else. If you can then make another implementation of the same feature, that will help you clean up the structure and realize where you've been way too closely tied to the underlying hardware/driver/whatever, which if nothing else, is bad if it ever gets updated in a breaking way.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
in general i think people have too much of a reaction to jump to "lovely code" when it's either simply unfamiliar code, or solving a problem you don't know all the nuances of

as i get more and more familiar with codebases that most people bounce off of, i tend to fall in love with their idiosyncracies and weird conventions and love it all the more. but i think given my posts you guys know i have awful programming opinions anyway

like, i've been reverse engineering wind waker's codebase, something i used to think was impossibly miserable. japanese names are all two-letter abbreviations owing to that culture, so you get class names like "dCcD_GAtTgCoCommonBase"

but once you figure out what all that stands for, you're over the big psych hurdle and it's mostly smooth sailing

Presto
Nov 22, 2002

Keep calm and Harry on.

Bongo Bill posted:

Game devs can get by with "good enough" programming until it isn't good enough.

I think this is most software. You start coding and soldier onward until that inevitable day when you realize you made a bad design decision back on day 2 and now it's wrecking the project.

At that point one of two things happens: You either rewind and fix the underlying flaw, which takes a lot of time and effort; or you say gently caress it and start bolting on workarounds and hacks.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

NtotheTC posted:

I know nothing about game programming. How much separation is there between things like the graphics engine and "gameplay" logic (i.e. shootmans = he loses 10hp)?

I have to believe that modern graphics engines or physics engines have some decent code behind them and aren't just a load of switch statements. Surely. Please?

The game engine usually doesn't know about bullets, hitpoints, etc. There will be a player entity, and when the player clocks the mouse it will call the player entity's shoot function (or something is registered to listen to the button or whatever). The player entity will have a current weapon, which will have its fire method triggered. That weapon will have some way of doing something. This can be hit scan (draw a vector where the player is pointing, and call damage on whatever it hits first, or register a bullet hole detail etc). Or, instead of a simple vector it might create a new bullet entity, which now has a direction and speed assigned. Every game tick the bullet entity will be moved forward (gravity influence optional, allowing for bullet drop). On every clock tick off the game engine, every entity movement will happen, and if something intersects a collision is registered; the bullet tells the entity it collides with "do -10 health". The entity it applies to may decide to do something as a result, etc.

Meanwhile, the entity will have a way to describe to the game engine how it should be rendered. The graphics engine generally doesn't care about the details of the entity, just that it should be drawn a certain way.

The older iD engines are open source, you might want to see about picking one up, compiling it, then tinkering to see what happens. I remember learning and internalizing a lot of this with the first half life game making a mod for it

Ruzihm
Aug 11, 2010

Group up and push mid, proletariat!


Suspicious Dish posted:

it's mostly smooth sailing

:ocelot: :imunfunny:

Ruzihm fucked around with this message at 22:34 on Jan 11, 2020

lobsterminator
Oct 16, 2012




Suspicious Dish posted:

in general i think people have too much of a reaction to jump to "lovely code" when it's either simply unfamiliar code, or solving a problem you don't know all the nuances of

as i get more and more familiar with codebases that most people bounce off of, i tend to fall in love with their idiosyncracies and weird conventions and love it all the more. but i think given my posts you guys know i have awful programming opinions anyway

like, i've been reverse engineering wind waker's codebase, something i used to think was impossibly miserable. japanese names are all two-letter abbreviations owing to that culture, so you get class names like "dCcD_GAtTgCoCommonBase"

but once you figure out what all that stands for, you're over the big psych hurdle and it's mostly smooth sailing

You see "dCcD_GAtTgCoCommonBase" but I just see the lady in a red dress.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

Suspicious Dish posted:

in general i think people have too much of a reaction to jump to "lovely code" when it's either simply unfamiliar code, or solving a problem you don't know all the nuances of

The trouble here is that knowing whether what you're seeing is nonsense or simply not something you've learned can only be gleaned after getting your head wrapped around both the code as well as the domain as well as just experience with code in general.

Game code tends to be a mess because a lot of what establishes structure - at least to business development - isn't necessarily *fast*.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
I've seen where someone will do stuff like write out a function that returns a boolean as if ... return ... else ... return ..., and maybe there's some expressions that can be simplified, a variable gets reassigned where it really shouldn't, small things like that; but the overall layout of the project is very thoughtful and understandable. I'd definitely prefer to work with that, than the other way around.

Beef
Jul 26, 2004
The Celeste player class is often thrown around in discussions like these. It's super brancy logic full of manually crafted edge cases, so it makes sense that the code follows that structure. I don't consider it horrific.

https://github.com/NoelFB/Celeste/blob/master/Source/Player/Player.cs

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Yeah, I think that class is actually really good. Maybe some of the animation code could be cleaned up, but the core logic is sound and sane. I wouldn't change much.

Linear Zoetrope
Nov 28, 2011

A hero must cook

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Athas posted:

This is not a semicolon, but a Greek question mark or something like that. Programming languages that permit Unicode symbols are pretty much vulnerable to the same kinds of vulnerabilities as typosquatting (Haskell particularly so, since you are allowed to define operators that consist solely of punctuation).

When I copy it out of the tweet, it's a semicolon, so did she just write a semicolon because it's easier than typing a Greek question mark on her phone or whatever or has Twitter or Chrome "helpfully" coalesced it into the ASCII code for me?

Xarn
Jun 26, 2015
C++ code:
bool trigraphs_are_available() {
    // Are trigraphs available??/
    return false;
    return true;
}

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Xarn posted:

C++ code:
bool trigraphs_are_available() {
    // Are trigraphs available??/
    return false;
    return true;
}

Never forget:

"We realize the world is moving mostly to non-EBCDIC..." (IBM, in the Year of Our Lord 2014)

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


https://twitter.com/jxxf/status/1219009308438024200

TheresaJayne
Jul 1, 2011

Volmarias posted:

If something looks strange, it's way more helpful to have a quick comment than to have to blame the source and do archaeology.

Commit messages should definitely be detailed here as well, but it's foolish to not document the actual code.

Its all about comments should be why not what.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
code:
public void Dispose()
{
    DoDispose();
}

private void DoDispose(int retryCount = 0)
{
    // delay disposal of services scope for up to 10 seconds if background cache item refresh is in progress
    // note: required to prevent EF context from being immediately disposed on request end
    if (retryCount < 10 && CacheService().BackgroundRefreshInProgress)
    {
        Task.Run(async () =>
        {
            await Task.Delay(1000);
            DoDispose(retryCount + 1);
        });
    }
    else
    {
        Scope.Dispose();
    }
}
Came across this idiotic poo poo today after spending days trying to figure out an early dispose bug. This is not the first time I've found code that shows the author had absolutely no idea what "async" actually means.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

a hot gujju bhabhi posted:

code:
public void Dispose()
{
    DoDispose();
}

private void DoDispose(int retryCount = 0)
{
    // delay disposal of services scope for up to 10 seconds if background cache item refresh is in progress
    // note: required to prevent EF context from being immediately disposed on request end
    if (retryCount < 10 && CacheService().BackgroundRefreshInProgress)
    {
        Task.Run(async () =>
        {
            await Task.Delay(1000);
            DoDispose(retryCount + 1);
        });
    }
    else
    {
        Scope.Dispose();
    }
}
Came across this idiotic poo poo today after spending days trying to figure out an early dispose bug. This is not the first time I've found code that shows the author had absolutely no idea what "async" actually means.

Despite working with async code in the past, I often find it difficult to wrap my head around it and I'm sure others do too. Could you help spread the knowledge by explaining why this code fails to do what the author intended it to do, and how you would go about fixing it (if you had to content yourself with just putting a bandaid on it?)

Adbot
ADBOT LOVES YOU

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
I'm not a c# dev, but seems like

- This doesn't need to be recursive, it should absolutely be iterative
- CacheService should have an async function that completes when the background refresh is no longer in progress
- Task.Run returns immediately, although it's not clear if the author wanted the waiting to happen on another thread or not so that might be ok, but recursively making a new thread each time is gross

Edit:
Assuming we can't do #2 and #3 is expected behavior, seems like we can do slightly better with

code:
public void Dispose()
{
  Task.Run(async () =>


    // delay disposal of services scope for up to 10 seconds if background cache item refresh is in progress
    // note: required to prevent EF context from being immediately disposed on request end
    var count = 0
    while (count++ < 10 && CacheService().BackgroundRefreshInProgress) {
            await Task.Delay(1000);

        }
    }
    if(!CacheService().BackgroundRefreshInProgress) {
        Scope.Dispose();
    });
}

Volmarias fucked around with this message at 23:45 on Jan 21, 2020

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