Jump to content
  • Advertisement
Sign in to follow this  
bensmith87

How do I save a scene?

This topic is 3750 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I'm currently working on a game/engine, just for educational sake, and I've come to a hurdle, I want to be able to save and load scenes from a file, I dont care if it is ascii or binary, but as I hope you can see from the scene class below is that the scene has a list of all the meshes, and textures, and a list of "mesh nodes", with each mesh node containing a pointer to a mesh to be rendered, as well as a pointer to the texture to use, and its position and rotation. My main problem is that obviously a dump of a pointer is not going to mean anything when it is reloaded. I've read one of the articles in the enginuity series about data serialization, but it seamed overly complicated, and I was looking at a smaller solution. my scene class...
class Scene
{
public:
    Scene(Mouse *pMouse, Keyboard *pKeyboard);
    
    Mesh *addMesh(const char *pFileName);
    void removeMesh(Mesh *pMesh);
    
    MeshNode *addMeshNode();
    void removeMeshNode(MeshNode *pMeshNode);
    
    Texture *addTexture(const char *pFileName);
    void removeTexture(Texture *pTexture);

    Camera *setCamera(Vector3f pPosition, float pYaw, float pPitch);
    
    void update();
    void beginScene();
    void endScene();
    void render();
    void removeAll();
    
    bool saveScene(const char *pFileName);
    bool loadScene(const char *pFileName);
    
protected:
    Camera mCamera;
    
    std::list<Mesh *> mMesh;
    std::list<MeshNode *> mMeshNode;
    std::list<Texture *> mTexture;
    
    Keyboard *mKeyboard;
    Mouse *mMouse;
};

how I've been creating my scenes so far...
Mesh *mesh = sceneManager->addMesh("data/spaceship.3ds");
Texture *texture = sceneManager->addTexture("data/spaceshiptexture.bmp");

MeshNode *meshNode = sceneManager->addMeshNode();
meshNode->setMesh(mesh);
meshNode->setPosition(Vector3f(-100.0f, 0.0f, 0.0f));
meshNode->setRotation(Vector3f(0.0f, 0.0f, -10.0f));
meshNode->setTexture(texture);

Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • 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!