简体   繁体   English

策略游戏帮助:战争迷雾

[英]strategy game help: fog of war

im trying to make a real time strategy game such as starcraft or age of empires. 我试图制作一个真正的战略游戏,如星际争霸或帝国时代。 my maps woud have to support up to about 1500 entities. 我的地图必须支持多达约1500个实体。 My problem arrises with how to implement a fog of war without lagging the game. 我的问题在于如何在不延迟游戏的情况下实施战争迷雾。 The method that i initialy tried was to simply caclulate the distance to all surrounding area of a unit everytime it moved but as i expected this lagged since many units would be constantly moving. 我最初尝试的方法是每次移动时简单地计算到一个单元的所有周围区域的距离,但正如我预期的那样,由于许多单元将不断移动,因此这种情况滞后。 If anyone knows a faster algorythim for a fog of war please help. 如果有人知道更快的algorythim战争迷雾,请帮助。 the maps would be tile based and stored in an array. 地图将基于图块并存储在数组中。

A quite basic implementation can be as follows: 一个非常基本的实现可以如下:

  • Visibility is given by a value v[i,j] for each tile (i,j) . 可见性由每个图块(i,j)的值v[i,j]给出。 Any value below a certain threshold lies within the fog. 低于某个阈值的任何值都在雾中。

  • The values are updated with regular time steps (note: for such a thing no high accuracy or high frequency is needed besides for very special cases) using the following two steps: 使用以下两个步骤,使用常规时间步骤更新这些值(注意:对于非常特殊的情况,不需要高精度或高频率):

    1. blur the current map v[i,j] 模糊当前地图v[i,j]
    2. for each unit increase the value v[unit_i, unit_j] by a constant amount. 对于每个unit将值v[unit_i, unit_j]增加一个恒定量。 You can also add a constant amount if a unit is on a square (no matter how many of them are there). 如果单位在正方形上(无论有多少单位),您也可以添加一个恒定的数量。

Another solution: binning for your entities. 另一种解决方案:为您的实体装箱。

You create a relatively spare grid, or even a quad-tree. 您可以创建相对备用的网格,甚至是四叉树。 Given coordinates (x,y) , it allows you to find in log(d) steps all entities which are in the same (or neighbouring) cells, where d is the depth of your quad-tree. 给定坐标(x,y) ,它允许您在log(d)步骤中找到位于相同(或相邻)单元格中的所有实体,其中d是四叉树的深度。

With some help of ropes (pointers from leaf nodes pointing to adjacent cells), accessing a neighbour can be done in a constant time. 在绳索的帮助下(叶子节点指向相邻小区的指针),可以在恒定时间内访问邻居。

To learn if a given map tile is visible or not, you just need a query into your quad-tree. 要了解给定的地图图块是否可见,您只需要查询四叉树。

Also, a quad-tree may be useful for other tasks unrelated to fog-of-war. 此外,四叉树可能对与战争无关的其他任务有用。 Eg you might want to find the nearest "worker" to the given coordinates (x,y) or you want to apply some area-damage to all units in a region. 例如,您可能希望找到距给定坐标(x,y)最近的“工人” (x,y)或者您想对区域中的所有单位应用一些区域损坏。

Every time a unit moves, you can probably assume that it moves to neighboring tile, can't you? 每当一个单位移动时,你可能会认为它移动到相邻的瓷砖,不是吗? In this case you can also assume that visible area of this unit also moves by one tile in the same direction, so you should have no trouble determining nor updating an area that is supposed to be visible. 在这种情况下,您还可以假设此单元的可见区域也沿同一方向移动一个图块,因此您应该可以确定或更新应该可见的区域。 Depending on sight radius of a unit, updating only values that need updating can probably save a lot of CPU power. 根据单元的视距,仅更新需要更新的值可能会节省大量CPU功率。

The problem would be area that is supposed to be blurred - there can be more units seeing the same tile but this can be solved by doing what Howard suggests. 问题是应该模糊的区域 - 可以有更多的单位看到相同的瓷砖,但这可以通过做霍华德的建议来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM