添加f8命名空间

This commit is contained in:
aozhiwei 2018-11-26 21:09:20 +08:00
parent 51f7f26e4f
commit 83cf86548e
14 changed files with 1256 additions and 1212 deletions

View File

@ -1,41 +1,45 @@
#include "framework/cpp/dynmodule.h" #include "framework/cpp/dynmodule.h"
DynModule::DynModule() namespace f8
{ {
} DynModule::DynModule()
{
}
DynModule::~DynModule() DynModule::~DynModule()
{ {
} }
bool DynModule::IsDataMsg(int msgid) bool DynModule::IsDataMsg(int msgid)
{ {
return false; return false;
} }
bool DynModule::IsPending() bool DynModule::IsPending()
{ {
return module_state_.pending; return module_state_.pending;
} }
bool DynModule::DataIsValid() bool DynModule::DataIsValid()
{ {
return module_state_.data_is_valid; return module_state_.data_is_valid;
} }
void DynModule::MarkDataValid() void DynModule::MarkDataValid()
{ {
module_state_.data_is_valid = true; module_state_.data_is_valid = true;
} }
void DynModule::MarkPending() void DynModule::MarkPending()
{ {
module_state_.pending = true; module_state_.pending = true;
} }
void DynModule::CancelPending() void DynModule::CancelPending()
{ {
module_state_.pending = false; module_state_.pending = false;
}
} }

View File

@ -1,13 +1,15 @@
#pragma once #pragma once
struct DynModuleState namespace f8
{ {
struct DynModuleState
{
bool pending = false; bool pending = false;
bool data_is_valid = false;; bool data_is_valid = false;;
}; };
class DynModule class DynModule
{ {
public: public:
DynModule(); DynModule();
~DynModule(); ~DynModule();
@ -20,5 +22,7 @@ class DynModule
private: private:
DynModuleState module_state_; DynModuleState module_state_;
}; };
}

View File

@ -6,8 +6,11 @@
#include "framework/cpp/protoutils.h" #include "framework/cpp/protoutils.h"
#include "framework/cpp/netmsghandler.h" #include "framework/cpp/netmsghandler.h"
NetMsgHandler* GetNetMsgHandler(NetMsgHandlerObject* handlers, namespace f8
unsigned short msgid)
{ {
NetMsgHandler* GetNetMsgHandler(NetMsgHandlerObject* handlers,
unsigned short msgid)
{
return msgid < MAX_MSG_ID ? handlers->handlers[msgid] : nullptr; return msgid < MAX_MSG_ID ? handlers->handlers[msgid] : nullptr;
}
} }

View File

@ -7,24 +7,26 @@
#include <google/protobuf/extension_set.h> #include <google/protobuf/extension_set.h>
#include <google/protobuf/unknown_field_set.h> #include <google/protobuf/unknown_field_set.h>
const unsigned short MAX_MSG_ID = 2000; namespace f8
struct MsgHdr;
struct NetMsgHandler
{ {
const unsigned short MAX_MSG_ID = 2000;
struct MsgHdr;
struct NetMsgHandler
{
int handlerid; int handlerid;
const ::google::protobuf::Message* prototype = nullptr; const ::google::protobuf::Message* prototype = nullptr;
}; };
struct NetMsgHandlerObject struct NetMsgHandlerObject
{ {
NetMsgHandler* handlers[MAX_MSG_ID] = { nullptr }; NetMsgHandler* handlers[MAX_MSG_ID] = { nullptr };
}; };
template<typename InstanceType, typename MsgType> template<typename InstanceType, typename MsgType>
static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr& hdr, NetMsgHandler* handler) static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr& hdr, NetMsgHandler* handler)
{ {
MsgType msg; MsgType msg;
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset); bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset);
assert(ok); assert(ok);
@ -38,15 +40,15 @@ static void NetMsgHandlerWrapper(InstanceType* instance, MsgHdr& hdr, NetMsgHand
auto ptr = invoker->func; auto ptr = invoker->func;
(instance->*ptr)(hdr, msg); (instance->*ptr)(hdr, msg);
} }
} }
template<typename InstanceType, typename MsgType> template<typename InstanceType, typename MsgType>
static void RegisterNetMsgHandler(NetMsgHandlerObject* msghandler, static void RegisterNetMsgHandler(NetMsgHandlerObject* msghandler,
void (InstanceType::*ptr)(MsgHdr&, const MsgType&) void (InstanceType::*ptr)(MsgHdr&, const MsgType&)
) )
{ {
MsgType dumy_msg; MsgType dumy_msg;
static int msgid = ::Net_GetMessageId(dumy_msg); static int msgid = f8::Net_GetMessageId(dumy_msg);
assert(msgid >= 0 || msgid < MAX_MSG_ID); assert(msgid >= 0 || msgid < MAX_MSG_ID);
if (msgid < 0 || msgid >= MAX_MSG_ID) { if (msgid < 0 || msgid >= MAX_MSG_ID) {
abort(); abort();
@ -62,13 +64,13 @@ static void RegisterNetMsgHandler(NetMsgHandlerObject* msghandler,
p->handlerid = InstanceType::HID; p->handlerid = InstanceType::HID;
p->prototype = ::google::protobuf::MessageFactory::generated_factory()->GetPrototype(MsgType::descriptor()); p->prototype = ::google::protobuf::MessageFactory::generated_factory()->GetPrototype(MsgType::descriptor());
msghandler->handlers[msgid] = p; msghandler->handlers[msgid] = p;
} }
template<typename InstanceType> template<typename InstanceType>
static bool ProcessNetMsg(NetMsgHandler* handler, static bool ProcessNetMsg(NetMsgHandler* handler,
InstanceType* instance, InstanceType* instance,
MsgHdr& hdr) MsgHdr& hdr)
{ {
if(handler){ if(handler){
struct Invoker: public NetMsgHandler struct Invoker: public NetMsgHandler
{ {
@ -81,9 +83,9 @@ static bool ProcessNetMsg(NetMsgHandler* handler,
}else{ }else{
return false; return false;
} }
} }
NetMsgHandler* GetNetMsgHandler(NetMsgHandlerObject* handlers, NetMsgHandler* GetNetMsgHandler(NetMsgHandlerObject* handlers,
unsigned short msgid); unsigned short msgid);
}
#endif #endif

View File

@ -8,8 +8,10 @@
#include <google/protobuf/message.h> #include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
int Net_GetMessageId(::google::protobuf::Message& msg) namespace f8
{ {
int Net_GetMessageId(::google::protobuf::Message& msg)
{
std::string msgname; std::string msgname;
{ {
std::string full_msgname = msg.GetTypeName(); std::string full_msgname = msg.GetTypeName();
@ -48,10 +50,10 @@ int Net_GetMessageId(::google::protobuf::Message& msg)
return 0; return 0;
} }
return msgid_value->number(); return msgid_value->number();
} }
void Net_PackMsg(unsigned short msgid, ::google::protobuf::Message& msg, std::string& out) void Net_PackMsg(unsigned short msgid, ::google::protobuf::Message& msg, std::string& out)
{ {
int packlen = msg.ByteSize(); int packlen = msg.ByteSize();
out.resize(sizeof(PackHead) + packlen); out.resize(sizeof(PackHead) + packlen);
@ -61,10 +63,10 @@ void Net_PackMsg(unsigned short msgid, ::google::protobuf::Message& msg, std::st
head->msgid = msgid; head->msgid = msgid;
head->magic_code = MAGIC_CODE; head->magic_code = MAGIC_CODE;
msg.SerializeToArray(buff + sizeof(PackHead), packlen); msg.SerializeToArray(buff + sizeof(PackHead), packlen);
} }
int Net_SendMsg(a8::TcpClient* tcp_client, unsigned seqid, unsigned short msgid, ::google::protobuf::Message& msg) int Net_SendMsg(a8::TcpClient* tcp_client, unsigned seqid, unsigned short msgid, ::google::protobuf::Message& msg)
{ {
int packlen = msg.ByteSize(); int packlen = msg.ByteSize();
assert(packlen < 1024 * 60); assert(packlen < 1024 * 60);
@ -79,11 +81,11 @@ int Net_SendMsg(a8::TcpClient* tcp_client, unsigned seqid, unsigned short msgid,
tcp_client->SendBuff(buff, sizeof(PackHead) + packlen); tcp_client->SendBuff(buff, sizeof(PackHead) + packlen);
free(buff); free(buff);
return sizeof(PackHead) + packlen; return sizeof(PackHead) + packlen;
} }
int Net_SendMsg(a8::TcpListener* tcp_listener, unsigned short socket_handle, unsigned int seqid, int Net_SendMsg(a8::TcpListener* tcp_listener, unsigned short socket_handle, unsigned int seqid,
unsigned short msgid, ::google::protobuf::Message& msg) unsigned short msgid, ::google::protobuf::Message& msg)
{ {
int packlen = msg.ByteSize(); int packlen = msg.ByteSize();
assert(packlen < 1024 * 60); assert(packlen < 1024 * 60);
@ -98,11 +100,11 @@ int Net_SendMsg(a8::TcpListener* tcp_listener, unsigned short socket_handle, uns
tcp_listener->SendClientMsg(socket_handle, buff, sizeof(PackHead) + packlen); tcp_listener->SendClientMsg(socket_handle, buff, sizeof(PackHead) + packlen);
free(buff); free(buff);
return sizeof(PackHead) + packlen; return sizeof(PackHead) + packlen;
} }
int Net_BroadcastMsg(a8::TcpListener* tcp_listener, unsigned int seqid, int Net_BroadcastMsg(a8::TcpListener* tcp_listener, unsigned int seqid,
unsigned short msgid, ::google::protobuf::Message& msg) unsigned short msgid, ::google::protobuf::Message& msg)
{ {
int packlen = msg.ByteSize(); int packlen = msg.ByteSize();
assert(packlen < 1024 * 60); assert(packlen < 1024 * 60);
@ -117,10 +119,10 @@ int Net_BroadcastMsg(a8::TcpListener* tcp_listener, unsigned int seqid,
tcp_listener->BroadcastMsg(buff, sizeof(PackHead) + packlen); tcp_listener->BroadcastMsg(buff, sizeof(PackHead) + packlen);
free(buff); free(buff);
return sizeof(PackHead) + packlen; return sizeof(PackHead) + packlen;
} }
int Net_SendProxyCMsg(a8::TcpClient* tcp_client, unsigned short msgid, ::google::protobuf::Message& msg) int Net_SendProxyCMsg(a8::TcpClient* tcp_client, unsigned short msgid, ::google::protobuf::Message& msg)
{ {
int packlen = msg.ByteSize(); int packlen = msg.ByteSize();
assert(packlen < 1024 * 60); assert(packlen < 1024 * 60);
@ -128,30 +130,30 @@ int Net_SendProxyCMsg(a8::TcpClient* tcp_client, unsigned short msgid, ::google:
WSProxyPackHead_C* head = (WSProxyPackHead_C*)buff; WSProxyPackHead_C* head = (WSProxyPackHead_C*)buff;
head->packlen = packlen; head->packlen = packlen;
head->msgid = msgid; head->msgid = msgid;
#if 1 #if 1
head->seqid = 0; head->seqid = 0;
#else #else
head->seqid = seqid; head->seqid = seqid;
#endif #endif
head->magic_code = MAGIC_CODE; head->magic_code = MAGIC_CODE;
#if 0 #if 0
head->rpc_error_code = error_code; head->rpc_error_code = error_code;
#endif #endif
#if 1 #if 1
head->socket_handle = 0; head->socket_handle = 0;
#else #else
head->socket_handle = child_socket_handle; head->socket_handle = child_socket_handle;
#endif #endif
msg.SerializeToArray(buff + sizeof(WSProxyPackHead_C), packlen); msg.SerializeToArray(buff + sizeof(WSProxyPackHead_C), packlen);
tcp_client->SendBuff(buff, sizeof(WSProxyPackHead_C) + packlen); tcp_client->SendBuff(buff, sizeof(WSProxyPackHead_C) + packlen);
free(buff); free(buff);
return sizeof(WSProxyPackHead_C) + packlen; return sizeof(WSProxyPackHead_C) + packlen;
} }
int Net_SendProxyMsg(a8::TcpListener* tcp_listener, int socket_handle, unsigned int seqid, unsigned short error_code, int Net_SendProxyMsg(a8::TcpListener* tcp_listener, int socket_handle, unsigned int seqid, unsigned short error_code,
unsigned short msgid, ::google::protobuf::Message& msg) unsigned short msgid, ::google::protobuf::Message& msg)
{ {
unsigned short parent_socket_handle = (socket_handle >> 16) & 0xFFFF; unsigned short parent_socket_handle = (socket_handle >> 16) & 0xFFFF;
unsigned short child_socket_handle = socket_handle & 0xFFFF; unsigned short child_socket_handle = socket_handle & 0xFFFF;
@ -172,4 +174,5 @@ int Net_SendProxyMsg(a8::TcpListener* tcp_listener, int socket_handle, unsigned
tcp_listener->SendClientMsg(parent_socket_handle, buff, sizeof(WSProxyPackHead_S) + packlen); tcp_listener->SendClientMsg(parent_socket_handle, buff, sizeof(WSProxyPackHead_S) + packlen);
free(buff); free(buff);
return sizeof(WSProxyPackHead_S) + packlen; return sizeof(WSProxyPackHead_S) + packlen;
}
} }

View File

@ -1,66 +1,6 @@
#pragma once #pragma once
//普通消息头部
struct PackHead
{
unsigned short packlen;
unsigned short msgid;
unsigned int seqid;
unsigned short magic_code;
unsigned short rpc_error_code;
};
//转发类消息头部
struct ForwardPackHead
{
unsigned short packlen;
unsigned short sockethandle;
unsigned short msgid;
unsigned short src_msgid;
unsigned int src_seqid;
unsigned long ip_saddr;
unsigned int sign;
};
struct WSProxyPackHead_C
{
unsigned short packlen;
unsigned short msgid;
unsigned int seqid;
unsigned short magic_code;
unsigned short socket_handle;
unsigned long ip_saddr;
};
struct WSProxyPackHead_S
{
unsigned short packlen;
unsigned short msgid;
unsigned int seqid;
unsigned short magic_code;
unsigned short rpc_error_code;
unsigned short socket_handle;
unsigned short reserved;
};
class Player; class Player;
struct MsgHdr
{
unsigned int seqid;
unsigned short msgid;
int socket_handle;
unsigned long ip_saddr;
const char* buf;
int buflen;
int offset;
Player *hum = nullptr;
const void* user_data = nullptr;
};
const unsigned short MAGIC_CODE = (((unsigned short)'S') << 8) | ((unsigned short)'K');
namespace google namespace google
{ {
namespace protobuf namespace protobuf
@ -75,19 +15,82 @@ namespace a8
class TcpListener; class TcpListener;
} }
int Net_GetMessageId(::google::protobuf::Message& msg); namespace f8
{
//普通消息头部
struct PackHead
{
unsigned short packlen;
unsigned short msgid;
unsigned int seqid;
unsigned short magic_code;
unsigned short rpc_error_code;
};
void Net_PackMsg(unsigned short msgid, ::google::protobuf::Message& msg, std::string& out); //转发类消息头部
int Net_SendMsg(a8::TcpClient* tcp_client, unsigned int seqid, struct ForwardPackHead
{
unsigned short packlen;
unsigned short sockethandle;
unsigned short msgid;
unsigned short src_msgid;
unsigned int src_seqid;
unsigned long ip_saddr;
unsigned int sign;
};
struct WSProxyPackHead_C
{
unsigned short packlen;
unsigned short msgid;
unsigned int seqid;
unsigned short magic_code;
unsigned short socket_handle;
unsigned long ip_saddr;
};
struct WSProxyPackHead_S
{
unsigned short packlen;
unsigned short msgid;
unsigned int seqid;
unsigned short magic_code;
unsigned short rpc_error_code;
unsigned short socket_handle;
unsigned short reserved;
};
struct MsgHdr
{
unsigned int seqid;
unsigned short msgid;
int socket_handle;
unsigned long ip_saddr;
const char* buf;
int buflen;
int offset;
Player *hum = nullptr;
const void* user_data = nullptr;
};
const unsigned short MAGIC_CODE = (((unsigned short)'S') << 8) | ((unsigned short)'K');
int Net_GetMessageId(::google::protobuf::Message& msg);
void Net_PackMsg(unsigned short msgid, ::google::protobuf::Message& msg, std::string& out);
int Net_SendMsg(a8::TcpClient* tcp_client, unsigned int seqid,
unsigned short msgid, ::google::protobuf::Message& msg); unsigned short msgid, ::google::protobuf::Message& msg);
int Net_SendMsg(a8::TcpClient* tcp_client, unsigned int seqid, unsigned short msgid, int Net_SendMsg(a8::TcpClient* tcp_client, unsigned int seqid, unsigned short msgid,
const char* msgbody, int msgbody_len); const char* msgbody, int msgbody_len);
int Net_SendMsg(a8::TcpListener* tcp_tlistener, unsigned short socket_handle, unsigned int seqid, int Net_SendMsg(a8::TcpListener* tcp_tlistener, unsigned short socket_handle, unsigned int seqid,
unsigned short msgid, ::google::protobuf::Message& msg); unsigned short msgid, ::google::protobuf::Message& msg);
int Net_BroadcastMsg(a8::TcpListener* tcp_tlistener, unsigned int seqid, int Net_BroadcastMsg(a8::TcpListener* tcp_tlistener, unsigned int seqid,
unsigned short msgid, ::google::protobuf::Message& msg); unsigned short msgid, ::google::protobuf::Message& msg);
int Net_SendProxyCMsg(a8::TcpClient* tcp_client, unsigned short msgid, ::google::protobuf::Message& msg); int Net_SendProxyCMsg(a8::TcpClient* tcp_client, unsigned short msgid, ::google::protobuf::Message& msg);
int Net_SendProxyMsg(a8::TcpListener* tcp_tlistener, int socket_handle, unsigned int seqid, unsigned short error_code, int Net_SendProxyMsg(a8::TcpListener* tcp_tlistener, int socket_handle, unsigned int seqid, unsigned short error_code,
unsigned short msgid, ::google::protobuf::Message& msg); unsigned short msgid, ::google::protobuf::Message& msg);
}

View File

@ -4,8 +4,10 @@
#include "scriptengine.h" #include "scriptengine.h"
void ScriptEngine::Init() namespace f8
{ {
void ScriptEngine::Init()
{
engine_ = new a8::PyEngine(); engine_ = new a8::PyEngine();
if (getenv("is_dev_env")) { if (getenv("is_dev_env")) {
engine_->work_path = "/var/data/conf_test/game1008/res/pyscripts/"; engine_->work_path = "/var/data/conf_test/game1008/res/pyscripts/";
@ -16,21 +18,21 @@ void ScriptEngine::Init()
if (!engine_->IsInitialized()) { if (!engine_->IsInitialized()) {
abort(); abort();
} }
} }
void ScriptEngine::UnInit() void ScriptEngine::UnInit()
{ {
engine_->UnInit(); engine_->UnInit();
delete engine_; delete engine_;
engine_ = nullptr; engine_ = nullptr;
} }
void ScriptEngine::Update() void ScriptEngine::Update()
{ {
} }
bool ScriptEngine::LoadModule(const std::string& module_name) bool ScriptEngine::LoadModule(const std::string& module_name)
{ {
bool ret = engine_->LoadModule(module_name.c_str()); bool ret = engine_->LoadModule(module_name.c_str());
if (!ret) { if (!ret) {
a8::UdpLog::Instance()->Warning("load python module %s error %s\n", a8::UdpLog::Instance()->Warning("load python module %s error %s\n",
@ -41,10 +43,10 @@ bool ScriptEngine::LoadModule(const std::string& module_name)
assert(false); assert(false);
} }
return ret; return ret;
} }
bool ScriptEngine::LoadString(const std::string& str) bool ScriptEngine::LoadString(const std::string& str)
{ {
bool ret = engine_->ExecString(str.c_str()); bool ret = engine_->ExecString(str.c_str());
if (!ret) { if (!ret) {
a8::UdpLog::Instance()->Warning("load python string %s error %s", a8::UdpLog::Instance()->Warning("load python string %s error %s",
@ -55,11 +57,11 @@ bool ScriptEngine::LoadString(const std::string& str)
assert(false); assert(false);
} }
return ret; return ret;
} }
std::tuple<bool, a8::XValue> ScriptEngine::CallGlobalFunc(const char* func_name, std::tuple<bool, a8::XValue> ScriptEngine::CallGlobalFunc(const char* func_name,
std::initializer_list<a8::XValue> args) std::initializer_list<a8::XValue> args)
{ {
auto ret = engine_->CallGlobalFunc(func_name, args); auto ret = engine_->CallGlobalFunc(func_name, args);
if (!std::get<0>(ret)) { if (!std::get<0>(ret)) {
a8::UdpLog::Instance()->Warning("call global function %s error %s", a8::UdpLog::Instance()->Warning("call global function %s error %s",
@ -69,12 +71,12 @@ std::tuple<bool, a8::XValue> ScriptEngine::CallGlobalFunc(const char* func_name,
}); });
} }
return ret; return ret;
} }
std::tuple<bool, a8::XValue> ScriptEngine::CallModuleFunc(const char* module_name, std::tuple<bool, a8::XValue> ScriptEngine::CallModuleFunc(const char* module_name,
const char* func_name, const char* func_name,
std::initializer_list<a8::XValue> args) std::initializer_list<a8::XValue> args)
{ {
auto ret = engine_->CallModuleFunc(module_name, func_name, args); auto ret = engine_->CallModuleFunc(module_name, func_name, args);
if (!std::get<0>(ret)) { if (!std::get<0>(ret)) {
a8::UdpLog::Instance()->Warning("call module function [%s] %s error %s", a8::UdpLog::Instance()->Warning("call module function [%s] %s error %s",
@ -85,4 +87,5 @@ std::tuple<bool, a8::XValue> ScriptEngine::CallModuleFunc(const char* module_nam
}); });
} }
return ret; return ret;
}
} }

View File

@ -5,8 +5,10 @@ namespace a8
class PyEngine; class PyEngine;
}; };
class ScriptEngine : public a8::Singleton<ScriptEngine> namespace f8
{ {
class ScriptEngine : public a8::Singleton<ScriptEngine>
{
private: private:
ScriptEngine() {}; ScriptEngine() {};
friend class a8::Singleton<ScriptEngine>; friend class a8::Singleton<ScriptEngine>;
@ -27,4 +29,6 @@ class ScriptEngine : public a8::Singleton<ScriptEngine>
public: public:
a8::PyEngine *engine_ = nullptr; a8::PyEngine *engine_ = nullptr;
}; };
}

View File

@ -7,19 +7,21 @@
#include <a8/mutable_xobject.h> #include <a8/mutable_xobject.h>
#include "tglog.h" #include "tglog.h"
static const char* const TGLOG_ROOT = "/data/logs/%s/upload/"; namespace f8
static const char* const POLY_TGLOG_ROOT = "/data/logs/%s/%s/upload/";
static const char* const TGLOG_FILENAME = "log_$pid_%Y%m%d%H.log";
struct TGLogMsgNode
{ {
static const char* const TGLOG_ROOT = "/data/logs/%s/upload/";
static const char* const POLY_TGLOG_ROOT = "/data/logs/%s/%s/upload/";
static const char* const TGLOG_FILENAME = "log_$pid_%Y%m%d%H.log";
struct TGLogMsgNode
{
int game_id = 0; int game_id = 0;
std::string jsonstr; std::string jsonstr;
TGLogMsgNode* next = nullptr; TGLogMsgNode* next = nullptr;
}; };
struct TGLogImpl struct TGLogImpl
{ {
std::string filename_fmt; std::string filename_fmt;
std::string project_name; std::string project_name;
bool is_poly_log = false; bool is_poly_log = false;
@ -60,10 +62,10 @@ struct TGLogImpl
std::string filename((char*)szfilename); std::string filename((char*)szfilename);
return filename; return filename;
} }
}; };
void TGLog::Init() void TGLog::Init()
{ {
impl_ = new TGLogImpl(); impl_ = new TGLogImpl();
impl_->filename_fmt = TGLOG_FILENAME; impl_->filename_fmt = TGLOG_FILENAME;
a8::ReplaceString(impl_->filename_fmt, "$pid", a8::XValue(getpid())); a8::ReplaceString(impl_->filename_fmt, "$pid", a8::XValue(getpid()));
@ -73,23 +75,23 @@ void TGLog::Init()
impl_->save_thread_shutdown = false; impl_->save_thread_shutdown = false;
impl_->save_thread = new std::thread(&TGLog::SaveToFileThreadProc, this); impl_->save_thread = new std::thread(&TGLog::SaveToFileThreadProc, this);
} }
void TGLog::UnInit() void TGLog::UnInit()
{ {
delete impl_; delete impl_;
impl_ = nullptr; impl_ = nullptr;
} }
void TGLog::SetProjectInfo(const std::string& project_name, bool is_poly_log) void TGLog::SetProjectInfo(const std::string& project_name, bool is_poly_log)
{ {
project_name_ = project_name; project_name_ = project_name;
is_poly_log_ = is_poly_log; is_poly_log_ = is_poly_log;
} }
void TGLog::AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr, void TGLog::AddTrackLog(int game_id, const std::string& accountid, unsigned long ip_saddr,
int logclass1, int logclass2, a8::XObject* prop) int logclass1, int logclass2, a8::XObject* prop)
{ {
std::string logtime_str; std::string logtime_str;
{ {
time_t nowtime = time(nullptr); time_t nowtime = time(nullptr);
@ -127,10 +129,10 @@ void TGLog::AddTrackLog(int game_id, const std::string& accountid, unsigned long
impl_->save_cond->notify_all(); impl_->save_cond->notify_all();
} }
} }
} }
void TGLog::SaveToFileThreadProc() void TGLog::SaveToFileThreadProc()
{ {
auto GetLogFile = [this] (std::map<int, FILE*>& opened_log_files_hash, int game_id, const std::string& filename) -> FILE* auto GetLogFile = [this] (std::map<int, FILE*>& opened_log_files_hash, int game_id, const std::string& filename) -> FILE*
{ {
auto itr = opened_log_files_hash.find(game_id); auto itr = opened_log_files_hash.find(game_id);
@ -192,4 +194,5 @@ void TGLog::SaveToFileThreadProc()
} }
} }
}
} }

View File

@ -1,13 +1,15 @@
#pragma once #pragma once
struct TGLogImpl; namespace f8
class TGLog : public a8::Singleton<TGLog>
{ {
struct TGLogImpl;
class TGLog : public a8::Singleton<TGLog>
{
private: private:
TGLog() {}; TGLog() {};
friend class a8::Singleton<TGLog>; friend class a8::Singleton<TGLog>;
public: public:
void Init(); void Init();
void UnInit(); void UnInit();
@ -22,4 +24,5 @@ public:
std::string project_name_; std::string project_name_;
bool is_poly_log_ = false; bool is_poly_log_ = false;
TGLogImpl* impl_ = nullptr; TGLogImpl* impl_ = nullptr;
}; };
}

View File

@ -3,33 +3,35 @@
#include <a8/stringlist.h> #include <a8/stringlist.h>
#include "framework/cpp/tiledmap.h" #include "framework/cpp/tiledmap.h"
a8::XValue TiledObject::GetProperty(const std::string& prop_name) namespace f8
{ {
a8::XValue TiledObject::GetProperty(const std::string& prop_name)
{
auto itr = prop_hash.find(prop_name); auto itr = prop_hash.find(prop_name);
return itr != prop_hash.end() ? itr->second : a8::XValue(); return itr != prop_hash.end() ? itr->second : a8::XValue();
} }
bool TiledObject::HasProperty(const std::string& prop_name) bool TiledObject::HasProperty(const std::string& prop_name)
{ {
auto itr = prop_hash.find(prop_name); auto itr = prop_hash.find(prop_name);
return itr != prop_hash.end(); return itr != prop_hash.end();
} }
a8::XValue TiledLayer::GetProperty(const std::string& prop_name) a8::XValue TiledLayer::GetProperty(const std::string& prop_name)
{ {
auto itr = prop_hash.find(prop_name); auto itr = prop_hash.find(prop_name);
return itr != prop_hash.end() ? itr->second : a8::XValue(); return itr != prop_hash.end() ? itr->second : a8::XValue();
} }
bool TiledLayer::HasProperty(const std::string& prop_name) bool TiledLayer::HasProperty(const std::string& prop_name)
{ {
auto itr = prop_hash.find(prop_name); auto itr = prop_hash.find(prop_name);
return itr != prop_hash.end(); return itr != prop_hash.end();
} }
bool TiledMap::LoadTmxFile(const std::string& filename) bool TiledMap::LoadTmxFile(const std::string& filename)
{ {
a8::XObject xobj; a8::XObject xobj;
if (!xobj.ReadFromXmlFile(filename)) { if (!xobj.ReadFromXmlFile(filename)) {
return false; return false;
@ -38,13 +40,13 @@ bool TiledMap::LoadTmxFile(const std::string& filename)
std::shared_ptr<a8::XObject> tileset_node = xobj.At("child_node.tileset")->At(0); std::shared_ptr<a8::XObject> tileset_node = xobj.At("child_node.tileset")->At(0);
tile_width = tileset_node->At("attrs.tilewidth")->AsXValue(); tile_width = tileset_node->At("attrs.tilewidth")->AsXValue();
tile_height = tileset_node->At("attrs.tileheight")->AsXValue(); tile_height = tileset_node->At("attrs.tileheight")->AsXValue();
#if 0 #if 0
tile_count = tileset_node->At("attrs.tilecount")->AsXValue(); tile_count = tileset_node->At("attrs.tilecount")->AsXValue();
tile_columns = tileset_node->At("attrs.columns")->AsXValue(); tile_columns = tileset_node->At("attrs.columns")->AsXValue();
tile_rows = tile_count/tile_columns + 1; tile_rows = tile_count/tile_columns + 1;
tile_columns += 1; tile_columns += 1;
tile_count = tile_rows * tile_columns; tile_count = tile_rows * tile_columns;
#endif #endif
for (int i = 0; i < xobj.At("child_node.layer")->Size(); ++i) { for (int i = 0; i < xobj.At("child_node.layer")->Size(); ++i) {
std::shared_ptr<a8::XObject> layer_node = xobj.At("child_node.layer")->At(i); std::shared_ptr<a8::XObject> layer_node = xobj.At("child_node.layer")->At(i);
@ -108,40 +110,40 @@ bool TiledMap::LoadTmxFile(const std::string& filename)
return true; return true;
} }
std::list<TiledObject>* TiledMap::GetObjectGroup(const std::string& object_class_name) std::list<TiledObject>* TiledMap::GetObjectGroup(const std::string& object_class_name)
{ {
auto itr = object_group_hash.find(object_class_name); auto itr = object_group_hash.find(object_class_name);
return itr != object_group_hash.end() ? &itr->second : nullptr; return itr != object_group_hash.end() ? &itr->second : nullptr;
} }
StagePoint* TiledMap::GetStageObject(int point) StagePoint* TiledMap::GetStageObject(int point)
{ {
auto itr = stage_object_hash.find(point); auto itr = stage_object_hash.find(point);
return itr != stage_object_hash.end() ? &itr->second : nullptr; return itr != stage_object_hash.end() ? &itr->second : nullptr;
} }
bool TiledMap::HasStageObject(int point) bool TiledMap::HasStageObject(int point)
{ {
auto itr = stage_object_hash.find(point); auto itr = stage_object_hash.find(point);
return itr != stage_object_hash.end(); return itr != stage_object_hash.end();
} }
std::vector<GridCell*>* TiledMap::GetStagePath(const std::string& path_name) std::vector<GridCell*>* TiledMap::GetStagePath(const std::string& path_name)
{ {
auto itr = stage_path_hash.find(path_name); auto itr = stage_path_hash.find(path_name);
return itr != stage_path_hash.end() ? &itr->second : nullptr; return itr != stage_path_hash.end() ? &itr->second : nullptr;
} }
bool TiledMap::HasStagePath(const std::string& path_name) bool TiledMap::HasStagePath(const std::string& path_name)
{ {
auto itr = stage_path_hash.find(path_name); auto itr = stage_path_hash.find(path_name);
return itr != stage_path_hash.end(); return itr != stage_path_hash.end();
} }
void TiledMap::Init() void TiledMap::Init()
{ {
grid_cell_list.reserve(tile_count); grid_cell_list.reserve(tile_count);
grid_cell_list.assign(tile_count,GridCell{}); grid_cell_list.assign(tile_count,GridCell{});
@ -218,33 +220,33 @@ void TiledMap::Init()
stage_object_hash[point] = sp; stage_object_hash[point] = sp;
} }
} }
} }
void TiledMap::Dump() void TiledMap::Dump()
{ {
Init(); Init();
#if 0 #if 0
for (auto& pair : stage_path_hash) { for (auto& pair : stage_path_hash) {
a8::XPrintf("stage$:%s\n", {pair.first}); a8::XPrintf("stage$:%s\n", {pair.first});
for (auto& gc : pair.second) { for (auto& gc : pair.second) {
a8::XPrintf("path$x:%d,y:%d,speed:%d,value:%d\n", {gc->x, gc->y, gc->speed, gc->value}); a8::XPrintf("path$x:%d,y:%d,speed:%d,value:%d\n", {gc->x, gc->y, gc->speed, gc->value});
} }
} }
#endif #endif
#if 0 #if 0
for (auto& tp : trigger_list) { for (auto& tp : trigger_list) {
a8::XPrintf("x:%d,y:%d,point:%d,istrigger:%d\n", {tp.x, tp.y, tp.point, a8::XValue(tp.istrigger)}); a8::XPrintf("x:%d,y:%d,point:%d,istrigger:%d\n", {tp.x, tp.y, tp.point, a8::XValue(tp.istrigger)});
} }
#endif #endif
#if 0 #if 0
int len = grid_cell_list.size(); int len = grid_cell_list.size();
a8::XPrintf("grid_cell_size:%s\n", {len}); a8::XPrintf("grid_cell_size:%s\n", {len});
for (int i= 0; i < len; ++i) { for (int i= 0; i < len; ++i) {
auto gc = grid_cell_list[i]; auto gc = grid_cell_list[i];
a8::XPrintf("i:%d, x:%d,y:%d,speed:%d,value:%d\n", {i, gc.x, gc.y, gc.speed, gc.value}); a8::XPrintf("i:%d, x:%d,y:%d,speed:%d,value:%d\n", {i, gc.x, gc.y, gc.speed, gc.value});
} }
#endif #endif
#if 0 #if 0
for (auto& pair : stage_object_hash) { for (auto& pair : stage_object_hash) {
a8::XPrintf("object$:%s\n", {pair.first}); a8::XPrintf("object$:%s\n", {pair.first});
a8::XPrintf("value$x:%d,y:%d,p:%s,relation:", {pair.second.x, pair.second.y, pair.second.point}); a8::XPrintf("value$x:%d,y:%d,p:%s,relation:", {pair.second.x, pair.second.y, pair.second.point});
@ -253,7 +255,7 @@ void TiledMap::Dump()
} }
a8::XPrintf("\n",{}); a8::XPrintf("\n",{});
} }
#endif #endif
return; return;
a8::XPrintf("map$tile_count:%d\n", {tile_count}); a8::XPrintf("map$tile_count:%d\n", {tile_count});
@ -278,10 +280,10 @@ void TiledMap::Dump()
} }
} }
} }
} }
bool TiledMap::CalcCurrPos(std::vector<int>& path_points, int old_pos_x, int old_pos_y, int time_ms, int& curr_pos_x, int& curr_pos_y) bool TiledMap::CalcCurrPos(std::vector<int>& path_points, int old_pos_x, int old_pos_y, int time_ms, int& curr_pos_x, int& curr_pos_y)
{ {
if (path_points.size() < 2) { if (path_points.size() < 2) {
return false; return false;
} }
@ -458,3 +460,4 @@ void TiledMap::SetGridCellSpeedByAreaId(std::map<int,int>& area_speed_hash)
} }
} }
} }
}

View File

@ -1,17 +1,19 @@
#pragma once #pragma once
class TiledObject namespace f8
{ {
class TiledObject
{
public: public:
a8::XValue GetProperty(const std::string& prop_name); a8::XValue GetProperty(const std::string& prop_name);
bool HasProperty(const std::string& prop_name); bool HasProperty(const std::string& prop_name);
public: public:
std::map<std::string, a8::XValue> prop_hash; std::map<std::string, a8::XValue> prop_hash;
}; };
class TiledLayer class TiledLayer
{ {
public: public:
a8::XValue GetProperty(const std::string& prop_name); a8::XValue GetProperty(const std::string& prop_name);
@ -20,35 +22,35 @@ class TiledLayer
public: public:
std::map<std::string, a8::XValue> prop_hash; std::map<std::string, a8::XValue> prop_hash;
a8::XValue data; a8::XValue data;
}; };
//格子对象 //格子对象
struct GridCell struct GridCell
{ {
int x = 0; int x = 0;
int y = 0; int y = 0;
int speed = 0; int speed = 0;
int value = 0; int value = 0;
}; };
struct StagePoint struct StagePoint
{ {
int x = 0; int x = 0;
int y = 0; int y = 0;
int point = 0; int point = 0;
std::vector<int> relation_list; std::vector<int> relation_list;
}; };
struct TriggerPoint struct TriggerPoint
{ {
int x = 0; int x = 0;
int y = 0; int y = 0;
int point = 0; int point = 0;
bool istrigger = false; bool istrigger = false;
}; };
class TiledMap class TiledMap
{ {
public: public:
TiledLayer* ground_layer = nullptr; TiledLayer* ground_layer = nullptr;
std::list<TiledLayer> speed_layers; std::list<TiledLayer> speed_layers;
@ -84,4 +86,5 @@ class TiledMap
std::vector<GridCell> grid_cell_list; //所有的格子数组 size = x * y std::vector<GridCell> grid_cell_list; //所有的格子数组 size = x * y
std::map<std::string, std::vector<GridCell>> grid_cell_hash; //key 11|2 坐标 std::map<std::string, std::vector<GridCell>> grid_cell_hash; //key 11|2 坐标
}; };
}

View File

@ -9,10 +9,12 @@
#include "framework/cpp/utils.h" #include "framework/cpp/utils.h"
bool ReadCsvMetaFile(const std::string& filename, namespace f8
{
bool ReadCsvMetaFile(const std::string& filename,
google::protobuf::Message* prototype, google::protobuf::Message* prototype,
std::function<void (google::protobuf::Message*)> push_back_func) std::function<void (google::protobuf::Message*)> push_back_func)
{ {
const google::protobuf::Descriptor* descriptor = prototype->GetDescriptor(); const google::protobuf::Descriptor* descriptor = prototype->GetDescriptor();
const google::protobuf::Reflection* reflection = prototype->GetReflection(); const google::protobuf::Reflection* reflection = prototype->GetReflection();
@ -76,10 +78,10 @@ bool ReadCsvMetaFile(const std::string& filename,
} }
return true; return true;
} }
void InitMysqlConnection(a8::mysql::Query* query) void InitMysqlConnection(a8::mysql::Query* query)
{ {
a8::UdpLog::Instance()->Info("show variables like 'character%';", {}); a8::UdpLog::Instance()->Info("show variables like 'character%';", {});
a8::UdpLog::Instance()->Info("Variable_name\tValue", {}); a8::UdpLog::Instance()->Info("Variable_name\tValue", {});
#if 1 #if 1
@ -116,20 +118,20 @@ void InitMysqlConnection(a8::mysql::Query* query)
assert(query->GetValue(1).GetString() == "utf8_general_ci"); assert(query->GetValue(1).GetString() == "utf8_general_ci");
query->Next(); query->Next();
} }
} }
bool CheckRegisterTimeInSessionId(const std::string& accountid, const std::string& sessionid) bool CheckRegisterTimeInSessionId(const std::string& accountid, const std::string& sessionid)
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
a8::Split(sessionid, strings, '_'); a8::Split(sessionid, strings, '_');
if (strings.size() < 4) { if (strings.size() < 4) {
return false; return false;
} }
return true; return true;
} }
time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid) time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid)
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
a8::Split(sessionid, strings, '_'); a8::Split(sessionid, strings, '_');
if (strings.size() < 4) { if (strings.size() < 4) {
@ -140,20 +142,20 @@ time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid)
std::string md51 = strings[2]; std::string md51 = strings[2];
std::string md52 = strings[3]; std::string md52 = strings[3];
return a8::XValue(account_registertime); return a8::XValue(account_registertime);
} }
bool IsValidSessionId(const std::string& accountid, const std::string& sessionid) bool IsValidSessionId(const std::string& accountid, const std::string& sessionid)
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
a8::Split(sessionid, strings, '_'); a8::Split(sessionid, strings, '_');
if (strings.size() < 4) { if (strings.size() < 4) {
return false; return false;
} }
return true; return true;
} }
int ExtractGameIdFromAccountId(const std::string& accountid) int ExtractGameIdFromAccountId(const std::string& accountid)
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
a8::Split(accountid, strings, '_'); a8::Split(accountid, strings, '_');
if (strings.size() < 2) { if (strings.size() < 2) {
@ -162,10 +164,10 @@ int ExtractGameIdFromAccountId(const std::string& accountid)
std::string channelid = strings[0]; std::string channelid = strings[0];
std::string gameid = strings[1]; std::string gameid = strings[1];
return a8::XValue(gameid); return a8::XValue(gameid);
} }
int ExtractChannelIdFromAccountId(const std::string& accountid) int ExtractChannelIdFromAccountId(const std::string& accountid)
{ {
std::vector<std::string> strings; std::vector<std::string> strings;
a8::Split(accountid, strings, '_'); a8::Split(accountid, strings, '_');
if (strings.size() < 2) { if (strings.size() < 2) {
@ -174,4 +176,5 @@ int ExtractChannelIdFromAccountId(const std::string& accountid)
std::string channelid = strings[0]; std::string channelid = strings[0];
std::string gameid = strings[1]; std::string gameid = strings[1];
return a8::XValue(channelid); return a8::XValue(channelid);
}
} }

View File

@ -17,13 +17,15 @@ namespace a8
} }
} }
bool ReadCsvMetaFile(const std::string& filename, namespace f8
{
bool ReadCsvMetaFile(const std::string& filename,
google::protobuf::Message* prototype, google::protobuf::Message* prototype,
std::function<void (google::protobuf::Message*)> push_back_func); std::function<void (google::protobuf::Message*)> push_back_func);
template <typename T> template <typename T>
bool ReadCsvMetaFile(const std::string& filename, std::list<T>& meta_list) bool ReadCsvMetaFile(const std::string& filename, std::list<T>& meta_list)
{ {
T dummy; T dummy;
return ReadCsvMetaFile(filename, return ReadCsvMetaFile(filename,
&dummy, &dummy,
@ -33,52 +35,53 @@ bool ReadCsvMetaFile(const std::string& filename, std::list<T>& meta_list)
t.CopyFrom(*msg); t.CopyFrom(*msg);
meta_list.emplace_back(t); meta_list.emplace_back(t);
}); });
} }
template <typename T1, template <typename T1,
typename T2> typename T2>
static void RepeatedFieldToVector(const T1& t1, T2& t2) static void RepeatedFieldToVector(const T1& t1, T2& t2)
{ {
t2.clear(); t2.clear();
for (auto& val : t1) { for (auto& val : t1) {
t2.push_back(val); t2.push_back(val);
} }
} }
template <typename T1, template <typename T1,
typename T2> typename T2>
static void RepeatedFieldToSet(const T1& t1, T2& t2) static void RepeatedFieldToSet(const T1& t1, T2& t2)
{ {
t2.clear(); t2.clear();
for (auto& val : t1) { for (auto& val : t1) {
t2.insert(val); t2.insert(val);
} }
} }
template <typename T1, template <typename T1,
typename T2> typename T2>
static void VectorToRepeatedField(const T1& t1, T2& t2) static void VectorToRepeatedField(const T1& t1, T2& t2)
{ {
t2.Clear(); t2.Clear();
for (auto& val : t1) { for (auto& val : t1) {
*t2.Add() = val; *t2.Add() = val;
} }
} }
template <typename T1, template <typename T1,
typename T2> typename T2>
static void SetToRepeatedField(const T1& t1, T2& t2) static void SetToRepeatedField(const T1& t1, T2& t2)
{ {
t2.Clear(); t2.Clear();
for (auto& val : t1) { for (auto& val : t1) {
*t2.Add() = val; *t2.Add() = val;
} }
}
void InitMysqlConnection(a8::mysql::Query* query);
bool CheckRegisterTimeInSessionId(const std::string& accountid, const std::string& sessionid);
time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid);
bool IsValidSessionId(const std::string& accountid, const std::string& sessionid);
int ExtractGameIdFromAccountId(const std::string& accountid);
int ExtractChannelIdFromAccountId(const std::string& accountid);
} }
void InitMysqlConnection(a8::mysql::Query* query);
bool CheckRegisterTimeInSessionId(const std::string& accountid, const std::string& sessionid);
time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid);
bool IsValidSessionId(const std::string& accountid, const std::string& sessionid);
int ExtractGameIdFromAccountId(const std::string& accountid);
int ExtractChannelIdFromAccountId(const std::string& accountid);