Reflection for Tools Development - Jeremy Walker, Senior Tools Programmer
Jeremy Walker, a Senior Tools Programmer at Ubisoft Vancouver, explores the costs and techniques of data-driven solutions in tools development. Delving into the comparison between hard-coded and data-driven systems, he emphasizes the importance of great workflows and offers insights on creating efficient infrastructure for tools. With a focus on animation, sounds, scenes, and more, this content showcases different approaches to development, including keep-it-simple and monolithic engine strategies.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Reflection for Tools Development Jeremy Walker Senior Tools Programmer Ubisoft Vancouver
Table of Contents Understanding the Costs of Tools Development The Ultimate Technique for Data Driven Solutions A Reflection-Powered Infrastructure for Tools
Hard Coded vs. Data Driven Systems Data Driven System Hard Coded System Animation Animation Animation Tools Animation Build System Hard Coded Animation System Animation Serialization Animation Engine
What's the Cost of Great Workflows? Animation Sounds Scenes Animation Tools Sound Editing Tools Scene Editing Tools Animation Build System Sound Build System Scene Build System Animation Serialization Sound Serialization Scene Serialization Animation Engine Sound Playback Engine Scene Rendering Engine
Great Workflows for All Types of Content Scenes Animation Input Front End Cameras Particles Characters Sounds SHARED SHARED SHARED SHARED SHARED SHARED Textures AI Levels Models Shaders Materials HUD Props SHARED SHARED SHARED SHARED SHARED SHARED Skeletons Music Sequences State Flows Curves Videos Cut Scenes Scripts SHARED SHARED SHARED SHARED SHARED SHARED
The Keep-It-Simple Approach Scenes Animation Input Front End Cameras Particles Characters Sounds Hard Coded Hard Coded Hard Coded Hard Coded SHARED SHARED SHARED SHARED SHARED SHARED Textures AI Levels Models Shaders Materials HUD Props Hard Coded Hard Coded Hard Coded SHARED SHARED SHARED SHARED SHARED SHARED Skeletons Music Sequences State Flows Curves Videos Cut Scenes Scripts Hard Coded Hard Coded Hard Coded Hard Coded Hard Coded SHARED SHARED SHARED SHARED SHARED SHARED
The Monolithic Engine Approach Monolithic Engine Scenes Animation Input Front End Cameras Particles Characters Sounds Animation, Sounds, Scenes, Input, Front End, Cameras, Particles, Characters, Textures, AI, Levels, Models, Shaders, Materials, HUD, Props, Skeletons, Music, Sequences, State Flows, Curves, Videos, Scripts, Cut Scenes Textures Animation, Sounds, Scenes, Input, Front End, Cameras, Particles, Characters, Textures, AI, Levels, Models, Shaders, Materials, HUD, Props, Skeletons, Music, Sequences, State Flows, Curves, Videos, Scripts, Cut Scenes AI Levels Models Shaders Materials HUD Props Animation, Sounds, Scenes, Input, Front End, Cameras, Particles, Characters, Textures, AI, Levels, Models, Shaders, Materials, HUD, Props, Skeletons, Music, Sequences, State Flows, Curves, Videos, Scripts, Cut Scenes Skeletons Music Sequences State Flows Curves Videos Cut Scenes Scripts Animation, Sounds, Scenes, Input, Front End, Cameras, Particles, Characters, Textures, AI, Levels, Models, Shaders, Materials, HUD, Props, Skeletons, Music, Sequences, State Flows, Curves, Videos, Scripts, Cut Scenes
The Problem Low Game and Genre-Specific Needs Development Cost Adaptable To Change Stable Tools Reusable Systems Great Workflows
The Solution For all types of content: Minimize the cost of developing great workflows. Design reusable systems while accommodating game- specific needs. Develop stable tools that adapt to constant change during production.
The Package Release Cycle Source Code Release Candidate Release yes yes Artist Gets Package Release Artist Testing Process Programmer Modifies Code Automated Build Process OK? Requests New Features OK? no no
The Monolithic Package Release Problem Monolithic Package Source Code Monolithic Package Release
The Benefit of Decoupled Packages Package Source Code Package Release Package Source Code Package Release Package Source Code Package Release Package Source Code Package Release Package Source Code Package Release
The Lockstep Release Problem Animation Tool Source Code Animation Tool Release Compile Time Dependency Run Time Dependency Sound Tool Source Code Lockstep Release Cycle Sound Tool Release Compile Time Dependency Run Time Dependency Game Source Code Game Release
Reducing Cost and Complexity Hardcoded Engine Monolithic Engine Decoupled Systems Decoupled Systems Scenes Scenes Sounds Sounds Animation Animation Animation, Sounds, Scenes, Input, Front End, Cameras, Particles, Characters, Textures, AI, Levels, Models, Shaders, Materials, HUD, Props, Skeletons, Music, Sequences, State Flows, Curves, Videos, Scripts, Cut Scenes Cameras Particles Character s Animation, Sounds, Scenes, Input, Front End, Cameras, Particles, Characters, Textures, AI, Levels, Models, Shaders, Materials, HUD, Props, Skeletons, Music, Sequences, State Flows, Curves, Videos, Scripts, Cut Scenes Cameras Particles Character s Hard Coded Animation, Sounds, Scenes, Input, Front End, Cameras, Particles, Characters, Textures, AI, Levels, Models, Shaders, Materials, HUD, Props, Skeletons, Music, Sequences, State Flows, Curves, Videos, Scripts, Cut Scenes Materials HUD Props Materials HUD Props Animation, Sounds, Scenes, Input, Front End, Cameras, Particles, Characters, Textures, AI, Levels, Models, Shaders, Materials, HUD, Props, Skeletons, Music, Sequences, State Flows, Curves, Videos, Scripts, Cut Scenes Reflection Medium Cost Complex Reuse All or Nothing Great Workflow Low Cost Simple Very Reusable Low Cost Simple Hard to Reuse Poor Workflow High Cost Very Complex Very Reusable Great Workflow Great Workflow
What is Reflection? From Wikipedia: Reflection is the process by which a computer program can observe and modify its own structure and behaviour.
Case Study: C++ Compilation Function Declaration Discover Expose Function B calls Function A C++ C++ Reflection Function A Compiler Compiler Binding to Function Definition Validate Implement
Reflection for Language Interoperability Type Discover Expose Definitions C# Visual Basic Compiler Visual Basic Code Reflection C# Code Compiler Type Binding Validate Implement
Reflection for Scripting in Games Type Discover Expose Definitions Script Adapter C++ Adapter Reflection Lua Script C++ Classes Type Binding Validate Implement
Reflection for Serialization in Games Type Discover Expose Definitions Serialized Objects C++ Adapter Reflection Serializer C++ Classes Type Binding Validate Implement
Common Language Specification Type Definitions Type Binding Reflection Type size and alignment Native types Classes Enums Allocate objects Binary representation Invoke constructor, get/invoke members Get/set enum value
Reflection in Action Example: Print all fields of type float Output const Type* type = TypeOf<SimpleVehicle>(); const char* name = type->Name(); size_t size = type->Size(); printf( Type: %s\n Size: %d\n , name, size); Type: SimpleVehicle Size: 4 Field: MaxSpeedKPH Offset 0 Value: 193.12 Instance vehicle = type->CreateInstance(); vehicle.As<SimpleVehicle&>().m_MaxSpeedKPH = 193.12f; for (int i=0; i<type->NumMembers(); i++) { const Member* member = vehicle.GetMember(i); if (member->IsField()) { const Field* field = (Field*)member; if (field->GetType() == TypeOf<float>()) { Instance value = vehicle.GetField(field); printf( Field: %s\n Offset: %d\n Value: %.2f\n , field->Name(), field->Offset(), value.As<float>()); } } }
Popular Approaches to C++ Reflection Macros Code Parser Type Definition Language
Reflection with Macros Pros Cons Macros Example No external tools class SimpleVehicle : public Entity { public: DECLARE_TYPE(); float m_MaxSpeedKPH; void Reset(bool useDefaults); float GetMaxSpeedMPH() const; void SetMaxSpeedMPH(float maxSpeedMPH); }; Awkward to implement Hard to debug Run-time discovery //In a separate .CPP file: DEFINE_TYPE(SimpleVehicle) BASE_CLASS(Entity) FIELD( MaxSpeedKPH , m_MaxSpeedKPH) METHOD(Reset) PROPERTY(GetMaxSpeedMPH, SetMaxSpeedMPH) DEFINE_TYPE_END()
Reflection with Code Parser Pros Cons Code Parser Example Easier to implement Compile-time discovery /// [Class] class SimpleVehicle : public Entity { public: /// [Field( MaxSpeedKPH )] float m_MaxSpeedKPH; /// [Method] void Reset(bool useDefaults); /// [Property] float GetMaxSpeedMPH() const; /// [Property] void SetMaxSpeedMPH(float maxSpeedMPH); }; Slow pre-build step
Reflection with Type Definition Language Pros Cons Type Definition Language Example Easiest to implement No slow pre-build class SimpleVehicle : Entity { float MaxSpeedKPH; void Reset(bool useDefaults); float MaxSpeedMPH { get; set; } }; Can t reflect existing classes
Exporting Type Definitions for Game Generated Binder Code C++ Reflected Types (game-side) Reflection System (game-side) Code Parser Types.xml C++ Class Types.xml /// [Class] class SimpleVehicle : public Entity { public: /// [Field( MaxSpeedKPH )] float m_MaxSpeedKPH; /// [Method] void Reset(bool useDefaults); /// [Property] float GetMaxSpeedMPH() const; /// [Property] void SetMaxSpeedMPH(float maxSpeedMPH); }; <type name= SimpleVehicle > <field name= MaxSpeedKPH type= float /> <method name= Reset returntype= void > <parameter name= useDefaults type= bool /> </method> <property name= MaxSpeedMPH type= float hasget= true hasset= true /> </type>
Exporting Type Definitions for Tools C++ Reflected Types (game-side) C# Proxy Generator Reflection System (tool-side) Code Parser Types.xml Types.xml C# Proxy Class <type name= SimpleVehicle > <field name= MaxSpeedKPH type= float /> <method name= Reset returntype= void > <parameter name= useDefaults type= bool /> </method> <property name= MaxSpeedMPH type= float hasget= true hasset= true /> </type> set { this.Instance.GetField( MaxSpeedKPH ).Set<float>(value); } } } public float MaxSpeedMPH { ... } public void Reset(bool useDefaults) { ... } } [ProxyType( SimpleVehicle , 0x81c37132)] public partial class SimpleVehicle : Entity { public float MaxSpeedKPH { get { return this.Instance.GetField( MaxSpeedKPH ).Get<float>(); }
Primary Uses for Reflection in Tools Types.xml Client-Server Remoting Serialization Reflection System Generated UI (PropertyGrid, TreeView, etc.)
Client-Server Remoting Tools (Client) Game (Server) Type Type Discover Definitions Discover Expose Definitions Expose Generated C# Proxy Classes C# Proxy Generator Remoting Client Remoting Server C++ Game Classes Reflection Reflection C++ Adapter Type Binding Validate Type Binding Validate Implement Implement
Problems and Workarounds Type definitions out of sync Detect type checksum mismatch Detect problems early Auto-synchronization of type information Auto-migration of data
Problems and Workarounds Tools tightly coupled to the game Avoid overuse of generated proxy classes Use generated UI where possible Use polymorphic proxy classes Tools Code Base Class has proxy Derived Class A Derived Class B Derived Class C has no proxy
Problems and Workarounds Excessive memory usage Strip type information based on usage Auto-detect unused reflected types
Other Uses for Reflection Marshalling events for multi-processor architectures Client-Server Remoting for Online Serialization of saved game data
Content Framework Tool-side Game-side 3rdParty Content Framework Asset Repository Asset Explorer Package System Asset Previewing Build System Asset Manager Reflection
Promising Results Fast tools development Great workflows for all types of content Decoupled systems with improved reusability and resilience to change