Home >php教程 >php手册 >PHP网页游戏学习之Xnova(ogame)源码解读(十五)

PHP网页游戏学习之Xnova(ogame)源码解读(十五)

WBOY
WBOYOriginal
2016-06-06 20:20:361172browse

这篇文章主要介绍了PHP网页游戏Xnova(ogame)源码解读的舰队活动页面处理流程,需要的朋友可以参考下

十八、舰队活动(FlyingFleetHandler.php)

在前文中我们曾经初步研究过舰队活动的源码,提到过舰队活动的触发。现在我进一步分析Xnova中舰队活动,这些在本质上是由玩家触发的,并不是由定时器在进行定时计算。舰队活动的触发是在common.php中进行的,所以入口就在这文件中,代码如下:

//检查是否有到达目的地的舰队 $_fleets = doquery("SELECT * FROM {{table}} WHERE 'fleet_start_time'

大家看到了,前面这段代码其实写的不好,因为这里每次都会被调用,效率太低了。因此我们在这里可以进行优化,使每次循环只需要一个舰队的ID传递给函数即可;相应的函数也要做修改,有兴趣的自己修改下。

接下来看看函数FlyingFleetHandler(),这是集中调用舰队活动的函数。

//锁表,防止出现数据不同步等问题 doquery("LOCK TABLE {{table}}lunas WRITE, {{table}}rw WRITE, {{table}}errors WRITE, {{table}}messages WRITE, {{table}}fleets WRITE, {{table}}planets WRITE, {{table}}galaxy WRITE ,{{table}}users WRITE", ""); //这里一大段就是取得舰队数组,参数完全可以使用舰队ID,优化之 $QryFleet = "SELECT * FROM {{table}} "; $QryFleet .= "WHERE ("; $QryFleet .= "( "; $QryFleet .= "`fleet_start_galaxy` = ". $planet['galaxy'] ." AND "; $QryFleet .= "`fleet_start_system` = ". $planet['system'] ." AND "; $QryFleet .= "`fleet_start_planet` = ". $planet['planet'] ." AND "; $QryFleet .= "`fleet_start_type` = ". $planet['planet_type'] ." "; $QryFleet .= ") OR ( "; $QryFleet .= "`fleet_end_galaxy` = ". $planet['galaxy'] ." AND "; $QryFleet .= "`fleet_end_system` = ". $planet['system'] ." AND "; $QryFleet .= "`fleet_end_planet` = ". $planet['planet'] ." ) AND "; $QryFleet .= "`fleet_end_type`= ". $planet['planet_type'] ." ) AND "; $QryFleet .= "( `fleet_start_time`

上面的函数结构清晰,代码明了,注释也讲的很清楚了。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn