重构项目src框架,添加c#脚本功能
This commit is contained in:
19
Hazel-ScriptCore/CMakeLists.txt
Normal file
19
Hazel-ScriptCore/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
set(CSPROJECT_NAME Hazel-ScriptCore)
|
||||
|
||||
# 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 Sources/**.cs)
|
||||
|
||||
add_library(${CSPROJECT_NAME} SHARED ${CS_SOURCES})
|
||||
|
||||
12
Hazel-ScriptCore/Sources/Hazel/Input.cs
Normal file
12
Hazel-ScriptCore/Sources/Hazel/Input.cs
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
public class Input
|
||||
{
|
||||
public static bool IsKeyDown(KeyCode keycode)
|
||||
{
|
||||
return InternalCalls.Input_IsKeyDown(keycode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
32
Hazel-ScriptCore/Sources/Hazel/InternalCalls.cs
Normal file
32
Hazel-ScriptCore/Sources/Hazel/InternalCalls.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
public static class InternalCalls
|
||||
{
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static bool Entity_HasComponent(ulong entityID, Type componentType);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static void NativeLog(string text, int param);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static float NativeLog_VectorDot(ref Vector3 param);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static void TransformComponent_GetTranslation(ulong entityID, out Vector3 translation);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static void TransformComponent_SetTranslation(ulong entityID, ref Vector3 translation);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static void RigidBody2DComponent_ApplyLinearImpulse(ulong entityID, ref Vector2 impulse, ref Vector2 worldPoint, bool wake);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static void RigidBody2DComponent_ApplyLinearImpulseToCenter(ulong entityID, ref Vector2 impulse, bool wake);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static bool Input_IsKeyDown(KeyCode keycode);
|
||||
}
|
||||
}
|
||||
292
Hazel-ScriptCore/Sources/Hazel/KeyCode.cs
Normal file
292
Hazel-ScriptCore/Sources/Hazel/KeyCode.cs
Normal file
@ -0,0 +1,292 @@
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
// from SDL_Scancode
|
||||
public enum KeyCode
|
||||
{
|
||||
A = 4,
|
||||
B = 5,
|
||||
C = 6,
|
||||
D = 7,
|
||||
E = 8,
|
||||
F = 9,
|
||||
G = 10,
|
||||
H = 11,
|
||||
I = 12,
|
||||
J = 13,
|
||||
K = 14,
|
||||
L = 15,
|
||||
M = 16,
|
||||
N = 17,
|
||||
O = 18,
|
||||
P = 19,
|
||||
Q = 20,
|
||||
R = 21,
|
||||
S = 22,
|
||||
T = 23,
|
||||
U = 24,
|
||||
V = 25,
|
||||
W = 26,
|
||||
X = 27,
|
||||
Y = 28,
|
||||
Z = 29,
|
||||
|
||||
NUM1 = 30,
|
||||
NUM2 = 31,
|
||||
NUM3 = 32,
|
||||
NUM4 = 33,
|
||||
NUM5 = 34,
|
||||
NUM6 = 35,
|
||||
NUM7 = 36,
|
||||
NUM8 = 37,
|
||||
NUM9 = 38,
|
||||
NUM0 = 39,
|
||||
|
||||
RETURN = 40,
|
||||
ESCAPE = 41,
|
||||
BACKSPACE = 42,
|
||||
TAB = 43,
|
||||
SPACE = 44,
|
||||
|
||||
MINUS = 45,
|
||||
EQUALS = 46,
|
||||
LEFTBRACKET = 47,
|
||||
RIGHTBRACKET = 48,
|
||||
BACKSLASH = 49,
|
||||
|
||||
NONUSHASH = 50,
|
||||
|
||||
SEMICOLON = 51,
|
||||
APOSTROPHE = 52,
|
||||
GRAVE = 53,
|
||||
|
||||
|
||||
COMMA = 54,
|
||||
PERIOD = 55,
|
||||
SLASH = 56,
|
||||
|
||||
CAPSLOCK = 57,
|
||||
|
||||
F1 = 58,
|
||||
F2 = 59,
|
||||
F3 = 60,
|
||||
F4 = 61,
|
||||
F5 = 62,
|
||||
F6 = 63,
|
||||
F7 = 64,
|
||||
F8 = 65,
|
||||
F9 = 66,
|
||||
F10 = 67,
|
||||
F11 = 68,
|
||||
F12 = 69,
|
||||
|
||||
PRINTSCREEN = 70,
|
||||
SCROLLLOCK = 71,
|
||||
PAUSE = 72,
|
||||
INSERT = 73,
|
||||
|
||||
HOME = 74,
|
||||
PAGEUP = 75,
|
||||
DELETE = 76,
|
||||
END = 77,
|
||||
PAGEDOWN = 78,
|
||||
RIGHT = 79,
|
||||
LEFT = 80,
|
||||
DOWN = 81,
|
||||
UP = 82,
|
||||
|
||||
NUMLOCKCLEAR = 83,
|
||||
|
||||
KP_DIVIDE = 84,
|
||||
KP_MULTIPLY = 85,
|
||||
KP_MINUS = 86,
|
||||
KP_PLUS = 87,
|
||||
KP_ENTER = 88,
|
||||
KP_1 = 89,
|
||||
KP_2 = 90,
|
||||
KP_3 = 91,
|
||||
KP_4 = 92,
|
||||
KP_5 = 93,
|
||||
KP_6 = 94,
|
||||
KP_7 = 95,
|
||||
KP_8 = 96,
|
||||
KP_9 = 97,
|
||||
KP_0 = 98,
|
||||
KP_PERIOD = 99,
|
||||
|
||||
NONUSBACKSLASH = 100,
|
||||
|
||||
|
||||
APPLICATION = 101,
|
||||
POWER = 102,
|
||||
|
||||
KP_EQUALS = 103,
|
||||
F13 = 104,
|
||||
F14 = 105,
|
||||
F15 = 106,
|
||||
F16 = 107,
|
||||
F17 = 108,
|
||||
F18 = 109,
|
||||
F19 = 110,
|
||||
F20 = 111,
|
||||
F21 = 112,
|
||||
F22 = 113,
|
||||
F23 = 114,
|
||||
F24 = 115,
|
||||
EXECUTE = 116,
|
||||
HELP = 117,
|
||||
MENU = 118,
|
||||
SELECT = 119,
|
||||
STOP = 120,
|
||||
AGAIN = 121,
|
||||
UNDO = 122,
|
||||
CUT = 123,
|
||||
COPY = 124,
|
||||
PASTE = 125,
|
||||
FIND = 126,
|
||||
MUTE = 127,
|
||||
VOLUMEUP = 128,
|
||||
VOLUMEDOWN = 129,
|
||||
DE_LOCKINGCAPSLOCK = 130,
|
||||
DE_LOCKINGNUMLOCK = 131,
|
||||
DE_LOCKINGSCROLLLOCK = 132,
|
||||
KP_COMMA = 133,
|
||||
KP_EQUALSAS400 = 134,
|
||||
|
||||
INTERNATIONAL1 = 135,
|
||||
|
||||
INTERNATIONAL2 = 136,
|
||||
INTERNATIONAL3 = 137,
|
||||
INTERNATIONAL4 = 138,
|
||||
INTERNATIONAL5 = 139,
|
||||
INTERNATIONAL6 = 140,
|
||||
INTERNATIONAL7 = 141,
|
||||
INTERNATIONAL8 = 142,
|
||||
INTERNATIONAL9 = 143,
|
||||
LANG1 = 144,
|
||||
LANG2 = 145,
|
||||
LANG3 = 146,
|
||||
LANG4 = 147,
|
||||
LANG5 = 148,
|
||||
LANG6 = 149,
|
||||
LANG7 = 150,
|
||||
LANG8 = 151,
|
||||
LANG9 = 152,
|
||||
|
||||
ALTERASE = 153,
|
||||
SYSREQ = 154,
|
||||
CANCEL = 155,
|
||||
CLEAR = 156,
|
||||
PRIOR = 157,
|
||||
RETURN2 = 158,
|
||||
SEPARATOR = 159,
|
||||
OUT = 160,
|
||||
OPER = 161,
|
||||
CLEARAGAIN = 162,
|
||||
CRSEL = 163,
|
||||
EXSEL = 164,
|
||||
|
||||
KP_00 = 176,
|
||||
KP_000 = 177,
|
||||
THOUSANDSSEPARATOR = 178,
|
||||
DECIMALSEPARATOR = 179,
|
||||
CURRENCYUNIT = 180,
|
||||
CURRENCYSUBUNIT = 181,
|
||||
KP_LEFTPAREN = 182,
|
||||
KP_RIGHTPAREN = 183,
|
||||
KP_LEFTBRACE = 184,
|
||||
KP_RIGHTBRACE = 185,
|
||||
KP_TAB = 186,
|
||||
KP_BACKSPACE = 187,
|
||||
KP_A = 188,
|
||||
KP_B = 189,
|
||||
KP_C = 190,
|
||||
KP_D = 191,
|
||||
KP_E = 192,
|
||||
KP_F = 193,
|
||||
KP_XOR = 194,
|
||||
KP_POWER = 195,
|
||||
KP_PERCENT = 196,
|
||||
KP_LESS = 197,
|
||||
KP_GREATER = 198,
|
||||
KP_AMPERSAND = 199,
|
||||
KP_DBLAMPERSAND = 200,
|
||||
KP_VERTICALBAR = 201,
|
||||
KP_DBLVERTICALBAR = 202,
|
||||
KP_COLON = 203,
|
||||
KP_HASH = 204,
|
||||
KP_SPACE = 205,
|
||||
KP_AT = 206,
|
||||
KP_EXCLAM = 207,
|
||||
KP_MEMSTORE = 208,
|
||||
KP_MEMRECALL = 209,
|
||||
KP_MEMCLEAR = 210,
|
||||
KP_MEMADD = 211,
|
||||
KP_MEMSUBTRACT = 212,
|
||||
KP_MEMMULTIPLY = 213,
|
||||
KP_MEMDIVIDE = 214,
|
||||
KP_PLUSMINUS = 215,
|
||||
KP_CLEAR = 216,
|
||||
KP_CLEARENTRY = 217,
|
||||
KP_BINARY = 218,
|
||||
KP_OCTAL = 219,
|
||||
KP_DECIMAL = 220,
|
||||
KP_HEXADECIMAL = 221,
|
||||
|
||||
LCTRL = 224,
|
||||
LSHIFT = 225,
|
||||
LALT = 226,
|
||||
LGUI = 227,
|
||||
RCTRL = 228,
|
||||
RSHIFT = 229,
|
||||
RALT = 230,
|
||||
RGUI = 231,
|
||||
|
||||
MODE = 257,
|
||||
|
||||
SLEEP = 258,
|
||||
WAKE = 259,
|
||||
|
||||
CHANNEL_INCREMENT = 260,
|
||||
CHANNEL_DECREMENT = 261,
|
||||
|
||||
MEDIA_PLAY = 262,
|
||||
MEDIA_PAUSE = 263,
|
||||
MEDIA_RECORD = 264,
|
||||
MEDIA_FAST_FORWARD = 265,
|
||||
MEDIA_REWIND = 266,
|
||||
MEDIA_NEXT_TRACK = 267,
|
||||
MEDIA_PREVIOUS_TRACK = 268,
|
||||
MEDIA_STOP = 269,
|
||||
MEDIA_EJECT = 270,
|
||||
MEDIA_PLAY_PAUSE = 271,
|
||||
MEDIA_SELECT = 272,
|
||||
|
||||
AC_NEW = 273,
|
||||
AC_OPEN = 274,
|
||||
AC_CLOSE = 275,
|
||||
AC_EXIT = 276,
|
||||
AC_SAVE = 277,
|
||||
AC_PRINT = 278,
|
||||
AC_PROPERTIES = 279,
|
||||
|
||||
AC_SEARCH = 280,
|
||||
AC_HOME = 281,
|
||||
AC_BACK = 282,
|
||||
AC_FORWARD = 283,
|
||||
AC_STOP = 284,
|
||||
AC_REFRESH = 285,
|
||||
AC_BOOKMARKS = 286,
|
||||
|
||||
SOFTLEFT = 287,
|
||||
|
||||
SOFTRIGHT = 288,
|
||||
|
||||
CALL = 289,
|
||||
ENDCALL = 290,
|
||||
|
||||
RESERVED = 400, /**< 400-500 reserved for dynamic keycodes */
|
||||
|
||||
COUNT = 512 /**< not a key, just marks the number of scancodes for array bounds */
|
||||
}
|
||||
}
|
||||
32
Hazel-ScriptCore/Sources/Hazel/Scene/Components.cs
Normal file
32
Hazel-ScriptCore/Sources/Hazel/Scene/Components.cs
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
public abstract class Component
|
||||
{
|
||||
public Entity Entity { get; internal set; }
|
||||
}
|
||||
|
||||
public class TransformComponent : Component
|
||||
{
|
||||
public Vector3 Translation {
|
||||
get {
|
||||
InternalCalls.TransformComponent_GetTranslation(Entity.ID, out Vector3 translation);
|
||||
return translation;
|
||||
}
|
||||
set {
|
||||
InternalCalls.TransformComponent_SetTranslation(Entity.ID, ref value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RigidBody2DComponent : Component
|
||||
{
|
||||
public void ApplyLinearImpulse(Vector2 impulse, Vector2 point, bool wake) {
|
||||
InternalCalls.RigidBody2DComponent_ApplyLinearImpulse(Entity.ID, ref impulse, ref point, wake);
|
||||
}
|
||||
|
||||
public void ApplyLinearImpulseToCenter(Vector2 impulse, bool wake) {
|
||||
InternalCalls.RigidBody2DComponent_ApplyLinearImpulseToCenter(Entity.ID, ref impulse, wake);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Hazel-ScriptCore/Sources/Hazel/Scene/Entity.cs
Normal file
42
Hazel-ScriptCore/Sources/Hazel/Scene/Entity.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace Hazel{
|
||||
|
||||
public class Entity {
|
||||
|
||||
protected Entity() { ID = 0; }
|
||||
|
||||
internal Entity(ulong id) { ID = id; }
|
||||
|
||||
public readonly ulong ID;
|
||||
|
||||
public Vector3 Translation
|
||||
{
|
||||
get
|
||||
{
|
||||
InternalCalls.TransformComponent_GetTranslation(ID, out Vector3 translation);
|
||||
return translation;
|
||||
}
|
||||
set
|
||||
{
|
||||
InternalCalls.TransformComponent_SetTranslation(ID, ref value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool HasComponent<T>() where T : Component, new()
|
||||
{
|
||||
Type componentType = typeof(T);
|
||||
return InternalCalls.Entity_HasComponent(ID, componentType);
|
||||
}
|
||||
|
||||
public T GetComponent<T>() where T : Component, new()
|
||||
{
|
||||
if(!HasComponent<T>())
|
||||
return null;
|
||||
T component = new T() { Entity = this };
|
||||
return component;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
68
Hazel-ScriptCore/Sources/Hazel/Vector.cs
Normal file
68
Hazel-ScriptCore/Sources/Hazel/Vector.cs
Normal file
@ -0,0 +1,68 @@
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
public struct Vector2
|
||||
{
|
||||
public float X, Y;
|
||||
|
||||
public static Vector2 Zero => new Vector2(0.0f);
|
||||
|
||||
public Vector2(float scale) {
|
||||
X = scale;
|
||||
Y = scale;
|
||||
}
|
||||
|
||||
public Vector2(float x, float y) {
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public static Vector2 operator*(Vector2 vec, float scale)
|
||||
{
|
||||
return new Vector2(vec.X * scale, vec.Y * scale);
|
||||
}
|
||||
|
||||
public static Vector2 operator+(Vector2 a, Vector2 b)
|
||||
{
|
||||
return new Vector2(a.X + b.X, a.Y + b.Y);
|
||||
}
|
||||
}
|
||||
|
||||
public struct Vector3
|
||||
{
|
||||
public float X, Y, Z;
|
||||
|
||||
public static Vector3 Zero => new Vector3(0.0f);
|
||||
|
||||
public Vector3(float scale) {
|
||||
X = scale;
|
||||
Y = scale;
|
||||
Z = scale;
|
||||
}
|
||||
|
||||
public Vector3(float x, float y, float z) {
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public Vector2 XY {
|
||||
get => new Vector2(X, Y);
|
||||
set
|
||||
{
|
||||
X = value.X;
|
||||
Y = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 operator*(Vector3 vec, float scale)
|
||||
{
|
||||
return new Vector3(vec.X * scale, vec.Y * scale, vec.Z * scale);
|
||||
}
|
||||
|
||||
public static Vector3 operator+(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user