• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=jA_cOp;25174273]I don't know Objective-C and your question is a bit strange, so I might be misinterpreting it. Anyway, yeah, that's absolutely possible (and common). Let's assume "object" is a pointer to a class instance with a method 'foo' taking no arguments, returning an integer. C++ [cpp] int var = object->foo(); [/cpp] C#, Java, D, C++ (object being a reference, not a pointer) [cpp] int var = object.foo(); [/cpp] To elaborate, the right side of a C-style assignment can be any expression yielding a value of a compatible type. These expression results are called "rvalues" (because in C-style assignments, they appear on the right). Examples of rvalues include literals, other variables, the result of arithmetic operations, the return value of a function or method call; almost anything is a valid rvalue (with some language-specific reservations). The opposite of an rvalue is an lvalue, in short, stuff that is assignable. This includes variables, a dereferenced pointer; stuff you can "write" to. All lvalues are valid rvalues, but not the other way around. C-style syntax is arguably quite intuitive so this stuff is not something most people need to know the specifics of, but it's useful in understanding the syntax in depth and understanding compile error messages.[/QUOTE] Thanks for clarifying that so well. [editline]02:08AM[/editline] [QUOTE=Chandler;25176437]Well you can't call methods in Objective-C without them being pointers :P But what you have above is absolutely fine. Though *technically*, it should read [cpp] NSInteger aVar = [object methodThatReturnsSomething]; [/cpp] And that is only because you will actually get compiler warnings about int not being the same size when compiling for multiple platforms.[/QUOTE] Hm... so using standard C datatypes is a bad idea? Can you just show me how to define the most common datatypes as the NS versions? Like floats, booleans, doubles, strings etc... [editline]02:09AM[/editline] Also, I get the feeling I'm going to be bombarding this thread with questions. Here's another: Does defining variables as objects (ie NSNumber) take up more memory? I would assume so, but I just want to double check.
[QUOTE=ProWaffle;25186321]Hm... so using standard C datatypes is a bad idea? Can you just show me how to define the most common datatypes as the NS versions? Like floats, booleans, doubles, strings etc... Does defining variables as objects (ie NSNumber) take up more memory? I would assume so, but I just want to double check.[/QUOTE] the NS types are just better more for platform portability, in the event you ever move to a different processor. The basic types are just NS{C data type in capitalized}. NSNumber *can* take up more memory as its apple's version of bignum, and can hold numbers larger than a 64-bit int. The only time I've never used an NSNumber is reading an integer from a plist, as NSInteger isn't capable of that. Also, you *are* able to use the C data types, but if you do, for the love of Knuth, please please please, use the ones defined in stdint.h. Also, there's no harm in posting questions, that's what this thread is for :)
[QUOTE=Chandler;25186869]the NS types are just better more for platform portability, in the event you ever move to a different processor. The basic types are just NS{C data type in capitalized}. NSNumber *can* take up more memory as its apple's version of bignum, and can hold numbers larger than a 64-bit int. The only time I've never used an NSNumber is reading an integer from a plist, as NSInteger isn't capable of that. Also, you *are* able to use the C data types, but if you do, for the love of Knuth, please please please, use the ones defined in stdint.h. Also, there's no harm in posting questions, that's what this thread is for :)[/QUOTE] So I should only use NSNumber when I need to put variables in an array or something else that needs to be treated as an object?
[QUOTE=ProWaffle;25189050]So I should only use NSNumber when I need to put variables in an array or something else that needs to be treated as an object?[/QUOTE] It's actually better if you're serializing an NS{C Type} to a Plist, or reading one in. Also, in the event that a method returns an NSNumber. It's mostly there for conversion purposes at this point.
How would I go about making a Chat Program using SFML ? (Because WinSock2 is just too hard for me) I made a basic Server to Client chat program using TCP Sockets but how would I make multiple users chat with each other on the server? Should I use UDP Sockets? I have no idea really.
[QUOTE=NotMeh;25198338]How would I go about making a Chat Program using SFML ? (Because WinSock2 is just too hard for me) I made a basic Server to Client chat program using TCP Sockets but how would I make multiple users chat with each other on the server? Should I use UDP Sockets? I have no idea really.[/QUOTE] Use TCP sockets and a I/O multiplexer, IIRC it's called SocketSelector in SFML.
[QUOTE=NotMeh;25198338]How would I go about making a Chat Program using SFML ? (Because WinSock2 is just too hard for me) I made a basic Server to Client chat program using TCP Sockets but how would I make multiple users chat with each other on the server? Should I use UDP Sockets? I have no idea really.[/QUOTE] I'm not an expert on networking, but UDP packets might not even arrive or they might arrive in the wrong order. For chat program this might not be so good.
[QUOTE=esalaka;25198397]Use TCP sockets and a I/O multiplexer, IIRC it's called SocketSelector in SFML.[/QUOTE] Yeah I already used a Selector to make my Client-to-Server chat program. But I don't really understand how to use it to get multiple clients to chat with each other.
[QUOTE=NotMeh;25198581] But I don't really understand how to use it to get multiple clients to chat with each other.[/QUOTE] Have the server listen for new clients as well as waiting for data from any existing clients. When a new client connects, broadcast his info to all the other clients as well as sending him the info for all the existing clients. When a client sends a chat message to the server, broadcast it to all other clients. If those parts were already obvious to you, then I'd love to hear which specific parts of the process you have trouble doing :smile: (edit: using TCP makes everything a lot easier. UDP is connection-less and provides no guarantees about sent packets, allowing you to fine-tune the workings of your protocol, which you don't need at all)
Whats the best (in your opinion) youtube series for:C++, SFML, Game Development?
[QUOTE=Richy19;25200987]Whats the best (in your opinion) youtube series for:C++, SFML, Game Development?[/QUOTE] Why do you want video tutorials on that?
I find them easier to take in than books and web pages
[QUOTE=jA_cOp;25198859]Have the server listen for new clients as well as waiting for data from any existing clients. When a new client connects, broadcast his info to all the other clients as well as sending him the info for all the existing clients. When a client sends a chat message to the server, broadcast it to all other clients. If those parts were already obvious to you, then I'd love to hear which specific parts of the process you have trouble doing :smile: (edit: using TCP makes everything a lot easier. UDP is connection-less and provides no guarantees about sent packets, allowing you to fine-tune the workings of your protocol, which you don't need at all)[/QUOTE] I honestly feel like a fucking idiot right now but I have absolutely no idea how to broadcast any info to other clients.
use the broadcast IP address [url]http://en.wikipedia.org/wiki/Broadcast_address[/url]
[QUOTE=NotMeh;25201432]I honestly feel like a fucking idiot right now but I have absolutely no idea how to broadcast any info to other clients.[/QUOTE] Sorry if it was confusing, I'm not talking about the network term (like IPv4 broadcasting); I just mean looping through all clients, forwarding the freshly received chat message to everyone else. In the client-server model, everything has to go through the server. [QUOTE=Richy19;25201485]use the broadcast IP address [url]http://en.wikipedia.org/wiki/Broadcast_address[/url][/QUOTE] That's exactly what I'm [B]not[/B] talking about for a myriad of reasons. For example: IP broadcasting is wasteful, much lower level than TCP and only works on the LAN level on modern networks. I know you're probably just trying to help, but if you don't know what you're talking about, you're only going to confuse him more.
I no it just clutter out the network but its the simplest way of doing it As for it only working in LANs that is true but i though that was what he was trying to achieve i didnt realize he was trying to make it work across the internet -edit- Could he not also store all of the IP adresses of connected clients into a list and just loop through it?
[QUOTE=Richy19;25201935]I no it just clutter out the network but its the simplest way of doing it As for it only working in LANs that is true but i though that was what he was trying to achieve i didnt realize he was trying to make it work across the internet[/QUOTE] Using the client-server model with TCP is a lot easier than using a datagram protocol (like UDP) with broadcast packets, and some routers don't even allow directed broadcasts by default. Global broadcasts are rarely allowed by modern routers. (If you didn't mean "simple" as in "easy": he's a beginner to sockets programming, he needs easy, not simple.) [QUOTE=Richy19;25201935] Could he not also store all of the IP adresses of connected clients into a list and just loop through it?[/QUOTE] He's using TCP sockets. IP addresses will do him no good, he already has socket descriptors. And if that's what you meant, that's exactly what I just suggested.
Forget it. All I've been doing for the past hour is staring at my screen trying to figure out where the fuck to even start. All of my motivation pretty much went down the drain. Seems like I really can't learn shit without someone literally spoonfeeding it to me.
Here is a class I use in my game engine. It maintains a single TCP connection, and bunches incoming data into packets. Each "packet" must be sent by the server prefixed by the packet size, so the class knows how much data to bung into 1 packet. You need some kind of loop which calls Tick() on the class instance, and then checks HasPacket(), IsOpen(), IsTimedOut() and all that jazz. It might take a bit of editing to compile since it uses stuff from my engine, but nothing significant (globals.h, util.h, UE_Print() are not required). [url]http://thomasfn.pastebin.com/pT7TnydQ[/url] - CNetClient.h [url]http://thomasfn.pastebin.com/a0TQQzf3[/url] - CNetClient.cpp I don't have any C++ server code though. Make sure to call Dispose on the packet once you've finished reading it, but you don't need to when sending it.
[QUOTE=NotMeh;25202663] Seems like I really can't learn shit without someone literally spoonfeeding it to me.[/QUOTE] I'll try my best to clear it up, I'm probably guilty of over-simplifying things. The easiest way (and a very good and common way) to do a simple chat application is to use the client-server model. Most serious chat protocols also use this model, except traffic is usually transparently distributed over several inter-connected servers. To do client-server, you want to work with connections, a solid choice is then TCP. Some applications implement their own connections on top of UDP (a connection-less protocol) to fine-tune performance, but this is unnecessarily complex for chat applications. The most common way to work with TCP in code is the Berkeley socket model, or just "sockets". WinSock2 and the SFML network module are examples of socket APIs. Technically there's no such thing as a client-client relationship with TCP: there's always a server socket and one or more connected client sockets. On the client-side of your chat application, you will have one socket connected to the server (unless you decide to support several servers at the same time etc). On the server-side, you will have one server socket and one socket for every connected client. The server socket's only responsibility is to "listen" for new clients; all client sockets are created from the server socket. To receive a new client, the server has to "accept" it. Accepting a new client yields you a new TCP socket which you can both write to and read from to communicate with the connected client. You'll want to store all these client sockets so you can read from/write to them later. On the client, stuff is simpler. You create a new socket and connect it to the server by providing it with the host-name of the server in some form or another. Once connected, you just read from it and write to it to talk to the server. At this point you need to decide on an application-level protocol or create your own. I assume you want to create your own since you didn't mention any protocol in specific (like IRC, MSN etc). A common approach for chat protocols is to send "messages"/"packets"/"commands" as a line of text in a specific format. A line-based protocol could go something like this: ("<<" meaning sent-to-server, ">>" meaning received-from-server, neither actually being part of the lines sent. Lines prefixed with // are not part of the conversation, but my comments) [code] //Connection has just been established, send our information <<INFO jA_cOp\r\n //Server tells us that our nick is ok >>OK\r\n //Server sends the list of online users >>USERS Bob NotMeh Joe\r\n //We say "Hi!" <<SEND Hi!\r\n //Some time later, NotMeh replies and the server forwards this to us <<SEND NotMeh Hello :)\r\n [/code] This is just an example, all details of the protocol is up to you. Remember that TCP connections are streams, so you don't send fixed-length "packets" (like the IP or UDP protocols). The use of the carriage-return and newline characters as the message separator is just another example, but it fits well with the idea of everything being text. TCP doesn't actually care what kind of data you send. The above conversation is from the clients perspective. The server would check if any clients were trying to connect, accept the client and start reading lines from it. Upon getting the INFO line, it would send the nick of the new guy to all the already connected clients, informing them of the new arrival. The server is also listening for new data on all the client sockets. Once the server gets a SEND line from a client, it sends it to all the other clients with the nick of the sender included. So there you have it, a run-through of how one could go about this. It doesn't include any specific code samples because I've never used the SFML network module myself, but you should be able to draw some lines by reading the relevant tutorials and documentation (I'd be able to help you with WinSock2, though). I realise that I could be misunderstanding a bit, maybe you actually wanted to know how to do all this in code. If so, I'll be able to answer specific questions about any part of the process.
Trying to parse a function like: "put \"dicks go here\" title" for my console, so far what I'm doing is splitting by spaces into a vector with boost. Which leaves me with a vector like: put, "dicks, go, here", title; Where I want it to be split more like this: put, dicks go here, title. Any idea how I'd go about doing this?
Anything to convert a SVN repo to a GIT repo?
[QUOTE=NorthernGate;25211834]Trying to parse a function like: "put \"dicks go here\" title" for my console, so far what I'm doing is splitting by spaces into a vector with boost. Which leaves me with a vector like: put, "dicks, go, here", title; Where I want it to be split more like this: put, dicks go here, title. Any idea how I'd go about doing this?[/QUOTE] [cpp]#include <vector> #include <string> #include <iostream> std::vector<std::string> tokenize(const std::string & str, const std::string & delim) { using namespace std; vector<string> tokens; size_t p0 = 0, p1 = string::npos; while(p0 != string::npos) { p1 = str.find_first_of(delim, p0); if(p1 != p0) { string token = str.substr(p0, p1 - p0); tokens.push_back(token); } p0 = str.find_first_not_of(delim, p1); } return tokens; } int main( int argc, char* argv[]) { std::string delim = " "; //std::string str = "arg1 arg2 arg3"; //std::string str = "arg1 arg2 arg3 \"arg4 sub_arg\""; std::string str = "arg1 arg2 arg3 \"arg4 sub_arg\" \"arg5 sub_arg sub_sub_arg\""; std::vector<std::string> tokens = tokenize( str, delim ); std::vector<std::string> finaltokens; for( int x=0;x<tokens.size();x++) { // Regular argument to add if( tokens[x].find("\"") == -1 ) finaltokens.push_back( tokens[x] ); else { // Save it as the first string std::string construct = tokens[x]; // Go to the next element x++; // Loop while we have elements while( x < tokens.size() ) { // Add it in construct += (" " + tokens[x]); if( tokens[x].find("\"") != -1 ) break; // We're done! // Next element x++; } // Erase the two quotes construct.erase( construct.find("\""), 1); construct.erase( construct.find("\""), 1); // Save this argument finaltokens.push_back( construct ); } } for( x=0;x<finaltokens.size();x++) { std::cout << finaltokens[x] << std::endl; } return 0; }[/cpp] Taken from [url=http://www.gamedev.net/community/forums/topic.asp?topic_id=320087]GameDev forums[/url].
I am in need of some help, I am attmepting to write a C++ program that will take 5 decimal numbers, turn them into binary, then store them in an external file, and then later open that file, take the binary and turn them back into a decimal number. I have a way to see what bits are what for each number, but I can't figure out how to add each bit in a way to produce binary. [CODE]int encypt(int n) { int bit128 = 0; int bit64 = 0; int bit32 = 0; int bit16 = 0; int bit8 = 0; int bit4 = 0; int bit2 = 0; int bit1 = 0; int encodedValue; if(n >= 128) { bit128 = 1; n -= 128; } if(n >= 64) { bit64 = 1; n -= 64; } if(n >= 32) { bit32 = 1; n -= 32; } if(n >= 16) { bit16 = 1; n -= 16; } if(n >= 8) { bit8 = 1; n -= 8; } if(n >= 4) { bit4 = 1; n -= 4; } if(n >= 2) { bit2 = 1; n -= 2; } if(n >= 1) { bit1 = 1; n -= 1; } encodedValue = (bit128) + (bit64) + (bit32) + (bit16) + (bit8) + (bit4) + (bit2) + (bit1); return encodedValue; }[/CODE]When I run this in debug to check what the return is, it doesnt make it into binary, it just adds the 1s and 0s together to get another decimal number. I am new to C++ programming if that explains anything. So how do I make it convert it all into binary?
So you want to save as a binary file? Look into file i/o. [editline]10:32PM[/editline] Oh, and use else ifs. That'll fix your problem, but it's still a string of ASCII 1s and 0s.
[QUOTE=Agent766;25214312]So you want to save as a binary file? Look into file i/o. [editline]10:32PM[/editline] Oh, and use else ifs. That'll fix your problem, but it's still a string of ASCII 1s and 0s.[/QUOTE] So replace all the ifs with else ifs? Also I was saving it as a .dat file. I didn't post all of my code, just the encypt function. Also, it is susposed to save it as 1s and 0s, because then my decypt function (once I finish it, havn't started yet as to test it I need a working encypt) will turn it back into a decimal.
[QUOTE=raBBish;25213666] Taken from [url=http://www.gamedev.net/community/forums/topic.asp?topic_id=320087]GameDev forums[/url].[/QUOTE] Hot damn, thanks a lot.
[QUOTE=high;25212314]Anything to convert a SVN repo to a GIT repo?[/QUOTE] Git has the conversion from SVN to git built in. git svn co <svn url> git remote add origin <git push url> git push origin master Something along those lines. Google git-svn though
[QUOTE=TBleader;25214360]So replace all the ifs with else ifs? Also I was saving it as a .dat file. I didn't post all of my code, just the encypt function. Also, it is susposed to save it as 1s and 0s, because then my decypt function (once I finish it, havn't started yet as to test it I need a working encypt) will turn it back into a decimal.[/QUOTE] dont replace them add an [code]else { bit ### = 0; }[/code] that way if the bit isnt a 1 its a 0 Also salve the encryptedValue as a string not a int
[QUOTE=TBleader;25214128]I am in need of some help, I am attmepting to write a C++ program that will take 5 decimal numbers, turn them into binary, then store them in an external file, and then later open that file, take the binary and turn them back into a decimal number. I have a way to see what bits are what for each number, but I can't figure out how to add each bit in a way to produce binary. [CODE]int encypt(int n) { int bit128 = 0; int bit64 = 0; int bit32 = 0; int bit16 = 0; int bit8 = 0; int bit4 = 0; int bit2 = 0; int bit1 = 0; int encodedValue; if(n >= 128) { bit128 = 1; n -= 128; } if(n >= 64) { bit64 = 1; n -= 64; } if(n >= 32) { bit32 = 1; n -= 32; } if(n >= 16) { bit16 = 1; n -= 16; } if(n >= 8) { bit8 = 1; n -= 8; } if(n >= 4) { bit4 = 1; n -= 4; } if(n >= 2) { bit2 = 1; n -= 2; } if(n >= 1) { bit1 = 1; n -= 1; } encodedValue = (bit128) + (bit64) + (bit32) + (bit16) + (bit8) + (bit4) + (bit2) + (bit1); return encodedValue; }[/CODE]When I run this in debug to check what the return is, it doesnt make it into binary, it just adds the 1s and 0s together to get another decimal number. I am new to C++ programming if that explains anything. So how do I make it convert it all into binary?[/QUOTE] [cpp]//minimum int might not be able to hold the number, long will though long encrypt(unsigned char n) { long binary = 0, i = 1e7l; for(uint8_t mask = 1 << 7; mask != 0; mask >>= 1, i /= 10) { if((n & mask) != 0) //mask out a single bit { binary += i; n &= ~mask; //remove the bit by using and on the inversed mask } } return binary; }[/cpp]
Sorry, you need to Log In to post a reply to this thread.