2012-02-29 10:38:00 aigao1992 阅读数 0
  • 从这里开始虚幻4-Editor介绍 v4.18

    本课程系列取名英译系列,是录制人员参考国外英文原版经典教程,结合中国人的习惯录制而成。希望能够给大家以帮助。从这里开始虚幻4系列教程,是Unreal的官方发布的入门教学,非常经典,是学习Unreal的佳入口。

    2398 人正在学习 去看看 杨石兴

 

背景

Unreal中使用了一套非常Amazing的网络同步机制,

虽然由于种种原因,实际项目中把Atlas,同步等都弃之不用,完全自行处理网络模块,

但就其机制上,还是非常值得玩味的~

通过UDN,及BeyondUnreal上的Wiki资料,可以对此有一些初步的了解~

(PS:

想做些翻译,及Sample,但苦于时间实在不够,先在此挖个坑,日后来填~~

--Zephyroal

概要

In Unreal Engine games replication is the concept of passing data between the server and clients in network games. Closely related is simulation, which is the concept of "guessing" server behavior on network clients using only the information already available to the client.

Despite consisting of a relatively small set of rules, applying replication concepts usually scares programmers new to UnrealScript and makes even UnrealScript veterans scratch their head once in a while。。。

     在Unreal引擎中,replication 是一个用于在服务器与客户端同步数据的一个重要概念,

现在还没有很好的翻译,这里先姑且称之为“副本”,当然此副本非彼游戏副本也,

      在UE的Dev代码库中,我们也可以看到很多simulation修饰符的函数,它们的作用既是为此而生,

简而言之,replication 的作用便是写一份代码,自动地分离,同时维护服务器计算、客户端交互。

      当然,初入USript,这些突如其来的概念也许会让你抓耳饶腮,但是,who cares?!Just do it!

 

Basics

 

Replication concepts

 

Replication examples

函数

Network modifiers

These modifiers affect function replication in Unreal Engine 3. Earlier engine generations use the replication block to define these.

Client3
Specifies that this function should be replicated to the client owning the actor if it is called on the server. This modifier automatically makes the function simulated as well.
DemoRecording3-x1
Specifies that this function should be replicated to the demorecording driver. It will only be executed during demo playback. This modifier automatically makes the function simulated as well, which makes sense since demo playback essentially is a client environment.
Reliable3
Replicated functions will be replicated reliably when marked with this modifier.
Server3
Specifies that this function should be replicated to the server if it was called on a replicated actor that is owned by the local client.
Unreliable3
Replicated functions will be replicated unreliably when marked with this modifier, i.e. they may be dropped due to packet loss or bandwidth saturation.

相关Topic

《Everything you ever wanted to know about replication (but were afraid to ask)》

Replication is a mighty beast lurking inside the Unreal Engine that even seasoned UnrealScript programmers treat with a lot of respect. With this article I'll try to explain how replication works and hopefully get rid of some myths and misunderstandings on that topic.

I'm not that good at writing tutorials, so feedback on the discussion page is very welcome. —Wormbo

Contents

[hide]

 

 Things to keep in mind while reading

We're on the Unreal Wiki, a site full of tutorials and reference documentation. I won't go into detail for every feature, because you can find that elsewhere. You really should have gathered some experience with the language itself and know how to use it properly before you take on scary features like replication. If you still have a question, try looking it up on the wiki first. If you can't find an answer, you can of course still ask on this article's discussion page. For more complex questions you might want to post on a forum instead, though.

One fact people probably don't expect is that the demo recording feature of the UT series of games is internally handled much like a network game. When you record a demo you are something similar to a listen server and when you play back a demo you are a client. Even if you write an offline-only mod, as soon as you want to support demo recording, you will have to deal with replication. The difference between demos and network play is that when recording a demo, the "server" doesn't expect the client to respond (network traffic is just dumped to a file) and that the "client" in demo playback will discard any data that is supposed to be sent to the server.

Another interesting case is UTV. A UTV server basically is a proxy server that looks like a special client on the game server, but acts as a server to its own clients. A UTV server's clients are spectators that can interact with each other via chat, but except for the primary client their data stays on the UTV proxy and doesn't reach the game server. Additionally the UTV proxy intentionally delays the game server's data so UTV clients cannot be used by the players to cheat in some way.

 

Background - What you start with on the client side

I won't explain how you should set up a server and connect to it with a game client, that part is covered in great detail elsewhere. This section is about what you start with after the game loaded a map on the client.

To make it short: You start with most of what the mapper added to his level. Particularly all non-actor objects (sounds, textures, meshes) used in the map will be loaded. Some of the actors the mapper placed will be missing, though. To be precise, the engine deletes all actors that have neither bStatic nor bNoDelete set to True. Level geometry, most lights, movers, navigation points, keypoints, emitters, decorations and many other actors aren't affected by this. However, all Pawns (especially placed monsters, vehicles and turrets), Projectiles, in UE1/2 also Pickups, and triggers will be gone. All of the remaining actors will have their Role and RemoteRole values exchanged, except for ClientMovers and similar actors marked as bClientAuthoritative. Quite a lot of the static and non-deletable actors end up with Role set to ROLE_None here, but that doesn't mean they don't exist on the client. It only means they won't receive any property updates through replication.

See What happens at map startup for what else happens before replication kicks in.

 

Replication basis - Actor replication

F6 network stats.

So, how does the client get to know about them? They do show up when you play the game, right? The basic concept responsible here is actor replication. For each relevant actor, the engine creates an "actor channel" between the server and the target client. The number of active channels can be viewed via the stat net command, which is usually bound to the F6 key. Note that the number of channels listed there is the total number of channels. Most of these are actor channels, but the engine also has other channel types, e.g. for voice chat.

There are actually two flavors of actor replication, one for static and non-deletable actors (those that aren't deleted at map load on the client) and one for any other actors that were either deleted at map load or spawned on the server at runtime. As mentioned above, static or non-deletable actors already exist in the client world, so their flavor of actor replication just establishes a channel between the corresponding server and client instances. It should be mentioned that static actors can only be subject to replication if they were already marked as bAlwaysRelevant before map load.

The other version is for actors that are neither bStatic nor bNoDelete (let's call them "runtime actors" because they can be spawned and destroyed at runtime) and requires a bit more work, as the target actor does not exist on the client. The server basically tells the client to spawn an actor of the required type and it also tells where to spawn it. By spawning the actor on the client, all its properties start at the class default values. See What happens when an Actor is spawned for details on how actors are initialized. The most important part here is that the actor gets its Role and RemoteRole values exchanged before any UnrealScript code is executed.

In case this isn't immediately obvious: Runtime actors placed by the mapper are deleted at map load and then possibly spawned again through actor replication. When they are replicated, all their properties are reset to class default values. Some of the change done by the mapper might later be reconstructed through other means, but for now they are gone.

 

 Network relevance - Which actors are replicated

Most of what this article explained was from the network client's point of view. Let's switch to the server side for a while to discuss a very important thing, network bandwidth. Bandwidth is usually the most-restricted parameter in a network. Data is sent sequentially, so apart from the time it takes for data to travel anyway, some of the data needs to wait while other data is transmitted. This further increases response times ("ping"), which is undesirable in most games. Games can't reduce the actual travel time of the data, that's a fixed property of the underlying network architecture. They can, however, attempt to reduce the data's waiting time by reducing the overall amount of data to transmit. The Unreal Engine employs several tricks to reduce the overall amount of data, but the best way always is to not send any data at all.

To figure out which actors need to be replicated to a client at all, the engine performs several checks to see if the actor is relevant to the client. These checks can be summed up in the following rules that will be tested roughly in the given order:

  1. If the actor is bAlwaysRelevant, it is relevant to the client.
  2. If the client or its view target owns the actor, it is relevant.
  3. If the client is a UTV see-all spectator, the actor is relevant.
  4. If the client can hear the actor's ambient sound, it is relevant.
  5. If the actor is based on (or attached to the bone of) another actor, it is relevant to the client if the other actor is.
  6. If the actor is bHidden or bOnlyOwnerSee and neither blocks other actors nor has an ambient sound, it is not relevant to the client.
  7. If the actor is in a zone with distance fog and is further away from the client's view location than the distance fog end, it is not relevant to the client.
  8. If there is BSP geometry between the client's view location and the actor's center (!), the actor is not relevant.
  9. The server may decide to check if the actor is behind some terrain and/or beyond its CullDistance if it needs to save bandwidth, which may result in the actor being not relevant to the client.
  10. The actor is relevant to the client.

Note that, while they usually prevent an actor from being rendered, anti portals do not affect network relevance, probably because testing every actor against every single AntiPortalActor for every client may be far too expensive.

Once an actor became relevant, it will continue to be considered relevant until the above rules fail for more than a few seconds. The duration is configured via RelevantTimeout=... under [IpDrv.TcpNetDrv] in the server's main configuration file for UE1/2 or the Engine.ini in UE3. The default value is 5 seconds and provides a good balance between getting rid of non-relevant actors and not having to restart replication too often for actors that often switch between being relevant and being not.

If a previously net-relevant actor is really no longer relevant, its channel to the client is closed and the actor is destroyed on the client. (See What happens when an Actor is destroyed for details.) If the actor becomes relevant again later, it will be spawned again as a completely new actor. If an actor is destroyed on the server, its channel is closed as well, causing the corresponding actor instances on all clients to be destroyed.

There are also two other ways to close an actor channel, which don't destroy the client instance. When that happens, the client takes over "simulation" of the actor behavior without any further help from the server. One way is the property bNetTemporary, which closes the actor channel immediately after the initial set of properties has been replicated (see below). This mode is used for most projectiles that don't change their movement after spawning, except for a potential influence of gravity. Projectiles that allow interaction other than the usual explode/bounce-on-impact logic usually don't use bNetTemporary. This includes projectiles that can be blown up (e.g. shock projectile, Redeemer or AVRiL rocket), that track down a target (e.g. seeking rockets or spider mines) or that simply stick to a target (e.g. bio goo or sticky grenades). bNetTemporary also has the advantage that the server doesn't need to remember which variable values it replicated to clients, but more on that later.

The other way is the bTearOff property, which also closes the actor channel, but it also swaps the Role and RemoteRole properties of the actor again so the client side instance becomes an "authoritative" instance. Unlike bNetTemporary, which can only be set in the defaultproperties, bTearOff is set on the server at runtime to "tear off" replication to all clients at the same time. On the clients the actor was relevant to, the event TornOff() is called for the actor. Once an actor is "torn off", it will no longer be replicated to new clients it might become relevant to.

 

 Variable replication - Updating properties on the client

Alright, now that you know how actors are brought to existence on clients, it's time to think about how to get modifications across the network. Remember, when a replicated actor is spawned on a client, it starts with its class defaults and the only information from the server is the actor's location and potentially its rotation, if it matters. Any other properties are sent separately through what is called variable replication.

Replicated properties are always replicated from the server to all or a specific subset of the clients, but of course only to clients to which a channel for the actor exists. In Unreal Engine 1 there was also the possibility to replicate variables from the client owning the actor to the server, but that feature has been dropped in favor of sending the values via replicated function calls. (We'll see about that one later.) One left-over of that two-way replication is that almost all variable replication conditions in stock code contain the term Role == ROLE_Authority.

 

 Replication conditions

Wait, what's a "replication condition"? Well, as mentioned before, variable replication can be restricted to a specific subset of the relevant clients. The subset is selected via a bool-type expression known as the replication condition. Replication conditions are specified in a special area of the source code, the replication block. Each class may only contain one replication block. Inside there may be one or more replication conditions, each applying to one or more variables or functions. Only one condition may be specified for a variable or function and you are not allowed to specify replication conditions for members inherited from a parent class.

A typical replication block in UE2 might look as follows:


{
    (bNetOwner)
    ThisVarOnlyConcernsTheOwner
 
    (bNetInitial)
    ThisVarIsOnlyReplicatedOnce
}

In UE3 it would be similar, except that the "reliable" or "unreliable" keyword is missing. That keyword doesn't have any effect on variable replication, it only exists because it affects the way function calls are replicated, but we'll get into that later.

Technically the boolean expression between the parentheses after the "if" is standard UnrealScript code, so you could call functions there if you want. In practice, however, nobody will do that because the time and frequency at which replication conditions are evaluated is unpredictable. Also, this is deep inside network code and should be as quick as possible. Because of that, some classes have their replication conditions implemented in native code, which is specified in the class declaration via the NativeReplication modifier. These classes still have a replication block so you can figure out when exactly the various properties are replicated. Also, NativeReplication only applies to variable replication, not to replicated function calls.

So, what kind of conditions can you use? Here are a few properties you may find useful:

bNetInitial
True only for the initial bunch of variables replicated in addition to the information for spawning the actor on the client.
bNetDirty2,3
True whenever variables changed on the actor. To be honest I'm not entirely sure why this exists as variables always only get replicated if they changed from what the server thinks the client's value is.
bNetOwner
True only if the actor is owned by the client.
bDemoRecording
True if replicating to the demo recording driver instead of a "real" network connection.
bClientDemoRecording
True if the demo is being recorded on a network client, false if recording offline or on a server or not recording a demo at all.
bRepClientDemo
True on the server if the actor is owned by a client that currently records a demo.
Level.ReplicationViewer2
The PlayerController of the client currently replicating to.
Level.ReplicationViewTarget2
The ReplicationViewer's current view target.
WorldInfo.ReplicationViewers3
A dynamic array with information about the PlayerController(s) on the target client, their view target, view location and view direction. It's an array because UE3 allows more than one player on a client if splitscreen mode is enabled.
Role
This actor's local network role. You only need to check it when replicating variables in UE1 or when replicating function calls in UE1/2.

If you look around in the replication blocks of stock classes, you may find other variables being used. For example an actor's Mesh is only replicated if the DrawType is DT_Mesh.

 

 What is replicated and when?

So, when exactly does variable replication happen? The short answer is "between world updates, if anything changed". But the server doesn't really check all actors after each tick. Each actor class has a NetUpdateFrequency, which tells how often per second the actor should be checked for changed replicated variables. The first check is of course done right when the actor becomes relevant to the client and bNetTemporary actors won't get any further updates after that. For all other relevant actors, the engine repeats checks for changed variables about every 1.0/NetUpdateFrequency. Usually there's only limited bandwidth available, so the engine needs to prioritize the various actors. This is done via the NetPriority property. The higher an actor's priority is, the more likely it will be updated. However, lower priority actors won't "starve", because the longer an actor has to wait for its update check, the more likely it will be updated during the next round of checks.

In Unreal Engine 1 you can't control at which time an update check for replicated variables happens. In Unreal Engine 2 you can force (well, at least strongly suggest) updates earlier by setting the NetUpdateTime to a value in the past, e.g. Level.TimeSeconds - 1. Unreal Engine 3 provides the property bForceNetUpdate, which can be set to True for an immediate update.

The server keeps track of what each client knows about the actors replicated to it and their replicated variable values. The initial assumption about what the client knows is built based on the serverside class defaults, which includes localized and configurable values read from the localization/config files. In other words, config/globalconfig properties might not initially get replicated because the server thinks the client already knows about them. It is really recommended you use separate properties for replicating configurable values. Similarly if you edit class defaults at runtime and then spawn a new replicated actor, the server will not know you have changed the defaults and just assume the client knows about it.

Every time a variable is send to the client, the server will remember its value for that client. This may use a good amount of memory, but it helps the server save bandwidth by not having to replicate the same value again. Consider the following scenario: The server replicated a certain value to the client, then the variable is modified on the server multiple times, eventually ending up the same as it was when the server replicated it. None of the changes were replicated yet because they happened too quickly, but the server marked the actor as having changed properties. Now it's time again to check for properties to replicate. The server will look up what values it sent to the client last time and finds that the replicated property hasn't actually changed. To save bandwidth, the server won't send the property value again, because the client already knows about it.

 

 Value compression

As mentioned in the section about relevance, the engine has a few tricks to reduce the amount of data it needs to send. One of these tricks is that it compresses certain value types for transfer and uncompressing them. This compression is not lossless, but actually changes the value that arrives at the client. This doesn't apply to basic types, but only to certain structs:

Vector
The components are rounded to the nearest integer and send as integer data. This way small vectors only require several bits up to a few bytes, while the original three uncompressed float values would have required 12 bytes. If you need more than integer precision, you should multiply the vector by a scalar value before assigning it to the replicated variable.
Rotator
Only bits 9 to 16 of the components are transfered, which corresponds to the operation C & 0xff00. That way the required data amount is reduced from 12 to about 3 bytes. (It seems zero components even only take up a single bit, reducing the minimum size to 3 bits for the zero rotator.) The compression restricts replicated rotator values to rotations and makes them useless for rotation rates. To replicate a rotation rate, you could copy the rotator components to the components of a vector variable. Note that you shouldn't use typecasting to vector because that results in a unit vectors, which not only discards the Roll component entirely, but also is heavily affected by vector compression.
Quat
Values are assumed to be unit quaternions, allowing the engine to drop the W component from replication entirely and calculating it from X, Y and Z on the client. As a result Quat values require only 12 instead of 16 bytes.
CompressedPosition2
The struct consists of vectors for location and velocity and a rotator for rotation. The vectors are replicated as usual, but because this struct is used to pack a player position, the Roll component of the rotation is not replicated at all, while the Pitch and Yaw components receive the usual compression to byte size.
Plane
Components are rounded to signed integers in the range [-32768,32767]. That corresponds to a data size reduction of 50%.

 

 Detecting replicated values on the client

Most of the time you just let values replicate so they are available on the client. Sometimes, however, you will want to react to certain property changes immediately. Depending on the engine generation you have different options to react to replicated variables changing.

In Unreal Engine 1 you're entirely on your own as there is no notification. You will have to keep a backup copy of the variable you are monitoring and frequently check the backup against the original, e.g. in Tick() or a Timer().

Unreal Engine 2 at least tells you that it received replicated variables, but it doesn't tell you which variables were replicated. You need to set bNetNotify to True on the client to receive a PostNetReceive() call when a new bunch of replicated variable values arrived. It should be mentioned that if you only want to get a notification for a single, infrequent event, you can toggle the value of bClientTrigger. This will call the ClientTrigger() event as soon as the changed value arrives on the client.

Finally in Unreal Engine 3 you don't have to figure out which variable was changed, because the engine tells you. To get replication notifications, simply declare the corresponding variable with the modifier RepNotify and the engine will call the ReplicatedEvent() function with the variable's name as the parameter whenever a value for that variable is received.

Note that variables are not always replicated immediately when they are changed. Usually the engine makes sure there are at least 1/NetUpdateFrequency seconds between variable updates for a single actor. Also, actors with a higher NetPriority are usually preferred when there's not enough space to replicate changed properties in all relevant actors. Actors with a lower priority may have to wait longer for their variables to replicate.

To get instant replication at the expense of the ability to pick more than one target client, you can use replicated function calls instead.

 

 Restrictions

Not all types can be replicated, others may only replicate properly under certain conditions. For example dynamic arrays cannot be replicated at all. Any variable's value must at least fit into a single network packet to be replicated, but if multiple values from the same actor are small enough to fit into the same packet, then they will be transferred together, saving some overhead.

Strings and structs can only be replicated as a whole, while the elements of a static array are treated as separate variables for replication. That means, a static array with hundreds of relatively small elements may replicate just fine, while a long string or a very complex struct may fail. Note that static arrays in structs are subject to the "structs are replicated as a unit" rule, while dynamic arrays in a struct will be excluded from the struct replication data.

Actor or object references are another thing where you need to pay attention. Actor references can only be replicated if the referenced actor is either bStatic or bNoDelete or is currently relevant to the target client. Non-actor object references, such as classes, sounds, textures or meshes, will only reach the client if the object wasn't created at runtime. Non-Actor objects (not a reference, but the object itself) are generally not replicated, so you always need an actor if you want to establish a "connection" between the server and a client.

It might be obvious from the article already, but just in case: There is no way to achieve direct replication between clients. Clients can only communicate with the server.

 

 Function call replication - Sending messages between server and client

The word "messages" should be understood in a much wider range than just text messages. UnrealScript functions can have up to 16 parameters and each parameter can have one of many built-in and custom types. Replicated function calls can use almost the entire range of feature you can imagine. For parameters the same restrictions apply as for variable replication, with two additions: The entire function call with all parameter values must fit into a single network packet, and only the first element of a static array parameter is replicated, the others are set to their corresponding null value. If you hit the upper data size limit, you may have to find a way to break down the data into separate calls. If you need to replicate a static array, wrap it into a struct. This also makes passing it around in other cases much easier because structs can be copied as a whole, while static arrays cannot.

Ok, that said, let's look at how to replicate a function call. This differs between UE1/2 and UE3. In engine generations 1 and 2 you use the replication block to specify when to replicate the function call to the remote end. Usually you will include Role == ROLE_Authority for functions you want to send from the server to the client and Role != ROLE_Authority for functions the client should send to the server other terms are extremely rare in the replication condition. Keep one thing in mind: Function replication always implies bNetOwner, i.e. function call are only replicated if the executing actor is owned by a client, and the call will only be replicated to/from that owning client.

Unreal Engine 3 no longer uses the replication block to specify replicated function conditions. Instead it provides function modifiers to specify the replication direction. The modifier server means if the function is called on the client owning the actor, the call should be replicated to the server, while the modifier client means the server should replicate the function call to the client owning the actor. Because it makes sense, the client modifier also implies the modifier simulated to ensure the function can definitely be executed on the client when it arrives. Another modifier is demorecording, which means the function should be replicated to the demo recording driver.

 

 Calling replicated functions

If a replicated function is called and its replication condition is met, the call and all parameter values passed to it will be sent to the remote side immediately. If the condition isn't met, the function will be called locally instead. That means, if the executing actor does not have any Owner or the owner does not belong to any clients, the function call is evaluated as if the function isn't defined to be replicated. For functions replicated from a client to the server this usually means the function call is ignored because it lacks the simulated keyword. Calls from the server that stay on the server don't have such a "failsafe switch" and will cause the function to be executed there.

Note that while replicated functions are allowed to have a return type, the actual return value will be that type's null value if the function is replicated successfully. The code will not wait for the function to be executed and return a value, that's just not feasible for a game engine. If you want a replicated function to send by a value, you need to do that via a parameter of another replicated function that is sent in the other direction. Similarly if a replicated function has out parameters, their value will not change if the function is replicated. On the remote side, any out parameters or return values will be discarded when the function has finished.

Note that the parameters of replicated functions are subject to the same variable compression strategies as mentioned in the section about variable replication. Additionally, any parameter that is a null value is omitted from the replication data to save bandwidth. This goes only for entire parameter values, not for individual members of a struct used as a parameter type.

 

 Reliability

Function call replication can be either "reliable" or "unreliable", which is specified by the keywords of the same name either in the replication condition in UE1/2 or as optional function modifier in UE3. If a function is marked as "reliable", the engine makes sure it is processed in the correct order in relation to other reliable network events, especially other reliable function calls. But also opening and closing an actor channel is a reliable event. In other words, provided they are called after the actor channel is opened by the server, reliably replicated function calls are guaranteed to be processed on the client while the actor exists and they are guaranteed top be processed in the same order as they were called on the server.

Why is the order important? I'll spare you the gory details, but we need to get a bit more technical to answer that. The Unreal Engine uses UDP to transmit its data. This protocol does not actually create a connection, but just sends packets to the target address. It doesn't even guarantee that the packets arrive, let alone that they arrive in the same order they were sent. Due to the way the internet works, different packets might takes different routes and overtake each other. They may get dropped somewhere or even get duplicated.

Sounds like a nightmare, but the lack of checks also has a big advantage. The TCP protocol would implement guaranteed order and data integrity, but all of its checks cause a lot of overhead and slow down transfers. That might not be a problem for file transfers (HTTP, FTP and the various mail protocols are built on TCP), but for a game where low response times are crucial, this would be a catastrophe. Thus the engine swallows the bitter pill and performs its own checks for dropped, duplicated and out-of-order packets. These checks are only performed for important things like opening/closing actor channel or reliable replicated function calls. Note that even reliable function calls might get lost when there's packet loss, but the calls that do arrive are guaranteed to be executed in the correct order.

Unreliable function calls on the other hand might not even get send if the connection is saturated. If they are sent, they are more likely to get lost, they could be duplicated or be called out of the correct order. If the ordering gets really bad, they may even arrive after their channel is already closed or before it was opened on the client, in which case they are dropped. In stock code, unreliable functions are used for things like replicating sounds, less important visual effects and (this may be surprising) player input. If one player input packet is lost, this usually isn't a great problem as the server extrapolates movement and the client has some freedom in correcting the server's extrapolation errors. Losing a jump or fire event may be a bit annoying, but the sheer amount of input packets causes unreliable replication to provide a huge advantage compared to reliable replication, including better response times. Duplicated and out-of-order packets are caught by a timestamp value in the function call, which allows the server to discard any obsolete updates.

So when deciding whether to make a function reliable or unreliable ask yourself the following questions: Is it really that bad if the function call gets lost underway or isn't received in the correct order? And if so, would the advantages of making it reliable outweigh the response time penalty caused by the engine ensuring the correct order?

 

Ok, what's with that "simulated" keyword?

Ah yes, that weird function modifier. In fact, it can also be applied to states to affect state code in the same way. Remember the talk about Role and RemoteRole and how they are exchanged on the client up in the first few sections of this article? Well, the simulated keyword, or actually the lack of it, is related to the value of the Role property. Actor instances (as opposed to static functions and non-actor objects) will execute code in their functions and states only if the actor's Role is higher than ROLE_SimulatedProxy or if the function or state is marked as simulated.

Offline and on a server all actors have ROLE_Authority as their Role value, and the same goes for "runtime actors" (remember? bStatic and bNoDelete both set to False) created on the client via the Spawn() function, i.e. not received through replication. Also bStatic or bNoDelete actors that are bClientAuthoritative don't get their roles exchanged on clients, and replicated actors that are "torn off" get their roles exchanged back to the original values, so these also have a Role of ROLE_Authority on the client.

Now the rule says "either simulated or Role higher than ROLE_SimulatedProxy", but ROLE_Authority is not the only role satisfying that rule. There's also ROLE_AutonomousProxy, which is used by the local PlayerController and its Pawn on the client. That is actually set as the RemoteRole value on the server, but replication magic downgrades it to ROLE_SimulatedProxy on other clients so it really only applies to the owning client.

On the other side, there are also ROLE_DumbProxy (at least in UE1/2) and ROLE_None. Remember how mapper-placed actors may end up with Role set to ROLE_None on clients? It just means you can't use replication on them, but nothing would prevent you from calling simulated functions on these actors, if they had any.

 

 

 

 

转载于:https://www.cnblogs.com/Zephyroal/archive/2012/02/29/2372944.html

2019-04-16 12:01:00 NIUBINGWEI 阅读数 437
  • 从这里开始虚幻4-Editor介绍 v4.18

    本课程系列取名英译系列,是录制人员参考国外英文原版经典教程,结合中国人的习惯录制而成。希望能够给大家以帮助。从这里开始虚幻4系列教程,是Unreal的官方发布的入门教学,非常经典,是学习Unreal的佳入口。

    2398 人正在学习 去看看 杨石兴

基于Unreal游戏引擎的lidar传感器仿真及场景重建(混合点云) <912285@163.com>

目的:

  •     自动驾驶中激光雷达传感器非常重要,是感知的重要数据来源。3D感知模块的开发和测试过程中需要大量的标注好的点云数据。
  •     人工标注存在低效,存在一定错误率的问题。
  •     通过Unreal游戏引擎,构建仿真lidar传感器,并根据路测数据,进行3D重建场景,就能够很好地克服人工标注的缺点。
  •     训练神经网络时,可以通过仿真点云预先训练,再用真实点云训练,加速收敛。或者二者混合训练
  •     假如基于3D重建1秒钟标注2帧3D数据,则每天可以标注17.28万帧无错的点云数据,假如有10台标注电脑,每天可以标注172.8万帧点云数据

技术方案:

  •     Unreal游戏引擎是游戏行业的标杆引擎,支持光线追踪
  •     Unreal提供singleLineTraceByChannel的c++ api,允许用户指定ray的起点和终点,如果ray在起点和终点之间打到3d object,会返回hitPoint.
  •     以上就是lidar sensor的原理, 基于raytrace技术,并根据Velodyne的lidar参数构建仿真lidar sensor
  •     我用的是Velodyne的32线lidar,  技术书册可以到Velodyne官网上下载

项目成败的关键:

  •     仿真lidar sensor是否能够模拟噪声,这里通过引入gassusian dirtribution,加入噪声,下面会有理想lidar和gauss噪声lidar的对比
  •     能否有游戏美工,构建足够丰富的车辆,行人,电动车等的3d模型
  •     通过提取路测真实激光雷达扫描的“背景点云”,并和仿真生成的交通参与者的“干净”点云进行混合,生成混合点云
  •     混合点云具有真实点云的多样性,和仿真点云的高效和准确性。(下图为混合点云及真值,可用于模型训练和测试)

项目注意事项:

  •     高斯分布的方差不宜设置的过大
  •      一定要注意Velodyne的lidar在垂直方向上是不均匀分布的,市面上的仿真软件,如PreScan并不支持这种垂向不均匀分布特性。

项目成果:

    10mm噪声的混合点云:

    不带噪声的lidar sensor的场景:

simu lidar no noise

    高斯噪声的lidar sensor的场景(5mm gauss):

高斯噪声的lidar sensor的场景(10mm gauss):

 

2018-11-15 17:21:01 xiaoxiaolooi 阅读数 257
  • 从这里开始虚幻4-Editor介绍 v4.18

    本课程系列取名英译系列,是录制人员参考国外英文原版经典教程,结合中国人的习惯录制而成。希望能够给大家以帮助。从这里开始虚幻4系列教程,是Unreal的官方发布的入门教学,非常经典,是学习Unreal的佳入口。

    2398 人正在学习 去看看 杨石兴

unreal GIS 模块

unreal4 源代码模块

自从unreal4 开源以来,osg ogre 渐渐不能用来吃饭,于是本着听人劝吃饱饭的思想,转头unreal门下,继续为混口饭事业,投身革命。可是unreal的c++编程基本没有什么例子可看,只好自己从头做起。

  1. 开发者驱动
  2. 编辑器
  3. 工程目录
  4. 基础框架代码
  5. 第三方库

在这里插入图片描述
这个是文档目录,代码量难以阅读,决定从以下三方向入手,第一次写文字,真心不容易。
1.案例编写使用unreal4 的普通界面搭建自定义三维场景 介绍 editor层的基础代码
2.添加GIS地图属性信息 介绍 驱动层的基础代码
3.程序化植物合成 介绍 与unreal基础平台结合
以后会陆续跟新到这里
推荐大家使用 阿里云 https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=ic4sfgeu

2016-05-23 18:46:10 noahzuo 阅读数 4887
  • 从这里开始虚幻4-Editor介绍 v4.18

    本课程系列取名英译系列,是录制人员参考国外英文原版经典教程,结合中国人的习惯录制而成。希望能够给大家以帮助。从这里开始虚幻4系列教程,是Unreal的官方发布的入门教学,非常经典,是学习Unreal的佳入口。

    2398 人正在学习 去看看 杨石兴

这篇博客讲解了在UE4中,反射机制的实现。


反射机制

反射机制指的是程序可以在运行期间进行检测和修改自己状态的能力。

UE4引擎使用C++语言编写,C++语言本质上不支持反射机制,但是UE4提供了反射机制的实现。

FindFunction函数

在UE4中提供了FindFunction函数,用于在UObject或者AActor中查找某个函数名的函数并且返回其函数指针。

使用方法如下:

UFunction *Injured = this->FindFunction(TEXT("Injured"));

因此我们可以在Runtime时根据函数名的不同来进行函数的查找并且触发。

使用ProcessEvent函数来进行函数的触发

在UE4中提供了ProcessEvent函数来进行触发函数指针对应的函数,具体使用方法如下:

UFunction *Injured = this->FindFunction(TEXT("Injured"));
if (Injured)
{
    ProcessEvent(Injured, nullptr);
}

ProcessEvent函数第一个参数是函数指针,第二个参数指的是参数列表,其类型为void*类型。

使用CallFunction函数进行触发

还可以使用CallFunction函数来进行对应函数的触发,但是需要进行FFrame的建立。

并且为了避免内存泄漏,需要注意在使用过后销毁FFrame

使用方法如下:

UFunction *Injured = this->FindFunction(TEXT("Injured"));
if (Injured)
{
    void* params = nullptr;
    FFrame* frame = new Frame(this, Injured, params);
    CallFunction(*frame, params, Injured);

    delete frame;
}

额外功效

使用如下的两种方法还可以有一个额外的功能 —— 在C++中进行BP函数的调用。当需要在C++与BP进行通信时,一个做法是在关卡中进行通信,另一个做法则是使用上面的方法进行函数调用。

<全文完>

2015-09-01 23:40:52 dongdongbusi 阅读数 888
  • 从这里开始虚幻4-Editor介绍 v4.18

    本课程系列取名英译系列,是录制人员参考国外英文原版经典教程,结合中国人的习惯录制而成。希望能够给大家以帮助。从这里开始虚幻4系列教程,是Unreal的官方发布的入门教学,非常经典,是学习Unreal的佳入口。

    2398 人正在学习 去看看 杨石兴

Unreal 4 术语简介

标签: unreal4 游戏引擎 游戏开发

翻译自ue4官方文档

Objects

UE4中的objects和其他c++框架(QT、cocos2d-x)一样,具有垃圾收集、元数据等功能。
官方文档的描述:

The base building blocks in the Unreal Engine are called Objects and contain a lot of the essential “under the hood” functionality for your game assets. Just about everything in Unreal Engine 4 inherits (or gets some functionality) from an Object. In C++, UObject is the base class of all objects; it implements features such as garbage collections, metadata (UProperty) support for exposing variables to the Unreal Editor, and serialization for loading and saving.

Actors

在关卡摆放的游戏对象就是Actor。Actor可以可以作位置体积变换。在UE4中可以用蓝图或者c++来创建Actor。如果用c++,AActor是所有Actor的基类。
常用Actor:

- StaticMeshActor   环境
- CameraActor       相机
- PlayerStartActor  玩家起始

Components

组件component就是一个个可以附加到Actor上的功能点。人是Actor,会开车就是一个component。这个和和u3d里的概念类似的。ue4有很多组件,例如位置变换、audio等。

pawns

Actor的子类,用于表示人形角色或者其他具备avatar模型的角色。玩家以及NPC都是pawns。

Characters

pawn 的子类。用于表示玩家角色,具备输入控制、碰撞等属性。

PlayerController

玩家角色控制器?怎么翻译无所谓啦,反正就是用来接收玩家的输入并将这些输入信息关联到游戏中的角色。
在多人游戏中,每个客户端有且只有一个玩家控制器,客户端通过这个与服务端交互。

AIController

顾名思义,控制游戏中AI角色。

Brushes

用画刷画出来的游戏对象?不是很理解这个概念。反正画在游戏场景里的都是actor,可以用bursh画一些BSP(basic shape),例如圆柱体、立方体等等。

Levels

关卡,相当于游戏场景,里面有个中游戏对象。UE4中每个关卡都会被单独保存成.umap文件。

World

所有的level组成一个world。

GameModes

看了下文档,感觉似乎GameRule更适合它的意义。GameMode就是游戏的规则:玩家怎么加入游戏、游戏能否暂停、关卡的切换条件和方式等等。

GameStates

游戏状态,例如玩家的连接状态、比分等信息。

PlayerStates

玩家信息,例如姓名、职业、种族、等级、比分等等。

没有更多推荐了,返回首页