??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲综合久久综合激情久久,久久电影网,国产激情久久久久影院小草http://www.shnenglu.com/jolleydtan/plan,refactor,daily-build, self-discipline,zh-cnWed, 07 May 2025 22:00:01 GMTWed, 07 May 2025 22:00:01 GMT60nginx开发第一个helloworld.http://www.shnenglu.com/jolleydtan/archive/2016/05/10/213147.htmljolleyjolleyTue, 10 May 2016 00:25:00 GMThttp://www.shnenglu.com/jolleydtan/archive/2016/05/10/213147.htmlhttp://www.shnenglu.com/jolleydtan/comments/213147.htmlhttp://www.shnenglu.com/jolleydtan/archive/2016/05/10/213147.html#Feedback2http://www.shnenglu.com/jolleydtan/comments/commentRss/213147.htmlhttp://www.shnenglu.com/jolleydtan/services/trackbacks/213147.html 

Nginx开发第三方模块实例

Ø 序言

Nginx是一个极h展性的服务?/span>,q显著体现在对第三方模块的支持,开发者能够将自己开发的模块Q按?/span>nginx既有的规则,完美地融合进http框架中,以实现开发者定制功能的作用?/span>

q篇文章主要用于l合如何开发一个简单的W三Ҏ块,目标人群为想了解nginx开发第三方模块的同学,文章内容主要包括三个部分Q如何将HTTP模块嵌入nginx和如何开发第三方模块以及一个例子?/span>

Ø 如何?/span>HTTP模块嵌入nginx

Nginx目前来说提供了二U方?/span>,config文g+configure 脚本Q手动方式,后面手动方式是更加复杂的Q且Ҏ出错Q在常规?/span>nginx开发中Q基本上都是?/span>config文g+configure脚本方式比较多。接下来分别介绍q两U方式?/span>

 

1)      Config文g+configure脚本

Config文g

q个是指提供config文gQƈ且在文g里面l出三个配置,可以达到效果。这三个配置Ҏ指:

A.      Ngx_addon_nameQ?/span>是自己要开发的q个模块名字?/span>

B.        Nginx模块名:q有点像讄环境变量啥的Q首先要知道自己开发啥模块Q?/span>nginx对应的模块有Q?/span>$HTTP_MODULES(常规?/span>http模块), $HTTP_FILTER_MODULES(HTTPqo模块)Q?/span>$HTTP_HEAD_FILTER_MODULES(HTTP 头部qo模块)Q?/span> $CORE_MODULES(nginx的核心模?/span>)Q?/span>$EVENT_MODULES(nginx的事件模?/span>){,然后在后面添加你所要添加的模块名字Q以I格隔开Q比如这ơ我们开发添加的模块:

HTTP_MODULES = “$HTTP_MODULES ngx_http_helloworld_module”

C.        NGX_ADDON_SRCSQ?/span>q个֐思义Q就是指定新d文g的\径,不过q个都是相对路径Q因为在configure的时候就指定了上层\径,比如--add-modules=PATH?/span>

比如我们q次开发要d的源文gQ?/span>

NGX_ADDON_SRCS = “$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_helloworld_module.c”

Configure脚本

q里需要用- -add-module=PATH第三方模块的\径加入,

比如configure - -add-module=~/ngx_3rd_modules/

那我们能分析下这背后做了什么呢Q我们从下面两个部分来展开说明

a)      Auto/modules

q个主要是说明将定制的第三方模块d到生成的ngx_modules.c里面?/span>

a)         指定模块下面的配|文?/span>.

b)         生成模块信息

一?/span>生成模块数组

Ҏ需要开启的模块加蝲对应的模?/span>,下面是开?/span>http模块后的所需要的模块
 

二?/span>生成ngx_modules.c文g

 

b)      Auto/make

显而易见,q个是负责~译相关的模块?/span>

1)         生成W三Ҏ?br />

2)         生成链接代码Qƈ目标文Ӟ库文仉接成二进制程?br />

2)      手动方式

分两步来做,W一Q修?/span>obj/ngx_modules.c, 在里面增加对应的W三Ҏ块,W二Q修?/span>obj/Makefile,在里面增加第三方模块的编译,q种直接修改的方法不太可取,易出错,一般都是用上面的第二种Ҏ?/span>

Ø 开发第三方模块注意事项

首先,要确定针寚w个模块进行开发,nginx的模块是有顺序性的Q比如: HTTP_MODULES = “$HTTP_MODULES ngx_http_helloworld_module”

其次Q因?/span>nginx是异步非d的,在编制代码时Q一定要注意不能dnginxq程.

Ø CZ

见附?a href="/Files/jolleydtan/test.zip">/Files/jolleydtan/test.zip

 

 参考:

深入理解nginx. 



jolley 2016-05-10 08:25 发表评论
]]>
游戏服务器框架设?/title><link>http://www.shnenglu.com/jolleydtan/archive/2016/04/16/213293.html</link><dc:creator>jolley</dc:creator><author>jolley</author><pubDate>Sat, 16 Apr 2016 09:33:00 GMT</pubDate><guid>http://www.shnenglu.com/jolleydtan/archive/2016/04/16/213293.html</guid><wfw:comment>http://www.shnenglu.com/jolleydtan/comments/213293.html</wfw:comment><comments>http://www.shnenglu.com/jolleydtan/archive/2016/04/16/213293.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/jolleydtan/comments/commentRss/213293.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/jolleydtan/services/trackbacks/213293.html</trackback:ping><description><![CDATA[<p class="MsoNormal" style="text-align: center; margin: 0cm 0cm 0pt" align="center"><span style="font-size: 14pt; font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">游戏服务器框架设?/span><span lang="EN-US" style="font-size: 14pt"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l2 level1 lfo1"><span lang="EN-US" style="font-size: 12pt; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><span style="mso-list: Ignore">Ø<span style="font: 7pt "Times New Roman"">  </span></span></span><strong style="mso-bidi-font-weight: normal"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">序言</span></strong><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></strong></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">Z在认识事物的时候,一般都是先从大致的骨架开始,然后再到具体的细节,金字塔原理中用的比较多的是自上而下的分析方法,q个Ҏ攑֜放之四v而皆准。那么回到我们游戏服务器开发上面,也是如此。那么如何设计和选择服务器架构以及有啥需要注意的呢?</span><font face="Calibri"> </font><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">q是本文章要解决的问题?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">文章主要目标人群是,Ҏ务器框架设计感兴,有从事过游戏框架设计的同学?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">文章内容Q介l五大设计原则以及给Z个示?/span><span lang="EN-US"><font face="Calibri">,</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">最后做ȝ?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l2 level1 lfo1"><span lang="EN-US" style="font-size: 12pt; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><span style="mso-list: Ignore">Ø<span style="font: 7pt "Times New Roman"">  </span></span></span><strong style="mso-bidi-font-weight: normal"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">设计原则</span></strong><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></strong></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">设计原则其实也是在设计时需要考虑的因素,q度设计是加重工作量的元Ӟ设计本质是Z解决问题而存在的Q下面列Z</span><span lang="EN-US"><font face="Calibri">5</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">大比较典型的原则?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l4 level1 lfo2; mso-para-margin-left: 2.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">1.</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">业务逻辑开?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo4; mso-para-margin-left: 4.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">a)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">比如游戏Z增加存储Q你需要考虑使用内存数据库还是弄个数据库|关服务器来处理?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo4; mso-para-margin-left: 4.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">b)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">比如游戏Z理游戏玩家账号Q以及支持对q_账号的接入,那么需要̎h务器?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo4; mso-para-margin-left: 4.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">c)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">比如游戏Z理游戏玩家订单和跟t付Ҏ况,可能需要支付服务器Q如果游戏类型是计时收费的话Q那么可能会需要计时服务器?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l4 level1 lfo2; mso-para-margin-left: 2.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">2.</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">q营l护</span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l1 level2 lfo3; mso-para-margin-left: 4.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">a)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">配置</span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">q里牉|到静态配|和动态配|的问题Q假讄在有一台网x务器和三台游戏逻辑服务器,静态配|的话,是|关服务器这边写dq接q三台服务器Q然后让|关服务器主动去q接Q动态配|的话,是让这三台服务器知道这个网x务器的地址Q然后自己在启动的时候去q接?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l1 level2 lfo3; mso-para-margin-left: 4.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">b)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">开启或者关闭顺?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">q主要是看各个服务器上面负责什么功能以及服务器上面的相兛_能,拿游戏登陆服务器Q游戏逻辑服以及数据库|关服务器这三个服务器的架构来说Q比如开启的时候,你尽可能地跟玩家登陆q接的顺序相反,</span><font face="Calibri"> </font><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">一般都是数据库|关服务器,然后才是游戏逻辑服,最后才是游戏登陆服务器Q其实就是防止玩家过早地登陆q来Q却发现数据q没有准备好?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">关闭的顺序其实就是相反的Q主要原则就是让数据可能地保存好,q且让玩家不再进来?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l1 level2 lfo3; mso-para-margin-left: 4.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">c)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">动态增删改</span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">增删改分Z部分Q?/span><span lang="EN-US"><font face="Calibri">1</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">Q增加一台服务器Q?/span><span lang="EN-US"><font face="Calibri">2</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">Q减一台服务器Q?/span><span lang="EN-US"><font face="Calibri">3</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">Q修Ҏ务器信息Q比如前面提到的静态配|,是不太方便增加服务器,要增加一台服务器Q需要更新网x务器的配|表Q然后让|关服务器重新连接到新的服务器,而动态配|的话,非常方便,让新增的服务器发起到|关服务器就好了。无需更改配置?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l1 level2 lfo3; mso-para-margin-left: 4.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">d)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">服务器管?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 63pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">服务器的理主要在服务器的在U离U状态的理Q中心服务器Q用来管理其它服务器Q必d时知道所理服务器的状态,比如|关服务器必要实时知道游戏逻辑服的状态,q样才好更新到登陆服务器上面Q更Ҏ务器状态。基本上在众多同U服务器上面基本上都会有个中心服务器?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l4 level1 lfo2; mso-para-margin-left: 2.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">3.</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">性能效率</span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">q需要权衡利弊和性能优劣Q比如在</span><span lang="EN-US"><font face="Calibri">ARPG</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">游戏逻辑服务器里面大量的消耗在</span><span lang="EN-US"><font face="Calibri">AI</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">上面Q那么就要考虑l弄个线E还是进E?/span><span lang="EN-US"><font face="Calibri">,</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">q同样适用于聊天功能,有一些聊天功能,或许可以选择使用</span><span lang="EN-US"><font face="Calibri">UDP</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">来作为网l层通讯方式。是否将功能模块设计成单独进E,q需要权衡,虽然可能在运营中会部|内|,怺之间是通过发消息的Q类g׃n内存Q但是还是会产生一些消耗的?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: 0cm; mso-char-indent-count: 0"><span lang="EN-US"><o:p><font face="Calibri"> </font></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l4 level1 lfo2; mso-para-margin-left: 2.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">4.</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">负蝲均衡</span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">q里包括两个部分Q硬件负载均衡,和Y件负载均衡。硬件负载均衡主要是指\由器。Y件负载均衡主要有几种软g</span><span lang="EN-US"><font face="Calibri">,nginx/lvs/haproxy/dns, </font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">负蝲均衡的策略,可以参?/span><span lang="EN-US"><font face="Calibri">nginx </font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">的负载均衡,主要?/span><span lang="EN-US"><font face="Calibri">round-robin, least-connected, </font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">以及</span><span lang="EN-US"><font face="Calibri">ip-hash</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">{?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">一般来_游戏中大都是二负蝲Q首先是在登陆这边负载一ơ,然后再在q入游戏逻辑服那边负载一ơ,q样够了?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l4 level1 lfo2; mso-para-margin-left: 2.0gd"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">5.</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">安全?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">q里说下|关服务器,其它地方也叫前置服务器,</span><span lang="EN-US"><font face="Calibri">front-end servers,</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">Q这个有几个好处Q?/span><span lang="EN-US"><font face="Calibri">1</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">Q隐藏游戏逻辑服的q接信息</span><span lang="EN-US"><font face="Calibri">. 2) </font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">l筹游戏逻辑服的负蝲信息?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l2 level1 lfo1"><span lang="EN-US" style="font-size: 12pt; font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><span style="mso-list: Ignore">Ø<span style="font: 7pt "Times New Roman"">  </span></span></span><strong style="mso-bidi-font-weight: normal"><span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">服务器框架示?/span></strong><strong style="mso-bidi-font-weight: normal"><span lang="EN-US" style="font-size: 12pt"><o:p></o:p></span></strong></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l3 level1 lfo5"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">1)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">无中心服务器架构<br /><img style="border-top-color: ; border-left-color: ; border-bottom-color: ; border-right-color: " border="0" alt="" src="http://www.shnenglu.com/images/cppblog_com/jolleydtan/sf1.png" width="710" longdesc="" height="189" /><br /></span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: 0cm; mso-char-indent-count: 0"><span lang="EN-US" style="mso-no-proof: yes"><v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype></span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 42pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l3 level1 lfo5"><span lang="EN-US" style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin"><span style="mso-list: Ignore"><font face="Calibri">2)</font><span style="font: 7pt "Times New Roman"">         </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">有中心服务器架构<br /><img style="border-top-color: ; border-left-color: ; border-bottom-color: ; border-right-color: " border="0" alt="" src="http://www.shnenglu.com/images/cppblog_com/jolleydtan/sf2.png" width="348" longdesc="" height="242" /><br /></span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: 0cm; mso-char-indent-count: 0"><span lang="EN-US" style="mso-no-proof: yes"></span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: -21pt; mso-char-indent-count: 0; mso-list: l2 level1 lfo1"><span lang="EN-US" style="font-family: Wingdings; mso-fareast-font-family: Wingdings; mso-bidi-font-family: Wingdings"><span style="mso-list: Ignore">Ø<span style="font: 7pt "Times New Roman"">  </span></span></span><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">l论</span><span lang="EN-US"><o:p></o:p></span></strong></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: 0cm; mso-char-indent-count: 0"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">服务器框架设计更像一门艺术,需要在解决问题的同Ӟ又需要注意^衡得失?/span><span lang="EN-US"><o:p></o:p></span></p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 21pt; text-indent: 0cm; mso-char-indent-count: 0"><span lang="EN-US"><o:p><font face="Calibri"> </font></o:p></span></p><br /><br /><br /><img src ="http://www.shnenglu.com/jolleydtan/aggbug/213293.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/jolleydtan/" target="_blank">jolley</a> 2016-04-16 17:33 <a href="http://www.shnenglu.com/jolleydtan/archive/2016/04/16/213293.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>从长度ؓN的数l里面随机取得M个数http://www.shnenglu.com/jolleydtan/archive/2016/04/02/213183.htmljolleyjolleySat, 02 Apr 2016 03:51:00 GMThttp://www.shnenglu.com/jolleydtan/archive/2016/04/02/213183.htmlhttp://www.shnenglu.com/jolleydtan/comments/213183.htmlhttp://www.shnenglu.com/jolleydtan/archive/2016/04/02/213183.html#Feedback0http://www.shnenglu.com/jolleydtan/comments/commentRss/213183.htmlhttp://www.shnenglu.com/jolleydtan/services/trackbacks/213183.html1Q随机排序,按照序先后取出M个数字?br /> IntVec shuffle(IntVec& vec)
133 {
134 int size = vec.size();
135 IntVec::iterator first = vec.begin();
136 IntVec::iterator last = vec.end();
137 for(IntVec::iterator i = first + 1; i != last; ++i)
138 {
139 std::iter_swap(i, first + rand()%((i - first)+ 1));
140 }
141 return vec;
142 }
q个呢,不会影响源数l,q个
2Q取Mơ,每次做个事情是随机Z个数Q添加到目标数组里面Q然后从源数l中删除。?font color="#000000" face="Verdana">
143
144 IntVec shuffle(IntVec& vec, int count)
145 {
146     IntVec desVec;
147     for(int i = 0; i < count;i++)
148     {
149         int random = rand()%vec.size();
150         desVec.push_back(vec[random]);
151         vec.erase(remove(vec.begin(),vec.end(),vec[random]),vec.end());
152     }  
153     return desVec;
154 }
q个呢,会媄响源数组?br />3Q取Mơ,借助一个辅助数l记录哪个数据被取过Q随机出一个数Q添加到目标数组里面Q然后将q个值添加到辅助数组里面.
 IntVec shuffle2(IntVec& vec, int count)
158 {
159     IntVec desVec;
160     IntVec flagVec;
161     for(int j = 0; j < count; j++)
162     {
163         flagVec.push_back(0);
164     }
165     for(int i = 0; i < count;i++)
166     {
167
168         int random = rand()%vec.size();
169         if (flagVec[random] == 0)
170         {
171             desVec.push_back(vec[random]);
172             flagVec[random] = 1;
173         }
174         else
175         {
176             i--;// 如果已经取过了,q次不算.
177         }
178
179     }
180     return desVec;
181 }


jolley 2016-04-02 11:51 发表评论
]]>
二分查找?/title><link>http://www.shnenglu.com/jolleydtan/archive/2016/03/23/213101.html</link><dc:creator>jolley</dc:creator><author>jolley</author><pubDate>Wed, 23 Mar 2016 14:16:00 GMT</pubDate><guid>http://www.shnenglu.com/jolleydtan/archive/2016/03/23/213101.html</guid><wfw:comment>http://www.shnenglu.com/jolleydtan/comments/213101.html</wfw:comment><comments>http://www.shnenglu.com/jolleydtan/archive/2016/03/23/213101.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/jolleydtan/comments/commentRss/213101.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/jolleydtan/services/trackbacks/213101.html</trackback:ping><description><![CDATA[<font color="#000000" face="Verdana">q个是改良版的二分查找树Q是通过阅读nebula device意外获得Q这边先C来。?br />typedef vector<int> IntVec;<br /> 16 int binarysearch(const IntVec& vec, int element)<br /> 17 {<br /> 18     int num = vec.size();<br /> 19     int begin = 0;<br /> 20     int end = num - 1;<br /> 21     int half;<br /> 22     int mid;<br /> 23     int count = 0;<br /> 24     printf("binarysearch--- vec count=%d, element=%d\n",num, element);<br /> 25     while(begin <= end)<br /> 26     {<br /> 27         count++;<br /> 28         if((half = num / 2))<br /> 29         {<br /> 30             if (element == vec[begin])<br /> 31             {<br /> 32                 printf("count=%d\n", count);<br /> 33                 return begin;<br /> 34             }<br /> 35             if (element == vec[end])<br /> 36             {<br /> 37                 printf("count=%d\n", count);<br /> 38                 return end;<br /> 39             }<br /> 40             mid = begin + ((num & 1)? half : (half - 1));<br /> 41             printf("vec[%d]=%d\n",mid, vec[mid]);<br /> 42 <br /> 43             if(element < vec[mid])<br /> 44             {<br /> 45                 end = mid - 1;<br /> 46                 num = (num & 1)? half: half - 1;<br /> 47                 printf("element < vec[mid]-- end, num\n", end, num);<br /> 48             }<br /> 49             else if (element > vec[mid])<br /> 50             {<br /> 51                 begin = mid + 1;<br /> 52                 num = half;<br /> 53                 printf("element < vec[mid]-- end, num\n",end, num);<br /> 54             }<br /> 55             else<font color="#000000" face="Verdana"><br /> 56             {<br /> 57                 printf("count=%d\n", count);<br /> 58                 return mid;<br /> 59             }<br /> 60         }<br /> 61         else if(num)<br /> 62         {<br /> 63             if (element != vec[begin])<br /> 64             {<br /> 65                 return -1;<br /> 66             }<br /> 67             else<br /> 68             {<br /> 69                 return begin;<br /> 70             }<br /> 71         }<br /> 72         else<br /> 73         {<br /> 74             break;<br /> 75         }<br /> 76     }<br /> 77     return -1;<br /> 78 }<br /></font></font><img src ="http://www.shnenglu.com/jolleydtan/aggbug/213101.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/jolleydtan/" target="_blank">jolley</a> 2016-03-23 22:16 <a href="http://www.shnenglu.com/jolleydtan/archive/2016/03/23/213101.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>nginx tcp负蝲均衡http://www.shnenglu.com/jolleydtan/archive/2016/03/11/212962.htmljolleyjolleyFri, 11 Mar 2016 00:44:00 GMThttp://www.shnenglu.com/jolleydtan/archive/2016/03/11/212962.htmlhttp://www.shnenglu.com/jolleydtan/comments/212962.htmlhttp://www.shnenglu.com/jolleydtan/archive/2016/03/11/212962.html#Feedback0http://www.shnenglu.com/jolleydtan/comments/commentRss/212962.htmlhttp://www.shnenglu.com/jolleydtan/services/trackbacks/212962.html现在nginx的版本已l到?.9.12Q不q在1.9.0的时候,开始了对TCP代理服务器的支持?br />之前也有一些早期的做法Q比如就有写了nginx_tcp_module模块?a style="text-transform: none; text-indent: 0px; letter-spacing: normal; font: 15px/24px Helvetica, 'Hiragino Sans GB', 微Y雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; white-space: normal; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" >https://github.com/yaoweibin/nginx_tcp_proxy_module,
以及nginx_stream_lua模块?br />https://github.com/openresty/stream-lua-nginx-module
本来想着用这两个的,后来发现已经有支持了Q就先来试试看看q个了?br />默认的话Qnginx是没有开启对tcp的支持的.如果要支持的话,需要用--with-streamL定?br />我这边只要需要三个IPQ一个是nginxq程所在的机器Q我q边?92.168.1.4表示Q?br />另外两台是TCP上游业务服务器,我们分别?92.168.1.5?92.168.1.21来表C,
Zq样的考虑是因为nginx充当tcp代理服务器后Q自w也会占用一个端口?br />q且从目前来_貌似一个nginxq程也就只能listen一个端口?br />我用的版本是nginx 1.9.9.
我在/usr/local/nginx/conf下面新徏了nginx_stream_tcp.conf作ؓ本次的测试?br />worker_processes auto;
  2 error_log /usr/local/nginx/logs/error.log info;
  3 events {
  4     worker_connections  1024;
  5 }
  6
  7 stream {
  8     upstream loadbalance {
  9 # Specifies a load balancing method for a server group where client-server mapping is based on the hashed key value
 10         hash $remote_addr consistent;
 11 # sets the weight of the server, by default, 1.
 12         server 192.168.1.21:8001 weight=5;
 13 # by default, the parameter is set to 10 seconds.
 14         server 192.168.1.5:9001  max_fails=3 fail_timeout=30s;
 15
 16 
 17     }
 18
 19 server {
 20 # listen 8001.
 21         listen 8001;
 22 # Defines a timeout for establishing a connection with a proxied server.
 23         proxy_connect_timeout 1s;
 24 # Sets the timeout between two successive read or write operations on client or proxied server connections
 25         proxy_timeout 3s;
 26 # Sets the address of a proxied server
 27         proxy_pass loadbalance;
 28     }
 29
 30 }
q个大部分是官网支持的,所以其实我也没有修改太多,p|了几个IP和端口?br />在编译好nginx后,可以?usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx_stream_tcp.conf
可以v来了Q可以通过netstat -tlnp查看是否hQ大致显CLQ?br />tcp        0      0 0.0.0.0:8001            0.0.0.0:*               LISTEN      7744/nginx_stream_t
当然也可以通过telnet来查看?br />接下来,写个单的csE序来验证下?

server端:
if __name__ == '__main__':
 import socket
 import commands
 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.bind(('192.168.1.21', 8001))
 sock.listen(5)
 while True:
  connection,address = sock.accept()
  print "connected by",address
  while 1:

    buf = connection.recv(1024)
    if buf != "" :
     print "connection buffer", buf
     connection.sendall(buf)
 connection.close()

client端:
if __name__ == '__main__': 
    import socket
    HOST='192.168.1.4'
    PORT=8001
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    sock.connect((HOST, PORT))
    while 1:
        cmd = raw_input("please input cmd:")
        sock.sendall(cmd)
        data = sock.recv(1024)
        print data
    sock.close()

在client?92.168.1.4发v一个TCPq接Ӟ接下?92.168.1.4会连接到192.168.1.21Q?br />
192.168.1.21的server端会昄Q?connected by ('192.168.1.4',58559)
后面的端口应该是随机的时端口?br />其实它的vC转发作用Q这个nginxq程相当于一个通用|关Q如果有两个client向nginxq程发vq接Q一旦nginx那边调度到同一个上游TCP服务器,那么只需要从NGINXq程建立一个TCPq接C游TCP服务器即可?br />
之前我自p计网关的时候,不是依赖于用LQ而是通过静态配|来建立q接的,比如上游逻辑服务器跟|关有连接,那都是在启动服务器的时候,徏立v来了?br />q样有个好处是可以省事Q不q也可以采用q种方式Q有玩家q接q某个上游TCP服务器才让网兌q个TCP服务器徏立连接,否则无需处理。因Z时候还是会有不服务器处于I闲?



jolley 2016-03-11 08:44 发表评论
]]>
整型数据跟字W串比较http://www.shnenglu.com/jolleydtan/archive/2011/06/08/148296.htmljolleyjolleyWed, 08 Jun 2011 12:30:00 GMThttp://www.shnenglu.com/jolleydtan/archive/2011/06/08/148296.htmlhttp://www.shnenglu.com/jolleydtan/comments/148296.htmlhttp://www.shnenglu.com/jolleydtan/archive/2011/06/08/148296.html#Feedback0http://www.shnenglu.com/jolleydtan/comments/commentRss/148296.htmlhttp://www.shnenglu.com/jolleydtan/services/trackbacks/148296.htmlstruct A
{
 int a;// 装备
 int b;// 角色数据
 char c;
};
void main( void )
{
 //printf("hello world!");
 char buffer[] = "This is a test of the memset function";

 A aStruct;
 // 发现数据相同?br /> memset(&aStruct,'*',sizeof(aStruct));
 printf( "Before: %s\n", buffer );
 memset( buffer, '*', 4 );
 printf( "After:  %s\n", buffer );
 if (buffer[2] == '*')
 {
  printf("hello,world\n");
 }
 // 判断q个是否要保存?br /> if (aStruct.a == 0x2a2a2a2a)
 {
  // 发送给DBSERVER.
  printf("hello char\n");
 }
 if (aStruct.c == 0x2a)
 {

 }
 getchar();



jolley 2011-06-08 20:30 发表评论
]]>
3DW记杂烩http://www.shnenglu.com/jolleydtan/archive/2009/04/10/70024.htmljolleyjolleyFri, 10 Apr 2009 08:56:00 GMThttp://www.shnenglu.com/jolleydtan/archive/2009/04/10/70024.htmlhttp://www.shnenglu.com/jolleydtan/comments/70024.htmlhttp://www.shnenglu.com/jolleydtan/archive/2009/04/10/70024.html#Feedback0http://www.shnenglu.com/jolleydtan/comments/commentRss/70024.htmlhttp://www.shnenglu.com/jolleydtan/services/trackbacks/70024.html调试d3d,控刉板中D3DDebugging打开Q进行调试,在选择调试信息输出{的时候,可以选择more来获得更加多得详l信息?br>http://nexe.gamedev.net/directKnowledge/default.asp?p=Debugging?
Direct3D9: (INFO) :MemFini!
Direct3D9: (WARN) :Memory still allocated!  Alloc count = 152
Direct3D9: (WARN) :Current Process (pid) = 00000fb8
Direct3D9: (WARN) :Memory Address: 00c95988 lAllocID=1 dwSize=000047f8, (pid=00000fb8)
q里是检出内存泄露?
一般是内存信息什么的没有releasing和deleting?
之前遇到的一个问题lock is not supported when multi-sampling is enabled是因为shader debugging打开了,之后关闭了,没有事情了?br>刚才~译hlsl的时候,发现了x3025错误Q后来的dx版本要用D3DXSHADER_ENABLE_BACKWARDS_COMPATIABLITY|D3DXSHADER_DEBUG才能~译,特别?008q的dx版本?br>
 DX默认的是D3DFILL_SOLIDQ如果出现D3DFILL_WIREFRAME的情况一定要讄回去?
CD3DArcBall:允许你将用户的输入解释ؓ旋{或者^U?我们所要做的是鼠标消息传递给q个c?q且视囄阵设为类的旋转或者^Uȝ阵就可以?
点乘: a.b = ||a|| *||b|| * cosA, 一般用来判断ؓ0,那么表明正交,>0,方向基本相同,<0,方向基本相反.使用点乘来计投?
l定两向量v,n,其分解为vq_v?分别q于和垂直于n,q且满 v = vq?v?一般成q分量vqؓv在n 上的投媄.
Vq?= n * ||Vq|| / ||n||.
cosA = ||Vq||/||V|| cosA||V|| = ||Vq||
Vq? n*n*v/( ||n||*||n||).
叉乘得到的向量垂直于原来的两个向?
a *b指向该^面的正上?垂直于a和b.
||a*b|| = ||a|| * ||b|| * sinA.
||a*b|| 也等于以a和bZ边的q四边形的面积.
如果a,bq或Q意一个ؓ0,则a*b = 0,叉乘寚w向量的解释是它^行于L其他向量,点乘的解释是和Q意其他向量垂?
L对角矩阵D,都有D转置矩阵= D,包括单位矩阵.
DirectX使用的行向量.
v = xp+yq+zr,向量vpC成p,q,r的线性变换了,向量p,q,rU做基向?q里基向量是W卡坐标系
变换物体相当于以相反的量变换描述q个物体的坐标系.
2d里面是这栯|的:
逆时针旋转经?不是必须)被认为是正方?时针方向是负方?
lx轴旋?
[ 1 0 0        
0 cosA sinA
0 -sinA cosA]
ly轴旋?
[cosA 0 -sinA
0  1 0
sinA 0 cosA]
lz轴旋?
[ cosA sinA 0
-sinA cosA 0
0 0 1]
lun旋{角度A,那么获得的矩阉|:
[nx*nx*(1-cosA)+cosA     nx*ny*(1-cosA)-nz * sinA  nx*nz*(1-cosA) + ny*sinA
nx * ny *(1-cosA) - nz *sinA ny*ny*(1-cosA)+cosA  ny*nz*(1-cosA) - nx* sinA
nx * nz *(1-cosA)+ny * sinA ny * nz *(1-cosA) + nx* sinA nz*nz*(1-cosA)+cosA]
~放:通过基向量构造矩?得到以单位向量n为羃放方?k为因子的~放矩阵:
s(n,k) = [ p]     [ 1 + (k-1)nx2  (k-1)nxny   (k-1)nxnz]
                    =
             [ q]     [ (k -1)nxny   1+(k-1)ny2   (k-1)nxnz]
             [ r]     [(k-1)nxnz  (k-1)nzny   1+(k-1)nz2]

投媄意味着降维操作,有一U投影方法是在某个方向上用零做羃攑֛?q种情况?所有点都被拉^臛_直的?2D)或^?3D),q种cd的投q做正交投?或者^行投?因ؓ从原来的点到投媄点的直线怺q.
n垂直于投qU?而不是^?3D?向垂直于n的^面投q矩阵如公?
p(N) =   [1-nx2 -nxny -nxnz]
              [-nxny 1-ny2 -nynz]
              [-nxnz -nzny 1-nz2]
镜像: 物体沿直线(2D?或^?3D?L.
P(n) = [ 1-2nx2 -2nxny -2nxnz]
          [-2nxny 1-2ny2 -2nynz]
          [-2nxnz -2nzny 1-2nz2]
Hxy的意义是x,y坐标被坐标z改变
Hxy(s,t) = [1 0 0]
                [0 1 0]
                [s  t 1 ]

Hxz(s,t) = [ 1 0 0]
                [s  1 t]
                [0 0 1]

Hyz(s,t) = [1 s t]
                [0 1 0]
                [0 0 1] 

M物体->像机 = M物体->世界M世界->像机
P->像机 = P物体 M物体->像机
UŞ变换: 如果满下式,那么映射f(a)是U性的:
f(a+b) = f(a) + f(b)
以及F(ka) = kf(a).
仿射变换: U性变换后接着q移,因此仿射变换的集合是U性变换的集.MU性变换都是仿变?但不是所有仿变换都是线性变?
如果存在一个逆变换可?撤消"原变?那么该变换是可逆的.
如果变换前后两向量夹角的大小和方向都不改?该变换是{角.只有q移,旋{和均匀~放是等角变?
{角变换会保持比例不变.
q移,旋{和镜像是仅有的正交变?长度,角度,面积,和体U都保持不变.
刚体变换只改变物体的位置和方?不包括Ş?所有长?角度,面积和体U都不变.q移和旋转是仅有的刚体变?镜像q不被认为是刚体变换.
假设矩阵M有r?c?记法Mij表示从M中除ȝi行和Wj列后剩下的矩?昄,该矩阉|r-1?c-1?矩阵MijUCؓM的余子式.


jolley 2009-04-10 16:56 发表评论
]]>
在xp上安装sqlserver2000遇到的问题,以及application verifier的相关信?/title><link>http://www.shnenglu.com/jolleydtan/archive/2009/03/30/78299.html</link><dc:creator>jolley</dc:creator><author>jolley</author><pubDate>Mon, 30 Mar 2009 00:46:00 GMT</pubDate><guid>http://www.shnenglu.com/jolleydtan/archive/2009/03/30/78299.html</guid><wfw:comment>http://www.shnenglu.com/jolleydtan/comments/78299.html</wfw:comment><comments>http://www.shnenglu.com/jolleydtan/archive/2009/03/30/78299.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/jolleydtan/comments/commentRss/78299.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/jolleydtan/services/trackbacks/78299.html</trackback:ping><description><![CDATA[q几天安装这个sql server 2000,花掉了很多时_希望以后安装的时候,量避免出现q些情况Q其它的错误情况׃说明了,现在只说明我遇到的问题的解决办法Q将原来的安装目录删除掉Q将c:\program files\Microsoft SQL Server下面?0目录l删除掉Q将注册表里面的HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server以及HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer里面的键g息删除掉。我机器上面q没有HKEY_LOCAL_USER\SOFTWARE\Microsoft\Microsoft SQL Serverq个目录的?<br>application verifier 的信息可以从q里获得:http://technet.microsoft.com/en-us/library/bb457063.aspx<br>application verifier主要用来指针引L内存错误.在程序运行期间进行跟t内存用情? <br>application verifier的log信息包括错误所在的调用堆栈,q且要注意及时地清除上次的错误记?我之前遇到的问题?我用application verifier到某个错误,而之后再用这个exedebug启动的时?报?后来在application verifier里面清除了记录才可以正常q行. <img src ="http://www.shnenglu.com/jolleydtan/aggbug/78299.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/jolleydtan/" target="_blank">jolley</a> 2009-03-30 08:46 <a href="http://www.shnenglu.com/jolleydtan/archive/2009/03/30/78299.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>3D线http://www.shnenglu.com/jolleydtan/archive/2009/02/17/74039.htmljolleyjolleyTue, 17 Feb 2009 07:49:00 GMThttp://www.shnenglu.com/jolleydtan/archive/2009/02/17/74039.htmlhttp://www.shnenglu.com/jolleydtan/comments/74039.htmlhttp://www.shnenglu.com/jolleydtan/archive/2009/02/17/74039.html#Feedback0http://www.shnenglu.com/jolleydtan/comments/commentRss/74039.htmlhttp://www.shnenglu.com/jolleydtan/services/trackbacks/74039.htmlcomputer display = a single graphics adapter + a display monitor.
graphics adapter contains the hardware needed store and display images on a monitor or other display device.
all of these adapters stored a representation of the displayed image in a bank of dual-ported memeory called a frame buffer.
the system uses one of the ports to read and write images into the frame buffer.the second port is used by the video scan out circuitry of the adapter to create a signal for the monitor.Direct3D only supports VGA compatible adapters.

Frame                               Color Lookup
Buffer                               Table


2D Pixel                           D/A
Engine                              Converter

Host CPU                        CRT Monitor

Direct3D abstractions include :device, swap chains, surfaces, and resource .

an application enumerates the devices available on each adapter, examining their capablities and supported display modes to find an acceptable device.
device is the object that expose the rendering operations of the hardware. its properties control the rendering behavior or provide information about rendering, while the device's methods are used to perform the rendering itself.

devices always contain at least one swap chain and a collection of resources used for rendering.
resources are application specific data stored in or near the device hardware for use during rendering Direct3D provides resources for scene geometry(vertices and indices) and appearance(images, textures, and volumes).

a surface is a resource containing a rectangular collection of pixel data such as color, alpha, depth/stencil or texture information.
a swap chain contains one or more back buffer surfaces where scenes are rendered and presented for display on the monitor, is a collection of back buffers.

a device's render target is the back buffer surface, with an optional depth/stencil surface, in which rendering will occur.

while all back buffers are valid render targets, not all render targets are back buffers.
it is also possible to have a texture as a render target allowing dynamic rendering effects.

to obtain a device object, Direct3D provides an object for device enumeration and creation. all other objects are created through the device. an application first obtains the runtime interface, then selects and creates a device from those available, and using the device creates the necessary resources for rendering.

most COM methods return HRESULT to indicate success or failure.
in windowed mode: the results of graphic rendering are presented for display insidei the client area of a window on the desktop.
Direct3D cooperates with GDI to make the results of rendering visible, using a ::StretchBlt operation to present a back buffer in the window's client region
in exclusive mode: Direct3D communicates directly with the display driver avoiding GDI. when an exclusive mode application is running, no other applications have access to display hardware and no GDI is visible on the screen.

HAL(hardware abstraction layer): has hardware acceleration of graphics rendering, making it fastest device type.

reference device: useful for debugging, when developing software applications that target new features not yet common in hardware, the reference device maybe your obly choice for generating an image with those Direct3D features.

the null reference device: does nothing and all rendering will result in a black screen.useful for manipulating resources on a machine that provides no hardware or software  implementation of the runtime.

the pluggable software device: RegisterSoftwareDevice method,

each resource has Type, Pool, Format, and Usage attributes, each of these attributes of a resource are specified at the time the resource is created and remain constant for the lifetime of the resource object.
type attributes describes the kind of resource and is defined by D3DRESOURCETYPE.
pool attribute of a resource describes how it is managed by the Direct3D runtime and is defined by the D3DPOOL enumeration.
resources in the default pool exist only in device memory.
resources in the managed pool exist in system memory and will be copied into the device's memory by the runtime when needed.
resource in the system memory pool exist only in system memory
resource in the scratch pool reside only in system memory and are not bound  by format constraints of the device
when a device is lost, all resources in the default pool are lost and should be released and recreated by the application when the device is regained.
Format attribute of a resource describes the layout of the resources's data in memory and is defined by the D3DFORMAT enumeration.

all resources have a format, but most of the format enumerants define the memory layout for pixel data.
D3DFMT_D24S8: D:depth buffer, S:stencil buffer.

Usage attribute describes how the application will be use the resource and is defined by a collection of flag bits. static reources are typically loaded with data once and used repeatedly without change, while dynamic resources are repeatedly modified bu the application.
a direct3D application starts by obtaining the IDirect3D9 COM interface pointer by calling Direct3DCreate9.
GetAdapterCount is to determine the number of adapters in the system. each adapter provides a number of video display modes. each display mode contains a screen dimention, refresh rate and pixel format and is described by D3DDISPLAYMODE structure.
the back buffer surface format of a device must be compatible with the display mode's format. CheckDeviceFormat method can be used to discover compatible formats.
GetAdapterModeCount: the number of display modes.
EnumAdapterModes: the display mode information.
GetAdapterDisplayMode: the display mode currently in use by the adapter.
two display modes can have the same width, height and format values but different values for the RefreshRates.
the CheckDeviceType method tells us if a particular combination of display format and back buffer format are valid for a device of a given type operating in windowed or exclusive mode.
with a valid device type, we can check the device's capabilities for rendering required by our application with GetDeviceCaps.

we can validate all the resources required by our application with the CheckDeviceFormat, checkDeviceFormat should be used to validate all the format of all resources used by the application: back buffer surfaces, depth/stencil surfaces, texture surfaces, and volume texture formats. if the application requires a depth buffer for viaiblitiy determination, it should use CheckDepthStencilMatch to find a depth buffer that can be used with its render target formats in a given display mode.
CheckDeviceMultiSampleType: check multisampling needs.
GetAdapterIdentifier: allows an application to identify a specific brand of adapter from a specific vendor.
D3DCREATE_ADAPTERGROUP_DEVICE: allows an application to drive both video outputs through a single device interface, allowing resources to be shaed for both outputs.
Direct3D uses single precision floating point computations. if an application requires higher precision from FPU.there are two choices, either the application can ensure that the FPU is in single precision mode when calling into Direct3D, or ir can request that the device preserve the application's FPU precision before Direct3D performs any floating -point operations and restore the precision before returning to the application.
D3DCREATE_SOFTWARE_VERTEXPROCESSING: select software vertex processing, which is always available from the runtime.the runtime used an efficient implementation of software vertex processing that is optimized for the CPU.
D3DCREATE_MIXED_VEVERTEXPROCESSING: select a combination of software and hardware vertex processing selected by SetSoftwareVertexProcessing mixed vertex processing is incompatible with a pure device and will fail if both are requested together.

D3DPRESENTFLAG_DEVICECLIP: restricts the results of a present operation to the client area of the device window in windowed mode.
D3DPRESENTFLAG_DISCARDDEPTHSTENCIL: instructs the runtime to discard the contents of the depth stencil surface after a call to Present, or when a new depth stencil surface is set on the device.
D3DPRESENTFLAG_LOCKABLEBACKBUFFER: requests a default swap chain with back buffer surfaces that can be directly accessed by the application.
in windowed mode: hDeviceWindow specifies the window whose client area will be used for presentation in windowed operation  if hDeviceWindow is zero, then the focus window willbe used for presentation.
in exclusive mode, hDeviceWindow specifies the top-level window used by the application

D3DPRESENT_RATE_DEFAULT: instructs the runtime to choose a suitable refresh rate in exclusive mode, and uses the current refresh rate in windowed mode.
an application may wish to create a full-screen display on a specific monitor.
GetAdapterMonitor: return an HMONITOR handle for an adapter, once you have the handle to the device 's montior, u can determine what part of the virtual desktop is covered by the monitor.

a scene is a collection of three dimensional objects that are projected onto the render target surface from the viewpoint of a syntheitic camera
each object in a scene is described by a collection of geometric primitives, such as points, lines, and triangles, with the device's action methods. 
the pipeline converts geometric descriptions into pixels on the render target surface through the process of rasterization. graphic primitives are rendered in the order in which they are described to the devices similar to the way a CPU executes binary instructions sequentially through memory.
the entire graphics pipeline is controlled through the properties of the device.
the properites are manipulated through the Get/Set methods of the device.
every device has a distinct set of capabilities. Direct3D specifies an abstract machine interface, but does not provide a software emulation for a feature not provided directly by the hardware's driver.
 a device provides specific information on its capabilities to allow an application to adapt to the capabilities of the device.
much of the behavior of the graphics pipeline is controlled by render states.
groups of device properties, including render states, can be cached and set as a group with state blocks.
the device object represents the rendering pipeline, we get images from the pipeline by supplying it with scene data and instructing it to render scenes into images.
scene data consists of geometric data defining shapes in space and data defining the appearance of the shapes.
we can break the pipeline up into large sections consisting of vertex data assembly, vertex processing, promitive assembly and rasterization, pixel processing, the frame buffer,a dn video scan out.

vertex data assembly section gathers together vertex components from a collection of data streams to assemble a compute vertex and its associated data.
vertex processing performs computations on each vertex such as the transformation and lighting of vertices.the processed vertex data is then assembled into graphic primitives and rasterized into a stream of pixels.
pixel processing performs a computations on each rasterized pixel to determine the final color of the pixel that will be written into the frame buffer.
frame buffer performs a read/modify/write operations combining processed pixels from the rasterizer with the existing pixels in the render ttarget.
video scan out reads the pixels out of the frame buffer for conversion into video signals displayed by the monitor.

scenes are rendered to the render target selected on the device. if the render target is part of a swap chain, the render target can be made viaible on the device through presentation.
the render target may not be part of a swap chain if the render target is a texture resource.
you present renderings for display through a swap chain as the last thing you do when rendering a scene.
a swap chain consists of one or more back color buffers into which images are rendered. a device is always associated with at least one swap chain and in windowed mode additional swap chains can be created to obtain multiple presentable surfaces.
the philosophy of the Direct3D object is to expose the capabilities of the hardware to the application programmer and let the application adapt to the hardware.
GetDeviceCaps: return the capabilities of an actual device, while GetDeviceCaps method on the Direct3D object returns the generic capabilities of a device.
IUnknown 
      IDirect3DVolume9
      IDirect3DResource9
           IDirect3DIndexBuffer9
           IDirect3DVertexBuffer9
           IDirect3DSurface9
           IDirect3DBaseTexture9
               IDirect3DTexture9
               IDirect3DCubeTexture9
               IDirect3DVolumeTexture9
resource objects are used as containers for the scene data rendered by the device such as primitive vertices, indices intto vertex arrays, surface textures and volumes. 
two and three dimensional textures expose their contents as collections of sutfaces and volumes, respectively. the back buffer, depth/stencil buffer and render target properties of the device are also exposed as surfaces.
volume objects do not inherit from IDirect3DResoutce9 and therefore do not participate in the resource management exposed by this interface.
managed resources are assigned an unsigned integer priority, with higher priority taking precedence so that resources with a lower priority are discarded from device memory first.
non-managed resources always return a priority of zero. within the same priority, Direct3D uses a least-recently used strategy to discard old resoucrs in preference to newly created resources.
when the application attempts to use more resources than the card can hold while rendering a scene, Direct3D switches to a most-recently used first strategy for discarding memory.
resources in D3DPOOL_DEFAULT are not managed and are never discarded from device memory by the resource manager.
if u need to allocate new resources in the default pool after managed resources have been loaded, you should evict all managed resources before allocating new resources in the default pool.
resources in pool D3DPOOL_SYSTEMMEM are never located in device memory, so that they do not participate in resource management.
GetAvailableTextureMem: obtain an estimate of the available texture memory.
the GetDevice method returns the device with which this resource is associated. resources cannot be shared across devices.
GetPrivateData/SetPrivateData: allow an application to associate its own arbitrary chunks of data with any Direct3D erouces.
each distinct item of private data is identified by a GUID. all private data associated with a resource is freed when the associated resource itself is freed.
methods and functions in Direct3D that create COM objects, such as CreateDevice, add a reference to the object for the caller before they return the interface pointer, the application must release these objects when they are no longer needed to avoid a memory leak.
Device queries allow you to obtain information from the driver layer of the device, the two main uses for driver queries are for obtaining rendering statistics and event notifications from the device.
D3DQUERYTYPE enumeration gives the possible kinds of queries: vertex cache description queries, resource manager statistics queries, vertex statistics queries, event queries, occlusion queries, timestamp queries, time queries and cache utilization queries.
a query exists in one of three state: signaled, building, or issued.
Issue: used by the application to signal a state transition on the query.
the device driver can also change the state of a query when it has returned the data requested by the query.
the query will report the results for primitives issued between the begining of the query and the end of the query.
occlusion queries return the number of pixels that passed the depth test for primitives rendered between the begin and end of the query.
the resource manager statistics query returns a D3DDEVINFO_RESOURCEMANAGER structure, which contains an array of D3DRESOURCESTATS structure, one for each resource type.
the vertex cache is a memory cache close to the GPU that avoids access to vertex memory for a small number of recently used vertices.
PIX: is a performance measurement tool for DirectX applications. the remaining query types return data for performance measurements with tools like PIX.
the device object's properties control the behavior of the rendering pipeline while its methods supply data for the pipeline to render.

state blocks are COM objects that provide a way for your application to cache a group of device properties for later use.
each state block is associated with a device, returned by the GetDevice method.once  a state block has been created, the state block can be applied to the device by calling apply on the state block, calling capture on an existing state block captures the current values of the device properties into the state block.
there are two ways to create a state block object and fill it with specific device property values.
the first way: call CreateStateBlock with D3DSTATEBLOCKTYPE value identifying the kind of state you  want recorded in the block.
the second way of obtaining a state block object is to call BeginStateBlock, set device properties and then call EndStateBlock.
when EndStateBlock is called, each device property marked for capture is recorded into the state block. if a device property is set multiple times between BeginStateBlock and EndStateBlock, only the last value set in the property is captureed into the state block.
release the state block COM object when you are finished with a state block.
a pure device has a performance advantage because the runtime and driver do not have to keep a copy of the non-queryable state for the application.
scenes contain one or more objects that are positioned relative to each other and to the virtual camera that views the scene. such objects are called "models", and contain data that define their shape and apperance. the shape of a model is described by a collection of a simple geometric shapes, called graphic primitives.
when we draw a three dimensional scene, we need to solve the problem of visibility: objects in the foreground should occlude objects in the background. Two- dimensional applications use a painter's algorithm to determine visibility. Direct3D can use depth/stencil surfaces to resolve visibility.

using either a flexible vertex format or a vertex shader declaration, Direct3D describes colors, textures corrdinates,vertex blending weights and arbitrary shader data at each vertex.the vertex data is supplied to the device through a collection of streams, each associated with a vertex buffer.
the streams can be driven through a level of indirection with an index buffer.the streams can be driven though a level of indirection with an index buffer.
the scene is described to the device one primitive at a time. each primitive  is rasterized into a collection of pixels written to the render target property of the device.
All Direct3D rendering is done within a scene. each successive frame draws the models at successive moments in time, as in cel animation used for cartoons.
frame rates of greater than 15 fps can be preceived as "real-time", the z-buffer algorithm solution to the visibility problem works at each pixels on the render target instead of on models, as models are rasterized, each pixel that is associated with z value is used to determine which pixel is cloest to the camera.the closer pixels are stored into the render target, while pixels farther away are discarded. the depth/stencil buffer holds each pixel's depth from the camera. to use the Z-buffer for resolving visibility, set RS_Z Enable to D3DZB_TRUE, RS_Z Write Enable to TRUE, and RS_Z Func to D3DCMP_LESS.

if the D3DPRASTERCAPS_ZBUFFERLESSHSR bit of D3DCAPS9:RasterCaps is set, it indicates the device has an alternative visivility algorithm for hidden surface removal that doesn't use a Z-buffer. how visibility is determined is hardware dependent and application transparent. 

all back buffers on swap chains are valid render targets, but render targets are not restricted to back buffer surfaces, when the device is created or reset, the render target is back buffer zero of the device's default swap chain. when present is called on the device, the render target  advances to the next back buffer so that after present returns, render target is back buffer zero again.

setting the render target to a surface other than a back buffer surface allows the device to render directly into an imanage surface instead of rendering into a swap chain's back buffer and using stretchrect to obtain the results of the rendering, which could stall the pipeline.

D3DPT_POINTLIST draws a collection of points,
D3DPT_LINELIST draws a squence of possibly disjoint line segments.


jolley 2009-02-17 15:49 发表评论
]]>
~程杂烩http://www.shnenglu.com/jolleydtan/archive/2009/01/31/66889.htmljolleyjolleySat, 31 Jan 2009 00:23:00 GMThttp://www.shnenglu.com/jolleydtan/archive/2009/01/31/66889.htmlhttp://www.shnenglu.com/jolleydtan/comments/66889.htmlhttp://www.shnenglu.com/jolleydtan/archive/2009/01/31/66889.html#Feedback2http://www.shnenglu.com/jolleydtan/comments/commentRss/66889.htmlhttp://www.shnenglu.com/jolleydtan/services/trackbacks/66889.html // 参数1:密聊用户?参数2:频道信息
 static bool ChangeChannelAndSetFocus(char* username,Channel channel);
q段代码看v来是没有事情?但是在接口设|上面存在不好的做法,如果是私密频道的?是有用username做私聊对象的,如果是非U聊频道的话,没有这个私聊对象了.但是如果要调用这个接口的?q得l个q样的?
比如q样的用?->ChangeChannelAndSetFocus("",public_channel),
其实如果E微改变一下接口设|的?好?
 static bool ChangeChannelAndSetFocus(Channel channelchar* username = "");
q样使用默认参数好?
之前的调用就可以q样使用?
:->ChangeChannelAndSetFocus(public_channel),看v来舒服多?哎感觉编E功底还有待加强,q么单的问题,拿出来想?q有q么多学问呢.

q几天写了一D函C?后来被一个家伙调用了,他直接在我的函数里面修改,q样造成了原来我函数里面的逻辑出现错误,现在x,如果以后是这L情况,׃能允总在我的函数里面修Ҏ的逻辑和相兌?但是要留出接口给它调?至于具体的操?要我自己允许才能d,当然我可以帮他看看原来他d的代?但是q样也就没有什么意义了.q种合作性的工作其要讲I这?不然很麻烦的.


H然惌v来要记录点什?调试引擎的时?可以采用q样的方?打开上层逻辑的工E?然后引擎相关的代码拖拽C层逻辑所在的工程里面?然后在这个代码里面可以设|相x?以前M知道怎么找上层逻辑与底层引擎的入口,最q终于知道了.呵呵.通过q样的方?可以在上层逻辑做某些操?然后兌q些逻辑相关的引擎代?

今天一直在被单态困扰着,事情是这L:大厅和战斗场景里面都有两个类似的chatroom,q且他们各自使用的协议是不一L.现在x他合qv来做成类似singleton的东? 之前遇C个问题,大厅和战斗场景不能在怺之间发送信息,后来我的处理Ҏ是将战斗场景里面d大厅里面的响应事Ӟq样的话Q在大厅里面发送私聊信息到战斗场景里面Q就可以接受CQ但是后来发现在战斗场景里面发送信息到大厅里面Q却接受不到Qƈ且这个时候,在大厅和战斗场景里面已经存在很多冗余代码了,q样的处理让我感觉很不爽Q我在想有没有其它办法,后来h了老大Q老大帮忙解释了一下,后来Q在协议处理方式上面修改了一下,才可以的。chatroom在不同的时候发送不同的协议好了,q且在接受的时候分开大厅和战斗场景处理就好了Q这栯是用了接受、和发送这两段废代码。对于singleton的了解还是不够好?nbsp;

之前遇到的问题,是聊天发送消息ƈ不立xC在本地Q而要先将信息转到服务端,服务端进行查询,如果能够扑ֈq个U聊对象Q那么就q回l信息,否则显C该用户不存在Q在战斗场景里面向大厅的某个玩家发送私聊信息以后,退出战斗场景以后,发现大厅里面q显C着在战斗场景里面发送的聊天信息。这样即使我按照常规思\L|络接受端的相关代码注释掉也不能辑ֈ消除大厅里面的聊天信息的目的Q感觉很郁闷。后来查看私聊信息方面的代码Q发现没有将信息有效地拦截,U聊信息在本C面还可以被显C,没有l过|络斚w的验证就直接发送过来了。在U聊信息斚w做一些处理ƈ且在退出战斗场景的时候做一些信息删除处理,q样可以达到目的了?
因ؓ玩家对象位置数据是从服务器那边发送过来的,玩家从服务器获得数据需要一D|?所以需要加入一个插?来将现在的位|过渡到下一个的位置.q里可以采用多种插值方?

今天写了代码L写强制动作的处理Q结果发现很多处是有问题的,其中原因是没有将原来的代码作用看仔细造成了,感到愧呢,

另外在编写交互性比较强的代码时Q一定要考虑自己的代码可能带来的影响?br>
更新某个文g比较ȝ的话,那么可以先采用原始文件删?q且重新全部更新的做法去?而不是用更新某个字段的方法去?

如果没有初始化声韌备成功的?那么应该可以弹出提示信息?q且原始声音音量设|ؓ0.

之前在修改一个bug(在h物控刉板打开以后,一直克隆object,造成了在引擎底层无法锁定vertexBuffer的问?,开始以为是内存泄露?在打开控制面板10分钟以后,游戏q然出错了,q一度想用一些辅助工h查找内存的信息是否出?后来发现在h物控刉杉K面克隆了q多的h物object,而这些object却没有及时地删除,造成占用q多的资?到最后连锁住vertex buffer也不行了.在分析这个问题上面的时?我还是一个劲地挖底层而没有考虑太多的逻辑层面的东?实在有点南辕北辙的味?值得反省.

在输入的使用上面,一般的游戏都采用directInput,即是U2,上次遇到的问题是,在一同事机器上面q行输入的时候就q入不了,但是在别人的机器上面却可以运行好好的,后来l常查访发现:1)用配|文件写入的,之后再绑定到某个特定键的快捷键都不能?因ؓq些是读入内存以?然后用add_binding来绑定到directInput讑֤上面?2) 在游戏里面用windows message的却可以正常使用.q入游戏的时?你不能输?而只能回?按tab键以?可以在登陆界面输入,如果不能按tab?则不能输?q入游戏以后却可以按不是从配|文仉面读取的信息,比如技?人物面板,仓库,以及地图{?
其中我个人徏议是,量不要用directInput.1)首先是directInput依赖于机?如果机器好的?那么没事?如果有事情的?那么也很难解?2)directInput里面采用了hook,来拦截消?q样,q不如直接用windows message来的?
http://www.gamedev.net/community/forums/topic.asp?topic_id=520366
详细的讨上面.

在调试逻辑没有发现什么错误提C的时?试着去调试引?可能问题发生得更加深,不在逻辑层面?而在引擎内部,q样p直接调试引擎?

在涉及到渲染斚w的bug,量借用d3ddebugging来辅助查?q样可以方便解决问题.

q接错误QIID_IDirectSound3DBufferQ其实加上dxguid.lib好了?br>U理d模式包括Q?br>wrap, border color, clamp,和mirror以及mirror once.
 pDrawPrimInternal->SetTexture(hTex);
之前遇到的一个问题是Q显C玩家在地图上面到地图边界了,q能重复l制地图Q给人的感觉好像是走不到边界Q走地图好像是在卯u里面一栗?br>后来才知道一般默认的U理d模式是wrap方式?br> get_device()->SetSamplerState(0,D3DSAMP_BORDERCOLOR,0x00ffffff);
 get_device()->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
 get_device()->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);

解决bug有时候不如重?br>量让策划去理逻辑Q逻辑E序员尽量将重心攑֜具体技术问题上面,不懂的地方应该主动跟{划沟通,而不是自己想?br>代码可以先模拟出来,然后再放到具体的环境里面试Q独立写个demo之后再去试Q这样往往会比较快捷和省事情?br>学会模拟机器执行代码的次序,q且提高阅读代码的问题,之前的时候,我劲去调试Q每ơ调试只Z解决一个问题,但是事实上,如果从阅M码开始的话,那么我可以省?天的旉?br>学会调节~写代码时候的心情和心态,q样有助于进行高效编E,当心情不好的时候,一定要集中全部的注意力Qƈ且将思\和流E作出图记蝲在纸上面Q这样可以强q自己全诏注?br>
今天遇到的文件打开问题是文件名路径有空格造成的,值得指出的是对于文g打开报错Q一般很难获得返回g息,但是可以通过GetLastError或者@Err,以及hr{来获得一些错误返回g息?br>
对字W串操作Q尽量要查是否有I格Q如果字W串长度前面有空格的话,那么被认ؓ所提供的字W串是空的。要避免q种情况的发生。对于字W串匚w要注意部分匹配的情况Q比?Tex", "Text",q里如果只匹配前面三个字W的话,那么两者是相等的,之前遇C个这L问题Q就是texture的信息被text信息所覆盖了,D控g找不到正的texture而不能显C出来?nbsp;

今天遇到的问题是q样的,之前遇到的状态切换问题,是与状态切换无养I而与插值有养I在切换状态以后,收到一个插g|,q样又给角色一个新的位|,l别人看的效果就是角色先落地了,之后又上升了Q像坐电梯一栗不q从q里说明了一个问?我在思考问题的时候,有欠周全的因素?br>
今天跟踪一个bug,在战斗的时候,出现卡死的情况,后来发现状态切换出C问题Q后来一直去查看战斗斚w的状态,但是q没有发C么结果,现在在想在战斗中的标志或者状态的时候应该设立一些标志集合,q样便于在某个时候检查一些状态的信息。现在很多的标志在游戏里面,局部的Q全局的,标志在角色上面的Q标志在物体上面的,q些都需要好好地理?br>
全方?多角度地思考问?而不能将思维局限在某处.学会从大局或者小处去分析问题,大处不行的话,小?相关的信息串v?所有的信息应该是个串型或者链型的.之前在处理问题的时?把思\限制在太的范围内了.以至于花了很多时间才扑ֈ问题所?

Ҏ正常情况和非正常情况来获得数据比较,以确定正的程和结构。如果遇到错误的乱|那么q看正常的数|然后Ҏq个比较来获得一些提CZ息?br>
今天犯了错误Q自己有最新版本,但是没有上传Q结果vss上面的版本把自己的最新版本给覆盖了?br>
在发送消息的时候,有时候ؓ了防止频J发送消息,要加入一个cd旉Q防止因为网l问题,服务端收到玩家连l的信息?br>
物理pȝ, v = v0 - gt. 玩家上蟩的速度表示,而在下降,则是v = gt,按照自由落体q动来进?q且速度是个向量,q样如果在X,Z轴上面有初速度的话,那么可能出现抛物线的情?





jolley 2009-01-31 08:23 发表评论
]]>
ŷþһwwwwww.| 91Ʒ91þۺ| 99þѹƷ| պƷþþþþ| ƷŮþøվ| ľþۺĻ| 97Ʒ97þþþþ| þþƷAVũ帾Ů| þþùҺ| þˬˬƬAV| ѾƷþþþþĻ| þþþרav| þþƷ޾Ʒ| þֻƷ99re66| ˾ƷۺϾþþþ| þþþþ| aaaƷþþùƬ| þŮƵ| þþƷɭ| þۺƵվ| þþƷav鶹ѿ | ޹ƷAVþۺӰԺ| ƷŮþþAV| ޹˾ƷŮ˾þþ| þþþùƷ۲ӰԺ| ޾þþþþ77777| 鶹˾þþƷ | ˾þˬ| ۺþþ| ݺɫþۺѿ| ھƷþþþþþþõӰ| þ99Ʒ鶹լլ| þþþƷ޳18վ| þþù׮| AëƬþþƷ| þþҹƷ| 69Ʒþþþ99| һɫۺþ| þþþƷþþþþ| þõӰ2021| 99þɫĻ|