Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lighting #1881

Merged
merged 57 commits into from Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5680ea6
Initial commits
HarsimranVirk May 22, 2020
5f5becd
Added hard coded mesh
HarsimranVirk Jun 1, 2020
2dcdf58
Added instance renderer and radius property
HarsimranVirk Jun 6, 2020
e862a33
Added color property
HarsimranVirk Jun 7, 2020
b2bb6dd
added obstacles manager
HarsimranVirk Jun 10, 2020
1964b5d
raycasting
HarsimranVirk Jun 15, 2020
7d8bfe4
Center of light is now the x and y of object. Fixed in both, runtime …
HarsimranVirk Jun 17, 2020
2d3db00
Working algorithm for raycasting.
HarsimranVirk Jun 17, 2020
8b6b163
Fixed the rendering issue, added debug mode.
HarsimranVirk Jun 18, 2020
5d0e661
fixed index buffers
HarsimranVirk Jun 18, 2020
ca85bd5
Replaced flat() with reduce() and concat()
HarsimranVirk Jun 18, 2020
fa41a19
Replaced map, reduce, and filter with for loops
HarsimranVirk Jun 19, 2020
29aeeef
Used setType('color') for color property of light
HarsimranVirk Jun 19, 2020
12572d0
Reduced allocation of vertex and index buffers.
HarsimranVirk Jun 19, 2020
66eb544
Renamed variables
HarsimranVirk Jun 19, 2020
ee3e226
Absolute minimum for render texture
HarsimranVirk Jun 26, 2020
94dcbfa
Working ambient light
HarsimranVirk Jul 2, 2020
92edbf4
Fixed issues with moving layers.
HarsimranVirk Jul 3, 2020
a046139
Added logic to bypass raycasting if there's no obstacle around. Moved…
HarsimranVirk Jul 4, 2020
1cd73fd
Added feature for having textured lights. Renamed expensive functions…
HarsimranVirk Jul 7, 2020
55f157d
Added UI for lighting layer
HarsimranVirk Jul 11, 2020
4dcafbc
Added lighting functionalities in gd::Layer.
HarsimranVirk Jul 11, 2020
4d64f6b
Fixed type errors
HarsimranVirk Jul 14, 2020
f9fcab8
Added a way to define additional logic which executes after an object…
HarsimranVirk Jul 15, 2020
369ad6f
Format fix
HarsimranVirk Jul 15, 2020
58c40c5
Format fix
HarsimranVirk Jul 15, 2020
c336c5f
Renamed variables and functions of Layer.
HarsimranVirk Jul 17, 2020
11b6211
Added ObjectsAdditionalService to handle objects and instances.
HarsimranVirk Jul 17, 2020
915a046
Reworked ObjectsAdditionalWork, removed dependency of light object fr…
HarsimranVirk Jul 18, 2020
9b9a387
Made LightingLayerDialog consistent in LayersList to fix warnings rel…
HarsimranVirk Jul 18, 2020
e234dd8
Fixed filters and removed console logs
HarsimranVirk Jul 18, 2020
b93d3b5
Fixing gdjs build errors
HarsimranVirk Jul 18, 2020
d2e4983
Added a button for lighting layer in LayersList
HarsimranVirk Jul 20, 2020
9377840
* Added button for lighting layer
HarsimranVirk Jul 20, 2020
abef037
Fixed errors related to texture of lights, changed image for light ob…
HarsimranVirk Jul 20, 2020
67d5dcf
Added the fix for renderTexture issue. Changed the forceUpdateLayersL…
HarsimranVirk Jul 22, 2020
aa76b67
Fixed potentional errors due to radius being 0. Changed hasLightingin…
HarsimranVirk Jul 22, 2020
dd05fcb
Changes in documentation. Changed updateTime() to update() for pixi a…
HarsimranVirk Jul 24, 2020
34a566a
Made changes in IDE, JsExtension and runtimeScene-pixi-renderer accor…
HarsimranVirk Jul 25, 2020
1dccf32
Merge branch 'master' of https://github.com/4ian/GDevelop into lights…
HarsimranVirk Jul 25, 2020
fcf2931
Fixed blend mode for filters on lighting layer.
HarsimranVirk Jul 25, 2020
acbaa9c
Merge branch 'master' of https://github.com/4ian/GDevelop into lights…
HarsimranVirk Jul 26, 2020
5ed3ec1
Changes for RuntimeScenePixiRenderer.setLayerIndex()
HarsimranVirk Jul 26, 2020
9508828
Changes to documentation and add layer button
HarsimranVirk Jul 29, 2020
0ef96b1
Merge branch 'master' of https://github.com/4ian/GDevelop into lights…
HarsimranVirk Jul 30, 2020
fd4d10d
Fixed debug mode bug, added a small test
HarsimranVirk Aug 1, 2020
127324b
Quick fixes
HarsimranVirk Aug 2, 2020
90f15aa
Added tests for raycasting
HarsimranVirk Aug 4, 2020
bee7426
Test moved from GDJS/tests to Extensions/Lighting/tests.
HarsimranVirk Aug 6, 2020
bd4ac8d
Added actions to set color and radius.
HarsimranVirk Aug 7, 2020
f5027b7
Refactored the pixi renderer to support hot-reloading
HarsimranVirk Aug 7, 2020
f167a6a
formatting
HarsimranVirk Aug 7, 2020
3626425
Fixed debug mode and added support for it with hot-reloading.
HarsimranVirk Aug 8, 2020
1c7f506
Added support to lighting layer for hot-reloading.
HarsimranVirk Aug 12, 2020
fafa0c5
Merge branch 'master' of https://github.com/4ian/GDevelop into lights…
HarsimranVirk Aug 12, 2020
d56623b
Fixed check-types errors
HarsimranVirk Aug 12, 2020
5b3ffce
Added onDestroy, onActivate and onDeActivate methods on LightObstacle…
HarsimranVirk Aug 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion Core/GDCore/Project/Layer.cpp
Expand Up @@ -13,7 +13,7 @@ namespace gd {
Camera Layer::badCamera;
Effect Layer::badEffect;

Layer::Layer() : isVisible(true) {}
Layer::Layer() : isVisible(true), isLightingLayer(false), followBaseLayerCamera(false) {}

/**
* Change cameras count, automatically adding/removing them.
Expand All @@ -29,6 +29,11 @@ void Layer::SetCameraCount(std::size_t n) {
void Layer::SerializeTo(SerializerElement& element) const {
element.SetAttribute("name", GetName());
element.SetAttribute("visibility", GetVisibility());
element.SetAttribute("isLightingLayer", IsLightingLayer());
element.SetAttribute("followBaseLayerCamera", IsFollowingBaseLayerCamera());
element.SetAttribute("ambientLightColorR", (int)GetAmbientLightColorRed());
element.SetAttribute("ambientLightColorG", (int)GetAmbientLightColorGreen());
element.SetAttribute("ambientLightColorB", (int)GetAmbientLightColorBlue());

SerializerElement& camerasElement = element.AddChild("cameras");
camerasElement.ConsiderAsArrayOf("camera");
Expand Down Expand Up @@ -61,6 +66,11 @@ void Layer::SerializeTo(SerializerElement& element) const {
void Layer::UnserializeFrom(const SerializerElement& element) {
SetName(element.GetStringAttribute("name", "", "Name"));
SetVisibility(element.GetBoolAttribute("visibility", true, "Visibility"));
SetLightingLayer(element.GetBoolAttribute("isLightingLayer", false));
SetFollowBaseLayerCamera(element.GetBoolAttribute("followBaseLayerCamera", false));
SetAmbientLightColor(element.GetIntAttribute("ambientLightColorR", 128),
element.GetIntAttribute("ambientLightColorG", 128),
element.GetIntAttribute("ambientLightColorB", 128));

// Compatibility with GD <= 3.3
if (element.HasChild("Camera")) {
Expand Down
49 changes: 49 additions & 0 deletions Core/GDCore/Project/Layer.h
Expand Up @@ -51,6 +51,26 @@ class GD_CORE_API Layer {
*/
bool GetVisibility() const { return isVisible; }

/**
* \brief Set if the layer is a lightining layer or not.
*/
void SetLightingLayer(bool isLightingLayer_) { isLightingLayer = isLightingLayer_; }

/**
* \brief Return true if the layer is a lighting layer.
*/
bool IsLightingLayer() const { return isLightingLayer; }

/**
* \brief Set if the layer automatically follows the base layer or not.
*/
void SetFollowBaseLayerCamera(bool followBaseLayerCamera_) { followBaseLayerCamera = followBaseLayerCamera_; }

/**
* \brief Return true if the layer follows the base layer.
*/
bool IsFollowingBaseLayerCamera() const { return followBaseLayerCamera; }

/** \name Cameras
*/
///@{
Expand Down Expand Up @@ -96,6 +116,30 @@ class GD_CORE_API Layer {

///@}

/**
* Get the ambient light color red component.
*/
unsigned int GetAmbientLightColorRed() const { return ambientLightColorR; }

/**
* Get the ambient light color green component.
*/
unsigned int GetAmbientLightColorGreen() const { return ambientLightColorG; }

/**
* Get the ambient light color blue component.
*/
unsigned int GetAmbientLightColorBlue() const { return ambientLightColorB; }

/**
* Set the ambient light color.
*/
void SetAmbientLightColor(unsigned int r, unsigned int g, unsigned int b) {
ambientLightColorR = r;
ambientLightColorG = g;
ambientLightColorB = b;
}

/** \name Effects
*/
///@{
Expand Down Expand Up @@ -177,6 +221,11 @@ class GD_CORE_API Layer {
private:
gd::String name; ///< The name of the layer
bool isVisible; ///< True if the layer is visible
bool isLightingLayer; ///< True if the layer is used to display lights and renders an ambient light.
bool followBaseLayerCamera; ///< True if the layer automatically follows the base layer
unsigned int ambientLightColorR; ///< Ambient light color Red component
unsigned int ambientLightColorG; ///< Ambient light color Green component
unsigned int ambientLightColorB; ///< Ambient light color Blue component
std::vector<gd::Camera> cameras; ///< The camera displayed by the layer
std::vector<std::shared_ptr<gd::Effect>>
effects; ///< The effects applied to the layer.
Expand Down
287 changes: 158 additions & 129 deletions Extensions/DraggableBehavior/tests/draggableruntimeautomatism.spec.js
@@ -1,131 +1,160 @@
// @ts-check
describe('gdjs.DraggableRuntimeBehavior', function() {
var runtimeGame = new gdjs.RuntimeGame({
variables: [],
resources: {resources: []},
// @ts-ignore
properties: {windowWidth: 800, windowHeight: 600}
});
var runtimeScene = new gdjs.RuntimeScene(runtimeGame);
runtimeScene.loadFromScene({
layers:[{name:"", visibility: true, cameras: [], effects: []}],
variables: [],
r: 0,
v: 0,
b: 0,
mangledName: 'Scene1',
name: 'Scene1',
stopSoundsOnStartup: false,
title: '',
behaviorsSharedData: [],
objects: [],
instances: []
});

var object = new gdjs.RuntimeObject(runtimeScene, {name: "obj1", type: "", behaviors: [{name: "Behavior1", type: "DraggableBehavior::Draggable"}], variables: []});
var object2 = new gdjs.RuntimeObject(runtimeScene, {name: "obj1", type: "", behaviors: [{name: "Behavior1", type: "DraggableBehavior::Draggable"}], variables: []});
runtimeScene.addObject(object);
runtimeScene.addObject(object2);

it('should handle mouse', function() {
object.setPosition(450, 500);

//Drag'n'drop
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onMouseMove(450, 500);
runtimeGame.getInputManager().onMouseButtonPressed(gdjs.InputManager.MOUSE_LEFT_BUTTON);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onMouseMove(750, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onMouseButtonReleased(gdjs.InputManager.MOUSE_LEFT_BUTTON);
runtimeScene.renderAndStep();

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(600);

//Mouse move with dragging
runtimeGame.getInputManager().onMouseMove(600, 600);
runtimeScene.renderAndStep();

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(600);

//Start dragging again
runtimeGame.getInputManager().onMouseMove(750, 600);
runtimeGame.getInputManager().onMouseButtonPressed(gdjs.InputManager.MOUSE_LEFT_BUTTON);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onMouseMove(850, 700);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onMouseButtonReleased(gdjs.InputManager.MOUSE_LEFT_BUTTON);
runtimeScene.renderAndStep();

expect(object.getX()).to.be(850);
expect(object.getY()).to.be(700);

});
it('should handle touches', function() {
runtimeGame.getInputManager().touchSimulateMouse(false);
object.setPosition(450, 500);

//Drag'n'drop
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchStart(1, 10, 20);
runtimeGame.getInputManager().onTouchStart(0, 450, 500);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchMove(0, 750, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchEnd(0);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(600);

//Move another unrelated touch
runtimeGame.getInputManager().onTouchMove(1, 750, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchMove(1, 850, 700);
runtimeScene.renderAndStep();

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(600);

//Start drag'n'drop with another touch
runtimeGame.getInputManager().onTouchEnd(1);
runtimeGame.getInputManager().onFrameEnded();
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchStart(1, 750, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchMove(1, 850, 700);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchEnd(1);
runtimeGame.getInputManager().onFrameEnded();

expect(object.getX()).to.be(850);
expect(object.getY()).to.be(700);
});
it('should handle multitouch', function() {
runtimeGame.getInputManager().touchSimulateMouse(false);
object.setPosition(450, 500);
object2.setPosition(650, 600);

//Drag'n'drop
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchStart(2, 450, 500);
runtimeGame.getInputManager().onTouchStart(1, 650, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchMove(2, 750, 700);
runtimeGame.getInputManager().onTouchMove(1, 100, 200);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchEnd(2);

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(700);
expect(object2.getX()).to.be(100);
expect(object2.getY()).to.be(200);
});
describe('gdjs.DraggableRuntimeBehavior', function () {
var runtimeGame = new gdjs.RuntimeGame({
variables: [],
resources: { resources: [] },
// @ts-ignore
properties: { windowWidth: 800, windowHeight: 600 },
});
var runtimeScene = new gdjs.RuntimeScene(runtimeGame);
runtimeScene.loadFromScene({
layers: [
{
name: '',
visibility: true,
cameras: [],
effects: [],
ambientLightColorR: 127,
ambientLightColorB: 127,
ambientLightColorG: 127,
isLightingLayer: false,
followBaseLayerCamera: false,
},
],
variables: [],
r: 0,
v: 0,
b: 0,
mangledName: 'Scene1',
name: 'Scene1',
stopSoundsOnStartup: false,
title: '',
behaviorsSharedData: [],
objects: [],
instances: [],
});

var object = new gdjs.RuntimeObject(runtimeScene, {
name: 'obj1',
type: '',
behaviors: [{ name: 'Behavior1', type: 'DraggableBehavior::Draggable' }],
variables: [],
});
var object2 = new gdjs.RuntimeObject(runtimeScene, {
name: 'obj1',
type: '',
behaviors: [{ name: 'Behavior1', type: 'DraggableBehavior::Draggable' }],
variables: [],
});
runtimeScene.addObject(object);
runtimeScene.addObject(object2);

it('should handle mouse', function () {
object.setPosition(450, 500);

//Drag'n'drop
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onMouseMove(450, 500);
runtimeGame
.getInputManager()
.onMouseButtonPressed(gdjs.InputManager.MOUSE_LEFT_BUTTON);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onMouseMove(750, 600);
runtimeScene.renderAndStep();
runtimeGame
.getInputManager()
.onMouseButtonReleased(gdjs.InputManager.MOUSE_LEFT_BUTTON);
runtimeScene.renderAndStep();

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(600);

//Mouse move with dragging
runtimeGame.getInputManager().onMouseMove(600, 600);
runtimeScene.renderAndStep();

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(600);

//Start dragging again
runtimeGame.getInputManager().onMouseMove(750, 600);
runtimeGame
.getInputManager()
.onMouseButtonPressed(gdjs.InputManager.MOUSE_LEFT_BUTTON);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onMouseMove(850, 700);
runtimeScene.renderAndStep();
runtimeGame
.getInputManager()
.onMouseButtonReleased(gdjs.InputManager.MOUSE_LEFT_BUTTON);
runtimeScene.renderAndStep();

expect(object.getX()).to.be(850);
expect(object.getY()).to.be(700);
});
it('should handle touches', function () {
runtimeGame.getInputManager().touchSimulateMouse(false);
object.setPosition(450, 500);

//Drag'n'drop
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchStart(1, 10, 20);
runtimeGame.getInputManager().onTouchStart(0, 450, 500);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchMove(0, 750, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchEnd(0);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(600);

//Move another unrelated touch
runtimeGame.getInputManager().onTouchMove(1, 750, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchMove(1, 850, 700);
runtimeScene.renderAndStep();

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(600);

//Start drag'n'drop with another touch
runtimeGame.getInputManager().onTouchEnd(1);
runtimeGame.getInputManager().onFrameEnded();
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchStart(1, 750, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchMove(1, 850, 700);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchEnd(1);
runtimeGame.getInputManager().onFrameEnded();

expect(object.getX()).to.be(850);
expect(object.getY()).to.be(700);
});
it('should handle multitouch', function () {
runtimeGame.getInputManager().touchSimulateMouse(false);
object.setPosition(450, 500);
object2.setPosition(650, 600);

//Drag'n'drop
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onTouchStart(2, 450, 500);
runtimeGame.getInputManager().onTouchStart(1, 650, 600);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchMove(2, 750, 700);
runtimeGame.getInputManager().onTouchMove(1, 100, 200);
runtimeScene.renderAndStep();
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchEnd(2);

expect(object.getX()).to.be(750);
expect(object.getY()).to.be(700);
expect(object2.getX()).to.be(100);
expect(object2.getY()).to.be(200);
});
});