Handmade Hero»Forums»Code
6 posts
How to keep files from depending on each other?
Maybe I'm missing something; but I don't really understand what to do when two files depend on each other types in the "handmade hero style file" where everything is included into one big file.

This may not be a great example but what if I have these files:

1
2
3
4
5
6
 [game_audio.h]
struct oscillator
{
  real32 tSine;
  void* Memory;
};

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
[game_audio.cpp]
#include game_audio.h

internal 
void FillRegion(game_oscillator Oscillator, game_state State)
{
  // Do the filling if a button is down.
  if(State->Joystick.AnyButtonIsDown)
  {

  }
}


And these:
1
2
3
4
5
6
[game_world.h]
struct game_state
{
  bool32 IsInitialized;
  void* GameMemory;
};

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[game_world.cpp]
internal void
UpdateWorld(game_state State, oscillator Oscillator)
{
  // Change the state of the world.
  // Reset oscillator time in a certain state.
  if(State->MovingToNextLevel)
  {
    Oscillator.tSine = 0;
  }
}


There is no order possible in which it works because both files need to know about each other:
1
2
3
[game.cpp]
#include "game_audio.cpp" // Now game_audio.cpp doesnt know about game_state
#include "game_world.cpp"


1
2
3
[game.cpp]
#include "game_world.cpp" // Now game_world.cpp doesnt know about oscillator
#include "game_audio.cpp"




498 posts
How to keep files from depending on each other?
put all headers first:

1
2
3
4
#include "game_world.h" 
#include "game_audio.h"
#include "game_world.cpp" 
#include "game_audio.cpp"
6 posts
How to keep files from depending on each other?
@ratchetfreak
Oh my damn, how could I not see that. Thanks man.