mirror of
https://github.com/zeldaret/tww.git
synced 2026-08-21 14:07:29 -04:00
JUTConsole work
inspired by nw4r
This commit is contained in:
@@ -21,47 +21,40 @@ public:
|
||||
struct TNodeLinkList {
|
||||
struct iterator {
|
||||
iterator(TLinkListNode* pNode) { node = pNode; }
|
||||
iterator(const iterator& iter) { *this = iter; }
|
||||
operator bool() const {
|
||||
return node != NULL;
|
||||
}
|
||||
|
||||
iterator& operator++() {
|
||||
node = node->getNext();
|
||||
return *this;
|
||||
}
|
||||
iterator& operator--() {
|
||||
node = node->getPrev();
|
||||
return *this;
|
||||
}
|
||||
bool operator==(const iterator& o) { return o.node == node; }
|
||||
bool operator!=(const iterator& o) { return !(*this == o); }
|
||||
iterator& operator++() { node = node->getNext(); return *this; }
|
||||
iterator& operator--() { node = node->getPrev(); return *this; }
|
||||
iterator operator++(int) { const iterator old(*this); (void)++*this; return old; }
|
||||
iterator operator--(int) { const iterator old(*this); (void)--*this; return old; }
|
||||
friend bool operator==(TNodeLinkList::iterator a, TNodeLinkList::iterator b) { return a.node == b.node; }
|
||||
friend bool operator!=(TNodeLinkList::iterator a, TNodeLinkList::iterator b) { return !(a == b); }
|
||||
|
||||
TLinkListNode* node;
|
||||
TLinkListNode* operator->() const { return node; }
|
||||
TLinkListNode& operator*() const { return *node; }
|
||||
|
||||
public:
|
||||
/* 0x00 */ TLinkListNode* node;
|
||||
};
|
||||
|
||||
struct const_iterator {
|
||||
const_iterator(TLinkListNode* pNode) { node = pNode; }
|
||||
const_iterator(const const_iterator& iter) { *this = iter; }
|
||||
operator bool() const {
|
||||
return node != NULL;
|
||||
}
|
||||
|
||||
const_iterator& operator++() {
|
||||
node = node->getNext();
|
||||
return *this;
|
||||
}
|
||||
const_iterator& operator--() {
|
||||
node = node->getPrev();
|
||||
return *this;
|
||||
}
|
||||
bool operator==(const const_iterator& o) { return o.node == node; }
|
||||
bool operator!=(const const_iterator& o) { return !(*this == o); }
|
||||
const_iterator& operator++() { node = node->getNext(); return *this; }
|
||||
const_iterator& operator--() { node = node->getPrev(); return *this; }
|
||||
const_iterator operator++(int) { const const_iterator old(*this); (void)++*this; return old; }
|
||||
const_iterator operator--(int) { const const_iterator old(*this); (void)--*this; return old; }
|
||||
friend bool operator==(TNodeLinkList::const_iterator a, TNodeLinkList::const_iterator b) { return a.node == b.node; }
|
||||
friend bool operator!=(TNodeLinkList::const_iterator a, TNodeLinkList::const_iterator b) { return !(a == b); }
|
||||
|
||||
TLinkListNode* node;
|
||||
TLinkListNode* operator->() const { return node; }
|
||||
TLinkListNode& operator*() const { return *node; }
|
||||
|
||||
public:
|
||||
/* 0x00 */ TLinkListNode* node;
|
||||
};
|
||||
|
||||
TNodeLinkList() : ocObject_() { Initialize_(); }
|
||||
~TNodeLinkList();
|
||||
|
||||
void Initialize_() {
|
||||
count = 0;
|
||||
@@ -69,37 +62,21 @@ struct TNodeLinkList {
|
||||
ocObject_.mPrev = &ocObject_;
|
||||
}
|
||||
|
||||
iterator begin() {
|
||||
iterator iter(ocObject_.getNext());
|
||||
return iter;
|
||||
}
|
||||
iterator begin() { return iterator(ocObject_.getNext()); }
|
||||
iterator end() { return iterator(ocObject_.getPrev()); }
|
||||
const_iterator begin() const { return const_iterator(ocObject_.getNext()); }
|
||||
const_iterator end() const { return const_iterator(ocObject_.getPrev()); }
|
||||
u32 size() { return count; }
|
||||
|
||||
iterator end() {
|
||||
iterator iter(ocObject_.getPrev());
|
||||
return iter;
|
||||
}
|
||||
|
||||
const_iterator begin() const {
|
||||
const_iterator iter(ocObject_.getNext());
|
||||
return iter;
|
||||
}
|
||||
|
||||
const_iterator end() const {
|
||||
const_iterator iter(ocObject_.getPrev());
|
||||
return iter;
|
||||
}
|
||||
|
||||
~TNodeLinkList();
|
||||
iterator erase(JGadget::TNodeLinkList::iterator, JGadget::TNodeLinkList::iterator);
|
||||
iterator erase(JGadget::TNodeLinkList::iterator);
|
||||
void splice(JGadget::TNodeLinkList::iterator, JGadget::TNodeLinkList&,
|
||||
JGadget::TNodeLinkList::iterator);
|
||||
void splice(JGadget::TNodeLinkList::iterator, JGadget::TNodeLinkList&, JGadget::TNodeLinkList::iterator);
|
||||
iterator Find(const JGadget::TLinkListNode*);
|
||||
iterator Insert(JGadget::TNodeLinkList::iterator, JGadget::TLinkListNode*);
|
||||
iterator Erase(JGadget::TLinkListNode*);
|
||||
void Remove(JGadget::TLinkListNode*);
|
||||
u32 size() { return count; }
|
||||
|
||||
public:
|
||||
/* 0x00 */ u32 count;
|
||||
/* 0x04 */ TLinkListNode ocObject_;
|
||||
}; // Size: 0xC
|
||||
@@ -108,88 +85,69 @@ template <typename T, int I>
|
||||
struct TLinkList : public TNodeLinkList {
|
||||
TLinkList() : TNodeLinkList() {}
|
||||
|
||||
static TLinkListNode* Element_toNode(T* element) { return reinterpret_cast<TLinkListNode*>(((char*)element) - I); }
|
||||
static T* Element_toValue(TLinkListNode* node) { return reinterpret_cast<T*>(((char*)node) + I); }
|
||||
static TLinkListNode* Element_toNode(T* element) { return reinterpret_cast<TLinkListNode*>(reinterpret_cast<char*>(element) - I); }
|
||||
static T* Element_toValue(TLinkListNode* node) { return reinterpret_cast<T*>(reinterpret_cast<char*>(node) + I); }
|
||||
|
||||
struct iterator : TNodeLinkList::iterator {
|
||||
iterator(TNodeLinkList::iterator iter) : TNodeLinkList::iterator(iter) {}
|
||||
iterator(const iterator& o) : TNodeLinkList::iterator(o) {}
|
||||
struct iterator {
|
||||
iterator(TNodeLinkList::iterator iter) : base(iter) {}
|
||||
|
||||
iterator& operator++() {
|
||||
iterator it(TNodeLinkList::iterator::operator++());
|
||||
return it;
|
||||
}
|
||||
iterator& operator--() {
|
||||
iterator it(TNodeLinkList::iterator::operator--());
|
||||
return it;
|
||||
}
|
||||
iterator& operator++() { ++base; return *this; }
|
||||
iterator& operator--() { --base; return *this; }
|
||||
iterator operator++(int) { const iterator old(*this); ++*this; return old; }
|
||||
iterator operator--(int) { const iterator old(*this); --*this; return old; }
|
||||
friend bool operator==(iterator a, iterator b) { return a.base == b.base; }
|
||||
friend bool operator!=(iterator a, iterator b) { return !(a == b); }
|
||||
|
||||
T* operator*() {
|
||||
return Element_toValue(node);
|
||||
}
|
||||
T* operator->() {
|
||||
return Element_toValue(node);
|
||||
}
|
||||
T* operator->() const { return Element_toValue(base.operator->()); }
|
||||
T& operator*() const { return *operator->(); }
|
||||
|
||||
public:
|
||||
/* 0x00 */ TNodeLinkList::iterator base;
|
||||
};
|
||||
|
||||
struct const_iterator : TNodeLinkList::const_iterator {
|
||||
const_iterator(TNodeLinkList::const_iterator iter) : TNodeLinkList::const_iterator(iter) {}
|
||||
const_iterator(const const_iterator& o) : TNodeLinkList::const_iterator(o) {}
|
||||
struct const_iterator {
|
||||
const_iterator(TNodeLinkList::const_iterator iter) : base(iter) {}
|
||||
|
||||
const_iterator& operator++() {
|
||||
const_iterator it(TNodeLinkList::const_iterator::operator++());
|
||||
return it;
|
||||
}
|
||||
const_iterator& operator--() {
|
||||
const_iterator it(TNodeLinkList::const_iterator::operator--());
|
||||
return it;
|
||||
}
|
||||
const_iterator& operator++() { ++base; return *this; }
|
||||
const_iterator& operator--() { --base; return *this; }
|
||||
const_iterator operator++(int) { const const_iterator old(*this); ++*this; return old; }
|
||||
const_iterator operator--(int) { const const_iterator old(*this); --*this; return old; }
|
||||
friend bool operator==(const_iterator a, const_iterator b) { return a.base == b.base; }
|
||||
friend bool operator!=(const_iterator a, const_iterator b) { return !(a == b); }
|
||||
|
||||
T* operator*() {
|
||||
return Element_toValue(node);
|
||||
}
|
||||
T* operator->() {
|
||||
return Element_toValue(node);
|
||||
}
|
||||
T* operator->() const { return Element_toValue(base.operator->()); }
|
||||
T& operator*() const { return *operator->(); }
|
||||
|
||||
public:
|
||||
/* 0x00 */ TNodeLinkList::const_iterator base;
|
||||
};
|
||||
|
||||
void Insert(TLinkList::iterator iter, T* element) {
|
||||
TLinkListNode* node = Element_toNode(element);
|
||||
TNodeLinkList::Insert(iter, node);
|
||||
iterator Insert(iterator iter, T* element) {
|
||||
return TNodeLinkList::Insert(iter.base, Element_toNode(element));
|
||||
}
|
||||
|
||||
iterator Erase(T* element) {
|
||||
TLinkListNode* node = Element_toNode(element);
|
||||
return ((TNodeLinkList*)this)->Erase(node);
|
||||
return TNodeLinkList::Erase(Element_toNode(element));
|
||||
}
|
||||
|
||||
TLinkList::iterator begin() {
|
||||
TNodeLinkList::iterator node_iter = TNodeLinkList::begin();
|
||||
TLinkList::iterator iter(node_iter);
|
||||
return iter;
|
||||
iterator begin() {
|
||||
return iterator(TNodeLinkList::begin());
|
||||
}
|
||||
|
||||
TLinkList::iterator end() {
|
||||
TNodeLinkList::iterator node_iter = TNodeLinkList::end();
|
||||
TLinkList::iterator iter(node_iter);
|
||||
return iter;
|
||||
iterator end() {
|
||||
return iterator(TNodeLinkList::end());
|
||||
}
|
||||
|
||||
TLinkList::const_iterator begin() const {
|
||||
TNodeLinkList::const_iterator node_iter = TNodeLinkList::begin();
|
||||
TLinkList::const_iterator iter(node_iter);
|
||||
return iter;
|
||||
const_iterator begin() const {
|
||||
return const_iterator(TNodeLinkList::begin());
|
||||
}
|
||||
|
||||
TLinkList::const_iterator end() const {
|
||||
TNodeLinkList::const_iterator node_iter = TNodeLinkList::end();
|
||||
TLinkList::const_iterator iter(node_iter);
|
||||
return iter;
|
||||
const_iterator end() const {
|
||||
return const_iterator(TNodeLinkList::end());
|
||||
}
|
||||
|
||||
void Push_back(T* element) {
|
||||
TLinkList::iterator iter(TLinkList::end());
|
||||
this->Insert(iter, element);
|
||||
Insert(end(), element);
|
||||
}
|
||||
|
||||
iterator Find(T* element) {
|
||||
@@ -200,16 +158,8 @@ struct TLinkList : public TNodeLinkList {
|
||||
TNodeLinkList::Remove(Element_toNode(element));
|
||||
}
|
||||
|
||||
T* front() {
|
||||
TLinkList::iterator iter(TLinkList::begin());
|
||||
return *iter;
|
||||
}
|
||||
|
||||
T* back() {
|
||||
TLinkList::iterator iter(TLinkList::end());
|
||||
--iter;
|
||||
return *iter;
|
||||
}
|
||||
T& front() { return *begin(); }
|
||||
T& back() { return *--end(); }
|
||||
};
|
||||
|
||||
template <typename T, int I>
|
||||
|
||||
@@ -132,8 +132,10 @@ public:
|
||||
|
||||
static JUTConsoleManager* sManager;
|
||||
|
||||
typedef JGadget::TLinkList<JUTConsole, -offsetof(JUTConsole, mLinkNode)> ConsoleList;
|
||||
|
||||
private:
|
||||
/* 0x00 */ JGadget::TLinkList<JUTConsole, -offsetof(JUTConsole, mLinkNode)> soLink_;
|
||||
/* 0x00 */ ConsoleList soLink_;
|
||||
/* 0x0C */ JUTConsole* mActiveConsole;
|
||||
/* 0x10 */ JUTConsole* mDirectConsole;
|
||||
}; // Size: 0x14
|
||||
|
||||
@@ -386,7 +386,7 @@ void JUTConsoleManager::removeConsole(JUTConsole* console) {
|
||||
if (soLink_.size() <= 1) {
|
||||
mActiveConsole = NULL;
|
||||
} else {
|
||||
mActiveConsole = console != soLink_.back() ? soLink_.Element_toValue(console->mLinkNode.getNext()) : soLink_.front();
|
||||
mActiveConsole = console != &soLink_.back() ? soLink_.Element_toValue(console->mLinkNode.getNext()) : &soLink_.front();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,10 +403,10 @@ void JUTConsoleManager::draw() const {
|
||||
/* Nonmatching */
|
||||
|
||||
// need to figure out how TLinkList works
|
||||
JGadget::TLinkList<JUTConsole, 4>::const_iterator iter = soLink_.begin();
|
||||
JGadget::TLinkList<JUTConsole, 4>::const_iterator end = soLink_.end();
|
||||
ConsoleList::const_iterator iter = soLink_.begin();
|
||||
ConsoleList::const_iterator end = soLink_.end();
|
||||
for (; iter != end; ++iter) {
|
||||
JUTConsole* pConsole = *iter;
|
||||
JUTConsole* pConsole = &(*iter);
|
||||
if (pConsole != mActiveConsole)
|
||||
pConsole->doDraw(JUTConsole::INACTIVE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user