Jump to content
  • Advertisement

Maverick Programmer

Member
  • Content Count

    501
  • Joined

  • Last visited

Community Reputation

100 Neutral

About Maverick Programmer

  • Rank
    Advanced Member
  1. Maverick Programmer

    G++ compiler being weird.

    Quote:Original post by alvaro Why are you compiling header files? Because I thought all the cool kids were doing it. Nah, but it was more convenient to compile them together and then just build the entire exe by doing this: g++ *.o main.cpp -o game_exc Should I not? Quote:Original blah blee blah by Bregma -snippet removed- Hmmm.... What? The Particle class?
  2. Maverick Programmer

    G++ compiler being weird.

    It's just like CrawlerTurrent but rather empty. They both produce the same errors. But anyway: Fighter.cpp #include "Fighter.h" Fighter::Fighter() : Entity(){ } Fighter::Fighter(int x, int y, int w, int h, INPUT_DEVICE input) : Entity(x, y, w, h){ ax = 0.9f; ay = 0.9f; this->input = input; switch(input){ case AUTONOMOUS: affiliation = ENEMY; break; default: affiliation = FRIENDLY; break; } load_animation(IDLE, "data/sprites/fighter/idle.bmp", 8); load_animation(MOVING, "data/sprites/fighter/moving.bmp", 8); load_animation(DEAD, "data/sprites/fighter/dead.bmp", 8); idle.set_state(FORWARD | LOOP); moving.set_state(FORWARD | LOOP); dead.set_state(FORWARD | LOOP); } //_____________________________________________________________________________________ //add an particle to the end of the list void Fighter::push(int x, int y, int w, int h, INPUT_DEVICE input){ entity_list.push_back(new Fighter(x,y,w,h,input)); } void Fighter::update(){ } //_____________________________________________________________________________________ //choose the appropriate animation to render based on the particle's current state void Fighter::render(BITMAP* buffer, int mapxoff, int mapyoff){ Entity::render(buffer, mapxoff, mapyoff); } Fighter.h #ifndef FIGHTER_H #define FIGHTER_H #include "Particle.h" #include "Map.h" #include "Entity.h" #include "Math.h" class Fighter : public Entity{ public: Fighter (); Fighter (int x, int y, int w, int h, INPUT_DEVICE = AUTONOMOUS); static void push (int x, int y, int w, int h, INPUT_DEVICE input = AUTONOMOUS); void update (); void render (BITMAP* buffer, int mapxoff = 0, int mapyoff = 0); private: Entity* target; }; #endif
  3. Maverick Programmer

    G++ compiler being weird.

    Maverick$ g++ -c Entity.cpp // <- seems to compile fine Maverick$ g++ -c Fighter.cpp Entity.h:14: error: multiple definition of ‘enum ENTITY_STATE’ Entity.h:13: error: previous definition here Entity.h:14: error: conflicting declaration ‘IDLE’ Entity.h:14: error: ‘IDLE’ has a previous declaration as ‘ENTITY_STATE IDLE’ Entity.h:14: error: conflicting declaration ‘MOVING’ Entity.h:15: error: ‘MOVING’ has a previous declaration as ‘ENTITY_STATE MOVING’ Entity.h:14: error: conflicting declaration ‘DEAD’ Entity.h:16: error: ‘DEAD’ has a previous declaration as ‘ENTITY_STATE DEAD’ Entity.h:16: error: multiple definition of ‘enum INPUT_DEVICE’ Entity.h:18: error: previous definition here Entity.h:16: error: conflicting declaration ‘AUTONOMOUS’ Entity.h:19: error: ‘AUTONOMOUS’ has a previous declaration as ‘INPUT_DEVICE AUTONOMOUS’ Entity.h:16: error: conflicting declaration ‘KEYBOARD’ Entity.h:20: error: ‘KEYBOARD’ has a previous declaration as ‘INPUT_DEVICE KEYBOARD’ Entity.h:16: error: conflicting declaration ‘JOY0’ Entity.h:21: error: ‘JOY0’ has a previous declaration as ‘INPUT_DEVICE JOY0’ Entity.h:16: error: conflicting declaration ‘JOY1’ Entity.h:22: error: ‘JOY1’ has a previous declaration as ‘INPUT_DEVICE JOY1’ Entity.h:16: error: conflicting declaration ‘JOY2’ Entity.h:23: error: ‘JOY2’ has a previous declaration as ‘INPUT_DEVICE JOY2’ Entity.h:16: error: conflicting declaration ‘JOY3’ Entity.h:24: error: ‘JOY3’ has a previous declaration as ‘INPUT_DEVICE JOY3’ Entity.h:18: error: multiple definition of ‘enum AFFILIATION’ Entity.h:26: error: previous definition here Entity.h:18: error: conflicting declaration ‘NEUTRAL’ Entity.h:27: error: ‘NEUTRAL’ has a previous declaration as ‘AFFILIATION NEUTRAL’ Entity.h:18: error: conflicting declaration ‘FRIENDLY’ Entity.h:28: error: ‘FRIENDLY’ has a previous declaration as ‘AFFILIATION FRIENDLY’ Entity.h:18: error: conflicting declaration ‘ENEMY’ Entity.h:29: error: ‘ENEMY’ has a previous declaration as ‘AFFILIATION ENEMY’ Entity.h:20: error: redefinition of ‘class Entity’ Entity.h:32: error: previous definition of ‘class Entity’ So long story short, she still yells at me and tells me I'll never be anything like Dave.
  4. Maverick Programmer

    G++ compiler being weird.

    I have before but here it goes: When compiling: g++ -c Entity.cpp Entity.h g++ -c Fighter.cpp Fighter.h When examining the .ii file: g++ -c -save-temps Fighter.cpp Fighter.h
  5. Maverick Programmer

    G++ compiler being weird.

    Quote:Original post by Bregma Quote:Original post by Maverick Programmer I followed Bregma's advice and turned up something interesting. What SiCrane said. Compile with -save-temps and examine the .ii file. What I tell you three times is true. Mkay. # 1 "CrawlerTurret.h" # 1 "<built-in>" # 1 "<command line>" # 1 "CrawlerTurret.h" #pragma GCC pch_preprocess "Particle.h.gch" # 1 "Map.h" 1 # 1 "Define.h" 1 # 5 "Map.h" 2 # 1 "Entity.h" 1 # 1 "/usr/include/c++/4.0.0/list" 1 3 # 5 "Entity.h" 2 # 1 "Animation.h" 1 # 6 "Entity.h" 2 # 1 "/usr/include/stdio.h" 1 3 4 # 7 "Entity.h" 2 # 1 "/usr/include/math.h" 1 3 4 # 8 "Entity.h" 2 # 1 "Math.h" 1 class Math{ public: Math(); static int min(int a, int b); static float min(float a, float b); static int max(int a, int b); static float max(float a, float b); static float dist(int a, int b, int a2, int b2); }; # 9 "Entity.h" 2 using namespace std; enum ENTITY_STATE { IDLE, MOVING, DEAD }; enum INPUT_DEVICE { AUTONOMOUS, KEYBOARD, JOY0, JOY1, JOY2, JOY3 }; enum AFFILIATION { NEUTRAL, FRIENDLY, ENEMY }; class Entity{ public: Entity (); Entity (int col_x, int col_y, int col_w, int col_h); public: static list<Entity*> entity_list; int x, y, w, h; int bx, by, bw, bh; float vx, vy; float ax, ay; int life; int damage; ENTITY_STATE state; INPUT_DEVICE input; AFFILIATION affiliation; Animation idle; Animation moving; Animation dead; bool inside (int x,int y,int left,int top,int right,int bottom); bool use_collision_correction; bool colliding; public: static void push (int x, int y, int w, int h); static void delete_dead_entities (); virtual void update (); virtual void render (BITMAP* buffer, int mapxoff = 0, int mapyoff = 0); void load_animation (ENTITY_STATE animation, char* path, int frames); Animation *get_animation (ENTITY_STATE); bool detect_collision (Entity* b); static Entity* get_entity (int number); static int get_count (); void apply_force (float x = 0, float y = 0); void move_to (int x = 0, int y = 0); void move (); void collision_correction (bool on_off = true); int get_x (); int get_y (); int get_w (); int get_h (); float get_vx (); float get_vy (); void set_life (int life); int get_life (); int get_damage (); int get_affiliation (); int collided_tl(int x, int y); int get_user_data(int x, int y, int u); }; # 6 "Map.h" 2 class Map{ public: Map(); static bool load (char* path); static bool load (int map_number); static void update(Entity* target); static void render(BITMAP* buffer); static int get_x(); static int get_y(); static int get_w(); static int get_h(); static void set_xoffset(int x); static void set_yoffset(int y); static void destroy(); private: static int mapxoff; static int mapyoff; static BITMAP* background; static int bgx; static int bgy; }; # 6 "CrawlerTurret.h" 2 class CrawlerTurret : public Entity{ public: enum facing_enum {NONE, LEFT, RIGHT, UP, DOWN}; CrawlerTurret (); CrawlerTurret (int x, int y, int w, int h, INPUT_DEVICE = AUTONOMOUS); static void push (int x, int y, int w, int h, INPUT_DEVICE input = AUTONOMOUS); void update (); void render (BITMAP* buffer, int mapxoff = 0, int mapyoff = 0); void crawlerAI (); private: Entity* target; facing_enum facing; facing_enum lastContact; int lastx, lasty; int bufferedVelx, bufferedVely; }; Going to be honest here. I am hella confused.
  6. Maverick Programmer

    G++ compiler being weird.

    I followed Bregma's advice and turned up something interesting. By renaming the #define _ENTITY_ and naming it INCLUDE_ENTITY_H this happens: First. Entity.cpp and Entity.h compile fine. BUT- when I compile a file that DERIVES from the Entity class- THIS happens: Maverick$ g++ -c Entity.cpp Entity.h //Side note. This compiles fine Maverick$ g++ -c Fighter.cpp Fighter.h //Side note. This is an empty class that derives from Entity Entity.h:14: error: multiple definition of ‘enum ENTITY_STATE’ Entity.h:13: error: previous definition here Entity.h:14: error: conflicting declaration ‘IDLE’ Entity.h:14: error: ‘IDLE’ has a previous declaration as ‘ENTITY_STATE IDLE’ Entity.h:14: error: conflicting declaration ‘MOVING’ Entity.h:15: error: ‘MOVING’ has a previous declaration as ‘ENTITY_STATE MOVING’ Entity.h:14: error: conflicting declaration ‘DEAD’ Entity.h:16: error: ‘DEAD’ has a previous declaration as ‘ENTITY_STATE DEAD’ Entity.h:16: error: multiple definition of ‘enum INPUT_DEVICE’ Entity.h:18: error: previous definition here Entity.h:16: error: conflicting declaration ‘AUTONOMOUS’ Entity.h:19: error: ‘AUTONOMOUS’ has a previous declaration as ‘INPUT_DEVICE AUTONOMOUS’ Entity.h:16: error: conflicting declaration ‘KEYBOARD’ Entity.h:20: error: ‘KEYBOARD’ has a previous declaration as ‘INPUT_DEVICE KEYBOARD’ Entity.h:16: error: conflicting declaration ‘JOY0’ Entity.h:21: error: ‘JOY0’ has a previous declaration as ‘INPUT_DEVICE JOY0’ Entity.h:16: error: conflicting declaration ‘JOY1’ Entity.h:22: error: ‘JOY1’ has a previous declaration as ‘INPUT_DEVICE JOY1’ Entity.h:16: error: conflicting declaration ‘JOY2’ Entity.h:23: error: ‘JOY2’ has a previous declaration as ‘INPUT_DEVICE JOY2’ Entity.h:16: error: conflicting declaration ‘JOY3’ Entity.h:24: error: ‘JOY3’ has a previous declaration as ‘INPUT_DEVICE JOY3’ Entity.h:18: error: multiple definition of ‘enum AFFILIATION’ Entity.h:26: error: previous definition here Entity.h:18: error: conflicting declaration ‘NEUTRAL’ Entity.h:27: error: ‘NEUTRAL’ has a previous declaration as ‘AFFILIATION NEUTRAL’ Entity.h:18: error: conflicting declaration ‘FRIENDLY’ Entity.h:28: error: ‘FRIENDLY’ has a previous declaration as ‘AFFILIATION FRIENDLY’ Entity.h:18: error: conflicting declaration ‘ENEMY’ Entity.h:29: error: ‘ENEMY’ has a previous declaration as ‘AFFILIATION ENEMY’ Entity.h:20: error: redefinition of ‘class Entity’ Entity.h:32: error: previous definition of ‘class Entity’ And just for you who need the Entity.h again and don't want to scroll to the top: #ifndef INCLUDE_ENTITY_H #define INCLUDE_ENTITY_H #include <list> #include "Animation.h" #include <stdio.h> #include <math.h> #include "Math.h" using namespace std; //entity state will dictate parameters for how an entity should //react, animate and move enum ENTITY_STATE{ IDLE = 0, MOVING, DEAD, }; enum INPUT_DEVICE{ AUTONOMOUS = 0, KEYBOARD, JOY0, JOY1, JOY2, JOY3 }; enum AFFILIATION{ NEUTRAL = 0, FRIENDLY, ENEMY }; class Entity{ public: Entity (); Entity (int col_x, int col_y, int col_w, int col_h); public://temporarily public for debug printing static list<Entity*> entity_list; int x, y, w, h; //entity source x,y,w,h int bx, by, bw, bh; //bitmap source x,y,w,h float vx, vy; //velocity x,y float ax, ay; //acceleration x,y int life; //if (life < 1) entity = dead; delete; int damage; //b.life -= a.damage when colliding ENTITY_STATE state; INPUT_DEVICE input; //AI or keyboard/joystick controlled AFFILIATION affiliation; Animation idle; //the run animation Animation moving; //other example animations Animation dead; bool inside (int x,int y,int left,int top,int right,int bottom); bool use_collision_correction; bool colliding; public: static void push (int x, int y, int w, int h); static void delete_dead_entities (); virtual void update (); virtual void render (BITMAP* buffer, int mapxoff = 0, int mapyoff = 0); void load_animation (ENTITY_STATE animation, char* path, int frames); Animation *get_animation (ENTITY_STATE); bool detect_collision (Entity* b); static Entity* get_entity (int number); static int get_count (); void apply_force (float x = 0, float y = 0); void move_to (int x = 0, int y = 0); void move (); void collision_correction (bool on_off = true); int get_x (); int get_y (); int get_w (); int get_h (); float get_vx (); float get_vy (); void set_life (int life); int get_life (); int get_damage (); int get_affiliation (); //level collision routines int collided_tl(int x, int y); int get_user_data(int x, int y, int u); }; #endif No other changes were made.
  7. Maverick Programmer

    G++ compiler being weird.

    Hrmm. Well, I removed the Entity:: part and got a new error. CrawlerTurret.cpp:41: error: ‘collision_correction’ was not declared in this scope So instead of it not being a member, it's not in the scope.
  8. Maverick Programmer

    G++ compiler being weird.

    So no real advice then?
  9. Maverick Programmer

    G++ compiler being weird.

    Right, but other things like Entity::update() work fine. And I sent the exact code to another coder and it compiles fine with Dev-C++. I'm trying to get experience by staying away from IDEs. EDIT: And this-> doesn't work.
  10. Maverick Programmer

    G++ compiler being weird.

    I have a parent class called Entity and another class named CrawlerTurret which derives from the parent class Entity. When I go to compile and get the object file of the files, however, g++ informs me that there is a member function in there that is not of class Entity. Here's some code and what I'm typing in: CrawlerTurret.h - FULL #ifndef CRAWLERTURRET_H #define CRAWLERTURRET_H #include "Particle.h" #include "Map.h" #include "Entity.h" #include "Math.h" class CrawlerTurret : public Entity{ public: enum facing_enum {NONE, LEFT, RIGHT, UP, DOWN}; CrawlerTurret (); CrawlerTurret (int x, int y, int w, int h, INPUT_DEVICE = AUTONOMOUS); static void push (int x, int y, int w, int h, INPUT_DEVICE input = AUTONOMOUS); void update (); void render (BITMAP* buffer, int mapxoff = 0, int mapyoff = 0); void crawlerAI (); private: Entity* target; facing_enum facing; facing_enum lastContact; int lastx, lasty; int bufferedVelx, bufferedVely; }; #endif CrawlerTurret - SNIPPET void CrawlerTurret::update(){ Entity::collision_correction(true); // <- This is causing problamos Entity::update(); int px = 5.0f + fabs(vx); int py = 5.0f + fabs(vy); int d = 0; //shooting distance as not to collide with shooting entity int pw = 5; //particle width int ph = 5; //particle height ... Entity.h - FULL #ifndef _ENTITY_ #define _ENTITY_ #include <list> #include "Animation.h" #include <stdio.h> #include <math.h> #include "Math.h" using namespace std; //entity state will dictate parameters for how an entity should //react, animate and move enum ENTITY_STATE{ IDLE = 0, MOVING, DEAD, }; enum INPUT_DEVICE{ AUTONOMOUS = 0, KEYBOARD, JOY0, JOY1, JOY2, JOY3 }; enum AFFILIATION{ NEUTRAL = 0, FRIENDLY, ENEMY }; class Entity{ public: Entity (); Entity (int col_x, int col_y, int col_w, int col_h); public://temporarily public for debug printing static list<Entity*> entity_list; int x, y, w, h; //entity source x,y,w,h int bx, by, bw, bh; //bitmap source x,y,w,h float vx, vy; //velocity x,y float ax, ay; //acceleration x,y int life; //if (life < 1) entity = dead; delete; int damage; //b.life -= a.damage when colliding ENTITY_STATE state; INPUT_DEVICE input; //AI or keyboard/joystick controlled AFFILIATION affiliation; Animation idle; //the run animation Animation moving; //other example animations Animation dead; bool inside (int x,int y,int left,int top,int right,int bottom); bool use_collision_correction; bool colliding; public: static void push (int x, int y, int w, int h); static void delete_dead_entities (); virtual void update (); virtual void render (BITMAP* buffer, int mapxoff = 0, int mapyoff = 0); void load_animation (ENTITY_STATE animation, char* path, int frames); Animation *get_animation (ENTITY_STATE); bool detect_collision (Entity* b); static Entity* get_entity (int number); static int get_count (); void apply_force (float x = 0, float y = 0); void move_to (int x = 0, int y = 0); void move (); void collision_correction (bool on_off = true); int get_x (); int get_y (); int get_w (); int get_h (); float get_vx (); float get_vy (); void set_life (int life); int get_life (); int get_damage (); int get_affiliation (); //level collision routines int collided_tl(int x, int y); int get_user_data(int x, int y, int u); }; #endif // _ENTITY_ Entity.cpp - SNIPPET ... void Entity::collision_correction(bool on_off) { use_collision_correction = on_off; } ... In Terminal: g++ -c Entity.cpp Entity.h g++ -c CrawlerTurret.cpp CrawlerTurret.h -- Error in CrawlerTurret.cpp in update function: collision_correction is not a member of Entity ... But update and everything else in there is fine??
  11. Maverick Programmer

    List iterator not decrementable (C++)

    For those of you who stumble upon this topic. Std::list is not what you need. I had to change it to std::vector. Lists do not allow random element access (like *(current+1) ) but vectors do. :)
  12. Maverick Programmer

    List iterator not decrementable (C++)

    Wow. Holy crap. I knew I was over complicating things but I didn't realize I could shrink it down by that much. I really need to get better at using iterators. >_> Thanks a bunch. I've definitely learned a lot from this little thing!
  13. Maverick Programmer

    List iterator not decrementable (C++)

    Yeah, I should be iMalc. You are right. I think I read somewhere that list in Xcode my be circular whereas MSVC is only linear. Thanks for the tips guys. Especially you visitor. You're right on the implementation. I don't know what I was thinking. I know better to use ::find. I may have been rushing.
  14. Ugh. Ok. So this code worked fine in Xcode for Mac. I port this thing over to Windows and MSVC 8 decided he didn't like it. So, I'm having iterator problems. I know WHAT is causing the problems. I just don't know a better way to re-write this! setActiveLevel(const std::string level) { bool exists = false; std::map<std::string, boost::shared_ptr<LevelManager> >::iterator i; std::list<std::string>::iterator j; std::list<std::string>::reverse_iterator k; for(i = mManagers.begin(); i != mManagers.end(); ++i) { if(i->first == level && !levelNames.empty()) { exists = true; for(j = levelNames.begin(); j != levelNames.end(); ++j) { std::cout << (*j) << std::endl; if((*j) == level) { if(++j != levelNames.end()) { nextLevel = (*j); } } } //Now find the previous level for(k = levelNames.rbegin();k != levelNames.rend(); ++k) { if((*k) == level) { if(++k != levelNames.rend()) { previousLevel = (*k); } } } break; } } if(!exists) { std::cout << "Error setting the active level! Name does not exist!\n"; } lastVisitedLevel = activeLevel; activeLevel = level; std::cout << "nextLevel: " << nextLevel << std::endl; std::cout << "previousLevel: " << previousLevel << std::endl; std::cout << "lastVisitedLevel: " << lastVisitedLevel << std::endl; std::cout << "activeLevel: " << activeLevel << std::endl; } The goal of this code, is when I set the level (by name. i.e. "Level1") it finds stores the other two variables, nextLevel and previousLevel. So if I can't increment or decrement passed my current iteration without getting that error from MSVC, how else can I do this? Thanks for the help in advanced, guys. :)
  15. Maverick Programmer

    You know you've been playing too many video games when...

    Quote: Also, in addition to the usual game-related stories, I once tried to copy paste text from a sheet of paper. :( We've all done this at least once. What's bad is when you have to look down to see why it's not working. XD
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!