• What do you need help with? V. 3.0
    4,884 replies, posted
[C++ 2011] I need help with bitmasking. I want to find out if the user enter either a lowercase or an uppercase character. If it's lowercase it will convert it to uppercase an vice-versa. So far I can only do lowercase->uppercase. I can't seem to find a way to find when the user enters an uppercase letter: [code]#include <iostream> #include <conio.h> using namespace std; int convert_letter(char); int main() { char letter; cout << "Enter letter: "; cin >> letter; convert_letter(letter); _getch(); } int convert_letter(char letter) { //"if" condition would be here letter = letter | 0x20; cout << letter; return 0; }[/code]
Don't use getch. Don't. use cin.get(); Also, to do lower->uppercase, you shouldn't use bitmasking.
//Nevermind. The bitmask for uppercase is "0xDF" with AND. However, if I use cin.get() the program exits as soon as the results show. That's why I use getch.
[cpp]if(tolower(char) == char) char = toupper(char); else char = tolower(char);[/cpp] Oh wait, I'd actually prefer this: [cpp] char = (char == tolower(char) ? toupper(char) : tolower(char))[/cpp]
Why not use islower(char) ? toupper(char) : tolower(char)
To switch the case (on an printable ASCII character set), XOR by 0x20.
Was that an intentional design choice?
So i have this problem with my 3d rendering engine(using Direct3d). My terrain has texture splatting that uses a color map and blends according to it. My vision is to be able to change the splatting on the terrain during runtime, to have a 'living' terrain that can have grass grow like in From Dust. Since a long time ago i implemented this idea to have a shader pass per patch, as all the vertices of the terrain are stored inside separate patches(which are then stored in a quadtree). This idea seems to have been a very [B]BAD [/B]decision to implement, since my framerate is very low for the primitives that are being drawn. (according to PerfHUD, a model with half the primitives renders many times faster). Obviously i will revert back to having a single pass for the entire terrain, which will also mean a single shared vertex buffer (every patch has it's own vertex buffer at the moment). At the time i thought this was a good tradeoff, more shader control over my terrain in exchange for performance but this is a very bad bottleneck. So the question is: [I]How can i dynamically alter my splatting on my terrain?[/I] I sort of had this idea to maybe use the fvf to store information passed to the shader, but i will have to take a look.
[QUOTE=Jookia;31915039]Was that an intentional design choice?[/QUOTE] [quote=Wikipedia]Locating the lowercase letters in columns 6 and 7 caused the characters to differ in bit pattern from the upper case by a single bit, which simplified case-insensitive character matching and the construction of keyboards and printers.[/quote]
In linux is it possible to put the .so file with the executable like you do with windows .dll? Or is it necessary to install all the libraries?
[QUOTE=Richy19;31919638]In linux is it possible to put the .so file with the executable like you do with windows .dll? Or is it necessary to install all the libraries?[/QUOTE] It's better to install the libraries using a package manager. If not possible, that's a route.
[QUOTE=Jookia;31919692]It's better to install the libraries using a package manager. If not possible, that's a route.[/QUOTE] Fedora doesnt seem to have jsonCpp so I had to build it myself, but placing the .so wit the executable doesnt work, keeps saying it cant find it
[QUOTE=Richy19;31919638]In linux is it possible to put the .so file with the executable like you do with windows .dll? Or is it necessary to install all the libraries?[/QUOTE] The Linux dynamic linker will search these, in order: [del]- Executable (or execution? I don't remember) path[/del] or maybe not. - LD_LIBRARY_PATH environment variable - /etc/ld.so.conf contents (usually /usr/lib, /usr/local/lib...)
I am trying to code a kind of I/O system for entities. I have an std::map of function pointers: [cpp] std::map<std::string, InputFunc> Inputs; [/cpp] I also have two functions called 'Fire' and 'RegisterInput'. Fire is what will call the function in the std::map with the associated name. RegisterInput will take a function from derived classes and store it so that any entity can call ent->Fire("explode"). I have no idea if this is even possible but I thought it sounded pretty convenient if it could work, but I'm no expert on function pointers am I doing something wrong here? [cpp] typedef void (BaseEntity::*InputFunc)(BaseEntity* ent); //These are public functions in base entity void Fire(std::string &Name); void RegisterInput(std::string &Name, InputFunc Func(BaseEntity* ent)); [/cpp] [cpp] void BaseEntity::Fire(std::string &Name) { if (Inputs[Name] == NULL) { std::cout << "Invalid input '" << Name << "' invoked!\n"; return; } } void BaseEntity::RegisterInput(std::string &Name, InputFunc Func(BaseEntity* ent)) { Inputs[Name] = Func; std::cout << "Registered input: " << Name << "\n"; } [/cpp] I hoped to implement it like this: [cpp] Turret::Turret(sf::RenderWindow *App) : BaseEntity(App) { RegisterInput(std::string("shoot"), &FireShell); } void Turret::FireShell(BaseEntity* ent) { //Do stuff } [/cpp] I appreciate this is probably impossible because I am converting function pointers from void::Turret to viod::BaseEntity but I thought I might give it a shot. Would be nice to hear of any alternative systems.
[QUOTE=q3k;31919770]The Linux dynamic linker will search these, in order: - LD_LIBRARY_PATH environment variable - Executable (or execution? I don't remember) path - /etc/ld.so.conf contents (usually /usr/lib, /usr/local/lib...)[/QUOTE] It doesnt seem to be working with mine [code] [richy@fedoraLt linux-gcc Gnu C++]$ dir jsontestrunner libjson_linux-gcc\ Gnu\ C++_libmt.so test_lib_json [richy@fedoraLt linux-gcc Gnu C++]$ ./test_lib_json ./test_lib_json: error while loading shared libraries: libjson_linux-gcc Gnu C++_libmt.so: cannot open shared object file: No such file or directory[/code] Same happens with SFML
[QUOTE=Richy19;31920213]It doesnt seem to be working with mine [code] [richy@fedoraLt linux-gcc Gnu C++]$ dir jsontestrunner libjson_linux-gcc\ Gnu\ C++_libmt.so test_lib_json [richy@fedoraLt linux-gcc Gnu C++]$ ./test_lib_json ./test_lib_json: error while loading shared libraries: libjson_linux-gcc Gnu C++_libmt.so: cannot open shared object file: No such file or directory[/code] Same happens with SFML[/QUOTE] Hm, I think I might've been wrong. Try executing [code]LD_LIBRARY_PATH=`pwd` ./test_lib_json[/code]
[QUOTE=q3k;31920306]Hm, I think I might've been wrong. Try executing [code]LD_LIBRARY_PATH=`pwd` ./test_lib_json[/code][/QUOTE] [code] [richy@fedoraLt linux-gcc Gnu C++]$ LD_LIBRARY_PATH=`pwd` ./test_lib_json Testing ValueTest/size: OK Testing ValueTest/isObject: OK Testing ValueTest/isArray: OK Testing ValueTest/isBool: OK Testing ValueTest/isInt: OK Testing ValueTest/isUInt: OK Testing ValueTest/isDouble: OK Testing ValueTest/isString: OK Testing ValueTest/isNull: OK All 9 tests passed [/code] [editline]24th August 2011[/editline] [QUOTE=q3k;31920306]Hm, I think I might've been wrong. Try executing [code]LD_LIBRARY_PATH=`pwd` ./test_lib_json[/code][/QUOTE] Is there any setting in codeblocks so that it always runs that command when running a program?
[QUOTE=conman420;31919790]I am trying to code a kind of I/O system for entities.[/QUOTE] What you are trying to do will not work the way you have it setup. There are feasible ways to do it, though they may not look as pretty. Right off, this isn't correct:[cpp]void RegisterInput(std::string &Name, InputFunc Func(BaseEntity* ent));[/cpp]You don't need the (BaseEntity* ent) part at the end. Your typedef can work, but with one very annoying restriction (this isn't a very ideal way of doing it). Have a virtual version of "FireShell" inside the BaseEntity, have a pointer to that, and that will actually polymorphicly call the one inside turret. You'll have to do this for every input function you want, so only reason I'm mentioning it is because it is doable. The way I would do it, is setup my typedef like this:[cpp]typedef void (*InputFunc)(BaseEntity* ent);[/cpp](Notice no BaseEntity::) The restriction here is that all of your events will have to be static. This is actually a very ideal way of doing it. [cpp]class Turret : public BaseEntity { public: static void Turret::FireShell(BaseEntity* ent) { // do stuff with (Turret*)ent } Turret::Turret() { RegisterInput(std::string("shoot"), FireShell); } };[/cpp] I'm not sure what the baseentity pointer you were passing in before was for, but you could pass in the object you'd be calling it for and just do stuff with it. Since it's a member method of the class it'll still be able to access all the private members so it's basically a work-around for non-static methods. There's also lambdas to consider, but I would actually advice not to do that. They're not fully supported and learning function pointers is very good practice.
[QUOTE=Richy19;31920347][code] [richy@fedoraLt linux-gcc Gnu C++]$ LD_LIBRARY_PATH=`pwd` ./test_lib_json Testing ValueTest/size: OK Testing ValueTest/isObject: OK Testing ValueTest/isArray: OK Testing ValueTest/isBool: OK Testing ValueTest/isInt: OK Testing ValueTest/isUInt: OK Testing ValueTest/isDouble: OK Testing ValueTest/isString: OK Testing ValueTest/isNull: OK All 9 tests passed [/code] [editline]24th August 2011[/editline] Is there any setting in codeblocks so that it always runs that command when running a program?[/QUOTE] First off, it's up to the user and/or package maintainers to make sure the correct version of the library is available. You don't ship libraries with software in Linux. It doesn't make sense to do so because when a popular library releases ultra-important-security-bugfix you end up having to update it twelve times instead of once. If you're really afraid that people won't be able to satisfy the dependencies, try choosing a library that you [i]know[/i] is available. A quick search for Ubuntu yields "libjson" (don't know if it's any good, but there's a stable package available for it). I don't seem to be getting good results for Fedora, but that's no surprise as Fedora has always been pretty terrible at packaging useful things. Second, if you really absolutely must ship the binaries with your application (a few games and stuff do that, mostly bad ports of Windows titles) what usually happens is the whole mess gets dumped into a subfolder of /opt/ and you write a little shell script to launch the binary with whatever LD_LIBRARY_PATH you need.
[QUOTE=ROBO_DONUT;31923443]First off, it's up to the user and/or package maintainers to make sure the correct version of the library is available. You don't ship libraries with software in Linux. It doesn't make sense to do so because when a popular library releases ultra-important-security-bugfix you end up having to update it twelve times instead of once. If you're really afraid that people won't be able to satisfy the dependencies, try choosing a library that you [i]know[/i] is available. A quick search for Ubuntu yields "libjson" (don't know if it's any good, but there's a stable package available for it). I don't seem to be getting good results for Fedora, but that's no surprise as Fedora has always been pretty terrible at packaging useful things. Second, if you really absolutely must ship the binaries with your application (a few games and stuff do that, mostly bad ports of Windows titles) what usually happens is the whole mess gets dumped into a subfolder of /opt/ and you write a little shell script to launch the binary with whatever LD_LIBRARY_PATH you need.[/QUOTE] The problem is it isnt running on my computer not others
[QUOTE=Richy19;31923581]The problem is it isnt running on my computer not others[/QUOTE] In that case there's no reason you can't install the library to /usr/local/lib.
[QUOTE=ROBO_DONUT;31923685]In that case there's no reason you can't install the library to /usr/local/lib.[/QUOTE] The package management gods will slay you.
[QUOTE=Jookia;31923865]The package management gods will slay you.[/QUOTE] The package manager deals with things in the rest of the filesystem. /usr/local is for anything you don't want the package manager to touch.
Oh.
Is there any stable alternative to XNA for linux? SFML.Net wont work and II dont think MonoXNA is stable yet [editline]24th August 2011[/editline] It still wasnt working after installing it to usr/local but after chechink the ld.so.conf, it want even on the list.
How would one go about rotating a sprite in the direction a mouse is pointed in XNA.
[QUOTE=reevezy67;31927073]How would one go about rotating a sprite in the direction a mouse is pointed in XNA.[/QUOTE] Use atan2.
how do you integrate luaJIT in a project? Also id it worth using it just for variable storage?
I'm rendering terrain using a triangle list with a series of vertecies in XNA. I want to draw the triangles one way, but I have no idea how to do it. Here's an example of what I mean [img]http://i.imgur.com/s7jpE.png[/img] How would I achieve this?
Hello, I've been looking into simply 'terrain generation' using this fractal method I found here: [url]http://properundead.com/2009/03/cave-generator.html[/url] Look for this picture on the page: [img]http://properundead.com/images/map4.PNG[/img] It takes a 128x128 array and simplifies it to 8x8, and randomly assigns every block to be land or water, using a given percentage of land. Then it assumes it's a 16x16 array and further details every block in it given the other blocks around it. It repeats until it gets down to 128x128 resolution. I wanted to make a simple version of it using the c++ console. However, it isn't working. Currently it only tries the original randomization which doesn't work yet. Whenever I clear my boolean array, with the function I gave it, it doesn't print anything to the file. However, when I don't clear it beforehand, the values aren't random as they should be and some are high values, something I wouldn't find in a boolean array. [cpp] #include <cstdlib> #include <iostream> #include <string> #include <ctime> #include <fstream> using namespace std; //Use set_res before detailing or printing class Terrain { public: Terrain::Terrain(int size_total);//const. void array_print();//Sends to file void array_clear();//sets all to false void set_filename(string name);//decides output filename bool getrand_bool(int percent, bool type);//Returns true/fale a given Percent of the time void detail();//Details the array (this is the fractal part) void set(int x, int y, bool type); //Sets block to land/water int count(int x, int y);//Counts the true blocks next to and including the given one. void set_res(int res);//Sets the size_l and size_s void set_random(int percent);//randomly assigns land according to percentage private: bool array[128][128]; int size_t;//How big array is (128 for now) int size_l;//How many blocks per total array int size_s; //How big each local block is int x, y; string filename; ofstream myfile; }; int main() { Terrain map(128); map.array_clear(); map.set_filename("fileone.txt"); map.array_print(); map.set_filename("filetwo.txt"); map.set_random(75); map.array_print(); map.set_filename("filethree.txt"); map.set_random(50); map.array_print(); } Terrain::Terrain(int size_total) { size_t = size_total; set_res(8); x = 0; y = 0; filename = "Terrain_Generation.txt"; } //Sends to file void Terrain::array_print() { myfile.open(filename.c_str()); for(int yplace = 0; yplace <= (size_t - size_s) ; yplace += size_s) { for(int xplace = 0; xplace <= (size_t - size_s); xplace += size_s) { myfile << array[xplace][yplace] << " "; cout <<array[xplace][yplace] << " "; } myfile << endl; cout << endl; } myfile.close(); } void Terrain::array_clear() { for(int yplace = 0; yplace < size_t; y++) { for(int xplace = 0; xplace < size_t; x++) { array[x][y] = false; } } } void Terrain::set_filename(string name) { filename = name; } bool Terrain::getrand_bool(int percent, bool type) { if ( ((int)(rand() / (RAND_MAX + 1.0) * (100 - 1) + 1) ) <= percent ) return type; else return !type; } void Terrain::detail() { for(int yplace = 0; yplace <= (size_t - size_s); yplace += size_s) { for(int xplace = 0;xplace <= (size_t - size_s); xplace += size_s) { set(xplace, yplace, getrand_bool(count(xplace, yplace), 1) ); } } } //returns fraction around coords that are true int Terrain::count(int x, int y) { int xplace = x; int yplace = y; int truth = 0; int total = 0; if(x > 0) x -= size_s;//Ensures it stays in bound if(y > 0) y -= size_s;//same for(; y <= (yplace + size_s ) || y <= (size_t - size_s); y += size_s) { for(x = xplace; x <= (xplace + size_s ) || x <= (size_t - size_s); x += size_s)//Finds all ajoining blocks, counts them { total++; if(array[x][y]) truth++; } } return (truth/total); } void Terrain::set(int x, int y, bool type) { for(int yplace = size_s * y; yplace < (y + size_s); yplace++) { for(int xplace = size_s *x; xplace < (x + size_s); xplace++) { array[xplace][yplace] = type; } } } void Terrain::set_res(int res) { size_l = res; size_s = size_t/size_l; } //sets up initial array void Terrain::set_random(int percent) { for(int yplace = 0; yplace <= (size_t - size_s); yplace += (size_s)) { for(int xplace = 0; xplace <= (size_t - size_s); xplace += (size_s)) { set(xplace, yplace, getrand_bool(percent, 1) ); } } } [/cpp]
Sorry, you need to Log In to post a reply to this thread.