Skip to content

Commit

Permalink
feat: code editor in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMcAvoy committed Oct 16, 2024
1 parent b6685df commit f1e6079
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 140 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ Come back later, sorry! Jenjin is not ready for real usage.
- [x] Scripting (Lua)
- [x] Transparency on sprites
- [x] Icons everywhere
- [ ] Code editor in the editor
- [x] Code editor in the editor
- [ ] Autocompletion in the editor
- [ ] Dynamic data attached to game objects at runtime
- [ ] Hierarchy and `.Parent` in Lua along with `workspace` (e.g. `Workspace.MyGameObject.Parent` == `Workspace`)

## TODO (Future)
- [ ] Serialization/Deserialization of scenes to better formats
- [ ] Syntax highlighting in the editor
- [ ] Sprite animations
- [ ] Scripting (Python)
- [ ] Physics engine
- [ ] Instancing
Expand Down
10 changes: 9 additions & 1 deletion engine/include/jenjin/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <glm/fwd.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>

namespace Jenjin {
// 2D Orthographic Camera
Expand Down Expand Up @@ -34,15 +35,22 @@ class Camera {
glm::vec3 *GetPositionPointer() { return &position; }
float *GetZoomPointer() { return &zoom; }
float *GetRotationPointer() { return &rotation; }
glm::vec3 *GetBackgroundPointer() { return &background; }

glm::mat4 *GetProjetionPointer() { return &this->projection; }

glm::vec2 size;

private:
Shader *shader;

glm::vec3 position;
glm::vec3 position = glm::vec3(0, 0, 0);
float rotation;
float zoom;

glm::mat4 projection;
glm::mat4 view;

glm::vec3 background = glm::vec3(0.15, 0.15, 0.15);
};
} // namespace Jenjin
1 change: 1 addition & 0 deletions engine/include/jenjin/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Manager {
void show_all(Jenjin::Scene *scene);

bool hasProjectOpen = false;
int renderTexture = -1;

private:
Jenjin::GameObject *selectedObject = nullptr;
Expand Down
5 changes: 4 additions & 1 deletion engine/include/jenjin/editor/widgets.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once

#include "jenjin/gameobject.h"
#include "jenjin/camera.h"

namespace Jenjin::Editor::Widgets {
bool transformWidget(
void transformWidget(
Jenjin::GameObject::Transform
*transform);

void cameraWidget(Jenjin::Camera *camera);
};
4 changes: 4 additions & 0 deletions engine/include/jenjin/target.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <glm/glm.hpp>
#include <imgui.h>

namespace Jenjin {
// A "Target" is somewhere for the engine to render to. This class is completely
Expand All @@ -24,6 +25,9 @@ class Target {
// Get the mouse position
virtual glm::vec2 GetMousePosition() { return glm::vec2(-1, -1); };

// Set the window position (information) usually used for the editor
virtual void SetWindowPosition(ImVec2) {};

// Does the target respond to events of the window resizing
virtual bool RespondsToWindowResize() { return true; };
};
Expand Down
3 changes: 3 additions & 0 deletions engine/include/jenjin/targets/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ class EditorTarget : public Jenjin::Target {
virtual glm::vec2 GetMousePosition() override;

virtual bool RespondsToWindowResize() override;
virtual void SetWindowPosition(ImVec2 pos) override;

Jenjin::Framebuffer renderTexture;
int width, height;

Jenjin::Editor::Manager editor;

ImVec2 pos;
};
} // namespace Targets
} // namespace Jenjin
3 changes: 2 additions & 1 deletion engine/src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Camera::Camera(Shader *shader, glm::vec2 size) : shader(shader) {
}

void Camera::Resize(glm::vec2 size) {
this->size = size;

float aspectRatio = size.x / size.y;
float inverseZoom =
1.0f /
Expand All @@ -35,7 +37,6 @@ void Camera::Resize(glm::vec2 size) {
}

void Camera::Update() {
// include rotation
view =
glm::translate(glm::mat4(1.0f), -position) *
glm::rotate(glm::mat4(1.0f), glm::radians(rotation), glm::vec3(0, 0, 1));
Expand Down
Loading

0 comments on commit f1e6079

Please sign in to comment.