• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=reevezy67;42365646]Eclipse I guess.[/QUOTE] That was what I was going to go for, but I've edited my post.
C# is the easiest and the fastest for 2D games and has a lot of great frameworks like Monogame, SFML.NET, Unity etc. I suggest C# and SFML.NET. [editline]1st October 2013[/editline] You can find lots of resources in this thread. [url]http://facepunch.com/showthread.php?t=1305793[/url]
[QUOTE=reevezy67;42365646]Eclipse I guess.[/QUOTE] Noooo, IntelliJ!
Does anyone know of a quick way to parse integers from a string seperated by spaces into integers ie. parse the string "52 2 3" into an array of integers {52, 2, 3}? Currently I'm doing [code]integer[0] = atoi(in.substr(0, in.find_first_of(" ")).data()); in = in.substr(in.find_first_of(" ")+1, std::string::npos); integer[1] = atoi(in.substr(0, in.find_first_of(" ")).data()); in = in.substr(in.find_first_of(" ")+1, std::string::npos);[/code] But I really wish there was some function that made it simpler to parse.
[QUOTE=FPSMango;42367616]Does anyone know of a quick way to parse integers from a string seperated by spaces into integers ie. parse the string "52 2 3" into an array of integers {52, 2, 3}? Currently I'm doing [code]integer[0] = atoi(in.substr(0, in.find_first_of(" ")).data()); in = in.substr(in.find_first_of(" ")+1, std::string::npos); integer[1] = atoi(in.substr(0, in.find_first_of(" ")).data()); in = in.substr(in.find_first_of(" ")+1, std::string::npos);[/code] But I really wish there was some function that made it simpler to parse.[/QUOTE] I'm not sure what language that is (I think c++ but I've only ever used Java), but it should have a split method which you can use to split your String at every space and put the results in a String array. You can then loop through the array and parse them to an integer.
[QUOTE=mobrockers;42367674]I'm not sure what language that is (I think c++ but I've only ever used Java), but it should have a split method which you can use to split your String at every space and put the results in a String array. You can then loop through the array and parse them to an integer.[/QUOTE] The C++ standard librariy has no split-like function for (std::)strings. The closest would perhaps be strtok, which operates on c-strings though. Boost has boost::string_algo::split. You can also use istringstream: [code]std::istringstream inStream(in); for(int idx = 0; inStream; ++idx) { inStream >> integer[idx]; }[/code]
Hello! Does anyone here know how a 2-3 tree works?
[QUOTE=ZeekyHBomb;42368033]The C++ standard librariy has no split-like function for (std::)strings. The closest would perhaps be strtok, which operates on c-strings though. Boost has boost::string_algo::split. You can also use istringstream: [code]std::istringstream inStream(in); for(int idx = 0; inStream; ++idx) { inStream >> integer[idx]; }[/code][/QUOTE] Use istream_iterator! [cpp] #include <iterator> #include <iostream> #include <sstream> #include <vector> int main () { std::istringstream stream { std::string { "52 2 3" } }; std::vector<int> values { std::istream_iterator<int> { stream }, std::istream_iterator<int> { } }; for (auto x : values) { std::clog << x << std::endl; } } [/cpp] Output is [code] 52 2 3 [/code]
What's up dudes, I recently started my programming course and I have lots of curiosity about lots and lots of stuff, which is good, I think. I messed a little with LÖVE already, came up with a little thingy and all :v:. I have a question however, let's say I have a program running on C, and I want to take information from it, say a game of sorts, and I want another program (on whatever language, one that's more suited to it, I really have no idea) to grab how much life I have left and do whatever I want with it. What's the name of this process? Sorry if this is a really dumb question, since I know nothing but the basics. [editline]1st October 2013[/editline] I'm currently reading a lot about this, found some stuff etc. If you guys could send me some more stuff to read I'd be really glad!
So, I am having an issue parsing Source MDL files. Does anyone happen to know of a place I can go, or someone I can talk to, with regards to resolving my issue? Thanks.
[QUOTE=Fingers!!!;42374186]What's up dudes, I recently started my programming course and I have lots of curiosity about lots and lots of stuff, which is good, I think. I messed a little with LÖVE already, came up with a little thingy and all :v:. I have a question however, let's say I have a program running on C, and I want to take information from it, say a game of sorts, and I want another program (on whatever language, one that's more suited to it, I really have no idea) to grab how much life I have left and do whatever I want with it. What's the name of this process? Sorry if this is a really dumb question, since I know nothing but the basics. [editline]1st October 2013[/editline] I'm currently reading a lot about this, found some stuff etc. If you guys could send me some more stuff to read I'd be really glad![/QUOTE] This is called Inter-process communication, or IPC.
Any regex god can help me with this dark magic ? I am trying to match the 3 (or any other number of arbitrary lenght before the Files keyword in this string : [code] 226 Transfer OK Directory of / 20-9-2013 14:06:00 0 New Text Document - Copy (2).txt 20-9-2013 14:06:00 0 New Text Document - Copy.txt 20-9-2013 14:06:00 0 New Text Document.txt 0 Dirs 3 Files 0 Bytes [/code] Came up with this but it doesn't seem to work [code][0-9]+(?<=Files)[/code]
[code](\d+) Files[/code]?
[QUOTE=ZeekyHBomb;42377421][code](\d+) Files[/code]?[/QUOTE] Wooh thanks, this also matches the Files after it but I can easily strip that away
You can just get the first match group too. That'll just be the digits.
[QUOTE=quincy18;42377437]Wooh thanks, this also matches the Files after it but I can easily strip that away[/QUOTE] You might want to also include the tabs after "Files" in case you come across a file named "Files" [code](\d+) Files\t+[/code]
I'm really inexperienced in programming (especialy when it comes to graphics) and this is a program fillls the screen with randomly colored square grid. The question is why is this using 25% of the cpu (no more and no less than 25% which is strange) Here is the code EDIT: Simplified the code and it still uses 25% cpu [code] #include <SFML\Window.hpp> #include <SFML\Graphics.hpp> #include <vector> #include <cstdio> #include <ctime> #include <cstdlib> using namespace std; int main() { srand(time(0)); sf::RenderWindow mainWin(sf::VideoMode(640,480),"Test"); bool change; //Should the screen be redrawn ? //Prototype rectangle sf::RectangleShape recta; recta.setSize(sf::Vector2f(64,48)); //Vector of these rectangles vector<sf::RectangleShape> kvadai; //Set the position and a random color for every rectangle and then push it to the vector for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { recta.setFillColor(sf::Color(rand() % 256,rand() % 256,rand() % 256)); recta.setPosition(x*64.0,y*48.0); kvadai.push_back(recta); } } //Draw them to the buffer for (int i = 0; i < kvadai.size(); i++) { mainWin.draw(kvadai[i]); change = true; } //Handle events and drawing to screen while (mainWin.isOpen()) { sf::Event evt; while (mainWin.pollEvent(evt)) { //Closing event if (evt.type == sf::Event::Closed) mainWin.close(); } if (change) { mainWin.display(); change = false; } } return 0; }[/code]
Alright, so basically I've been working on a fun little office match off of our programming skills, it's using this neat little 'game' called RoboCode, it allows for Java,C#,and VB implementations to be used to program the robots. It's quite fun. I've however encountered an issue with it, you can always access your own robots X and Y coordinates, however, the only thing you can get from an enemy is the bearing, heading, rotation of your radar whilst looking at them, distance from you, and that's it. I've tried getting the X,Y taking the sine of the X and cosine of the Y and multiplying each by the distance, failed to work. Tried using bearing and heading but to no avail because bearing is a term I barely grasp. Any practical ways of doing this? I need to get the degrees needed to turn my gun towards the other robot, in degrees, and the gun can turn either left or right The API for it is here: [url]http://robocode.sourceforge.net/docs/robocode.dotnet/Index.html[/url] And I'm using C# because of a lack of knowledge of Java
Heading is the direction the robot is facing, bearing is the angle of the robot relative to you. As such, you should simply be able to do something like turnGun(enemyBearing - gunHeading). [QUOTE=demoTron;42382130]I'm really inexperienced in programming (especialy when it comes to graphics) and this is a program fillls the screen with randomly colored square grid. The question is why is this using 25% of the cpu (no more and no less than 25% which is strange) Here is the code EDIT: Simplified the code and it still uses 25% cpu [code]//code-snip[/code][/QUOTE] If you have a quad-core, then it's taking 100% of a single CPU core. You probably don't have vsync enabled, which means it'll render as fast as it can. Anyway, it's nothing to worry about.
[url]https://github.com/thekarangoel/Projects/blob/master/README-scratch.md[/url]
A while back I was trying to have custom memory stats in C++ [code] #include <cstddef> #include <new> #include <iostream> unsigned long long MemoryUse::TotalBytesUsed = 0; unsigned long long MemoryUse::AssetsBytesUsed = 0; unsigned long long MemoryUse::GraphicsBytesUsed = 0; unsigned long long MemoryUse::NormalBytesUsed = 0; unsigned long long MemoryUse::UnknownBytesUsed = 0; static int magicNumber = 5551234; struct MemoryChunk { int myCreation; std::size_t size; MemoryType type; }; //Overrides the new operator and adds the size of the variable to bytesUsed void *operator new ( const std::size_t size, MemoryType type ) { //create memory for the new object and the information header void *const p = std::malloc( sizeof( MemoryChunk ) + size ); if( !p ) { throw std::bad_alloc(); } //add the amount of memory to use to the bytesUsed MemoryUse::TotalBytesUsed += size; switch ( type ) { case Normal: MemoryUse::NormalBytesUsed += size; break; case Graphics: MemoryUse::GraphicsBytesUsed += size; break; case Assets: MemoryUse::AssetsBytesUsed += size; break; case Unknown: default: MemoryUse::UnknownBytesUsed += size; break; } //populate the header MemoryChunk *mc = ( MemoryChunk * )p; mc->myCreation = magicNumber; mc->size = size; mc->type = type; //return the location + the size of the header to not overwrite the header return mc + 1; } void *operator new[] ( const std::size_t size, MemoryType type ) { return operator new( size, type ); } void *operator new ( const std::size_t size ) { return operator new( size, MemoryType::Unknown ); } void *operator new[] ( const std::size_t size ) { return operator new( size, MemoryType::Unknown ); } void operator delete ( void *p ) { if( !p ) { return; } MemoryChunk *mc = ( MemoryChunk * )p - 1; if( mc->myCreation == magicNumber ) { MemoryUse::TotalBytesUsed -= mc->size; switch ( mc->type ) { case Normal: MemoryUse::NormalBytesUsed -= mc->size; break; case Graphics: MemoryUse::GraphicsBytesUsed -= mc->size; break; case Assets: MemoryUse::AssetsBytesUsed -= mc->size; break; case Unknown: default: MemoryUse::UnknownBytesUsed -= mc->size; break; } std::free( mc ); } else { //doesnt seem to have been created by me so just free it std::free( p ); } p = NULL; } void operator delete[] ( void *const p ) { delete( p ); } [/code] In VS2010 it compiles and works fine, but I just tried compiling in linux with GCC 4.6 and got the following: [code] In file included from ../src/DebugOperators.cpp:3:0: /usr/include/c++/4.6/new:93:54: error: declaration of 'void* operator new(std::size_t) throw (std::bad_alloc)' has a different exception specifier ../src/./DebugOperators.hpp:22:7: error: from previous declaration 'void* operator new(std::size_t)' /usr/include/c++/4.6/new:94:56: error: declaration of 'void* operator new [](std::size_t) throw (std::bad_alloc)' has a different exception specifier ../src/./DebugOperators.hpp:24:7: error: from previous declaration 'void* operator new [](std::size_t)' /usr/include/c++/4.6/new:95:35: error: declaration of 'void operator delete(void*) throw ()' has a different exception specifier ../src/./DebugOperators.hpp:27:6: error: from previous declaration 'void operator delete(void*)' /usr/include/c++/4.6/new:96:37: error: declaration of 'void operator delete [](void*) throw ()' has a different exception specifier ../src/./DebugOperators.hpp:28:6: error: from previous declaration 'void operator delete [](void*)' ../src/DebugOperators.cpp: In function 'void* operator new(std::size_t, MemoryType)': ../src/DebugOperators.cpp:25:21: error: 'malloc' is not a member of 'std' ../src/DebugOperators.cpp: In function 'void* operator new(std::size_t)': ../src/DebugOperators.cpp:69:32: error: 'MemoryType' is not a class or namespace ../src/DebugOperators.cpp: In function 'void* operator new [](std::size_t)': ../src/DebugOperators.cpp:74:32: error: 'MemoryType' is not a class or namespace ../src/DebugOperators.cpp: In function 'void operator delete(void*)': ../src/DebugOperators.cpp:107:9: error: 'free' is not a member of 'std' ../src/DebugOperators.cpp:111:9: error: 'free' is not a member of 'std' ../src/DebugOperators.cpp: In function 'void operator delete [](void*)': ../src/DebugOperators.cpp:119:15: warning: deleting 'void* const' is undefined [enabled by default] [/code]
In lua you can do the following [code] functions = [function() return 1 end, function() return 2 end] [/code] Does python have something like that? Currently i'm doing this and it's kind of annoying to define a function for everything [code] def func1(): return 1 def func2(): return 2 functions = [func1, func2] [/code]
[QUOTE=Goz3rr;42395211]In lua you can do the following [code] functions = [function() return 1 end, function() return 2 end] [/code] Does python have something like that? Currently i'm doing this and it's kind of annoying to define a function for everything [code] def func1(): return 1 def func2(): return 2 functions = [func1, func2] [/code][/QUOTE] For simple statements, you can use a lambda. [i]BUT[/i] you can only have a single expression as the return. (there is also no return statement used) Per your example: [code] functions = [lambda: 1, lambda: 2] [/code]
[QUOTE=Chandler;42395323]For simple statements, you can use a lambda. [i]BUT[/i] you can only have a single expression as the return. (there is also no return statement used) Per your example: [code] functions = [lambda: 1, lambda: 2] [/code][/QUOTE] Any way to have multiple expressions/lines?
[QUOTE=Richy19;42394994][code] In file included from ../src/DebugOperators.cpp:3:0: /usr/include/c++/4.6/new:93:54: error: declaration of 'void* operator new(std::size_t) throw (std::bad_alloc)' has a different exception specifier ../src/./DebugOperators.hpp:22:7: error: from previous declaration 'void* operator new(std::size_t)' /usr/include/c++/4.6/new:94:56: error: declaration of 'void* operator new [](std::size_t) throw (std::bad_alloc)' has a different exception specifier ../src/./DebugOperators.hpp:24:7: error: from previous declaration 'void* operator new [](std::size_t)' /usr/include/c++/4.6/new:95:35: error: declaration of 'void operator delete(void*) throw ()' has a different exception specifier ../src/./DebugOperators.hpp:27:6: error: from previous declaration 'void operator delete(void*)' /usr/include/c++/4.6/new:96:37: error: declaration of 'void operator delete [](void*) throw ()' has a different exception specifier ../src/./DebugOperators.hpp:28:6: error: from previous declaration 'void operator delete [](void*)' ../src/DebugOperators.cpp: In function 'void* operator new(std::size_t, MemoryType)': ../src/DebugOperators.cpp:25:21: error: 'malloc' is not a member of 'std' ../src/DebugOperators.cpp: In function 'void* operator new(std::size_t)': ../src/DebugOperators.cpp:69:32: error: 'MemoryType' is not a class or namespace ../src/DebugOperators.cpp: In function 'void* operator new [](std::size_t)': ../src/DebugOperators.cpp:74:32: error: 'MemoryType' is not a class or namespace ../src/DebugOperators.cpp: In function 'void operator delete(void*)': ../src/DebugOperators.cpp:107:9: error: 'free' is not a member of 'std' ../src/DebugOperators.cpp:111:9: error: 'free' is not a member of 'std' ../src/DebugOperators.cpp: In function 'void operator delete [](void*)': ../src/DebugOperators.cpp:119:15: warning: deleting 'void* const' is undefined [enabled by default] [/code][/QUOTE] Just specify the shown exception specifier to get rid of the declaration with different exception specifier error. In C++11 you might need to use noexcept instead of throw() for delete. malloc and free are in the cstdlib header. And MemoryType is simply not defined, like stated in the error. You probably forgot to include some header there. You can get rid of the warning via reinterpret_cast to char *const. It seems deleting a void* is undefined behavior by the standard, and note that delete( stuff ) is still using the operator delete() and not a function-call. [editline]3rd October 2013[/editline] [QUOTE=Goz3rr;42395496]Any way to have multiple expressions/lines?[/QUOTE] In a lambda? Nope.
[QUOTE=ZeekyHBomb;42395645]Just specify the shown exception specifier to get rid of the declaration with different exception specifier error. In C++11 you might need to use noexcept instead of throw() for delete.[/QUOTE] I tried having [code] void *operator new ( const std::size_t size, MemoryType type ) throw(std::bad_alloc) { ... } [/code] but that didnt seem to do anything, would this need to be on the header as well? [QUOTE] malloc and free are in the cstdlib header. And MemoryType is simply not defined, like stated in the error. You probably forgot to include some header there. [/QUOTE] It seems that because MemoryType is a enum it wants the raw value not MemoryType::XYZ [QUOTE] You can get rid of the warning via reinterpret_cast to char *const. It seems deleting a void* is undefined behavior by the standard, and note that delete( stuff ) is still using the operator delete() and not a function-call. [/QUOTE] Not sure what you mean by this?
[QUOTE=Richy19;42396076]I tried having [code] void *operator new ( const std::size_t size, MemoryType type ) throw(std::bad_alloc) { ... } [/code] but that didnt seem to do anything, would this need to be on the header as well?[/QUOTE] Yes [QUOTE]It seems that because MemoryType is a enum it wants the raw value not MemoryType::XYZ[/QUOTE] Ah, so it is defined somewhere. Yes, else the error would be different. I'm guessing it's not an enum class? You need to write just XYZ then, not MemoryType::XYZ. [QUOTE]Not sure what you mean by this?[/QUOTE] [code]../src/DebugOperators.cpp:119:15: warning: deleting 'void* const' is undefined [enabled by default][/code]
[QUOTE=demoTron;42382130]The question is why is this using 25% of the cpu (no more and no less than 25% which is strange)[/QUOTE] You must sleep the CPU during a loop to keep it from taking all available processing power. Generally this is done by limiting the framerate via sleeps. Since you're using SFML however, you can just a call to [url=http://sfml-dev.org/documentation/2.0/classsf_1_1Window.php#af4322d315baf93405bf0d5087ad5e784]sf::Window::setFramerateLimit()[/url].
[QUOTE=ZeekyHBomb;42396325]Yes Ah, so it is defined somewhere. Yes, else the error would be different. I'm guessing it's not an enum class? You need to write just XYZ then, not MemoryType::XYZ. [code]../src/DebugOperators.cpp:119:15: warning: deleting 'void* const' is undefined [enabled by default][/code][/QUOTE] I mean would it just become: [code] void operator delete[] ( void *const p ) { delete( reinterpret_cast<char *const>(p) ); } [/code]
[QUOTE=Noi;42393754]Guys, is there some set of tasks of things to code? I really need some practice on some languages.[/QUOTE] [URL="https://www.hackerrank.com/"]https://www.hackerrank.com/[/URL] has lots of algorithm problems, not so many app ideas though.
Sorry, you need to Log In to post a reply to this thread.