Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerceptiveGames committed Dec 15, 2024
1 parent 86875b6 commit 232121b
Show file tree
Hide file tree
Showing 19 changed files with 216 additions and 97 deletions.
3 changes: 3 additions & 0 deletions modules/pg_g1/core/pgn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
//}


PSA PGN_ST::_st;


bool PGN_ST::push_back(String file, String fn, int line) {
_st.append(vformat("%s:%s:%i", file.replace(PGN_Paths::get_modules_dir_path(), ""), fn, line));
return true;
Expand Down
5 changes: 5 additions & 0 deletions modules/pg_g1/core/pgn.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
// Add multiple slots instead of only doing +1 like append() does.
// Resize back at the end. Keep internal counter indicating count of actual valid values.
// - Try to avoid reassigning strings to new memory.
// - Check if passing String and Variant types by reference shows perf improvement.
// In fns where a param passed by value is modified in the fn body, we'll need to make
// a copy of that param first.


//////////////////////////////////////////////////
Expand Down Expand Up @@ -53,6 +56,8 @@ using Dict = Dictionary;
template <typename K, typename V>
using TD = TypedDictionary<K, V>;

template <typename V>
using HS = HashSet<V>;
template <typename K, typename V>
using HM = HashMap<K, V>;
template <typename K, typename V>
Expand Down
16 changes: 10 additions & 6 deletions modules/pg_g1/core/pgn_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//#include "core/variant/callable.h"
//#include "core/variant/variant.h"
#include "modules/pg_g1/core/pgn.h"
//#include "modules/pg_g1/utils/pgn_types.h"
#include "modules/pg_g1/utils/pgn_types.h"
//#include "pgn_cmds.h"
#include "core/variant/typed_dictionary.h"
#include "core/variant/typed_array.h"
Expand Down Expand Up @@ -59,7 +59,7 @@ void PGN_Cmds::send(Str cmd) {
}

Ref<PGN_Cmd> o = s->_commands[id];
TD<SN, Ref<PGN_Cmd>> deps;
HM<SN, Ref<PGN_Cmd>> deps;

for (SN dep : o->get_deps()) {
deps[dep] = s->_commands[dep];
Expand All @@ -79,23 +79,27 @@ Variant PGN_Cmds::get(Str id) {
//////////////////////////////////////////////////


TA<SN> &PGN_Cmd::get_deps() const {
//TA<SN> &PGN_Cmd::get_deps() {
HS<SN> &PGN_Cmd::get_deps() {
return _dependencies;
}


Ref<PGN_Cmd> PGN_Cmd::add_dep(SN dep) {
this->_dependencies.append(dep);
this->_dependencies.insert(dep);
return this;
}


//////////////////////////////////////////////////


void PGN_Cmd::call_send(const PSA &args, const TD<SN, Ref<PGN_Cmd>> &deps) const {
_f_send.call(args, deps);
//void PGN_Cmd::call_send(const PSA &args, const TD<SN, Ref<PGN_Cmd>> &deps) const {
void PGN_Cmd::call_send(const PSA &args, const HM<SN, Ref<PGN_Cmd>> &deps) const {
_f_send.call(args, PGN_Types::ref_to_dict<PGN_Cmd>(deps));
}
//Dictionary(const Dictionary &p_base, uint32_t p_key_type, const StringName &p_key_class_name,
// const Variant &p_key_script, uint32_t p_value_type, const StringName &p_value_class_name, const Variant &p_value_script);


Variant PGN_Cmd::call_get() const {
Expand Down
20 changes: 14 additions & 6 deletions modules/pg_g1/core/pgn_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//#include "core/variant/variant.h"
#include "modules/pg_g1/core/pgn.h"
//#include "modules/pg_g1/utils/pgn_types.h"
//#include "core/variant/typed_array.h"
#include "core/variant/typed_array.h"


//////////////////////////////////////////////////
Expand All @@ -33,7 +33,7 @@ class PGN_Cmd;
class PGN_Cmds : public RefCounted {
GDCLASS(PGN_Cmds, RefCounted);
PG_SMF(PGN_Cmds);
PG_BIND;
//PG_BIND;


//////////////////////////////////////////////////
Expand Down Expand Up @@ -69,11 +69,13 @@ class PGN_Cmd : public RefCounted {

protected:
SN _id;
TA<Str> _args;
//TA<Str> _args;
HS<Str> _args;
Str _title;
Str _desc;
Str _help;
TA<SN> _dependencies;
//TA<SN> _dependencies;
HS<SN> _dependencies;

bool _case_sensitive;

Expand All @@ -82,13 +84,15 @@ class PGN_Cmd : public RefCounted {


public:
TA<SN> &get_deps() const;
//TA<SN> &get_deps();
HS<SN> &get_deps();

Ref<PGN_Cmd> add_dep(SN dep);


public:
void call_send(const PSA &args, const TD<SN, Ref<PGN_Cmd>> &deps) const;
//void call_send(const PSA &args, const TD<SN, Ref<PGN_Cmd>> &deps) const;
void call_send(const PSA &args, const HM<SN, Ref<PGN_Cmd>> &deps) const;

Variant call_get() const;

Expand All @@ -97,6 +101,10 @@ class PGN_Cmd : public RefCounted {


public:
PGN_Cmd() :
_case_sensitive(false) {}


PGN_Cmd(Str id, const Callable &f_send, const Callable &f_get);
};

Expand Down
10 changes: 9 additions & 1 deletion modules/pg_g1/core/pgn_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
#include "pgn_timer.h"
//#include "pgw.h"
//#include "scene/main/scene_tree.h"
#include "core/object/script_language.h"
#include "scene/resources/packed_scene.h"


//////////////////////////////////////////////////
//////////////////////////////////////////////////


// TODO: Avoid unbind() in Callables, because it creates a new Callable.


//////////////////////////////////////////////////


PG_SI(PGN_FS);


Expand Down Expand Up @@ -229,7 +237,7 @@ PGN_FS::PGN_FS() {

PGN_FS::~PGN_FS() {
HashMap<String, Ref<FileAccess>>::Iterator it = _open_files.begin();
for (int i = 0; i < _open_files.size(); ++it, i++) {
for (uint32_t i = 0; i < _open_files.size(); ++it, i++) {
_pop_(close_file(_a_ it->key));
}

Expand Down
45 changes: 26 additions & 19 deletions modules/pg_g1/core/pgn_msgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
//////////////////////////////////////////////////


PG_SI(PGN_Msgr)


//////////////////////////////////////////////////
//////////////////////////////////////////////////


Ref<PGN_Msgs> PGN_Msgs::mk() {
return pg_mk_ref<PGN_Msgs>();
}
Expand Down Expand Up @@ -176,25 +183,25 @@ void PGN_MsgrTgt::send(Ref<PGN_Msg> msg) {
//////////////////////////////////////////////////


PGN_MsgrTgt::PGN_MsgrTgt(SN id, Callable &f, bool strip_bbcode, int min_lvl, int max_lvl, bool is_enabled) {
_id = id;
_f = f;

_strip_bbcode = strip_bbcode;
_min_lvl = min_lvl;
_max_lvl = max_lvl;

_is_enabled = is_enabled;
_is_ready = false;
//_buf_sz = buf_sz;

//if (buf_sz > 0) {
// _has_buf = true;
// _buf_min = buf_sz / 2;
// _buf_max = buf_sz;
// _buf.resize(_buf_max);
//}
}
//PGN_MsgrTgt::PGN_MsgrTgt(SN id, Callable &f, bool strip_bbcode, int min_lvl, int max_lvl, bool is_enabled) {
// _id = id;
// _f = f;
//
// _strip_bbcode = strip_bbcode;
// _min_lvl = min_lvl;
// _max_lvl = max_lvl;

// _is_enabled = is_enabled;
// _is_ready = false;
// //_buf_sz = buf_sz;
//
// //if (buf_sz > 0) {
// // _has_buf = true;
// // _buf_min = buf_sz / 2;
// // _buf_max = buf_sz;
// // _buf.resize(_buf_max);
// //}
//}


//////////////////////////////////////////////////
Expand Down
29 changes: 28 additions & 1 deletion modules/pg_g1/core/pgn_msgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,24 @@ class PGN_MsgrTgt : public RefCounted {


public:
PGN_MsgrTgt(SN id, Callable &f, bool strip_bbcode, int min_lvl, int max_lvl, bool is_enabled);
PGN_MsgrTgt() :
//_id(""),
//_f(Callable()),
_strip_bbcode(false),
_min_lvl(0),
_max_lvl(0),
_is_enabled(false),
_is_ready(false) {}


PGN_MsgrTgt(SN id, Callable &f, bool strip_bbcode, int min_lvl, int max_lvl, bool is_enabled) :
_id(id),
_f(f),
_strip_bbcode(strip_bbcode),
_min_lvl(min_lvl),
_max_lvl(max_lvl),
_is_enabled(is_enabled),
_is_ready(false) {}
};


Expand Down Expand Up @@ -185,9 +202,19 @@ class PGN_Msg : public RefCounted {

public:
static Ref<PGN_Msg> mk(_d_ PGE_MsgLevel lvl, StringName id, String txt, String str = "", Error e = Error::OK, Variant vrt = Variant::NIL);


//////////////////////////////////////////////////


public:
PGN_Msg() :
lvl(PGE_MsgLevel::NONE),
e(Error::OK) {}
};



//////////////////////////////////////////////////
//////////////////////////////////////////////////

Expand Down
15 changes: 15 additions & 0 deletions modules/pg_g1/core/pgn_scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "scene/main/window.h"
//#include "scene/resources/3d/world_3d.h"
#include "../utils/pgn_globals.h"
#include "scene/resources/3d/world_3d.h"
#include "scene/3d/camera_3d.h"


//////////////////////////////////////////////////
Expand Down Expand Up @@ -97,6 +99,18 @@ PGN_SceneTree::PGN_SceneTree() {
// or (2) init below, and then init 'es' and assign vars from s to 'es', and then get rid of s.


pgn_sys = pg_mk_ref<PGN_Sys>();
pgn_fs = pg_mk_ref<PGN_FS>();
//pgn_time = pg_mk_ref<PGN_Time>();
pgn_time = memnew(PGN_Time);
pgn_timers = pg_mk_ref<PGN_Timers>();
pgn_msgr = pg_mk_ref<PGN_Msgr>();

pgn_rgx = pg_mk_ref<PGN_Rgx>();
pgn_num = pg_mk_ref<PGN_Num>();

pgn_cmds = pg_mk_ref<PGN_Cmds>();


//pgn_fs.instantiate();
//pgn_msgr.instantiate();
Expand All @@ -105,6 +119,7 @@ PGN_SceneTree::PGN_SceneTree() {


PGN_SceneTree::~PGN_SceneTree() {
memdelete(pgn_time);
PG_SD;
}

Expand Down
34 changes: 18 additions & 16 deletions modules/pg_g1/core/pgn_scene_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
//#include "modules/pg_g1/utils/pgn_num.h"
//#include "modules/pg_g1/utils/pgn_rgx.h"
#include "pgn.h"
//#include "pgn_cmds.h"
//#include "pgn_fs.h"
//#include "pgn_msgr.h"
//#include "pgn_sys.h"
//#include "pgn_time.h"
//#include "pgn_timer.h"
#include "pgn_sys.h"
#include "pgn_fs.h"
#include "pgn_time.h"
#include "pgn_timer.h"
#include "pgn_msgr.h"
#include "../utils/pgn_rgx.h"
#include "../utils/pgn_num.h"
#include "pgn_cmds.h"
//#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
//#include "scene/main/viewport.h"
Expand Down Expand Up @@ -57,25 +59,25 @@ class PGN_SceneTree : public SceneTree {


protected:
Ref<PGN_Sys> pgn_sys = pg_mk_ref<PGN_Sys>();
Ref<PGN_FS> pgn_fs = pg_mk_ref<PGN_FS>();
Ref<PGN_Time> pgn_time = pg_mk_ref<PGN_Time>();
Ref<PGN_Timers> pgn_timers = pg_mk_ref<PGN_Timers>();
Ref<PGN_Msgr> pgn_msgr = pg_mk_ref<PGN_Msgr>();
Ref<PGN_Sys> pgn_sys;
Ref<PGN_FS> pgn_fs;
PGN_Time *pgn_time;
Ref<PGN_Timers> pgn_timers;
Ref<PGN_Msgr> pgn_msgr;

Ref<PGN_Rgx> pgn_rgx = pg_mk_ref<PGN_Rgx>();
Ref<PGN_Num> pgn_num = pg_mk_ref<PGN_Num>();
Ref<PGN_Rgx> pgn_rgx;
Ref<PGN_Num> pgn_num;

Ref<PGN_Cmds> pgn_cmds = pg_mk_ref<PGN_Cmds>();
Ref<PGN_Cmds> pgn_cmds;


//////////////////////////////////////////////////


public:
_FORCE_INLINE_ static Node *pg_get_root();
/*_FORCE_INLINE_*/ static Node *pg_get_root();

_FORCE_INLINE_ static bool pg_is_paused();
/*_FORCE_INLINE_*/ static bool pg_is_paused();


//////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion modules/pg_g1/core/pgn_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
// DOC: This class needs to inherit from Node to get per-frame notifications,
// thanks to 'PROCESS_MODE_ALWAYS'. We can't have the contents of this class
// in PGN_SceneTree, because its mode is 'PROCESS_MODE_WHEN_PAUSED',
// which shouldn't be changed.
// which shouldn't be changed because we don't want all SceneTree children nodes
// set to inherited process mode to execute their _process() fn.
class PGN_Time : public Node {
GDCLASS(PGN_Time, Node);
PG_SM(PGN_Time);
Expand Down
Loading

0 comments on commit 232121b

Please sign in to comment.