• What do you need help with? V. 3.0
    4,884 replies, posted
i'm looking to get into c# programming and eventually making games in XNA. i've scoured google all over but i can't find any good tutorials. i'm using visual c# 2010 if that helps.
-snip-
[QUOTE=Richy19;31072352]I have this book [URL]http://www.amazon.co.uk/Primer-Graphics-Development-Wordware-Library/dp/1556229119[/URL] its pretty awesome, and you might find it cheap on ebay. As for free resources then khan academy is probably your best place to look[/QUOTE] This was exactly the kind of thing I was looking for. Thanks!
So I am looking at c#'s TCP socks. Well I am interested to know if it is possible to only get data that is actually there instead of just filling a array full of null's (EG) [code]while(true) { data = new byte[1024]; recv = client.Receive(data); if (recv == 0) break; Console.WriteLine( Encoding.ASCII.GetString(data, 0, recv)); client.Send(data, recv, SocketFlags.None); }[/code] Is there a better way to do this? The reason Im asking this is because I want to make a basic minecraft tunnel and I want to send packets as a get them from the server. And vise versa
Rather stupid question but in C++ how do I set a minimum and maximum for rand()? I've tried googling but keep finding answers requiring the use of multiplication, and percentages which I don't understand at all.
[QUOTE=cdlink14;31091141]Rather stupid question but in C++ how do I set a minimum and maximum for rand()? I've tried googling but keep finding answers requiring the use of multiplication, and percentages which I don't understand at all.[/QUOTE] [cpp]rand() % (max - min + 1) + min;[/cpp]
[QUOTE=sim642;31091202][cpp]rand() % (max - min + 1) + min;[/cpp][/QUOTE] You should probably use your platform's random device or write your own PRNG, though. Mersenne Twister is pretty easy to implement, sometimes faster than rand() and usually has more entropy or "randomness". The modulo operation apparently might greatly reduce the entropy of the random number or something. You're not supposed to use it that way if you really need randomness. That aside, boost does provide you with much better PRNGs and I think some of them are included in the C++0x standard.
[QUOTE=sim642;31091202] rand() % (max - min + 1) + min;[/QUOTE] Thanks that works great. Also Garry created this function for me in the FP chat: [URL]http://pastebin.com/raw.php?i=rGicYuV6[/URL]
[QUOTE=cdlink14;31091672]Also Garry created this function for me in the FP chat: [URL]http://pastebin.com/raw.php?i=rGicYuV6[/URL][/QUOTE] it's a namespaceful of functions, actually
[QUOTE=esalaka;31091713]it's a namespaceful of functions, actually[/QUOTE] I'm not that far into my learning of C++ to know what namespaces are yet. I do however know what functions are from my (very limited) time using Visual Basic. But thanks anyway. :)
[QUOTE=esalaka;31091608]You should probably use your platform's random device or write your own PRNG, though. Mersenne Twister is pretty easy to implement, sometimes faster than rand() and usually has more entropy or "randomness". The modulo operation apparently might greatly reduce the entropy of the random number or something. You're not supposed to use it that way if you really need randomness. That aside, boost does provide you with much better PRNGs and I think some of them are included in the C++0x standard.[/QUOTE] The reason why the modulo operator is poor with RNGs is because it operates on the lowest-order bits. Not only is its period limited to the period of the lowest bits, i.e. its period is a maximum of 2^n where n is the amount of bits that are taken into account, but the lowest-order bits tend to be the least random when generated with standard RNGs. It'd be better to bit shift the input random number than to use the modulo, but even better would be hashing the entire input into the result range.
[QUOTE=cdlink14;31091754]I'm not that far into my learning of C++ to know what namespaces are yet. I do however know what functions are from my (very limited) time using Visual Basic. But thanks anyway. :)[/QUOTE] You're working with random numbers but you haven't learned what namespaces are?
[QUOTE=AgentBoomstick;31092288]You're working with random numbers but you haven't learned what namespaces are?[/QUOTE] That is correct, the only thing I know is that if you use standard things like "cout" you require to use namespace std else you have to type it as "std::cout". Although from what I've seen I'm guessing a namespace basically stores an array of functions.
[QUOTE=cdlink14;31092786]That is correct, the only thing I know is that if you use standard things like "cout" you require to use namespace std else you have to type it as "std::cout". Although from what I've seen I'm guessing a namespace basically stores an array of functions.[/QUOTE] You should probably get into the habit of doing std::cout and so on anyway, importing the entire std namespace into your project through "using namespace std;" is quite a bad idea; it clutters up the global namespace.
It's bad to put in in a header, since then it will indeed land everywhere, but you should be save doing it in an implementation-file or a function. Thinking of namespaces as arrays is wrong, because namespaces are not datatypes (like real arrays or ints or something). They will 'disappear' when you compile the code, just like classes will disappear. Namespaces help you in organizing the code, but won't actually contribute to the resulting code (other than different name mangling). Imagine you'd implement a vector-type and simply call it vector. Now you'd get into trouble when wanting to use the C++ STL vector, which is not a vector in the mathematical sense, but a dynamic array. Luckily everything in the STL resides in the std-namespace, so you can still differentiate (as you see, if you'd have put 'using namespace std;' in a header, you'd be in trouble again!). Usually you don't need to put your own stuff in a namespace. However, should you ever create a framework/library/whatever you want to use across multiple projects, it might be handy to put it in a namespace so you can try to avoid colliding with any names there.
[img]http://dl.dropbox.com/u/23989104/ilovec%2B%2Bv2.png[/img] Want to subtract the found iterator with begin to get a relative index.
[QUOTE=ThePuska;31091836]The reason why the modulo operator is poor with RNGs is because it operates on the lowest-order bits. Not only is its period limited to the period of the lowest bits, i.e. its period is a maximum of 2^n where n is the amount of bits that are taken into account, but the lowest-order bits tend to be the least random when generated with standard RNGs. It'd be better to bit shift the input random number than to use the modulo, but even better would be hashing the entire input into the result range.[/QUOTE] In games or applications that don't need to be very secure that period is big enough. When you have to deal with cryptography you won't use rand() or the likes from a standard library anyway (unless you are retarded). In some games (warcraft3 as an example) RNGs aren't even directly used to calculate proc chances or damage. Instead shuffling bags are used so the game can only be "unfair" towards a player to a certain degree. rand() / System.Random and all the like are good enough for everything in games (except network encryption). But one might consider to use one of the countless implementations of the MersenneTwister on the internet because of the possible speed benefits. Speed of the code and "getting it done" are your biggest concern when working on a game. Still I'd be interested in how you'd implement shifting the numbers in the correct range or hashing them into the result range. (especially the hashing) :)
[QUOTE=WeltEnSTurm;31093620][img]http://dl.dropbox.com/u/23989104/ilovec%2B%2Bv2.png[/img] Want to subtract the found iterator with begin to get a relative index.[/QUOTE] That cannot work, because the data might not be stored continuously. That should work with a std::vector, but it's probably not what you want. Could you not just use the iterator instead of the index? What do you need it for? [editline]13th July 2011[/editline] Also, use some spaces, they won't bite :S
#define znew ((z=36969*(z&65535)+(z>>16))<<16) #define wnew ((w=18000*(w&65535)+(w>>16))&65535) #define IUNI (znew+wnew) #define UNI (znew+wnew)*2.328306e-10 static unsigned long z=362436069, w=521288629; inline void setseed(unsigned long i1,unsigned long i2) { z=i1; w=i2; } Cant remember where i got this from now, but it works. Do variable=UNI*(max-min) + min
[QUOTE=ZeekyHBomb;31093721]That cannot work, because the data might not be stored continuously. That should work with a std::vector, but it's probably not what you want. Could you not just use the iterator instead of the index? What do you need it for? [/QUOTE] Texture indexes for vertices. They have different names and every time one is needed, I load or get it from the texture manager and map it to the name. When I draw the model I bind all of the textures it needs. Every vertex has its own texture index starting from 0 so it knows which texture from the bound ones should be used for a face, and that's what I need that for. [editline]13th July 2011[/editline] [QUOTE=ZeekyHBomb;31093721]Also, use some spaces, they won't bite :S[/QUOTE] I doubt anybody will need to read it except for when I need help :v: And I find it far more readable than the STL code.
[QUOTE=Felheart;31093707]In games or applications that don't need to be very secure that period is big enough. When you have to deal with cryptography you won't use rand() or the likes from a standard library anyway (unless you are retarded). In some games (warcraft3 as an example) RNGs aren't even directly used to calculate proc chances or damage. Instead shuffling bags are used so the game can only be "unfair" towards a player to a certain degree. rand() / System.Random and all the like are good enough for everything in games (except network encryption). But one might consider to use one of the countless implementations of the MersenneTwister on the internet because of the possible speed benefits. Speed of the code and "getting it done" are your biggest concern when working on a game. Still I'd be interested in how you'd implement shifting the numbers in the correct range or hashing them into the result range. :)[/QUOTE] Both depend on the output-number you want to have. iirc rand() returns 16 randomized bits, so you could shift by 10 and still get a range from [0..64]. [cpp]return (rand() >> 10) % num;[/cpp] Like Puska said, there's more randomness in the higher bits, so you just shift the lower bits out. For hashing you could use folding or something. Here 4 bits are folded: [cpp]int rnd = rand(); return (rnd >> 12) + (rnd >> 8) + (rnd >> 4) + rnd;[/cpp] Imagine rand() returned 0b1100011011110001 (=50929), what folding would do is just split it, so you have 0b1100, 0b0110, 0b1111 and 0b0001 and add them together (to 0b100010 (=34)).
What is the proper way to lerp a rotation value in radians? Right now i'm just lerping from the old value to the next one, which creates this bug. [media]http://www.youtube.com/watch?v=A1nbuhOHSLQ[/media]
[QUOTE=WeltEnSTurm;31093873]Texture indexes for vertices. They have different names and every time one is needed, I load or get it from the texture manager and map it to the name. When I draw the model I bind all of the textures it needs. Every vertex has its own texture index starting from 0 so it knows which texture from the bound ones should be used for a face, and that's what I need that for. [editline]13th July 2011[/editline] I doubt anybody will need to read it except for when I need help :v: And I find it far more readable than the STL code.[/QUOTE] Then just store the iterator with the vertices, they can perform the same function as the index. If you use another API that relies on the indices then you'll have to loop through the container yourself (or store the index along side the texture in a pair). I don't think there's a specification of the coding convention for the STL (apart from the naming of the public API of course). And it can't hurt to write easily readable code, since if you every want to work in a team you don't need to change your style, or if you are revisiting your code you can also make out its semantic more easily.
[QUOTE=Dj-J3;31094115]What is the proper way to lerp a rotation value in radians? Right now i'm just lerping from the old value to the next one, which creates this bug. [/QUOTE] if(a > pi) a -= 2pi; if(a < -pi) a += 2pi; (or something)
[QUOTE=Dj-J3;31094115]What is the proper way to lerp a rotation value in radians? Right now i'm just lerping from the old value to the next one, which creates this bug. [media]http://www.youtube.com/watch?v=A1nbuhOHSLQ[/media][/QUOTE] Check if the absolute of the difference is bigger than Pi, and if so lerp to nextValue+2Pi instead.
what does the [b]inline[/b] keyword do? I read it simply puts the function of a function straight into code, so efectivelly you arent making a call to a function, but if thats true why not make everything inline? language would be c++ if it matters
[QUOTE=Dj-J3;31094115]What is the proper way to lerp a rotation value in radians? Right now i'm just lerping from the old value to the next one, which creates this bug. [media]http://www.youtube.com/watch?v=A1nbuhOHSLQ[/media][/QUOTE] That flashlight light looks almost exactly like the one I made ...
[QUOTE=Richy19;31095079]what does the [B]inline[/B] keyword do? I read it simply puts the function of a function straight into code, so efectivelly you arent making a call to a function, but if thats true why not make everything inline? language would be c++ if it matters[/QUOTE] Because if you did that to every function (and the compiler didn't override your choice to do so), you'd fill up your executable with tons and tons of redundant code from massive functions and stuff. Basically your exe would be much, much larger than it would be without. You should only inline the smallest of functions really.
[QUOTE=AntonioR;31095089]That flashlight light looks almost exactly like the one I made ...[/QUOTE] That's because it is the same :v: I'm borrowing it until i start focusing on the visuals. [editline]13th July 2011[/editline] [QUOTE=ZeekyHBomb;31094222]Check if the absolute of the difference is bigger than Pi, and if so lerp to nextValue+2Pi instead.[/QUOTE] Oh, that was easy :v: Thanks
[QUOTE=Richy19;31095079]what does the [b]inline[/b] keyword do? I read it simply puts the function of a function straight into code, so efectivelly you arent making a call to a function, but if thats true why not make everything inline? language would be c++ if it matters[/QUOTE] [url]http://www.parashift.com/c++-faq-lite/inline-functions.html[/url] Also, it's just a hint, which means the compiler still can decide, though MSVC and gcc both supply a (non-standard) keyword to force inlining.
Sorry, you need to Log In to post a reply to this thread.