Skip to content

Commit

Permalink
create cleanup part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
dankmeme01 committed Jun 23, 2024
1 parent 5b2d15b commit 11299d3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
7 changes: 4 additions & 3 deletions handbook/vol1/chap1_6.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected:
bool init() {
if (!CCNode::init())
return false;

// Initialize SomeNode

return true;
Expand All @@ -29,11 +29,12 @@ protected:
public:
static SomeNode* create() {
auto ret = new SomeNode();
if (ret && ret->init()) {
if (ret->init()) {
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);

delete ret;
return nullptr;
}
};
Expand Down
31 changes: 16 additions & 15 deletions mods/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ The first class that the mod needs to provide for the setting is one that inheri
using namespace geode::prelude;

class MySettingValue : public SettingValue {
// store the current value in some form.
// this may be an enum, a class, or
// whatever it is your setting needs -
// store the current value in some form.
// this may be an enum, a class, or
// whatever it is your setting needs -
// you are free to do whatever!

public:
Expand All @@ -160,7 +160,7 @@ public:
: SettingValue(key, mod), m_someMember(someValue) {}

bool load(matjson::Value const& json) override {
// load the value of the setting from json,
// load the value of the setting from json,
// returning true if loading was succesful
}
bool save(matjson::Value& json) const override {
Expand Down Expand Up @@ -189,23 +189,23 @@ protected:
bool init(MySettingValue* value, float width) {
if (!SettingNode::init(value))
return false;
// You may change the height to anything, but make sure to call
// You may change the height to anything, but make sure to call
// setContentSize!
this->setContentSize({ width, 40.f });
// Set up the UI. Note that Geode provides a background for the
// Set up the UI. Note that Geode provides a background for the
// setting automatically
return true;
}
// Whenever the user interacts with your controls, you should call
// Whenever the user interacts with your controls, you should call
// this->dispatchChanged()
public:
// When the user wants to save this setting value, this function is
// called - this is where you should actually set the value of your
// When the user wants to save this setting value, this function is
// called - this is where you should actually set the value of your
// setting
void commit() override {
// Set the actual value
Expand All @@ -214,13 +214,13 @@ public:
this->dispatchCommitted();
}
// Geode calls this to query if the setting value has been changed,
// Geode calls this to query if the setting value has been changed,
// and those changes haven't been committed
bool hasUncommittedChanges() override {
// todo
}
// Geode calls this to query if the setting has a value that is
// Geode calls this to query if the setting has a value that is
// different from its default value
bool hasNonDefaultValue() override {
// todo
Expand All @@ -233,11 +233,12 @@ public:
static MySettingNode* create(MySettingValue* value, float width) {
auto ret = new MySettingNode();
if (ret && ret->init(value, width)) {
if (ret->init(value, width)) {
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);
delete ret;
return nullptr;
}
};
Expand All @@ -248,7 +249,7 @@ The last this the mod needs to do is register their setting value class to Geode
```cpp
$on_mod(Loaded) {
Mod::get()->addCustomSetting<MySettingValue>("my-setting", ...);

// or, alternatively:
Mod::get()->registerCustomSetting(
"my-setting",
Expand Down
11 changes: 6 additions & 5 deletions tutorials/memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ Remembering to manage every object you have ever created is a real problem, thou
```cpp
auto node = CCNode::create();
auto other = CCNode::create();
// CCNode increments other's ref count by 1, and decrements it when the child
// CCNode increments other's ref count by 1, and decrements it when the child
// is removed or when node is freed
node->addChild(other);
auto array = CCArray::create();
// CCArray increment node's ref count by 1, and decrements it when the child
// CCArray increment node's ref count by 1, and decrements it when the child
// is removed or when the node is freed
array->addObject(node);
```
Expand All @@ -70,7 +70,7 @@ This means that if you store your created object as a child to something or add
```cpp
{
auto array = CCArray::create();
// If this array is never used anywhere, it's ref count stays at 0 but
// If this array is never used anywhere, it's ref count stays at 0 but
// nothing calls release on it, so the memory is leaked - except it's not!
}
```
Expand All @@ -80,12 +80,13 @@ This code looks like it should cause a memory leak, since nothing ever calls `re
```cpp
SomeNode* SomeNode::create() {
auto ret = new SomeNode();
if (ret && ret->init()) {
if (ret->init()) {
// Make the node be automatically garbage collected
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);

delete ret;
return nullptr;
}
```
Expand Down
11 changes: 6 additions & 5 deletions tutorials/popup.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected:
bool setup(std::string const& value) override {
auto winSize = CCDirector::sharedDirector()->getWinSize();

// convenience function provided by Popup
// convenience function provided by Popup
// for adding/setting a title to the popup
this->setTitle("Hi mom!");

Expand All @@ -55,11 +55,12 @@ protected:
public:
static MyPopup* create(std::string const& text) {
auto ret = new MyPopup();
if (ret && ret->init(240.f, 160.f, text)) {
if (ret->init(240.f, 160.f, text)) {
ret->autorelease();
return ret;
}
CC_SAFE_DELETE(ret);

delete ret;
return nullptr;
}
};
Expand Down Expand Up @@ -120,7 +121,7 @@ class $modify(MenuLayer) {
bool init() {
if (!MenuLayer::init())
return false;

FLAlertLayer::create(
"Title",
"Hi mom!",
Expand All @@ -137,7 +138,7 @@ class $modify(MenuLayer) {
bool init() {
if (!MenuLayer::init())
return false;

auto alert = FLAlertLayer::create(
"Title",
"Hi mom!",
Expand Down

0 comments on commit 11299d3

Please sign in to comment.