Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
PerceptiveGames committed Jan 9, 2025
1 parent ef04112 commit e51b6e1
Show file tree
Hide file tree
Showing 38 changed files with 516 additions and 180 deletions.
2 changes: 1 addition & 1 deletion modules/pg_g1/2d/pg_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "modules/pg_g1/2d/pg_console.h"
#include "modules/pg_g1/core/pg_cmds.h"
#include "modules/pg_g1/core/pg_msgr.h"
#include "modules/pg_g1/core/pg_scene_tree.h"
#include "modules/pg_g1/core/pg_scene_tree.h" // NOTE: Is used.
#include "modules/pg_g1/core/pg_timers.h"
#include "modules/pg_g1/data/pg_macros.h"
#include "modules/pg_g1/exts/pg_str.h"
Expand Down
12 changes: 6 additions & 6 deletions modules/pg_g1/core/pg_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
//////////////////////////////////////////////////


Ref<PG_Cmd> PG_Cmds::mk_cmd(String id, const Callable &f_send, const Callable &f_get) {
_commands[id] = PG_Types::mk_ref<PG_Cmd>(id, f_send, f_get);
Ref<PG_Cmd> PG_Cmds::mk_cmd(String id, const Callable &f_send, const Callable &f_recv) {
_commands[id] = PG_Types::mk_ref<PG_Cmd>(id, f_send, f_recv);
return _commands[id];
}

Expand Down Expand Up @@ -71,7 +71,7 @@ Ref<PG_Cmds> PG_Cmds::mk() {

void PG_Cmds::_bind_methods() {
#ifdef PG_GD_FNS
ClassDB::bind_method(D_METHOD("mk_cmd", "id", "f_send", "f_get"), &PG_Cmds::mk_cmd);
ClassDB::bind_method(D_METHOD("mk_cmd", "id", "f_send", "f_recv"), &PG_Cmds::mk_cmd);

ClassDB::bind_method(D_METHOD("send", "cmd"), &PG_Cmds::send);
ClassDB::bind_method(D_METHOD("receive", "id"), &PG_Cmds::receive);
Expand All @@ -89,7 +89,7 @@ void PG_Cmd::call_send(const Vector<String> &args) const {


Variant PG_Cmd::call_receive() const {
return _f_get.call();
return _f_recv.call();
}


Expand All @@ -100,10 +100,10 @@ PG_Cmd::PG_Cmd() :
_case_sensitive(false) {}


PG_Cmd::PG_Cmd(String id, const Callable &f_send, const Callable &f_get) :
PG_Cmd::PG_Cmd(String id, const Callable &f_send, const Callable &f_recv) :
_id(id),
_f_send(f_send),
_f_get(f_get),
_f_recv(f_recv),
_case_sensitive(false) {}


Expand Down
6 changes: 3 additions & 3 deletions modules/pg_g1/core/pg_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PG_Cmds : public RefCounted {


public:
Ref<PG_Cmd> mk_cmd(String id, const Callable &f_send, const Callable &f_get);
Ref<PG_Cmd> mk_cmd(String id, const Callable &f_send, const Callable &f_recv);


//////////////////////////////////////////////////
Expand Down Expand Up @@ -89,7 +89,7 @@ class PG_Cmd : public RefCounted {
bool _case_sensitive;

Callable _f_send;
Callable _f_get;
Callable _f_recv;


protected:
Expand All @@ -102,7 +102,7 @@ class PG_Cmd : public RefCounted {

public:
PG_Cmd();
PG_Cmd(String id, const Callable &f_send, const Callable &f_get);
PG_Cmd(String id, const Callable &f_send, const Callable &f_recv);
};


Expand Down
4 changes: 2 additions & 2 deletions modules/pg_g1/core/pg_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Ref<FileAccess> PG_FS::open_file(String path, bool create_if_none, bool auto_clo
timer = _open_files_timers[path];
_st_(timer->restart());
} else {
timer = _timers->simple(nullptr, pg_file_auto_close_delay, callable_mp(this, &PG_FS::close_file).unbind(1).bind(path));
timer = _timers->simple(nullptr, PG_Const::file_auto_close_delay, callable_mp(this, &PG_FS::close_file).unbind(1).bind(path));
_st_(timer->start());
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ void PG_FileLogger::_delete_old_logs() {
if (!paths->ok()) {
return;
}
for (int i = 0; i < paths->r().size() - pg_max_log_files; ++i) {
for (int i = 0; i < paths->r().size() - PG_Const::max_log_files; ++i) {
if (Error e = DirAccess::remove_absolute(paths->r()[i])) {
_st_(_msgr->bcast(PGE_MsgLevel::WARNING, "RM_FILE", e, paths->r()[i]));
}
Expand Down
24 changes: 18 additions & 6 deletions modules/pg_g1/core/pg_msgr.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "core/error/error_list.h"
#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/object/class_db.h"
#include "core/object/ref_counted.h"
#include "core/string/string_name.h"
#include "core/string/ustring.h"
Expand All @@ -13,8 +14,9 @@
#include "modules/pg_g1/data/pg_macros.h"
#include "modules/pg_g1/exts/pg_arr.h"
#include "modules/pg_g1/exts/pg_sn.h"
#include "modules/pg_g1/types/pg_types.h"
#include "modules/pg_g1/exts/pg_str.h"
#include "modules/pg_g1/exts/pg_vec.h"
#include "modules/pg_g1/types/pg_types.h"


//////////////////////////////////////////////////
Expand Down Expand Up @@ -243,8 +245,8 @@ Ref<PG_Msg> PG_Msgr::bcast(Ref<PG_Msg> msg) {


#ifdef PG_GD_FNS
Ref<PG_Msg> PG_Msgr::_gd_bcast(PGE_MsgLevel lvl, Vector<StringName> tgts, StringName id, Error e, TypedArray<String> strs) {
return bcast(lvl, tgts, id, e, strs);
Ref<PG_Msg> PG_Msgr::_gd_bcast(PGE_MsgLevel lvl, TypedArray<StringName> tgts, StringName id, Error e, TypedArray<String> strs) {
return bcast(lvl, PG_Vec::from_typed_arr<StringName>(tgts), id, e, strs);
}
#endif

Expand All @@ -254,8 +256,19 @@ Ref<PG_Msg> PG_Msgr::_gd_bcast(PGE_MsgLevel lvl, Vector<StringName> tgts, String

void PG_Msgr::_bind_methods() {
#ifdef PG_GD_FNS
// TODO: UNCOMMENT AND FIX.
//ClassDB::bind_static_method("PG_Msgr", D_METHOD("bcast", "lvl", "id", "str", "e", "vrt"), &PG_Msgr::_gd_bcast, DEFVAL(""), DEFVAL(Error::OK), DEFVAL(Variant::NIL));
ClassDB::bind_method(D_METHOD("bcast", "lvl", "tgts", "id", "e", "strs"), &PG_Msgr::_gd_bcast);
//, DEFVAL(""), DEFVAL(Error::OK), DEFVAL(Variant::NIL)


BIND_ENUM_CONSTANT(NONE);
BIND_ENUM_CONSTANT(INPUT);
BIND_ENUM_CONSTANT(INFO);
BIND_ENUM_CONSTANT(WARNING);
BIND_ENUM_CONSTANT(ERROR);
BIND_ENUM_CONSTANT(INPUT_VIP);
BIND_ENUM_CONSTANT(INFO_VIP);
BIND_ENUM_CONSTANT(WARNING_VIP);
BIND_ENUM_CONSTANT(FATAL);
#endif
}

Expand All @@ -267,7 +280,6 @@ Ref<PG_Msgr> PG_Msgr::mk() {

PG_Msgr::PG_Msgr() {
_msgs = PG_Msgs::mk();

}


Expand Down
10 changes: 9 additions & 1 deletion modules/pg_g1/core/pg_msgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/templates/vmap.h"
#include "core/variant/binder_common.h"
#include "modules/pg_g1/data/pg_macros.h"
#include "modules/pg_g1/types/pg_typedefs.h"

Expand Down Expand Up @@ -141,7 +142,7 @@ class PG_Msgr : public RefCounted {
Ref<PG_Msg> bcast(PGE_MsgLevel lvl, Vector<StringName> tgts, StringName id, Error e, TypedArray<String> strs);

#ifdef PG_GD_FNS
Ref<PG_Msg> _gd_bcast(PGE_MsgLevel lvl, Vector<StringName> tgts, StringName id, Error e, TypedArray<String> strs);
Ref<PG_Msg> _gd_bcast(PGE_MsgLevel lvl, TypedArray<StringName> tgts, StringName id, Error e, TypedArray<String> strs);
#endif


Expand Down Expand Up @@ -234,4 +235,11 @@ class PG_Msg : public RefCounted {
//////////////////////////////////////////////////


VARIANT_ENUM_CAST(PGE_MsgLevel);


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


#endif // PG_MSGR_H
26 changes: 19 additions & 7 deletions modules/pg_g1/core/pg_scene_tree.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "core/object/class_db.h"
#include "core/object/ref_counted.h"
#include "core/os/memory.h"
#include "editor/editor_interface.h"
Expand Down Expand Up @@ -124,17 +125,28 @@ Vector2 PG_SceneTree::get_mouse_pos(int ed_idx) {

void PG_SceneTree::_bind_methods() {
#ifdef PG_GD_FNS
// TODO: No longer static.
//ClassDB::bind_static_method("PG_SceneTree", D_METHOD("pg_get_viewport", "ed_idx"), &PG_SceneTree::pg_get_viewport, DEFVAL(0));
//ClassDB::bind_static_method("PG_SceneTree", D_METHOD("get_world_3d", "ed_idx"), &PG_SceneTree::get_world_3d, DEFVAL(0));
//ClassDB::bind_static_method("PG_SceneTree", D_METHOD("get_main_cam", "ed_idx"), &PG_SceneTree::get_main_cam, DEFVAL(0));
//ClassDB::bind_static_method("PG_SceneTree", D_METHOD("get_mouse_pos", "ed_idx"), &PG_SceneTree::get_mouse_pos, DEFVAL(0));
ClassDB::bind_static_method("PG_SceneTree", D_METHOD("get_pg_scene_tree"), &PG_SceneTree::get_PG_SceneTree);
ClassDB::bind_method(D_METHOD("get_pg_sys"), &PG_SceneTree::get_PG_Sys);
ClassDB::bind_method(D_METHOD("get_pg_fs"), &PG_SceneTree::get_PG_FS);
ClassDB::bind_method(D_METHOD("get_pg_time"), &PG_SceneTree::get_PG_Time);
ClassDB::bind_method(D_METHOD("get_pg_timers"), &PG_SceneTree::get_PG_Timers);
ClassDB::bind_method(D_METHOD("get_pg_msgr"), &PG_SceneTree::get_PG_Msgr);
ClassDB::bind_method(D_METHOD("get_pg_cmds"), &PG_SceneTree::get_PG_Cmds);
ClassDB::bind_method(D_METHOD("get_pg_"), &PG_SceneTree::get_PG_SgnsUser);

ClassDB::bind_method(D_METHOD("pg_get_root"), &PG_SceneTree::pg_get_root);
ClassDB::bind_method(D_METHOD("pg_is_paused"), &PG_SceneTree::pg_is_paused);

ClassDB::bind_method(D_METHOD("pg_get_viewport", "ed_idx"), &PG_SceneTree::pg_get_viewport, DEFVAL(0));
ClassDB::bind_method(D_METHOD("get_world_3d", "ed_idx"), &PG_SceneTree::get_world_3d, DEFVAL(0));
ClassDB::bind_method(D_METHOD("get_main_cam", "ed_idx"), &PG_SceneTree::get_main_cam, DEFVAL(0));
ClassDB::bind_method(D_METHOD("get_mouse_pos", "ed_idx"), &PG_SceneTree::get_mouse_pos, DEFVAL(0));
#endif
}


PG_SceneTree::PG_SceneTree() {
// TODO:
// TODO (OLD?):
// For each singleton s below
// If in-editor singleton 'es' inheriting from s exists
// Get singleton 'es' and assign it to the field assigned to s
Expand All @@ -144,7 +156,7 @@ PG_SceneTree::PG_SceneTree() {
// Since 'es' does not exist at this point in the ctor, either (1) defer assignment of 'es' to s,
// or (2) init below, and then init 'es' and assign vars from s to 'es', and then get rid of s.

// TODO: Maybe have sys, fs, time, timers, msgr, cmds not be singletons and be members of 'sys' or new 'core'
// TODO (OLD?): Maybe have sys, fs, time, timers, msgr, cmds not be singletons and be members of 'sys' or new 'core'
// singleton instead. rgx, num can be members of a new exts singleton.

_singleton = this;
Expand Down
6 changes: 3 additions & 3 deletions modules/pg_g1/core/pg_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "modules/pg_g1/core/pg_sys.h"
#include "modules/pg_g1/types/pg_types.h"
#include "scene/main/node.h"
#include "core/object/class_db.h"


//////////////////////////////////////////////////
Expand All @@ -26,9 +27,8 @@ void PG_Sys::force_quit() {

void PG_Sys::_bind_methods() {
#ifdef PG_GD_FNS
// TODO: Not static anymore
//ClassDB::bind_static_method("PG_Sys", D_METHOD("quit"), &PG_Sys::quit);
//ClassDB::bind_static_method("PG_Sys", D_METHOD("force_quit"), &PG_Sys::force_quit);
ClassDB::bind_method(D_METHOD("quit"), &PG_Sys::quit);
ClassDB::bind_method(D_METHOD("force_quit"), &PG_Sys::force_quit);
#endif
}

Expand Down
7 changes: 6 additions & 1 deletion modules/pg_g1/core/pg_time.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "core/config/engine.h"
#include "core/error/error_list.h"
#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/os/time.h"
#include "core/string/string_name.h"
Expand Down Expand Up @@ -96,8 +97,12 @@ void PG_Time::_notification(int p_what) {


void PG_Time::_bind_methods() {
ADD_SIGNAL(MethodInfo("process", PropertyInfo(Variant::INT, "delta")));
ClassDB::bind_method(D_METHOD("get_delta_usec"), &PG_Time::get_delta_usec);
ClassDB::bind_method(D_METHOD("connect_to_ticker", "f"), &PG_Time::connect_to_ticker);
ClassDB::bind_method(D_METHOD("get_time_scale", "id"), &PG_Time::get_time_scale);
ClassDB::bind_method(D_METHOD("set_time_scale", "id", "v"), &PG_Time::set_time_scale);

ADD_SIGNAL(MethodInfo("process", PropertyInfo(Variant::INT, "delta")));
//ADD_SIGNAL(MethodInfo("frame_started_0"));
//ADD_SIGNAL(MethodInfo("frame_started_1"));
//ADD_SIGNAL(MethodInfo("frame_started_2"));
Expand Down
48 changes: 38 additions & 10 deletions modules/pg_g1/core/pg_timers.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "core/object/callable_method_pointer.h"
#include "core/object/class_db.h"
#include "core/object/ref_counted.h"
#include "core/templates/vector.h"
#include "core/variant/callable.h"
Expand Down Expand Up @@ -75,31 +76,31 @@ bool PG_TimerUnit::_update(PG_Time *time, int delta) {
//////////////////////////////////////////////////


Ref<PG_Timer> PG_Timer::initial_delay(float initial_delay) {
_initial_delay = initial_delay;
Ref<PG_Timer> PG_Timer::set_initial_delay(const float d) {
_initial_delay = d;
return this;
}


Ref<PG_Timer> PG_Timer::time_scale_id(Variant time_scale_id) {
_time_scale_id = time_scale_id;
Ref<PG_Timer> PG_Timer::set_time_scale_id(const Variant &id) {
_time_scale_id = id;
return this;
}


Ref<PG_Timer> PG_Timer::process_mode(Node::ProcessMode process_mode) {
Ref<PG_Timer> PG_Timer::set_process_mode(const Node::ProcessMode m) {
#if PG_BUILD_LEVEL < PG_RELEASE
if (process_mode == Node::PROCESS_MODE_INHERIT && !_process_mode_parent) {
if (m == Node::PROCESS_MODE_INHERIT && !_process_mode_parent) {
_st_(_msgr->bcast(PGE_MsgLevel::ERROR, "TIMER_INSTANCE_PROCESS_MODE", to_string()));
}
#endif // DEBUG_PUBLIC
#endif // PG_BUILD_LEVEL < PG_RELEASE

_process_mode = process_mode;
_process_mode = m;
return this;
}


const bool PG_Timer::is_persistent() const {
bool PG_Timer::is_persistent() const {
return _persistent;
}

Expand Down Expand Up @@ -286,13 +287,29 @@ void PG_Timer::_setup_process_mode(Node *process_mode_parent) {
_process_mode_parent = process_mode_parent;
_process_mode = Node::PROCESS_MODE_INHERIT;
}
// DOC: Else: Keep default, which is 'PROCESS_MODE_PAUSABLE'.
// DOC: Else: Keeps default, which is 'PROCESS_MODE_PAUSABLE'.
}


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


void PG_Timer::_bind_methods() {
#ifdef PG_GD_FNS
ClassDB::bind_method(D_METHOD("set_initial_delay", "d"), &PG_Timer::set_initial_delay);
ClassDB::bind_method(D_METHOD("set_time_scale_id", "id"), &PG_Timer::set_time_scale_id);
ClassDB::bind_method(D_METHOD("set_process_mode", "m"), &PG_Timer::set_process_mode);
ClassDB::bind_method(D_METHOD("is_persistent"), &PG_Timer::is_persistent);

ClassDB::bind_method(D_METHOD("start"), &PG_Timer::start);
ClassDB::bind_method(D_METHOD("pause"), &PG_Timer::pause);
ClassDB::bind_method(D_METHOD("resume"), &PG_Timer::resume);
ClassDB::bind_method(D_METHOD("restart"), &PG_Timer::restart);
ClassDB::bind_method(D_METHOD("cancel"), &PG_Timer::cancel);
#endif
}


PG_Timer::PG_Timer() {
_pulse_interval = -1.0f;
_pulse_count = -INFINITY;
Expand Down Expand Up @@ -462,6 +479,17 @@ void PG_Timers::process(int delta) {

void PG_Timers::_bind_methods() {
#ifdef PG_GD_FNS
ClassDB::bind_method(D_METHOD("simple", "process_mode_parent", "finish_delay", "finish_f"), &PG_Timers::simple);
ClassDB::bind_method(D_METHOD("simple_pulse", "process_mode_parent", "pulse_count", "pulse_f", "finish_delay", "finish_f"), &PG_Timers::simple_pulse);
ClassDB::bind_method(D_METHOD("pulse", "process_mode_parent", "pulse_interval", "pulse_count", "pulse_f", "finish_f"), &PG_Timers::pulse);
ClassDB::bind_method(D_METHOD("infinite", "process_mode_parent", "pulse_interval", "pulse_f"), &PG_Timers::infinite);

ClassDB::bind_method(D_METHOD("simple_persistent", "process_mode_parent", "finish_delay", "finish_f"), &PG_Timers::simple_persistent);
ClassDB::bind_method(D_METHOD("simple_pulse_persistent", "process_mode_parent", "pulse_count", "pulse_f", "finish_delay", "finish_f"), &PG_Timers::simple_pulse_persistent);
ClassDB::bind_method(D_METHOD("pulse_persistent", "process_mode_parent", "pulse_interval", "pulse_count", "pulse_f", "finish_f"), &PG_Timers::pulse_persistent);
ClassDB::bind_method(D_METHOD("infinite_persistent", "process_mode_parent", "pulse_interval", "pulse_f"), &PG_Timers::infinite_persistent);

ClassDB::bind_method(D_METHOD("deferred_one_shot", "process_mode_parent", "f"), &PG_Timers::deferred_one_shot);
#endif
}

Expand Down
Loading

0 comments on commit e51b6e1

Please sign in to comment.