Merge branch 'main' of https://github.com/antopilo/Nuake into main

This commit is contained in:
unknown
2021-06-19 13:19:12 -04:00
125 changed files with 1932 additions and 16952 deletions

View File

@@ -2,12 +2,12 @@
#include <src/Scene/Entities/Entity.h>
#include <src/Scene/Scene.h>
#include <src/Scene/Entities/Components/QuakeMap.h>
#include <src/Scene/Components/QuakeMap.h>
#include <src/Vendors/imgui/imgui.h>
#include <src/Vendors/imgui/ImGuizmo.h>
#include <src/Scene/Entities/Components.h>
#include <src/Scene/Components/Components.h>
#include <src/Core/Physics/PhysicsManager.h>
#include "../Scene/Entities/Components/BoxCollider.h"
#include "../Scene/Components/BoxCollider.h"
#include "src/EditorInterface.h"
#include "../Core/Input.h"
#include <GLFW/glfw3.h>

View File

@@ -1,13 +1,7 @@
.hello{
width: 400px;
height: 200px;
}
.screen{
height: 100%;
width: 100%;
display: flex;
justify-content: center;
flex-direction: row;
align-content:flex-start;
@@ -16,5 +10,4 @@
.rect{
height: 200px;
width: 200px;
}

View File

@@ -1,12 +1,11 @@
<Canvas
script="Scripts/test Test"
stylesheet="Interface/Testing.css"
groups="screen"
color="25 25 25 9"
>
<p groups="header">Hello, world!</p>
<Rect onclick="hello()"
groups="rect"
color="128 128 255 255">
groups="rect">
</Rect>
</Canvas>

View File

@@ -1,20 +1,25 @@
{
"Entities": [
{
"CameraComponent": {
"CameraInstance": {
"AspectRatio": 1.774647831916809,
"Exposure": 1.0,
"Fov": 88.0,
"Speed": 1.0,
"m_Type": 1
}
},
"NameComponent": {
"Name": "Trenchbroom map"
"Name": "Camera"
},
"ParentComponent": {
"HasParent": false
},
"QuakeMapComponent": {
"HasCollisions": false,
"Path": "C:\\Dev\\Nuake\\Editor\\resources\\Maps\\texture_test.map"
},
"TransformComponent": {
"Rotation": {
"x": 0.0,
"y": 0.0,
"y": -0.0,
"z": 0.0
},
"Scale": {
@@ -23,11 +28,15 @@
"z": 1.0
},
"Translation": {
"x": 9.199999809265137,
"y": 5.599999904632568,
"z": 0.0
"x": -25.119064331054688,
"y": 19.491336822509766,
"z": 4.5285515785217285
},
"Type": "TransformComponent"
},
"WrenScriptComponent": {
"Class": "CamScript",
"Script": "Scripts/Cam.wren"
}
},
{
@@ -66,11 +75,80 @@
"z": 1.0
},
"Translation": {
"x": 7.035792350769043,
"y": 5.795107364654541,
"z": -0.9431453943252563
"x": -359.2229919433594,
"y": -1.979316234588623,
"z": -322.51702880859375
},
"Type": "TransformComponent"
},
"WrenScriptComponent": {
"Class": "TestScript",
"Script": "Scripts/entityScript.wren"
}
},
{
"NameComponent": {
"Name": "Trenchbroom map"
},
"ParentComponent": {
"HasParent": false
},
"QuakeMapComponent": {
"HasCollisions": true,
"Path": "C:\\Dev\\Nuake\\Editor\\resources\\Maps\\texture_test.map"
},
"TransformComponent": {
"Rotation": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"Scale": {
"x": 1.0,
"y": 1.0,
"z": 1.0
},
"Translation": {
"x": 9.199999809265137,
"y": 5.599999904632568,
"z": 0.0
},
"Type": "TransformComponent"
}
},
{
"CharacterControllerComponent": {
"Height": 1.2000000476837158,
"Mass": 2500.0,
"Radius": 0.20000000298023224
},
"NameComponent": {
"Name": "Player"
},
"ParentComponent": {
"HasParent": false
},
"TransformComponent": {
"Rotation": {
"x": 0.0,
"y": -0.0,
"z": 0.0
},
"Scale": {
"x": 1.0,
"y": 1.0,
"z": 1.0
},
"Translation": {
"x": -25.119064331054688,
"y": 18.649978637695313,
"z": 4.5285515785217285
},
"Type": "TransformComponent"
},
"WrenScriptComponent": {
"Class": "PlayerScript",
"Script": "Scripts/Player.wren"
}
}
],
@@ -78,7 +156,7 @@
"m_Environement": {
"AmbientColor": {
"w": 0.0,
"x": null,
"x": 0.0,
"y": 0.0,
"z": 0.0
},

View File

@@ -0,0 +1,78 @@
import "Scripts/ScriptableEntity" for ScriptableEntity
import "Scripts/Engine" for Engine
import "Scripts/Scene" for Scene
import "Scripts/Math" for Vector3, Math
import "Scripts/Input" for Input
class CamScript is ScriptableEntity {
construct new() {
_Pitch = 0
_Yaw = 0
_mouseLastX = 0
_mouseLastY = 0
_BobHeight = 0.1
_BobSpeed = 5.0
_CamHeight = 0.5
_deltaTime = 0
Input.HideMouse()
}
init() {}
update(ts) {
_deltaTime = _deltaTime + ts
var x = Input.GetMouseX()
var y = Input.GetMouseY()
var diffx = x - _mouseLastX
var diffy = _mouseLastY - y
_mouseLastX = x
_mouseLastY = y
var sens = 0.1
diffx = diffx * sens
diffy = diffy * sens
_Yaw = _Yaw + diffx
_Pitch = _Pitch + diffy
if(_Pitch > 89) _Pitch = 89
if(_Pitch < -89) _Pitch = -89
var cam = this.GetComponent("Camera")
var rad_yaw = Math.Radians(_Yaw)
var rad_pitch = Math.Radians(_Pitch)
var camX = Math.Cos(rad_yaw) * Math.Cos(rad_pitch)
var camY = Math.Sin(rad_pitch)
var camZ = Math.Sin(rad_yaw) * Math.Cos(rad_pitch)
var newDir = Vector3.new(camX, camY, camZ)
var player = Scene.GetEntity("Player")
var playerScript = player.GetComponent("Script")
var velocity = playerScript.Velocity.Duplicate()
velocity.y = 0 // Dont count gravity in bob.
velocity = velocity.Sqrt()
var amount = (Math.Sin(_deltaTime * (velocity * 0.01)) / 2 + 1) * _BobHeight
Engine.Log("BobAmount: %(amount)")
var pTransform = player.GetComponent("Transform")
var pPos = pTransform.GetTranslation()
if(amount < 1 && amount > -1) amount = 0
var transform = this.GetComponent("Transform")
var newPos = Vector3.new(pPos.x, pPos.y + _CamHeight + amount , pPos.z)
transform.SetTranslation(newPos)
cam.SetDirection(newDir)
}
exit() {}
}

View File

@@ -1,5 +1,16 @@
class Math {
foreign static Sqrt_(x, y, z)
foreign static Sin(s)
foreign static Cos(s)
foreign static Radians(s)
foreign static Degrees(s)
static Cross(vec1, vec2) {
var result = this.Cross_(vec1.x, vec1.y, vec1.z, vec2.x, vec2.y, vec2.z)
return Vector3.new(result[0], result[1], result[2])
}
foreign static Cross_(x, y, z, x1, y2, z2)
}
class Vector3 {
@@ -7,6 +18,7 @@ class Vector3 {
x {_x}
y {_y}
z {_z}
x=(value) {
_x = value
}
@@ -37,6 +49,16 @@ class Vector3 {
}
}
/(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,
@@ -49,16 +71,36 @@ class Vector3 {
}
}
-(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
_z = z
}
Duplicate() {
return Vector3.new(_x, _y, _z)
}
Sqrt() {
return Math.Sqrt_(_x, _y, _z)
}
Cross(vec) {
Math.Cross(this, vec)
}
Normalize() {
var length = this.Sqrt()
var x = _x / length
@@ -66,4 +108,12 @@ class Vector3 {
var z = _z / length
return Vector3.new(x, y, z)
}
Angle(vec) {
this.Normalize() * vec.Normalize()
}
Length() {
this.Sqrt()
}
}

View File

@@ -0,0 +1,28 @@
import "Scripts/Math" for Vector3
class CollisionResult {
LocalPosition { _Local}
WorldPosition { _World}
Normal { _Normal}
construct new(l, w, n) {
_Local = l
_World = w
_Normal = n
}
}
class Physics {
foreign static Raycast_(x, y, z, x2, y2, z2)
static Raycast(v1, v2) {
var result = this.Raycast_(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z)
var local = Vector3.new(result[0], result[1], result[2])
var world = Vector3.new(result[3], result[4], result[5])
var normal = Vector3.new(result[6], result[7], result[8])
return CollisionResult.new(local, world, normal)
}
}

View File

@@ -0,0 +1,104 @@
import "Scripts/ScriptableEntity" for ScriptableEntity
import "Scripts/Engine" for Engine
import "Scripts/Scene" for Scene
import "Scripts/Math" for Vector3
import "Scripts/Input" for Input
import "Scripts/Physics" for Physics, CollisionResult
class PlayerScript is ScriptableEntity {
Velocity {_Velocity}
construct new() {
_InputDir = Vector3.new(0, 0, 0)
_Velocity = Vector3.new(0, 0, 0)
_Accel = 25
_Deccel = 0.92
_AirDeccel = 0.7
_Gravity = 10
_MaxSpeed = 20
_Jump = 200
//Input.HideMouse()
}
init() {
Engine.Log("Player init")
}
fixedUpdate(ts) {
this.CheckInput()
var camEntity = Scene.GetEntity("Camera")
var cam = camEntity.GetComponent("Camera")
var dir = cam.GetDirection()
dir.y = 0
dir = dir.Normalize()
var right = cam.GetRight()
right.y = 0
right = right.Normalize()
var move = _InputDir
var new_Velocity = (dir * move.z) + (right * move.x)
var controller = this.GetComponent("CharacterController")
var transform = this.GetComponent("Transform")
var from = transform.GetTranslation()
var to = from - Vector3.new(0, 1, 0)
var normal = Physics.Raycast(from, to).Normal
if(!controller.IsOnGround()) {
_Velocity.y = _Velocity.y -_Gravity
//_Velocity.x = _Velocity.x * _AirDeccel
//_Velocity.z = _Velocity.z * _AirDeccel
} else {
_Velocity.y = -10
Engine.Log("Grav: %(_Velocity.y)")
if(Input.IsKeyPressed(32)) _Velocity.y = _Jump
_Velocity.x = _Velocity.x + new_Velocity.x * _Accel
_Velocity.z = _Velocity.z + new_Velocity.z * _Accel
_Velocity.x = _Velocity.x * _Deccel
_Velocity.z = _Velocity.z * _Deccel
}
Engine.Log("Grav: %(_Velocity.y)")
controller.MoveAndSlide(_Velocity * ts)
}
CheckInput() {
/*
87 = W
65 = A
83 = S
68 = D
32 = SPACE
*/
if(Input.IsKeyDown(87)) {
_InputDir.z = 1
} else if(Input.IsKeyDown(83)) {
_InputDir.z = -1
} else {
_InputDir.z = 0
}
if(Input.IsKeyDown(65)) {
_InputDir.x = 1
} else if(Input.IsKeyDown(68)) {
_InputDir.x = -1
} else {
_InputDir.x = 0
}
}
exit() {
Engine.Log("Player exit")
}
}

View File

@@ -24,7 +24,11 @@ class Scene {
return CharacterController.new(id)
} else if (component == "Camera") {
return Camera.new(id)
}
} else if (component == "Transform") {
return TransformComponent.new(id)
} else if (component == "Script") {
return this.GetScript_(id)
}
}
@@ -32,7 +36,10 @@ class Scene {
// Components
//
// Transform
//foreign static SetTranslation_(e, x, y, z)
foreign static GetScript_(e)
foreign static GetTranslation_(e)
foreign static SetTranslation_(e, x, y, z)
//foreign static SetRotation_(e, x, y, z)
//foreign static SetScale_(e, x, y, z)
@@ -53,6 +60,7 @@ class Scene {
// Character controller
foreign static MoveAndSlide_(e, x, y, z)
foreign static IsCharacterControllerOnGround_(e)
//foreign static IsOnGround_(e)
@@ -97,6 +105,22 @@ class Entity {
*/
}
class TransformComponent {
construct new(id) {
_entityId = id
}
GetTranslation() {
var result = Scene.GetTranslation_(_entityId)
return Vector3.new(result[0], result[1], result[2])
}
SetTranslation(t) {
Scene.SetTranslation_(_entityId, t.x, t.y, t.z)
}
}
class Light {
construct new(id) {
_entityId = id
@@ -131,6 +155,10 @@ class CharacterController {
MoveAndSlide(vel) {
Scene.MoveAndSlide_(_entityId, vel.x, vel.y, vel.z)
}
IsOnGround() {
return Scene.IsCharacterControllerOnGround_(_entityId)
}
}
class Camera {

View File

@@ -0,0 +1,23 @@
import "Scripts/Engine" for Engine
import "Scripts/ScriptableEntity" for ScriptableEntity
class TestScript is ScriptableEntity {
construct new() {
_deltaTime = 0
}
init() {
Engine.Log("Hello init")
}
update(ts) {
_deltaTime = _deltaTime + ts
}
exit() {
Engine.Log("Hello exit")
}
}

View File

@@ -1,27 +1,23 @@
import "Scripts/Engine" for Engine
import "Scripts/Input" for Input
import "Scripts/Scene" for Scene, Entity
class Test {
construct new() {}
init() {
System.print("hello init")
}
update(t) {
System.print("hello update %(t)")
}
exit() {
System.print("hello exit ")
}
// Gets called on the click event.
static hello() {
// Get the entity named Light
var entity = Scene.GetEntity("Light")
var light = entity.GetComponent("Light")
light.SetIntensity(1.0)
if(Input.IsMouseButtonPressed(2) == true) {
Engine.Log("RIGHT CLICK!!!!!!")
}
// Get the component light
var light = entity.GetComponent("Light")
//light.SetIntensity(222.0) // Change intensity
var currentIntensity = light.GetIntensity() // Get new intensity
Engine.Log("Current intensity %(currentIntensity)")
}
}
}

View File

@@ -1 +1 @@
{"Description":"","Name":"", "DefaultScene":"Scenes/test.scene"}
{"DefaultScene":"Scenes/test.scene","Description":"","Name":""}

View File

@@ -3,9 +3,9 @@
#include <src/Vendors/imgui/ImGuizmo.h>
#include <src/Rendering/Textures/Texture.h>
#include <Engine.h>
#include <src/Scene/Entities/Components/LightComponent.h>
#include <src/Scene/Components/LightComponent.h>
#include <src/Core/Physics/PhysicsManager.h>
#include <src/Scene/Entities/Components.h>
#include <src/Scene/Components/Components.h>
#include <src/Vendors/glm/gtc/type_ptr.hpp>
#include <src/Vendors/glm/gtx/matrix_decompose.hpp>
#include "src/Scene/Entities/ImGuiHelper.h"
@@ -13,13 +13,14 @@
#include <src/Core/MaterialManager.h>
#include "../Resource/FontAwesome5.h"
#include <src/Scene/Entities/Components/BoxCollider.h>
#include <src/Scene/Components/BoxCollider.h>
#include <algorithm>
#include <Dependencies/GLEW/include/GL/glew.h>
#include "src/Resource/Project.h"
#include <src/Scene/Entities/Components/LuaScriptComponent.h>
#include <src/Scene/Components/LuaScriptComponent.h>
#include <src/Core/Logger.h>
#include <src/Scene/Entities/Components/WrenScriptComponent.h>
#include <src/Scene/Components/WrenScriptComponent.h>
#include <src/Rendering/MSAAFramebuffer.h>
Ref<UI::UserInterface> userInterface;
ImFont* normalFont;
ImFont* EditorInterface::bigIconFont;
@@ -35,7 +36,7 @@ void EditorInterface::Init()
ImGuiID dockspace_id = ImGui::GetID("MyDockSpace");
ImGui::DockSpaceOverViewport(viewport, dockspace_flags);
this->filesystem = FileSystemUI();
//this->filesystem = FileSystemUI();
}
@@ -854,7 +855,7 @@ void EditorInterface::DrawRessourceWindow()
textureID = m_SelectedMaterial->m_Normal->GetID();
if (ImGui::ImageButtonEx(ImGui::GetCurrentWindow()->GetID("#image3"), (void*)textureID, ImVec2(80, 80), ImVec2(0, 1), ImVec2(1, 0), ImVec2(2,2), ImVec4(0,0,0,1), ImVec4(1, 1, 1, 1)))
{
std::string texture = FileDialog::OpenFile("*.png|*.jpg");
std::string texture = FileDialog::OpenFile("*.png");
if (texture != "")
{
m_SelectedMaterial->SetNormal(TextureManager::Get()->GetTexture(texture));
@@ -923,7 +924,7 @@ void NewProject()
void OpenProject()
{
// Parse the project and load it.
std::string projectPath = FileDialog::OpenFile(".project");
std::string projectPath = "C:/Dev/Nuake/Editor/resources/test.project";//FileDialog::OpenFile(".project");
FileSystem::SetRootDirectory(projectPath + "/../");
Ref<Project> project = Project::New();
@@ -1130,13 +1131,13 @@ void EditorInterface::Draw()
DrawRessourceWindow();
DrawViewport();
DrawSceneTree();
DrawFileSystem();
DrawDirectoryExplorer();
//DrawDirectoryExplorer();
DrawEntityPropreties();
DrawLogger();
// new stuff
filesystem.Draw();
filesystem.DrawDirectoryExplorer();
if(m_ShowImGuiDemo)
ImGui::ShowDemoWindow();

View File

@@ -9,7 +9,7 @@ class Material;
class EditorInterface
{
private:
FileSystemUI filesystem;
FileSystemUI filesystem = FileSystemUI();
Entity m_SelectedEntity;
bool m_IsEntitySelected = false;
bool m_DrawGrid = false;

View File

@@ -1,7 +1,7 @@
#include "FileSystemUI.h"
#include <src/Vendors/imgui/imgui.h>
#include <src/Resource/FontAwesome5.h>
#include <src/Scene/Entities/Components/ParentComponent.h>
#include "src/Scene/Components/ParentComponent.h"
#include <src/Rendering/Textures/Texture.h>
#include <src/Core/TextureManager.h>
#include "EditorInterface.h"
@@ -34,7 +34,7 @@ void FileSystemUI::Draw()
}
if (open)
{
//EditorInterfaceDrawFiletree(rootDirectory);
EditorInterfaceDrawFiletree(rootDirectory);
ImGui::TreePop();
}
}
@@ -88,6 +88,12 @@ void FileSystemUI::DrawDirectory(Ref<Directory> directory)
std::string id = ICON_FA_FOLDER + std::string("##") + directory->name;
if (ImGui::Button(id.c_str(), ImVec2(100, 100)))
m_CurrentDirectory = directory;
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::MenuItem("Htest"));
ImGui::EndPopup();
}
ImGui::Text(directory->name.c_str());
ImGui::PopFont();
}
@@ -199,6 +205,54 @@ void FileSystemUI::DrawDirectoryExplorer()
i++;
}
}
if (ImGui::BeginPopupContextItem("item context menu"))
{
float value;
if (ImGui::Selectable("Set to zero")) value = 0.0f;
if (ImGui::Selectable("Set to PI")) value = 3.1415f;
ImGui::SetNextItemWidth(-1);
ImGui::DragFloat("##Value", &value, 0.1f, 0.0f, 0.0f);
ImGui::EndPopup();
}
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::Button("New Wren script"))
{
ImGui::OpenPopup("CreateNewFile");
}
if (ImGui::MenuItem("New interface script"))
{
}
if (ImGui::MenuItem("New Scene"))
{
}
if (ImGui::MenuItem("New folder"))
{
}
if (ImGui::MenuItem("New interface"))
{
}
if (ImGui::MenuItem("New stylesheet"))
{
}
if (ImGui::BeginPopup("CreateNewFile"))
{
static char name[32] = "Label1";
char buf[64];
sprintf(buf, "Button: %s###Button", name); // ### operator override ID ignoring the preceding label
ImGui::Text("Edit name:");
ImGui::InputText("##edit", name, IM_ARRAYSIZE(name));
if (ImGui::Button("Close"))
ImGui::CloseCurrentPopup();
if(ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Enter)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
ImGui::EndPopup();
}
ImGui::EndTable();
}