Jump to content
  • Advertisement

CaspianB

Member
  • Content Count

    145
  • Joined

  • Last visited

Community Reputation

309 Neutral

About CaspianB

  • Rank
    Member
  1. CaspianB

    c++ class help

    There's a few problems with that code. First, you haven't fully defined CClass2 before using it in CClass1. Thus in the constructor where you call Class2.GetVar() you will get an error. Second, you really should read the link on organizing code files. Otherwise you're going to end up with other difficulties going down this route where your class and method definitions are stepping on each others toes. You should have a CClass1.h and a CClass2.h which do nothing more than this: class CClass1 { public: CClass1(const CClass2 &Class2); void SetVar(int val); int GetVar() const; private: int var; }; And then you should have a CClass1.cpp file which includes both CClass1.h and CClass2.h and actually defines the methods. You would use a forward declaration in one or both of your .h files as needed. #include "CClass1.h" #include "CClass2.h" CClass1::CClass1(const CClass2 &Class2) { this->SetVar(Class2.GetVar()); } void CClass1::SetVar(int val) { var=val; } int CClass1::GetVar() { return var; }
  2. Quote:Original post by Anddos no because if its a shutdown and reboot and then rejoin the stats wont be saved , its only if there was any unexpected closure , which is unfare to the player... It is impossible to determine if the player computer was turned off, the game client crashed, their network cord was unplugged, their ISP connection dropped, or a UFO attack destroyed the internet cables between the game server and the client. Impossible. Period. You. Can. Not. Do. It. All the game server can know is that the client connection was disconnected. So the solution to your problem is simple. In addition to saving the state when the user selects the option to log-off / disconnect from the server, you also save the state when the server detects that the connection has been dropped. Quote:Well you can't have multiplayer games if you can't trust the client for anything. Even the key presses could be faked! Might as well stop making games, someone will find a way to exploit them. Sure, key presses can be faked. But the user has the ability to press keys. Thus, you can trust the client for key presses. The point CodeMunkie was making is you don't trust the client for any information that should be determined by the server. You don't trust the client for where the player is located. You don't trust the client for if they hit or missed another player/monster. You don't trust the client for how much gold they have or what items they found. You trust the client for actions that the user directly chooses to take in the game. And the server then puts those actions into affect. You do trust the client for choosing to walk forward. Or choosing to fire their gun. Or choosing to cast fireball.
  3. CaspianB

    .bat or .cmd

    If I'm understanding you correctly, then at the end of your batch file add a "pause" command. Or, more properly, run the batch from from a command prompt rather than double clicking on it in windows.
  4. CaspianB

    multi-dimesion pointer array

    Wutz, now try creating a three dimensional array using your method where you prompt the user for the different dimensions then create an array based on those dimensions. You're not fulfilling the dynamic sized array that the original poster was asking for. [edit] Quote:CaspianB's example is close, but I don't think it's entirely correct. I tested it... You're right. I had the order of my indexes incorrect, and was getting seg-faults. I edited the above post and tried it and it seems to be working fine... Or, at least, no segfaults. :)
  5. CaspianB

    multi-dimesion pointer array

    Something like this is what you would need, I believe. It's untested so I may have a few asterisks out of place. Anyway, I would just use a vector of a vector of a vector of vectors or rethink what I'm doing that needs this weird 4-dimensional array. :p [edit]Order of array indexing was reversed, I believe. T ***array[4]; for (int i = 0; i < 4; i++) array = new T**[WIDTH]; for (int w = 0; w < WIDTH; w++) for (int i = 0; i < 4; i++) array[w] = new T*[LENGTH]; for (int l = 0; l < LENGTH; l++) for (int w = 0; w < WIDTH; w++) for (int i = 0; i < 4; i++) array[w][l] = new T[HEIGHT]; -- array[#][w][l][h]; To delete... for (int l = 0; l < LENGTH; l++) for (int w = 0; w < WIDTH; w++) for (int i = 0; i < 4; i++) delete [] array[w][l]; for (int w = 0; w < WIDTH; w++) for (int i = 0; i < 4; i++) delete [] array[w] for (int i = 0; i < 4; i++) delete [] array; [Edited by - CaspianB on April 20, 2010 12:15:54 PM]
  6. CaspianB

    Windows: Name of key codes

    I'm not sure if there's a way to do it for mouse buttons... I believe the oddities you are getting is due to the extended-key code bit which is bit 24 on the passed in scan code. If you look at the numpad, then "Num 8" Is the Up arrow. If you modify the scanCode value like this to set the bit you will get the correct name when passing in VK_PRIOR or VK_UP... scanCode |= 0x01000000; However, I do not think you always want that bit set. For example, if that bit is set and you pass in VK_RETURN you get "Num Enter" back instead of just "Enter" or if you pass in VK_F1 you get nothing back... So you'll probably need to add some code to check if it should be set or not. It looks like there might be an example of this here... http://www.ffuts.org/blog/mapvirtualkey-getkeynametext-and-a-story-of-how-to/
  7. CaspianB

    Windows: Name of key codes

    I can't recall if I've ever used this method, but a brief search on the MSDN brought up this: GetKeyNameText #include <iostream> #include <string> #include <windows.h> #include <windowsx.h> using namespace std; wstring getKeyText(unsigned int vKey) { WCHAR buf[256]; unsigned int scanCode = MapVirtualKey(vKey, 0) << 16; GetKeyNameText(scanCode, buf, 256); return wstring(buf); } int main() { wcout << getKeyText(VK_RETURN) << endl; } [Edited by - CaspianB on April 13, 2010 8:21:44 AM]
  8. CaspianB

    Prime Number Generator [C++]

    Quote:Couldn't really follow the code. To check if a number is prime (exhastitivly) first calculate its square root then check every number up to and including that, if it divides exactly then its not a prime. You don't need to check *every* number from two to its square root, either. Of course, if you really want a fast algorithm, this brute force algorithm isn't going to be it once you start getting into numbers larger than a 32-bit integer data type will handle. bool IsPrime(int primeCandidate) { if (primeCandidate < 2) return false; // less than 2 if (primeCandidate == 2) return true; // only even prime if (primeCandidate % 2 == 0) return false; // divisible by 2 int root = sqrt( (double) primeCandidate); for(int i = 3; i <= root; i += 2) { if(primeCandidate % i == 0) { return false; } } return true; } [Edited by - CaspianB on March 29, 2010 7:55:26 PM]
  9. CaspianB

    pointers usefulness

    Quote:Original post by Lode When I just started using C++, I remember I wanted to make an array of multiple polymorphic objects (something I had learned in a Java course at university), like std::vector<Vehicle>, and was confused by why it didn't work until I discovered that it was possible with pointers. That's why I wanted to give that example now... And IMHO, polymorphism is especially useful if you need a variable amount of objects. And then you need pointers, not an impossible array or container of references... Yeah, that's true, at least as far as I'm aware. I don't believe it's possible for a container to store references, which would be nice when coupled with the above points on polymorphism.
  10. CaspianB

    pointers usefulness

    Quote:Original post by Lode This isn't possible without pointers because when allocating the object on the stack, or making an std::vector of the type Car or Bike itself, they can only have that fixed type, making it impossible to mix multiple vehicle types together. I'm not sure if you weren't reading the rest of the thread, or what... But what you said is not correct. You do not have to use pointers with polymorphism. You can use references as well. For instance, using your examples... void numberOfWheels(Vehicle &vehicle) { std::cout << vehicle.getNumWheels() << std::endl; } Bike bike; Car car; numberOfWheels(car); // outputs 4 numberOfWheels(bike); // outputs 2 The reason when you should use pointers has been said repeatedly in this thread: "if the object must live outside the scope in which it is created."
  11. CaspianB

    pointers usefulness

    Ah crap, I saw pass by reference vs X and my mind read that as the typical question. You are correct, of course. :)
  12. CaspianB

    pointers usefulness

    Quote:Sounds simple... thanks a lot to you guys! And also, I believe that passing arguments by references instead of pointers is faster as well, or am I wrong? [edit] Misread as passing by reference vs *value* - not reference vs pointer, in which case there is not a large difference outside of semantics, as Zahlman says below. Depends on *what* you are passing. If you are passing an integer, then no - passing by reference is not any faster. If you are passing an object which holds a vector of thousands of other objects, then passing by reference will almost certainly be faster. The reason is simple: If you pass a reference, you are actually passing a *pointer* (a single value) to your object. If you pass the object itself, then you are going to generate a copy of that object which will involve copying the vector, meaning reallocation and everything else. So, the generalization of this is if you working with simple data, pass by value (unless you need to pass by reference for a specific reason). If working with objects, pass by reference. You can pass by const reference if you want to guarantee that the method will affect the object.
  13. CaspianB

    pointers usefulness

    Simple answer: you create objects using 'new' and (by extension) a pointer if you need the objects to exist outside of the scope in which they are created. You create objects on the stack (without using new) if you only need the object for the scope in which it is created. A bit longer answer might also involve references/pointers if you're using miscellaneous OOP concepts; specifically, polymorphism. But those scenarios will almost certainly still fall under the above simple answer as well.
  14. CaspianB

    [PHP] GameDev basic

    You should be able to find the answer to both of those questions on your webhost's website or by calling them and asking.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!