Jump to content

How to operate database


photo

Recommended Posts

Hello!

Who can tell me that the unigine how to operate the database(oracle,db2,sql2005).I think it not only for xml data.

and those 3D games how to do ? must use database.

I read the unigine document but find nothing. how to operate the database about the unigine?

Thanks!

Link to comment

This is a fairly atypical use case for games. There isn't any out of the box functionality for it. Your best bet is to use the C++ plugin interface to build a bridge between the database and your Unigine based application.

Link to comment

you will need a source version license, I've already created a sql plugin support mysql and sqlite(these are my only need), it's very easy to do this. and I don't think other database server is a problem, also, using database as filesystem is also easy with plugin, but of course you will need the engine source to do some modification.

Link to comment

My company is planning for buying the source version license .but must cost some little time.

I must be familiar with it at full speed.

But I know that your source code is keeping secret.

So can you give me some thinking or pseudocode for reference.

Thank you!

Link to comment

In your MyPlugin::init() method you have to register in UnigineScript the methods and classes to start, finish and execute DB operations:


int PicPlugin::init()
{
 Interpreter::addExternLibrary("pic");
 Interpreter::addExternFunction("pic.startPlatform",MakeExternFunction(&PicPlatform::startPlatform,",,,DBUSER,DBPASS"));
 Interpreter::addExternFunction("pic.stopPlatform",MakeExternFunction(&PicPlatform::stopPlatform));
 Interpreter::addExternFunction("pic.isConnected",MakeExternFunction(&PicPlatform::isConnected));
 Interpreter::addExternFunction("pic.execute",MakeExternFunction(&PicPlatform::execute));
 Interpreter::addExternFunction("pic.executeRtnInt",MakeExternFunction(&PicPlatform::executeRtnInt));
 Interpreter::addExternFunction("pic.executeRtnDouble",MakeExternFunction(&PicPlatform::executeRtnDouble));
 Interpreter::addExternFunction("pic.executeRtnString",MakeExternFunction(&PicPlatform::executeRtnStr));
 Interpreter::addExternFunction("pic.executeRtnList",MakeExternFunction(&PicPlatform::executeRtnList));


 ExternClass<Unigine_d_query> *d_queryclass= MakeExternClass<Unigine_d_query>();
 d_queryclass->addConstructor();
 d_queryclass->addFunction("execute",&Unigine_d_query::_execute);
 d_queryclass->addFunction("fetch",&Unigine_d_query::_fetch);
 d_queryclass->addFunction("skip",&Unigine_d_query::_skip);
 d_queryclass->addFunction("get_data_bool",&Unigine_d_query::_get_data_bool);

 // ...

 d_queryclass->addFunction("set_cur_idx",&Unigine_d_query::_set_cur_idx);
 Interpreter::addExternClass("d_query",d_queryclass);

 //...
}

 

Once Unigine is running, in world script, the connection is started:

 

int init() {

 //...

 //start cache connection
 if(!pic.startPlatform(server,port,namespace,"DBUSER","DBPASS")) {
   log.error("[init()] Pic platform Pic can't be initialized ('%s','%s','%s'). Shutting down the application.",server,port,namespace);
   goto cant_run;
 }

 // ...


 /* d_query Test */
 /* ------------ */
 //create d_query on UnigineScript
 d_query q= class_manage(new d_query());

 q.execute("SELECT Name,Camera,IP FROM app.camera");
 while(q.fetch()) {
   string name= q.get_data_str();
   string cam= q.get_data_int();
   string ip= q.get_data_str();
   log.message("[%s] Cam:%d IP:%s",name,cam,ip);
 }
 delete q;

 //...
 return 1
}

 

Basically, in the plugin you have to implement the data base operations using C++, then you have to create and interface for UnigineScript in order to use those functions and data types in your game/app scripts.

Link to comment

I find a article in unigine document of "Dynamically Loading Library as Plugin".

I cann't find these files in unigine install package.("UnigineInterpreter.h","UniginePlugin.h" )

Are these files saved in source version license?

Link to comment

yuwen.xiang, there is no access to Unigine C++ API from evaluation kit.

 

danni.coy, steve3d and ivan.cuevas are right. To be able to work with databases you will need to extend Unigine functionality with your own C++ plugin. There are several plugins in binary/source kit (but not with database access functionality), so you will be able to use them as a reference to Unigine plugins system.

Link to comment
  • 1 month later...

HI all!

how the data record save from reading database by c++ plugin? how do to reload the db data record in unigine.I use "-extern_plugin" load c++ plugin.but it run in frist init in unigine.i don't know how to save the data and for unigine use . how process the memory ???

thank you!

Link to comment
×
×
  • Create New...