Various improvements:

Framebuffer resize queued to next frame to fix flickering
Wren VM init moved to on play event
Added new Wren modules
Added missing components to the editor
Changed how the wren scripts gets initialized
This commit is contained in:
Antoine Pilote
2021-06-12 13:01:07 -04:00
parent 855bb1edd6
commit cdfee1981c
25 changed files with 451 additions and 108 deletions

View File

@@ -3,6 +3,52 @@ class Math {
}
class Vector3 {
x {_x}
y {_y}
z {_z}
x=(value) {
_x = value
}
y=(value) {
_y = value
}
z=(value) {
_z = value
}
mul(other) {
if(other is Vector3) {
return Vector3.new(_x * other.x,
_y * other.y,
_z * other.z)
} else {
return Vector3.new(_x * other, _y * other, _z * other)
}
}
*(other) {
if(other is Vector3) {
return Vector3.new(_x * other.x,
_y * other.y,
_z * other.z)
} else if(other is Num) {
return Vector3.new(_x * other, _y * other, _z * other)
}
}
+(other) {
if(other is Vector3) {
return Vector3.new(_x + other.x,
_y + other.y,
_z + other.z)
} else if(other is Num) {
return Vector3.new(_x + other,
_y + other,
_z + other)
}
}
construct new(x, y, z) {
_x = x
_y = y

View File

@@ -1,4 +1,5 @@
import "Scripts/Engine" for Engine
import "Scripts/Math" for Vector3
class Scene {
foreign static GetEntityID(name)
@@ -11,35 +12,50 @@ class Scene {
}
foreign static EntityHasComponent(id, name)
static EntityGetComponent(id, component) {
if(this.EntityHasComponent(id, component) == false) {
Engine.Log("Tried getting a non-existent component of type: %(component) on entity with id: %(id)")
return
}
// Component specific private setter and getter.
foreign static GetLightIntensity_(e)
foreign static SetLightIntensity_(e, intensity)
if (component == "Light") {
return Light.new(id)
} else if (component == "CharacterController") {
return CharacterController.new(id)
} else if (component == "Camera") {
return Camera.new(id)
}
}
/*
// Transform
foreign static SetTranslation_(e, x, y, z)
foreign static SetRotation_(e, x, y, z)
foreign static SetScale_(e, x, y, z)
// Character controller
foreign static SetVelocity(e, x, y, z)
foreign static SetStepHeight(e, x, y, z)
foreign static IsOnGround(e)
*/
// Light
//
// Components
//
/*
foreign static SetLightIsVolumetric_(e, bool)
foreign static SetLightSyncDirectionWithSky_(e, bool)
foreign static SetLightColor_(e, r, g, b)
// Transform
//foreign static SetTranslation_(e, x, y, z)
//foreign static SetRotation_(e, x, y, z)
//foreign static SetScale_(e, x, y, z)
// Light
foreign static GetLightIntensity_(e) // returns a float
foreign static SetLightIntensity_(e, intensity)
//foreign static SetLightIsVolumetric_(e, bool)
//foreign static SetLightSyncDirectionWithSky_(e, bool)
//foreign static SetLightColor_(e, r, g, b)
//foreign static GetLightColor_(e)
// Camera
foreign static SetCameraFov_(e, fov)
foreign static SetCameraType(e, type)
foreign static SetCameraDirection_(e, x, y, z)
*/
foreign static GetCameraDirection_(e) // returns a list x,y,z
foreign static GetCameraRight_(e) // returns a list x,y,z
//foreign static SetcameraFov(e, fov)
//foreign static GetCameraFov(e) // returns a float
// Character controller
foreign static MoveAndSlide_(e, x, y, z)
//foreign static IsOnGround_(e)
}
class Entity {
@@ -52,14 +68,7 @@ class Entity {
}
GetComponent(component) {
if(this.HasComponent(component) == false) {
Engine.Log("Tried getting a non-existent component of type: %(component) on entity with id: %(_entityId)")
return
}
if (component == "Light") {
return Light.new(_entityId)
}
return Scene.EntityGetComponent(_entityId, component)
}
// Foreign engine functions
@@ -110,17 +119,37 @@ class Light {
SetColor(color) {
this.SetColor_(_entityId, color.r, color.g, color.b, color.a)
}*/
}
class CharacterController {
construct new(id) {
_entityId = id
}
SetDirection(direction) {
var normalized = direction.Normalize()
this.SetDirection_(_entityId, normalized.x, normalized.y, normalized.z)
MoveAndSlide(vel) {
Scene.MoveAndSlide_(_entityId, vel.x, vel.y, vel.z)
}
foreign static SetType_(id, type)
foreign static SetColor_(id, r, g, b)
foreign static SetDirection_(id, x, y, z)
*/
}
}
class Camera {
construct new(id) {
_entityId = id
}
SetDirection(dir) {
Scene.SetCameraDirection_(_entityId, dir.x, dir.y, dir.z)
}
GetDirection() {
var dir = Scene.GetCameraDirection_(_entityId)
return Vector3.new(dir[0], dir[1], dir[2])
}
GetRight() {
var dir = Scene.GetCameraRight_(_entityId)
return Vector3.new(dir[0], dir[1], dir[2])
}
}

View File

@@ -0,0 +1,15 @@
import "Scripts/Scene" for Scene
class ScriptableEntity {
SetEntityId(id) {
_EntityID = id
}
GetComponent(component) {
return Scene.EntityGetComponent(_EntityID, component)
}
HasComponent(component) {
return Scene.EntityHasComponent(_EntityID, component)
}
}