00001
00002 #include <stdexcept>
00003
00004 #include "Object.h"
00005
00006
00011 Object::Object(bool enablePhysics)
00012 : PhysicalObject(enablePhysics),
00013 mBoundingBox(),
00014 mCastShadows(true),
00015 mRefCounter(NULL),
00016 mName("unnamed_object")
00017 {
00018 mRefCounter = new (unsigned int)(1);
00019 }
00020
00021
00027 Object::Object(const Object & other)
00028 : PhysicalObject(other),
00029 mBoundingBox(other.mBoundingBox),
00030 mCastShadows(other.mCastShadows),
00031 mRefCounter(other.mRefCounter),
00032 mName("copy of " + other.mName)
00033 {
00034 (*mRefCounter)++;
00035 LOG("Making cheap Object copy of \"" << other.mName << "\". Reference counter: "
00036 << mRefCounter << " (" << *mRefCounter << " copies)");
00037 }
00038
00039
00042 Object::~Object()
00043 {
00044 (*mRefCounter)--;
00045 if (*mRefCounter <= 0)
00046 {
00047
00048 delete mRefCounter;
00049 LOG("Removed last copy of object \"" << mName << "\"");
00050 }
00051 else
00052 {
00053 LOG("Removed object \"" << mName << "\" with refcounter " << mRefCounter
00054 << " (" << *mRefCounter << " copies left)");
00055 }
00056 }
00057
00058
00061 void Object::setCastShadows(bool b)
00062 {
00063
00064 mCastShadows = b;
00065 }
00066
00067
00072 void Object::writeDump(std::ostream & outs)
00073 {
00074 outs << mName << '\0';
00075 PhysicalObject::writeDump(outs);
00076 }
00077
00078
00083 void Object::readDump(std::istream & ins)
00084 {
00085 std::string name;
00086 std::getline(ins, name, '\0');
00087 if (name != mName)
00088 {
00089 throw std::logic_error("Found other object name: \"" + name + "\" instead of \"" + mName + "\"");
00090 }
00091 PhysicalObject::readDump(ins);
00092 }
00093
00094