Skip to content

Commit

Permalink
Merge pull request 4ian#313 from 4ian/feature/layer-timescale
Browse files Browse the repository at this point in the history
Time scale for layers and various fixes/improvements
  • Loading branch information
4ian authored Dec 17, 2016
2 parents 96afbeb + b9abd56 commit 40fcb66
Show file tree
Hide file tree
Showing 40 changed files with 494 additions and 94 deletions.
52 changes: 40 additions & 12 deletions Core/GDCore/Extensions/Builtin/CameraExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,69 +288,97 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCameraExtension(gd::Pla
.AddParameter("expression", _("New value"))
.MarkAsAdvanced();

extension.AddExpression("CameraWidth", _("Width of a camera of a layer"), _("Width of a camera of a layer"), _("Camera"), "res/actions/camera.png")
extension.AddCondition("LayerTimeScale",
_("Layer time scale"),
_("Compare the time scale applied on the objects of the layer."),
_("The time scale of layer _PARAM1_ is _PARAM2__PARAM3_"),
_("Layers and cameras/Time"),
"res/conditions/time24.png",
"res/conditions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("relationalOperator", _("Sign of the test"))
.AddParameter("expression", _("Value to test"))
.MarkAsAdvanced()
.SetManipulatedType("number");

extension.AddAction("ChangeLayerTimeScale",
_("Change layer time scale"),
_("Change the time scale applied on the objects of the layer."),
_("Set time scale of layer _PARAM1_ to _PARAM2_"),
_("Layers and cameras/Time"),
"res/actions/time24.png",
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer (base layer if empty)"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Scale (1: Default, 2: 2x faster, 0.5: 2x slower...)"));

extension.AddExpression("CameraWidth", _("Width of a camera of a layer"), _("Width of a camera of a layer"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");

extension.AddExpression("CameraHeight", _("Height of a camera of a layer"), _("Height of a camera of a layer"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("CameraHeight", _("Height of a camera of a layer"), _("Height of a camera of a layer"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");

extension.AddExpression("CameraViewportLeft", _("X position of the top left side point of a render zone"), _("X position of the top left side point of a render zone"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("CameraViewportLeft", _("X position of the top left side point of a render zone"), _("X position of the top left side point of a render zone"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");

extension.AddExpression("CameraViewportTop", _("Y position of the top left side point of a render zone"), _("Y position of the top left side point of a render zone"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("CameraViewportTop", _("Y position of the top left side point of a render zone"), _("Y position of the top left side point of a render zone"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");

extension.AddExpression("CameraViewportRight", _("X position of the bottom right side point of a render zone"), _("X position of the bottom right side point of a render zone"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("CameraViewportRight", _("X position of the bottom right side point of a render zone"), _("X position of the bottom right side point of a render zone"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");

extension.AddExpression("CameraViewportBottom", _("Y position of the bottom right side point of a render zone"), _("Y position of the bottom right side point of a render zone"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("CameraViewportBottom", _("Y position of the bottom right side point of a render zone"), _("Y position of the bottom right side point of a render zone"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"))
.AddParameter("expression", _("Camera number (default : 0)")).SetDefaultValue("0");

extension.AddExpression("CameraX", _("Camera X position"), _("Camera X position"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("CameraX", _("Camera X position"), _("Camera X position"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");

extension.AddExpression("VueX", _("Camera X position"), _("Camera X position"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("VueX", _("Camera X position"), _("Camera X position"), _("Layers and cameras"), "res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");

extension.AddExpression("CameraY", _("Camera Y position"), _("Camera Y position"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("CameraY", _("Camera Y position"), _("Camera Y position"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");

extension.AddExpression("VueY", _("Camera Y position"), _("Camera Y position"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("VueY", _("Camera Y position"), _("Camera Y position"), _("Layers and cameras"), "res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");

extension.AddExpression("CameraRotation", _("Angle of a camera of a layer"), _("Angle of a camera of a layer"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("CameraRotation", _("Angle of a camera of a layer"), _("Angle of a camera of a layer"), _("Layers and cameras"), "res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");

extension.AddExpression("VueRotation", _("Angle of a camera of a layer"), _("Angle of a camera of a layer"), _("Camera"), "res/actions/camera.png")
extension.AddExpression("VueRotation", _("Angle of a camera of a layer"), _("Angle of a camera of a layer"), _("Layers and cameras"), "res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"), "",true).SetDefaultValue("\"\"")
.AddParameter("expression", _("Camera number (default : 0)"), "",true).SetDefaultValue("0");

extension.AddExpression("LayerTimeScale", _("Time scale"), _("Time scale"), _("Layers and cameras"), "res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("layer", _("Layer"));
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/Extensions/Builtin/TimeExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsTimeExtension(gd::Platf
"res/actions/time24.png",
"res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("expression", _("Scale (1 : Default, 2 : Faster, 0.5 : Slower...)"));
.AddParameter("expression", _("Scale (1: Default, 2: 2x faster, 0.5: 2x slower...)"));

extension.AddExpression("TimeDelta", _("Time elapsed since the last image"), _("Time elapsed since the last image"), _("Time"), "res/actions/time.png")
.AddCodeOnlyParameter("currentScene", "");
Expand Down
2 changes: 1 addition & 1 deletion Extensions/PanelSpriteObject/panelspriteruntimeobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ gdjs.PanelSpriteRuntimeObject.prototype.onDeletedFromScene = function(runtimeSce
}
};

gdjs.PanelSpriteRuntimeObject.prototype.updateTime = function() {
gdjs.PanelSpriteRuntimeObject.prototype.update = function() {
this._renderer.ensureUpToDate();
}

Expand Down
16 changes: 7 additions & 9 deletions Extensions/ParticleSystem/ParticleEmitterObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,14 @@ void ParticleEmitterBase::UpdateLifeTime()
particleSystem->particleModel->setLifeTime(particleLifeTimeMin,particleLifeTimeMax);
}

RuntimeParticleEmitterObject::RuntimeParticleEmitterObject(RuntimeScene & scene_, const ParticleEmitterObject & particleEmitterObject):
RuntimeObject(scene_, particleEmitterObject),
RuntimeParticleEmitterObject::RuntimeParticleEmitterObject(RuntimeScene & scene, const ParticleEmitterObject & particleEmitterObject):
RuntimeObject(scene, particleEmitterObject),
hasSomeParticles(true)
{
ParticleEmitterBase::operator=(particleEmitterObject);

//Store a pointer to the scene
scene = &scene_;

CreateParticleSystem();
SetTexture(scene_, GetParticleTexture());
SetTexture(scene, GetParticleTexture());

OnPositionChanged();
}
Expand Down Expand Up @@ -683,13 +680,14 @@ void ParticleEmitterBase::SetZoneRadius(float newValue)
if ( particleSystem && particleSystem->zone ) particleSystem->zone->setRadius(zoneRadius);
}

void RuntimeParticleEmitterObject::UpdateTime(float deltaTime)
void RuntimeParticleEmitterObject::Update(const RuntimeScene & scene)
{
double elapsedTimeInSeconds = static_cast<double>(GetElapsedTime(scene))/1000000.0;
if ( GetParticleSystem() )
hasSomeParticles = GetParticleSystem()->particleSystem->update(deltaTime);
hasSomeParticles = GetParticleSystem()->particleSystem->update(elapsedTimeInSeconds);

if (GetDestroyWhenNoParticles() && !hasSomeParticles)
DeleteFromScene(const_cast<RuntimeScene&>(*scene)); //Ugly const cast
DeleteFromScene(const_cast<RuntimeScene&>(scene)); //Ugly const cast
}

void ParticleEmitterBase::SetParticleGravityAngle( float newAngleInDegree )
Expand Down
3 changes: 1 addition & 2 deletions Extensions/ParticleSystem/ParticleEmitterObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public :
virtual float GetWidth() const {return 32;};
virtual float GetHeight() const {return 32;};

virtual void UpdateTime(float timeElapsed);
virtual void Update(const RuntimeScene & scene);

bool NoMoreParticles() const {return !hasSomeParticles;};

Expand All @@ -281,7 +281,6 @@ public :
private:

bool hasSomeParticles;
const RuntimeScene * scene; ///< Pointer to the scene. Initialized during LoadRuntimeResources call.
};

#endif // PARTICLEEMITTEROBJECT_H
2 changes: 1 addition & 1 deletion Extensions/PathBehavior/PathBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void PathBehavior::DoStepPreEvents(RuntimeScene & scene)
}

// add to the current time along the path
timeOnSegment += static_cast<double>(scene.GetTimeManager().GetElapsedTime())
timeOnSegment += static_cast<double>(object->GetElapsedTime(scene))
/ 1000000.0 * speed;

// if I reached the end of this segment, move to a new segment
Expand Down
2 changes: 1 addition & 1 deletion Extensions/PathfindingBehavior/PathfindingBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void PathfindingBehavior::DoStepPreEvents(RuntimeScene & scene)
if (path.empty() || reachedEnd) return;

//Update the speed of the object
float timeDelta = static_cast<double>(scene.GetTimeManager().GetElapsedTime()) / 1000000.0;
float timeDelta = static_cast<double>(object->GetElapsedTime(scene)) / 1000000.0;
speed += acceleration*timeDelta;
if ( speed > maxSpeed ) speed = maxSpeed;
angularSpeed = angularMaxSpeed; //No acceleration for angular speed for now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ gdjs.PathfindingRuntimeBehavior.prototype.doStepPreEvents = function(runtimeScen
if (this._path.length === 0 || this._reachedEnd) return;

//Update the speed of the object
var timeDelta = runtimeScene.getTimeManager().getElapsedTime()/1000;
var timeDelta = this.owner.getElapsedTime(runtimeScene)/1000;
this._speed += this._acceleration*timeDelta;
if ( this._speed > this._maxSpeed ) this._speed = this._maxSpeed;
this._angularSpeed = this._angularMaxSpeed;
Expand Down
2 changes: 1 addition & 1 deletion Extensions/PlatformBehavior/PlatformerObjectBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void PlatformerObjectBehavior::DoStepPreEvents(RuntimeScene & scene)

if ( !sceneManager ) return;

double timeDelta = static_cast<double>(scene.GetTimeManager().GetElapsedTime()) / 1000000.0;
double timeDelta = static_cast<double>(object->GetElapsedTime(scene)) / 1000000.0;

//0.1) Get the player input:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ gdjs.PlatformerObjectRuntimeBehavior.prototype.doStepPreEvents = function(runtim
var SHIFTKEY = 16;
var SPACEKEY = 32;
var object = this.owner;
var timeDelta = runtimeScene.getTimeManager().getElapsedTime()/1000;
var timeDelta = this.owner.getElapsedTime(runtimeScene)/1000;

//0.1) Get the player input:
var requestedDeltaX = 0;
Expand Down
8 changes: 3 additions & 5 deletions Extensions/TextEntryObject/TextEntryObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,19 @@ TextEntryObject::TextEntryObject(gd::String name_) :
RuntimeTextEntryObject::RuntimeTextEntryObject(RuntimeScene & scene_, const TextEntryObject & textEntryObject) :
RuntimeObject(scene_, textEntryObject),
text(),
scene(&scene_),
activated(true)
{
}

/**
* \brief Used to update input
*/
void RuntimeTextEntryObject::UpdateTime(float)
void RuntimeTextEntryObject::Update(const RuntimeScene & scene)
{
if (!activated || scene == NULL) return;
if (!activated) return;

//Retrieve text entered
const auto & characters = scene->GetInputManager().GetCharactersEntered();
const auto & characters = scene.GetInputManager().GetCharactersEntered();
for (std::size_t i = 0;i<characters.size();++i)
{
//Skip some non displayable characters
Expand All @@ -64,7 +63,6 @@ void RuntimeTextEntryObject::UpdateTime(float)
}
else if (characters[i] == 8)
{
std::cout << "Backspace" << std::endl;
//Backspace : find the previous codepoint and remove it
if(text.empty())
continue;
Expand Down
3 changes: 1 addition & 2 deletions Extensions/TextEntryObject/TextEntryObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public :
virtual std::size_t GetNumberOfProperties() const;
#endif

virtual void UpdateTime(float);
virtual void Update(const RuntimeScene & scene);

inline void SetString(gd::String str) { text = str; };
const gd::String & GetString() const { return text; };
Expand All @@ -73,7 +73,6 @@ public :
private:

gd::String text;
const RuntimeScene * scene; ///< Pointer to the scene. Initialized during LoadRuntimeResources call.
bool activated;
};

Expand Down
2 changes: 1 addition & 1 deletion Extensions/TextEntryObject/textentryruntimeobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gdjs.TextEntryRuntimeObject.prototype.onDeletedFromScene = function(runtimeScene
}
};

gdjs.TextEntryRuntimeObject.prototype.updateTime = function(elapsedTime) {
gdjs.TextEntryRuntimeObject.prototype.update = function() {
if (this._renderer.getString) {
this._str = this._renderer.getString();
}
Expand Down
2 changes: 1 addition & 1 deletion Extensions/TextObject/textruntimeobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ gdjs.TextRuntimeObject.prototype.getRendererObject = function() {
return this._renderer.getRendererObject();
};

gdjs.TextRuntimeObject.prototype.updateTime = function() {
gdjs.TextRuntimeObject.prototype.update = function() {
this._renderer.ensureUpToDate();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void TopDownMovementBehavior::DoStepPreEvents(RuntimeScene & scene)
}

//Update the speed of the object
float timeDelta = static_cast<double>(scene.GetTimeManager().GetElapsedTime())/1000000.0;
float timeDelta = static_cast<double>(object->GetElapsedTime(scene))/1000000.0;
if (direction != -1)
{
directionInRad = static_cast<float>(direction)*gd::Pi()/4.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ gdjs.TopDownMovementRuntimeBehavior.prototype.doStepPreEvents = function(runtime
var DOWNKEY = 40;
var SHIFTKEY = 16;
var object = this.owner;
var timeDelta = runtimeScene.getTimeManager().getElapsedTime()/1000;
var timeDelta = this.owner.getElapsedTime(runtimeScene)/1000;

//Get the player input:
this._leftKey |= !this._ignoreDefaultControls && runtimeScene.getGame().getInputManager().isKeyPressed(LEFTKEY);
Expand Down
5 changes: 4 additions & 1 deletion GDCpp/GDCpp/Extensions/Builtin/CameraExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ CameraExtension::CameraExtension()

GetAllConditions()["LayerVisible"].SetFunctionName("LayerVisible").SetIncludeFile("GDCpp/Extensions/Builtin/RuntimeSceneTools.h");

GetAllConditions()["LayerTimeScale"].SetFunctionName("GetLayerTimeScale").SetIncludeFile("GDCpp/Extensions/Builtin/RuntimeSceneCameraTools.h");
GetAllActions()["ChangeLayerTimeScale"].SetFunctionName("SetLayerTimeScale").SetIncludeFile("GDCpp/Extensions/Builtin/RuntimeSceneCameraTools.h");
GetAllExpressions()["LayerTimeScale"].SetFunctionName("GetLayerTimeScale").SetIncludeFile("GDCpp/Extensions/Builtin/RuntimeSceneCameraTools.h");

GetAllExpressions()["CameraWidth"].SetFunctionName("GetCameraWidth").SetIncludeFile("GDCpp/Extensions/Builtin/RuntimeSceneCameraTools.h");
GetAllExpressions()["CameraHeight"].SetFunctionName("GetCameraHeight").SetIncludeFile("GDCpp/Extensions/Builtin/RuntimeSceneCameraTools.h");
GetAllExpressions()["CameraViewportLeft"].SetFunctionName("GetCameraViewportLeft").SetIncludeFile("GDCpp/Extensions/Builtin/RuntimeSceneCameraTools.h");
Expand All @@ -64,4 +68,3 @@ CameraExtension::CameraExtension()

#endif
}

14 changes: 12 additions & 2 deletions GDCpp/GDCpp/Extensions/Builtin/RuntimeSceneCameraTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void GD_API CenterCameraOnObjectWithLimits(RuntimeScene & scene, RuntimeObject *

float xOffset = 0;
float yOffset = 0;
double elapsedTime = static_cast<double>(scene.GetTimeManager().GetElapsedTime()) / 1000000.0;
double elapsedTime = static_cast<double>(object->GetElapsedTime(scene)) / 1000000.0;
if (anticipateObjectMove)
{
xOffset = object->TotalForceX() * elapsedTime;
Expand All @@ -166,7 +166,7 @@ void GD_API CenterCameraOnObject(RuntimeScene & scene, RuntimeObject * object,

float xOffset = 0;
float yOffset = 0;
double elapsedTime = static_cast<double>(scene.GetTimeManager().GetElapsedTime()) / 1000000.0;
double elapsedTime = static_cast<double>(object->GetElapsedTime(scene)) / 1000000.0;
if (anticipateObjectMove)
{
xOffset = object->TotalForceX() * elapsedTime;
Expand Down Expand Up @@ -221,3 +221,13 @@ void GD_API SetCameraViewport( RuntimeScene & scene, const gd::String & layer,
RuntimeCamera & camera = scene.GetRuntimeLayer(layer).GetCamera(cameraNb);
camera.SetViewport(viewportLeft, viewportTop, viewportRight, viewportBottom);
}

double GD_API GetLayerTimeScale(RuntimeScene & scene, const gd::String & layer)
{
return scene.GetRuntimeLayer(layer).GetTimeScale();
}

void GD_API SetLayerTimeScale(RuntimeScene & scene, const gd::String & layer, double timeScale)
{
scene.GetRuntimeLayer(layer).SetTimeScale(timeScale);
}
Loading

0 comments on commit 40fcb66

Please sign in to comment.