添加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"
DynModule::DynModule()
namespace f8
{
}
DynModule::DynModule()
{
}
DynModule::~DynModule()
{
DynModule::~DynModule()
{
}
}
bool DynModule::IsDataMsg(int msgid)
{
bool DynModule::IsDataMsg(int msgid)
{
return false;
}
}
bool DynModule::IsPending()
{
bool DynModule::IsPending()
{
return module_state_.pending;
}
}
bool DynModule::DataIsValid()
{
bool DynModule::DataIsValid()
{
return module_state_.data_is_valid;
}
}
void DynModule::MarkDataValid()
{
void DynModule::MarkDataValid()
{
module_state_.data_is_valid = true;
}
}
void DynModule::MarkPending()
{
void DynModule::MarkPending()
{
module_state_.pending = true;
}
}
void DynModule::CancelPending()
{
void DynModule::CancelPending()
{
module_state_.pending = false;
}
}

View File

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

View File

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

View File

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

View File

@ -8,8 +8,10 @@
#include <google/protobuf/message.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 full_msgname = msg.GetTypeName();
@ -48,10 +50,10 @@ int Net_GetMessageId(::google::protobuf::Message& msg)
return 0;
}
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();
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->magic_code = MAGIC_CODE;
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();
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);
free(buff);
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)
{
{
int packlen = msg.ByteSize();
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);
free(buff);
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)
{
{
int packlen = msg.ByteSize();
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);
free(buff);
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();
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;
head->packlen = packlen;
head->msgid = msgid;
#if 1
#if 1
head->seqid = 0;
#else
#else
head->seqid = seqid;
#endif
#endif
head->magic_code = MAGIC_CODE;
#if 0
#if 0
head->rpc_error_code = error_code;
#endif
#if 1
#endif
#if 1
head->socket_handle = 0;
#else
#else
head->socket_handle = child_socket_handle;
#endif
#endif
msg.SerializeToArray(buff + sizeof(WSProxyPackHead_C), packlen);
tcp_client->SendBuff(buff, sizeof(WSProxyPackHead_C) + packlen);
free(buff);
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 parent_socket_handle = (socket_handle >> 16) & 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);
free(buff);
return sizeof(WSProxyPackHead_S) + packlen;
}
}

View File

@ -1,66 +1,6 @@
#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;
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 protobuf
@ -75,19 +15,82 @@ namespace a8
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);
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);
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);
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);
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);
}

View File

@ -4,8 +4,10 @@
#include "scriptengine.h"
void ScriptEngine::Init()
namespace f8
{
void ScriptEngine::Init()
{
engine_ = new a8::PyEngine();
if (getenv("is_dev_env")) {
engine_->work_path = "/var/data/conf_test/game1008/res/pyscripts/";
@ -16,21 +18,21 @@ void ScriptEngine::Init()
if (!engine_->IsInitialized()) {
abort();
}
}
}
void ScriptEngine::UnInit()
{
void ScriptEngine::UnInit()
{
engine_->UnInit();
delete engine_;
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());
if (!ret) {
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);
}
return ret;
}
}
bool ScriptEngine::LoadString(const std::string& str)
{
bool ScriptEngine::LoadString(const std::string& str)
{
bool ret = engine_->ExecString(str.c_str());
if (!ret) {
a8::UdpLog::Instance()->Warning("load python string %s error %s",
@ -55,11 +57,11 @@ bool ScriptEngine::LoadString(const std::string& str)
assert(false);
}
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)
{
{
auto ret = engine_->CallGlobalFunc(func_name, args);
if (!std::get<0>(ret)) {
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;
}
}
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,
std::initializer_list<a8::XValue> args)
{
{
auto ret = engine_->CallModuleFunc(module_name, func_name, args);
if (!std::get<0>(ret)) {
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;
}
}

View File

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

View File

@ -7,19 +7,21 @@
#include <a8/mutable_xobject.h>
#include "tglog.h"
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
namespace f8
{
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;
std::string jsonstr;
TGLogMsgNode* next = nullptr;
};
};
struct TGLogImpl
{
struct TGLogImpl
{
std::string filename_fmt;
std::string project_name;
bool is_poly_log = false;
@ -60,10 +62,10 @@ struct TGLogImpl
std::string filename((char*)szfilename);
return filename;
}
};
};
void TGLog::Init()
{
void TGLog::Init()
{
impl_ = new TGLogImpl();
impl_->filename_fmt = TGLOG_FILENAME;
a8::ReplaceString(impl_->filename_fmt, "$pid", a8::XValue(getpid()));
@ -73,23 +75,23 @@ void TGLog::Init()
impl_->save_thread_shutdown = false;
impl_->save_thread = new std::thread(&TGLog::SaveToFileThreadProc, this);
}
}
void TGLog::UnInit()
{
void TGLog::UnInit()
{
delete impl_;
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;
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)
{
{
std::string logtime_str;
{
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();
}
}
}
}
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 itr = opened_log_files_hash.find(game_id);
@ -192,4 +194,5 @@ void TGLog::SaveToFileThreadProc()
}
}
}
}

View File

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

View File

@ -3,33 +3,35 @@
#include <a8/stringlist.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);
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);
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);
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);
return itr != prop_hash.end();
}
}
bool TiledMap::LoadTmxFile(const std::string& filename)
{
bool TiledMap::LoadTmxFile(const std::string& filename)
{
a8::XObject xobj;
if (!xobj.ReadFromXmlFile(filename)) {
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);
tile_width = tileset_node->At("attrs.tilewidth")->AsXValue();
tile_height = tileset_node->At("attrs.tileheight")->AsXValue();
#if 0
#if 0
tile_count = tileset_node->At("attrs.tilecount")->AsXValue();
tile_columns = tileset_node->At("attrs.columns")->AsXValue();
tile_rows = tile_count/tile_columns + 1;
tile_columns += 1;
tile_count = tile_rows * tile_columns;
#endif
#endif
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);
@ -108,40 +110,40 @@ bool TiledMap::LoadTmxFile(const std::string& filename)
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);
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);
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);
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);
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);
return itr != stage_path_hash.end();
}
}
void TiledMap::Init()
{
void TiledMap::Init()
{
grid_cell_list.reserve(tile_count);
grid_cell_list.assign(tile_count,GridCell{});
@ -218,33 +220,33 @@ void TiledMap::Init()
stage_object_hash[point] = sp;
}
}
}
}
void TiledMap::Dump()
{
void TiledMap::Dump()
{
Init();
#if 0
#if 0
for (auto& pair : stage_path_hash) {
a8::XPrintf("stage$:%s\n", {pair.first});
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});
}
}
#endif
#if 0
#endif
#if 0
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)});
}
#endif
#if 0
#endif
#if 0
int len = grid_cell_list.size();
a8::XPrintf("grid_cell_size:%s\n", {len});
for (int i= 0; i < len; ++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});
}
#endif
#if 0
#endif
#if 0
for (auto& pair : stage_object_hash) {
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});
@ -253,7 +255,7 @@ void TiledMap::Dump()
}
a8::XPrintf("\n",{});
}
#endif
#endif
return;
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) {
return false;
}
@ -458,3 +460,4 @@ void TiledMap::SetGridCellSpeedByAreaId(std::map<int,int>& area_speed_hash)
}
}
}
}

View File

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

View File

@ -9,10 +9,12 @@
#include "framework/cpp/utils.h"
bool ReadCsvMetaFile(const std::string& filename,
namespace f8
{
bool ReadCsvMetaFile(const std::string& filename,
google::protobuf::Message* prototype,
std::function<void (google::protobuf::Message*)> push_back_func)
{
{
const google::protobuf::Descriptor* descriptor = prototype->GetDescriptor();
const google::protobuf::Reflection* reflection = prototype->GetReflection();
@ -76,10 +78,10 @@ bool ReadCsvMetaFile(const std::string& filename,
}
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("Variable_name\tValue", {});
#if 1
@ -116,20 +118,20 @@ void InitMysqlConnection(a8::mysql::Query* query)
assert(query->GetValue(1).GetString() == "utf8_general_ci");
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;
a8::Split(sessionid, strings, '_');
if (strings.size() < 4) {
return false;
}
return true;
}
}
time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid)
{
time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid)
{
std::vector<std::string> strings;
a8::Split(sessionid, strings, '_');
if (strings.size() < 4) {
@ -140,20 +142,20 @@ time_t ExtractRegisterTimeFromSessionId(const std::string& sessionid)
std::string md51 = strings[2];
std::string md52 = strings[3];
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;
a8::Split(sessionid, strings, '_');
if (strings.size() < 4) {
return false;
}
return true;
}
}
int ExtractGameIdFromAccountId(const std::string& accountid)
{
int ExtractGameIdFromAccountId(const std::string& accountid)
{
std::vector<std::string> strings;
a8::Split(accountid, strings, '_');
if (strings.size() < 2) {
@ -162,10 +164,10 @@ int ExtractGameIdFromAccountId(const std::string& accountid)
std::string channelid = strings[0];
std::string gameid = strings[1];
return a8::XValue(gameid);
}
}
int ExtractChannelIdFromAccountId(const std::string& accountid)
{
int ExtractChannelIdFromAccountId(const std::string& accountid)
{
std::vector<std::string> strings;
a8::Split(accountid, strings, '_');
if (strings.size() < 2) {
@ -174,4 +176,5 @@ int ExtractChannelIdFromAccountId(const std::string& accountid)
std::string channelid = strings[0];
std::string gameid = strings[1];
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,
std::function<void (google::protobuf::Message*)> push_back_func);
template <typename T>
bool ReadCsvMetaFile(const std::string& filename, std::list<T>& meta_list)
{
template <typename T>
bool ReadCsvMetaFile(const std::string& filename, std::list<T>& meta_list)
{
T dummy;
return ReadCsvMetaFile(filename,
&dummy,
@ -33,52 +35,53 @@ bool ReadCsvMetaFile(const std::string& filename, std::list<T>& meta_list)
t.CopyFrom(*msg);
meta_list.emplace_back(t);
});
}
}
template <typename T1,
template <typename T1,
typename T2>
static void RepeatedFieldToVector(const T1& t1, T2& t2)
{
static void RepeatedFieldToVector(const T1& t1, T2& t2)
{
t2.clear();
for (auto& val : t1) {
t2.push_back(val);
}
}
}
template <typename T1,
template <typename T1,
typename T2>
static void RepeatedFieldToSet(const T1& t1, T2& t2)
{
static void RepeatedFieldToSet(const T1& t1, T2& t2)
{
t2.clear();
for (auto& val : t1) {
t2.insert(val);
}
}
}
template <typename T1,
template <typename T1,
typename T2>
static void VectorToRepeatedField(const T1& t1, T2& t2)
{
static void VectorToRepeatedField(const T1& t1, T2& t2)
{
t2.Clear();
for (auto& val : t1) {
*t2.Add() = val;
}
}
}
template <typename T1,
template <typename T1,
typename T2>
static void SetToRepeatedField(const T1& t1, T2& t2)
{
static void SetToRepeatedField(const T1& t1, T2& t2)
{
t2.Clear();
for (auto& val : t1) {
*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);