Skip to content

Commit dbb6dd0

Browse files
committed
MINOR: Added Frameworks for Debugger
1 parent d0cdedf commit dbb6dd0

File tree

2,418 files changed

+1143589
-5935
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,418 files changed

+1143589
-5935
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "Code/ThirdParty/JoltPhysics"]
2+
path = Code/ThirdParty/JoltPhysics
3+
url = https://github.com/jrouwe/JoltPhysics.git

Code/BuildSystem/CMake/CMakeUtils/nsUtilsVulkan.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# #####################################
22
# ## Vulkan support
33
# #####################################
4-
5-
set(NS_BUILD_EXPERIMENTAL_VULKAN OFF CACHE BOOL "Whether to enable experimental / work-in-progress Vulkan code")
4+
# NOTE: Forcing Vulkan on since JDebug Must be Cross-Platform.
5+
set(NS_BUILD_EXPERIMENTAL_VULKAN ON CACHE BOOL "Whether to enable experimental / work-in-progress Vulkan code")
66

77
# #####################################
88
# ## ns_requires_vulkan()

Code/Core/CMakeLists.txt

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
ns_cmake_init()
2+
3+
4+
5+
# Get the name of this folder as the project name
6+
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME_WE)
7+
8+
ns_create_target(LIBRARY ${PROJECT_NAME})
9+
10+
ns_enable_strict_warnings(${PROJECT_NAME})
11+
12+
target_link_libraries(${PROJECT_NAME}
13+
PUBLIC
14+
Foundation
15+
Texture
16+
17+
PRIVATE
18+
mikktspace
19+
)
20+
21+
if (NS_3RDPARTY_LUA_SUPPORT)
22+
23+
target_link_libraries(${PROJECT_NAME}
24+
PUBLIC
25+
Lua
26+
)
27+
28+
endif()
29+
30+
if (NS_3RDPARTY_DUKTAPE_SUPPORT)
31+
32+
target_link_libraries(${PROJECT_NAME}
33+
PUBLIC
34+
Duktape
35+
)
36+
37+
endif()
38+
39+
if(NS_3RDPARTY_GLFW_SUPPORT)
40+
41+
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
42+
43+
endif()

Code/Core/Console/Console.h

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#pragma once
2+
3+
#include <Core/Console/ConsoleFunction.h>
4+
#include <Foundation/Communication/Event.h>
5+
#include <Foundation/Configuration/CVar.h>
6+
#include <Foundation/Containers/Deque.h>
7+
#include <Foundation/Containers/Map.h>
8+
#include <Foundation/Containers/StaticArray.h>
9+
#include <Foundation/Strings/StringBuilder.h>
10+
#include <Foundation/Threading/Mutex.h>
11+
#include <Foundation/Types/RefCounted.h>
12+
#include <Foundation/Types/SharedPtr.h>
13+
14+
struct NS_CORE_DLL nsConsoleString
15+
{
16+
enum class Type : nsUInt8
17+
{
18+
Default,
19+
Error,
20+
SeriousWarning,
21+
Warning,
22+
Note,
23+
Success,
24+
Executed,
25+
VarName,
26+
FuncName,
27+
Dev,
28+
Debug,
29+
};
30+
31+
Type m_Type = Type::Default;
32+
nsString m_sText;
33+
nsColor GetColor() const;
34+
35+
bool operator<(const nsConsoleString& rhs) const { return m_sText < rhs.m_sText; }
36+
};
37+
38+
struct NS_CORE_DLL nsCommandInterpreterState
39+
{
40+
nsStringBuilder m_sInput;
41+
nsHybridArray<nsConsoleString, 16> m_sOutput;
42+
43+
void AddOutputLine(const nsFormatString& text, nsConsoleString::Type type = nsConsoleString::Type::Default);
44+
};
45+
46+
class NS_CORE_DLL nsCommandInterpreter : public nsRefCounted
47+
{
48+
public:
49+
virtual void Interpret(nsCommandInterpreterState& inout_state) = 0;
50+
51+
virtual void AutoComplete(nsCommandInterpreterState& inout_state);
52+
53+
/// \brief Iterates over all cvars and finds all that start with the string \a szVariable.
54+
static void FindPossibleCVars(nsStringView sVariable, nsDeque<nsString>& ref_commonStrings, nsDeque<nsConsoleString>& ref_consoleStrings);
55+
56+
/// \brief Iterates over all console functions and finds all that start with the string \a szVariable.
57+
static void FindPossibleFunctions(nsStringView sVariable, nsDeque<nsString>& ref_commonStrings, nsDeque<nsConsoleString>& ref_consoleStrings);
58+
59+
/// \brief Returns the prefix string that is common to all strings in the \a vStrings array.
60+
static const nsString FindCommonString(const nsDeque<nsString>& strings);
61+
};
62+
63+
/// \brief The event data that is broadcast by the console
64+
struct nsConsoleEvent
65+
{
66+
enum class Type : nsInt32
67+
{
68+
OutputLineAdded, ///< A string was added to the console
69+
};
70+
71+
Type m_Type;
72+
73+
/// \brief The console string that was just added.
74+
const nsConsoleString* m_AddedpConsoleString;
75+
};
76+
77+
class NS_CORE_DLL nsConsole
78+
{
79+
public:
80+
nsConsole();
81+
virtual ~nsConsole();
82+
83+
/// \name Events
84+
/// @{
85+
86+
public:
87+
/// \brief Grants access to subscribe and unsubscribe from console events.
88+
const nsEvent<const nsConsoleEvent&>& Events() const { return m_Events; }
89+
90+
protected:
91+
/// \brief The console event variable, to attach to.
92+
nsEvent<const nsConsoleEvent&> m_Events;
93+
94+
/// @}
95+
96+
/// \name Helpers
97+
/// @{
98+
99+
public:
100+
/// \brief Returns the mutex that's used to prevent multi-threaded access
101+
nsMutex& GetMutex() const { return m_Mutex; }
102+
103+
static void SetMainConsole(nsConsole* pConsole);
104+
static nsConsole* GetMainConsole();
105+
106+
protected:
107+
mutable nsMutex m_Mutex;
108+
109+
private:
110+
static nsConsole* s_pMainConsole;
111+
112+
/// @}
113+
114+
/// \name Command Interpreter
115+
/// @{
116+
117+
public:
118+
/// \brief Replaces the current command interpreter.
119+
///
120+
/// This base class doesn't set any default interpreter, but derived classes may do so.
121+
void SetCommandInterpreter(const nsSharedPtr<nsCommandInterpreter>& pInterpreter) { m_pCommandInterpreter = pInterpreter; }
122+
123+
/// \brief Returns the currently used command interpreter.
124+
const nsSharedPtr<nsCommandInterpreter>& GetCommandInterpreter() const { return m_pCommandInterpreter; }
125+
126+
/// \brief Auto-completes the given text.
127+
///
128+
/// Returns true, if the string was modified in any way.
129+
/// Adds additional strings to the console output, if there are further auto-completion suggestions.
130+
virtual bool AutoComplete(nsStringBuilder& ref_sText);
131+
132+
/// \brief Executes the given input string.
133+
///
134+
/// The command is forwarded to the set command interpreter.
135+
virtual void ExecuteCommand(nsStringView sInput);
136+
137+
protected:
138+
nsSharedPtr<nsCommandInterpreter> m_pCommandInterpreter;
139+
140+
/// @}
141+
142+
/// \name Console Display
143+
/// @{
144+
145+
public:
146+
/// \brief Adds a string to the console.
147+
///
148+
/// The base class only broadcasts an event, but does not store the string anywhere.
149+
virtual void AddConsoleString(nsStringView sText, nsConsoleString::Type type = nsConsoleString::Type::Default);
150+
151+
/// @}
152+
153+
/// \name Input History
154+
/// @{
155+
156+
public:
157+
/// \brief Adds an item to the input history.
158+
void AddToInputHistory(nsStringView sText);
159+
160+
/// \brief Returns the current input history.
161+
///
162+
/// Make sure to lock the console's mutex while working with the history.
163+
const nsStaticArray<nsString, 16>& GetInputHistory() const { return m_InputHistory; }
164+
165+
/// \brief Replaces the input line by the next (or previous) history item.
166+
void RetrieveInputHistory(nsInt32 iHistoryUp, nsStringBuilder& ref_sResult);
167+
168+
/// \brief Writes the current input history to a text file.
169+
nsResult SaveInputHistory(nsStringView sFile);
170+
171+
/// \brief Reads the text file and appends all lines to the input history.
172+
void LoadInputHistory(nsStringView sFile);
173+
174+
protected:
175+
nsInt32 m_iCurrentInputHistoryElement = -1;
176+
nsStaticArray<nsString, 16> m_InputHistory;
177+
178+
/// @}
179+
};

Code/Core/Console/ConsoleFunction.h

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#pragma once
2+
3+
#include <Core/CoreDLL.h>
4+
#include <Foundation/Types/Delegate.h>
5+
#include <Foundation/Types/Variant.h>
6+
#include <Foundation/Utilities/EnumerableClass.h>
7+
8+
/// \brief Base class for all types of nsConsoleFunction, represents functions to be exposed to nsConsole.
9+
///
10+
/// Console functions are similar to nsCVar's in that they can be executed from the nsConsole.
11+
/// A console function can wrap many different types of functions with differing number and types of parameters.
12+
/// nsConsoleFunction uses an nsDelegate internally to store the function reference, so even member functions would be possible.
13+
///
14+
/// All console functions are enumerable, as their base class nsConsoleFunctionBase is an nsEnumerable class.
15+
///
16+
/// Console functions can have between zero and six parameters. The LuaInterpreter for nsConsole only supports parameter types
17+
/// (unsigned) int, float/double, bool and string and uses the conversion feature of nsVariant to map the lua input to the final function.
18+
///
19+
/// To make a function available as a console function, create a global variable of type nsConsoleFunction with the proper template
20+
/// arguments to mirror its parameters and return type.
21+
/// Note that although functions with return types are accepted, the return value is currently always ignored.
22+
///
23+
/// \code{.cpp}
24+
/// void MyConsoleFunc1(int a, float b, nsStringView sz) { ... }
25+
/// nsConsoleFunction<void ()> ConFunc_MyConsoleFunc1("MyConsoleFunc1", "()", MyConsoleFunc1);
26+
///
27+
/// int MyConsoleFunc2(int a, float b, nsStringView sz) { ... }
28+
/// nsConsoleFunction<int (int, float, nsString)> ConFunc_MyConsoleFunc2("MyConsoleFunc2", "(int a, float b, string c)", MyConsoleFunc2);
29+
/// \endcode
30+
///
31+
/// Here the global function MyConsoleFunc2 is exposed to the console. The return value type and parameter types are passed as template
32+
/// arguments. ConFunc_MyConsoleFunc2 is now the global variable that represents the function for the console.
33+
/// The first string is the name with which the function is exposed, which is also used for auto-completion.
34+
/// The second string is the description of the function. Here we inserted the parameter list with types, so that the user knows how to
35+
/// use it. Finally the last parameter is the actual function to expose.
36+
class NS_CORE_DLL nsConsoleFunctionBase : public nsEnumerable<nsConsoleFunctionBase>
37+
{
38+
NS_DECLARE_ENUMERABLE_CLASS(nsConsoleFunctionBase);
39+
40+
public:
41+
/// \brief The constructor takes the function name and description as it should appear in the console.
42+
nsConsoleFunctionBase(nsStringView sFunctionName, nsStringView sDescription)
43+
: m_sFunctionName(sFunctionName)
44+
, m_sDescription(sDescription)
45+
{
46+
}
47+
48+
/// \brief Returns the name of the function as it should be exposed in the console.
49+
nsStringView GetName() const { return m_sFunctionName; }
50+
51+
/// \brief Returns the description of the function as it should appear in the console.
52+
nsStringView GetDescription() const { return m_sDescription; }
53+
54+
/// \brief Returns the number of parameters that this function takes.
55+
virtual nsUInt32 GetNumParameters() const = 0;
56+
57+
/// \brief Returns the type of the n-th parameter.
58+
virtual nsVariant::Type::Enum GetParameterType(nsUInt32 uiParam) const = 0;
59+
60+
/// \brief Calls the function. Each parameter must be put into an nsVariant and all of them are passed along as an array.
61+
///
62+
/// Returns NS_FAILURE, if the number of parameters did not match, or any parameter was not convertible to the actual type that
63+
/// the function expects.
64+
virtual nsResult Call(nsArrayPtr<nsVariant> params) = 0;
65+
66+
private:
67+
nsStringView m_sFunctionName;
68+
nsStringView m_sDescription;
69+
};
70+
71+
72+
/// \brief Implements the functionality of nsConsoleFunctionBase for functions with different parameter types. See nsConsoleFunctionBase for more
73+
/// details.
74+
template <typename R>
75+
class nsConsoleFunction : public nsConsoleFunctionBase
76+
{
77+
};
78+
79+
80+
#define ARG_COUNT 0
81+
#include <Core/Console/Implementation/ConsoleFunctionHelper_inl.h>
82+
#undef ARG_COUNT
83+
84+
#define ARG_COUNT 1
85+
#include <Core/Console/Implementation/ConsoleFunctionHelper_inl.h>
86+
#undef ARG_COUNT
87+
88+
#define ARG_COUNT 2
89+
#include <Core/Console/Implementation/ConsoleFunctionHelper_inl.h>
90+
#undef ARG_COUNT
91+
92+
#define ARG_COUNT 3
93+
#include <Core/Console/Implementation/ConsoleFunctionHelper_inl.h>
94+
#undef ARG_COUNT
95+
96+
#define ARG_COUNT 4
97+
#include <Core/Console/Implementation/ConsoleFunctionHelper_inl.h>
98+
#undef ARG_COUNT
99+
100+
#define ARG_COUNT 5
101+
#include <Core/Console/Implementation/ConsoleFunctionHelper_inl.h>
102+
#undef ARG_COUNT
103+
104+
#define ARG_COUNT 6
105+
#include <Core/Console/Implementation/ConsoleFunctionHelper_inl.h>
106+
#undef ARG_COUNT

0 commit comments

Comments
 (0)