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
JawnV6
Jul 4, 2004

So hot ...

MononcQc posted:

I realized that I have not frequently needed to make these decisions at a conscious level and I have no good heuristic.

do you have a specific use case? aside from high school dimensional analysis or hw-constraints, there's not much too it that'll apply much higher

Adbot
ADBOT LOVES YOU

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
kinda neat

MononcQc
May 29, 2007

JawnV6 posted:

do you have a specific use case? aside from high school dimensional analysis or hw-constraints, there's not much too it that'll apply much higher

Nah not really. I mean I have been programming in languages with bignums for most of my career, and I mostly just winged it when I handled binary protocols. So you end up going with sizes based on how many types you want to represent, and for types something like "this is a 32 bit unsigned integer as a size tag, if you need more you just gotta use this additional continuation flag" and realized I had no good mechanism to choose aside from trying to guess.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

MononcQc posted:

Nah not really. I mean I have been programming in languages with bignums for most of my career, and I mostly just winged it when I handled binary protocols. So you end up going with sizes based on how many types you want to represent, and for types something like "this is a 32 bit unsigned integer as a size tag, if you need more you just gotta use this additional continuation flag" and realized I had no good mechanism to choose aside from trying to guess.

as someone in the process of learning lower level programming i totally get where you're coming from. this has always made me super anxious and i'm glad you asked.

my experience so far has been that you usually have some hardware constraints or similar that are informing your decisions. other than that, absent some specific requirement, i think it's either "the most performant thing you can get away with on the platform", or "the safest thing you can get away with on the platform" (just like higher level programming). but like, take this with a massive grain of salt, i'm definitely in the middle of learning.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

MALE SHOEGAZE posted:

as someone in the process of learning lower level programming i totally get where you're coming from. this has always made me super anxious and i'm glad you asked.

my experience so far has been that you usually have some hardware constraints or similar that are informing your decisions. other than that, absent some specific requirement, i think it's either "the most performant thing you can get away with on the platform", or "the safest thing you can get away with on the platform" (just like higher level programming). but like, take this with a massive grain of salt, i'm definitely in the middle of learning.

if you don't care the best case is probably the machine word size. doing stuff in C like:

code:
for (char i = 0; i < 10; i++) {
  // do something
}
may end up compiled as 'i' as an int because it's faster on a particular architecture.

then you also sometimes have to worry about misaligned memory access, which can bite you if you're not careful.

for example, on some arch that requires aligned memory access, say you are trying to write to a binary blob somewhere, and the format is defined as:

code:
 8 bit     32bit   32bit   32bit ....
<length>, <num0>, <num1>, <num2>, ..., <num (length -1)>
so then you do something like

code:
unsigned char buffer[256];
unsigned char *p = &buffer[0];
*p = 3;
p++;
*((uint32_t *)p) = 123; // misaligned memory access, this will segfault
p += 4;
*((uint32_t *)p) = 456;
p += 4;
*((uint32_t *)p) = 678;
so there's other things you need to worry about besides just size.

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
^^I have a feeling some of that might be germane to my question :).

Ok, I don't fully understand the rotation the emulator101 author is doing, and I'm also a little bit confused about his C. Does it look like I've translated this correctly? I'm not sure that it's wrong, I just want to check it off my list of things that could be broken.

author's code:
https://github.com/kpmiller/emulator101/blob/master/CocoaPart3-Attract/InvadersView.m#L61
code:
#define RGB_ON   0xFFFFFFFFL
#define RGB_OFF 0x00000000L

    unsigned char *b = (unsigned char *)buffer8888; // buffer8888 = malloc(4 * 224*256);
    unsigned char *fb = [invaders framebuffer]; //  a pointer to malloc(16 * 0x1000) offset by 0x2400.
    for (i=0; i< 224; i++)
    {
        for (j = 0; j < 256; j+= 8)
        {
            int p;
            //Read the first 1-bit pixel
            // divide by 8 because there are 8 pixels
            // in a byte
            unsigned char pix = fb[(i*(256/8)) + j/8];
            
            //That makes 8 output vertical pixels
            // we need to do a vertical flip
            // so j needs to start at the last line
            // and advance backward through the buffer
            int offset = (255-j)*(224*4) + (i*4);
            unsigned int*p1 = (unsigned int*)(&b[offset]);  // This is where i'm suspicious
            for (p=0; p<8; p++)
            {
                if ( 0!= (pix & (1<<p)))
                    *p1 = RGB_ON;
                else
                    *p1 = RGB_OFF;
                p1-=224;  //next line
            }
        }
}
my code:
code:
    // FB_SIZE is 0x4000 - 0x2400 = 7168 bytes
    fn update_buf(&mut self, fb: [u8; FB_SIZE]) {
        for i in 0..224 {
            let mut j = 0;
            while j < 256 {
                let pixel_offset = (i * (256 / 8)) + j / 8;
                let pixel = fb[pixel_offset];
                let mut offset = (255 - j) * (224 * 4) + (i * 4);

                for p in 0..8 {
                    // I do not understand what this is testing, but I think it's correct anyhow.
                    let p1 = if 0 != (pixel & (1 << p)) {
                        0xff
                    } else {
                        0x00
                    };

                    // self.buf is [u8;4 * 224 * 256]
                    self.buf[offset] = p1;
                    self.buf[offset + 1] = p1;
                    self.buf[offset + 2] = p1;
                    // ggez (game framework) works with rgba, but authors config ignores alpha channel.
                    // So, our last byte represents the alpha channel, which we always want turned up 2 max,
                    // even when the other bytes are 0x0.
                    self.buf[offset + 3] = 0xff;
                    offset -= 224;
                }
                j += 8;
            }
        }
    }
i think the problem might be with how c/objc are going to behave with pointer offsets into a raw malloc, i've never done that before and i'm not sure that i'm getting the right behavior in rust. i'm also not sure that stuffing 4 bytes into my u8 array is the same as stuffing a 32-bit long into a raw buffer.

this relatively simple rotation is melting my brain so i think we can rule out graphics stuff for me.

DONT THREAD ON ME fucked around with this message at 16:14 on Aug 22, 2018

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
"I do not understand what this is testing, but I think it's correct anyhow."

space invaders uses 1-bit color, so it's on/off. in a single byte it represents 8 pixels, but in the target buffer it expects each pixel to be 32-bit (0xAARRGGBB probably).

the for loop is basically doing

code:
if (input & 0b00000001) {
  output[0] = 0xffffffff;
} else {
  output[0] = 0x00000000;
}

if (input & 0b00000010) {
  output[1] = 0xffffffff;
} else {
  output[1] = 0x00000000;
}

if (input & 0b00000100) {
  output[2] = 0xffffffff;
} else {
  output[2] = 0x00000000;
}

// etc etc
edit: the rest of it looks like the rotation is right, though, but that's just a quick glance

CRIP EATIN BREAD fucked around with this message at 16:20 on Aug 22, 2018

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

CRIP EATIN BREAD posted:

"I do not understand what this is testing, but I think it's correct anyhow."

space invaders uses 1-bit color, so it's on/off. in a single byte it represents 8 pixels, but in the target buffer it expects each pixel to be 32-bit (0xAARRGGBB probably).

the for loop is basically doing

code:
if (input & 0b00000001) {
  output[0] = 0xffffffff;
} else {
  output[0] = 0x00000000;
}

if (input & 0b00000010) {
  output[1] = 0xffffffff;
} else {
  output[1] = 0x00000000;
}

if (input & 0b00000100) {
  output[2] = 0xffffffff;
} else {
  output[2] = 0x00000000;
}

// etc etc
edit: the rest of it looks like the rotation is right, though, but that's just a quick glance

thanks, that made it click for me.

Lime
Jul 20, 2004

You do you have one problem: in the C code, p1 is an unsigned int* so p1 -= 224 is actually moving p1 back by 224 * sizeof(unsigned int) bytes, ie, 224 * 4 bytes. But in your code, you're working with byte offsets directly, so you need to do offset -= 224 * 4 (which is the actual size in bytes of one row because it's 32bpp).

Lime fucked around with this message at 20:55 on Aug 22, 2018

Lime
Jul 20, 2004

oops doublepost

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Lime posted:

You do you have one problem: in the C code, p1 is an unsigned int* so p1 -= 224 is actually moving p1 back by 224 * sizeof(unsigned int) bytes, ie, 224 * 4 bytes. But in your code, you're working with byte offsets directly, so you need to do offset -= 224 * 4 (which is the actual size in bytes of one row because it's 32bpp).



!!!!!!!!!!!!!!!

CPColin
Sep 9, 2003

Big ol' smile.
NICE!

Lime
Jul 20, 2004

CPColin
Sep 9, 2003

Big ol' smile.
I can't wait to see how slowly my code is going to draw that first screen!

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

CPColin posted:

I can't wait to see how slowly my code is going to draw that first screen!

it's pretty incredible that the cpu loop needs to run ~200k times per second in order to hit the target of 2mhz, which is insanely slow by modern standards. i've definitely never written a loop that hot. and yet i still need to clamp it.

anyhow, here's how things look in action:
https://imgur.com/a/oNQBA0G

it's smoother than it looks, i think it's chunky because the gif is only 15fps.

i havent done input yet, so this is just the demo loop, which i'm hoping is supposed to be random because things are not looking very deterministic atm. sometimes it will hit a bug (either an unimplemented op or an out of range access) and sometimes it will keep running.

also aliens look missing.

DONT THREAD ON ME fucked around with this message at 22:24 on Aug 22, 2018

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
hows the rust plugin for intellij doing these days?

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

CRIP EATIN BREAD posted:

hows the rust plugin for intellij doing these days?
I've spent a good deal of time with both rls+vscode and intellij+plugin and while I prefer vscode greatly as an editor, i have a much better experience overall with the intellij plugin. better completion (still a crapshoot) and it can fill out trait implementations which is a big deal for me.

rls continues to be really slow and rls+vscode basically destroys my laptop. honestly i'd probably be on rls+vscode if not for the slowness, because i do prefer the editor.

emacs also has some basic rls integration and it seems okay, but i'm in the middle of overhauling my emacs setup and haven't really invested in learning it yet.

the community is pretty audibly frustrated over rls mostly being not a good experience.

DONT THREAD ON ME fucked around with this message at 22:42 on Aug 22, 2018

Bloody
Mar 3, 2013

rls just crashes nonstop

Beamed
Nov 26, 2010

Then you have a responsibility that no man has ever faced. You have your fear which could become reality, and you have Godzilla, which is reality.


MALE SHOEGAZE posted:

I've spent a good deal of time with both rls+vscode and intellij+plugin and while I prefer vscode greatly as an editor, i have a much better experience overall with the intellij plugin. better completion (still a crapshoot) and it can fill out trait implementations which is a big deal for me.

rls continues to be really slow and rls+vscode basically destroys my laptop. honestly i'd probably be on rls+vscode if not for the slowness, because i do prefer the editor.

emacs also has some basic rls integration and it seems okay, but i'm in the middle of overhauling my emacs setup and haven't really invested in learning it yet.

the community is pretty audibly frustrated over rls mostly being not a good experience.


Bloody posted:

rls just crashes nonstop

this is my experience yep. RLS is..really, really, really not there yet, and it's frustrating they're pushing it to 1.0 for marketing.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
ever since I moved to various JetBrains platforms I have no desire to go back. I still use vim for everything C related, but otherwise it’s IDEA for pretty much everything. Most of my professional work these days is Java/Kotlin, but sometimes I need to touch other stuff.

last time I checked the rust plugin it had some showstopping issues, although I don’t remember what those were. I’m pretty positive it was pre-1.0, though.

Bloody
Mar 3, 2013

i casually checked out pycharm the other day with low expectations because i have had some negative historical interactions with various jetbrains tools but i was blown away at how good it was at everything

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

i am slowly trying to move as much of my development as i can into intellij

just rewrote a few tiny sample websphere apps into kotlin too

gonadic io
Feb 16, 2011

>>=

CRIP EATIN BREAD posted:

ever since I moved to various JetBrains platforms I have no desire to go back. I still use vim for everything C related, but otherwise it’s IDEA for pretty much everything. Most of my professional work these days is Java/Kotlin, but sometimes I need to touch other stuff.

last time I checked the rust plugin it had some showstopping issues, although I don’t remember what those were. I’m pretty positive it was pre-1.0, though.

it's good now

also they're pretty quick to respond to issues

vodkat
Jun 30, 2012



cannot legally be sold as vodka

MALE SHOEGAZE posted:

it's pretty incredible that the cpu loop needs to run ~200k times per second in order to hit the target of 2mhz, which is insanely slow by modern standards. i've definitely never written a loop that hot. and yet i still need to clamp it.

anyhow, here's how things look in action:
https://imgur.com/a/oNQBA0G


this is incredibly cool :cheers:

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
i think once it's done imna see about targeting wasm. that would honestly be cool.

CRIP EATIN BREAD posted:

ever since I moved to various JetBrains platforms I have no desire to go back. I still use vim for everything C related, but otherwise it’s IDEA for pretty much everything. Most of my professional work these days is Java/Kotlin, but sometimes I need to touch other stuff.

last time I checked the rust plugin it had some showstopping issues, although I don’t remember what those were. I’m pretty positive it was pre-1.0, though.

i'm good with intellij, i just don't love it. i think i could invest in learning it better but overall i just don't enjoy the editing experience.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

carry on then posted:

i am slowly trying to move as much of my development as i can into intellij

just rewrote a few tiny sample websphere apps into kotlin too

kotlin owns so much. the coroutines built into the compiler own a lot, too.

Spime Wrangler
Feb 23, 2003

Because we can.

as a terrible python programmer is kotlin a good option for a second not-javascript language?

I mostly want to see how I like strict typing and maybe work towards having another set of tools besides django for backend development

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Spime Wrangler posted:

as a terrible python programmer is kotlin a good option for a second not-javascript language?

I mostly want to see how I like strict typing and maybe work towards having another set of tools besides django for backend development

yeah i haven't worked with it but i think kotlin is a good choice for that use case. java proper or C# would probably also suit your needs. ideally we'd be able to recommend server side swift but i dont think adoption is there yet.

DONT THREAD ON ME fucked around with this message at 00:26 on Aug 23, 2018

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Spime Wrangler posted:

as a terrible python programmer is kotlin a good option for a second not-javascript language?

I mostly want to see how I like strict typing and maybe work towards having another set of tools besides django for backend development

learn java then if you like it give kotlin a go. there's nothing in kotlin that's a super killer feature imo it's just a generally nice and well polished language on the jvm.

redleader
Aug 18, 2005

Engage according to operational parameters

Spime Wrangler
Feb 23, 2003

Because we can.

Blinkz0rz posted:

learn java then if you like it give kotlin a go. there's nothing in kotlin that's a super killer feature imo it's just a generally nice and well polished language on the jvm.

sounds suspiciously like you’re telling me to eat my vegetables

gonadic io
Feb 16, 2011

>>=

Spime Wrangler posted:

sounds suspiciously like you’re telling me to eat my vegetables

Yeah I'm not sure I'd recommend java to somebody messing around and trying static types

gonadic io
Feb 16, 2011

>>=

gonadic io posted:

Yeah I'm not sure I'd recommend java to somebody messing around and trying static types

Hmm static types are incredibly verbose and inflexible and get in my way


Nope that's just java

Sapozhnik
Jan 2, 2005

Nap Ghost
:ssh: java 10 has local variable type inference

bob dobbs is dead
Oct 8, 2017

I love peeps
Nap Ghost
ime its still verbose w/ the type inference cuz you need to deal with the rest of javaworld

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Sapozhnik posted:

:ssh: java 10 has local variable type inference

so does kotlin

plus smart-casting

code:
fun foobar(something: Any) {
  if (something is String) {
    println(something.length)
  } else if (something is List<*>) {
    something.foreach { println(it) }
  }
}

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

no such thing :smug:

NihilCredo
Jun 6, 2011

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

MALE SHOEGAZE posted:

no such thing :smug:

works fine in starcraft 2 actually

Soricidus
Oct 21, 2010
freedom-hating statist shill

Sapozhnik posted:

:ssh: java 10 has local variable type inference

so does java 8, if you’re not allergic to lombok

Adbot
ADBOT LOVES YOU

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Soricidus posted:

so does java 8, if you’re not allergic to lombok

lombok is super bad.

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