dpgjci27392 2011-01-11 05:09
浏览 79

我正在制作一个带有地图的PHP游戏,我有一些问题

Well im Making a PHP webgame with a map where players can walk on. but im very about overall performance of the game. it is a bit like this:

  1. The page to start saving resources i made a main page with an iframe to the map code and with a chat below like this:

(start page) (iframe with the map.php code) (include chat.php) (end page)

so with this i dont have to reload all the page and the chat stands still while we walk on the map.

  1. the map code: in the beginning it was very slow and buggy but i managed it to run very simple, like this: the maps are divided by areas, and each row stores a single tile of a 9x9 map. so my db looks like this:

id-map(this defines the area)-pos(this defines the position of the tile)-tile(img of the tile)-block(if tile is walkable or not)

so when i call to create map i ask to select all rows of map X, then the script create a table of 9 rows by 9 collumns and set the background of each cell with the specific tile image.

while that is script executes it also asks for the DB for any other players and objects in the map in the same way but showing them as img inside the cell, not as background.

to save calls for the db, i had the idea of: in each loop of the map creation it create a hidden input which name is the actual map position and value is the img so it stores in the browser and it is resent every time we walk so it calls for the map once we enter it.

for walking i made a big form and the arrows for walking being buttons, every time we walk the page sends a POST and depending for which direction play has walked, it updates the DB and generate the map again.

well thats it. im already using GZip compression. So my questions are:

1- Will the server overload if there is like 50 players walking at same time? 2- there is any tips, improvements or optimizations i should do to this map script? may a way to save DB calls and make it less overloading?

(i dont want to use ajax)

  • 写回答

1条回答 默认 最新

  • dongmaoluan5719 2011-05-12 20:03
    关注

    Yes, your server will overload. Plus the lag will make the game un-bearable.

    Use Ajax.

    Send action commands to the server/DB. "MOVE|PLAYER 1|3|3"

    Then have your client recieve update commands from the DB. "ATTACK|PLAYER 1|PLAYER2|DAMAGE=30"

    Only update what you have to update, do NOT refresh the entire map.

    You still have lag, but you will be able to handle more players gracefully.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法