Timelines, VirtualCameras
This commit is contained in:
parent
81a55f96b8
commit
ae960523cf
|
@ -12,14 +12,24 @@ class CppClassMember
|
||||||
isStatic = false;
|
isStatic = false;
|
||||||
isSignal = false;
|
isSignal = false;
|
||||||
type = "void";
|
type = "void";
|
||||||
|
initialValue = null;
|
||||||
parameters = [];
|
parameters = [];
|
||||||
|
|
||||||
constructor( nameDefinition, body )
|
constructor( nameDefinition, body )
|
||||||
{
|
{
|
||||||
if ( nameDefinition.endsWith( "()" ) )
|
if ( nameDefinition.indexOf( "()" ) != -1)
|
||||||
{
|
{
|
||||||
this.isMethod = true;
|
this.isMethod = true;
|
||||||
nameDefinition = nameDefinition.replace( /\(\)$/, "" );
|
|
||||||
|
let typeRegex = /\(\)\s*(?:\:\s*(.+)\s*)?$/;
|
||||||
|
let result = typeRegex.exec( nameDefinition );
|
||||||
|
|
||||||
|
if ( result[ 1 ] )
|
||||||
|
{
|
||||||
|
this.type = result[ 1 ];
|
||||||
|
}
|
||||||
|
|
||||||
|
nameDefinition = nameDefinition.replace( typeRegex, "" );
|
||||||
}
|
}
|
||||||
|
|
||||||
let names = nameDefinition.split( /\s+/ );
|
let names = nameDefinition.split( /\s+/ );
|
||||||
|
@ -48,6 +58,46 @@ class CppClassMember
|
||||||
{
|
{
|
||||||
this.parseMethodBody( body );
|
this.parseMethodBody( body );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.parseVariableBody( body );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get isMemberWithInitialValue()
|
||||||
|
{
|
||||||
|
return ! this.isMethod && this.initialValue !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getMemberInitializer()
|
||||||
|
{
|
||||||
|
return `${this.name} = ${this.initialValue};`;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
parseVariableBody( body )
|
||||||
|
{
|
||||||
|
if ( typeof body === "boolean" )
|
||||||
|
{
|
||||||
|
this.type = "bool";
|
||||||
|
this.initialValue = body + "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( typeof body === "number" )
|
||||||
|
{
|
||||||
|
this.type = "float";
|
||||||
|
this.initialValue = body + "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let regex = /((?:\w|\<|\>)+)(?:\s*\=\s*(.+))?/;
|
||||||
|
let result = regex.exec( body );
|
||||||
|
|
||||||
|
this.type = result[ 1 ];
|
||||||
|
|
||||||
|
this.initialValue = result[ 2 ] || null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseMethodBody( body )
|
parseMethodBody( body )
|
||||||
|
@ -57,38 +107,50 @@ class CppClassMember
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.type = body.type || "void";
|
if ( typeof body === "string" )
|
||||||
|
|
||||||
let parameters = body.parameters;
|
|
||||||
|
|
||||||
if ( ! parameters )
|
|
||||||
{
|
{
|
||||||
|
this.type = body;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( let i = 0; i < parameters.length; i++ )
|
for ( let it in body )
|
||||||
{
|
{
|
||||||
let pm = parameters[ i ];
|
if ( ! body.hasOwnProperty( it ) )
|
||||||
|
|
||||||
let cppParameter = new CppParameter();
|
|
||||||
|
|
||||||
for ( let it in pm )
|
|
||||||
{
|
{
|
||||||
if ( ! pm.hasOwnProperty( it ) )
|
continue;
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
cppParameter.name = it;
|
|
||||||
cppParameter.type = pm[ it ];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cppParameter = new CppParameter();
|
||||||
|
cppParameter.name = it;
|
||||||
|
cppParameter.type = body[ it ];
|
||||||
|
|
||||||
this.parameters.push( cppParameter );
|
this.parameters.push( cppParameter );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getMethodBinding( className )
|
getMethodBinding( className )
|
||||||
{
|
{
|
||||||
|
if ( ! this.isMethod )
|
||||||
|
{
|
||||||
|
let type = stringToVariantType( this.type );
|
||||||
|
|
||||||
|
let bindings = [];
|
||||||
|
|
||||||
|
bindings.push( `/* ${this.name}: ${this.type} */` );
|
||||||
|
bindings.push( `ClassDB::bind_method(D_METHOD("get_${this.name}"), &${className}::get_${this.name});` );
|
||||||
|
bindings.push( `ClassDB::bind_method(D_METHOD("set_${this.name}"), &${className}::set_${this.name});` );
|
||||||
|
bindings.push( `ADD_PROPERTY(PropertyInfo(Variant::${type}, "${this.name}"), "set_${this.name}", "get_${this.name}");` );
|
||||||
|
bindings.push( ` ` );
|
||||||
|
|
||||||
|
//ClassDB::bind_method(D_METHOD("set_color", "color"), &GLTFLight::set_color);
|
||||||
|
//ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); // Color
|
||||||
|
|
||||||
|
return bindings.join( "\n " );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if ( this.isSignal )
|
if ( this.isSignal )
|
||||||
{
|
{
|
||||||
//ADD_SIGNAL(MethodInfo("session_supported", PropertyInfo(Variant::STRING, "session_mode"), PropertyInfo(Variant::BOOL, "supported")));
|
//ADD_SIGNAL(MethodInfo("session_supported", PropertyInfo(Variant::STRING, "session_mode"), PropertyInfo(Variant::BOOL, "supported")));
|
||||||
|
@ -108,7 +170,16 @@ class CppClassMember
|
||||||
}
|
}
|
||||||
else if ( this.isVirtual )
|
else if ( this.isVirtual )
|
||||||
{
|
{
|
||||||
return `GDVIRTUAL_BIND( ${this.name} );`;
|
let parameterInfos = "";
|
||||||
|
|
||||||
|
for ( let i = 0; i < this.parameters.length; i++ )
|
||||||
|
{
|
||||||
|
let name = `, "${this.parameters[ i ].name}"`;
|
||||||
|
|
||||||
|
parameterInfos += name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `GDVIRTUAL_BIND( ${this.name}${parameterInfos} );`;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -160,10 +231,28 @@ class CppClassMember
|
||||||
}
|
}
|
||||||
|
|
||||||
getVariableHeaderDefinition()
|
getVariableHeaderDefinition()
|
||||||
|
{
|
||||||
|
return `${this.type} get_${this.name}(); void set_${this.name}( ${this.type} p_${this.name} );`
|
||||||
|
//return `${this.type} ${this.name};`
|
||||||
|
}
|
||||||
|
|
||||||
|
getPropertyHeaderDefinition()
|
||||||
{
|
{
|
||||||
return `${this.type} ${this.name};`
|
return `${this.type} ${this.name};`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPropertyImplementation( className )
|
||||||
|
{
|
||||||
|
let bindings = [];
|
||||||
|
|
||||||
|
bindings.push( `/* ${this.name}: ${this.type} */` );
|
||||||
|
bindings.push( `${this.type} ${className}::get_${this.name}() { return ${this.name}; }` );
|
||||||
|
bindings.push( `void ${className}::set_${this.name}( ${this.type} p_${this.name} ) { ${this.name} = p_${this.name}; }` );
|
||||||
|
bindings.push( ` ` );
|
||||||
|
|
||||||
|
return bindings.join( "\n" );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
@ -175,6 +264,11 @@ module.exports =
|
||||||
|
|
||||||
function stringToVariantType( stringType )
|
function stringToVariantType( stringType )
|
||||||
{
|
{
|
||||||
|
if ( /^TypedArray\<.+\>$/.test( stringType ) )
|
||||||
|
{
|
||||||
|
return "ARRAY";
|
||||||
|
}
|
||||||
|
|
||||||
switch( stringType )
|
switch( stringType )
|
||||||
{
|
{
|
||||||
case "bool": return "BOOL";
|
case "bool": return "BOOL";
|
||||||
|
@ -222,5 +316,7 @@ function stringToVariantType( stringType )
|
||||||
case "PackedColorArray": return "PACKED_COLOR_ARRAY";
|
case "PackedColorArray": return "PACKED_COLOR_ARRAY";
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
console.error( "Type could not be mapped: ", stringType );
|
||||||
|
|
||||||
|
return "OBJECT";
|
||||||
}
|
}
|
|
@ -3,7 +3,8 @@ const path = require( "path" );
|
||||||
const { loadJSON, getFiles, saveUTF8, getMatches, loadUTF8, insertText } = require( "./library.js" );
|
const { loadJSON, getFiles, saveUTF8, getMatches, loadUTF8, insertText } = require( "./library.js" );
|
||||||
const { CppClassMember } = require( "./cpp-class-member.js" );
|
const { CppClassMember } = require( "./cpp-class-member.js" );
|
||||||
|
|
||||||
function createCppHeader( className, extendingClassName, headerDefine, protectedMembers, publicMembers, includes )
|
function createCppHeader( className, extendingClassName, headerDefine, protectedMembers,
|
||||||
|
publicMembers, includes )
|
||||||
{
|
{
|
||||||
|
|
||||||
let cppHeader =
|
let cppHeader =
|
||||||
|
@ -15,7 +16,6 @@ let cppHeader =
|
||||||
#define ${headerDefine}
|
#define ${headerDefine}
|
||||||
|
|
||||||
${includes}
|
${includes}
|
||||||
#include "./${extendingClassName}.h"
|
|
||||||
|
|
||||||
|
|
||||||
class ${className} : public ${extendingClassName}
|
class ${className} : public ${extendingClassName}
|
||||||
|
@ -44,7 +44,7 @@ return cppHeader;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCppImplementation( className, boundMethods )
|
function createCppImplementation( className, boundMethods, constructorExpressions, destructorExpressions, methodImplementations )
|
||||||
{
|
{
|
||||||
|
|
||||||
let cppImplementation =
|
let cppImplementation =
|
||||||
|
@ -61,14 +61,16 @@ void ${className}::_bind_methods()
|
||||||
|
|
||||||
${className}::${className}()
|
${className}::${className}()
|
||||||
{
|
{
|
||||||
|
${constructorExpressions}
|
||||||
}
|
}
|
||||||
|
|
||||||
${className}::~${className}()
|
${className}::~${className}()
|
||||||
{
|
{
|
||||||
|
${destructorExpressions}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
${methodImplementations}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
return cppImplementation;
|
return cppImplementation;
|
||||||
|
@ -87,6 +89,22 @@ function createTypeRegistration( className )
|
||||||
|
|
||||||
function createIncludes( className )
|
function createIncludes( className )
|
||||||
{
|
{
|
||||||
|
console.log( "Create include", className );
|
||||||
|
|
||||||
|
let godotClasses =
|
||||||
|
{
|
||||||
|
"Node" : "scene/main/node.h",
|
||||||
|
"Node2D" : "scene/2d/node_2d.h",
|
||||||
|
"Node3D" : "scene/3d/node_3d.h",
|
||||||
|
"Resource" : "core/io/resource.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( godotClasses[ className ] )
|
||||||
|
{
|
||||||
|
return `#include "${godotClasses[ className ]}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return `#include "./${className}.h"`;
|
return `#include "./${className}.h"`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,13 +246,21 @@ async function createCppFiles( definitionPath, types, missingTypes )
|
||||||
let protectedMembers = grabMembers( data.protected );
|
let protectedMembers = grabMembers( data.protected );
|
||||||
let publicMembers = grabMembers( data.public );
|
let publicMembers = grabMembers( data.public );
|
||||||
|
|
||||||
let protectedHeader = protectedMembers.map( p => p.getHeaderDefinition() ).join( "\n " );
|
let allMembers = [].concat( protectedMembers ).concat( publicMembers );
|
||||||
let publicHeader = publicMembers.map( p => p.getHeaderDefinition() ).join( "\n " );
|
|
||||||
|
|
||||||
let protectedBindings = protectedMembers.map( p => p.getMethodBinding( className ) );
|
|
||||||
let publicBindings = publicMembers.map( p => p.getMethodBinding( className ) );
|
|
||||||
|
|
||||||
let bindings = protectedBindings.concat( publicBindings ).join( "\n " );
|
let protectedHeader = protectedMembers.map( m => m.getHeaderDefinition() ).join( "\n " );
|
||||||
|
let publicHeader = publicMembers.map( m => m.getHeaderDefinition() ).join( "\n " );
|
||||||
|
|
||||||
|
let properties = publicMembers.filter( m => ! m.isMethod );
|
||||||
|
|
||||||
|
let propertyDefinitions = properties.map( p => p.getPropertyHeaderDefinition() ).join( "\n " );
|
||||||
|
|
||||||
|
protectedHeader += "\n\n " + propertyDefinitions;
|
||||||
|
|
||||||
|
let methodBindings = allMembers.map( m => m.getMethodBinding( className ) ).join( "\n " );
|
||||||
|
|
||||||
|
let initializers = allMembers.filter( m => m.isMemberWithInitialValue ).map( m => m.getMemberInitializer() ).join( "\n ");
|
||||||
|
|
||||||
let includes = "";
|
let includes = "";
|
||||||
|
|
||||||
|
@ -243,8 +269,20 @@ async function createCppFiles( definitionPath, types, missingTypes )
|
||||||
includes = data.includes.map( inc => `#include "${inc}"` );
|
includes = data.includes.map( inc => `#include "${inc}"` );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let extendingClassInclude = createIncludes( extendingClass );
|
||||||
|
|
||||||
|
includes += "\n" + extendingClassInclude;
|
||||||
let header = createCppHeader( className, extendingClass, headerDefine, protectedHeader, publicHeader, includes );
|
let header = createCppHeader( className, extendingClass, headerDefine, protectedHeader, publicHeader, includes );
|
||||||
let implementation = createCppImplementation( className, bindings );
|
|
||||||
|
let constructorExpressions = initializers;
|
||||||
|
let destructorExpressions = "";
|
||||||
|
let methodImplementations = "";
|
||||||
|
|
||||||
|
let propertyImplementations = properties.map( p => p.getPropertyImplementation( className ) ).join( "\n" );
|
||||||
|
|
||||||
|
methodImplementations += propertyImplementations;
|
||||||
|
|
||||||
|
let implementation = createCppImplementation( className, methodBindings, constructorExpressions, destructorExpressions, methodImplementations );
|
||||||
|
|
||||||
//console.log( header );
|
//console.log( header );
|
||||||
//console.log( implementation );
|
//console.log( implementation );
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit d6b968703d75749c4f7ded3abe5ec9beba97ae8d
|
Subproject commit c19d8b71d88206e99fa2c987d369ac713c275d41
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"class":"RJTimeLine:Resource",
|
||||||
|
|
||||||
|
"public":
|
||||||
|
{
|
||||||
|
"isLooping": false,
|
||||||
|
"loopStart": 0,
|
||||||
|
"loopEnd": 16,
|
||||||
|
|
||||||
|
"startSpeed": 1,
|
||||||
|
"autoStart": false
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
{
|
||||||
|
"class":"RJTimeLineManager:RJNetworkNode",
|
||||||
|
|
||||||
|
"includes":[ "./RJTimeLine.h" ],
|
||||||
|
|
||||||
|
"public":
|
||||||
|
{
|
||||||
|
"virtual getTimeLineIndex():int" : { "timeLine":"Ref<RJTimeLine>" },
|
||||||
|
"virtual getTimeLineSize():int" : {},
|
||||||
|
|
||||||
|
"virtual createID():int" : {},
|
||||||
|
|
||||||
|
"virtual getLastPosition():double" : { "timeLineIndex":"int" },
|
||||||
|
|
||||||
|
"virtual getPosition():double" : { "timeLineIndex":"int" },
|
||||||
|
"virtual setPosition()" : { "timeLineIndex":"int", "position":"double" },
|
||||||
|
|
||||||
|
"virtual getSpeed():double" : { "timeLineIndex":"int" },
|
||||||
|
"virtual setSpeed()" : { "timeLineIndex":"int", "speed":"double" },
|
||||||
|
|
||||||
|
"virtual getPlayState():bool" : { "timeLineIndex":"int" },
|
||||||
|
"virtual setPlayState()" : { "timeLineIndex":"int", "playState":"bool" },
|
||||||
|
|
||||||
|
"virtual scheduleEvent()" :
|
||||||
|
{
|
||||||
|
"timeLineIndex": "int",
|
||||||
|
"position": "double",
|
||||||
|
"callbackID": "int",
|
||||||
|
"isPersistent": "bool"
|
||||||
|
},
|
||||||
|
|
||||||
|
"virtual scheduleSpan()" :
|
||||||
|
{
|
||||||
|
"timeLineIndex": "int",
|
||||||
|
"startPosition": "double",
|
||||||
|
"endPosition": "double",
|
||||||
|
"callbackID": "int",
|
||||||
|
"isPersistent": "bool"
|
||||||
|
},
|
||||||
|
|
||||||
|
"signal onEvent()" : { "callbackID": "int" },
|
||||||
|
|
||||||
|
"signal onSpan()" : { "callbackID": "int", "spanType": "int" }
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,9 +3,6 @@
|
||||||
|
|
||||||
"public":
|
"public":
|
||||||
{
|
{
|
||||||
"virtual update()":
|
"virtual update()":{ "delta":"double" }
|
||||||
{
|
|
||||||
"parameters":[ { "delta":"double" } ]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"class":"RJVirtualCamera3D:Node3D",
|
||||||
|
|
||||||
|
"public":
|
||||||
|
{
|
||||||
|
"virtual getCameraPosition()": "Vector3",
|
||||||
|
"virtual getCameraRotation()": "Quaternion",
|
||||||
|
"virtual getCameraFOV()":"float"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"class":"RJVirtualCamera3DManager:RJNetworkNode",
|
||||||
|
|
||||||
|
"includes":[ "./RJVirtualCamera3D.h" ],
|
||||||
|
|
||||||
|
"public":
|
||||||
|
{
|
||||||
|
"virtual getCamera():Ref<RJVirtualCamera3D>" : { "cameraIndex": "int" },
|
||||||
|
"virtual getCameraIndex():int" : { "timeLine":"Ref<RJVirtualCamera3D>" },
|
||||||
|
"virtual getCameraSize():int" : {},
|
||||||
|
|
||||||
|
"virtual getCameraPriority():float" : { "cameraIndex":"int" },
|
||||||
|
"virtual setCameraPriority()" : { "cameraIndex":"int", "priority":"float" },
|
||||||
|
|
||||||
|
"cameraPrioritySmoothingCoefficient": 0.5,
|
||||||
|
"cameraPrioritySmoothingStepFPS": 120
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,9 +3,9 @@
|
||||||
|
|
||||||
"public":
|
"public":
|
||||||
{
|
{
|
||||||
"virtual dispatchStart()" : { "type":"int" },
|
"virtual dispatchStart():int" : {},
|
||||||
"virtual dispatchCancel()" : { "parameters":[ { "id":"int" } ] },
|
"virtual dispatchCancel()": { "id":"int" },
|
||||||
"virtual dispatchEnd()" : { "parameters":[ { "id":"int" } ] },
|
"virtual dispatchEnd()" : { "id":"int" },
|
||||||
"signal onSequenceDone()" : { "parameters":[ { "id":"int" } ] }
|
"signal onSequenceDone()" : { "id":"int" }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue