Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

110 Neutral

About Striken

  • Rank
  1. One cause may be if you're sending many small messages over TCP, they may not actually be transmitted until the outgoing stream buffer is of a certain size. setsocketopt - Check out TCP_NODELAY
  2. I haven't played around with raw win32 sockets for a while as I'm quite fond of the abstraction that boost::asio provides. I do think however it is very important to understand the key underlying concepts as you are doing by working at the lower level so I'll give you some examples. This is from the top of my head without much thinking about it so usual disclaimers apply.... This is an example of sending data... receiving is similar in principle. This probably isn't your problem because sending just 8 bytes is likely to succeed in one call but this is necessary nontheless. // Encapsulating sending a buffer of generic data. Accepts the array of bytes to send // and the number of bytes to send. (True success, all sent, false failure). This is blocking. bool sendData(char *i_buf, int i_bufLen) { int offset = 0; int rc; while (offset < i_bufLen) { rc = send(socket, i_buf+offset, i_bufLen-offset); if (rc == SOCKET_ERROR) return false; offset += rc; } return true; } Your main concern is converting your data types into a common format supported at your client and server ends. Here is an example of receiving and translating data: char recvData[256]; uint32_t playerX = 0; uint32_t playerY = 0; if (receiveData(recvData, 256)) { // Similar to sendData // We've succesfully read 256 bytes of data, we know that the stream starts with 2 4-byte integers. Read them: // Read each byte into the integer representing the player position (similar to the way I'd do it) playerX = recvData[0] << 24; playerX |= revData[1] << 16; playerX |= revData[2] << 8; playerX |= revData[3]; playerY = recvData[4] << 24; playerY |= revData[5] << 16; playerY |= revData[6] << 8; playerY |= revData[7]; // Or use the helper function for this something like this: // playerX = ntohl(*(uint32_t*)recvData); } There's a whole lot more I'd recommend doing - think about implementing your own message buffer class that serializes / deserializes different data types into an appropriately encoded byte array.I hope this gives you an idea of what you need to do.
  3. Hmm looking at your code there are a few fundemental things wrong with your implementation.. Assuming this is all win32 sockets: Firstly the call to "recv" does not guarantee to read the entire packet as you're expecting it to. You need to encapsulate it within a loop that reads from the incoming stream until the expected amount of bytes are read as indicated by the return value of the function call. Same applies to the call to send - it doesn't guarantee that the whole packet is sent within 1 call. Next simply reading and writing to the packet structure as a buffer is a very bad way of doing things for a number of reasons - but foremost it's highly likely byte ordering on the recipient end will probably not be as you expect it to. If you're doing things with floating point values then you're really asking for trouble (look up nthol and htonl and others). Attempt to write a manual serialization for each data type within the packet. Also be aware that byte packing may be different the client/server so the sizeof(packet) may return different values. There are probably a few more issues but I hope that sets you in the right direction.
  4. Striken

    Reading from a text file (c++)

    For a quick and easy bit of string manipulation if you have access to boost I'd recommend looking at boost::split (within boost/algorithm/string.hpp).
  5. Quote:Original post by XTAL256 And i have a list of ObjectA objects. I could store ObjectB in the DB as a separate table, but how would i have each ObjectA reference an ObjectB? You'd definitely want to store the objects of different type in another table - you'd use the unique primary key of the object you want to refer to as a foreign key. For example CREATE TABLE ObjectsOfTypeA ( ID SERIAL, /* Primary key */ Data bytea, OwnedObjectB INT, /* Each Object A owns a single Object B */ CONSTRAINT objecta_pkey PRIMARY KEY (ID), CONSTRAINT objecta_owned_object FOREIGN KEY (OwnedObjectB) REFERENCES ObjectsOfTypeB (ID) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION ); CREATE TABLE ObjectsOfTypeB ( ID SERIAL, /* Primary key */ Data bytea, CONSTRAINT objectb_pkey PRIMARY KEY (ID) ); Something that that effect anyway... hth
  6. Although in addition, I suggest you read the topic (below this at the moment) regarding how matrix stacks are obsolete now.
  7. Broadly speaking.. for any given camera viewing the scene, start rendering from it's perspective by: // camera // Configure the projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fov, aspect_ratio, near_clip_plane, far_clip_plane); // Prepare the modelview matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(position.x(), position.y(), position.z(), position.x()+forward.x(), position.y()+forward().y(), position.z()+forward.z(), up.x(), up.y(), up.z()); // object rendering // Then sometime later during rendering your individual objects, you need to transform their vertices from object space into world space: glPushMatrix() glMultMatrixf(obj->obj_matrix().mat44); // This is a 4x4 matrix representing the object's orientation and position in world space. How you derive this is up to you... // render object here glBegin(GL_POINTS); glVertex3f(0,0,0); glEnd(); glPopMatrix(); HTH edit: Of course replace the glBegin/glEnd() with your vertex array rendering routine.
  8. I think you just need to go to the Project Properties page -> Configuration Properties -> C/C++ -> Advanced and select "Compile as C Code" under the option "Compile As".
  9. I would suggest making everything traversable in the scene graph of a common base type and then build derived classes based on that type which you can 'attach' or add as child nodes to the parent basic type. Then supply different properties to these derived classes to create the functionality you want to add to the 'father'. Like this: class mesh { float *vertices[3]; // etc... }; class game_object { // 3d position in space float pos[3]; }; class game_actor: public game_object { // collection of meshes that are rendered std::vector<Mesh> actor_meshes; }; These child nodes can inherit certain properties from their 'father' nodes, such as visibility status, world position and orientation etc. - game_object (x, y, z) | - game_actor (x, y, z), (mesh) | - game_actor (x, y, z), (mesh) | // or a more funky way of looking at it: - super_spaceship (124.51, 98.124, -32.55) | - laser_turret ( 0.1, 0.1, -1), (laser_mesh) | - laser_turret (-0.1, 0.1, -1), (laser_mesh)
  10. Striken

    Game designs of questionable ethics

    Hi there! I'm not used to posting here but this is a very interesting topic so I'd like to share my views. The whole issue about the morality of games was raised quite recently in the UK where the defence minister criticized the developers of the new Medal of Honour game for allowing players to play as Taliban and apparently kill coalition troops. That's certainly a morally questionable game play from a generic patriotic / Western democratic / capitalist viewpoint. But in my experience I've come across a different kind of moral question. I used to work as a developer for a company that made games for well known (childrens) brands. The games were dull, uninspiring with no lifespan. The business model was obvious: cash in on the latest fad while it lasts and move on. I personally found this more morally objectionable than any of the 'cool' violent games that were being developed at the same studio. This was one of the reasons that made me quit. But my answer to your question is that it depends totally on the person. Would I feel guilt for enslaving and cross-breeding elves? Would I feel guilt for shooting a British soldier in a game? (should be quite a personal issue for me as my brother is in the army) No. I see them as games and only that. This doesn't mean I have no concern about their influences on other (mainly younger) people.
  11. Think about starting with the basic data structure that encapsulates your terrain before you worry too much about nice terrain features. I did some personal work on a terrain editor out of boredom and a nice place to start is some kind of midpoint displacement algorithm using QuadTrees... that was a few years ago now so there are probably some far better methods out there - but good luck!
  12. Striken

    inheritance / design query

    Ah ok.. as I feared!! Thanks for the clarification :)
  13. Hi guys... I need a little bit of advice as to the way to go about things. Suppose I have a class... I suppose the easiest concept is a something like a Parameter. Each of these 'parameter' classes can contain sub parameters, identified by their ID. class Parameter { private: int _type; std::map<int, Parameter> _subParams; public: Parameter(const Parameter&); virtual void operator=(const Parameter&); void addSubParameter(const Parameter& i_param) { _subParams.insert(std::pair<int, Parameter>(, i_param)); } int type() const; }; class TypeA : Parameter { private: //member stuff _type = 1 public: TypeA(const TypeA&); virtual void operator=(const TypeA&); }; class TypeB : Parameter { private: //member stuff _type = 2 public: TypeB(const TypeB&); virtual void operator=(const TypeB&); }; Say Type B is contained within Type A, so we want to do: TypeA paramA(...); paramA.addSubParameter(TypeB(...)) When the std::map::insert function is called, only the base class copy-constructor is invoked, and not the TypeB() copy constructor / operator=, so I get none of the values copied across. It's a bit of a crude example - but I hope the concept comes across. What am I doing wrong? Or am I just a bit loopy...?
  14. Striken

    program expiry date

    Ok, pretty much what I thought.. Thanks guys!
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!