Jump to content

  • Log In with Google      Sign In   
  • Create Account

Mitchell314

Member Since 19 Feb 2008
Offline Last Active Jun 13 2014 08:06 PM

Topics I've Started

[solved] Calling recv() in a loop

14 December 2013 - 04:37 PM

When reading a tcp socket for arbitrarily sized packets, is it safe to keep calling recv() until it returns a negative number? For simplicity's sake, I'm assuming no other error is raised, just that return value of 0 means connection closed, and -1 means there's no data left to be read at the time.

 

For example, would the following code properly read all of the socket's contents? The other end of the connection is sending data in the format of "<text> \n <text> \n <text> \n .... <text> \n"

/* Make believe string structure */
struct resizableString string;

int bufferSize = 100;
int socket = connectToOtherHost();

while (-1){
    char *pBuffer = calloc(bufferSize);
    int bytesRead = recv(socket, pBuffer, bufferSize, 0);

    if (bytesRead == 0) {
        printf("Client closed connection\n");

    } else if (bytesRead >0) {
        /* Appends fix-length buffer to a string */
        appendBufferToString(string, pBuffer, bufferSize);

    } else {
        /* Done reading */
        free(pBuffer);
        break;
    }
}
parsePacket(&string);

Proper way to sync data to disk?

05 August 2013 - 08:49 PM

Hello.

 

I'm new to game development, and I'm trying to make a multi-player game server. One design issue I've run into is trying to find a fast but safe way to keep server data (account info, game states, etc) and file data synchronized. I thought about just saving directly to the file whenever any internal data structure is changed, but I don't know how much that would impact performance to constantly write to the disk. I also want to minimize the chance of putting the files in an inconsistent state in the event of a crash. Which the current server gleefully makes a hobby of doing.

 

 

So what's a good disk I/O strategy to keep the performance decent, the data consistent, and code complexity/size down?


Sending messages in Objective C?

10 June 2009 - 01:26 PM

How am I supposed to send messages between classes in different files? I've got a controller for intercepting buttons to change the screen's colors, in "MyColorController.m," and an associative header. I've also got a controller for an OpenGL screen in "myOGLview.m," which also has a header. My goal is to have this flow: Step 1: User presses button Step 2: MyColorController sets it's own color value according to buttons pressed Step 3: A miracle happens, and myOGLview class some how gets the new color Step 4: myOGLview draws a simple flat shaded rectangle Steps 1,2, and 4 are all accomplished, I know how to do that stuff. But I can't get step 3 to work. According to the "MyColorController" files, the other files don't exist, and vice versa. Global variables don't work. And everything I google tends to pull up stuff I already know or don't need to know for the moment.

Question about projections and transpose matrices

16 October 2008 - 02:39 PM

I've got a book on 3d graphics & game design by David Eberly. I've been reworking the equations for projections (point to line, orthogonal, perspective), and I keep getting confused when he uses transpose operations on 4-tuple vectors. For instance in point-to-line-projections: Let L be some 3d line defined by unit vector V and some point P. X is a given point not on the line that is to be projected orthogonally to point Y. Solve for Y. When I try to solve the equations for Y, I end up with something important canceling out. Or worst, in this case I had X = Y. The book arrives at Y-P=(V*(X-P))*V . I see how that came about by following the author's math. I know a little about linear algebra so far. Then the next equation is Y-P=V*V'*(X-P), where V' is the transpose of V. I don't get that part, and the only thing I know about transposes is that they're like 'flipping' a matrix. How did this transpose operation arrive?

What method is the quickest for depth testing?

05 March 2008 - 01:24 PM

I thought depth testing meant having a depth buffer (as an array) where the depth of pixel chunks were stored. But I've seen somewhere (I don't remember where) that depth testing might have been spatial sorting (using nodes I think). So, which method would be quicker: sorting polygons by distance from the camera, or using an extra screen buffer? I'm thinking that the load is around a couple hundred triangles. And are there faster methods?

PARTNERS