• What Do You Need Help With? V6
    7,544 replies, posted
So visual studio is giving me this [img]https://pbs.twimg.com/media/B4M7imOIIAE1Jq8.png:large[/img] I haven't made static classes or functions before in c++ and it's going completly off its rocker because of my inexperience. [code]#ifndef CONTENTMANAGER_H #define CONTENTMANAGER_H #include "SFML\Graphics.hpp" #include <map> #include <sstream> using namespace sf; using namespace std; static class CONTENTMANAGER { public: static Texture getTexture(string textureName) { if(textureMap.find(textureName) == textureMap.end()) { Texture texture; stringstream ss; ss<<"Texture"<<textureName<<".png"; texture.loadFromFile(ss.str()); textureMap.emplace(textureName, texture); return textureMap[textureName]; } else { return textureMap[textureName]; } } private: static map<string,Texture> textureMap; }; #endif[/code]
[QUOTE=Fatfatfatty;46655212]So visual studio is giving me this [img]https://pbs.twimg.com/media/B4M7imOIIAE1Jq8.png:large[/img] I haven't made static classes or functions before in c++ and it's going completly off its rocker because of my inexperience. [code]#ifndef CONTENTMANAGER_H #define CONTENTMANAGER_H #include "SFML\Graphics.hpp" #include <map> #include <sstream> using namespace sf; using namespace std; static class CONTENTMANAGER { public: static Texture getTexture(string textureName) { if(textureMap.find(textureName) == textureMap.end()) { Texture texture; stringstream ss; ss<<"Texture"<<textureName<<".png"; texture.loadFromFile(ss.str()); textureMap.emplace(textureName, texture); return textureMap[textureName]; } else { return textureMap[textureName]; } } private: static map<string,Texture> textureMap; }; #endif[/code][/QUOTE] I see your problem Your indents aren't wide enough. [code] #ifndef CONTENTMANAGER_H #define CONTENTMANAGER_H #include "SFML\Graphics.hpp" #include <map> #include <sstream> using namespace sf; using namespace std; static class CONTENTMANAGER { public: static Texture getTexture(string textureName) { if(textureMap.find(textureName) == textureMap.end()) { Texture texture; stringstream ss; ss<<"Texture"<<textureName<<".png"; texture.loadFromFile(ss.str()); textureMap.emplace(textureName, texture); return textureMap[textureName]; } else { return textureMap[textureName]; } } private: static map<string,Texture> textureMap; }; #endif [/code] There you go [editline]6th December 2014[/editline] for real though, is [url=http://www.cplusplus.com/reference/map/map/]this[/url] the map you're referring to with "static map<string, Texture> texturemap" ? [editline]6th December 2014[/editline] [url]http://stackoverflow.com/questions/3585069/weird-linker-error-with-static-stdmap[/url] have you seen this?
Thanks, that worked.
[QUOTE=Fatfatfatty;46655212]So visual studio is giving me this [img]https://pbs.twimg.com/media/B4M7imOIIAE1Jq8.png:large[/img] I haven't made static classes or functions before in c++ and it's going completly off its rocker because of my inexperience. [code]#ifndef CONTENTMANAGER_H #define CONTENTMANAGER_H #include "SFML\Graphics.hpp" #include <map> #include <sstream> using namespace sf; using namespace std; static class CONTENTMANAGER { public: static Texture getTexture(string textureName) { if(textureMap.find(textureName) == textureMap.end()) { Texture texture; stringstream ss; ss<<"Texture"<<textureName<<".png"; texture.loadFromFile(ss.str()); textureMap.emplace(textureName, texture); return textureMap[textureName]; } else { return textureMap[textureName]; } } private: static map<string,Texture> textureMap; }; #endif[/code][/QUOTE] You need to define static variables somewhere. Do this in your .cpp [code]map<string,Texture> CONTENTMANAGER::textureMap;[/code] [editline]6th December 2014[/editline] Oh ok, a bit late.
... Why are you using a static class in C++? They don't even exist outside of Managed C++. That textureMap might is basically a global.
[QUOTE=Tommyx50;46644840]You could perform the transformation afterwards. If you maximum "grid" negative position is -8, then just add 8 to every transformed grid position before you actually place it into the 2d array. [/QUOTE]Can you explain this more?
I have so many times in the past made attempts att getting the directory which contains the executable files. The problem is that the function that does it uses some LPWSTR thing instead of a string or char array, it's really giving me a headache. Could I get some help with this?
LPWSTR is wstr_t* You could use wcstombs() to get char*
This code crashes for me because I have no idea what this function is supposed to do at all and I am doing my damn hardest to try an understand, but the more I look the more confused i get. [code]LPWSTR buffer = 0; GetCurrentDirectory(sizeof(buffer), buffer); char bufferchar[MAX_PATH]; //wcstombs(bufferchar, buffer, sizeof(bufferchar)); wcstombs_s(0, bufferchar, MAX_PATH, buffer, MAX_PATH); filePath = bufferchar; [/code] Please just tell me how I do this so i might learn a thing or two about it. Had to comment out wcstombs because it complained about it being insecure and refused to compile. All code examples I find online gives me compiler errors too, so i am really feeling down in my luck getting this to work.
[QUOTE=NixNax123;46655737]Can you explain this more?[/QUOTE] Well if we assume that you are splitting your world into 16 * 16 grid squares, then the largest negative grid position must be -8 (as half are to the left and top of the origin, and the other half are to the bottom and down). This means that when you do your calculation of checking what grid square you are in, all you need to do is add 8 - so -8 becomes 0, 0 becomes 8, and 8 becomes 16. It's just moving it all along so nothing is negative.
So I have this piece of code, setting dt in a game loop: [code] // set delta time float currentTime = clock.getElapsedTime().asSeconds(); float dt = currentTime - lastTime; // ... lastTime = currentTime;[/code] However, when the game is paused, the clock still runs. So as the game is paused, dt becomes large. How would I avoid this? [editline]6th December 2014[/editline] [QUOTE=Tommyx50;46656318]Well if we assume that you are splitting your world into 16 * 16 grid squares, then the largest negative grid position must be -8 (as half are to the left and top of the origin, and the other half are to the bottom and down). This means that when you do your calculation of checking what grid square you are in, all you need to do is add 8 - so -8 becomes 0, 0 becomes 8, and 8 becomes 16. It's just moving it all along so nothing is negative.[/QUOTE] This is my grid data: [code]cell size: 40.0 Rows: 24 Cols: 32[/code]
[QUOTE=NixNax123;46656484]So I have this piece of code, setting dt in a game loop: [code] // set delta time float currentTime = clock.getElapsedTime().asSeconds(); float dt = currentTime - lastTime; // ... lastTime = currentTime;[/code] However, when the game is paused, the clock still runs. So as the game is paused, dt becomes large. How would I avoid this? [/QUOTE] You can make a workaround by creating a new timer when pausing, and then substracting the time spent in pause from dt.
[QUOTE=NixNax123;46656484]So I have this piece of code, setting dt in a game loop: [code] // set delta time float currentTime = clock.getElapsedTime().asSeconds(); float dt = currentTime - lastTime; // ... lastTime = currentTime;[/code] However, when the game is paused, the clock still runs. So as the game is paused, dt becomes large. How would I avoid this? [editline]6th December 2014[/editline] This is my grid data: [code]cell size: 40.0 Rows: 24 Cols: 32[/code][/QUOTE] About dt: I don't understand. "dt" is simply the time between the current frame and the last - whether you pause the game or not shouldn't affect it. The game runs at 60fps whether paused or not. About your grid data - that simply means that after you calculate your grid cell size, you add 12 to the X position and 16 to the Y, if all is correct.
[QUOTE=Tommyx50;46656907] About your grid data - that simply means that after you calculate your grid cell size, you add 12 to the X position and 16 to the Y, if all is correct.[/QUOTE] I don't quite understand. I'm doing this based off your advice: [code] cols = (int)((gridBounds.x + gridCellSize - 1) / gridCellSize) + 12; rows = (int)((gridBounds.y + gridCellSize - 1) / gridCellSize) + 16;[/code] Is this correct? If so, what do I do next?
[QUOTE=NixNax123;46657077]I don't quite understand. I'm doing this based off your advice: [code] cols = (int)((gridBounds.x + gridCellSize - 1) / gridCellSize) + 12; rows = (int)((gridBounds.y + gridCellSize - 1) / gridCellSize) + 16;[/code] Is this correct? If so, what do I do next?[/QUOTE] I don't really understand what you are doing there. (gridBounds.y + gridCellSize - 1) Huh? At this point I'm beginning to think the optimization isn't worth it. In my projects, I only needed it when I had hundreds of items performing collision detection, and it looks as if your project doesn't go that high.
Alright! I'll scrap that and just focus on fixing the pause problem.
Winter break is approaching and I want to learn C++, I come from Java/Python/Ruby - I really love Ruby. What are good books/tutorials/videos/shaman magic/other resources I can use to learn C++?
[QUOTE=blacksam;46661858]Winter break is approaching and I want to learn C++, I come from Java/Python/Ruby - I really love Ruby. What is are good books/tutorials/videos/shaman magic/other resources I can use to learn C++?[/QUOTE] "The C++ Programming language" by Bjarne Stroustrup, the dude who invented the language. You can get 3rd edition if 4th is too expensive for you, but you should be aware of C++11 conventions early on
[QUOTE=proboardslol;46661932]"The C++ Programming language" by Bjarne Stroustrup, the dude who invented the language. You can get 3rd edition if 4th is too expensive for you, but you should be aware of C++11 conventions early on[/QUOTE] For my data structures class next semester we're using [URL="http://www.amazon.com/Structures-Algorithm-Analysis-Computer-Science/dp/048648582X/ref=sr_1_9?s=books&ie=UTF8&qid=1417984575&sr=1-9&keywords=data+structures+and+algorithms+in+c%2B%2B"]this[/URL]. I have been told we don't use C++11 in class. So it's safer to go with the third edition or can I buy the latest and gloss over the sections that contain C++11?
[QUOTE=blacksam;46661953]For my data structures class next semester we're using [URL="http://www.amazon.com/Structures-Algorithm-Analysis-Computer-Science/dp/048648582X/ref=sr_1_9?s=books&ie=UTF8&qid=1417984575&sr=1-9&keywords=data+structures+and+algorithms+in+c%2B%2B"]this[/URL]. I have been told we don't use C++11 in class. So it's safer to go with the third edition or can I buy the latest and gloss over the sections that contain C++11?[/QUOTE] The only difference between 3rd and 4th edition is C++11. I can't make any recommendations for your class, but I will tell you that.
[QUOTE=proboardslol;46661978]The only difference between 3rd and 4th edition is C++11. I can't make any recommendations for your class, but I will tell you that.[/QUOTE] Thank you!
So I am making a Player class which stores a players information like name, wins, contact info etc. My plan was every time I add a new Player they would be added to a list of Players. I am now realizing that each time I start the program, the Players I created before won't exist anymore. I am still pretty new and have never tried to work with this much data before. What is the best way for me to store and use it? Can I use my class I made and my list to transfer the data somewhere that will be persistent? I am using Visual Studio and C#.
[QUOTE=Jitterz;46664827]So I am making a Player class which stores a players information like name, wins, contact info etc. My plan was every time I add a new Player they would be added to a list of Players. I am now realizing that each time I start the program, the Players I created before won't exist anymore. I am still pretty new and have never tried to work with this much data before. What is the best way for me to store and use it? Can I use my class I made and my list to transfer the data somewhere that will be persistent? I am using Visual Studio and C#.[/QUOTE] Persistent data that exists between program executions generally involves secondary / disk storage. For C#, you probably want to look into the [url=http://msdn.microsoft.com/en-us/library/system.io.binarywriter(v=vs.110).aspx]BinaryWriter[/url] and [url=http://msdn.microsoft.com/en-us/library/system.io.binaryreader(v=vs.110).aspx]BinaryReader[/url] classes. Implementation specifics are obviously at your discretion, but the general idea is that whatever way you end up writing your classes out to file (a process known as [url=http://en.wikipedia.org/wiki/Serialization]serialization[/url], if you are interested), you will want to run in parallel when reading. So if you, say, write your list and players in a way such as: - Number of players in list -- Player 1 name -- Player 1 wins -- Player 2 name -- Player 2 wins Then you will want to read it in that same order, first reading the list size (which tells you how many players are coming), and then reading each player. With each player, you will create a Player class, then fill it with the fields you read, and add them to your list. That way you are creating new Player objects each time, but their details are persistent.
[QUOTE=Gmod4ever;46664912]Persistent data that exists between program executions generally involves secondary / disk storage. For C#, you probably want to look into the [url=http://msdn.microsoft.com/en-us/library/system.io.binarywriter(v=vs.110).aspx]BinaryWriter[/url] and [url=http://msdn.microsoft.com/en-us/library/system.io.binaryreader(v=vs.110).aspx]BinaryReader[/url] classes. Implementation specifics are obviously at your discretion, but the general idea is that whatever way you end up writing your classes out to file (a process known as [url=http://en.wikipedia.org/wiki/Serialization]serialization[/url], if you are interested), you will want to run in parallel when reading. So if you, say, write your list and players in a way such as: - Number of players in list -- Player 1 name -- Player 1 wins -- Player 2 name -- Player 2 wins Then you will want to read it in that same order, first reading the list size (which tells you how many players are coming), and then reading each player. With each player, you will create a Player class, then fill it with the fields you read, and add them to your list. That way you are creating new Player objects each time, but their details are persistent.[/QUOTE] So wait was I way off track trying to figure out how to use a Service-based Database?
I'm doing some complete beginner uni work and am having trouble with a bash script command. The idea is to create something like a recycle bin that files go to when the command is executed. I want to add in a check that makes sure the recycle bin folder actually exists and asks the user if he wants it created. [code] if [ -d ~/.waste ]; then mv $1 ~/.waste else echo "Waste bin does not exist, would you like it to be created? (y/n)" read yn if [ $yn == y ]; then mkdir ~/.waste mv $1 ~/.waste elif [$yn == n ]; then echo "Command aborted" else echo "Incorrect input" fi fi [/code] (excuse the shoddy formatting) It works perfectly except when the folder doesn't exist and the user inputs "n". For some reason it just screams at me and prints out "Incorrect input" instead of "Command aborted". Can anyone spot what the problem is?
[QUOTE=Stopper;46665134]I'm doing some complete beginner uni work and am having trouble with a bash script command. The idea is to create something like a recycle bin that files go to when the command is executed. I want to add in a check that makes sure the recycle bin folder actually exists and asks the user if he wants it created. [code] if [ -d ~/.waste ]; then mv $1 ~/.waste else echo "Waste bin does not exist, would you like it to be created? (y/n)" read yn if [ $yn == y ]; then mkdir ~/.waste mv $1 ~/.waste elif [$yn == n ]; then echo "Command aborted" else echo "Incorrect input" fi fi [/code] (excuse the shoddy formatting) It works perfectly except when the folder doesn't exist and the user inputs "n". For some reason it just screams at me and prints out "Incorrect input" instead of "Command aborted". Can anyone spot what the problem is?[/QUOTE] I'm not really knowledgeable about shell scripts, but why do the "if []" have a semicolon after them? In most other languages, that semicolon would result in the if being useless and all the code afterwards being run regardless.
snipple
In bash the semicolon separates statements (not sure if this is the right term for bash) so you can have multiple statements on the same line. In his code the semicolon isn't doing anything. This is a syntax error [code]if [ ... ] then ... fi[/code] The semicolon is needed to separate the if and the then [code]if [ ... ]; then ... fi[/code] Or they can be on 2 lines like in Stopper's code. It doesn't matter if there's a semicolon or not. [code]if [ ... ] then ... fi[/code]
I just found my error... The fucking square bracket wasn't separated by a space from the "elif", resulting in an error. I kinda hate bash for being stupid like that. And I swear to god, I looked over the code about a dozen times, because it looked too simple to [I]not[/I]&#8203; work. [editline]8th December 2014[/editline] To clarify, from my understanding of bash, Fredo is absolutely correct - the semicolon here does nothing. The reason I put it up is because I do my work in Notepad++ and then copy it into nano, which can sometimes kill the formatting. To avoid having to look for something small, stupid and hard to notice, I add the semicolon either way. Alas...
[QUOTE=Gmod4ever;46664912]Persistent data that exists between program executions generally involves secondary / disk storage. For C#, you probably want to look into the [url=http://msdn.microsoft.com/en-us/library/system.io.binarywriter(v=vs.110).aspx]BinaryWriter[/url] and [url=http://msdn.microsoft.com/en-us/library/system.io.binaryreader(v=vs.110).aspx]BinaryReader[/url] classes. Implementation specifics are obviously at your discretion, but the general idea is that whatever way you end up writing your classes out to file (a process known as [url=http://en.wikipedia.org/wiki/Serialization]serialization[/url], if you are interested), you will want to run in parallel when reading. So if you, say, write your list and players in a way such as: - Number of players in list -- Player 1 name -- Player 1 wins -- Player 2 name -- Player 2 wins Then you will want to read it in that same order, first reading the list size (which tells you how many players are coming), and then reading each player. With each player, you will create a Player class, then fill it with the fields you read, and add them to your list. That way you are creating new Player objects each time, but their details are persistent.[/QUOTE] Wanted to say thanks. This actually got me pointed in the right direction. The plan now is to still use a Dataset and then just write it to an xml file. I keep getting overwhelmed with the scope of data I am dealing with so if anyone has any experience with that I would love to hear any advice you might have.
Sorry, you need to Log In to post a reply to this thread.