Skip to main content
added 8 characters in body
Source Link
user124120
user124120

I am trying to replicate a chunk loading system, in C, for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk?
In my game, once I load chunks using fread, what should I use to store them? My problem for a two dimensional array for storing chunks, is that the loaded chunks might be separate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

Edit:

I gotThe problem is just an answerarray will not work. DoSuppose there is a player at 1000000 and another one at -1000000 They would only render 6 chunks around them, but if they mean somethingshared an array, all the 2000000 blocks worth of chunks that aren't loaded would be taking up memory. I would refer to chunks like thisLoadedChunk[1000]. How can I handle that?

#define NOTHING
struct ChunkInstance {
    struct BlockInstance Block[16][256][16];
} ***LoadedChunk NOTHING NOTHING NOTHING;

then later

#define molloc(arg) malloc(arg)
LoadedChunk = molloc((2rd+1)squared); //<--pseudo code, rd = render distance

I am trying to replicate a chunk loading system, in C, for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk?
In my game, once I load chunks using fread, what should I use to store them? My problem for a two dimensional array for storing chunks, is that the loaded chunks might be separate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

Edit:

I got an answer. Do they mean something like this?

#define NOTHING
struct ChunkInstance {
    struct BlockInstance Block[16][256][16];
} ***LoadedChunk NOTHING NOTHING NOTHING;

then later

#define molloc(arg) malloc(arg)
LoadedChunk = molloc((2rd+1)squared); //<--pseudo code, rd = render distance

I am trying to replicate a chunk loading system, in C, for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk?
In my game, once I load chunks using fread, what should I use to store them? My problem for a two dimensional array for storing chunks, is that the loaded chunks might be separate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

Edit:

The problem is just an array will not work. Suppose there is a player at 1000000 and another one at -1000000 They would only render 6 chunks around them, but if they shared an array, all the 2000000 blocks worth of chunks that aren't loaded would be taking up memory. I would refer to chunks like LoadedChunk[1000]. How can I handle that?

How should I store loaded world chunks in RAM (For my game similar to minecraftMinecraft)?

I am trying to replicate a chunk loading system, in C, for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk,?
In my game, once I load chunks using fread, what should I use to store them.? My problem for a two dimensional array for storing chunks, is that the loaded chunks might be seperateseparate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

Edit:

I got an anweranswer. Do they mean something like this?

#define NOTHING
struct ChunkInstance {
    struct BlockInstance Block[16][256][16];
} ***LoadedChunk NOTHING NOTHING NOTHING;

then later

#define molloc(arg) malloc(arg)
LoadedChunk = molloc((2rd+1)squared); //<--pseudo code, rd = render distance

How should I store loaded world chunks in RAM (For my game similar to minecraft)?

I am trying to replicate a chunk loading system in C for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk,In my game, once I load chunks using fread, what should I use to store them. My problem for a two dimensional array for storing chunks, is that the loaded chunks might be seperate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

Edit:

I got an anwer. Do they mean something like this?

#define NOTHING
struct ChunkInstance {
    struct BlockInstance Block[16][256][16];
} ***LoadedChunk NOTHING NOTHING NOTHING;

then later

#define molloc(arg) malloc(arg)
LoadedChunk = molloc((2rd+1)squared); //<--pseudo code, rd = render distance

How should I store loaded world chunks in RAM (For my game similar to Minecraft)?

I am trying to replicate a chunk loading system, in C, for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk?
In my game, once I load chunks using fread, what should I use to store them? My problem for a two dimensional array for storing chunks, is that the loaded chunks might be separate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

Edit:

I got an answer. Do they mean something like this?

#define NOTHING
struct ChunkInstance {
    struct BlockInstance Block[16][256][16];
} ***LoadedChunk NOTHING NOTHING NOTHING;

then later

#define molloc(arg) malloc(arg)
LoadedChunk = molloc((2rd+1)squared); //<--pseudo code, rd = render distance
added 298 characters in body
Source Link
user124120
user124120

I am trying to replicate a chunk loading system in C for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk,In my game, once I load chunks using fread, what should I use to store them. My problem for a two dimensional array for storing chunks, is that the loaded chunks might be seperate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

Edit:

I got an anwer. Do they mean something like this?

#define NOTHING
struct ChunkInstance {
    struct BlockInstance Block[16][256][16];
} ***LoadedChunk NOTHING NOTHING NOTHING;

then later

#define molloc(arg) malloc(arg)
LoadedChunk = molloc((2rd+1)squared); //<--pseudo code, rd = render distance

I am trying to replicate a chunk loading system in C for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk,In my game, once I load chunks using fread, what should I use to store them. My problem for a two dimensional array for storing chunks, is that the loaded chunks might be seperate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

I am trying to replicate a chunk loading system in C for my own minecraft like game, though I don't know how. Once chunks are loaded, are they placed in an array, or are there a bunch of variables for each loaded chunk,In my game, once I load chunks using fread, what should I use to store them. My problem for a two dimensional array for storing chunks, is that the loaded chunks might be seperate and not start at zero. Are there any suggestions for storing loaded chunks?

I have a code fragment, solely so you guys will not yell at me for not including code:

    char ChunkFilePath[strlen(CurrentWorld)+32];
    sprintf(ChunkFilePath, "%s/ChunkData/%ld %ld", CurrentWorld, X, Z);
    FILE *ChunkFile;
    if ((ChunkFile = fopen(ChunkFilePath, "r"))) {
        //chunk file exists, Read Chunk file to ???
    }
    if ((ChunkFile = fopen(ChunkFilePath, "w")) == NULL) {
        fputs("Error Loading Chunk (File Not Found)", stderr);
        return;
    }
        /*Chunk does not exist, but any other errors would have been caught 
        at this point, so Generate chunk, write generated results to ???*/

Note: The game I am trying to make is purely for my personal use, not for any commercial use.

Edit:

I got an anwer. Do they mean something like this?

#define NOTHING
struct ChunkInstance {
    struct BlockInstance Block[16][256][16];
} ***LoadedChunk NOTHING NOTHING NOTHING;

then later

#define molloc(arg) malloc(arg)
LoadedChunk = molloc((2rd+1)squared); //<--pseudo code, rd = render distance
edited tags
Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342
Loading
deleted 1 character in body
Source Link
user124120
user124120
Loading
Source Link
user124120
user124120
Loading