Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include "Headers/GUIConsoleCommandParser.h"

#include "Headers/GUI.h"
#include "Core/Headers/ParamHandler.h"
#include "Core/Headers/PlatformContext.h"
#include "Managers/Headers/SceneManager.h"
#include "Core/Resources/Headers/ResourceCache.h"
#include "AI/PathFinding/NavMeshes/Headers/NavMesh.h"  ///< For NavMesh creation
#include "Platform/Video/Shaders/Headers/ShaderProgram.h"

#include "Geometry/Shapes/Headers/Mesh.h"
#include "Geometry/Shapes/Headers/Predefined/Box3D.h"
#include "Geometry/Shapes/Headers/Predefined/Sphere3D.h"

namespace Divide {

GUIConsoleCommandParser::GUIConsoleCommandParser(PlatformContext& context, ResourceCache& cache)
    : _context(context),
      _resCache(cache),
      _sound(nullptr)
{
    _commandMap[_ID("say")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handleSayCommand, this,
                      std::placeholders::_1);
    _commandMap[_ID("quit")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handleQuitCommand, this,
                      std::placeholders::_1);
    _commandMap[_ID("help")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handleHelpCommand, this,
                      std::placeholders::_1);
    _commandMap[_ID("editparam")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handleEditParamCommand, this,
                      std::placeholders::_1);
    _commandMap[_ID("playsound")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handlePlaySoundCommand, this,
                      std::placeholders::_1);
    _commandMap[_ID("createnavmesh")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handleNavMeshCommand, this,
                      std::placeholders::_1);
    _commandMap[_ID("setfov")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handleFOVCommand, this,
                      std::placeholders::_1);
    _commandMap[_ID("invalidcommand")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handleInvalidCommand, this,
                      std::placeholders::_1);
    _commandMap[_ID("addobject")] = DELEGATE_BIND(
        &GUIConsoleCommandParser::handleAddObject, this, std::placeholders::_1);
    _commandMap[_ID("recompileshader")] =
        DELEGATE_BIND(&GUIConsoleCommandParser::handleShaderRecompileCommand,
                      this, std::placeholders::_1);

    _commandHelp[_ID("say")] = Locale::get(_ID("CONSOLE_SAY_COMMAND_HELP"));
    _commandHelp[_ID("quit")] = Locale::get(_ID("CONSOLE_QUIT_COMMAND_HELP"));
    _commandHelp[_ID("help")] = Locale::get(_ID("CONSOLE_HELP_COMMAND_HELP"));
    _commandHelp[_ID("editparam")] = Locale::get(_ID("CONSOLE_EDITPARAM_COMMAND_HELP"));
    _commandHelp[_ID("playsound")] = Locale::get(_ID("CONSOLE_PLAYSOUND_COMMAND_HELP"));
    _commandHelp[_ID("createnavmesh")] = Locale::get(_ID("CONSOLE_NAVMESH_COMMAND_HELP"));
    _commandHelp[_ID("recompileshader")] = Locale::get(_ID("CONSOLE_SHADER_RECOMPILE_COMMAND_HELP"));
    _commandHelp[_ID("setfov")] = Locale::get(_ID("CONSOLE_CHANGE_FOV_COMMAND_HELP"));
    _commandHelp[_ID("addObject")] = Locale::get(_ID("CONSOLE_ADD_OBJECT_COMMAND_HELP"));
    _commandHelp[_ID("invalidhelp")] = Locale::get(_ID("CONSOLE_INVALID_HELP_ARGUMENT"));
}

GUIConsoleCommandParser::~GUIConsoleCommandParser()
{
}

bool GUIConsoleCommandParser::processCommand(const stringImpl& commandString) {
    // Be sure we have a string longer than 0
    if (commandString.length() >= 1) {
        // Check if the first letter is a 'command' operator
        if (commandString.at(0) == '/') {
            stringImpl::size_type commandEnd = commandString.find(" ", 1);
            stringImpl command = commandString.substr(1, commandEnd - 1);
            stringImpl commandArgs = commandString.substr(
                commandEnd + 1, commandString.length() - (commandEnd + 1));
            if (commandString.compare(commandArgs) == 0) commandArgs.clear();
            // convert command to lower case
            for (stringImpl::size_type i = 0; i < command.length(); i++) {
                command[i] = static_cast<char>(tolower(command[i]));
            }
            if (_commandMap.find(_ID_RT(command)) != std::end(_commandMap)) {
                // we have a valid command
                _commandMap[_ID_RT(command)](commandArgs);
            } else {
                // invalid command
                _commandMap[_ID("invalidcommand")](command);
            }
        } else {
            Console::printfn(
                "%s", commandString
                          .c_str());  // no commands, just output what was typed
        }
    }
    return true;
}

void GUIConsoleCommandParser::handleSayCommand(const stringImpl& args) {
    Console::printfn(Locale::get(_ID("CONSOLE_SAY_NAME_TAG")), args.c_str());
}

void GUIConsoleCommandParser::handleQuitCommand(const stringImpl& args) {
    if (!args.empty()) {
        // quit command can take an extra argument. A reason, for example
        Console::printfn(Locale::get(_ID("CONSOLE_QUIT_COMMAND_ARGUMENT")),
                         args.c_str());
    }
    Application::instance().RequestShutdown();
}

void GUIConsoleCommandParser::handleHelpCommand(const stringImpl& args) {
    if (args.empty()) {
        Console::printfn(Locale::get(_ID("HELP_CONSOLE_COMMAND")));
        for (const CommandMap::value_type& it : _commandMap) {
            if (it.first != _ID("invalidhelp") &&
                it.first != _ID("invalidcommand")) {
                Console::printfn("%s", _commandHelp[it.first]);
            }
        }
    } else {
        if (_commandHelp.find(_ID_RT(args)) != std::end(_commandHelp)) {
            Console::printfn("%s", _commandHelp[_ID_RT(args)]);
        } else {
            Console::printfn("%s", _commandHelp[_ID("invalidhelp")]);
        }
    }
}

void GUIConsoleCommandParser::handleEditParamCommand(const stringImpl& args) {
    if (ParamHandler::instance().isParam<stringImpl>(args.c_str())) {
        Console::printfn(Locale::get(_ID("CONSOLE_EDITPARAM_FOUND")), args.c_str(),
                         "N/A", "N/A", "N/A");
    } else {
        Console::printfn(Locale::get(_ID("CONSOLE_EDITPARAM_NOT_FOUND")), args.c_str());
    }
}

void GUIConsoleCommandParser::handlePlaySoundCommand(const stringImpl& args) {
    stringImpl filename =
        ParamHandler::instance().getParam<stringImpl>(_ID("assetsLocation")) +
        "/" + args;
    std::ifstream soundfile(filename.c_str());
    if (soundfile) {
        // Check extensions (not really, musicwav.abc would still be valid, but
        // still ...)
        if (!Util::HasExtension(filename, "wav") &&
            !Util::HasExtension(filename, "mp3") &&
            !Util::HasExtension(filename, "ogg")) {
            Console::errorfn(Locale::get(_ID("CONSOLE_PLAY_SOUND_INVALID_FORMAT")));
            return;
        }

        // The file is valid, so create a descriptor for it
        ResourceDescriptor sound("consoleFilePlayback");
        sound.setResourceLocation(filename);
        sound.setFlag(false);
        _sound = CreateResource<AudioDescriptor>(_resCache, sound);
        if (filename.find("music") != stringImpl::npos) {
            // play music
            _context.sfx().playMusic(_sound);
        } else {
            // play sound but stop music first if it's playing
            _context.sfx().stopMusic();
            _context.sfx().playSound(_sound);
        }
    } else {
        Console::errorfn(Locale::get(_ID("CONSOLE_PLAY_SOUND_INVALID_FILE")),
                         filename.c_str());
    }
}

void GUIConsoleCommandParser::handleNavMeshCommand(const stringImpl& args) {
    SceneGraph& sceneGraph = _context.gui().activeScene()->sceneGraph();
    if (!args.empty()) {
        SceneGraphNode_ptr sgn = sceneGraph.findNode("args").lock();
        if (!sgn) {
            Console::errorfn(Locale::get(_ID("CONSOLE_NAVMESH_NO_NODE")), args.c_str());
            return;
        }
    }
    AI::AIManager& aiManager = sceneGraph.parentScene().aiManager();
    // Check if we already have a NavMesh created
    AI::Navigation::NavigationMesh* temp = aiManager.getNavMesh(AI::AIEntity::PresetAgentRadius::AGENT_RADIUS_SMALL);
    // Create a new NavMesh if we don't currently have one
    if (!temp) {
        temp = MemoryManager_NEW AI::Navigation::NavigationMesh(_context);
    }
    // Set it's file name
    temp->setFileName(_context.gui().activeScene()->getName());
    // Try to load it from file
    bool loaded = temp->load(sceneGraph.getRoot());
    if (!loaded) {
        // If we failed to load it from file, we need to build it first
        loaded = temp->build(
            sceneGraph.getRoot(),
            AI::Navigation::NavigationMesh::CreationCallback(), false);
        // Then save it to file
        temp->save(sceneGraph.getRoot());
    }
    // If we loaded/built the NavMesh correctly, add it to the AIManager
    if (loaded) {
        aiManager.addNavMesh(AI::AIEntity::PresetAgentRadius::AGENT_RADIUS_SMALL, temp);
    }
}

void GUIConsoleCommandParser::handleShaderRecompileCommand(const stringImpl& args) {
    ShaderProgram::recompileShaderProgram(args);
}

void GUIConsoleCommandParser::handleFOVCommand(const stringImpl& args) {
    if (!Util::IsNumber(args)) {
        Console::errorfn(Locale::get(_ID("CONSOLE_INVALID_NUMBER")));
        return;
    }
    I32 FoV = (atoi(args.c_str()));
    CLAMP<I32>(FoV, 40, 140);

    Camera::activeCamera()->setHorizontalFoV(to_float(FoV));
}

void GUIConsoleCommandParser::handleAddObject(const stringImpl& args) {
    std::istringstream ss(args.c_str());
    stringImpl args1, args2;
    std::getline(ss, args1, ',');
    std::getline(ss, args2, ',');

    float scale = 1.0f;
    if (!Util::IsNumber(args2.c_str())) {
        Console::errorfn(Locale::get(_ID("CONSOLE_INVALID_NUMBER")));
    } else {
        scale = to_float(atof(args2.c_str()));
    }
    stringImpl assetLocation(
        ParamHandler::instance().getParam<stringImpl>(_ID("assetsLocation")) + "/");

    FileData model;
    model.ItemName = args1 + "_console" + args;
    model.ModelName = 
        ((args1.compare("Box3D") == 0 || args1.compare("Sphere3D") == 0)
             ? ""
             : assetLocation) +
        args1;
    model.position = Camera::activeCamera()->getEye();
    model.data = 1.0f;
    model.scale = vec3<F32>(scale);
    model.orientation = Camera::activeCamera()->getEuler();
    model.type = (args1.compare("Box3D") == 0 || args1.compare("Sphere3D") == 0)
                     ? GeometryType::PRIMITIVE
                     : GeometryType::GEOMETRY;
    model.version = 1.0f;
    model.staticUsage = false;
    model.navigationUsage = true;
    model.useHighDetailNavMesh = true;
    model.physicsUsage = true;
    model.physicsStatic = true;
    _context.gui().activeScene()->addModel(model);
}

void GUIConsoleCommandParser::handleInvalidCommand(const stringImpl& args) {
    Console::errorfn(Locale::get(_ID("CONSOLE_INVALID_COMMAND")), args.c_str());
}
};

Commits for Divide-Framework/trunk/Source Code/GUI/GUIConsoleCommandParser.cpp

Diff revisions: vs.
Revision Author Commited Message
804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
802 Diff Diff IonutCava picture IonutCava Tue 29 Nov, 2016 17:15:38 +0000

[IonutCava]
- GUI class is no longer a Singleton
- Reduced usage of GFXDevice::instance()

784 Diff Diff IonutCava picture IonutCava Mon 17 Oct, 2016 16:20:49 +0000

[IonutCava]
- Removed the CameraManager and move most of its functionality into static members of the Camera class
- Removed Camera push/pop system in favour of a stateless ptr based system to better fit the RenderPass structure

715 Diff Diff IonutCava picture IonutCava Fri 27 May, 2016 16:19:22 +0000

[IonutCava]
- Added initial Fade In / Fade Out post effect (used for scene transitions for now)
- Added a GUI Interface that handles a list of GUI elements (used by GUI and SceneGUIElements)
- Fixed some race conditions related to multi-threaded scene loading (a lot remain to be fixed)
- Improved per-thread GPU sync system a bit
- Simplified Singleton define macros (although we should get rid of singletons all together)

713 Diff Diff IonutCava picture IonutCava Wed 25 May, 2016 15:43:38 +0000

[IonutCava]
- Removed all unique_ptr’s from the code with classic new/delete pairs. They were seriously not needed.
- Added the concept of SceneComponent to scene specific classes: aiManager, lightPool, sceneGraph, physicsInterface etc
— This allowed the removal of the global GET_ACTIVE_SCENEGRAPH call;

711 Diff Diff IonutCava picture IonutCava Mon 23 May, 2016 14:31:55 +0000

[IonutCava]
- More scene change fixes: pending tasks, GUI elements, etc
- Singleton removal: AIManager is a per-scene member instead of a global singleton now

709 Diff Diff IonutCava picture IonutCava Thu 19 May, 2016 16:21:46 +0000

[IonutCava]
- Massive rewrite of the resource system:
— ResourceCache now uses a map of weak pointers and passes shared pointers to the call point of CreateResource
— RemoveResource is no longer needed, but resource based smart pointers use a custom deleter that calls unload()
— Keep a shared_ptr of the resource in the entity that needs it and pass shared_ptr references from getter methods
-— All of this removed the need for calls to RemoveResource, REGISTER_TRACKED_DEPENDENCY and UNREGISTER_TRACKED_DEPENDENCY reducing the number of mutex locks and atomic exchanges
- Singleton cleanup:
— Removed ShaderManager singleton and merged it’s data and responsibilities in static methods in both ShaderProgram and Shader classes.
Explanation: Due to the complex interdependency chains in the system, copying, updating, tracking the cache in a thread safe way became a lot more slower than a straight forward smart pointer based implementation. (e.g. scene graph nodes have 3d objects and material instances, 3d objects have materials, materials have textures and shaders, etc)

705 Diff Diff IonutCava picture IonutCava Thu 12 May, 2016 20:27:20 +0000

[IonutCava]
- Decouple asset loading from the active scene
— completely remove GET_ACTIVE_SCENE() method

696 Diff Diff IonutCava picture IonutCava Mon 09 May, 2016 16:14:09 +0000

[IonutCava]
- More physics system preparation:
— Define specific px groups for nodes: static, kinematic, dynamic, ragdoll, etc

671 IonutCava picture IonutCava Fri 08 Apr, 2016 16:26:49 +0000

[Ionut]
- Custom memory allocation system part 1:
— Add http://www.codeproject.com/Articles/1089905/A-Custom-STL-std-allocator-Replacement-Improves-Pe
— Add custom allocators to strings and vectors
— Add custom allocators to a few test classes
— No support for aligned memory yet, so vec4<F32> and mat4<F32> vectors use the old allocation system
- Replace more std::async call with our custom task system