战魂小筑

讨论群:309800774 知乎关注:http://zhihu.com/people/sunicdavy 开源项目:https://github.com/davyxu

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  257 随笔 :: 0 文章 :: 506 评论 :: 0 Trackbacks

#

我们的工程使用notepad++挂载protobuf的protoc代码生成器, 每次生成后, 助手都要手动parse一次, 很麻烦. 研究了下VC助手的选项, 按下图配置即可静默刷新文件

image

posted @ 2013-11-13 10:39 战魂小筑 阅读(1649) | 评论 (1)编辑 收藏

http://www.andersriggelsen.dk/glblendfunc.php

即便是老外的教科书也是晦涩的,不如几行js来的爽快

posted @ 2013-11-12 13:58 战魂小筑 阅读(1875) | 评论 (0)编辑 收藏

我使用的是VS2010, 老版本的未测

call "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
    cd 你的工程sln目录

MSBuild “你的工程.sln” /t:Build /p:Configuration=Release /maxcpucount:4

解释: 首先调用VC上下文建立批处理, 转到你的sln目录,保证工作目录正确, /maxcpucount是并行编译, 根据你的需求配置即可

posted @ 2013-11-05 15:20 战魂小筑 阅读(2596) | 评论 (1)编辑 收藏

距离第一次使用HG已经由2,3年了。 从第一次将HG用于自己的项目, 用U盘同步代码. 到现在将HG应用于linux, 版本差异发布, 项目内部多人的分布式开发,已经感觉非常熟练。

我们的项目的客户端和服务器均由C++开发,由于HG设计的理念是1个工程对应1个库, 因此我们的客户端和服务器是分开的两个HG代码库。这种思想和SVN管理的代码有很大不同。SVN时代的游戏工程大多是这样安排目录的:

common <-客户端和服务器共享的库

client<-客户端的代码

server<-服务器的代码

通过SVN强大的权限控制给不同的前后端赋予权限,前后端程序将获得不同的目录组合。SVN下的这种工程组织方法能很好的解决单一语言跨工程的代码,协议共享问题。虽然现在各种Erlang,Java的服务器语言与as3,lua的不同客户端脚本语言混杂的时代已经无所谓这种老式设计思想。但是对于我们纯C++的手游来说,还是必须面对分布式代码管理工具下的代码跨库共享问题。

我就这个问题与多年前被我推荐过HG的朋友讨论起来,他们也存在我们这个问题,但是他们的解决方法就是每个工程一个库。然后被我问到:“同步一次代码,一次次的打开不同的库(他们客户端+服务器一共6到7个HG代码库),进行同步, 完成后, 还要反向pull,不累啊?”, 朋友回答:“习惯就好”

随后,我也翻查了git对多项目的支持。得到的答案也是跟HG一样的, 这类分布式代码管理工具本身的设计理念只有账号,而无权限, 本身就是基于开源代码精神设计的工具, 如果分了权限,岂不是违背开源精神(这是我想的微笑)。因此如果想管理多个项目代码, 要么多库,要么合库。

posted @ 2013-10-25 22:51 战魂小筑 阅读(2611) | 评论 (2)编辑 收藏

将boost更新到1.53时, 发现luabind死活编译不过, 报错如下

error: missing binary operator before token "("

根据老外的描述, boost中的BOOST_PP_ITERATION_FLAGS从1.49版本后发生了一些变化.

在git找到一个patch, 链接在此

以下简单描述

修改call_function.hpp, call_member.hpp及wrapper_base.hpp

去掉#elif BOOST_PP_ITERATION_FLAGS() == 1

更换为

#else

#if BOOST_PP_ITERATION_FLAGS() == 1

然后在源码底部加一个#endif即可

posted @ 2013-09-24 16:46 战魂小筑 阅读(2320) | 评论 (0)编辑 收藏

最近发现一个Qt写的切图软件, 导入PNG图片可以显示, 而JPEG图片无法显示. 开发机正常. Google了一下, 发现Qt通过外部插件机制支持各种扩展功能.

在启动前, 添加如下代码:

QApplication qapp(argc, argv);   

qapp.addLibraryPath(QCoreApplication::applicationDirPath()+"/plugins");

将QT开发目录下: Qt\4.8.2\plugins\拷贝到Qt的exe目录即可

posted @ 2013-08-10 09:44 战魂小筑 阅读(769) | 评论 (0)编辑 收藏

这里不能不说Google确实搜了1天都没解决问题, baidu第一个就解决了...

cygwin参考这里

http://my.oschina.net/tonywolf/blog/49214

简单的说

1.下载cygwin的网络安装包(第一次安装只能这样)

2. 选择靠前一点的网站进行下载( 下好的包可以留着, 下次安装直接从文件夹中选择就可以安装)

cygwin下使用NDK编译boost参考这里

http://blog.sina.com.cn/s/blog_a6946c8a01016aot.html

细节注意:

1. boost官网下载boost_1_53_0.tar.bz2, 解压放在android-ndk-r8e/sources下

2. 生成boost编译工具: 在boost目录下运行 ./bootstrap.sh 或者 bootstrap.bat 生成 b2

3. 修改 boost/tools/build/v2/user-config.jam 内容修改如下

import os ;
 
if [ os.name ] = CYGWIN || [ os.name ] = NT {
androidPlatform = windows ;
}
else if [ os.name ] = LINUX {
androidPlatform = linux-x86_64 ;
}
else if [ os.name ] = MACOSX {
androidPlatform = darwin-x86 ;
}
 
modules.poke : NO_BZIP2 : 1 ;
ANDROID_NDK = ../.. ;
using gcc : android4.6 : $(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ :
<archiver>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar
<ranlib>$(ANDROID_NDK)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib
<compileflags>--sysroot=$(ANDROID_NDK)/platforms/android-9/arch-arm
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/include
<compileflags>-I$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include
<compileflags>-DNDEBUG
<compileflags>-D__GLIBC__
<compileflags>-DBOOST_FILESYSTEM_VERSION=3
<compileflags>-lstdc++
<compileflags>-lgnustl_shared
<compileflags>-mthumb
<compileflags>-fno-strict-aliasing
<compileflags>-std=gnu++11
<compileflags>-O2
;
 

4. 为了安全起见, 我打了个BoostForAndriod上的补丁: 手动修改下就好了

 

diff -ruN boost_1_53_0-boot/boost/asio/detail/socket_types.hpp boost_1_53_0-patched/boost/asio/detail/socket_types.hpp
--- boost_1_53_0-boot/boost/asio/detail/socket_types.hpp     2012-01-15 14:46:25.000000000 +0100
+++ boost_1_53_0-patched/boost/asio/detail/socket_types.hpp     2012-06-27 19:19:01.279562338 +0200
@@ -123,7 +123,12 @@
typedef int socket_type;
const int invalid_socket = -1;
const int socket_error_retval = -1;
+// @Moss - Some platforms do not define it (Android)
+#if defined(INET_ADDRSTRLEN)
const int max_addr_v4_str_len = INET_ADDRSTRLEN;
+#else // defined(INET_ADDRSTRLEN)
+const int max_addr_v4_str_len = 16;
+#endif // defined(INET_ADDRSTRLEN)
#if defined(INET6_ADDRSTRLEN)
const int max_addr_v6_str_len = INET6_ADDRSTRLEN + 1 + IF_NAMESIZE;
#else // defined(INET6_ADDRSTRLEN)
diff -ruN boost_1_53_0-boot/boost/asio/ip/impl/address_v6.ipp boost_1_53_0-patched/boost/asio/ip/impl/address_v6.ipp
--- boost_1_53_0-boot/boost/asio/ip/impl/address_v6.ipp     2012-01-15 14:46:25.000000000 +0100
+++ boost_1_53_0-patched/boost/asio/ip/impl/address_v6.ipp     2012-06-27 19:19:11.029581297 +0200
@@ -11,6 +11,23 @@
#ifndef BOOST_ASIO_IP_IMPL_ADDRESS_V6_IPP
#define BOOST_ASIO_IP_IMPL_ADDRESS_V6_IPP
 
+// @Moss - Define IPv6 macros
+#if !defined(IN6_IS_ADDR_MULTICAST) 
+#define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff)
+#endif
+
+#if !defined(IN6_IS_ADDR_MC_NODELOCAL)
+#define IN6_IS_ADDR_MC_NODELOCAL(a) \
+        (IN6_IS_ADDR_MULTICAST(a) \
+         && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1))
+#endif
+
+#if !defined(IN6_IS_ADDR_MC_GLOBAL)
+#define IN6_IS_ADDR_MC_GLOBAL(a) \
+        (IN6_IS_ADDR_MULTICAST(a) \
+         && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe))
+#endif
+
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
diff -ruN boost_1_53_0-boot/boost/config/user.hpp boost_1_53_0-patched/boost/config/user.hpp
--- boost_1_53_0-boot/boost/config/user.hpp     2004-01-10 13:10:00.000000000 +0100
+++ boost_1_53_0-patched/boost/config/user.hpp     2012-06-27 19:18:46.129532736 +0200
@@ -13,6 +13,15 @@
//  configuration policy:
//
 
+// Android defines
+#define __arm__ 1
+#define _REENTRANT 1
+#define _GLIBCXX__PTHREADS 1
+// There is problem with std::atomic on android (and some other platforms).
+// See this link for more info:
+// https://code.google.com/p/android/issues/detail?id=42735#makechanges
+#define BOOST_ASIO_DISABLE_STD_ATOMIC 1
+
// define this to locate a compiler config file:
// #define BOOST_COMPILER_CONFIG <myheader>
 
diff -ruN boost_1_53_0-boot/boost/detail/endian.hpp boost_1_53_0-patched/boost/detail/endian.hpp
--- boost_1_53_0-boot/boost/detail/endian.hpp     2011-03-29 23:58:48.000000000 +0200
+++ boost_1_53_0-patched/boost/detail/endian.hpp     2012-06-27 19:18:39.359519453 +0200
@@ -31,7 +31,7 @@
// GNU libc offers the helpful header <endian.h> which defines
// __BYTE_ORDER
 
-#if defined (__GLIBC__)
+#if defined (__GLIBC__) || defined(ANDROID)
# include <endian.h>
# if (__BYTE_ORDER == __LITTLE_ENDIAN)
#  define BOOST_LITTLE_ENDIAN
diff -ruN boost_1_53_0-boot/boost/interprocess/detail/workaround.hpp boost_1_53_0-patched/boost/interprocess/detail/workaround.hpp
--- boost_1_53_0-boot/boost/interprocess/detail/workaround.hpp     2011-12-26 18:21:36.000000000 +0100
+++ boost_1_53_0-patched/boost/interprocess/detail/workaround.hpp     2012-06-27 19:18:52.909546004 +0200
@@ -54,7 +54,7 @@
    #endif
 
    //Check for XSI shared memory objects. They are available in nearly all UNIX platforms
-   #if !defined(__QNXNTO__)
+   #if !defined(__QNXNTO__) && !defined(ANDROID)
       #define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
    #endif
 
diff -ruN boost_1_53_0-boot/libs/filesystem/src/operations.cpp boost_1_53_0-patched/libs/filesystem/src/operations.cpp
--- boost_1_53_0-boot/libs/filesystem/src/operations.cpp     2012-01-28 15:40:16.000000000 +0100
+++ boost_1_53_0-patched/libs/filesystem/src/operations.cpp     2012-06-27 19:19:19.269597266 +0200
@@ -73,13 +73,15 @@
     const fs::path dot_dot_path("..");
#   include <sys/types.h>
#   include <sys/stat.h>
-#   if !defined(__APPLE__) && !defined(__OpenBSD__)
+#   if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__ANDROID__) && !defined(ANDROID)
#     include <sys/statvfs.h>
#     define BOOST_STATVFS statvfs
#     define BOOST_STATVFS_F_FRSIZE vfs.f_frsize
#   else
#     ifdef __OpenBSD__
#     include <sys/param.h>
+#     elif defined(__ANDROID__) || defined(ANDROID) // @Moss - Android messes up a bit with some headers, this one is the correct one :D
+#     include <sys/vfs.h>
#     endif
#     include <sys/mount.h>
#     define BOOST_STATVFS statfs
@@ -206,7 +208,19 @@
          || ::mkdir(to.c_str(),from_stat.st_mode)!= 0))
#   define BOOST_COPY_FILE(F,T,FailIfExistsBool)copy_file_api(F, T, FailIfExistsBool)
#   define BOOST_MOVE_FILE(OLD,NEW)(::rename(OLD, NEW)== 0)
+#if defined(__ANDROID__) || defined(ANDROID)
+    int BOOST_RESIZE_FILE(const char *path, off_t size)
+    {
+      int result = -1;
+      int fd = open(path, O_WRONLY);
+      if (fd != -1)
+        result = ftruncate(fd, size);
+      close(fd);
+      return result;
+    }
+#else
#   define BOOST_RESIZE_FILE(P,SZ)(::truncate(P, SZ)== 0)
+#endif
 
#   define BOOST_ERROR_NOT_SUPPORTED ENOSYS
#   define BOOST_ERROR_ALREADY_EXISTS EEXIST

 

5. 命令行编译:

./b2 --without-python --without-mpi --without-serialization toolset=gcc-android4.6 link=static runtime-link=static target-os=linux --stagedir=android

使用编译完成的boost库

1. 将编译boost_1_53_0\android\lib\ 下的.a库 及boost_1_53_0\boost\下的头文件拷贝出来放在工程的boost4android目录下

2. 在boost4android目录下,创建Android.mk, 内容如下

LOCAL_PATH:= $(call my-dir)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_atomic
LOCAL_SRC_FILES:= lib/libboost_atomic.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_chrono
LOCAL_SRC_FILES:= lib/libboost_chrono.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_context
LOCAL_SRC_FILES:= lib/libboost_context.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_date_time
LOCAL_SRC_FILES:= lib/libboost_date_time.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_exception
LOCAL_SRC_FILES:= lib/libboost_exception.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_filesystem
LOCAL_SRC_FILES:= lib/libboost_filesystem.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_graph
LOCAL_SRC_FILES:= lib/libboost_graph.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_iostreams
LOCAL_SRC_FILES:= lib/libboost_iostreams.a 
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_c99
LOCAL_SRC_FILES:= lib/libboost_math_c99.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_c99f
LOCAL_SRC_FILES:= lib/libboost_math_c99f.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_c99l
LOCAL_SRC_FILES:= lib/libboost_math_c99l.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_tr1
LOCAL_SRC_FILES:= lib/libboost_math_tr1.a 
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_tr1f
LOCAL_SRC_FILES:= lib/libboost_math_tr1f.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_math_tr1l
LOCAL_SRC_FILES:= lib/libboost_math_tr1l.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_program_options
LOCAL_SRC_FILES:= lib/libboost_program_options.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_random
LOCAL_SRC_FILES:= lib/libboost_random.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_regex
LOCAL_SRC_FILES:= lib/libboost_regex.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_system
LOCAL_SRC_FILES:= lib/libboost_system.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_thread
LOCAL_SRC_FILES:= lib/libboost_thread.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_timer
LOCAL_SRC_FILES:= lib/libboost_timer.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY)
 
可以根据自己的需要调整以上包含
 
3. 在应用程序的Android.mk中添加

LOCAL_WHOLE_STATIC_LIBRARIES += boost_system
LOCAL_WHOLE_STATIC_LIBRARIES += boost_filesystem
LOCAL_WHOLE_STATIC_LIBRARIES += boost_thread

用多少, 包多少

添加异常支持 LOCAL_CPPFLAGS += –fexceptions

 

添加模块引用

$(call import-module,boost4android)

posted @ 2013-07-20 16:23 战魂小筑 阅读(3519) | 评论 (2)编辑 收藏

protobuf就是为懒人而造的工具, 啥协议, 啥配置文件, 统统定义proto, 解析就ok, 非常方便

 

文本格式的解析错误不能使用捕获错误来获取, 因此,我们需要使用自定义的错误收集器进行收集, 看代码:

#include <google/protobuf/text_format.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/io/tokenizer.h>
 
class PBTextErrorCollector : public google::protobuf::io::ErrorCollector
{
public:
    PBTextErrorCollector( const std::string& FileName )
        : mFileName( FileName )
    {
 
    }
 
    virtual void AddError(int line, int column, const string& message)
    {
        CCLog("%s(%d:%d) %s ", mFileName.c_str(), line, column, message.c_str() );
    }
 
    virtual void AddWarning(int line, int column, const string& message) 
    {
        CCLog("%s(%d:%d) %s ", mFileName.c_str(), line, column, message.c_str() );
    }
 
private:
    std::string mFileName;
};
 

解析代码

google::protobuf::TextFormat::Parser P;        
    P.RecordErrorsTo( &PEC );
    P.Parse( &AIS, &AF );

 

另外: 文本格式的注释使用unix shell风格: 以#开头

下面是我的文本格式的配置文件

 

AnchorPointX: 0.5
AnchorPointY: 0

SpriteScale: 2

ComponentName: "ActorActionManager"
ComponentName: "ActorFrameEventDispatcher"
#ComponentName: "SoundFXController"
ComponentName: "RoleDeltaMoveController"
ComponentName: "RoleBehaviorDirector"

InitAction: AA_Idle

Animations 
{
  AnimationName: "mai_idle"
  AnimationInterval: 0.067
}
posted @ 2013-07-09 18:29 战魂小筑 阅读(6974) | 评论 (2)编辑 收藏

c++0x中已经添加了诸如function, bind等需要boost支持的功能, 不再需要编译复杂的boost了

在你的Android.mk文件中添加 LOCAL_CPPFLAGS += -std=gnu++0x即可

posted @ 2013-07-01 16:09 战魂小筑 阅读(2203) | 评论 (1)编辑 收藏

最近调试程序发现空指针老无法定位, 使用一个最简单的main函数做空指针检查也一样, 具体症状见图

image

pdb加载是正常的, 但是堆栈没显示如此简单的空指针访问位置. Google了以下

http://blogs.msdn.com/b/debugger/archive/2010/05/12/visual-studio-debugger-fails-to-catch-unhandled-exception-for-a-windows-form-or-wpf-application.aspx

解决方法: Debug->Exception中将所有异常勾选即可

 

不知道哪里的设置导致如此诡异的问题, 害的我重装一次..

posted @ 2013-06-27 11:05 战魂小筑 阅读(2287) | 评论 (0)编辑 收藏

仅列出标题
共26页: First 3 4 5 6 7 8 9 10 11 Last