Hallo,
I'm doing a simple solar system modelling program with OpenGL, so it's not really a game. However my main goal is to understand better and practice the advanced features of c++ as well as learn to design classes. I wrote code to read in the data about planets from a file and render the planets.
What I need help with is design. It would be great if you could tell me if there's anything wrong with my current design or maybe suggest something better.
Another thing i need help with is error checking. What to do with errors? throw an error? call exit() or what? how do you handle errors in game programming?
here's the .h file:
Code:
#ifndef SOLAR_SYS_H
#define SOLAR_SYS_H

#include <windows.h>
#include <GL\gl.h>
#include <GL\glu.h>

#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <stdexcept>

#include <cmath>
#include <cstdlib>


//Abstract base class
class Shape
{ 
  public:
  virtual void draw() = 0;
  virtual bool create() = 0;
};

//Sphere class, based on Shape
class Sphere : public Shape
{    
  public:
    
  virtual ~Sphere()
  {  
    dlat = dlng = 0;
    r = 0.0;
  
    vert.clear();
    vnum = 0;
  }
  
  //explicit Ctor: radius, points for lattitude, points for longitude
  explicit Sphere(GLfloat rad = 1.0, GLint dl = 42, GLint dg = 84);
  
  //draw the sphere
  void draw();
  
  protected:
  bool create(); //virtual
  
  // gen_sphere: create() wrapper, if change == true, then replace the params given in Ctor
  void gen_sphere(GLfloat, GLint, GLint, bool change = false); 
  
  struct Vertex //coords
  {
    GLfloat z, y, x;
  };
  
  private:
  GLint dlat, dlng; //lattitude & longitude
  GLfloat r; //radius
  
  std::vector<Vertex> vert; //coords vector
  size_t vnum; //should be same as vert.size()
  
  //no copy ctor & op=
  Sphere(const Sphere&);
  Sphere & operator=(const Sphere &);
  
};

//defined later
class Planet_info;

// Planets class holds information about all planets
// of the solar system. Only one instance should be
// created for all planets. This is because Planets
// inherits from Sphere and only one sphere should be
// generated in the program. All planets will reuse this
// one sphere.
class Planets : public Sphere
{
  public:
  Planets(const char *s);
  Planets();
  ~Planets();
  
  void draw(); //replace the virual Sphere::draw()
  
  
  protected:
  std:: istream & add_planet(std::istream &); //add a planet from file
  //void del_planet(const Planet_info &);
  
  size_t planet_num; //number of loaded planets
  
    
  private:
  //no copy ctor & op=
  Planets(const Planets &);
  Planets & operator=(const Planets &);
  
  // a std::list with info about all planets 
  std::list<Planet_info*> planets; 
  
  //TEXTURE support goes here (?) 
};


// friend of Planets, with info such as
// radius, orbit, name and other.
class Planet_info
{
  public:
  friend class Planets;

  Planet_info();
  Planet_info(const Planet_info &);
  
  //op=
  Planet_info & operator=(const Planet_info &);   
  
  //read info from file 
  friend std::istream & operator>>(std::istream &, Planet_info &);
  
  private:
  std::string name;
  GLfloat radius;
  GLfloat orbit;
  GLfloat mass;
  GLfloat spd;
  GLfloat revol; 
  //std::list<Planet_info*> satellites;
  
  GLfloat rot1, rot2; //orbit- and revolution-angles
};


#endif