RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

[2.0] Workbench Scripts.WB.dll for faster compile times.

Ashlar

Sorceror
[2.0] Workbench Scripts.WB.dll for faster compile times.

I recently started a thread in Modification Suggestions about an idea i had for reducing the amount of time it takes the server to compile.
You can find this thread at:
http://www.runuo.com/forums/showthread.php?t=72115

This is mostly aimed at people like me that restart the server very, very often and get annoyed that the server has to recompile every script, not just the script i changed.

RunUO - [www.runuo.com] Version 2.0, Build 2401.3936
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...done (0 errors, 0 warnings)
Scripts: Compiling VB.NET scripts...no files found.
Scripts: Compiling Workbench C# scripts...no files found.
Scripts: Verifying...done (2086 items, 497 mobiles)
RunUO - [www.runuo.com] Version 2.0, Build 2401.3936
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...done (cached)
Scripts: Compiling VB.NET scripts...no files found.
Scripts: Compiling Workbench C# scripts...done (0 errors, 0 warnings)
Scripts: Verifying...done (2087 items, 497 mobiles)
To do this, i made two additions to ScriptCompiler.cs (SVN version 66).
You can find my additions in the attached file as:
Code:
#region Workbench Mod 1 of 2
and
Code:
#region Workbench Mod 2 of 2
The original idea was for a new folder that compiles like the \Scripts folder does and created a separate assembly, but....

After looking at the code in ScriptCompiler.cs closely, i realized that it would be much simpiler to add in a new file extention and have it generate an assembly for the new extention like it already does for vb and cs files.

Note: This mod is for c# code only.
I don't use visual basic, so i didn't include a vb compiler version...

If you don't know how to compile a new Server.exe, check out Penndragon's faq here:
http://www.runuo.com/forums/showthread.php?t=70781

Once you have the Server.exe built with the ScriptCompiler.cs i include here, using the mod works like this:
1.
Any c# script file that ends in .wb (short for Workbench) will be compiled into a Scripts.WB.dll
This allows you to edit your .wb files as often as you like and not have to re-compile the .cs scripts each time.
If you only change a .wb file, the server will only compile the .wb and will load the .cs cache.
3.
After you are done, just rename your script file back to .cs!
( If you use this mod, Please, please rename files back to .cs. I can hear the questions about .wb files now... )

Test server version of RunUO 2.0 anyone?


Edit:
Currently, if a script contains a class or method that is required to exist by another file, you cannot just rename the cs to a wb.
This is because when you start the server, the cs scripts are compiled together and they have to all work together.

I am working on the problem but until i can find a solution, there does exist two partial workarounds for this situation.

1.
Make the rest of the dependant files wb.
This is a partial solution because having too many files to keep track of sucks.

2.
Copy the existing cs you want to edit and name the extention of the copy wb.
This way, the original cs script exists for the other scripts that depend on it, and you have a copy that you can make changes in.
This workaround is limited in that you can only check to see if your changes will compile.
Your changes to the wb file will not appear in-game since the dependant files compiled against the cs version of the file in question.

This is a partial solution because it does not work in all cases.
An example is that this workaround works on BaseKnife, but not on BaseWeapon.
 

Attachments

  • ScriptCompiler.cs
    24.2 KB · Views: 122

Lokai

Knight
Interesting idea.

I have a problem with it however.

This is only good if you are adding a file that is not depended on by existing c# files, and does not work if your files are integrated with stock scripts.

In other words, what files can you just simply rename with .wb extension, and still be able to compile your C# scripts? I don't have many files like that.

I cannot change BaseWeapon.cs to BaseWeapon.wb and work just on that file, because the C# scripts will not compile without BaseWeapon.cs being there.

EDIT: This WILL work OK if you are adding a completely 'Drag-n-drop' script or script system, where you are not modifying existing C# scripts (most of which depend on eachother to a degree.)
 

Ashlar

Sorceror
Lokai said:
I cannot change BaseWeapon.cs to BaseWeapon.wb and work just on that file, because the C# scripts will not compile without BaseWeapon.cs being there.

That is true and I believe that is what Phantom was refering to.
I don't edit the distro files much myself since i am more concerned with making new scripts.
And when you are making new scripts, the problem doesn't appear at all.

There is a partial workaround that works in some cases...
Copy BaseKnife.cs to a new folder, and change the extention on the copy to a .wb ( i.e. BaseKnife.cs.wb ).

You still have the original file as a cs so the server will compile, and a wb file to make your changes in and restart the server quickly.

Doing this however will only show you if the server will compile, since any knives created in game will not use values from the wb BaseKnife.
But, just knowing that your changes will compile as a .cs script will still save time.

I said earlier that this workaround will work in "some cases".
Your BaseWeapon example will still not work due to abstract class protection levels in IDurability.
But, as i have shown (and tested) with the BaseKnife, it doesn't take much time to find out if the workaround will work on a particular script file.

This mod will not work for everything unfortunately.
I didnt understand Phantom's concern until just today, but i still see this as an invaluable tool - it has saved me hours and hours already!

Like any tool however, it doesn't work for every job.... Just most of em :)


I am going to be looking into seeing if i can fix this problem by getting the wb scriptcompiler to load the Scripts.cs.dll as a resource. Edit: err, reverse that...

In the meantime, I hope that the workaround i suggested helps you Lokai.

P.S. Thanks for trying this out!
 

Cheetah2003

Wanderer
I think this tool is wonderful, its saving me tons of time working on some new stuff. I don't really see or understand the problem you guys are describing, however.

I've just made some new mobs, which are derived from BaseCreature, and I didn't need to rename my BaseCreature.cs to .wb. Seems like a great tool to me, I was really getting tired of recompiling everything everytime I made a little change. :)

Thanks Ashlar!
 

Lokai

Knight
Glad to hear that Cheetah.

Here is where the problem comes in:

I am working on several big systems at the moment. Each one has about 20-30 files in it. Now, if they were self-contained, or were based on other files, but "NOTHING DEPENDED ON THEM" then I could just rename them all with the .WB extension, and it would work fine. But for example, one of the systems I am working on also makes a change and addition to the AI system. So, if I rename the files, BaseAI says it "misses" them, and if I rename BaseAI, there are about 1000 files that miss that. etc. etc. etc.

Don't get me wrong. I was maybe the first one to create a brand new server to test this out. I think its a very cool idea. It is just frustrating that it doesnt work for me yet.
 

Ashlar

Sorceror
Glad you like it Cheetah2003 :D
For the first day or so i kept wanting to yell either "station" or "workbench" everytime i restarted the server.


This is only for those having problems like Lokai was desribing...
If you are having no problems with using this mod, dont bother to read on because this only occurs when editing WB files that CS scripts are dependant on.

Lokai, I have been working on this, trying to get it where you could use it with no problems.

Like you said, it works great for smaller projects, but for larger ones that change lots of code throughout the scripts... yech!

I have been making a lot of tests and suchlike and while i have figured out how to create a "trailing effect" (See next paragraph), it isn't something that i recommend for use because it gets.... err, complex to know what is going on where.

What i am calling a "trailing effect" is that;
I have been able to get the cs compiler to load the wb.dll as a resource if it exists.
Meaning that:
1. You copy the cs and name the copy a wb.
2. Compile, the cs is still there, so it loads the cs cache and compiles the wb.
3. Shut the server back down.
4. Rename or remove the cs that you copied.
5. Restart the server to re-compile. (It has to compile the cs scripts since you deleted one of them, but it loads the Scripts.WB.dll as a resource.)

From this point on, the wb file IS the cs script as far as the cs compiler is concerned since it loads it.

Problem:
If you cannot compile a script as a wb, (the baseweapon problem), you cannot get a dll of it and the whole thing breaks down.... grr!



On the plus side, from this effect i believe it is possible to get the compiler to loop through all the scripts in the \Scripts folder, compiling them one at a time and creating assemblys for each of them as it goes and then using the dll's of them as resources for suceeding compiles.

I believe that code that does this would be the ultimate word in a developers test shard.
This way, the server would only compile scripts that have changed and load everything else.

Now, the only problem is that i do not know enough about the CSharpCodeProvider to code this 'Dynamic, hierarchical, compile and load in-line loop'!

*Ashlar sends out a plea for help to those who know more than he.*

Attached is the version that loads the wb.dll as a resource for the cs compiler in case you want to see it.
I also have in it that the wb compiler loads the cs.dll as a resource in hopes that it would help on the baseweapon problem.
It gives different warnings, but the error remains.
+ BaseWeapon.cs.wb:
CS0122: Line 23: 'Server.Items.IDurability' is inaccessible due to its protection level.
ction level
( I do not yet understand why this error appears only in the wb script... pout )
 

Attachments

  • ScriptCompiler.cs
    24.9 KB · Views: 17

Lokai

Knight
Thank you Ashlar!

I am using the original version, and finally have a good use. Cuts compile time down from about 4 minutes ( i have lots of beefy customs ) to about 5 seconds (LITTERALLY!)

Excellent!
 

nickfly

Wanderer
Hey there,

Trying to get the new Server.exe working, but I get this feedback:
Code:
RunUO - [www.runuo.com] Version 2.0, Build 2424.3593
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...done (cached)
Scripts: Compiling VB.NET scripts...no files found.
Scripts: Compiling Workbench C# scripts...no files found.
Scripts: Verifying...done (4 items, 0 mobiles)
Error:
System.Reflection.TargetInvocationException: Exception has been thrown by the ta
rget of an invocation. ---> System.NullReferenceException: Object reference not
set to an instance of an object.
   at Server.Admin.AdminNetwork.Configure()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] argum
ents, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle
 typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] argume
nts, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwn
er)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisib
ilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
   at Server.ScriptCompiler.Compile(Boolean debug)
   at Server.Core.Main(String[] args)
This exception is fatal, press return to exit
 

Ashlar

Sorceror
Hey there :)

I just rebuilt the server to svn ver 74 myself to make sure that it still works.

It does, so my guess is that you probably forgot to delete the contents of \Scripts\Output before you started your new server build.

What the problem seems to be is that the scripts.dll was compiled with a different server.exe, and the new one cannot use it.

If you delete the files in \Scripts\Output does it still have the error?
 

Sparkin

Sorceror
Server compile time before .WB aprox 10 minutes
Server compile time After adding a new .wb aprox 2 seconds
Running this package has made my life alot smoother, running this on 2 servers at this time and going to add it to the 3rd soon :) i used to dread adding or changing one simple line of code now i hit [restart and just simply log back in and with a brief little burp the shard is running again!

Thanks Ashlar +++ Karma to you man
 

nerun

Sorceror
Updated to RunUO 2.2 and it works. The script updated is include. I compiled the file and post the RunUO.exe here if you prefer.
 

Attachments

  • RunUO-WBmod.7z
    169.9 KB · Views: 7
  • ScriptCompiler.cs
    24.7 KB · Views: 9

Lokai

Knight
Nerun, you may be interested in the version of this I made. The link is in my signature. Most people that used this had trouble with needing to rename file extensions. Mine simply stores the .cs files you are working on in separate folders, which means you can also still use Visual Studio, or any other editing tool. Should be very simple to update to latest version.
 

Pure Insanity

Sorceror
Nerun, you may be interested in the version of this I made. The link is in my signature. Most people that used this had trouble with needing to rename file extensions. Mine simply stores the .cs files you are working on in separate folders, which means you can also still use Visual Studio, or any other editing tool. Should be very simple to update to latest version.

Yes, I found one that didn't work with different file types too. Just thought that was a ridiculous requirement. Believe I'm using your version Lokai, doing a great job so far. Nice not having to worry about changing file types. =P
 

nerun

Sorceror
This file work with SVN 828. I tried to update to SVN 856+ (ScriptCompiler.cs in SVN 954 is the same file for 856), but get some issue with "GetDefines()" not defined...
 

Attachments

  • ScriptCompilerSVN828.cs
    24.8 KB · Views: 2

nerun

Sorceror
Hahahaha i made it!

Add this code to workbench mod and it will work with SVN 985:
Code:
        public static string GetDefines()
        {
            StringBuilder sb = null;
 
            #if MONO
            AppendDefine( ref sb, "/d:MONO" );
            #endif
 
            //These two defines are legacy, ie, depreciated.
            if( Core.Is64Bit )
                AppendDefine( ref sb, "/d:x64" );
 
            AppendDefine( ref sb, "/d:Framework_2_0" );
 
            #if Framework_4_0
            AppendDefine( ref sb, "/d:Framework_4_0" );
            #endif
 
            return (sb == null ? null : sb.ToString());
        }
       
        public static void AppendDefine( ref StringBuilder sb, string define )
        {
            if( sb == null )
                sb = new StringBuilder();
            else
                sb.Append( ' ' );
 
            sb.Append( define );
        }
 

Attachments

  • Ashlar Workbench RunUO SVN 985.7z
    4.8 KB · Views: 2
Top