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
Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

feedmegin posted:

And floating point at that, if I recall.

Sort of? I'm a little fuzzy on that myself, but I think it will recognize if something is a pure integer or not and treat it as such.

Adbot
ADBOT LOVES YOU

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Skandranon posted:

Don't try doing some weird math to fit values into a 16bit number... you can't even HAVE 16bit numbers in JavaScript, ALL numbers are 64bits.
I know that, which is why I'm not doing it that way like I would in C or Pascal

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Skandranon posted:

Sort of? I'm a little fuzzy on that myself, but I think it will recognize if something is a pure integer or not and treat it as such.



Crockford doesn't really explain it, but there's a railroad diagram for just integers, whatever that means

csammis
Aug 26, 2003

Mental Institution
The diagram is just the grammar for how a number literal is parsed in Javascript. The part of the number literal to the left of the optional "fraction" and the optional "exponent" is named the "integer." That by itself doesn't imply anything about how it's treated internally.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

64bit floating point has plenty of bits to represent 16bit integers (or 32 for that matter) with absolutely no loss of precision.

https://en.wikipedia.org/wiki/Double-precision_floating-point_format
The mantissa is 52bits

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

peepsalot posted:

64bit floating point has plenty of bits to represent 16bit integers (or 32 for that matter) with absolutely no loss of precision.

https://en.wikipedia.org/wiki/Double-precision_floating-point_format
The mantissa is 52bits

I wasn't suggesting there would be an issue representing numbers in JS, just that fussing about saving memory like it was 1985 is silly because JS is going to use 64bits no matter what you do.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
As far as I know, every major JavaScript implementation in practice tries to store integer values directly without using the floating-point format. It's a lot more efficient to do computation on the integer format, in part just because integer operations are cheaper but also because you're doing integer operations anyway just to figure out what kind of value it is; FP units like doing long sequences of operations on values that are already in the FP register file, not receiving values from the integer register file, doing a single operation, and then sending the result back. If the integer operation overflows or something, then fine, you convert the result to an FP value; but you keep things as integers as much as you can.

As long as you're doing that anyway, you can potentially keep your basic value representation 32-bits by allocating FP values on your GC heap. That'll be really bad if the script actually does use FP values, but maybe it doesn't, or at least not enough to outweigh the benefits of the smaller value representation.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

ok i didn't really back track enough to see the original post

Bob Morales posted:

I'm making a little Arkanoid game in Javascript. I store the level in a 10x10 array of arrays like so

code:
  var bricks = [ 
  ['0','0','0','0','0','0','0','0','0','0'],
  ['0','0','0','0','0','0','0','0','0','0'],
  ['1','2','3','4','5','1','2','3','4','5'],
  ['2','3','4','5','1','2','3','4','5','1'],
  ['3','4','5','1','2','3','4','5','1','2'],
..
..
Now I've gotten to the point where I want to start adding some features like bricks being able to take multiple hits, and a power-up hiding behind the brick. I could simply create another array for power-ups, and another array for 'brick health' or something like that, but I'd like to keep it in one array and have it easily editable by hand.

If I were going to be making 150 levels or something I'd make a little level editor and store something like { color: 'blue', strength: '3', powerup: 'none' } in each array location.

But what I'm wondering is what would be a handy way to store 3 values in one variable? Years and years ago when I did this in Turbo Pascal I just used used a 16-bit value and used the first 4 bits for one value, the next 4 for the next... and then I just did the values like $082a, and that meant power up #8, brick takes 2 hits to break, and is sprite # 10

I thought about just using a 3 digit # like 1028. I can / by 100 to get the sprite #, / 10 to get the strength, and then what's left to get the power up #. I want something I can use a fixed length for so that the map array stays human-readable.

Any other suggestions?
Sounds like you want typed arrays. Then you can create a array of 8 or 16 bit values, and do bit masking and packing to your hearts content.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays

Suspicious Dish
Sep 24, 2011

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

rjmccall posted:

As far as I know, every major JavaScript implementation in practice tries to store integer values directly without using the floating-point format. It's a lot more efficient to do computation on the integer format, in part just because integer operations are cheaper but also because you're doing integer operations anyway just to figure out what kind of value it is; FP units like doing long sequences of operations on values that are already in the FP register file, not receiving values from the integer register file, doing a single operation, and then sending the result back. If the integer operation overflows or something, then fine, you convert the result to an FP value; but you keep things as integers as much as you can.

As long as you're doing that anyway, you can potentially keep your basic value representation 32-bits by allocating FP values on your GC heap. That'll be really bad if the script actually does use FP values, but maybe it doesn't, or at least not enough to outweigh the benefits of the smaller value representation.

Don't most engines use the classic NaN abuse trick described in Memo 396? You get a few bits extra to play around with in your NaN space and you can have it point to a 48-bit pointer for x86-64, or reference true/false/null/undefined/a 32-bit integer.

I WANNA BE A TWINK
Mar 27, 2016
What's a good IDE for OSX? Python and Swift.
Xcode?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Suspicious Dish posted:

Don't most engines use the classic NaN abuse trick described in Memo 396? You get a few bits extra to play around with in your NaN space and you can have it point to a 48-bit pointer for x86-64, or reference true/false/null/undefined/a 32-bit integer.

Right, this is the most common representation now, even on 32-bit platforms. There was a time, though, when WebKit wasn't yet willing to use a 64-bit representation, and so they did have to allocate numbers that didn't fit in their small-integer range, which must have been something like 30 bits. I think eventually they just decided that such numbers were common enough in real code to cancel most of the benefits of the smaller representation.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
lol, anything with colors (clearly not anything you want to do in a large, graphical program and ui toolkit) is gonna take up all 32 bits, yeah.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

I WANNA BE A TWINK posted:

What's a good IDE for OSX? Python and Swift.
Xcode?

Xcode for Swift, yes.
Python, your editor of choice.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I WANNA BE A TWINK posted:

What's a good IDE for OSX? Python and Swift.
Xcode?

If you want to use an IDE, the best (IMO) Python IDE is PyCharm. They have a free, but limited, Community edition.

KernelSlanders
May 27, 2013

Rogue operating systems on occasion spread lies and rumors about me.

I WANNA BE A TWINK posted:

What's a good IDE for OSX? Python and Swift.
Xcode?

Thermopyle posted:

If you want to use an IDE, the best (IMO) Python IDE is PyCharm. They have a free, but limited, Community edition.

Seconded

22 Eargesplitten
Oct 10, 2010



As far as object oriented style goes, if I'm creating an event queue, should I create an event queue class, and then create an instance of it to use in the class where I want to implement it? Or should I just put it in the class where it's implemented? I'm pretty sure I'll only need it in that one place, but I feel like it would be tidier to give the queue its own class.

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

22 Eargesplitten posted:

As far as object oriented style goes, if I'm creating an event queue, should I create an event queue class, and then create an instance of it to use in the class where I want to implement it? Or should I just put it in the class where it's implemented? I'm pretty sure I'll only need it in that one place, but I feel like it would be tidier to give the queue its own class.

It really depends on how complicated the logic surrounding the event queue itself is. If you just need a dumb FIFO queue then there's no need to dress it up with a class (beyond whatever your language of choice already provides for queues, anyway), but if you're going to need a lot of special behaviors relating specifically to the queue (and not to the class the queue is in) then it makes more sense to make it its own class.

UnfurledSails
Sep 1, 2011

Recently at an interview I was asked a question in the lines of "How many threads would you use in a thread pool to maximize performance in a program that uses 75% computation and 25% I/O? And why?" Even though in college I've taken some rudimentary concurrency classes and used thread pools in some assignments, I don't really have any idea how to answer this question. Google was not really helpful in this case as well. Can someone point me to a good reference I can read for this?

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
I have no idea how you'd go about answering that question "correctly", but my answer would be "I'd try different thread counts and see what their resource utilization is like." I strongly suspect that any numbers you come up with would be heavily reliant on the specifics of the hardware you're running on (not to mention your definition of "maximizing performance"). Maybe for bonus points I could take a stab at trying to have the program automatically figure out what its thread count should be by monitoring usage metrics on the machine at runtime.

Linear Zoetrope
Nov 28, 2011

A hero must cook
That's probably meant to be a secret Amdahl's Law question.

Amdahl's law says that the Speedup gained by using n threads is approximately:

code:
                                 1
Speedup_n = --------------------------------------------
                    (F_parallel/n) + F_sequential

Where F_parallel is the proportion of the program that's parallel, and F_sequential is the portion that's sequential. These two values always add up to 1.

This is a dimensionless scaling factor, meaning Speedup=1 is no speedup, Speedup=2 means 2x speedup etc.

I/O is likely meant to be the sequential component (since everything is going through the same pipe), so this looks like:

code:
                              1
Speedup_n = ---------------------------------------------
                        (.75/n) + .25

Obviously, the speedup gets better as n trends towards infinity, so "as many threads as the CPU can handle" would be an okay answer, but there's probably a "sweet spot" if you graph that, since above a certain number of threads you begin to get diminishing returns, and those superfluous threads could be used for something better. Though obviously mentioning things like cache and hardware issues, and how in practice measuring is probably best will likely get you bonus points.

Edit:

The max speedup is where n->infinity which is a 4x speedup in this case. And you get the following pattern:

2: 1.6x
4: 2.2x
8: 2.9x
16: 3.3x
32: 3.6x

Doubling gets less and less valuable, and it's honestly pretty paltry between 16 and 32 for the number of threads you have to add. Even between 8 and 16 threads you go from a ~0.7 delta in speedup to a ~0.4 delta. You could probably make an argument for any thread pool between 8 and 16, or even possibly between 4 and 8. As you double more and more, we know for a fact it's only going to asymptotically reach 4x, and that's at infinite threads, so going beyond 32 is probably going to start to see almost no improvement at all.

Linear Zoetrope fucked around with this message at 03:11 on Jun 1, 2016

The Laplace Demon
Jul 23, 2009

"Oh dear! Oh dear! Heisenberg is a douche!"

UnfurledSails posted:

Recently at an interview I was asked a question in the lines of "How many threads would you use in a thread pool to maximize performance in a program that uses 75% computation and 25% I/O? And why?" Even though in college I've taken some rudimentary concurrency classes and used thread pools in some assignments, I don't really have any idea how to answer this question. Google was not really helpful in this case as well. Can someone point me to a good reference I can read for this?

My first guess would be the number of logical cores in the machine divided by 0.75. In a perfect world, that'd be enough threads to have every core constantly saturated with work.

Realistically, more or less threads may perform better due to all sorts of factors I couldn't even begin to account for in an interview, such as the distribution of IO latencies or the cost of context switches. The only correct answer is to profile and benchmark throughput at each thread pool size.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
It's not a bad question if the idea is to get the candidate to explore and challenge the question a bit. It's pretty bad if they think it's got an unambiguous answer.

I think the most plausible reading that leads towards an unambiguous answer is that you're supposed to assume that the I/O is a solid block of work but that the computation can be potentially parallelized, and moreover potentially parallelized with the I/O. That's not necessarily a ridiculous scenario — if you're getting (say) a stream of data points that can each be processed independently, you should be able to get pretty close to that ideal. If that's the case, then the ideal answer is that you need three dedicated computation threads in order to make the overall task dominantly I/O-bound.

However, that still raises a lot of questions, like (1) whether the I/O itself can be parallelized, (2) whether the processing can really occur in parallel with the I/O, as opposed to needing to see most/all of the data before it can begin, or (on the other end) needing to completely finish before some of the I/O can occur, (3) whether the processing is really embarrassingly parallel or whether there's some interaction between data that will require more coordination / redundancy if done in parallel, (4) how much overhead is introduced by the parallelization and whether it can be compensated for by using additional threads, and (5) whether the OS and hardware actually support the desired level of concurrency.

The answer for how you should approach these questions in real life is that you should break down the workload into tasks and the dependencies between them so that you understand how much you have to gain and how much you're likely to have to spend to get it, and then (if you still think it's worthwhile) you rough out an idea for the right number of threads and then benchmark to see how much it's really helping.

Nude
Nov 16, 2014

I have no idea what I'm doing.
Any recommendations for what language to be used for server management? To be more specific I'm using Unity right now and PHP + MYSQL. But then I noticed the Unity documentation was using Perl. So I was just wondering if Perl is a nicer alternative to PHP or maybe there is another language I don't know about that's even better. If I end up with PHP should I go out of my way to install PHP onto my computer? And what's the proper way to version control this, would a private github server be alright?

Thanks for any help.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Nude posted:

Any recommendations for what language to be used for server management? To be more specific I'm using Unity right now and PHP + MYSQL. But then I noticed the Unity documentation was using Perl. So I was just wondering if Perl is a nicer alternative to PHP or maybe there is another language I don't know about that's even better. If I end up with PHP should I go out of my way to install PHP onto my computer? And what's the proper way to version control this, would a private github server be alright?

Thanks for any help.

what kind of management/tasks? How many servers?

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
There's approximately a million different options for running servers. Personally I would avoid PHP because I think the language is badly-designed (I mean, it's the language equivalent of that game you've been hacking on for four years and never rewritten from scratch), but if it works for you then it works so :shrug:

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
I'm not really an expert on what's best for that situation, but I can't imagine php being the right choice unless you already have a lot of experience with it. What language/framework is best for you depends on exactly what your needs are and what you are familiar with.

Running github on your own server seems like huge overkill for what I assume to be a personal project. Most repository hosting services (including github) allow you make your own private repositories on their servers for free (whereas github enterprise starts at $2500/year + the cost of hosting your own server).

In terms of version control for Unity, Unity 5 has a tool called UnityYAMLMerge. It allows you to resolve conflicts on scene and prefab files. You should integrate it into your git configuration.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
I need a simple dialog that pops up and lets the user confirm/edit a string. I am using C++ on windows using visual studio 2015. I am not using the crazy .net version of C++ that isn't really C++.

I have spent all day on this and I am at my wits end. Is there some incredibly basic tutorial somewhere? Nothing here is giving me a single clue:

https://www.google.com/search?q=windows+c%2B%2B+how+do+i+make+a+dialog

more info: I can easily create and edit a dialog using the resource view panel. However, the code that it creates doesn't even compile when I try to include it into my project. Maybe I need to start over so I can at least get those errors.

baby puzzle fucked around with this message at 21:14 on Jun 1, 2016

csammis
Aug 26, 2003

Mental Institution

baby puzzle posted:

I need a simple dialog that pops up and lets the user confirm/edit a string. I am using C++ on windows using visual studio 2015. I am not using the crazy .net version of C++ that isn't really C++.

I have spent all day on this and I am at my wits end. Is there some incredibly basic tutorial somewhere? Nothing here is giving me a single clue:

https://www.google.com/search?q=windows+c%2B%2B+how+do+i+make+a+dialog

This and this are the first non-MSDN links in that search result and they look pretty detailed to me. Can you go into detail about what you're having trouble with?

quote:

more info: I can easily create and edit a dialog using the resource view panel. However, the code that it creates doesn't even compile when I try to include it into my project. Maybe I need to start over so I can at least get those errors.

What are the compilation errors? How are you trying to include it in your project? What type of project did you create (was it previously a command-line program or something else)?

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
It is a windows app. I am creating a window using CreateWindow() and everything.


After adding the dialog and using the code wizard, the first thing that happens is I get this error:

#error Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]

If I change my project's "Use of MFC" setting from "Use Standard Windows Libraries" to "Use Standard Windows Libraries" then that goes away, but I am not sure if that is the right way to fix that.


Next, I get this error:

1>StringRequestDialogfff.cpp(14): error C2065: 'IDD_DIALOG1': undeclared identifier

In this code that was generated:

code:
StringRequestDialogfff::StringRequestDialogfff(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_DIALOG1, pParent)
{

}
I can add an include to the generated resource1.h file, but then I get:

1>c:\users\lem\documents\nitwit\src\../vs/StringRequestDialogfff.h(7): error C2504: 'CDialogEx': base class undefined

Among many other errors. It just seems like the generated code is just wrong.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Maybe I am supposed to fix up the generated code? If I try to include the header for CDialogEx, then I then get this:

#error WINDOWS.H already included. MFC apps must not #include <windows.h>

I have no idea where this is coming from. At this point, I feel like I've gone too far the wrong way.

nielsm
Jun 1, 2009



You should probably not be using MFC.

For what sounds like a very basic use case, a single dialog box that prompts for input and your code only continues after that, the classic DialogBox() function in Win32 may be the right tool. Sample on MSDN - you'd make a DIALOG type resource in your project resources, containing a text box, possibly a label, and two buttons for OK and Cancel, or perhaps even just OK. Make sure to give the text edit an appropriate control ID, and your primary button should probably be IDOK. (And use IDCANCEL for any cancel button.)
You then have a DialogProc signature callback function that handles WM_COMMAND, checks the ID for which button was pressed, and then gets the text from the edit box and stores that to a variable somewhere, then calls EndDialog().
Then your calling code can just call the DialogBox() function to show the box and wait for the user.

The MSDN example code is almost exactly what you need, it shows a dialog box from template, with two buttons and an edit box, and stores the edit box text in a variable when OK is pushed.

nielsm fucked around with this message at 22:04 on Jun 1, 2016

csammis
Aug 26, 2003

Mental Institution
I think you should post your code someplace where we can look at more of it. You mentioned that you're using "CreateWindow and everything" but you're also using the MFC Class Wizard...CreateWindow isn't used for MFC dialogs so I'm not sure how or where you'd be using CreateWindow. The tutorials you found in your Google search were all geared towards Win32 GUI programming and not MFC. The two share the same concepts but otherwise they're built fairly differently.

quote:

Among many other errors.

Post all of the compiler errors along with your code.

quote:

Maybe I am supposed to fix up the generated code?

The generated code should be able to build without modification

It sounds to me like what you're experiencing is a result of trying to add a UI into a VC++ project that wasn't started with that in mind. Visual Studio, particularly when using MFC, has a lot of project settings which the class generator assumes are set. Precompiled headers, the MFC DLL loading options you mentioned, etc. When you used the New Project wizard what did you pick?

edit:

nielsm posted:

You should probably not be using MFC.

Maybe, maybe not. If they're trying to add a little bit of UI to a console application then yeah, retrofitting MFC into a non-MFC app is not fun (as evidenced). However if they're just starting out with UI programming on Windows in vanilla C++ then I wouldn't wish straight Win32 GUI programming on anyone in TYOOL 2016. It's great to understand the full and complete mechanics of window management but if all you want is to get some input from your user then MFC or even Qt would be a far saner approach in my opinion.

csammis fucked around with this message at 22:07 on Jun 1, 2016

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line

baby puzzle posted:

I need a simple dialog that pops up and lets the user confirm/edit a string. I am using C++ on windows using visual studio 2015. I am not using the crazy .net version of C++ that isn't really C++.

The Tiny File Dialogs library might help you out. I ended up not using it in a project I was doing as it didn't really fit what I needed, but maybe you can use it.

Do you need to be using C++? If not you could use C# and WPF, though I'm finding the latter to be a bit of a headache.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Maybe I need to re-evaluate what I am doing. So far all of my UI is in HTML5 (via awesomium), and so the obvious solution is to make a dialog in HTML... but I actually thought it would be easier to just use the windows stuff. I guess I was wrong. I really do not know what is or is not MFC.

No Safe Word
Feb 26, 2005

baby puzzle posted:

Maybe I need to re-evaluate what I am doing.


baby puzzle posted:

I need a simple dialog that pops up and lets the user confirm/edit a string. I am using C++ on windows using visual studio 2015. I am not using the crazy .net version of C++ that isn't really C++

If this is referring to C# then just suck it up and use C#? Making a super simple native Windows app that does this is super easy with C#.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

No Safe Word posted:

If this is referring to C# then just suck it up and use C#? Making a super simple native Windows app that does this is super easy with C#.

There's a batshit dialect of C++ for dealing with managed code, I assume that's what was being referred to.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Yeah sorry the managed c++ is not what I'm using.

I already have a bunch of work in c++ and that's what I am most comfortable in so I'd like to stick with that, and I guess stick with HTML for UI.

I wonder what people like to use for GUIs with c++? The Windows poo poo all has the worst api that I have ever seen in my life. I looked at qt as well but I don't want to use a different ide after decades of VS.

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

baby puzzle posted:

I wonder what people like to use for GUIs with c++? The Windows poo poo all has the worst api that I have ever seen in my life. I looked at qt as well but I don't want to use a different ide after decades of VS.

What do you mean, different IDE? Just write code that produces your dialogs. It's not hard*. You don't have to use GUI designers to make GUIs, especially for something as simple as what you're talking about.

* Disclaimer: I haven't used Qt in years, and then only in Python, but still, the Python wrapper was pretty thin as I recall.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
It's likely possible to do qt in vs but there is a special build that has to be set up since qt requires some non-cpp stuff. This is where my patience runs out.

Adbot
ADBOT LOVES YOU

Gul Banana
Nov 28, 2003

c# exists because c++ is bad at GUIs
this is an actual property of the language and is why things like QT have their custom setups with signals and slots. it has complex memory management and does not have the right kind of dynamism for widget-based uis

win32 c++ is fine for a simple messagebox, but, we can't help you if you don't post your code

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