Skip to content

Commit 0e2f475

Browse files
thoraxeRoddieKieley
authored andcommitted
makes the server cycle time configurable from the args
1 parent e80f089 commit 0e2f475

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/Application/Configuration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
class Configuration {
2222
private:
2323
std::string m_strBrokerURI;
24+
int m_intServerSleepCycle = 15;
2425

2526
protected:
2627
// Constructor(s)
@@ -31,6 +32,8 @@ class Configuration {
3132

3233
public:
3334
std::string& BrokerURI = m_strBrokerURI;
35+
int& ServerSleepCycle = m_intServerSleepCycle;
36+
3437

3538
// Singleton(s)
3639
static Configuration& Instance()

src/Application/Server.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include "Configuration.h"
1516
#include "Server.h"
1617
#include "../Game/World.h"
1718
#include "../Game/AEntity.h"
@@ -109,6 +110,7 @@ void Server::run()
109110
m_theEventDispatcher.Dispatch();
110111
m_theMessageDispatcher.Dispatch();
111112

112-
decaf::lang::Thread::currentThread()->sleep(5000);
113+
//decaf::lang::Thread::currentThread()->sleep(Configuration::Instance().ServerSleepCycle);
114+
decaf::lang::Thread::currentThread()->sleep(1500);
113115
}
114116
}

src/Application/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void usage(char **argv) {
4343
fprintf(stderr, "usage: %s [options]\n", argv[0]);
4444
fprintf(stderr, " --help: print usage\n");
4545
fprintf(stderr, " --broker-uri: broker uri with options e.g. tcp://127.0.0.1:61613?wireFormat=stomp&keepAlive=true\n");
46+
fprintf(stderr, " --sleep-cycle: the time (in milliseconds) of the server sleep (default 15) \n");
4647
fprintf(stderr, " ");
4748
fprintf(stderr, "\n\n");
4849
// fprintf(stderr, "bad argument: %s\n", *arg);
@@ -59,6 +60,7 @@ int main(int argc, char* argv[])
5960
std::string strBrokerURI = "tcp://127.0.0.1:61613?wireFormat=stomp&keepAlive=true";
6061
std::string strCommandInDestinationURI = "COMMAND.IN";
6162
std::string strGameEventOutDestinationURI = "GAME.EVENT.OUT";
63+
std::string strServerSleepCycle = "1500";
6264

6365
LOG_F(INFO, "Starting...");
6466
for (int i = 1; i < argc; ++i)
@@ -73,9 +75,14 @@ int main(int argc, char* argv[])
7375
// TODO: Error checking on arg
7476
strBrokerURI = argv[++i];
7577
}
78+
else if (0 == strcmp(argv[i], "--sleep-cycle"))
79+
{
80+
strServerSleepCycle = argv[++i];
81+
}
7682
}
7783

7884
Configuration::Instance().BrokerURI = strBrokerURI;
85+
Configuration::Instance().ServerSleepCycle = strtol(strServerSleepCycle.c_str(), nullptr, 0);
7986

8087
LOG_F(INFO, "Initializing the ActiveMQCPP library");
8188
activemq::library::ActiveMQCPP::initializeLibrary();

0 commit comments

Comments
 (0)