Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. class Object {
  2. Object* NextObject; // Pointer to first item in our same container (tiles are Map Containers). Can be NULL.
  3. Object* Container; // Cannot be NULL, except if we are a Map Container object.
  4. Object* Content; // Pointer to our content, if we have, otherwise NULL.
  5. ObjectType* Type; // A C array holds all the object types, this points to ours
  6. int32_t InstanceAttributes[20]; // Can be plain integers or some sort of reference to other object (i.e the Dynamic String Table).
  7. bool State;
  8.  
  9. };
  10.  
  11. Object::Object() {
  12. State = 0;
  13. ObjectTableFree.push_front();
  14.  
  15. }
  16.  
  17. #define TABLESIZE 64
  18. #define CHUNKSIZE 32768
  19.  
  20. ObjectChunk* ObjectTable;
  21. std::forward_list<Object *> ObjectTableFree(TABLESIZE * CHUNKSIZE);
  22.  
  23. struct ObjectChunk {
  24. Object Obj[CHUNKSIZE];
  25. };
  26.  
  27. void InitMap() {
  28. ObjectTable = new ObjectChunk[TABLESIZE];
  29.  
  30. // Here we also read the map from the hard disk, and
  31. }
  32.  
  33. Object* CreateObject() {
  34. if (ObjectTableFree.empty())
  35. ResizeObjectTable();
  36.  
  37. Object* obj = ObjectTableFree.front();
  38. assert(obj);
  39.  
  40. ObjectTableFree.pop_front();
  41. return obj;
  42. }
  43.  
  44. Object* AppendObject(Object* Con, ObjectType* Type, bool AsContent) {
  45. assert(Con);
  46.  
  47. Object* obj = CreateObject();
  48. obj->Container = Con;
  49. Object->setType(Type);
  50.  
  51. if (AsContent) {
  52. if (Con->Content)
  53. obj->NextObject = Con->Content;
  54.  
  55. Con->NextObject = obj;
  56. return obj;
  57.  
  58. if (Con->NextObject)
  59. obj->NextObject = Con->NextObject;
  60.  
  61. Con->NextObject = obj;
  62. return obj;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement