diff options
author | Adam Frisby | 2007-06-26 04:45:24 +0000 |
---|---|---|
committer | Adam Frisby | 2007-06-26 04:45:24 +0000 |
commit | 34c7a0e43a55e60466ce5527722cbdc5c946cd34 (patch) | |
tree | 3713623e7f4cf7fafdd1ca77a6c2cc74e8149c48 /OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs | |
parent | * Committing terrain filter demo (diff) | |
download | opensim-SC_OLD-34c7a0e43a55e60466ce5527722cbdc5c946cd34.zip opensim-SC_OLD-34c7a0e43a55e60466ce5527722cbdc5c946cd34.tar.gz opensim-SC_OLD-34c7a0e43a55e60466ce5527722cbdc5c946cd34.tar.bz2 opensim-SC_OLD-34c7a0e43a55e60466ce5527722cbdc5c946cd34.tar.xz |
* Terrain filters! - Think photoshop-style filters for terrain.
* Terrain filters may be written in either C# or JavaScript and loaded at runtime
Use:
terrain csfilter somefile.cs -- Loads a C# filter
terrain jsfilter somefile.js -- Loads a JavaScript filter
Once a terrain filter has been loaded, you can use the command as normal, eg
terrain demofilter
Diffstat (limited to 'OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs')
-rw-r--r-- | OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs b/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs new file mode 100644 index 0000000..6a83c8a --- /dev/null +++ b/OpenSim/OpenSim.Terrain.BasicTerrain/TerrainFilter.cs | |||
@@ -0,0 +1,97 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | using System.CodeDom.Compiler; | ||
6 | using System.CodeDom; | ||
7 | using Microsoft.CSharp; | ||
8 | using Microsoft.JScript; | ||
9 | |||
10 | using libTerrain; | ||
11 | |||
12 | namespace OpenSim.Terrain | ||
13 | { | ||
14 | public interface ITerrainFilter | ||
15 | { | ||
16 | void Filter(Channel heightmap, string[] args); | ||
17 | string Register(); | ||
18 | } | ||
19 | |||
20 | public class TestFilter : ITerrainFilter | ||
21 | { | ||
22 | public void Filter(Channel heightmap, string[] args) | ||
23 | { | ||
24 | Console.WriteLine("Hello world"); | ||
25 | } | ||
26 | |||
27 | public string Register() | ||
28 | { | ||
29 | return "demofilter"; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | public class FilterHost | ||
34 | { | ||
35 | public Dictionary<string, ITerrainFilter> filters = new Dictionary<string, ITerrainFilter>(); | ||
36 | |||
37 | private void LoadFilter(ICodeCompiler compiler, string filename) | ||
38 | { | ||
39 | CompilerParameters compilerParams = new CompilerParameters(); | ||
40 | CompilerResults compilerResults; | ||
41 | compilerParams.GenerateExecutable = false; | ||
42 | compilerParams.GenerateInMemory = true; | ||
43 | compilerParams.IncludeDebugInformation = false; | ||
44 | compilerParams.ReferencedAssemblies.Add("libTerrain-BSD.dll"); | ||
45 | compilerParams.ReferencedAssemblies.Add("OpenSim.Terrain.BasicTerrain.dll"); | ||
46 | compilerParams.ReferencedAssemblies.Add("System.dll"); | ||
47 | |||
48 | compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename); | ||
49 | |||
50 | if (compilerResults.Errors.Count > 0) | ||
51 | { | ||
52 | Console.WriteLine("Compile errors:"); | ||
53 | foreach (CompilerError error in compilerResults.Errors) | ||
54 | { | ||
55 | Console.WriteLine(error.Line.ToString() + ": " + error.ErrorText.ToString()); | ||
56 | } | ||
57 | } | ||
58 | else | ||
59 | { | ||
60 | foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes()) | ||
61 | { | ||
62 | Type testInterface = pluginType.GetInterface("ITerrainFilter",true); | ||
63 | |||
64 | if (testInterface != null) | ||
65 | { | ||
66 | ITerrainFilter filter = (ITerrainFilter)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString()); | ||
67 | |||
68 | string filterName = filter.Register(); | ||
69 | Console.WriteLine("Plugin: " + filterName + " loaded."); | ||
70 | |||
71 | if (!filters.ContainsKey(filterName)) | ||
72 | { | ||
73 | filters.Add(filterName, filter); | ||
74 | } | ||
75 | else | ||
76 | { | ||
77 | filters[filterName] = filter; | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | } | ||
84 | |||
85 | public void LoadFilterCSharp(string filename) | ||
86 | { | ||
87 | CSharpCodeProvider compiler = new CSharpCodeProvider(); | ||
88 | LoadFilter(compiler.CreateCompiler(), filename); | ||
89 | } | ||
90 | |||
91 | public void LoadFilterJScript(string filename) | ||
92 | { | ||
93 | JScriptCodeProvider compiler = new JScriptCodeProvider(); | ||
94 | LoadFilter(compiler.CreateCompiler(), filename); | ||
95 | } | ||
96 | } | ||
97 | } | ||