官术网_书友最值得收藏!

Extending the SandboxApplication class

Once your project has been set up, you need to create three blank files for Premake to discover.

Create the source and header files as follows:

src/my_sandbox/include/MySandbox.h
src/my_sandbox/src/MySandbox.cpp
src/my_sandbox/src/main.cpp

Now, it's time to regenerate the Visual Studio solution by executing vs2008.bat, vs2010.bat, vs2012.bat, or vs2013.bat. When you open the Visual Studio solution, you'll see your brand new My_Sandbox project!

Each of the sandbox demos is set up to extend the base SandboxApplication class and declare where to find the corresponding Lua script files for the executable.

Declaring your MySandbox class follows the same pattern and looks as follows:

MySandbox.h:

#include "demo_framework/include/SandboxApplication.h"

class MySandbox : public SandboxApplication {
public:
    MySandbox(void);

    virtual ~MySandbox(void);

    virtual void Initialize();
};

Inheriting from SandboxApplication gives you a base to start with. For now, we're only going to override the default behavior of Initialize in order to add the resource location for our Lua scripts.

Tip

Inheriting from the SandboxApplication class also allows you to override other functions such as Update and Cleanup. Any special C++ code can be injected into the main application through these function hooks.

You should always call the SandboxApplication class' original implementation of these functions if you override them, as they are responsible for cleaning, initializing, and updating the sandbox.

Creating the source file for the sandbox simply sets the resource location to find our sandbox Lua scripts and calls the parent class's initialization function.

MySandbox.cpp:

#include "my_sandbox/include/MySandbox.h"

MySandbox:: MySandbox ()
    : SandboxApplication("My Sandbox") {}

MySandbox::~ MySandbox () {}

void MySandbox::Initialize() {
    SandboxApplication::Initialize();

    // Relative location from the bin/x32/release/ or 
    // bin/x32/debug folders
    AddResourceLocation("../../../src/my_sandbox/script");
}

Finally, you can add the small runner code to kick off your application from main.cpp:

main.cpp:

#include "my_sandbox/include/MySandbox.h"
#include "ogre3d/include/OgreException.h"

#define WIN32_LEAN_AND_MEAN
#include "windows.h"

int main() {
    MySandbox application;

    try {
        application.Run();
    }
    catch(Ogre::Exception& error) {
        MessageBox(
            NULL,
            error.getFullDescription().c_str(),
            "An exception has occurred!",
            MB_OK | MB_ICONERROR | MB_TASKMODAL);
    }
}
主站蜘蛛池模板: 新郑市| 娄底市| 色达县| 当雄县| 新乡市| 偏关县| 普定县| 丹阳市| 云霄县| 珲春市| 合江县| 合阳县| 化隆| 河池市| 特克斯县| 泾川县| 阳泉市| 九龙坡区| 余干县| 怀柔区| 宁阳县| 射洪县| 遵化市| 沂源县| 咸宁市| 宁武县| 化州市| 东台市| 巨野县| 海口市| 蒙城县| 南汇区| 鹤山市| 昭觉县| 菏泽市| 石家庄市| 古浪县| 枣庄市| 曲阜市| 文登市| 宝坻区|