These project files are not generated from build scripts. The lib folder is an intermediate output folder where static libraries are compiled. It is safe to delete this folder, as Visual Studio will build any missing libraries during the next build of the sandbox.
The media folder contains all the shared assets used within the chapter demos. Assets used by the sandbox exist as both loose files and ZIP bundles. The premake folder contains the build script used to configure the sandbox's solution and project files. Any desired changes to the Visual Studio solution or projects should be made in the Premake script. The src folder contains the source code for each open source library as well as the sandbox itself. Every project within the sandbox solution file will have a corresponding src folder, with separate folders for header files and source files.
Chapter demos have an additional script folder that contains every Lua script for that particular chapter. The tools folder contains the installer for the Decoda IDE as well as the Premake utility program that is used to create the Visual Studio solution. Premake is a Lua-based build configuration tool. AI sandbox uses Premake in order to support multiple versions of Visual Studio without the need to maintain build configurations across solutions and build configurations.
Executing the vs Correspondingly, the vs The initial build of the sandbox might take several minutes to build all of the libraries the sandbox uses, and further builds will be much faster. Lua 5. The latest build of the Decoda IDE's debugger only supports up to 5. Newer versions of Lua can be substituted into the sandbox, but Lua's debugging support will no longer function. At the time of writing this, Ogre3D 1.
A minimal configuration of Ogre3D is used by the sandbox, which only requires the minimum library dependencies for image handling, font handling, ZIP compression, and DirectX graphics support. Additional open source libraries providing debug graphics, input handling, physics, steering, and pathfinding are detailed as follows:. Ogre3D Procedural 0. OIS 1. Bullet Physics 2. OpenSteer revision : This is a local steering library that is used to calculate steering forces of AI agents.
Recast 1. Detour 1. Premake dev e7a41f90fb80 is a development build of Premake that is based on the Premake development branch. The sandbox's Premake configuration files utilize the latest features that are only present in the development branch of Premake. Decoda 1. Decoda takes a unique approach to Lua script debugging, which makes integrating with an application far superior to other Lua debuggers.
Instead of using a networked-based approach where an internal Lua virtual machine must be configured to support debugging, Decoda uses the debug symbol files produced by Visual Studio in order to support Lua debugging.
The key advantage of this approach is that it supports Lua debugging without requiring any changes to the original application. This key difference in Decoda allows for easy debug support in the sandbox's embedded Lua virtual machines. Each sandbox Decoda project is already set up to run the correct corresponding sandbox executable.
Setting up a new Decoda project only requires a few initial steps to point Decoda to the correct executable and debug symbols. Open the Settings menu under the Project menu, as shown in the following screenshot:. Set the Command textbox to point to the new sandbox executable. Set the Working Directory and Symbols Directory fields to the executable's directory. Decoda can only debug bit applications where debug symbols are present. AI sandbox creates debug symbols in both Release and Debug build configurations.
To begin debugging Lua scripts within the sandbox, press F5 within Decoda. F5 will launch the sandbox application and attach Decoda to the running process. Selecting Break from the Debug menu or setting a breakpoint over a running script will pause the sandbox for debugging. Type any variable within the Watch window to monitor that variable while debugging.
Decoda also allows you to type in any arbitrary Lua statements within the Watch window. The Lua statement will be executed within the current scope of the debugger.
The stack window shows you the currently executing Lua call stack. Double-click on any line to jump to the caller. The Watch window will be automatically updated based on the current scope specified by the call stack. The Virtual Machines window shows you each of the Lua virtual machines the sandbox is running. In this case, there is a separate virtual machine for the sandbox and a separate virtual machine for each of the running agents.
If the sandbox was launched from Decoda, you can always attach it to the running process from Visual Studio through the Debug menu's Attach to Process option.
Decoda can also attach itself to a running process through the Debug menu. If the sandbox is run through Visual Studio, you can attach Decoda at any time in the same fashion that Visual Studio attaches it to the sandbox. To automatically attach both Decoda and Visual Studio when the sandbox launches from Decoda, select the Attach System Debugger option from the Debug menu.
The following screenshot shows you the Debug option that we are accessing in order to attach the system debugger:. Lua states are self-contained structures without the use for any global data, making them practical for threaded applications:.
The sandbox runs multiple Lua virtual machines simultaneously. One main virtual machine is assigned to the sandbox itself, while each spawned agent runs its own separate virtual machine. The use of individual virtual machines comes to the sandbox at the cost of performance and memory but allows for iterating Lua scripts in real time on a per-agent basis. Once the code has finished executing, any return values are pushed back to the stack for the executing Lua script to handle.
When interfacing with Lua, stack values can either be retrieved bottom-up, or top-down. The top element in the stack can be retrieved with an index of -1 , while the bottom element of the stack can be retrieved with an index of 1.
Additional elements can be retrieved by indexing -2 , -3 , 2 , 3 , and so on. Lua has 8 basic primitives: nil, Boolean, number, string, function, userdata, thread, and table:. Nil : Here, a value corresponds to a null value in C. Number : This internally represent doubles that Lua uses to store integers, longs, floats, and doubles. String : This represents any sequence of characters.
Function : Lua also considers functions as a primitive, which allows you to assign functions to variables. Userdata : This a special Lua type that maps a Lua variable to data managed by the C code.
Thread : A thread primitive is used by Lua to implement coroutines. Table : This is an associative array that maps an index to a Lua primitive. A Lua table can be indexed by any Lua primitive. A metatable in Lua is a table primitive that allows custom functions to override common operations such as addition, subtraction, assignment, and so on. To retrieve a metatable within Lua, use the getmetatable function on any object:. To set a metatable within Lua, use the setmetatable function that passes both the object to set and the metatable:.
As the sandbox heavily uses metatables for userdata, you can always use getmetatable on the userdata to see which operations a specific userdata type supports. A metamethod is a particular entry within a metatable that is called when an overriden operation is being requested by Lua. Typically, all Lua metamethods will begin with two underscores at the beginning of the function's name. To add a metamethod to a metatable, assign a function to the metatable indexed by the metamethod's name.
For example:. Userdata is an arbitrary block of data whose lifetime is managed by Lua's garbage collector. While the sandbox makes extensive use of userdata, the construction and destruction of the allocated memory is still handled within the sandbox.
This allows for Lua scripts to be easily iterated without worrying about Lua's internal memory management. For instance, when an agent is exposed to Lua through userdata, the only memory that Lua manages for the agent is a pointer to the agent. Lua is free to garbage collect the pointer at any time and has no effect on the agent itself. First, the Lua function is retrieved from Lua by name and pushed onto the stack.
Any bound functions exposed to Lua become accessible either as a global function or as a function available through a package. The actual function implementation is defined within the LuaScriptBindings. The GetRadius function expects an agent pointer as the first and only parameter from Lua and returns the radius of the agent. An additional helper function performs the actual work of calculating the agent's radius and pushes the value back onto the stack:.
To bind the function to Lua, we define a constant array that maps the function's name within Lua to the C function that should be called. The register function binds the table of function names to their corresponding C callback function. The package name is specified at this step and will be associated with each function within the mapping:. Lua will add the C functions to the Lua table at the top of the stack. While the sandbox uses userdata to pass around agents and the sandbox itself, another use of userdata is to add basic primitives into the sandbox.
These primitives are completely controlled by Lua's garbage collector. The vector primitive added into the sandbox is a good example of using userdata that is completely controlled by Lua. As a vector is essentially a struct that only holds three values, it is a great choice for Lua to completely maintain the creation and destruction of the data. Instead, the code should copy values retrieved from Lua and store them locally. Elevating a vector into a basic Lua primitive means supporting all the expected operations users would like to perform on a vector variable in Lua.
This means that vectors should support the addition, subtraction, multiplication, indexing, and any other basic operators supported by Lua. To accomplish this, the vector data type uses metamethods to support basic arithmetic operators, as well as supporting the dot operator for the ".
To support this functionality from the code, we need to let Lua know what type of userdata it is working with when we allocate memory. The LuaScriptUtilities header defines the metatable name of the vector type:. This allows Lua to know what type of userdata it is dealing with and what functions are supported on the userdata. The demo framework follows a very simple update, initialization, and cleanup design shared throughout many of the classes within the sandbox. The BaseApplication class has the main responsibility to configure the application window, process input commands, as well as configure and interface with Ogre3D.
The Cleanup , Draw , Initialize , and Update functions are stub functions with no implementation within the BaseApplication class itself. Classes that inherit from BaseApplication can overload any of these functions in order to plug in their own logic:. It may takes up to minutes before you received it. Please note : you need to verify every book you want to send to your Kindle. Check your mailbox for the verification email from Amazon Kindle.
Related Booklists. Post a Review To post a review, please sign in or sign up. You can write a book review and share your experiences. Other readers will always be interested in your opinion of the books you've read. Whether you've loved the book or not, if you give your honest and detailed thoughts then people will find new books that are right for them.
O'Reilly Media. Packt Publishing. Young , David. Since
0コメント