Re: [xmoto-dev] svn 1404 : merged benetnash with trunk

[ Thread Index | Date Index | More lists.tuxfamily.org/xmoto-dev Archives ]


Janek Polak a écrit :
Today morning I've invented that this floating point differences can be
removed by changeing (replay_time < highscore_time) to (replay_time -
highscore_time < -0.01). I'm not perfectly sure if it works, but this
solution looks fine. I left comment in case someone invent something
better.
i found a nice feature of sqlite,
it has not a lot of function, however, it allows to add news !

in
src/db/xmDatabase.cpp
put your own functions, example :

Note that some website propose a lot of built-in function, however, less functions there are, and faster it is to load.

It allows the following query :

   std::string query = "SELECT r.id_level, r.name FROM replays r "
...
"AND ( (h.id_room IS NULL) OR (h.finishTime*100.0) > xm_floor(r.finishTime*100.0)) "
   "ORDER BY r.id_level, r.finishTime;";

Note that i changed your query so that it send only the best replays for a levels, not all.

/* this function add all the function i want */
void xmDatabase::createUserFunctions() {
 if(sqlite3_create_function(m_db,
                "xm_floor",
                1,
                SQLITE_ANY,
                NULL,
                user_xm_floor,
                NULL,
                NULL) != SQLITE_OK) {
   throw Exception("xmDatabase::createUserFunctions() failed !");
 }
}

/* this one declare xm_floor one */
void xmDatabase::user_xm_floor(sqlite3_context* i_context, int i_nArgs, sqlite3_value** i_values) {
 double v_value;

 if(i_nArgs != 1) {
   throw Exception("user_xm_floor failed !");
 }

 v_value = sqlite3_value_double(i_values[0]);
 sqlite3_result_double(i_context, (double)((int)(v_value)));
}



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/