Jump to content

Start Level into C++ Side


photo

Recommended Posts

Hi All,

 

I have a project similar to the Unigine's Driving examples.I want to start the level into the C++ side.

How can i do this?

 

Link to comment

Hello, Firat!

 

All you need to do is to get pointer to Unigine::Console class and then run console command "world_load" as you do in the script or in the engine's console.

Unigine::Console *console = Unigine::Console::get();
console->run("world_load name_of_your_world");

Don't forget to include UnigineConsole.h file.

Link to comment

Hi Andrey,

 

Thanks for your answer.I want to start level (game framework) inside C++ side.

Can your answer be applied to my situation?

Link to comment

Yup, it's possible yet you'll need to do some work.

 

First of all, you have to have created and initialized Game instance in the code. Your task is to call its loadLevel method.

 

There might be many ways how to call it. For example, you can write a simple function in UnigineScript which will do the job and will take one string argument like this:

// UnigineScript

Game game = ...; // have to be initialized (via startup arguments or manually)

void cppLoadLevel(string name) {
   if(game == NULL) return;
   game.loadLevel(name);
}

// C++

Unigine::Engine *engine = Unigine::Engine::get();

if(engine->isWorldLoaded() && engine->isWorldFunction("cppLoadLevel",1)) {
    engine->runWorldFunction(Unigine::Variable("cppLoadLevel"),Unigine::Variable("MyLevelName"));
}

Link to comment

sorry,didnt following that

 

i can see in some of the c++ examples things like

 

TrackerTrack track = tracker.loadTrack("samples/tracker/tracks/materials_00.track");
 
can i get access to something like that, in the same sort of way that ive got access to the players
        Player myCamera = Player.create(editor.getNode(iNodeID));
        Game game = Game.get();
        game.setPlayer(myCamera);
 
i cant find the Tracker classes from visual studio,
 
 
Link to comment

Tracker is high-level system written entirely on UnigineScript. So the only possible way to interact between C++/C# and Tracker is to call functions from UnigineScript or from C++.

 

Here's how to export and call C++ function from UnigineScript: https://developer.unigine.com/en/docs/1.0/cpp_api/usage/functions

And I showed above how to call UnigineScript function from C++, also we have a C++ sample located in source\samples\Api\Scripts\Callbacks.

Link to comment

Hi Andrey,

 

Thanks for your answer.I have one question about where to call  your UnigineScript code.

Do i put your uniginescript code into the level cpp file?

Link to comment

Hi Silent,

 

Thanks for your answer.But i dont mean it.I know to separate UnigineScript code from the C++ code.I asked where i put code snippets that uncleboo suggests.

Do i have to put it into level file or somewhere else?

Link to comment
×
×
  • Create New...