summaryrefslogtreecommitdiff
path: root/plugins/skeleton
diff options
context:
space:
mode:
authorPetr Mrázek2011-10-07 03:53:58 +0200
committerPetr Mrázek2011-10-07 03:53:58 +0200
commitb09ff94b245c66c65a2cbc38264a1b2b6483a9b0 (patch)
tree9b86553219fddcda2666e82a2bccea2b528a9b3e /plugins/skeleton
parent5d54bfca96499b7a349a59d3d52933dbc87f00d2 (diff)
downloaddfhack-b09ff94b245c66c65a2cbc38264a1b2b6483a9b0.tar.gz
dfhack-b09ff94b245c66c65a2cbc38264a1b2b6483a9b0.tar.bz2
dfhack-b09ff94b245c66c65a2cbc38264a1b2b6483a9b0.tar.xz
STUFF!
Diffstat (limited to 'plugins/skeleton')
-rw-r--r--plugins/skeleton/CMakeLists.txt33
-rw-r--r--plugins/skeleton/skeleton.cpp78
-rw-r--r--plugins/skeleton/skeleton.h1
3 files changed, 112 insertions, 0 deletions
diff --git a/plugins/skeleton/CMakeLists.txt b/plugins/skeleton/CMakeLists.txt
new file mode 100644
index 00000000..542f08fe
--- /dev/null
+++ b/plugins/skeleton/CMakeLists.txt
@@ -0,0 +1,33 @@
+PROJECT (skeleton)
+# A list of source files
+SET(PROJECT_SRCS
+ skeleton.cpp
+)
+# A list of headers
+SET(PROJECT_HDRS
+ skeleton.h
+)
+SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE)
+
+# mash them together (headers are marked as headers and nothing will try to compile them)
+LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
+
+# option to use a thread for no particular reason
+OPTION(SKELETON_THREAD "Use threads in the skeleton plugin." ON)
+#linux
+IF(UNIX)
+ add_definitions(-DLINUX_BUILD)
+ SET(PROJECT_LIBS
+ # add any extra linux libs here
+ ${PROJECT_LIBS}
+ )
+# windows
+ELSE(UNIX)
+ SET(PROJECT_LIBS
+ # add any extra linux libs here
+ ${PROJECT_LIBS}
+ $(NOINHERIT)
+ )
+ENDIF(UNIX)
+# this makes sure all the stuff is put in proper places and linked to dfhack
+DFHACK_PLUGIN(skeleton ${PROJECT_SRCS} LINK_LIBRARIES ${PROJECT_LIBS})
diff --git a/plugins/skeleton/skeleton.cpp b/plugins/skeleton/skeleton.cpp
new file mode 100644
index 00000000..d69a2dd9
--- /dev/null
+++ b/plugins/skeleton/skeleton.cpp
@@ -0,0 +1,78 @@
+// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D
+
+// some headers required for a plugin. Nothing special, just the basics.
+#include <dfhack/Core.h>
+#include <dfhack/Console.h>
+#include <dfhack/Export.h>
+#include <dfhack/PluginManager.h>
+using namespace DFHack;
+
+// our own, empty header.
+#include "skeleton.h"
+
+
+// Here go all the command declarations...
+// mostly to allow having the mandatory stuff on top of the file and commands on the bottom
+DFhackCExport command_result skeleton (Core * c, std::vector <std::string> & parameters);
+
+// A plugins must be able to return its name. This must correspond to the filename - skeleton.plug.so or skeleton.plug.dll
+DFhackCExport const char * plugin_name ( void )
+{
+ return "skeleton";
+}
+
+// Mandatory init function. If you have some global state, create it here.
+DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
+{
+ // Fill the command list with your commands.
+ commands.clear();
+ commands.push_back(PluginCommand("skeleton",
+ "Do nothing, look pretty.",
+ skeleton /*,
+ true or false - true means that the command can't be used from non-interactive user interface'*/));
+ return CR_OK;
+}
+
+// This is called right before the plugin library is removed from memory.
+DFhackCExport command_result plugin_shutdown ( Core * c )
+{
+ // You *MUST* kill all threads you created before this returns.
+ // If everythin fails, just return CR_FAILURE. Your plugin will be
+ // in a zombie state, but things won't crash.
+ return CR_OK;
+}
+
+// Whatever you put here will be done in each game step. Don't abuse it.
+// It's optional, so you can just comment it out like this if you don't need it.
+/*
+DFhackCExport command_result plugin_onupdate ( Core * c )
+{
+ // whetever. You don't need to suspend DF execution here.
+ return CR_OK;
+}
+*/
+
+// A command! It sits around and looks pretty. And it's nice and friendly.
+DFhackCExport command_result skeleton (Core * c, std::vector <std::string> & parameters)
+{
+ // It's nice to provide a 'help' option for your command.
+ // It's also nice to print the same help if you get invalid options from the user instead of just acting strange
+ for(int i = 0; i < parameters.size();i++)
+ {
+ if(parameters[i] == "help" || parameters[i] == "?")
+ {
+ // Core has a handle to the console. The console is thread-safe.
+ // Only one thing can read from it at a time though...
+ c->con.print("This command does nothing!\n");
+ return CR_OK;
+ }
+ }
+ // Commands are called from threads other than the DF one.
+ // Suspend this thread until DF has time for us.
+ c->Suspend();
+ // Actually do something here. Yay.
+ c->con.print("Hello! I do nothing, remember?\n");
+ // Give control back to DF.
+ c->Resume();
+ return CR_OK;
+}
diff --git a/plugins/skeleton/skeleton.h b/plugins/skeleton/skeleton.h
new file mode 100644
index 00000000..7b9637ef
--- /dev/null
+++ b/plugins/skeleton/skeleton.h
@@ -0,0 +1 @@
+#pragma once \ No newline at end of file