mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
implement SIMPLE_STRUCT_POINTERS
This commit is contained in:
parent
b24638521a
commit
c82667c148
@ -48,9 +48,15 @@
|
|||||||
// same interface but with minimal runtime overhead.
|
// same interface but with minimal runtime overhead.
|
||||||
// (Actually, this isn't true yet, but it will be one
|
// (Actually, this isn't true yet, but it will be one
|
||||||
// day.)
|
// day.)
|
||||||
|
//
|
||||||
|
// We define this as a struct instead of a class to
|
||||||
|
// guarantee byte placement within the object, so that
|
||||||
|
// (particularly for the trivial implementation) the
|
||||||
|
// inherited struct's data is likely to be placed by the
|
||||||
|
// compiler at the "this" pointer.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
template<class CycleDataType>
|
template<class CycleDataType>
|
||||||
class PipelineCycler : public PipelineCyclerBase {
|
struct PipelineCycler : public PipelineCyclerBase {
|
||||||
public:
|
public:
|
||||||
INLINE PipelineCycler(Pipeline *pipeline = NULL);
|
INLINE PipelineCycler(Pipeline *pipeline = NULL);
|
||||||
INLINE PipelineCycler(const PipelineCycler<CycleDataType> ©);
|
INLINE PipelineCycler(const PipelineCycler<CycleDataType> ©);
|
||||||
|
@ -299,7 +299,11 @@ PipelineCyclerBase(CycleData *initial_data, Pipeline *) {
|
|||||||
// If this turns out not to be true on a particular platform, we
|
// If this turns out not to be true on a particular platform, we
|
||||||
// will have to store the pointer in this class, for a little bit of
|
// will have to store the pointer in this class, for a little bit of
|
||||||
// extra overhead.
|
// extra overhead.
|
||||||
|
#ifdef SIMPLE_STRUCT_POINTERS
|
||||||
nassertv(initial_data == (CycleData *)this);
|
nassertv(initial_data == (CycleData *)this);
|
||||||
|
#else
|
||||||
|
_data = initial_data;
|
||||||
|
#endif // SIMPLE_STRUCT_POINTERS
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -339,7 +343,11 @@ INLINE PipelineCyclerBase::
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE const CycleData *PipelineCyclerBase::
|
INLINE const CycleData *PipelineCyclerBase::
|
||||||
read() const {
|
read() const {
|
||||||
|
#ifdef SIMPLE_STRUCT_POINTERS
|
||||||
return (const CycleData *)this;
|
return (const CycleData *)this;
|
||||||
|
#else
|
||||||
|
return _data;
|
||||||
|
#endif // SIMPLE_STRUCT_POINTERS
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -381,7 +389,11 @@ release_read(const CycleData *) const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE CycleData *PipelineCyclerBase::
|
INLINE CycleData *PipelineCyclerBase::
|
||||||
write() {
|
write() {
|
||||||
|
#ifdef SIMPLE_STRUCT_POINTERS
|
||||||
return (CycleData *)this;
|
return (CycleData *)this;
|
||||||
|
#else
|
||||||
|
return _data;
|
||||||
|
#endif // SIMPLE_STRUCT_POINTERS
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -395,7 +407,11 @@ write() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE CycleData *PipelineCyclerBase::
|
INLINE CycleData *PipelineCyclerBase::
|
||||||
elevate_read(const CycleData *) {
|
elevate_read(const CycleData *) {
|
||||||
|
#ifdef SIMPLE_STRUCT_POINTERS
|
||||||
return (CycleData *)this;
|
return (CycleData *)this;
|
||||||
|
#else
|
||||||
|
return _data;
|
||||||
|
#endif // SIMPLE_STRUCT_POINTERS
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -467,7 +483,11 @@ release_write_stage(int, CycleData *) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
INLINE CycleData *PipelineCyclerBase::
|
INLINE CycleData *PipelineCyclerBase::
|
||||||
cheat() const {
|
cheat() const {
|
||||||
|
#ifdef SIMPLE_STRUCT_POINTERS
|
||||||
return (CycleData *)this;
|
return (CycleData *)this;
|
||||||
|
#else
|
||||||
|
return _data;
|
||||||
|
#endif // SIMPLE_STRUCT_POINTERS
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -29,8 +29,14 @@
|
|||||||
// Class : PipelineCyclerBase
|
// Class : PipelineCyclerBase
|
||||||
// Description : This is the non-template part of the implementation
|
// Description : This is the non-template part of the implementation
|
||||||
// of PipelineCycler. See PipelineCycler.
|
// of PipelineCycler. See PipelineCycler.
|
||||||
|
//
|
||||||
|
// We define this as a struct instead of a class to
|
||||||
|
// guarantee byte placement within the object, so that
|
||||||
|
// (particularly for the trivial implementation) the
|
||||||
|
// inherited struct's data is likely to be placed by the
|
||||||
|
// compiler at the "this" pointer.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class EXPCL_PANDA PipelineCyclerBase {
|
struct EXPCL_PANDA PipelineCyclerBase {
|
||||||
public:
|
public:
|
||||||
INLINE PipelineCyclerBase(CycleData *initial_data, Pipeline *pipeline = NULL);
|
INLINE PipelineCyclerBase(CycleData *initial_data, Pipeline *pipeline = NULL);
|
||||||
INLINE PipelineCyclerBase(const PipelineCyclerBase ©);
|
INLINE PipelineCyclerBase(const PipelineCyclerBase ©);
|
||||||
@ -63,6 +69,16 @@ private:
|
|||||||
PT(CycleData) _data;
|
PT(CycleData) _data;
|
||||||
Pipeline *_pipeline;
|
Pipeline *_pipeline;
|
||||||
short _read_count, _write_count;
|
short _read_count, _write_count;
|
||||||
|
|
||||||
|
#else // !DO_PIPELINING
|
||||||
|
// In a trivial implementation, we only need to store the CycleData
|
||||||
|
// pointer. Actually, we don't even need to do that, if we're lucky
|
||||||
|
// and the compiler doesn't do anything funny with the struct
|
||||||
|
// layout.
|
||||||
|
#ifndef SIMPLE_STRUCT_POINTERS
|
||||||
|
CycleData *_data;
|
||||||
|
#endif // SIMPLE_STRUCT_POINTERS
|
||||||
|
|
||||||
#endif // DO_PIPELINING
|
#endif // DO_PIPELINING
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user