lride

Members
  • Content count

    194
  • Joined

  • Last visited

Community Reputation

674 Good

About lride

  • Rank
    Member

Personal Information

  • Interests
    Programming
  1. struct BaseNetObj { std::vector<char> data; std::function<void()> func; }; struct NetPerson { void say() { std::cout << a << b << c << "\n"; } int a; int b; int c; }; template <typename T> BaseNetObj makeBase() { BaseNetObj obj; obj.data.resize(sizeof(T)); obj.func = std::bind(&T::say, (T*)obj.data.data()); return obj; } int main() { BaseNetObj obj0 = makeBase<NetPerson>(); BaseNetObj obj1 = makeBase<NetPerson>(); BaseNetObj obj2 = makeBase<NetPerson>(); NetPerson * p0 = (NetPerson*)obj0.data.data(); p0->a = p0->b = p0->c = 1; NetPerson * p1 = (NetPerson*)obj1.data.data(); p1->a = p1->b = p1->c = 1; obj0.func(); //111 obj1.func(); //111 for (int i = 0; i < obj0.data.size(); ++i) { obj2.data[i] = obj0.data[i] ^ obj1.data[i]; } obj2.func(); //000 } I think the above should do it. No inheritance, virtual functions. The base class holds the raw data in a vector. I can still do emulate polymorphism with std::function.
  2. This is the way how I do delta compression: All objects' information is represented in integers. I xor the two objects and I get lots of 0s. Then I do run length encoding. I think I can solve this problem by adding virtual void * data(), and virtual int size() methods.
  3. I want to be able to call a virtual function on the xor'd object. The reason is I'm trying to implement delta compression for compressing snapshots for a multiplayer game. I need to xor the contents of two objects and then call a virtual function to pack the bits.
  4. struct Base { virtual void func() = 0; }; struct A : Base { void func() { std::cout << "a: " << a << "\n"; } int a; }; int main() { A a; a.a = 1; A a2 = a; A a3; char * ap = reinterpret_cast<char*>(&a); char * ap2 = reinterpret_cast<char*>(&a2); char * ap3 = reinterpret_cast<char*>(&a3); for (int i = 0; i < sizeof(A); ++i) *(ap3 + i) = *(ap + i) ^ *(ap2 + i); Base * b = &a3; b->func(); } I want to bitwise xor the contents of an object with virtual functions like above. But I think i get a crash in above scenario because I xor'd the vptr too. Is there a way to achieve what I want?
  5. Server rewinding to account for player's ping spike is a terrible idea imo. If a player has unstable network condition, he/she should not expect a smooth gameplay.
  6. You could tick slightly slower. E.g. if you tick at 25hz, that's 40ms per tick. Increasing that to 41ms will slow you down by about 2.5%, which is probably not very noticeable to the player, but it will also not close the gap very fast (6.4s for 3 ticks at 25hz). There's a bit of a trade off to make between closing the gap faster and how noticeable the slowdown is to the player, this doesn't have to be a static value though, you can adjust the slowdown based on how large the gap is.   Thanks, this approach sounds good. 
  7. I'm making a 2d multiplayer platformer. I do client prediction for my own player and do interpolation for other players. I understand client always tries to stay ahead of server, so an input for tick T should arrive close to when server simulates T. For every input packet, server tells the client how far the input was off. If the input was too early, then the client needs to slow down. If the input was late, then the client needs to speed up. What i don't understand is how to slow down or speed up. For example, if server tells me it received my input for tick 10 at tick 7(3 ticks early), then I need to slow down 3 ticks worth of time. How should I go about doing this?
  8. Thanks, that works. But I don't understand why I don't get a warning with packer.pack<0, 127>(7u)?
  9. Here, I'm calling uint32_t version of Packer::pack, but I'm getting this warning.  Could someone help me out? Thanks! Packer packer; packer.pack<0, 127>(7u); //no warning packer.pack<0, 128>(7u); //warning class Packer { public: Packer(); const void * getData() const; std::size_t getDataSize() const; void pack(bool data); template <std::int8_t min = (std::numeric_limits<std::int8_t>::min)(), std::int8_t max = (std::numeric_limits<std::int8_t>::max)()> void pack(std::int8_t data); template <std::uint8_t min = (std::numeric_limits<std::uint8_t>::min)(), std::uint8_t max = (std::numeric_limits<std::uint8_t>::max)()> void pack(std::uint8_t data); template <std::int16_t min = (std::numeric_limits<std::int16_t>::min)(), std::int16_t max = (std::numeric_limits<std::int16_t>::max)()> void pack(std::int16_t data); template <std::uint16_t min = (std::numeric_limits<std::uint16_t>::min)(), std::uint16_t max = (std::numeric_limits<std::uint16_t>::max)()> void pack(std::uint16_t data); template <std::int32_t min = (std::numeric_limits<std::int32_t>::min)(), std::int32_t max = (std::numeric_limits<std::int32_t>::max)()> void pack(std::int32_t data); template <std::uint32_t min = (std::numeric_limits<std::uint32_t>::min)(), std::uint32_t max = (std::numeric_limits<std::uint32_t>::max)()> void pack(std::uint32_t data); ...  
  10. https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking https://code.google.com/archive/p/nuclear-bomberman/wikis/Interpolation.wiki   After reading these 2 articles, I was able to implement mine.
  11. Trying to see if there is a point in trying to write endian independent code
  12. simple java question

    i2 points to the same address as i does. so since i becomes "0", shouldon't i2 also be "0"?
  13. String i = "3"; String i2 = i; i = "0"; System.out.println(i2);     I expected this to print out 0, but it prints out  3. Why?
  14. Game Development Laptop

    Right now is a fantastic timing to build a desktop since the new skylake intel cores were just released. But if you absolutely need the portability, I recommend a high end ASUS or MSI gaming laptop.