1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

Pages

Saturday, May 16, 2020

Command Args Parser Update

Made a small update to the GitHub repository for the console command variables and functions library I've been working on.  Now both functions and variables can use functions with pre-computed hash values.

Variables Before:
CommandArgVariable g_testInteger("g_testInteger", CommandArgVariableType::Integer, 0);

Variables After:
CommandArgVariable g_testInteger(HASH_COMMAND_VARIABLE("g_testInteger", 0xf681f79d), CommandArgVariableType::Integer, 0);

Functions Before:
CONSOLE_COMMAND_FUNCTION_HASH(SetPlayerPosition)(CommandArgsParser & args) {

Functions After:
CONSOLE_COMMAND_FUNCTION_HASH(SetPlayerPosition, 0x13748f32)(CommandArgsParser & args) {

This has numerous benefits related to code size, initialization time, and perhaps most importantly security.  Unfortunately the trade off is that programmers need to calculate the hash value themselves.  To ease with this I've added 2 defines that allow you to compile an executable that makes this pretty easy.  By defining _HASH_COMMAND_VARIABLE and compiling you can create a simple command line utility that formats the HASH_COMMAND_VARIABLE macro for you.  By adding the folder this executable lives in to your system variables you can open up the command prompt and copy paste the values fairly easily.  Another _HASH_COMMAND_FUNCTION define has also been added to do the equivalent for the CONSOLE_COMMAND_FUNCTION_HASH macro.




Sunday, April 26, 2020

Doom: Eternal Recap

I started working on Doom: Eternal in January of 2019 until it shipped in March 2020 and I am still actively supporting it post launch today.  The commercial and critical feedback for Doom: Eternal has been very positive despite a pandemic forcing the closure of many retail outlets (yes people still buy games that way).  Some reviews have called it "one of the most intense shooters ever" and others have even given the game perfect 10 out 10 scores!

My personal experience differed with the one I had with Red Dead Redemption 2 for numerous reasons.  The team was much smaller, the genre was a first person shooter rather than an open world game, and rather than being on the project from the very start I joined relatively late into the development cycle of the project.  This meant I had to carry existing features across the finish line more often than architect them from the ground up and I had to become acquainted with these systems very quickly.  The project was originally scheduled to ship in November of the same year so this "whatever needs fixing fix it" attitude was more or less my experience working on the game.

Rather than linking to other videos I captured and edited some footage myself this time.  The compilation below does a good job of quickly demonstrating features I contributed to on the project.

You will likely want to  watch on YouTube and manually set the quality to 720p to get an acceptable resolution compared to the embedded video.  I captured the footage on an old 1680x1050 display and apologize for the inconvenience.

 




Weapons
I spent a lot of time working on the player’s Ballista weapon.  This included work on all 3 fire modes, the AI gore wounds used when hit by it, damage related issues, and the impact VFX.  This resulted in adding a few collision filtering features to our physics system, special shapetests for the primary fire, adding support for ‘sliced’ full body gore wounds, and splitting up the VFX into multiple instances for different positions and normal.

I did a lot of work on various weapons in the game aside from the Ballista.  This ranged from various damage issues, queueing up the equipment launcher, hit scan logic, smoke bombs for the playable mancubus, and many issues related to the upgrades for each weapon.



Gore
I fixed numerous features for gore systems and added a pattern for the destroyer blade gore cut behavior that could be re-used to replace demons with custom rigs, split ragdoll constraints, and shoot the pieces off with a random range of speed and direction.  I also worked on other gore behaviors like the blood punch, syncing wounds for multiplayer, and the deferred blood pools left behind by a corpse.


Multiplayer
My previous industry experience at Rockstar Games always used a peer to peer networking system which would migrate ownership of entities to different player machines during active gameplay.  Doom: Eternal was a fun learning and growth experience for me because it instead used a server authoritative method.  This meant I needed to learn new methods to deal with things that needed to be client authoritative such as hitscan weapon hits and how to validate it on the server.  Animation issues also could be much more difficult.  Previously during something like a ledge grab with a peer to peer setup we could simply disable all network blending but with a server authoritative setup this got much murkier and complicated than that.

I supported many gameplay features specific to our PVP gametype known as Battlemode.  This included demon character work (e.g. the revenant jetpack or the marauder shotgun), summon wheel abilities, 3rd person ledge grab animations, 1st person spectating, and a considerable amount of work adding features to our visual scripting system for the Battlemode tutorials.


Misc
  • Soft body repulsors that prevented characters from visually clipping into each other
  • Contributions to a heat map performance tool to find bottlenecks in a level
  • Contributions to player customization from getting skins to appear in cutscenes, animated deaths, and on remotely controlled clones in multiplayer
  • Gore nest secret encounter systems support
  • Boss voice over audio for the doom hunter boss fight
  • Numerous bug fixes for VFX, damage, stats and milestones not working as intended
  • Rune prototyping
  • Various UI and menu support


Sunday, August 11, 2019

QuakeCon 2019

Went to my first QuakeCon in July and had a great time meeting fans and being a part of the largest LAN party in North America.  The keynote for Doom: Eternal can be seen below.


Wednesday, June 19, 2019

Doom Eternal E3 Content

We released 2 trailers and 1 extended piece of gameplay footage at the Bethesda E3 Conference.  Looking forward to shipping this game in November!


Single Player Trailer




Battlemode Trailer






Full E3 Presentation

If you want to see just the gameplay you can skip to here.

Sunday, June 2, 2019

Console Command Variables & Functions Using Tagged Variants

An in game console and the ability to modify parts of your application from a file of command line arguments can be very useful for development.  I've written a fairly simple C++ solution that allows you to set any static variable using the interface and invoke functions from a file.  An actual in game console would be the next step after this and admittedly quite a bit of work.  You can go pretty far with this stuff with features like autocomplete, resetting back to default values, etc.  To use it yourself if you are using visual studio you can right click your project and go to Properties > Debugging and insert the path to the file in the Command Arguments.

It's got a GitHub repository you can find here:




Saturday, January 26, 2019

Joining iD Software as a Gameplay Programmer

After over 6 years of working at Rockstar Games I'm excited to announce that I have accepted an offer with iD Software. We've moved to the Dallas area and I will begin working on Doom Eternal on Monday!







Sunday, November 25, 2018

Red Dead Redemption 2 Recap

I worked on Red Dead Redemption 2 since milestone 1 in June of 2012. It has been 6.5 years and it's surreal to see the game has finally been shipped and well received by critics. Here are some of the features I made major contributions to during the course of the project.

The embedded videos have been resized to fit the Blogger post so they may not be as high quality as the actual video on YouTube itself.  Compared to the full YouTube videos these embeds have start and end times appropriate for quickly explaining the features.

Human Body Looting

Red Dead Redemption 2 features realistic and seamless dead body looting that lifts up the corpse slightly and picks at appropriate spots (waist, chest, etc) to get items.  We had lots of challenges to deal with related to ragdolls, slopes, and custom animation implementations to get such a feature to work.  Support for fallback swipes uses a generic asynchronous helper which does probes and route checks.





Animal Skinning

One of the most well received features I worked on is the animal skinning.  Compared to the previous entry in the series animal skinning in this game is seamless, gritty, and realistic.  Very small animals (e.g. rats) can be put straight into your satchel.  Slightly larger animals like rabbits need to be skinned with a pelt you put away like so.  Doing this seamlessly presented many challenges dealing with dynamic terrain, obstacles, target poses, slopes, and foot sliding.



Medium sized animals like deer have a carriable pelt after the skinning that you can put onto your horse.  We also had to support this in first person which presented some challenges with cameras and forced us to deliver on a high fidelity for such a feature that lets the player get this close to the action.




For the very large animals you can only get a large pelt and we do allow fade transitions to speed it along but the entries into it are still seamless.



Hogtie

A major tool for bounty hunting, missions, and ambient fun is the ability to hogtie (tie up) a character to carry them around without killing them.  Consistent with other improvements from the first Red Dead Redemption the hogtie, cut free, pickup, drop, stow, and unstow actions are seamless.  Compared to the other carriables like dead humans and objects hogtied characters are alive and thus support directional idles for various situations like being in shallow water or gun shots whizzing by.





Lasso

I spent a good deal of time getting the lasso working in a new codebase.  The basic blend trees, casting out, and reaction behaviors.  We have a fully physically simulated rope for the lasso in Redemption 2 so I'm really happy with the quality of it.




Carrying

You can pickup, drop, throw, stow, and unstow a lot of different things in Red Dead Redemption 2.  This presented complicated problems related to IK, reservations, mover fixups on sloped surfaces, and syncing it in multiplayer.  The final product supports pickup actions with humans (dead, knocked out, hogtied, dead and hogtied), animals (dead), and objects (moneybags, pelts, etc).  Fallbacks are supported for messy situations such as the corpse being under a wagon.

Another challenge we had to deal with was seamless transitions to and from cutscenes to carrying gameplay (see below).



Plant Picking

As part of our collection and looting mechanics we also have plant picking which features separate prompts for eating and storing in the player's satchel.  Similar to the other interactions we don't have camera cuts like in the first Red Dead Redemption and it's all seamless.  The player can walk away and continue this action with an upperbody performance when appropriate.




If you have time you can watch a video of all the herbs you can pick below.





Vehicle Locks

A minor but fun ambient feature in Red Dead Redemption 2 involves saving prisoners from the back of wagons and looting coaches with locks on the back.  To avoid making noise you can sometimes use a lockbreaker item to do it silently.  I worked on the basic vehicle extension for this which would spawn and attach the right lock object models and correctly sync this to the vehicle door state when broken.




Scenario Script Interface (Ambient AI)

Our scenario system in Red Dead Redemption 2 is used to give believable schedules and behaviors to NPCs in our world.  Typically we have points that are placed by designers and saved out into a binary file.  The script interface I added allowed scripters to add, remove, and modify scenario points on the fly which was very handy for missions and ambient scripts.

Volume Editor

We have an in-house tool that allows designers to specify volumes in their scripts to be used for queries and triggers.  I provided some support for this editor early in development to make it easier to use and add some features they needed.

Horse Saddlebag Searching

A relatively minor but still fun feature allows the player to loot the horse saddlebags of horses not owned by the player or the gang.



Dead Horse Saddlebag Searching

Searching a dead horse saddlebag is quite a bit different than our other dead interactions because we only animate the saddlebag itself.  This presented a very tricky penetration and animation problem which required a convex hull, swept circle, a static frame pose, and a lot of IK to alleviate.




Damage Tracking

Part of the challenge with hunting in Red Dead Redemption 2 is not just finding, killing, and skinning animals but retrieving high quality pelts and corpses.  This means the way the animal is killed matters in terms of where they are shot, the weapon used, and the ammo used.  From a programming perspective this meant we had to classify damage for an animal and then correlate that damage to the item received based on that damage quality.




Other

Minor contributions to early dueling prototypes, weapon prototypes, loot tables, blocking areas, ransacking, etc.

Saturday, September 22, 2018

Almost done

I've been working on this project for over 6 years and I'm happy to say it's set to ship in less than 40 days!




Saturday, April 13, 2013

Using Templates to Prevent/Catch Mistakes

I made a forum post on gamedev.net about templates and how they can be used to catch and prevent mistakes programmers inevitably make all the time. I felt it was worth linking to it here.

Sunday, September 2, 2012

Gameplay Architecture Part 2: Message Passing

Rationale
Games are very event driven applications which will sometimes (inevitably) end up resembling a web of complex states. In a project of any considerable size it simply isn't feasible to understand every component of the codebase.  This is especially true of at higher levels of gameplay code built on top of numerous parallel subsystems written by many different people over an extended period of time.

Messages which either inform pieces of code what has happened (e.g. DOOR_OPENED) or what to do (e.g. DISABLE_RENDERING) are part of the solution towards an architecturally sound and flexible codebase.  I had a few goals when implementing this system:

1) Integrates into the component/entity model system I wrote previously
2) Keeps class hierarchies flat, or avoids them altogether
3) Can queue messages efficiently and dispatch them later (e.g. send this message 10 seconds from now)
4) Components/Entities can listen in on these queues by their message type

Based on previous experience and these goals, this is what I came up with.

Simple Example
Message passing might be relatively simple if we could do everything on the stack.  As we will explore later, it is highly desirable to register components to listen in on messages by type, store them in a priority queue and dispatch them later.  This adds considerable amounts of difficulty to the problem, which will be addressed here in time.  First, lets explore the simplest case of a message sent on the stack to a known component.  Consistent with the component-entity model explained previously, here are the main interfaces for components/entities to send/receive messages.

const U32 DID_NOT_RECEIVE_MESSAGE = 0;
const U32 RECEIVED_MESSAGE = 1;

class jlMessage {
public:
      jlMessageType m_type;  // hashed message type
      void * m_data;         // untyped message data pointer
      U32 m_dataAndEntitySendMode;  // sizeof(*m_data) and flags
      F32 m_timeUntilDispatch; // when <= zero, dispatched from the queue
};

class jlComponent {
public:
    // Defers call to virtual receiveMessage function, non virtual base behavior for its benefits 
    // (e.g. tracing with certain debug builds that prints every message that is being sent)
    U32 sendMessage(jlMessage& msg);
protected:
     // Returns 1 if the message is received, 0 if not
     virtual U32 receiveMessage(jlMessage& msg);
}; 

class jlEntity {
public:
       // Iterates over attached components, calls sendMessage on them
       // Uses message entity send mode to determine which is called below
    U32 sendMessage(jlMessage& message, U32 minReceivers = DO_NOT_REQUIRE_RECEIVER);    
        // attached components  
 U32 sendMessageToComponents(jlMessage& message, U32 minReceivers = DO_NOT_REQUIRE_RECEIVER); 
        // attached components + all children
 U32 sendMessageToChildren(jlMessage& message, U32 minReceivers = DO_NOT_REQUIRE_RECEIVER);  
        // attached components + all ancestors 
 U32 sendMessageToAncestors(jlMessage& message, U32 minReceivers = DO_NOT_REQUIRE_RECEIVER);  
};



The non-virtual base behavior has numerous benefits for debugging
Lets take a look at a practical example, inside some script that detected a collision, we might wish to deal damage to an entity.


// inside some script which deals damage to an entity
void jlPhysicalCharacter::processCollisionWithFirePhantom() {
    jlDamageData dmgData;
    dmgData.m_amount = 5.0f;
    dmgData.m_damageType = FIRE;
    jlMessage damageMessage(JL_DAMAGE_MSG);
    damageMessage.setData(&dmgData, sizeof(dmgData));
    getHealthComponent()->sendMessage(damageMessage);
}

// inside the health component receiveMessage() function
U32 jlHealthComponent::receiveMessage(jlMessage& msg) {
    if (msg.getType() == JL_DAMAGE_MSG) {
         jlDamageData *data = static_cast<jlDamageData *>(msg.getData());
         JL_ASSERT(data);
         m_health -= data->m_damage;
         return RECEIVED_MESSAGE;
    } else {
        return DID_NOT_RECEIVE_MESSAGE;
    }
}

Message Data
The message is structured like so for a few reasons.  A unique type id makes message handling convenient in a switch statement, lets us know what to cast to and how to interpret the data.  In my implementation I am using an untyped void pointer so this is not something we can really ignore.  One alternative is to use a giant union of message data for all of your needs like so:

struct AlternativeMessageData {
 union {
  struct {
   Matrix4 m_matrix;
  };
  struct {
   char m_string[64];
  };
  struct {
   Point3 m_point;
   Vector3 m_vector;
   Quaternion4 m_quat;
   void* m_ptr;
  };
  // etc etc...
 };
};

The advantage of this approach is that you never have a dangling reference and queuing messages becomes as simple as queuing the message itself.  They have a consistent size and built in copy semantics.  Defining new types will add to compile times while the union works in all cases.


However, the unioned data approach has a number of downsides.  A giant union adds considerably to the size of the message struct.  This makes them less efficient to update and move around in the queue itself.  In certain instances, the data itself is not needed.  If a component receives a DISABLE_RENDERING message they likely don't need any more data to know what to do.  In these instances the unioned data can be excessive.  Such a system is also less readable in my opinion.  I found myself constantly going back and forth between code trying to find out what was really encoded where in the union.


With a pointer and knowledge of its size, you can define your own types and never have to wonder if the damage value was really encoded in m_floats[2] or m_floats[3] ever again.  Admittedly this requires jumping through a number of additional hoops, but it is a better solution in my opinion.

Entity Processing
Entities send the same messages, just with different kinds of iteration
The way the entity processes messages is pretty predictable given the signature.  We iterate through all components attached and call sendMessage to each one.  We accumulate the amount received and compare it to the minimum expected receivers.

In our messages we specify an EntitySendMode.  This is useful, since it allows us to queue messages without forcing the user to conform to one type of call.  If they want to send the message up or down the tree they merely need to specify the desired mode before queuing the message.

Queuing Messages
Don't Overcomplicate Things, It Is Just A Heap
So far things have been kept simple.  All we've really done is take a simple struct with a void pointer to some data, passed it to a consistent interface, casted it out and processed it appropriately.  All of this is still done when messages are queued, but we need to do a considerable amount of more behind the scenes to provide a safe and efficient priority queue of messages.

The easy part is providing the priority queue.  You can simply use an array heap and sort the messages by their remaining time.  You can keep popping messages off the heap until you find one that hasn't run out of time.  At that point, the following messages have not exceeded their delay yet and should not be dispatched just yet.  Any simple resource on heaps, where the data is sorted by the time until dispatch should be sufficient.

Except It Is Pool Allocated

In addition to your standard heap, we need to ensure our message data is safe.  To do this, when pushing our message we need to make a deep copy of our message data.  My implementation achieves this with a pool allocator.  The pool allocates space, the message data on the stack is memcopied to the newly allocated space, and the message struct which is copied into the queue has its data pointer readjusted to point to the data in the pool.  Popping the message does the usual heap manipulation and deallocates the message data from the pool.

Writing A Pool Allocator
Pool allocation might scare some people but it is one of the easiest custom memory allocators to roll yourself.    The idea is simple.  We have blocks of the same size kept in a buffer.  On init, every block goes into a "free list".  This is just a linked list of places in the pool that are currently unused.  When making an allocation we take the address (or offset) stored at the head of the "free list" and remove it from the free list.  When making a deallocation, we take the memory address/offset of the freed memory and add it to the free list.  This makes allocation and deallocation as fast as a linked list add/remove.  Of course, if we malloc these free list nodes it defeats the whole point of a custom memory allocator.  Therefore, we need to keep these nodes in the buffer itself.  This is not dangerous, since the free blocks are unused anyways. 

Listening For Queued Messages By Type
With the message queuing solved, we can somewhat trivially provide an interface that lets us register components/entities to listen for messages of a given type.  In addition to our existing queue, we can store a map that lets us efficiently look up all the listeners for a given message type.  Then when popping a message off the queue, we simply look up the linked list of listeners by its type, walk said list, and send the message to  every item in it.

Since I wanted to avoid virtual functions, I stored the type I needed to cast to in the nodes.  And yes, the nodes in the map should be pool allocated too.  

Other Implementations/Alternatives
- If you want to make things easier on yourself, you can use the unioned messaged data struct.  This will allow you to write an implementation that doesn't have to worry about any custom memory allocation.
-If you are less concerned about performance and more concerned about flexibility, you can have both components and entities derive from a "message receiver" class that has a virtual sendMessage function.  That way you don't need to store the receiver type yourself and worry about your type casts.
-You can forego the usage of an interface entirely and just use delegates/function pointers.
-You don't really need the message data size and time delay outside of the message queue itself.  This could be passed directly when queuing is needed and stored separately.  SoA would greatly improve data cache utilization when updating the remaining time on the message.