Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 25 Dec 2012
Offline Last Active Mar 25 2013 09:23 AM

#5033529 A question about how to organize in code, a small game project

Posted by on 17 February 2013 - 03:58 PM

This may help you:  http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)


What you are asking for is overly general; So I'm giving you a very general answer and that is that in most code bases its good to keep in mind that as long as classes have one responsibility, they are closed for modification but open for extension by design, and you follow all the OOP rules, you should be good.  If you need to learn these rules first, then I suggest you invest in a book called "Clean Code".  Most of the code samples are in java but the things it teaches will make you a better programmer in any language for any project, even if you disagree with some of the things the author :(Commonly simply known as "uncle bob") says.

#5030509 Grappling combat

Posted by on 09 February 2013 - 04:43 PM

So map it out in  a state diagram.

#5030484 Grappling combat

Posted by on 09 February 2013 - 03:27 PM

And you want this over a network?


Consider your animation rigging for a second.  Now think of your rigged joints and the degrees of freedom they have. Now modify that by the gear the player wears on a per instance basis.

That is a lot of work.  So what is the simplest version of this you can get working, and where are you hiding the network lag to make sure its playable?

#5030480 pointers while serializing

Posted by on 09 February 2013 - 03:15 PM

You can also store the pointers as offsets from the start of a structure.

Then when you load this structure into memory, you can 'fixup' the pointers by adding the offset to the actual memory address of the start of the loaded structure and saving the result back, and voila, your pointers are valid again.

0 Start of structure1 Pointer to Chicken (offset 3)2 Pointer to Duck (offset 6)3 Chicken4 ..5 ..6 Duck7 ..8 ..

Or better explained in C code (And x-posted on my site)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Declare your basic struct.
typedef struct MyGameObject{
unsigned char hp;
char *name; // Doesn't matter what this is for our demo here.
} GameObject;

// Declare your game id type to make things easier later.
typedef unsigned long int GameObjectId;

// Declare the struct that contains all of the data.
typedef struct MyGameRealObject{
GameObjectId id;
GameObject gameObject;
} AllocatedGameObject;

// Function to build the allocated object.
// Param name should be allocated off the heap not the stack.
GameObject *BuildGameObject(char *name, unsigned char hp){
// Get our gameObjectId.
// Lets just Pretend the number is coming from a
// global singleton manager.
GameObjectId gameobjectIdNumber = 12345;

// Allocate enough memory for your new struct
// and a hidden game object id.
AllocatedGameObject *go = (AllocatedGameObject*)malloc(sizeof(AllocatedGameObject));

// barf how you like, this isn't meant to be complete.

go->id = gameobjectIdNumber;
go->gameObject.hp = hp;
go->gameObject.name = name;

GameObject *gameObjectToReturn = &go->gameObject;

return gameObjectToReturn;

// Function to get the full allocated object.
// param gameObject should be part of a AllocatedGameObject allocated off the heap.
AllocatedGameObject *GetAllocatedGameObject(GameObject *gameObject){

return 0;

char *vhs = (char *)gameObject; // Makes our math easier.
AllocatedGameObject* allocated = (AllocatedGameObject*)(vhs - sizeof(GameObjectId));

return allocated;

// Get the gameObject's hidden id.
// param should be allocated off the heap not the stack or bad things will happen.
GameObjectId GetGameObjectId(GameObject *gameObject){
AllocatedGameObject* allocated = GetAllocatedGameObject(gameObject);

return allocated->id;

return 0;

// Cleanup and destroy the allocated GameObject.
// param gameObject should be part of a AllocatedGameObject allocated off the heap.
// Per the above so should the game objects ->name.
void DestroyGameObject(GameObject *gameObject){

AllocatedGameObject* allocated = GetAllocatedGameObject(gameObject);


allocated->id = 0;
allocated->gameObject.hp = 0;

size_t len = strlen(allocated->gameObject.name);
memset(allocated->gameObject.name, 0, len);
allocated->gameObject.name = NULL;


int main(char* argv){
// Build game object
char *objectName = strdup("Scary Monster!");
GameObject *gameObject = BuildGameObject( objectName, 100 );
GameObjectId gameObjectId = GetGameObjectId(gameObject);

printf("\nId: %d\n", gameObjectId);
printf("Name: %s\n", gameObject->name);

// Always clean up after yourself.

return 0;


#5029962 Microsoft confirms XNA is over

Posted by on 07 February 2013 - 10:25 PM

So C++ with the new math libs is the only future proof option?