Compare commits
38 Commits
ea59c82f35
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 66a3171ccd | |||
| 3272797873 | |||
| 875a77ff5b | |||
| 9e0a2963e8 | |||
| c5a88ac5e3 | |||
| 486b423343 | |||
| c7acb71355 | |||
| 477d6b9ffe | |||
| e8dec2e2d3 | |||
| 9c45444354 | |||
| 1bdb1d240e | |||
| e0bfdd9c4e | |||
| 02c7e0fcf9 | |||
| dd0e9b678c | |||
| d08285b62b | |||
| 8436331a7a | |||
| 6d76832c1d | |||
| aff8d1531c | |||
| 365134ce77 | |||
| 448c162705 | |||
| 71a5a994ff | |||
| 7ec76e23d5 | |||
| b1afcc4166 | |||
| 77f3945ae9 | |||
| f2422abfeb | |||
| 7c5511aa43 | |||
| 9a1700ebf8 | |||
| c17527e3b9 | |||
| 37c17bdb5c | |||
| fadb73243d | |||
| ab4ca6285e | |||
| 52463322dd | |||
| 0a24a2f3c7 | |||
| 9447453e47 | |||
| fdb1ada6cd | |||
| a32ce57503 | |||
| 0032814ed6 | |||
| aecaf86dc0 |
3
.gitignore
vendored
@ -10,5 +10,8 @@ bin-int/
|
||||
cmake-build-debug/
|
||||
cmake-build-release/
|
||||
|
||||
# directories
|
||||
build/
|
||||
|
||||
# Files
|
||||
*.user
|
||||
3
.gitmodules
vendored
@ -26,3 +26,6 @@
|
||||
[submodule "Hazel/vendor/box2d"]
|
||||
path = Hazel/vendor/box2d
|
||||
url = https://github.com/erincatto/box2d.git
|
||||
[submodule "Hazel/vendor/freetype"]
|
||||
path = Hazel/vendor/freetype
|
||||
url = https://github.com/freetype/freetype.git
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(Sandbox) # 占位符
|
||||
project(Editor-Sandbox) # 占位符
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
|
||||
@ -15,16 +14,12 @@ if(MSVC)
|
||||
endif ()
|
||||
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
|
||||
file(GLOB ASSETS Sandbox/assets/*)
|
||||
file(COPY ${ASSETS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)
|
||||
|
||||
file(GLOB RESOURCES Sandbox/Resources/*)
|
||||
file(COPY ${RESOURCES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources)
|
||||
|
||||
add_subdirectory(Hazel)
|
||||
add_subdirectory(Sandbox)
|
||||
add_subdirectory(Editor)
|
||||
add_subdirectory(Sandbox)
|
||||
add_subdirectory(Hazel-ScriptCore)
|
||||
add_subdirectory(Editor/SandboxProject)
|
||||
|
||||
#add_subdirectory(Sandbox)
|
||||
37
Editor/CMakeLists.txt
Normal file
@ -0,0 +1,37 @@
|
||||
# Hazel-Editor
|
||||
set(PROJECT_NAME "Editor")
|
||||
project(${PROJECT_NAME})
|
||||
|
||||
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin-int)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
|
||||
# set MSVC output directory
|
||||
if(MSVC)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
endif ()
|
||||
|
||||
file(GLOB ASSETS assets/*)
|
||||
file(COPY ${ASSETS} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets)
|
||||
|
||||
file(GLOB RESOURCES Resources/*)
|
||||
file(COPY ${RESOURCES} DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Resources)
|
||||
|
||||
# TODO: remove it later
|
||||
file(GLOB MONO_DEP lib/mono)
|
||||
file(COPY ${MONO_DEP} DESTINATION ${CMAKE_BINARY_DIR}/bin/Resources)
|
||||
|
||||
file(GLOB_RECURSE SOURCES
|
||||
src/**.cpp
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE Hazel-shared)
|
||||
|
||||
# add Hazel-ScriptCore.dll dependence to auto build
|
||||
#add_dependencies(${PROJECT_NAME} Hazel-ScriptCore)
|
||||
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 119 B After Width: | Height: | Size: 119 B |
|
Before Width: | Height: | Size: 357 B After Width: | Height: | Size: 357 B |
|
Before Width: | Height: | Size: 667 B After Width: | Height: | Size: 667 B |
|
Before Width: | Height: | Size: 438 B After Width: | Height: | Size: 438 B |
|
Before Width: | Height: | Size: 115 B After Width: | Height: | Size: 115 B |
29
Editor/SandboxProject/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
set(CSPROJECT_NAME Sandbox)
|
||||
|
||||
# set MSVC output directory
|
||||
if(MSVC)
|
||||
set(SCRIPT_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin/Resources/Scripts")
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${SCRIPT_OUTPUT_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${SCRIPT_OUTPUT_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${SCRIPT_OUTPUT_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${SCRIPT_OUTPUT_DIR})
|
||||
endif ()
|
||||
|
||||
enable_language(CSharp)
|
||||
|
||||
project(${CSPROJECT_NAME} LANGUAGES CSharp)
|
||||
|
||||
file(GLOB_RECURSE CS_SOURCES
|
||||
Source/**
|
||||
Properties/
|
||||
)
|
||||
|
||||
add_library(${CSPROJECT_NAME} SHARED ${CS_SOURCES})
|
||||
|
||||
add_dependencies(${CSPROJECT_NAME} Hazel-ScriptCore)
|
||||
|
||||
set_property(TARGET ${CSPROJECT_NAME} PROPERTY VS_DOTNET_REFERENCE_Hazel-ScriptCore
|
||||
Hazel-ScriptCore
|
||||
)
|
||||
|
||||
target_link_libraries(${CSPROJECT_NAME} PRIVATE Hazel-ScriptCore)
|
||||
57
Editor/SandboxProject/Source/Camera.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using Hazel;
|
||||
|
||||
namespace Sandbox {
|
||||
|
||||
public class Camera : Entity
|
||||
{
|
||||
// private TransformComponent m_Transform;
|
||||
// private RigidBody2DComponent m_Rigidbody;
|
||||
|
||||
public float MoveSpeed;
|
||||
public float DistanceFromPlayer = 5;
|
||||
|
||||
private Entity m_Player;
|
||||
|
||||
void OnCreate()
|
||||
{
|
||||
Console.WriteLine($"Camera.OnCreate - {ID}");
|
||||
|
||||
m_Player = FindEntityByName("Player");
|
||||
}
|
||||
|
||||
|
||||
void OnUpdate(float ts)
|
||||
{
|
||||
if(m_Player != null)
|
||||
{
|
||||
Translation = new Vector3(m_Player.Translation.XY, DistanceFromPlayer);
|
||||
}
|
||||
// Console.WriteLine($"Player.OnUpdate: {ts}");
|
||||
|
||||
float speed = MoveSpeed;
|
||||
Vector3 velocity = Vector3.Zero;
|
||||
|
||||
if(Input.IsKeyDown(KeyCode.UP))
|
||||
velocity.Y = 1.0f;
|
||||
else if(Input.IsKeyDown(KeyCode.DOWN))
|
||||
velocity.Y = -1.0f;
|
||||
|
||||
if(Input.IsKeyDown(KeyCode.LEFT))
|
||||
velocity.X = -1.0f;
|
||||
else if(Input.IsKeyDown(KeyCode.RIGHT))
|
||||
velocity.X = 1.0f;
|
||||
|
||||
// m_Rigidbody.ApplyLinearImpulse(velocity.XY * speed, Vector2.Zero, true);
|
||||
|
||||
velocity *= speed;
|
||||
|
||||
Vector3 translation = Translation;
|
||||
translation += velocity * ts;
|
||||
Translation = translation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
55
Editor/SandboxProject/Source/Player.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using Hazel;
|
||||
|
||||
namespace Sandbox {
|
||||
|
||||
public class Player : Entity
|
||||
{
|
||||
private TransformComponent m_Transform;
|
||||
private RigidBody2DComponent m_Rigidbody;
|
||||
|
||||
public float Force;
|
||||
public float Time;
|
||||
|
||||
void OnCreate()
|
||||
{
|
||||
Console.WriteLine($"Player.OnCreate - {ID}");
|
||||
|
||||
m_Transform = GetComponent<TransformComponent>();
|
||||
m_Rigidbody = GetComponent<RigidBody2DComponent>();
|
||||
}
|
||||
|
||||
void OnUpdate(float ts)
|
||||
{
|
||||
Time += ts;
|
||||
|
||||
float speed = Force;
|
||||
Vector3 velocity = Vector3.Zero;
|
||||
|
||||
if(Input.IsKeyDown(KeyCode.W))
|
||||
velocity.Y = 1.0f;
|
||||
else if(Input.IsKeyDown(KeyCode.S))
|
||||
velocity.Y = -1.0f;
|
||||
|
||||
if(Input.IsKeyDown(KeyCode.A))
|
||||
velocity.X = -1.0f;
|
||||
else if(Input.IsKeyDown(KeyCode.D))
|
||||
velocity.X = 1.0f;
|
||||
|
||||
Entity cameraEntity = FindEntityByName("Camera");
|
||||
if(cameraEntity != null)
|
||||
{
|
||||
Camera camera = cameraEntity.As<Camera>();
|
||||
|
||||
if(Input.IsKeyDown(KeyCode.Q))
|
||||
camera.DistanceFromPlayer -= speed * 2.0f * ts;
|
||||
else if(Input.IsKeyDown(KeyCode.E))
|
||||
camera.DistanceFromPlayer += speed * 2.0f * ts;
|
||||
}
|
||||
|
||||
m_Rigidbody.ApplyLinearImpulseToCenter(velocity.XY * speed, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
72
Editor/assets/shaders/Renderer2D_circle.glsl
Normal file
@ -0,0 +1,72 @@
|
||||
// Basic circle Texture Shader
|
||||
|
||||
#type vertex
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 a_WorldPosition;
|
||||
layout(location = 1) in vec3 a_LocalPosition;
|
||||
layout(location = 2) in vec4 a_Color;
|
||||
layout(location = 3) in float a_Thickness;
|
||||
layout(location = 4) in float a_Fade;
|
||||
layout(location = 5) in int a_EntityID;
|
||||
|
||||
layout(std140, binding = 0) uniform Camera
|
||||
{
|
||||
mat4 u_ViewProjection;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
vec3 LocalPosition;
|
||||
vec4 Color;
|
||||
float Thickness;
|
||||
float Fade;
|
||||
};
|
||||
|
||||
layout (location = 0) out VertexOutput Output;
|
||||
layout (location = 4) out flat int v_EntityID;
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.LocalPosition = a_LocalPosition;
|
||||
Output.Color = a_Color;
|
||||
Output.Thickness = a_Thickness;
|
||||
Output.Fade = a_Fade;
|
||||
|
||||
v_EntityID = a_EntityID;
|
||||
|
||||
gl_Position = u_ViewProjection * vec4(a_WorldPosition, 1.0);
|
||||
}
|
||||
|
||||
#type fragment
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) out vec4 o_Color;
|
||||
layout(location = 1) out int o_EntityID;
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
vec3 LocalPosition;
|
||||
vec4 Color;
|
||||
float Thickness;
|
||||
float Fade;
|
||||
};
|
||||
|
||||
layout (location = 0) in VertexOutput Input;
|
||||
layout (location = 4) in flat int v_EntityID;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
float distance = 1.0f - length(Input.LocalPosition);
|
||||
|
||||
float circle = smoothstep(0.0f, Input.Fade, distance);
|
||||
circle *= smoothstep(Input.Thickness + Input.Fade, Input.Thickness, distance);
|
||||
|
||||
if(circle == 0.0f)
|
||||
discard;
|
||||
|
||||
o_Color = Input.Color;
|
||||
o_Color.a *= circle;
|
||||
o_EntityID = v_EntityID;
|
||||
}
|
||||
49
Editor/assets/shaders/Renderer2D_line.glsl
Normal file
@ -0,0 +1,49 @@
|
||||
// Basic Line Texture Shader
|
||||
|
||||
#type vertex
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 a_Position;
|
||||
layout(location = 1) in vec4 a_Color;
|
||||
layout(location = 2) in int a_EntityID;
|
||||
|
||||
layout(std140, binding = 0) uniform Camera
|
||||
{
|
||||
mat4 u_ViewProjection;
|
||||
};
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
vec4 Color;
|
||||
};
|
||||
|
||||
layout (location = 0) out VertexOutput Output;
|
||||
layout (location = 1) out flat int v_EntityID;
|
||||
|
||||
void main()
|
||||
{
|
||||
Output.Color = a_Color;
|
||||
v_EntityID = a_EntityID;
|
||||
|
||||
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
|
||||
}
|
||||
|
||||
#type fragment
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) out vec4 o_Color;
|
||||
layout(location = 1) out int o_EntityID;
|
||||
|
||||
struct VertexOutput
|
||||
{
|
||||
vec4 Color;
|
||||
};
|
||||
|
||||
layout (location = 0) in VertexOutput Input;
|
||||
layout (location = 1) in flat int v_EntityID;
|
||||
|
||||
void main()
|
||||
{
|
||||
o_Color = Input.Color;
|
||||
o_EntityID = v_EntityID;
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
// Basic Texture Shader
|
||||
// Basic quad Texture Shader
|
||||
|
||||
#type vertex
|
||||
#version 450 core
|
||||
@ -60,5 +60,8 @@ void main()
|
||||
{
|
||||
o_Color = texture(u_Textures[int(v_TexIndex)], Input.TexCoord * Input.TilingFactor) * Input.Color;
|
||||
|
||||
if(o_Color.a == 0.0f)
|
||||
discard;
|
||||
|
||||
o_EntityID = v_EntityID;
|
||||
}
|
||||
69
Editor/assets/shaders/Renderer2D_text.glsl
Normal file
@ -0,0 +1,69 @@
|
||||
// Basic MSDF Text Texture Shader
|
||||
|
||||
#type vertex
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) in vec3 a_Position;
|
||||
layout(location = 1) in vec4 a_Color;
|
||||
layout(location = 2) in vec2 a_TexCoord;
|
||||
layout(location = 3) in int a_EntityID;
|
||||
|
||||
layout(std140, binding = 0) uniform Camera
|
||||
{
|
||||
mat4 u_ViewProjection;
|
||||
};
|
||||
|
||||
layout (location = 0) out vec4 o_Color;
|
||||
layout (location = 1) out vec2 o_TexCoord;
|
||||
layout (location = 2) out flat int v_EntityID;
|
||||
|
||||
void main()
|
||||
{
|
||||
o_Color = a_Color;
|
||||
o_TexCoord = a_TexCoord;
|
||||
v_EntityID = a_EntityID;
|
||||
|
||||
gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
|
||||
}
|
||||
|
||||
#type fragment
|
||||
#version 450 core
|
||||
|
||||
layout(location = 0) out vec4 o_Color;
|
||||
layout(location = 1) out int o_EntityID;
|
||||
|
||||
layout (location = 0) in vec4 i_Color;
|
||||
layout (location = 1) in vec2 i_TexCoord;
|
||||
layout (location = 2) in flat int v_EntityID;
|
||||
|
||||
layout (binding = 0) uniform sampler2D u_FontAtlas;
|
||||
|
||||
float screenPxRange() {
|
||||
const float pxRange = 2.0; // set to distance field's pixel range
|
||||
vec2 unitRange = vec2(pxRange)/vec2(textureSize(u_FontAtlas, 0));
|
||||
vec2 screenTexSize = vec2(1.0)/fwidth(i_TexCoord); // 使用 i_TexCoord
|
||||
return max(0.5*dot(unitRange, screenTexSize), 1.0);
|
||||
}
|
||||
|
||||
float median(float r, float g, float b) {
|
||||
return max(min(r, g), min(max(r, g), b));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = i_Color * texture(u_FontAtlas, i_TexCoord); // 使用 i_Color 和 i_TexCoord
|
||||
|
||||
vec3 msd = texture(u_FontAtlas, i_TexCoord).rgb; // 使用 i_TexCoord
|
||||
float sd = median(msd.r, msd.g, msd.b);
|
||||
float screenPxDistance = screenPxRange()*(sd - 0.5);
|
||||
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||||
if (opacity == 0.0)
|
||||
discard;
|
||||
|
||||
vec4 bgColor = vec4(0.0);
|
||||
o_Color = mix(bgColor, i_Color, opacity); // 使用 i_Color
|
||||
if (o_Color.a == 0.0)
|
||||
discard;
|
||||
|
||||
o_EntityID = v_EntityID;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 435 KiB After Width: | Height: | Size: 435 KiB |
|
Before Width: | Height: | Size: 216 KiB After Width: | Height: | Size: 216 KiB |
|
Before Width: | Height: | Size: 328 KiB After Width: | Height: | Size: 328 KiB |