From: ljsebald <ljs...@us...> - 2023-09-10 16:37:14
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "UNNAMED PROJECT". The branch, master has been updated via a9469557bddda8bc37a77935b770dbcfb5dc4203 (commit) via 07f410dc0165c7ca65da2505f1ea9e1acd76a69d (commit) via 5cff9720de671e0674407c9124882f217c14acc9 (commit) via b11b146dce5a9c8abcda71caf2447452132c610e (commit) via 015ffe2f5b1c50227e0b8268b39fee8a1dd0de1a (commit) via b6bf4a27edf71895d8ada7addd23cf9e3ec8550a (commit) via 280a443d13a609784acbebc6c387657c204278e8 (commit) via ef8ca14fb2fdb04106287b76d11d4b0143744f41 (commit) via 942067f13775fe656ff127d9f530ebf0ea676bb8 (commit) via 5ab9325d1cc938107417d1a5d597147ec4662888 (commit) via 06cf8d4511b914ebfc2a97a3811aa52c4201ee6a (commit) from 9771d16b0a91c7b1745ef61e792197eac70ef541 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit a9469557bddda8bc37a77935b770dbcfb5dc4203 Merge: 9771d16 07f410d Author: Lawrence Sebald <ljs...@us...> Date: Sun Sep 10 12:34:25 2023 -0400 Merge pull request #1 from pcercuei/c++17 Rework to use C++17 commit 07f410dc0165c7ca65da2505f1ea9e1acd76a69d Author: Paul Cercueil <pa...@cr...> Date: Sun Sep 3 00:07:32 2023 +0200 Remove custom reference counting This code is not needed / useful anymore, since everything has been switched to use C++11 std::shared_ptr<>. Signed-off-by: Paul Cercueil <pa...@cr...> commit 5cff9720de671e0674407c9124882f217c14acc9 Author: Paul Cercueil <pa...@cr...> Date: Sat Sep 2 23:55:34 2023 +0200 genmenu: Use shared pointers Use shared pointers instead of the custom RefCnt class. Signed-off-by: Paul Cercueil <pa...@cr...> commit b11b146dce5a9c8abcda71caf2447452132c610e Author: Paul Cercueil <pa...@cr...> Date: Sat Sep 2 23:54:56 2023 +0200 triggers: Use shared pointers Use shared pointers instead of the custom RefCnt class. Signed-off-by: Paul Cercueil <pa...@cr...> commit 015ffe2f5b1c50227e0b8268b39fee8a1dd0de1a Author: Paul Cercueil <pa...@cr...> Date: Sat Sep 2 23:45:44 2023 +0200 drawable: Use shared pointers Use shared pointers instead of the custom RefCnt class. Signed-off-by: Paul Cercueil <pa...@cr...> commit b6bf4a27edf71895d8ada7addd23cf9e3ec8550a Author: Paul Cercueil <pa...@cr...> Date: Sun Sep 3 00:05:45 2023 +0200 animations: Use shared pointers Use shared pointers instead of the custom RefCnt class. Signed-off-by: Paul Cercueil <pa...@cr...> commit 280a443d13a609784acbebc6c387657c204278e8 Author: Paul Cercueil <pa...@cr...> Date: Sat Sep 2 23:22:58 2023 +0200 Remove custom List<>, use std::depre instead There is no need to use a custom list object in favour of the ones provided by the standard C++ library. Use std::depre which allows us to queue pointers from the front, while still being able to loop front to back, to retain the old behaviour. Signed-off-by: Paul Cercueil <pa...@cr...> [gyrovorbis: quick bugfix for crash on erasing from std::deque] Signed-off-by: Falco Girgis <gyr...@gm...> commit ef8ca14fb2fdb04106287b76d11d4b0143744f41 Author: Paul Cercueil <pa...@cr...> Date: Sat Sep 2 23:17:46 2023 +0200 Add missing includes Some source files needed extra includes to compile properly. Signed-off-by: Paul Cercueil <pa...@cr...> commit 942067f13775fe656ff127d9f530ebf0ea676bb8 Author: Paul Cercueil <pa...@cr...> Date: Sat Sep 2 23:47:19 2023 +0200 Use C++ strings when applicable Use std::string instead of the C "const char *" where strings are used in the API. Signed-off-by: Paul Cercueil <pa...@cr...> commit 5ab9325d1cc938107417d1a5d597147ec4662888 Author: Paul Cercueil <pa...@cr...> Date: Sat Sep 2 23:16:16 2023 +0200 Use C++17 filesystem paths when applicable Use C++17 std::filesystem and in particular std::filesystem::path instead of using "const char *" for paths. Signed-off-by: Paul Cercueil <pa...@cr...> commit 06cf8d4511b914ebfc2a97a3811aa52c4201ee6a Author: Paul Cercueil <pa...@cr...> Date: Sun Sep 3 00:04:10 2023 +0200 Change NULL -> nullptr NULL is a C thing. Signed-off-by: Paul Cercueil <pa...@cr...> ----------------------------------------------------------------------- Summary of changes: include/animation.h | 10 +-- include/drawable.h | 14 ++-- include/drawables/banner.h | 8 ++- include/drawables/label.h | 13 ++-- include/font.h | 24 ++++--- include/genmenu.h | 9 +-- include/list.h | 168 ------------------------------------------- include/refcnt.h | 133 ---------------------------------- include/sound.h | 10 +-- include/texture.h | 11 +-- include/trigger.h | 5 +- include/triggers/birth.h | 9 ++- include/triggers/chainanim.h | 6 +- include/triggers/death.h | 6 +- include/triggers/oneshot.h | 7 +- src/animation.cpp | 29 ++++---- src/drawable.cpp | 121 ++++++++++++++----------------- src/drawables/banner.cpp | 4 +- src/drawables/label.cpp | 15 ++-- src/font.cpp | 58 +++++++-------- src/genmenu.cpp | 11 +-- src/sound.cpp | 10 +-- src/texture.cpp | 22 +++--- src/triggers/birth.cpp | 3 +- src/triggers/death.cpp | 2 +- 25 files changed, 210 insertions(+), 498 deletions(-) delete mode 100644 include/list.h delete mode 100644 include/refcnt.h diff --git a/include/animation.h b/include/animation.h index 6523759..4dae8d1 100644 --- a/include/animation.h +++ b/include/animation.h @@ -12,17 +12,19 @@ class Drawable; -#include "list.h" #include "trigger.h" -class Animation : virtual public RefCnt { +#include <memory> +#include <deque> + +class Animation { public: /// Constructor / Destructor Animation(); virtual ~Animation(); /// Add a trigger to our list of triggers - void triggerAdd(Trigger *t); + void triggerAdd(std::shared_ptr<Trigger> t); /// Remove a trigger from our list of triggers void triggerRemove(Trigger *t); @@ -41,7 +43,7 @@ protected: virtual void complete(Drawable *t); private: - List<Trigger> m_triggers; // Animation triggers + std::deque<std::shared_ptr<Trigger>> m_triggers; // Animation triggers }; #endif /* __TSUNAMI_ANIMATION_H */ diff --git a/include/drawable.h b/include/drawable.h index be71c3c..edf36ba 100644 --- a/include/drawable.h +++ b/include/drawable.h @@ -12,18 +12,20 @@ #include "animation.h" -#include "list.h" #include "vector.h" #include "color.h" -class Drawable : virtual public RefCnt { +#include <deque> +#include <memory> + +class Drawable { public: /// Constructor / Destructor Drawable(); virtual ~Drawable(); /// Add an animation object to us - void animAdd(Animation * ani); + void animAdd(std::shared_ptr<Animation> ani); /// Remove an animation object from us void animRemove(Animation * ani); @@ -46,7 +48,7 @@ public: void subNextFrame(); /// Add a new object to our sub-drawables - void subAdd(Drawable *t); + void subAdd(std::shared_ptr<Drawable> t); /// Remove an object from our sub-drawables void subRemove(Drawable * t); @@ -132,8 +134,8 @@ private: Drawable * m_parent; ///< Our parent object - List<Animation> m_anims; ///< Animation objects - List<Drawable> m_subs; ///< Our sub-drawable list + std::deque<std::shared_ptr<Animation>> m_anims; ///< Animation objects + std::deque<std::shared_ptr<Drawable>> m_subs; ///< Our sub-drawable list }; #endif /* __TSUNAMI_DRAWABLE_H */ diff --git a/include/drawables/banner.h b/include/drawables/banner.h index 20277ea..fa23c69 100644 --- a/include/drawables/banner.h +++ b/include/drawables/banner.h @@ -16,14 +16,16 @@ #include "../texture.h" #include "../color.h" +#include <memory> + /** Banner -- a texture banner drawable. This drawable takes a texture (and optional UV coordinates) and draws a banner. */ class Banner : public Drawable { public: - Banner(int list, Texture * texture); + Banner(int list, std::shared_ptr<Texture> texture); virtual ~Banner(); - void setTexture(Texture * txr); + void setTexture(std::shared_ptr<Texture> txr); // Points are: 2 4 // 1 3 @@ -35,7 +37,7 @@ public: private: int m_list; - RefPtr<Texture> m_texture; + std::shared_ptr<Texture> m_texture; float m_u1, m_v1, m_u2, m_v2; float m_u3, m_v3, m_u4, m_v4; diff --git a/include/drawables/label.h b/include/drawables/label.h index 4444dd5..3405642 100644 --- a/include/drawables/label.h +++ b/include/drawables/label.h @@ -13,19 +13,22 @@ #include "../drawable.h" #include "../font.h" +#include <string> + class Label : public Drawable { public: - Label(Font * fh, const char *text, int size, bool centered, bool smear); + Label(std::shared_ptr<Font> fh, const std::string &text, + int size, bool centered, bool smear); virtual ~Label(); - void setText(const char * text); - void setFont(Font * f); + void setText(const std::string &text); + void setFont(std::shared_ptr<Font> f); virtual void draw(int list); private: - RefPtr<Font> m_fh; - const char * m_text; + std::shared_ptr<Font> m_fh; + std::string m_text; int m_size; bool m_centered; bool m_smear; diff --git a/include/font.h b/include/font.h index a5b5ba3..4de54d7 100644 --- a/include/font.h +++ b/include/font.h @@ -11,15 +11,17 @@ #define __TSUNAMI_FONT_H #include <plx/font.h> -#include "refcnt.h" #include "vector.h" -class Font : virtual public RefCnt { +#include <filesystem> +#include <string> + +class Font { public: - Font(const char *fn = NULL, int list = PVR_LIST_TR_POLY); + Font(const std::filesystem::path &path, int list = PVR_LIST_TR_POLY); virtual ~Font(); - bool loadFromFile(const char * fn); + bool loadFromFile(const std::filesystem::path &path); void setFilter(int type); @@ -27,10 +29,10 @@ public: void setAlpha(float a); void setSize(float size); - void draw(float x, float y, float z, const char *text); - void drawCentered(float x, float y, float z, const char *text); - void smearDraw(float x, float y, float z, const char *text); - void smearDrawCentered(float x, float y, float z, const char *text); + void draw(float x, float y, float z, const std::string &text); + void drawCentered(float x, float y, float z, const std::string &text); + void smearDraw(float x, float y, float z, const std::string &text); + void smearDrawCentered(float x, float y, float z, const std::string &text); void drawCharBegin(float x, float y, float z); Vector drawCharGetPos(); @@ -39,9 +41,9 @@ public: void drawCharEnd(); void getCharExtents(int c, float * l, float * u, float * r, float * d); - void getTextSize(const char *text, float * w, float * h); - void upperleftCoords(const char * text, float *x, float *y); - void centerCoords(const char * text, float *x, float *y); + void getTextSize(const std::string &text, float * w, float * h); + void upperleftCoords(const std::string &text, float *x, float *y); + void centerCoords(const std::string &text, float *x, float *y); operator plx_font_t * () const { return m_font; } operator plx_fcxt_t * () const { return m_cxt; } diff --git a/include/genmenu.h b/include/genmenu.h index 4d32b87..1442fcb 100644 --- a/include/genmenu.h +++ b/include/genmenu.h @@ -9,9 +9,10 @@ #ifndef __TSUNAMI_GENMENU_H #define __TSUNAMI_GENMENU_H -#include "refcnt.h" #include "drawables/scene.h" +#include <filesystem> + /* This defines a fully generic menu system. Basically what you do is derive from this class and then implement the constructor (which adds things to the internal scene object) and the inputEvent method (which @@ -116,7 +117,7 @@ protected: // Call this method to setup a background song to be played during the // menu. You should do this before calling doMenu(). The song will // be started with the menu and faded out on exit. - virtual void setBgm(const char * fn, bool cache = false); + virtual void setBgm(const std::filesystem::path &fn, bool cache = false); // This method should be called any time the user does something that // would cancel the menu's timeout. @@ -138,7 +139,7 @@ protected: // Name of the song we'll use for background music (if any). If this // is an empty string, we'll not use a song. - char m_bgmFn[256]; + std::filesystem::path m_bgmFn; bool m_usebgm, m_cachebgm; // Background plane color @@ -156,7 +157,7 @@ protected: uint32 m_timeout; // Our scene object - RefPtr<Scene> m_scene; + std::shared_ptr<Scene> m_scene; // Allow one "main" controller in each port. We'll track what's in // each port and what buttons are currently held. diff --git a/include/list.h b/include/list.h deleted file mode 100644 index b9a9281..0000000 --- a/include/list.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - Tsunami for KallistiOS ##version## - - list.h - - Copyright (C) 2002 Megan Potter - -*/ - -#ifndef __TSUNAMI_LIST_H -#define __TSUNAMI_LIST_H - -/// \file A basic linked-list class. The only real constraint here -/// is that the type T must be a subclass of RefCnt or something that -/// provides similar methods. This cheats a little by implementing -/// all the core functionality via the BSD queue macros, but it provides -/// a much nicer C++ interface. - -#include <assert.h> -#include <string.h> -#include <sys/queue.h> -#include "refcnt.h" - -template <class T> -class List; - -template <class T> -struct ListNode { -public: - ListNode<T>(List<T> * head, T * d) - : m_head(head), m_data(d), m_inlist(false) - { } - - virtual ~ListNode<T>() { - assert( !m_inlist ); - } - - /// Get the next list item - ListNode<T> * getNext() const { - assert( m_inlist ); - if ( !m_inlist ) - return NULL; - - return TAILQ_NEXT(this, m_listptr); - } - - /// Get this list item's data - T * getData() const { return m_data; } - - /// Perform an operation on this list item's data - T * operator->() const { - assert( m_data != NULL ); - return (T*)m_data; - } - - /// Remove this item from the list (doesn't delete it) - void remove() { - assert( m_inlist ); - if (!m_inlist) return; - - TAILQ_REMOVE(&m_head->m_list, this, m_listptr); - m_inlist = false; - } - - /// Insert another element before us - void insertBefore(ListNode<T> * other) { - assert( !m_inlist ); - if (m_inlist) return; - - TAILQ_INSERT_BEFORE(other, this, m_listptr); - m_inlist = true; - } - - /// Insert another element after us - void insertAfter(ListNode<T> * other) { - assert( !m_inlist ); - if (m_inlist) return; - - TAILQ_INSERT_AFTER(&m_head->m_list, other, this, m_listptr); - m_inlist = true; - } - -private: - List<T> * m_head; - RefPtr<T> m_data; - bool m_inlist; - - friend class List<T>; - TAILQ_ENTRY(ListNode<T>) m_listptr; -}; - - -template <class T> -class List { -public: - List() { - TAILQ_INIT(&m_list); - } - - virtual ~List() { - delAll(); - } - - /// Insert an item at the head of the list. A reference will be added. - void insertHead(T * item) { - ListNode<T> * ni = new ListNode<T>(this, item); - TAILQ_INSERT_HEAD(&m_list, ni, m_listptr); - ni->m_inlist = true; - } - - /// Insert an item at the tail of the list. A reference will be added. - void insertTail(T * item) { - ListNode<T> * ni = new ListNode<T>(this, item); - TAILQ_INSERT_TAIL(&m_list, ni, m_listptr); - ni->m_inlist = true; - } - - /// Delete the named item. Return true if we actually had it. Its - /// reference will be removed if it is found. - bool del(T * item) { - ListNode<T> * n; - - TAILQ_FOREACH(n, &m_list, m_listptr) { - if (n->getData() == item) { - n->remove(); - delete n; - return true; - } - } - - return false; - } - - /// Remove all items from the list. - void delAll() { - ListNode<T> * n, * t; - - // Pull each item from the list and destroy it - t = TAILQ_FIRST(&m_list); - while (t) { - n = t->getNext(); - t->m_inlist = false; - delete t; - t = n; - } - - // Re-init the list - TAILQ_INIT(&m_list); - } - - /// Return the element at the head of the list - ListNode<T> * getHead() const { - return TAILQ_FIRST(&m_list); - } - -private: - friend class ListNode<T>; - - TAILQ_HEAD(listnodehead, ListNode<T>) m_list; - -public: - /// Return the element at the end of the list - ListNode<T> * getTail() const { - return TAILQ_LAST(&m_list, listnodehead); - } -}; - -#endif // __TSUNAMI_LIST_H diff --git a/include/refcnt.h b/include/refcnt.h deleted file mode 100644 index 0b6bf0f..0000000 --- a/include/refcnt.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - Tsunami for KallistiOS ##version## - - refcnt.h - - Copyright (C) 2002 Megan Potter - -*/ - -#ifndef __TSUNAMI_REFCNT_H -#define __TSUNAMI_REFCNT_H - -/// \file A simple reference counting system for managing shared -/// data objects. - -#include <arch/arch.h> -#include <stdio.h> -#include <assert.h> - -/// The reference count base class itself. Any class you want handled -/// by reference counting should add this as a public base class. -class RefCnt { -public: - RefCnt() { - m_refcnt = 0; - } - virtual ~RefCnt() { - if (m_refcnt != 0) { - dbglog(DBG_WARNING, "RefCnt::~RefCnt: **WARNING** My (%08lx), refcount isn't zero! It's %d.\n", - (uint32)this, m_refcnt); - } - assert( m_refcnt == 0 ); - } - - // Add a reference to the object - virtual void ref() { - m_refcnt++; - } - - // Remove a reference to the object; if we hit - // zero then delete it - virtual void unref() { - m_refcnt--; - if (m_refcnt < 0) { - dbglog(DBG_WARNING, "RefCnt::unref() refcount underflow! this=%08lx, caller=%08lx\n", - (uint32)this, arch_get_ret_addr()); - assert( false ); - } else if (m_refcnt == 0) { - delete this; - } - } - -private: - int m_refcnt; -}; - - -/// A "smart pointer" to handle the RefCnt objects. ...<truncated>... hooks/post-receive -- UNNAMED PROJECT |