setting up game core

in db and associated initialization code
gh-pages
Brian Jack 2014-12-14 10:23:09 -08:00
parent 066deea298
commit 5a7c574883
4 changed files with 130 additions and 0 deletions

View File

@ -139,6 +139,8 @@
<Unit filename="Account.cpp" />
<Unit filename="Account.hpp" />
<Unit filename="auto/version.h" />
<Unit filename="bvgame/core.cpp" />
<Unit filename="bvgame/core.hpp" />
<Unit filename="client.cpp">
<Option target="ClientDebug" />
<Option target="ClientRelease" />

View File

@ -0,0 +1,78 @@
/*
**
** Minetest-Blockiverse
**
** Incorporates portions of code from minetest 0.4.10-dev
**
** Blockiverse
** Copyright (C) 2014 Brian Jack <gau_veldt@hotmail.com>
** Distributed as free software using the copyleft
** LGPL Version 3 license:
** https://www.gnu.org/licenses/lgpl-3.0.en.html
** See file LICENSE in ../
**
** Blockiverse Game Implementation file core.cpp
**
** Basic core blockiverse game and database initializers.
**
*/
#include "../common.hpp"
#include "core.hpp"
namespace bvgame {
const char* queryHasModule="SELECT moduleId FROM Modules WHERE name=?1";
const char* queryAddModule="INSERT INTO Modules (name,description) VALUES (?1,?2)";
namespace core {
string coreModule="core";
string coreDesc="Main internal Blockiverse game module.";
void init(SQLiteDB &db) {
statement stmtHasModule;
statement stmtAddModule;
bool try_again;
s64 coreId=-1;
{
reread_HasCore:
stmtHasModule=db.prepare(queryHasModule);
db.bind(stmtHasModule,1,coreModule);
query_result rsltHasCore;
do {
try_again=false;
try {
rsltHasCore=db.run(stmtHasModule);
} catch (DBIsBusy &busy) {
try_again=true;
}
} while (try_again);
if (rsltHasCore->size()>0) {
coreId=db.get_result<s64>(rsltHasCore,0,0);
} else {
stmtAddModule=db.prepare(queryAddModule);
db.bind(stmtAddModule,1,coreModule);
db.bind(stmtAddModule,2,coreDesc);
query_result rsltAddCore;
do {
try_again=false;
try {
rsltAddCore=db.run(stmtAddModule);
} catch (DBIsBusy &busy) {
try_again=true;
}
} while (try_again);
goto reread_HasCore;
}
}
LOCK_COUT
cout << "[bvgame] core: module id is " << coreId << endl;
UNLOCK_COUT
}
}
}

View File

@ -0,0 +1,40 @@
/*
**
** Minetest-Blockiverse
**
** Incorporates portions of code from minetest 0.4.10-dev
**
** Blockiverse
** Copyright (C) 2014 Brian Jack <gau_veldt@hotmail.com>
** Distributed as free software using the copyleft
** LGPL Version 3 license:
** https://www.gnu.org/licenses/lgpl-3.0.en.html
** See file LICENSE in ../
**
** Declaration (header) file {Thing}.hpp
**
** {WhatThingDoes}
**
*/
#ifndef BVGAME_CORE_HPP_INCLUDED
#define BVGAME_CORE_HPP_INCLUDED
#include "../database.hpp"
namespace bvgame {
using bvdb::SQLiteDB;
using bvdb::DBIsBusy;
using bvdb::DBError;
typedef SQLiteDB::statement statement;
typedef SQLiteDB::query_result query_result;
namespace core {
void init(SQLiteDB &db);
}
}
#endif // BVGAME_CORE_HPP_INCLUDED

View File

@ -29,6 +29,7 @@
#include "queries.hpp"
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
#include "bvgame/core.hpp"
#include "Account.hpp"
@ -128,6 +129,15 @@ DWORD WINAPI server_main(LPVOID argvoid) {
<< " " << e.what() << endl;
UNLOCK_COUT
}
try {
SQLiteDB db; // RAII
bvgame::core::init(db);
} catch (DBError &e) {
LOCK_COUT
cout << "[DB] Error creating game:" << endl
<< " " << e.what() << endl;
UNLOCK_COUT
}
io_service acceptor_io;
int port=v2int(server_config["port"]);