I started a hobby project which would be the first thing I do in C that is intended to be seen by someone else. I've been practicing for a while but I'm actually a beginner; I never wrote real software in C/C++ yet.
I wanted to know what is OK from my code, what is wrong and why, if it's clear/readable, and everything you can tell me about it would be fine. I have never shown any of my code to anyone and I have no clue if I'm doing well, or if it can't be worse--the latter being what I consider most likely. So I would like to know the reasons from people with experience with C/C++, and what you consider that I can improve/remove, etc.
The code is something I've just started, about a small voxel system for a Minecraft-like game.
The basic idea would be:
- to have an array of voxel types
- to be able to assign rules to the voxel types (like functions/scripts to be called.. somehow?)
- to have an array of game relevant states for each voxel. The state data would be mostly lighting and visibility values.
- to be able to save and load state data as necessary
etc... I have a lot of ideas but I still barely wrote some code and I would like to know other people's opinions before continuing, so I can improve the project instead of having to fix it later.
This is the link for the project files (only a .h and a .cpp, it's just started) at google code
And here are some of the contents of the .h so you can give yourself an idea without opening the link:
typedef struct _GVOXEL_RULE
{
GVOXELRULE_ID nRuleID;
INT32 nRuleValue; // this value is left for use by the rule function, not needed right now
} GVOXEL_RULE;
// here I'm planning to store the description of the voxel types
typedef struct _GVOXEL_DATA
{
GVOXEL_TYPE nVoxelType;
dword nRuleCount;
GVOXEL_RULE* pVoxelRules; // I'm thinking this should be separated to a "voxel rule manager" class or something similar
dword nVoxelCount; // store here the amount of voxels applying this reference (so we stop looking when the limit is reached)
} GVOXEL_DATA;
typedef struct _GVOXEL_STATE_1_0
{
GVOXEL_ID nVoxelID; // This id will be equal to the voxel index which may be handy
GVOXEL_TYPE nVoxelType; // This number will reference the table with voxel descriptions
word nMetadata; // This was described below.
byte nLightX; // This stores how much light (from 0 to 255) is receiving the face pointing to +X
byte nLightXN; // Same from below but for -X face
byte nLightY; // etc.
byte nLightYN; // etc..
byte nLightZ; // etc...
byte nLightZN; //
} GVOXEL_STATE_1_0, GVOXEL_STATE;
typedef struct _GVOXELCHUNK_DATA_1_0 //
{
volatile long nRefCount; // <-- This gives me the chills
dword nChunkID; // some chunk ID that makes sense in some other reference table. or not.
dword nWidth; // size of the array in the X dimension
dword nHeight; // size of the array in the Y dimension
dword nDepth; // size of the array in the Z dimension
GVOXEL_STATE_1_0* pVoxelStateList; // The count of voxel states will be nWidth*nHeight*nDepth
dword nExtendedDataSize; // size of optional data, if found in the file, to be loaded to the "pExtendedData" pointer.
void* pExtendedData; // If bExtendedData is 0, this variable should be set to 0 (null).
} GVOXELCHUNK_DATA_1_0, GVOXELCHUNK_DATA;
void gvCreateChunkData10( GVOXELCHUNK_DATA_1_0** ppChunkData );
void gvAcquireChunkData10( GVOXELCHUNK_DATA_1_0* pChunkData );
void gvFreeChunkData10( GVOXELCHUNK_DATA_1_0** ppChunkData );
#define gvCreateChunkData gvCreateChunkData10
#define gvFreeChunkData gvFreeChunkData10
#define gvAcquireChunkData gvAcquireChunkData10
// wchar_t* pFilename: Name of the source file to load chunk data from
// dword *nMaxChunks: if ppChunkData is NULL, the function returns here the number of chunks in the file. else stores the
// GVOXELCHUNK_DATA** ppChunkData:
INT32 gvLoadChunkFromFileW( wchar_t* pFilename, dword *inout_nMaxChunks, GVOXELCHUNK_DATA** ppChunkData );
//
INT32 gvSaveChunkToFileW( wchar_t* pFilename, dword nChunkCount, GVOXELCHUNK_DATA** ppChunkData );
#ifdef _TODO
INT32 gvLoadChunkFromFileA( char* pFilename, dword nMaxChunks, GVOXELCHUNK_DATA** ppChunkData );
INT32 gvSaveChunkToFileA( char* pFilename, dword nChunkCount, GVOXELCHUNK_DATA** ppChunkData );
#endif
#define gvLoadChunkFromFile gvLoadChunkFromFileW
#define gvSaveChunkToFile gvSaveChunkToFileW