Use shared_ptr for Scene::mCamera
Makes memory management a bit easier...
This commit is contained in:
parent
c564791d1a
commit
c65c6a3cfd
3 changed files with 16 additions and 8 deletions
|
@ -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();
|
||||
|
|
15
src/scene.cc
15
src/scene.cc
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue