Revision 17

Date:
2008/12/14 10:46:25
Author:
moose
Revision Log:
update svn
Files:

Legend:

 
Added
 
Removed
 
Modified
  • trunk/data_test2.cpp

     
    12 12 friend class Item;
    13 13
    14 14 public:
    15 static const uint32_t ITEM_SIZE;
    16
    15 17 class Item {
    16 18 friend class Data;
    17 19
    18 20 public:
    19 Type operator[]( uint32_t idx ) { return ( (data && idx >= 0 && idx < Count ) ? data[idx] : (double)0xFF ); }
    21 Type operator[]( uint32_t idx ) { /*log("this: %p", this);*/ return ( (data && idx < Count ) ? data[idx] : (Type)0xDE ); }
    20 22
    21 23 // protected:
    22 24 Item( Type *d ) : data(d) { }
     
    28 30
    29 31 Data() : item_count(0), data_used(0), data_size(0), _data(0) { }
    30 32 virtual ~Data() { if(_data) free(_data); _data=0; }
    31 virtual Item operator[]( uint32_t idx ) { return ( idx >= 0 && idx < item_count) ? Item( & _data[ idx * Count ] ) : Item( 0 ); }
    33 virtual Item operator[]( uint32_t idx ) { /*log("idx:%i, pos:%i", idx, (idx)*Count);*/ return (idx < item_count) ? Item( & (_data[ (idx) * Count ]) ) : Item( (Type *)0xDECAFBAD ); }
    32 34
    33 35 uint32_t itemComponents() { return Count; }
    34 36 uint32_t itemCount() { return item_count; }
    35 37 Type *data() { return _data; }
    36 38
    37 bool addData( Type *dat[Count], uint32_t items )
    39 bool addData( Type dat[][Count], uint32_t items )
    38 40 {
    39 uint32_t oic = item_count;
    40 41 if(!resize_data(items))
    41 42 return false;
    42 43
    43 Type *ptr = & (_data[ oic ]);
    44 uint32_t len = items * Count * sizeof( Type );
    45 log("items=%i, data=%p, ptr=%p, data+data_size=%p, len=%i, %i", items, _data, ptr, _data+data_size, len, ptr < _data+data_size && ptr >= _data);
    46 memcpy(ptr, dat, len);
    44 //log("data_used: %i :: %p", data_used, &(_data[data_used]));
    47 45
    48 return true;
    46 for(uint32_t i = 0, k = 0; i < items; ++i) {
    47 for(uint32_t j = 0; j < Count; ++j) {
    48 // log("dat[%i][%i]: %f (%f)", i, j, dat[i][j], _data[Count * item_count + k]);
    49 _data[Count * item_count + k] = dat[i][j];
    50 ++k;
    51 }
    52 }
    53
    54 item_count += items;
    55 data_used += sizeof(Type) * Count * items;
    56 return true;
    49 57 }
    50 58
    59 void dump_data()
    60 {
    61 for(int i = 0, k = 0; i < item_count; ++i) {
    62 for(int j = 0; j < Count; ++j) {
    63 printf("%f, ", _data[k]);
    64 ++k;
    65 }
    66 printf("\n");
    67 }
    68 }
    69
    51 70 protected:
    52 71 inline uint32_t npot( uint32_t x, bool n = false )
    53 72 {
     
    73 92 if( size_npot+data_used >= data_size ) {
    74 93 // tmp everything so if the alloc does fail, we don't loose the old data.
    75 94
    76 uint32_t tmp_data_size = npot( data_size + size_npot );
    95 uint32_t tmp_data_size = npot( data_size + items_size );
    77 96
    78 97 Type *tmp_data = (Type *)realloc( _data, tmp_data_size );
    79 98 if(!tmp_data) {
     
    81 100 return false;
    82 101 }
    83 102
    84 log("ptr: %p, old size: %u, new size: %u, old used size: %u, new used size: %u", tmp_data, data_size, tmp_data_size, data_used, data_used + items_size);
    103 //log("ptr: %p, old size: %u, new size: %u, old used size: %u, new used size: %u", tmp_data, data_size, tmp_data_size, data_used, data_used + items_size);
    85 104 _data = tmp_data;
    105
    106 for(int i = 0; i < items * Count; ++i)
    107 memset(&_data[Count * item_count + i], 0xDECAFBAD, sizeof(Type));
    108
    86 109 data_size = tmp_data_size;
    87 data_used += items_size;
    88 item_count += items;
    110 //data_used += items_size;
    111 //item_count += items;
    89 112 }
    90 113
    91 114 return true;
     
    98 121
    99 122 };
    100 123
    124 template< typename Type, int Count >
    125 const uint32_t Data<Type, Count>::ITEM_SIZE = sizeof(Type) * Count;
    126
    101 127 typedef Data< double, 3 > VertexData;
    102 128
    103 129 int main(int argc, char **argv)
     
    105 131 VertexData data;
    106 132 double dat[][3] = {
    107 133 { 0, 0 ,0 },
    108 { 1, 1, 1 },
    109 { 2, 2, 2 },
    110 { 3, 3, 3 },
    111 { 4, 4, 4 },
    134 { 1.111111, 1.111111, 1.111111 },
    135 { 2.222222, 2.222222, 2.222222 },
    136 { 3.333333, 3.333333, 3.333333 },
    137 { 4.444444, 4.444444, 4.444444 },
    112 138 };
    113 139
    114 log("data size: %i, data items: %i", sizeof( dat ), sizeof( dat ) / sizeof ( double ) / 3);
    115 data.addData((double **)dat, sizeof( dat ) / sizeof ( double ) / 3);
    116 data.addData(
    140 //log("data size: %i, data items: %i", sizeof( dat ), sizeof( dat ) / sizeof ( double ) / 3);
    141 data.addData(dat, sizeof( dat ) / sizeof ( double ) / 3);
    142 //data.dump_data();
    117 143
    118 for(uint32_t i = 0; i < sizeof( dat ) / sizeof ( double ) / 3; ++i) {
    144 data.addData(dat, sizeof( dat ) / sizeof ( double ) / 3);
    145 //data.dump_data();
    146
    147 data.addData(dat, sizeof( dat ) / sizeof ( double ) / 3);
    148 data.dump_data();
    149
    150 data.addData(dat, sizeof( dat ) / sizeof ( double ) / 3);
    151 data.dump_data();
    152
    153 data.addData(dat, sizeof( dat ) / sizeof ( double ) / 3);
    154
    155 //log("...");
    156 for(uint32_t i = 0; i < data.itemCount(); ++i) {
    119 157 log("data[%i] = { %f, %f, %f }", i, data[i][0], data[i][1], data[i][2]);
    120 158 }
    121 159
    160 data.dump_data();
    161
    122 162 return 0;
    123 163 }
  • trunk/data_test3.cpp

     
    7 7 fprintf(stderr, "%i:%s:%s: %s\n", __LINE__, __FUNCTION__, __FILE__, __tmp__); \
    8 8 } while(0)
    9 9
    10 /*
    11 Engine has DataStore
    12 Engine has DataInterface
    13
    14 Ok, thinking about template meta programming here, somehow allow you to create N types,
    15 maybe using an enum or something, possibly based on this:
    16 http://www.cs.ualberta.ca/~graphics/software/boost/libs/mpl/doc/paper/html/intro.html#intro.cxx.seq
    17 ie:
    18
    19 typedef uint32_t I3[3];
    20 typedef uint32_t I4[4];
    21
    22 typedef double D3[3];
    23 typedef double D4[4];
    24
    25 template< typename First, typename Rest >
    26 struct cons
    27 {
    28 typedef First first;
    29 typedef Rest rest;
    30 };
    31
    32 struct nil {};
    33
    34 typedef
    35 cons<I3
    36 , cons<I4
    37 , cons<D3
    38 , cons<D4
    39 , nil
    40 > > > > my_types;
    41
    42 DataStore<double, 3> VectorData;
    43 DataStore<double, 3> ColorData;
    44
    45
    46 // Or something like:
    47
    48 typedef uint32_t I3[3];
    49 typedef uint32_t I4[4];
    50
    51 typedef double D3[3];
    52 typedef double D4[4];
    53
    54 struct types {
    55 union {
    56 I3 i3;
    57 I4 i4;
    58 D3 d3;
    59 D4 d4;
    60 };
    61 };
    62 */
    63
    64 // growable data type
    65 template < typename T, int N >
    66 class DataStore {
    67 public:
    68
    69 struct Type {
    70 Type() { for(int i=0; i<N; ++i) t[i] = (T)0; }
    71 Type( T *d ) { for(int i=0; i<N; ++i) t[i] = d[i]; }
    72 Type( T &d ) : t(d) { }
    73 void operator=( T d[N] ) { t = d; }
    74 T operator[]( int n ) { return t[n]; }
    75 T t[N];
    76 };
    77
    78 DataStore( Type &t );
    79 Type operator[]( int n ) { return Type( data + ( n * N ) ); }
    80
    81 private:
    82 T *data;
    83 };
    84
    85 // OR
    86
    87 template < typename T >
    88 class DataStore {
    89 public:
    90 enum { ItemCount = sizeof( T ) / sizeof ( typename( T ) ) };
    91 typedef typename T ItemType;
    92
    93 struct Type {
    94 Type() { for(int i=0; i<ItemCount; ++i) t[i] = (T)0; }
    95 Type( ItemType *d ) { for(int i=0; i<ItemCount; ++i) t[i] = d[i]; }
    96 Type( ItemType &d ) : t(d) { }
    97 void operator=( ItemType d[N] ) { t = d; }
    98 ItemType operator[]( int n ) { return t[n]; }
    99 ItemType t[N];
    100 };
    101
    102 DataStore( T &t );
    103 Type operator[]( int n ) { return Type( data + ( n * N ) ); }
    104
    105 private:
    106 ItemType *data;
    107 };
    108
    109 template < typename T, int M >
    110 class DataInterface {
    111 public:
    112
    113 template < typename S, int N >
    114 int addStore( ) { int new_id; b[new_id] = new DataBuffer<S,N>; return new_id; }
    115 // int my_store = foo->addStore< double, 3 >();
    116 // OR
    117 // int my_store = foo->addStore< double[3] >();
    118
    119 private:
    120 DataBuffer< T, M > *b;
    121 // OR
    122 DataBuffer< T[M] > *b;
    123 };
    124
    125 DataStore< double
    126
    127 !!!!!!!!! NONE OF THIS IS WHAT I'M LOOKING FOR !!!!!!!!! >:E
    128
    10 129 class DataInterface { .. }
    130
    11 131 class DataStore { ... }
    12 132
    13 133 int main(int argc, char **argv)
  • trunk/default.cbd

     
    10 10 compile data_test2.cpp
    11 11 linkexec data_test2
    12 12
    13 compile dynamo_template_test.cpp
    13 #compile data_test4.cpp
    14 #linkexec data_test4
    14 15
    15 linkexec dynamo_template_test
    16 #compile dynamo_template_test.cpp
    17 #linkexec dynamo_template_test
  • trunk/include/Render.h

     
    12 12
    13 13 /*
    14 14
    15 MVC:
    16 Model: Context
    17 View: Engine
    18 Delegate: ViewDelegate
    15 19
    16 */
    20 -------------------
    17 21
    18 BEGIN_NS(Render)
    22 MainView
    23 MiniMapView
    19 24
    20 class Context;
    21 class Engine;
    22 class ObjectFactory;
    23 class ContextFactory;
    24 class EngineFactory;
    25 ALL objects should use implicit sharing via the ptr/dptr scheme as Qt does.
    25 26
    26 struct ObjectData { } __attribute__((packed));
    27 Model View Controller
    28 =====================
    27 29
    28 class Object : public Dynamo::Object::Interface {
    29 public:
    30 typedef ObjectFactory Factory;
    31 typedef ObjectData Data;
    30 Model: stores all the data, needs to have PersistentIndex's
    31 View: displays said data, with help of the controller
    32 Delegate: Handles input, and specialized rendering
    32 33
    33 Object() : ctx(0) { log("new Render::Object"); }
    34 virtual ~Object() { log("~"); }
    35 34
    36 virtual const char *name() = 0;
    37 virtual const char *desc() = 0;
    35 Game Objects:
    36 =============
    38 37
    39 virtual void setRenderContext( Context *c ) { ctx = c; }
    40 virtual Context *renderContext() { return ctx; }
    41 38
    42 39
    43 protected:
    44 Context *ctx;
    45 Data *data;
    46 };
    40 Engine Program Flow:
    41 ====================
    47 42
    48 class Context : public Dynamo::Object::Interface {
    49 public:
    50 typedef ContextFactory Factory;
    43 Much like Qt, it'll all be handled via events, there will be no user controlled main loop.
    51 44
    52 Context() : engine(0) { log("new Render::Context"); }
    53 virtual ~Context() { log("~"); }
    54 45
    55 virtual const char *name() = 0;
    56 virtual const char *desc() = 0;
    57 46
    58 virtual void setRenderEngine( Engine * e ) { engine = e; }
    59 virtual Engine *renderEngine() { return engine; }
    60 47
    61 virtual void addObject( Object * ) = 0;
    62 virtual Data *objectData( Object * ) = 0;
    63 48
    49 DataModel
    50 TerainDataModel
    64 51
    65 // one option, generic virtual data class:
    66 template< typename Type >
    67 class Data : public Dynamo::Object::Interface {
    68 friend class Item;
    69 public:
    70 class Item {
    71 friend class Data;
    72 public:
    73 52
    74 protected:
    75 Item( Type
    76 };
    77 53
    78 Data( ) { }
    79 virtual ~Data() { }
    80 54
    81 virtual const char *name() = 0;
    82 virtual const char *desc() = 0;
    83 55
    84 virtual uint32_t id() = 0;
    85 virtual uint32_t type() = 0;
    56 Need to figure out if drawing a viewport sized FBO over the main viewport will overwrite it,
    57 ie, if the HUD should be screen sized?
    86 58
    87 virtual uint32_t componentSize() = 0;
    88 virtual uint32_t componentCount() = 0;
    59 Main GL rendering should utilize Frame Buffer Objects, Vertex Buffer Objects and Vertex Arrays
    89 60
    90 virtual uint32_t itemSize() = 0;
    91 virtual uint32_t itemCount() = 0;
    61 Try and test if a single FBO->tex render can handle a broken mirror surrface without looking weird,
    62 and compare against a single pass stencil buffer render pass
    92 63
    93 virtual Type operator[](
    64 FBO reflection rendering could use a single view sized render buffer, which gets reused for each object..
    94 65
    95 private:
    96 Type *data;
    97 };
    98 66
    99 // one option, generic data block class:
    100 class Data {
    101 public:
    102 Data( uint32_t id, uint32_t ut, uint32_t cs, uint32_t nc, uint32_t def_size = 64 ) : component_size(cs), num_components(nc), data_items(def_size) { }
    67 //--- new plan ----
    103 68
    104 void *operator ()( uint32_t idx ) { ... }
    69 Dynamo::Scene
    70 enum SceneLayer {
    71 Background,
    72 Item,
    73 Foreground,
    74 };
    75 class Scene {
    76 public:
    77 SceneItem *addItem(
    105 78
    106 protected:
    107 void data_resize( uint32_t num ) { ... }
    79 sceneItemData
    80 };
    108 81
    109 private:
    110 uint32_t user_id; // user specified id, like a vbo id
    111 uint32_t user_type; // user specified type, in gl, this may be GL_DOUBLE or something
    82 // BitArray can be used to keep track of which DataStoreItems are inuse in the DataStore,
    83 // could make the DataStore allocator easier to handle.
    84 class SceneDataBitArrayRef {
    85 SceneDataBitArray *arr;
    86 int index;
    112 87
    113 uint32_t component_size;
    114 uint32_t num_components;
    88 public:
    89 bool operator=(bool);
    90 };
    115 91
    116 uint32_t data_items;
    117 uint32_t data_size; // bytes
    118 void *data;
    119 };
    92 class SceneDataBitArray {
    93 public:
    94 bool operator[](int index);
    95 SceneDataBitArrayRef operator[](int index);
    96 };
    120 97
    121 class ColorData : public Data {
    122 public:
    123 ColorData() : Data( sizeof(double), 4 ) { }
    124 double operator( uint32_t idx, uint32_t com )
    125 {
    98 class SceneDataStoreItemRef {
    99 public:
    100 operator=
    101 };
    126 102
    127 }
    128 };
    103 enum SceneDataStoreItemType { Vertex, Colour, Normal ... };
    104 class SceneDataStoreItem {
    105 public:
    106 SceneDataStoreItem(SceneDataStore *store);
    129 107
    108 void setItemData(SceneDataStoreItemType typ, int idx, double value);
    109 void setItemData(SceneDataStoreItemType typ, int idx, int value);
    110 void setItemData(SceneDataStoreItemType typ, int idx, bool value);
    130 111
    112 SceneDataStoreItemRef operator[](SceneDataStoreItemType typ);
    113 };
    114
    115 // Separate data types? (probably have to)
    116 // Make this all templated?
    117 // ========= Ok, try and just deal with a simple implementation,
    118 // ========== Don't try and make it too general, just implement a basic setup with fixed datatypes for the SceneDataStoreItemType's
    119 // ========== IE: Vertex is double, Colour is char, EdgeFlag is a bool...
    120
    121 class SceneDataStore {
    122 public:
    123
    124 // called/emited by SceneItem prior to changing data if it needs to add or remove data items
    125 void itemDataSizeChange(SceneItem *item, size_t new, size_t old);
    126
    127 // called/emited by SceneItem after data has changed.
    128 void itemDataChanged(SceneItem *item);
    129
    130 //
    131 SceneDataStoreItem *itemData(SceneItem *);
    132
    133 private:
    134 off_t stride; // offset from one item to another
    135 };
    136
    137 class SceneItemData {
    138 public:
    139
    140
    141 private:
    142 SceneDataStore *ds;
    143 off_t offset;
    144 };
    145
    146 class SceneItem {
    147 public:
    148 // data should be stored in the Scene's datastore
    149 };
    150
    151 Dynamo::View
    152 class View {
    153 public:
    154
    155 };
    156
    157 */
    158
    159 BEGIN_NS(Render)
    160
    161 class Context;
    162 class Engine;
    163 class ContextFactory;
    164 class EngineFactory;
    165
    166 // Model
    167 class Context : public Dynamo::Object::Interface {
    168 public:
    169 typedef ContextFactory Factory;
    170
    171 Context() : engine(0) { log("new Render::Context"); }
    172 virtual ~Context() { log("~"); }
    173
    174 virtual const char *name() = 0;
    175 virtual const char *desc() = 0;
    176
    177 virtual void setRenderEngine( Engine * e ) { engine = e; }
    178 virtual Engine *renderEngine() { return engine; }
    179
    180 virtual void addObject( Object * ) = 0;
    181 virtual Data *objectData( Object * ) = 0;
    182
    131 183 private:
    132 184 Engine *engine;
    133 185 };
    134 186
    187 // View
    135 188 class Engine : public Dynamo::Object::Interface {
    136 189 public:
    137 190 typedef EngineFactory Factory;
  • trunk/include/Scene.h

     
    1 #ifndef DynamoScene_H_GUARD
    2 #define DynamoScene_H_GUARD
    3
    4 #ifndef Dynamo_H_GUARD
    5 DYNAMO_NS
    6 #endif
    7
    8 // Dynamo::Scene
    9
    10 enum SceneLayer {
    11 Background,
    12 Item,
    13 Foreground,
    14 };
    15
    16 class Scene {
    17 public:
    18 SceneItem *addItem(
    19
    20 sceneItemData
    21 };
    22
    23 // BitArray can be used to keep track of which DataStoreItems are inuse in the DataStore,
    24 // could make the DataStore allocator easier to handle.
    25 class SceneDataBitArrayRef {
    26 SceneDataBitArray *arr;
    27 int index;
    28
    29 public:
    30 bool operator=(bool);
    31 };
    32
    33 class SceneDataBitArray {
    34 public:
    35 bool operator[](int index);
    36 SceneDataBitArrayRef operator[](int index);
    37 };
    38
    39 class SceneDataStoreItemRef {
    40 public:
    41 operator=
    42 };
    43
    44 enum SceneDataStoreItemType { Vertex, Colour, Normal ... };
    45 class SceneDataStoreItem {
    46 public:
    47 SceneDataStoreItem(SceneDataStore *store);
    48
    49 void setItemData(SceneDataStoreItemType typ, int idx, double value);
    50 void setItemData(SceneDataStoreItemType typ, int idx, int value);
    51 void setItemData(SceneDataStoreItemType typ, int idx, bool value);
    52
    53 SceneDataStoreItemRef operator[](SceneDataStoreItemType typ);
    54 };
    55
    56 // Separate data types? (probably have to)
    57 // Make this all templated?
    58 // ========= Ok, try and just deal with a simple implementation,
    59 // ========== Don't try and make it too general, just implement a basic setup with fixed datatypes for the SceneDataStoreItemType's
    60 // ========== IE: Vertex is double, Colour is char, EdgeFlag is a bool...
    61
    62 class SceneDataStore {
    63 public:
    64
    65 // called/emited by SceneItem prior to changing data if it needs to add or remove data items
    66 void itemDataSizeChange(SceneItem *item, size_t new, size_t old);
    67
    68 // called/emited by SceneItem after data has changed.
    69 void itemDataChanged(SceneItem *item);
    70
    71 //
    72 SceneDataStoreItem *itemData(SceneItem *);
    73
    74 private:
    75 off_t stride; // offset from one item to another
    76 };
    77
    78 class SceneItemData {
    79 public:
    80
    81
    82 private:
    83 SceneDataStore *ds;
    84 off_t offset;
    85 };
    86
    87 class SceneItem {
    88 public:
    89 // data should be stored in the Scene's datastore
    90 };
    91
    92 #ifndef Dynamo_H_GUARD
    93 END_NS
    94 #endif
    95
    96 #endif /* DynamoScene_H_GUARD */