• What do you need help with? Version 5
5,752 replies, posted
I'd like some help on making a timer of some sort using Processing, if anyone knows what that is.
[QUOTE=lawlavex;37294337]I'd like some help on making a timer of some sort using Processing, if anyone knows what that is.[/QUOTE] Is this what you mean? [url]http://processing.org/reference/second_.html[/url]
[QUOTE=ECrownofFire;37294399]Is this what you mean? [url]http://processing.org/reference/second_.html[/url][/QUOTE] [url]http://processing.org/reference/millis_.html[/url] might be more useful. millis() returns the number of ms since the applet started, but second() returns the seconds count for the current minute.
I have a number that I need to select a random '1' bit from as quickly as possible. The naive solution of course is to iterate over each bit, add the '1' bits to an array or something and then pick a random one from there. But that is cumbersome and slow, and I'd like a better solution. I tried something like this: [cpp]int pickRandomBit(int n, int numBits) { int bitPos = rand() % numBits; unsigned int mask = ~((1 << bitPos) - 1); if(mask & n) n &= mask; return n - (n & (n - 1)); }[/cpp] But this heavily favours the lower significance bits. I need something that has a much more even probability of selecting each bit.
[QUOTE=Chris220;37302689]I have a number that I need to select a random '1' bit from as quickly as possible. The naive solution of course is to iterate over each bit, add the '1' bits to an array or something and then pick a random one from there. But that is cumbersome and slow, and I'd like a better solution. I tried something like this: [cpp]int pickRandomBit(int n, int numBits) { int bitPos = rand() % numBits; unsigned int mask = ~((1 << bitPos) - 1); if(mask & n) n &= mask; return n - (n & (n - 1)); }[/cpp] But this heavily favours the lower significance bits. I need something that has a much more even probability of selecting each bit.[/QUOTE] If the bits are evenly spaced [i]on average[/i], this gives an even probability [i]on average[/i]. [cpp]int pickRandomBit(unsigned int n, unsigned int numBits, unsigned int rnd) { int c; unsigned int bp = rnd % numBits; unsigned int mask = (1 << bp); unsigned int bit = 0; if (n == 0) return 0; /* Loop through the bits in a for-loop to make sure the compiler * unrolls it. We're breaking out of it anyway. */ for (c = 0; c < 8 * sizeof(unsigned int); c++) { bit = mask & n; /* If the current bit is not set, left rotate the mask bit. */ if (bit == 0) mask = (mask << 1) | (mask >> (numBits - 1)); else break; } return bit; }[/cpp] The naive solution is the best solution if you require absolute equality. Though I wouldn't store the bits; iterate through them once to count how many bits are set, pick a random number between 0 and the amount of set bits, and iterate again to find the random bit.
[QUOTE=ECrownofFire;37294399]Is this what you mean? [url]http://processing.org/reference/second_.html[/url][/QUOTE] I wanted to know if there was a way to make a timer that starts when a button is pressed, and a way to reset it when a different button is pressed.
Can someone please answer this? I really try not to be spammy, but this is the third time I've asked and I've gotten no responses. [quote]Alright, have you already built and placed GLFW in the correct folder (include and lib directories)?[/quote] What do you mean by built?
[QUOTE=Meatpuppet;37303209]Can someone please answer this? I really try not to be spammy, but this is the third time I've asked and I've gotten no responses. What do you mean by built?[/QUOTE] Not trying to be rude but you really shouldnt be using C/C++ if you dont even know what this is. One google search [url]http://www.glfw.org/release-2.7.4.html#compiling[/url]
[QUOTE=ThePuska;37303037]If the bits are evenly spaced [i]on average[/i], this gives an even probability [i]on average[/i]. [cpp]int pickRandomBit(unsigned int n, unsigned int numBits, unsigned int rnd) { int c; unsigned int bp = rnd % numBits; unsigned int mask = (1 << bp); unsigned int bit = 0; if (n == 0) return 0; /* Loop through the bits in a for-loop to make sure the compiler * unrolls it. We're breaking out of it anyway. */ for (c = 0; c < 8 * sizeof(unsigned int); c++) { bit = mask & n; /* If the current bit is not set, left rotate the mask bit. */ if (bit == 0) mask = (mask << 1) | (mask >> (numBits - 1)); else break; } return bit; }[/cpp] The naive solution is the best solution if you require absolute equality. Though I wouldn't store the bits; iterate through them once to count how many bits are set, pick a random number between 0 and the amount of set bits, and iterate again to find the random bit.[/QUOTE] Thank you for a brilliant answer. The bits in question are in a bitfield, and the values are more likely to be right next to each other that spaced out evenly. As for what you said about not storing the results, I didn't think of doing it how you said. Thanks again!
[QUOTE=Richy19;37303692]Not trying to be rude but you really shouldnt be using C/C++ if you dont even know what this is. One google search [url]http://www.glfw.org/release-2.7.4.html#compiling[/url][/QUOTE] I tried that already. It just says "'make' is not recognized as an internal or external command, operable program, or batch file."
[QUOTE=Meatpuppet;37307268]I tried that already. It just says "'make' is not recognized as an internal or external command, operable program, or batch file."[/QUOTE] Make is a Unix utility. If you expect to be able to use it on Windows you have to install some form of Unix-Windows port like cygwin or msys.
You don't need be discouraging. The reason I asked is because I wanted to [I]learn[/I]. How do you think one learns? By seeing a problem that he can't solve, and finding the solution. automerge
[QUOTE=Meatpuppet;37307311]You don't need be discouraging. The reason I asked is because I wanted to [I]learn[/I]. How do you think one learns? By seeing a problem that he can't solve, and finding the solution. automerge[/QUOTE] Google is an excellent tool for simple errors such as the one you posted. A general rule of internet etiquette is to search for existing solutions to the problem, and if you don't find any then make a post.
[QUOTE=calzoneman;37307369]Google is an excellent tool for simple errors such as the one you posted. A general rule of internet etiquette is to search for existing solutions to the problem, and if you don't find any then make a post.[/QUOTE] I didn't find it; that's why I made the post
[QUOTE=lawlavex;37303184]I wanted to know if there was a way to make a timer that starts when a button is pressed, and a way to reset it when a different button is pressed.[/QUOTE] I'd just use millis to get the start time, then use it again to compare the current time to it. The reset button would just move the start time to the current time again.
[QUOTE=Meatpuppet;37307702]I didn't find it; that's why I made the post[/QUOTE] Comes with mingw, its called mingw32-make.
[QUOTE=Neo Kabuto;37307867]I'd just use millis to get the start time, then use it again to compare the current time to it. The reset button would just move the start time to the current time again.[/QUOTE] Thanks, I ended up finding a nice object oriented timer that also used millis(). Another quick question, is Processing capable of doing things such as shutting down a computer?
[QUOTE=lawlavex;37308182]Another quick question, is Processing capable of doing things such as shutting down a computer?[/QUOTE] Well, this is a tricky question. Simple answer: yes, Processing is capable of doing [i]anything[/i]. Processing is really just a library for Java. Java can do technically do anything. But there is no nice, built-in, cross-platform way to shut down a computer with Java. You can either invoke the system executable responsible for shutting down (shutdown.exe on Windows, shutdown on Linux), or you can use trickier things like JNI to call the API function responsible for shutting down. But JNI would be really awkward to get working in a Processing environment (possible, but awkward). You could use something like this (taken from [URL="http://stackoverflow.com/questions/25637/shutting-down-a-computer-using-java"]this StackOverflow post[/URL]): [QUOTE]public static void shutdown() throws RuntimeException, IOException { String shutdownCommand; String operatingSystem = System.getProperty("os.name"); if ("Linux".equals(operatingSystem) || "Mac OS X".equals(operatingSystem)) { shutdownCommand = "shutdown -h now"; } else if ("Windows".equals(operatingSystem)) { shutdownCommand = "shutdown.exe -s -t 0"; } else { throw new RuntimeException("Unsupported operating system."); } Runtime.getRuntime().exec(shutdownCommand); System.exit(0); }[/QUOTE] But I'm not sure whether that code works directly in Processing or whether you have to explicitly import some libraries.
[QUOTE=Meatpuppet;37307702]I didn't find it; that's why I made the post[/QUOTE] Alright, here's a step by step. You SHOULD already have mingw-get in your MinGW installation's bin folder. If you don't, this won't work. 1. Open up CMD prompt. 2. Enter this without quotes: "mingw-get update" (Might as well update the lists while you're doing this) 3. Enter this without quotes: "mingw-get install msys" 4. Wait for it to download and install, then close the CMD prompt. 5. Go to your mingw installation directory, there should be a folder called "msys" in it. Inside of that is a folder with a version number (1.0 currently), and inside of THAT is "msys.bat". Open that up, and now you have a Unix-ish shell. There you go. Just CD over to your directory and "make" should do everything you need. After it finishes, you can "make install prefix=(mingw directory)" and it should get copied over. (Obviously, replace that (mingw directory) with your actual mingw directory location, excluding the parentheses.)
I'm following a 4 year Game Development course in the Netherlands where we get the freedom of choosing our own programming language. I've been going on and off with C++ and multiple libraries through this year. And while most programs developed were made in AS3, I've decided to continue with a language I personally find more useful in the industry. I've been contemplating C++ as my language of choice, however I was told that this was something that has never been done by anyone on the course before. Most of the students settle for AS3, seeing as that is the language that we have been taught in the first year, or C#. Do you think it is feasible for me to use C++ for my assignments, given that I have a limited timeframe for assignments, or should I try a more universally used language in this course seeing as that might be faster and wouldn't cause any problems when working in group projects. I have to add that I favor C++ over any language. It's become a language that I'm very comfortable with, and I have a tough time getting into different programming languages. I hope my post was at least a bit comprehensible. If it isn't, I will revise it later.
[QUOTE=Asgard;37313571]I'm following a 4 year Game Development course in the Netherlands where we get the freedom of choosing our own programming language. I've been going on and off with C++ and multiple libraries through this year. And while most programs developed were made in AS3, I've decided to continue with a language I personally find more useful in the industry. I've been contemplating C++ as my language of choice, however I was told that this was something that has never been done by anyone on the course before. Most of the students settle for AS3, seeing as that is the language that we have been taught in the first year, or C#. Do you think it is feasible for me to use C++ for my assignments, given that I have a limited timeframe for assignments, or should I try a more universally used language in this course seeing as that might be faster and wouldn't cause any problems when working in group projects. I have to add that I favor C++ over any language. It's become a language that I'm very comfortable with, and I have a tough time getting into different programming languages. I hope my post was at least a bit comprehensible. If it isn't, I will revise it later.[/QUOTE] If you're just trying to get the assignments done, choose a language you're comfortable with using that won't cause you headaches trying to figure out how something should be done. That being said, if you're trying to get useful experience out of the class I would go with C++ or C# since Flash seems to be on its way out (good riddance).
If you [B]can[/B] use C++ and you know you're able to do it, why not. Otherwise use something else. [editline]19th August 2012[/editline] And yeah, Flash is pretty much officially soon-to-be history since Adobe stopped supporting it on mobile devices, which seems to suggest they don't really want people to start using it more.
[QUOTE=Meatpuppet;37307702]I didn't find it; that's why I made the post[/QUOTE] Make sure you have MinGW\bin folder in your PATH variable
What's the best way to do platforming collision detection? I'm currently placing rectangles around my object and then checking the up/down/left/right collisions with them, but this is a piece of shit when the character is moving more than one pixel per frame.
Where do I place a file to be read by openFileInput on Android? I tried making a folder at the root of the package called maps, and tried to access the map.txt file using openFileInput("maps/map.txt) but it doesn't work. I realized that I can only open a file, not a file path using openFileInput. I have changed it and put the file map.txt into a folder named files in the root of the project. However, it still doesn't work.
[QUOTE=esalaka;37313721]Adobe stopped supporting it on mobile devices, which seems to suggest they don't really want people to start using it more.[/QUOTE] While they've stopped supporting it on mobile browsers, they still do update and encourage use of AIR on mobile platforms.
[QUOTE=Mr. Smartass;37315153]What's the best way to do platforming collision detection? I'm currently placing rectangles around my object and then checking the up/down/left/right collisions with them, but this is a piece of shit when the character is moving more than one pixel per frame.[/QUOTE] Use aabb penetration solving instead, it's much more exact and clean. You would still have to do some nice time stepping or some simple tracers to keep fast moving objects from flying through everything though.
[QUOTE=WTF Nuke;37315433]Where do I place a file to be read by openFileInput on Android? I tried making a folder at the root of the package called maps, and tried to access the map.txt file using openFileInput("maps/map.txt) but it doesn't work. I realized that I can only open a file, not a file path using openFileInput. I have changed it and put the file map.txt into a folder named files in the root of the project. However, it still doesn't work.[/QUOTE] openFileInput opens files stored in the private Application specific storage on the phone, it's not related to the files in your project at all. If you want to include a file with your project and read it later, put it in the [i]raw[/i] resource directory and use: [cpp]InputStream in = getResources().openRawResource(R.raw.filename);[/cpp]
How can I open a resource by using it's name? NVM Figured it out [url]http://www.anddev.org/tinytut_-_get_resources_by_name__getidentifier_-t460.html[/url]
[QUOTE=BMCHa;37315592]While they've stopped supporting it on mobile browsers, they still do update and encourage use of AIR on mobile platforms.[/QUOTE] Ah, dangit. I always consider Flash a purely web technology. Thanks for reminding.