Files
o3de/Gems/Multiplayer/Code/Source/AutoGen/AutoComponent_Common.jinja
T
2021-04-07 14:03:29 -07:00

307 lines
10 KiB
Django/Jinja

{% macro UpperFirst(text) %}{{ text[0] | upper}}{{ text[1:] }}{% endmacro %}
{% macro LowerFirst(text) %}{{ text[0] | lower}}{{ text[1:] }}{% endmacro %}
{#
#}
{%- macro ParseRpcParams(property, outNames, outTypes, outDefines, use_default_value=False) -%}
{%- for Param in property.iter('Param') -%}
{%- do outNames.append(Param.attrib['Name']) -%}
{%- do outTypes.append(Param.attrib['Type']) -%}
{%- if use_default_value and Param.attrib['DefaultValue'] -%}
{%- do outDefines.append('const ' ~ Param.attrib['Type'] ~ '& ' + Param.attrib['Name'] + ' = ' + Param.attrib['DefaultValue']) -%}
{%- else -%}
{%- do outDefines.append('const ' ~ Param.attrib['Type'] ~ '& ' ~ Param.attrib['Name']) -%}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{#
#}
{%- macro ParseIncludes(Component) -%}
{%- for Include in Component.iter('Include') -%}
{{ caller(Include) -}}
{%- endfor -%}
{%- endmacro -%}
{#
#}
{%- macro ParseNetworkInputs(Component) -%}
{%- for NetworkInput in Component.iter('NetworkInput') -%}
{{ caller(NetworkInput) -}}
{%- endfor -%}
{%- endmacro -%}
{#
#}
{%- macro ParseArchetypeProperties(Component) -%}
{%- for ArchetypeProperty in Component.iter('ArchetypeProperty') -%}
{{ caller(ArchetypeProperty) -}}
{%- endfor -%}
{%- endmacro -%}
{#
#}
{%- macro ParseNetworkProperties(Component, ReplicateFrom, ReplicateTo) -%}
{%- for NetworkProperty in Component.iter('NetworkProperty') -%}
{%- if NetworkProperty.attrib['ReplicateFrom'] == ReplicateFrom and NetworkProperty.attrib['ReplicateTo'] == ReplicateTo -%}
{{ caller(NetworkProperty) -}}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{#
#}
{%- macro ParseRemoteProcedures(Component, InvokeFrom, HandleOn) -%}
{%- for RemoteProcedure in Component.iter('RemoteProcedure') -%}
{%- if RemoteProcedure.attrib['InvokeFrom'] == InvokeFrom and RemoteProcedure.attrib['HandleOn'] == HandleOn -%}
{{ caller(RemoteProcedure) -}}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{#
#}
{%- macro GetNetPropertiesClassName(Component, ClassType) -%}
{{ Component.attrib['Name'] }}{{ ClassType }}NetProperties
{%- endmacro -%}
{#
#}
{%- macro GetNetPropertiesDirtyEnumName(Component, ClassType, ReplicateFrom, ReplicateTo) -%}
{{ ReplicateFrom }}To{{ ReplicateTo }}DirtyEnum
{%- endmacro -%}
{#
#}
{%- macro GetNetPropertiesPropertyDirtyEnum(Property) -%}
{{ Property.attrib['Name'] }}_DirtyFlag
{%- endmacro -%}
{#
#}
{%- macro GetNetPropertiesQualifiedPropertyDirtyEnum(Component, ClassType, ReplicateFrom, ReplicateTo, Property) -%}
{{ GetNetPropertiesDirtyEnumName(Component, ClassType, ReplicateFrom, ReplicateTo) }}::{{ GetNetPropertiesPropertyDirtyEnum(Property) }}
{%- endmacro -%}
{#
#}
{%- macro GetModelClassName(Component, ClassType) -%}
{{ Component.attrib['Name'] }}Model{{ ClassType }}
{%- endmacro -%}
{#
#}
{%- macro GetArchetypeClassName(Entity, ClassType) -%}
{{ Entity.attrib['Name'] }}Archetype{{ ClassType }}
{%- endmacro -%}
{#
#}
{%- macro GetNetPropertiesSetName(ReplicateFrom, ReplicateTo) -%}
{{ ReplicateFrom }}To{{ ReplicateTo }}
{%- endmacro -%}
{#
#}
{%- macro GetModelReplicationRecordName(Component, ClassType) -%}
{{ Component.attrib['Name'] }}{{ ClassType }}ReplicationRecord
{%- endmacro -%}
{#
#}
{%- macro GetComponentDeltaName(Component, ClassType) -%}
{{ Component.attrib['Name'] }}Delta{{ ClassType }}
{%- endmacro -%}
{#
#}
{%- macro GetNetworkPropertyEventType(Property) -%}
AZ::Event<{{ Property.attrib['Type'] }}>
{%- endmacro -%}
{#
#}
{%- macro GetEntityClassName(Entity, ClassType) -%}
{{ Entity.attrib['Name'] }}{{ ClassType }}
{%- endmacro -%}
{#
#}
{%- macro GetEntityReplicatorName(Entity, ClassType) -%}
{{ Entity.attrib['Name'] }}{{ ClassType }}Replicator
{%- endmacro -%}
{#
#}
{%- macro GetEntityReplicationRecordName(Entity) -%}
{{ Entity.attrib['Name'] }}ReplicationRecord
{%- endmacro -%}
{#
#}
{% macro DefineNetworkPropertyReflection(Component, ReplicateFrom, ReplicateTo, ClassName) %}
{% call(Property) ParseNetworkProperties(Component, ReplicateFrom, ReplicateTo) %}
{% if Property.attrib['ExposeToEditor'] | booleanTrue %}
->Field("{{ Property.attrib['Name'] }}", &{{ ClassName }}::m_{{ LowerFirst(Property.attrib['Name']) }})
{% endif %}
{% endcall -%}
{% endmacro %}
{#
#}
{% macro DefineArchetypePropertyReflection(Component, ClassName) %}
{% call(Property) ParseArchetypeProperties(Component) %}
{% if Property.attrib['ExposeToEditor'] | booleanTrue %}
->Field("{{ Property.attrib['Name'] }}", &{{ ClassName }}::m_{{ LowerFirst(Property.attrib['Name']) }})
{% endif %}
{% endcall %}
{% endmacro %}
{#
#}
{% macro DefineNetworkPropertyConstructors(Component, ReplicateFrom, ReplicateTo, ClassType) %}
{% call(Property) ParseNetworkProperties(Component, ReplicateFrom, ReplicateTo) %}
{% if Property.attrib['Container'] == 'Array' %}
, m_{{ LowerFirst(Property.attrib['Name']) }}({% if Property.attrib['IsRewindable']|booleanTrue %}Multiplayer::RewindableObject<{{ Property.attrib['Type'] }}, Multiplayer::RewindHistorySize>({% endif %}{{ Property.attrib['Init'] }}{% if Property.attrib['IsRewindable']|booleanTrue %}, this){% endif %})
{% elif Property.attrib['Container'] == 'Vector' %}
, m_{{ LowerFirst(Property.attrib['Name']) }}({{ Property.attrib['Init'] }})
{% elif Property.attrib['IsRewindable']|booleanTrue %}
, m_{{ LowerFirst(Property.attrib['Name']) }}({{ Property.attrib['Init'] }}, this)
{% else %}
, m_{{ LowerFirst(Property.attrib['Name']) }}({{ Property.attrib['Init'] }})
{% endif %}
{% endcall %}
{% endmacro %}
{#
#}
{% macro DefineArchetypePropertyConstructors(Component) %}
{% call(Property) ParseArchetypeProperties(Component) %}
{% if Property.attrib['Container'] == 'Vector' %}
, m_{{ LowerFirst(Property.attrib['Name']) }}({{ Property.attrib['Init'] }}, {{ Property.attrib['Count'] }})
{% else %}
, m_{{ LowerFirst(Property.attrib['Name']) }}({{ Property.attrib['Init'] }})
{% endif %}
{% endcall %}
{% endmacro %}
{#
#}
{% macro ParseComponentServiceTypeAndName(Component) %}
{% for Service in Component.iter('ComponentRelation') %}
{% if Service.attrib['Constraint'] != 'Incompatible' %}
{% set Type = Service.attrib['Namespace'] + "::" + Service.attrib['Name'] %}
{% set Name = 'm_' + LowerFirst(Service.attrib['Name']) %}
{{ caller(Type, Name) -}}
{% endif %}
{% endfor %}
{% endmacro %}
{#
#}
{%- macro GetRpcEventAccessorName(InvokeFrom, HandleOn) -%}
{{ "GetRpc" + InvokeFrom + "To" + HandleOn + "Event" }}
{% endmacro %}
{#
#}
{% macro DeclareRpcHandler(Property, HandleOn, IsOverride) %}
{% set paramNames = [] %}
{% set paramTypes = [] %}
{% set paramDefines = [] %}
{% set PropertyName = UpperFirst(Property.attrib['Name']) %}
{{ ParseRpcParams(Property, paramNames, paramTypes, paramDefines) }}
{% if IsOverride %}
void Handle{{ PropertyName }}({{ ', '.join(paramDefines) }}) override {}
{% else %}
//! {{ PropertyName }} Handler
//! {{ Property.attrib['Description'] }}
//! HandleOn {{ HandleOn }}
virtual void Handle{{ PropertyName }}({{ ', '.join(paramDefines) }}) = 0;
{% endif %}
{% endmacro %}
{#
#}
{% macro DeclareRpcHandlers(Component, InvokeFrom, HandleOn, IsOverride) %}
{% call(Property) ParseRemoteProcedures(Component, InvokeFrom, HandleOn) %}
{{- DeclareRpcHandler(Property, HandleOn, IsOverride) -}}
{% endcall %}
{% endmacro %}
{#
#}
{%- macro EmitDerivedClassesComment(dataFileNames, Component, ComponentName, ComponentNameBase, ComponentDerived, ControllerName, ControllerNameBase, ControllerDerived, NetworkInputCount) -%}
{% if ComponentDerived or ControllerDerived %}
/*
/// You may use the classes below as a basis for your new derived classes. Derived classes must be marked in {{ (dataFileNames[0] | basename) }}
/// Place in your .h
#pragma once
#include <Source/AutoGen/{{ ComponentName }}.AutoComponent.h>
namespace {{ Component.attrib['Namespace'] }}
{
{% if ComponentDerived %}
class {{ ComponentName }}
: public {{ ComponentNameBase }}
{
public:
AZ_MULTIPLAYER_COMPONENT({{ Component.attrib['Namespace'] }}::{{ ComponentName }}, s_{{ LowerFirst(ComponentName) }}ConcreteUuid, {{ Component.attrib['Namespace'] }}::{{ ComponentNameBase }});
static void Reflect([[maybe_unused]] AZ::ReflectContext* context);
void OnInit() override {}
void OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
void OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
{{ DeclareRpcHandlers(Component, 'Authority', 'Client', true)|indent(8) }}
};
{% endif %}
{% if ControllerDerived %}
class {{ ControllerName }}
: public {{ ControllerNameBase }}
{
public:
{{ ControllerName }}({{ ComponentName }}& parent) : {{ ControllerNameBase }}(parent) {}
void OnActivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
void OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating) override {}
{% if NetworkInputCount > 0 %}
//! Common input processing logic for the NetworkInput.
//! @param input input structure to process
//! @param deltaTime amount of time to integrate the provided inputs over
void ProcessInput([[maybe_unused]] Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime) override {}
{%endif %}
{{ DeclareRpcHandlers(Component, 'Server', 'Authority', true)|indent(8) }}
{{ DeclareRpcHandlers(Component, 'Client', 'Authority', true)|indent(8) }}
{{ DeclareRpcHandlers(Component, 'Autonomous', 'Authority', true)|indent(8) }}
{{ DeclareRpcHandlers(Component, 'Authority', 'Autonomous', true)|indent(8) }}
};
{% endif %}
}
{% if ComponentDerived %}
/// Place in your .cpp
namespace {{ Component.attrib['Namespace'] }}
{
void {{ ComponentName }}::{{ ComponentName }}::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<{{ ComponentName }}, {{ ComponentNameBase }}>()
->Version(1);
}
}
}
{% endif %}
*/
{% else %}
// NOTE:
// No component roles have been overridden. You can modify {{ (dataFileNames[0] | basename) }} to specify derived classes for your desired network role.
// Once your modifications are complete, build the game.
// Your build will fail, but this comment will be replaced with a stub that can be used as the basis for your derived component roles.
{% endif %}
{%- endmacro -%}