hello , I am making a small game engine and I have 2 header files engine.h and objects.h they both include each other. However it seems that its not getting included into objects.h , what is the "right" way to fix this ?

sorry , I'm too lazy to gut out my code to make it more readable

engine.h


#ifndef ENGIN_H_INCLUDED
#define ENGIN_H_INCLUDED

using namespace std;

#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_ttf.h>

#include <math.h>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <time.h>

#include "objects.h"

using namespace std;

/// user

//Surface Copy

void drip_blit( float x, float y, SDL_Surface* source, SDL_Surface* destination );

//Render text
enum textquality { solid, shaded, blended };

SDL_Surface * drip_draw_text(TTF_Font *fonttodraw, string texts, int fgR, int fgG, int fgB,int fgA , int bgR, int bgG, int bgB, int bgA, textquality quality);

// Load

unsigned int drip_load_font(string file, int ptsize);

unsigned int drip_load_image(string file);

unsigned drip_load_music(string file);

unsigned drip_load_sound(string file);

// Get

SDL_Surface * drip_get_image(unsigned int img_num);

Mix_Music * drip_get_music(unsigned int mus_num);

Mix_Chunk * drip_get_sound(unsigned int snd_num);

TTF_Font * drip_get_font(unsigned int font_num);

// Music/Sound

void drip_play_music(unsigned int pos,int loopn);// 1- = forever 0=1 1=2 etc

void drip_stop_music();

void drip_pause_music();

void drip_unpause_music();

void drip_music_position(double pos);

void drip_play_sound(unsigned int pos);

void drip_stop_sound();

void drip_pause_sound();

void drip_unpause_sound();

void drip_fadeout_sound(float seconds);

// collisions

int drip_rect_collide(SDL_Rect a , SDL_Rect b);

unsigned int drip_rect_collide_all(SDL_Rect rect,unsigned self);

int drip_get_distance(int x1,int y1,int x2,int y2);

unsigned int drip_rect_collide_circle(int radius,int x1 ,int y1,unsigned self);

// random

void drip_randomize();

int drip_random(int low , int high);

// xlength & ylength for moving in directions - what else do you name them ? (super_ultral_directiony_move_thinga_ma_jig)

float xlength(float direction,float length);

float ylength(float direction,float length);

// map / file

string drip_map_process(string data);

void drip_file_write(char file[255],string data);

string drip_file_load(char filen[255]);//standard text

string drip_map_rawload(char filen[255]); // output in map format

string drip_string_copy(string str,int pos1,int pos2);

string drip_map_extract(string mapdata,int num);

void drip_map_exec(string cmddata);

void drip_map_execute(string mapdata);

string drip_map_load(string file);

/// System

// Start the system

SDL_Surface * init(char caption[255],int width , int height , int soundvoulme , int musicvolume);

// load up all the system resources

bool load();

// update objects

void update(SDL_Surface * screen);

// quit game and free resources

void quit();

#endif // ENGIN_H_INCLUDED
objects.h

#include <SDL.h>
#include "SDL_image.h"
#include "SDL_mixer.h"
#include "SDL_ttf.h"
#include "SDL_rotozoom.h"

#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include "engine.h"

// not working ??? #include "engine.h"


#ifndef OBJECTS_H_INCLUDED
#define OBJECTS_H_INCLUDED

using namespace std;

class game_object;

namespace var
{
    extern vector<game_object*> _objects_;
    extern vector<SDL_Surface*> _img_;
    extern vector<TTF_Font*> _font_;
    extern vector<Mix_Chunk*> _sound_;
    extern vector<Mix_Music*> _music_;

    // gameplay

    extern int trigger[33];
    extern float delta;

    // settings

    extern bool quit;
    extern bool pause;

    extern int sound_volume;
    extern int music_volume;

    extern string error[2];
    extern int errorlevel;

    // screen

    extern int x;
    extern int y;
    extern int width;
    extern int height;

    // misc

    extern string data_dir;
    extern SDL_PixelFormat * format;
}

class game_object
{
    public:

    SDL_Surface* sprite;
    SDL_Rect rect;
    std::string type[3];// name , group , controller

    float x;
    float y;
    int z;
    unsigned int self;
    bool visable; // draw ?
    bool solid; // check for collisions ?
    bool remove; // kill it ?
    bool center; // draw sprite centered ?

    game_object()
    {
    }

    virtual void update()
    {
    }


    std::string get_type(int typen)
    {
        if (typen==0)
            return type[0];
        if (typen==1)
            return type[1];
        if (typen==2)
            return type[2];
    }

    SDL_Surface * get_sprite()
    {
        return sprite;
    }

    SDL_Rect get_rect()
    {
        return rect;
    }

};

/// map objects

class tile : public game_object
{
    public:

    tile(float xx,float yy,int zz,unsigned int image_num)
    {
        x=xx;
        y=yy;
        z=zz;

        sprite=drip_get_image(image_num);

        visable=1;
        solid=0;
        remove=0;
        center=0;

        type[0]="tile";
        type[1]="non-solid";
        type[2]="none";

        rect.w=sprite->w;
        rect.h=sprite->h;
        rect.x=x;
        rect.y=y;
    }

    virtual void update()
    {
    }

};

class player : public game_object
{
    public:

    float direction;
    float angle;
    float speed;
    float dspeed;
    int maxspeed;
    int turn;
    float friction;
    float acceleration;
    SDL_Surface * oldsprite;

    player(float xx,float yy,int zz,unsigned int image_num)
    {
        x=xx;
        y=yy;
        z=zz;

        direction=90;

        oldsprite=rotozoomSurface(drip_get_image(image_num),270,1,0); // change image to match with start angle

        angle=direction;
        speed=0;
        dspeed=0;
        maxspeed=2;
        friction=.0075;
        acceleration=.12;
        turn=200;

        visable=1;
        solid=0;
        remove=0;
        center=1;

        type[0]="tile";
        type[1]="non-solid";
        type[2]="none";

        rect.w=sprite->w;
        rect.h=sprite->h;
        rect.x=x;
        rect.y=y;
    }

    virtual void update()
    {
        // move

        //speed=100;

        //dspeed=speed * ( var::delta / 100.f );

        sprite=rotozoomSurface(oldsprite,angle,1,0);

        x+=xlength(direction,speed);
        y+=ylength(direction,speed);

        rect.x=x;
        rect.y=y;

        var::x=x-var::width/2;
        var::y=y-var::height/2;

        if (speed < 1)
           speed-=friction;

        if (speed > 0)
           speed-=friction;

        if (speed < 0)
           speed=0;


        Uint8 *keystate = SDL_GetKeyState(NULL);


        if ( keystate[SDLK_LEFT] )
        {
            angle+=1;
        }

        if ( keystate[SDLK_RIGHT] )
        {
            angle-=1;
        }

        if ( keystate[SDLK_UP] )
        {
            speed+=acceleration;// * ( var::delta / 1000.f );

            if (direction > angle)
                direction-=2;
            else
                direction+=2;

        }

        if ( keystate[SDLK_HOME] )
        {
            x=0;
            y=0;
        }

        if ( keystate[SDLK_END] )
        {
            speed=0;
            direction=0;
            angle=0;
        }

        if (angle > direction+360)
            direction+=360;
        if (angle < direction-360)
            direction-=360;



        if (speed > maxspeed)
            speed=maxspeed;
    }

};


#endif // OBJECTS_H_INCLUDED

Edited 6 Years Ago by wwsoft: n/a

You first included object.h in engine.h; fine. but I don't think you can include engine.h again in object.h, cos inter-inclusions like that are practically impossible.
Let's say [] stands for inclusion,then what you're trying to do is this:

object.h[engine.h [object.h?] ]

You first included object.h in engine.h; fine. but I don't think you can include engine.h again in object.h, cos inter-inclusions like that are practically impossible.
Let's say [] stands for inclusion,then what you're trying to do is this:

object.h[engine.h [object.h?] ]

I move everything to a C file and left declarations in the header and it seems to work ...

Also , I it seems too common that people [that reply] always state the problem and never give solutions to it , frustrating ...
[solution: state the solution to problems you replay to in your posts before you click "post"]

Edited 6 Years Ago by wwsoft: n/a

Also , I it seems too common that people [that reply] always state the problem and never give solutions to it , frustrating ...
[solution: state the solution to problems you replay to in your posts before you click "post"]

It also seems too common that people [that ask Q's] rarely state the real problem and never give enough details to understand it , frustrating ...
[solution: state the problems clearly with details and don't post 400 lines of code when 20 would do. And click PREVIEW so you can verify your problem is clearly stated before you click "SUBMIT"]

Try reading posts to HELP sometime.

EDIT: aren't moderator supposed to friendly even to the whiniest and dumbest of posters ? instead of firing back with a complaint ....

Edited 6 Years Ago by wwsoft: n/a

Why?

generally most forums don't like scaring off new users that generate ad revenue [and I'm assuming your not a volunteer with this reasoning ]

Edited 6 Years Ago by wwsoft: n/a

This question has already been answered. Start a new discussion instead.