Use shared_ptr for Scene::mCamera

Makes memory management a bit easier...
This commit is contained in:
Eryn Wells 2014-07-20 12:37:31 -07:00
parent c564791d1a
commit c65c6a3cfd
3 changed files with 16 additions and 8 deletions

View file

@ -10,11 +10,15 @@
#ifndef __CAMERA_H__
#define __CAMERA_H__
#include <memory>
#include "basics.h"
struct Camera
{
typedef std::shared_ptr<Camera> Ptr;
Camera();
Camera(const Camera& other);
virtual ~Camera();

View file

@ -31,10 +31,7 @@ Scene::Scene()
Scene::~Scene()
{
if (mCamera) {
delete mCamera;
mCamera = NULL;
}
mCamera.reset();
if (ambient != NULL) {
delete ambient;
@ -81,7 +78,10 @@ Scene::get_height()
}
Camera*
/*
* Scene::GetCamera --
*/
Camera::Ptr
Scene::GetCamera()
const
{
@ -89,10 +89,13 @@ Scene::GetCamera()
}
/*
* Scene::SetCamera --
*/
void
Scene::SetCamera(Camera* camera)
{
mCamera = camera;
mCamera.reset(camera);
}

View file

@ -36,8 +36,9 @@ public:
int get_height() const;
void set_height(int h) { height = h; }
Camera* GetCamera() const;
Camera::Ptr GetCamera() const;
void SetCamera(Camera* camera);
void SetCamera(Camera::Ptr camera);
AmbientLight &get_ambient() const;
const Color *get_pixels() const;
@ -55,7 +56,7 @@ private:
// Pixel dimensions of the image.
int width, height;
Camera *mCamera;
Camera::Ptr mCamera;
/*
* Ray tracing parameters. max_depth indicates the maximum depth of the ray tree. min_weight indicates the minimum