Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Nov 2010
Offline Last Active Apr 21 2016 06:49 PM

Posts I've Made

In Topic: Optimizing Generation

19 April 2016 - 04:06 PM

You have your block struct, eg;
struct Block
byte nSunlight;
ulong nColor;
EBlockType nType;

Then you have your array,
int nCacheWidth = (nCacheRange * 2) + 1;
int nCacheDepth = nCacheWidth;
Block* pBlocks = new Block[nCacheWidth * nCacheDepth * nChunkHeight];

Now with the nType in the Block struct, specify AIR to 'delete' a block. nSunlight I used to use it as a value between 0-100, with 100 being brightest. nColor holds 4 bytes for each color (ARGB).

Accessing each index would be,
long tmpX = nCacheDepth * nChunkHeight;
long tmpZ = nChunkHeight;

long x = pos.x % nCacheWidth;
long z = pos.z % nCacheDepth;
long OFFSET = x * tmpX + z * tmpZ + pos.y;
blocks[OFFSET].nType = EBlockType.AIR;

I typed that from memory on my phone so excuse any errors. I also prefer this way as it makes it so much simpler if you/user wants bigger or smaller view/cache ranges (loading more chunks).

In Topic: Optimizing Generation

19 April 2016 - 10:57 AM

Constant allocation and deallocation is a big no, for something this big.

It appears for every single block, you're new'ing and delete'ing. If you're aiming for world modification, shifting, etc. - create your initial data structure at once, then assign the block types.

Yes, new'ing each block works, but if in one scene you have 8,000,000 blocks, that's a lot of allocation and deallocation. But 8,000,000 new operations, and, let's just say, 400,000 delete operations, it's just flat overkill. Eg;

if( someCondition ) {
blocks[myIndex].nType = BlockTypes.AIR;

Also, I'd say use a 1D array instead of a 3D array.

In Topic: Combination n choose 2 - multithreading

23 June 2015 - 10:01 PM

Working with threads is really 3 things:
Do I need a new thread?

If you passed #1, #2 & #3 needs some form of locker. You can not write while reading and vice versa.
This could be as:
void Write( Obj o )
If not locked

void Read( Obj o )
If not locked

Or expand to something actually useful.

In Topic: what really get and set do?

23 June 2015 - 09:52 PM

Here's another approach:
public String CharName { get; private set; }

Which allows public return, but prohibits assigning outside the class.
Get/Set is just a quick 'macro'. It basically points to a data type in a class/struct.

In Topic: Hi there, freshman here =]

19 June 2015 - 09:51 PM

Programming is logic. Period.
Video games are logic. Mostly.

You won't really touch integrated GUI's (eg Win32), you will create your own. Like I said, logic. That's all a GUI is in the core. For a button, you click, then an 'event' happens.

As for visual, you'll need to understand OpenGL, it works like a pair in Java. You'll learn about buffers, memory management, textures/sprites, and let's not forget pulling hair out. To start, learn what versiom of OpenGL your system is running, then start on Google. Im sorry, but OpenGL likes to change drasticallt in each revision and much differs here and there.