Jump to content

  • Log In with Google      Sign In   
  • Create Account

MarlboroKing

Member Since 16 Nov 2010
Offline Last Active Sep 11 2016 11:35 AM

Posts I've Made

In Topic: GameObject class doesn't draw a image but a white box instead

10 September 2016 - 11:03 PM

I skimmed over it.. do you ever initialize "visible" anywhere in your sprite or GameObject? No? Then it's set to false, and your Sprite class is not drawing it due to the if conditional.

Edit: Scratch that, I see you initialized it in your .h file (not used to that at all...)

I'd have to add what has been said: you're going to have to use your debugger. Make sure all values are set correctly, then continue. As it stands, your code appears valid. Once you make sure EVERY piece of variables and objects have valid data, then please attach the rest of your code.

In Topic: C++ Going Beyond Basics

09 September 2016 - 08:04 PM

If you don't know programming, C++ is a terrible language to learn. I would start by learning a friendlier language first. Python is often suggested for this purpose, but I don't think there is anything wrong with learning C, for instance.

I think you have the right idea in trying to find projects that motivate the learning of different concepts.

Beyond input and output, try to learn:
* Loops (make a multiplication table)
* Fancier loops (test if a number is prime by trying to divide it by trial division)
* Functions (learn to organize your code in understandable chunks with a good name and a clean interface, provided by the parameters and the return value of the function)
* Data structures (things like arrays, lists and trees; but the details depend on the exact language you are working with)
* File I/O (process a text file and count how many characters, words and lines it contains)

C++ is a GREAT way to start coding. You learn about how a program behaves, instead of being stuck by rules. Once you understand how a program works, the rest is syntax.

Sure, memory manipulation, stricter syntax, no safety nets, etc. But, it's best to learn WHY you need to do /that/ instead of being told "its bad".

I always recommend starting with C or C++, then understanding the basics of x86/x64 Assembly. Seeing how a program works, is far better than being told "it works".

Edit: To the OP. Have you done classes and inheritance? The cpp standard? STL? Win32/x11? There's far and far more to learn. Master what you know now, then move on. I highly recommend learning the cpp standard first. Then move on to the area you like (sound, opengl/directx, vulkan, etc), api programming, so forth). Learn to structure code throughout files. Can you write a number guess game via std::cout? Try that. Then move on.

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?
Writing
Reading

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
m_Locker.Lock();
.....
Else
QueueIt();

void Read( Obj o )
If not locked
m_Locker.Lock();
......
Else
.....

Or expand to something actually useful.

PARTNERS