summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-06-01 18:45:31 +0300
committerAndrei Karas <akaras@inbox.ru>2013-06-01 18:45:31 +0300
commit49f27fffbe07e66a3047812a838f03d7636cc4a9 (patch)
tree68996fa1dfc002e239513af1a92d1ffd69539204
parent69108c8a2892cf87a3d425b5e82e0eadbb5f7fa9 (diff)
downloadmanaplus-49f27fffbe07e66a3047812a838f03d7636cc4a9.tar.gz
manaplus-49f27fffbe07e66a3047812a838f03d7636cc4a9.tar.bz2
manaplus-49f27fffbe07e66a3047812a838f03d7636cc4a9.tar.xz
manaplus-49f27fffbe07e66a3047812a838f03d7636cc4a9.zip
Add chat command /testparticle for testing particle effects on player.
Command: /testparticle particle.xml - set particle effect on player. /testparticle - remove particle effect. Each second it check for particle file update and reloading it if need.
-rw-r--r--src/commands.cpp6
-rw-r--r--src/commands.h4
-rw-r--r--src/gui/updaterwindow.cpp9
-rw-r--r--src/gui/updaterwindow.h2
-rw-r--r--src/localplayer.cpp43
-rw-r--r--src/localplayer.h7
-rw-r--r--src/net/download.cpp7
-rw-r--r--src/net/download.h2
8 files changed, 75 insertions, 5 deletions
diff --git a/src/commands.cpp b/src/commands.cpp
index da771ede4..3d30e2169 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -1192,6 +1192,12 @@ impHandler2(enableAway)
chatWindow->saveState();
}
+impHandler1(testParticle)
+{
+ if (player_node)
+ player_node->setTestParticle(args);
+}
+
impHandler0(testsdlfont)
{
#if defined USE_OPENGL && defined DEBUG_SDLFONT
diff --git a/src/commands.h b/src/commands.h
index 62f9eaead..f41a16339 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -123,6 +123,7 @@ namespace Commands
decHandler(removeName);
decHandler(disableAway);
decHandler(enableAway);
+ decHandler(testParticle);
void replaceVars(std::string &str);
} // namespace Commands
@@ -213,6 +214,7 @@ enum
COMMAND_MOVETOHOME,
COMMAND_SETHOME,
COMMAND_MAGICATTACK,
+ COMMAND_TEST_PARTICLE,
COMMAND_HACK,
END_COMMANDS
};
@@ -296,13 +298,13 @@ static const CommandInfo commands[] =
{"", &Commands::dontRemoveName, -1, false},
{"", &Commands::removeName, -1, false},
{"disableaway", &Commands::disableAway, -1, false},
- {"enableaway", &Commands::enableAway, -1, false},
{"drop", nullptr, Input::KEY_QUICK_DROP, false},
{"dropn", nullptr, Input::KEY_QUICK_DROPN, false},
{"movetotarget", nullptr, Input::KEY_MOVE_TO_TARGET, false},
{"movetohome", nullptr, Input::KEY_MOVE_TO_HOME, false},
{"sethome", nullptr, Input::KEY_SET_HOME, false},
{"magicattack", nullptr, Input::KEY_MAGIC_ATTACK, false},
+ {"testparticle", &Commands::testParticle, -1, true},
{"hack", &Commands::hack, -1, true}
};
diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp
index 28efe9499..80ff0c580 100644
--- a/src/gui/updaterwindow.cpp
+++ b/src/gui/updaterwindow.cpp
@@ -925,6 +925,15 @@ bool UpdaterWindow::validateFile(const std::string &filePath,
return adler == hash;
}
+unsigned long UpdaterWindow::getFileHash(const std::string &filePath)
+{
+ int size = 0;
+ char *buf = static_cast<char*>(ResourceManager::loadFile(filePath, size));
+ if (!buf)
+ return 0;
+ return Net::Download::adlerBuffer(buf, size);
+}
+
void UpdaterWindow::handleLink(const std::string &link,
gcn::MouseEvent *event A_UNUSED)
{
diff --git a/src/gui/updaterwindow.h b/src/gui/updaterwindow.h
index 440344367..e317e3f95 100644
--- a/src/gui/updaterwindow.h
+++ b/src/gui/updaterwindow.h
@@ -145,6 +145,8 @@ class UpdaterWindow final : public Window,
static void unloadManaPlusUpdates(const std::string &dir,
const ResourceManager *const resman);
+ static unsigned long getFileHash(const std::string &filePath);
+
private:
void download();
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index e77d3f249..c69e5b58a 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -50,6 +50,7 @@
#include "gui/sdlfont.h"
#include "gui/skilldialog.h"
#include "gui/socialwindow.h"
+#include "gui/updaterwindow.h"
#include "gui/viewport.h"
#include "gui/widgets/gmtab.h"
@@ -114,8 +115,8 @@ LocalPlayer::LocalPlayer(const int id, const int subtype) :
mLastTargetY(0),
mHomes(),
mTarget(nullptr),
- mPlayerFollowed(""),
- mPlayerImitated(""),
+ mPlayerFollowed(),
+ mPlayerImitated(),
mNextDestX(0),
mNextDestY(0),
mPickUpTarget(nullptr),
@@ -156,9 +157,13 @@ LocalPlayer::LocalPlayer(const int id, const int subtype) :
mNavigatePath(),
mTargetDeadPlayers(config.getBoolValue("targetDeadPlayers")),
mServerAttack(config.getBoolValue("serverAttack")),
- mLastHitFrom(""),
- mWaitFor(""),
+ mLastHitFrom(),
+ mWaitFor(),
mAdvertTime(0),
+ mTestParticle(nullptr),
+ mTestParticleName(),
+ mTestParticleTime(0),
+ mTestParticleHash(0l),
mBlockAdvert(false),
mEnableAdvert(config.getBoolValue("enableAdvert")),
mTradebot(config.getBoolValue("tradebot")),
@@ -358,6 +363,18 @@ void LocalPlayer::slowLogic()
else
mAdvertTime = time + 30;
}
+
+ if (mTestParticleTime != time && !mTestParticleName.empty())
+ {
+ unsigned long hash = UpdaterWindow::getFileHash(mTestParticleName);
+ if (hash != mTestParticleHash)
+ {
+ setTestParticle(mTestParticleName, false);
+ mTestParticleHash = hash;
+ }
+ mTestParticleTime = time;
+ }
+
BLOCK_END("LocalPlayer::slowLogic")
}
@@ -4310,6 +4327,24 @@ void LocalPlayer::updateStatus() const
}
}
+void LocalPlayer::setTestParticle(const std::string &fileName, bool updateHash)
+{
+ mTestParticleName = fileName;
+ mTestParticleTime = cur_time;
+ if (mTestParticle)
+ {
+ mChildParticleEffects.removeLocally(mTestParticle);
+ mTestParticle = nullptr;
+ }
+ if (!fileName.empty())
+ {
+ mTestParticle = particleEngine->addEffect(fileName, 0, 0, false);
+ controlParticle(mTestParticle);
+ if (updateHash)
+ mTestParticleHash = UpdaterWindow::getFileHash(mTestParticleName);
+ }
+}
+
void AwayListener::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok" && player_node && player_node->getAway())
diff --git a/src/localplayer.h b/src/localplayer.h
index 857b61167..6786ee0b0 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -468,6 +468,9 @@ class LocalPlayer final : public Being,
void updateStatus() const;
+ void setTestParticle(const std::string &fileName,
+ bool updateHash = true);
+
std::string getInvertDirectionString();
std::string getCrazyMoveTypeString();
@@ -632,6 +635,10 @@ class LocalPlayer final : public Being,
std::string mLastHitFrom;
std::string mWaitFor;
int mAdvertTime;
+ Particle *mTestParticle;
+ std::string mTestParticleName;
+ int mTestParticleTime;
+ unsigned long mTestParticleHash;
bool mBlockAdvert;
bool mEnableAdvert;
bool mTradebot;
diff --git a/src/net/download.cpp b/src/net/download.cpp
index fad0bf6f2..a8f0e1c0c 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -125,6 +125,13 @@ unsigned long Download::fadler32(FILE *const file)
return adler;
}
+unsigned long Download::adlerBuffer(char *buffer, int size)
+{
+ unsigned long adler = adler32(0L, Z_NULL, 0);
+ return adler32(static_cast<uInt>(adler),
+ reinterpret_cast<Bytef*>(buffer), size);
+}
+
void Download::addHeader(const std::string &header)
{
mHeaders = curl_slist_append(mHeaders, header.c_str());
diff --git a/src/net/download.h b/src/net/download.h
index d351a8355..d0025c2b3 100644
--- a/src/net/download.h
+++ b/src/net/download.h
@@ -100,6 +100,8 @@ class Download final
static void secureCurl(CURL *const curl);
+ static unsigned long adlerBuffer(char *buffer, int size);
+
private:
static int downloadThread(void *ptr);
static int downloadProgress(void *clientp, double dltotal,