• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Gyrbo

Saving compiled bytecode

27 posts in this topic

This has ben brought up on a couple of occasions and I decided to try and do this. After browsing through the code I came to the conclusion that this wouldn't be very difficult. My current approach is to simply dump all the the variables to a file (traversing all arrays, strings and classes) after Build() has been called on a module. To load the bytecode, you would simply restore all the data right after you create the engine. I'm currently working on this but because of the amount of classes involved I haven't finished yet. I'm currently using function such as WriteProperty(), but I would preffer to add a function asCProperty::Write() (this is an example, it would need to be done for each class). The problem with this is that it becomes a part of AngelScript itself and this may not be the best approach. I have some questions about the state of certain variables: - What is asCModule::globalMem used for? Can I simply dump it to a file or is special pre/post proccessing needed? - asCScriptFunction::cleanCode only seems to be used during the Build() stage, can I safely discard its contents? Comments appreciated!
0

Share this post


Link to post
Share on other sites
I welcome your effort, though I don't think it is quite so easy as you think. There are a few places where you would have to exchange pure address pointers for placeholders which would have to be resolved at load time. You should also verify that the engine was configured with the exact same functions as function ids would otherwise be wrong.

asCModule::globalMem is dynamic memory for holding global script variables. If you call @init after loading the bytecode I think you don't have to save the content of the array (just the size).

cleanCode is in fact used by the exception handler to clean up each function in case of exceptions. Thus you should definitely save this code as well.

I will give you all the support I can in the form of answering questions.

Regards,
Andreas



0

Share this post


Link to post
Share on other sites
I'm currently assuming that the system functions aren't being changed. In your code, you would have an if statement around your AddScriptSection() and Build() code. This code only has to be executed if bytecode is not available. There is actually no special compiler, the game/program acts as a compiler. After it first runs you have both a "compiled" and a source version and you can then remove the source version and the program uses the compiled.

I'm still writing the code so I can't test to see if it works or not. I'll report back when I have done some tests.

[edit]The union in asCProperty always seems to use index for script variables. Can I safely assume this to always be the case?

[edit2]I'm running into some problems with calling system functions. I'll debug it some more tomorrow and see if I can fix this up. System functions are registered in the engine and not the module, so I have no idea why it errors out...

[Edited by - Gyrbo on July 16, 2004 2:45:19 PM]
0

Share this post


Link to post
Share on other sites
Script variables are referenced with indices. I have no plans to change this at the moment. Variables registered by the host application are references by address pointer though. I could change this to be by index, but that would affect the performance slightly, though I suppose that can be a small cost for the added benefit of precompiled byte code.

It could be that you are running into the same bug reported by Dentoid in the following thread:

http://www.gamedev.net/community/forums/topic.asp?topic_id=257373

0

Share this post


Link to post
Share on other sites
I'm only storing the script variables anyway, it's up to the host program to register the host variables.

I'll see if that's the same bug I'm having problems with. If this doesn't fix my problems I might try another approach.

Thank you for your advice.

[edit]Thanks to the wonderful debugger that comes with MSVC6.0, I found the problem. paramSize contained a bogus value and thus a crash in the ASM code. This was because this variable is being calculated by running asCScriptEngine::PrepareEngine(), which in turn is being called by (surpize surprize) asCModule::Build().

I still have to do some more tests and clean up the code a bit before I can show you guys anything. I'll probably place it all in a nice class and friend it in the needed classes so it has access to protected variables.

[edit2]My addition is almost done. Because I have no real-life code to work with, I'm not sure all functionality works. If someone can send me some example code I can test to see if it all works. I'd hate to send buggy code to WitchLord.

[Edited by - Gyrbo on July 17, 2004 10:42:21 AM]
0

Share this post


Link to post
Share on other sites
You don't have to save the value of the registered global properties, but since the bytecode is using the absolute address directly you will have to somehow convert these values so that the correct addresses can be restored at load time. In this case I think the easiest solution is to simply create a new bytecode that references the properties by index instead, and change the compiler to output that bytecode instead.

Perhaps you can use the test framework available from the AngelScript site for your tests. You could even write your own tests as needed and send them to me.

I hope that I will be able to include your contribution in my library, but even if I can't do it at this moment I don't want your work to go to waste. It is too valuable for that and there are many developers asking for this feature. I promise you that I will upload your work to the AngelScript site as a stand alone improvement on AS, at least until I will have the time to include it in the official library.

I hope you don't feel bad about that. Your efforts are appreciated and I can assure you that they will be included in the library one day. I'm just not sure that this is the right moment to do it.

Regards,
Andreas
0

Share this post


Link to post
Share on other sites
I was using the test framework, but the problem is that very few of the tests use an actual script. Most use ExecuteString(), which makes it impossible to save the bytecode. I'll see if I can slap together some scripts for this.

I'll have to perform some tests with global variables to see how to solve this, but it shouldn't be much of a problem.

The problem with making it an external add-on is that the new class uses some methods in asCScriptEngine and it has to friend with asCModule to be able to access protected variables.
0

Share this post


Link to post
Share on other sites
I didn't mean to make it an external add-on. I just meant that I won't have the time to include it in the library for a while (I don't have time to do much at all on Angelscript right now). That is why I will upload your library as is so that others can take advantage of your work as an unofficial version. When I get the time I will make an official release that include your work.

It's good that you've made it a separate class, that should be much easier for me to import and maintain for future releases.

How have you designed the interface for this functionality?

0

Share this post


Link to post
Share on other sites
asCScriptEngine has two extra methods SaveByteCode() and RestoreByteCode(). Both take the module to save/restore and a special interface class as arguments.
This class is much like the asIOutputStream, but instead it's fully binary and supports reading and writing.
It's up to the user to implement code for checking if it should use the bytecode or the sourcecode. You can't pass both to the engine.

I'm downloading the latest version and I'll use that to do my further testing. Once everything work to my liking, I'll send the changes to you.
0

Share this post


Link to post
Share on other sites
Excellent, that is the way I had imagined implementing this as well.

From what you tell me, I should be able to include your implementation already in version 1.9.0 (the next interface change).

Regards,
Andreas
0

Share this post


Link to post
Share on other sites
I tested the code and it seems to work properly. I also think I understand why the global variables could be a problem. The following code won't work:
int* num = new num;
engine->RegisterGlobalProperty("int num", num);

The only way I see this to be currently possible is the following:

int ptoi(int* num) return *num;
...
int* num = new num;
engine->RegisterObjectType("intp", sizeof(int*), 0);
engine->RegisterGlobalProperty("intp num", &num);
engine->RegisterGlobalFunction("int valueof(intp)", asFUNCTION(ptoi), asCALL_CDECL);


This isn't the cleanest approach, but it should work. There's probably some way to automate this, but I can't currently think of any. Maybe using a special function to register the pointer of a pointer?

Here's the code for my modifications, simply extract to the angelscript root dir: http://users.pandora.be/gyrbo-be/AS/AngelScript-bytecode.tar.bz2
0

Share this post


Link to post
Share on other sites
You don't have to register a new type for int *, you can use it directly.

int *num = new int;
engine->RegisterGlobalProperty("int *num", &num);


When I get the time I will make the necessary changes to make global properties to work with saved byte code. It should only be necessary to create a new bytecode with similar functionality as BC_PGA, and changed the compiler to output this one instead of BC_SET4 with the absolute address. This change will most likely work directly with your code changes.




0

Share this post


Link to post
Share on other sites
I downloaded your file, but for some reason I couldn't unpack it.

Would it be possible for you to pack it as a normal .zip?

By the way, what's your full name? I would like to put your name as the author of modifications.

0

Share this post


Link to post
Share on other sites
I also had some problems unpacking the file using powerarchiver, but 7-zip worked OK. I'm not sure what the problem was, but here's the zip: http://users.pandora.be/gyrbo-be/AS/AngelScript-bytecode.zip
0

Share this post


Link to post
Share on other sites
Now I can also open it. Thanks. I took a quick look at the code and it looks good. It shouldn't be hard to maintain this code, so I'll probably include it with version 1.9.0. Until then I will upload it to the site for those that are interested in this functionality already.

Thanks for a great contribution to the library.

You didn't tell me your name. How would you like me to refer to you in the credits? Just Gyrbo?
0

Share this post


Link to post
Share on other sites
Sorry forgot that (you can look up my name in the copyright of the files I added though ;)). My full name is on Dennis Bollyn.
0

Share this post


Link to post
Share on other sites
Thanks, Dennis.

I've sent an e-mail to you about the copyright. There's something we need to clear up before I can put up the files on my site.
0

Share this post


Link to post
Share on other sites
Yay!! to both of you, let's hope i can get it running on my code, Gybro thanks a lot for your additions to Angelscript.

I wonder if my earlier doubts are appropriate here, i was trying to create a script compiler which can run along side VC and compile the scripts before the host App has to actually run, just probably as a syntax checker. we can scout through the whole App project for RegisterGlobalFunction and get stuff out of them to see if the syntaxes are alriught before we can start the Host APP. could we build this up to a discussion?

Cheers!!!
0

Share this post


Link to post
Share on other sites
A seperate compiler is a lot harder to make than a simply bytecode saver.

The only way I see this to be possible is if you have a sort of header file which the script compiler reads and uses to known which system functions and variables are available.
For functions, this is fairly trivial because an index is used. Variables are a bit harder. You would have to also use an index for them because I don't see any way how you could know the address beforehand.
0

Share this post


Link to post
Share on other sites
I will change the way global properties are handled so that they also use indices. This should make it easier to use the feature Dennis added, and also to write a separate compiler. AngelScriptBind that Thomas Suter wrote might help you in writing the compiler.

There might be a problem in the way function IDs are handled as well. The function ID holds two components, the module index and function index in the module. When loading the bytecode into a module the function ID (for each of the BC_CALL) must be updated to reflect the true index of the module. I'll have to think about how to solve this in a good way. Of course if you always load the modules in the same order the indices will always be the same.
0

Share this post


Link to post
Share on other sites
We can probably assume that the module ID will be consistent. You simply define the order in the "header" file. The script compiles should probably also generate some .h/.cpp files that you can include in your project.

I already took a quick look at ASB, but I'm not really sure how it works yet.
0

Share this post


Link to post
Share on other sites
The problem with the module ID will only arise if you load the modules dynamically. Example in one level you load modules a, b, and c. In another level you load only modules b, c, and so on.

I might be able to solve this by making the function IDs used in the byte code local to each module. When getting a function ID from the engine's GetFunctionID() you will still get the complete function ID with the module index. But when a context encounters a BC_CALL code it doesn't care about the module index (should be set to 0) and get the function from current module. In the future when AngelScript allow calls between modules, the module index will refer to a local table of module references. This should make the byte code indifferent to order of loading.

I will make these changes already for 1.8.1 so that it will be easier for you to use Gyrbo's contribution. For 1.9.0 I will officially include the save/load feature.

I must admit that I don't know how AngelScriptBind works either. I just know that it takes a pseudo header file (looks almost like a C++ header file) and generates the binds from that.
0

Share this post


Link to post
Share on other sites
Oops!....i really did mean a syntax checker, to warn the scripter that a code has to be correct before starting the Host App if necessary, since i am using scripts to initialize. i realised this would mainly be a tool to help the developer, and is no longer needed once the script functions are finalized.
0

Share this post


Link to post
Share on other sites
WitchLord: I was thinking about how this could be solved, but I couldn't come up with anything. Using a local table would indeed work very nice. You would store the name of the module and resolve it to a module ID on load?

EddHead: A syntax checker would be pretty easy to make. If you disable the checks for the existance of a functionn, type and variable you have a pretty working syntax checker. This in itself isn't very useful though. You could make it more useful by defining the host functions, types and variables in a sort of header and using those for checks.
0

Share this post


Link to post
Share on other sites
Yes, with the local function IDs it would be necessary to store the module name so that the global function IDs could be resolved at load time.

I haven't decided yet on how I want calls between modules to work. I would prefer some sort of late binding, so that scripts can optionally tell the host application to load a module and bind certain functions. Exactly how I implement this will be defined in a future version. I will probably also allow registration of application functions in modules, so that the application interface can be exchanged dynamically.

EddHead:

What Gyrbo's saying is true. You should register the host application interface (but without any function pointers) so that the compiler will be able to catch errors in function calls, and use of global variables.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0